| | |
| | | import org.springblade.mdm.program.service.ProgramSeqService; |
| | | import org.springblade.mdm.utils.EntityUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | NcNode curedProgramPackage = null; |
| | | if(!startVO.isTemporaryFlow() && !startVO.isDeviationFlow()) { |
| | | //æ£å¸¸æµç¨(éä¸´æ¶æµç¨) ä¸ä¸æ¯ å离å,æå¹é
åºåç¨åº |
| | | curedProgramPackage = ncNodeService.getLastCuredProgramPackageWithoutProcessEdition(programPkgName,startVO.getMachineCode()); |
| | | curedProgramPackage = ncNodeService.getLastCuredProgramWithoutProcessEdition(startVO.getDrawingNo(),startVO.getProcessNo(),startVO.getMachineCode()); |
| | | //设置æ¯å¦æåºåç¨åºæ è®° |
| | | vars.put(FlowContants.HAS_CURED_PROGRAM, curedProgramPackage != null ? FlowContants.Y : FlowContants.N); |
| | | //å·¥åºç次æ¯å¦ä¸è´ï¼æ¯å¦å¨æææå
|
| | |
| | | package org.springblade.mdm.flow.excution.dispatch; |
| | | |
| | | import com.alibaba.excel.util.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.service.ApproveRecordService; |
| | | import org.springblade.mdm.flow.service.FlowProgramFileService; |
| | | import org.springblade.mdm.flow.service.FlowProgramProperties; |
| | | import org.springblade.mdm.gkw.programnode.vo.ProgramNameVO; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.entity.NcProgramApproved; |
| | | import org.springblade.mdm.program.service.NcNodeAutoCreateService; |
| | | import org.springblade.mdm.program.service.NcNodeService; |
| | | import org.springblade.mdm.program.service.NcProgramApprovedService; |
| | | import org.springblade.mdm.utils.EntityUtil; |
| | | import org.springblade.mdm.utils.ProgramFileNameParser; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | Integer newVersion = packageNode.genNewVersionNumber(); |
| | | packageNode = ncNodeAutoCreateService.createNodeTreeWithProgram(props,newVersion); |
| | | }else{ |
| | | //å¯ç¨ï¼åçï¼ä¿®æ¹å
¶å·¥åºçæ¬ï¼ï¼åæ¥çèç¹æ¸
é¤ |
| | | //å¯ç¨ï¼åçï¼ä¿®æ¹å
¶å·¥åºç次ï¼ï¼åæ¥çèç¹æ¸
é¤ |
| | | moveToNewProcessEdition(packageNode,props); |
| | | } |
| | | }else{ |
| | |
| | | packageNode.setProcessEdition(tempProps.getProcessEdition()); |
| | | packageNode.setParentId(machineNode.getParentId()); |
| | | packageNode.setParentIds(machineNode.getParentIds()); |
| | | packageNode.setName(tempProps.getDrawingNo()+"-"+tempProps.getProcessNo()+"-"+tempProps.getProcessEdition()); |
| | | this.ncNodeService.updateById(packageNode); |
| | | |
| | | //ç§»å¨ç¨åºèç¹ |
| | | List<NcNode> programNodes = ncNodeService.getProgramFilesByPackageId(packageNode.getId()); |
| | | for(NcNode programNode : programNodes){ |
| | | |
| | | programNode.setName(buildNewFilename(programNode.getName(),tempProps.getProcessEdition()));//åç§°ä¿®æ¹ï¼å·¥åºç次é¨å |
| | | programNode.setParentIds(packageNode.getParentIds()+","+packageNode.getId()); |
| | | programNode.setProcessEdition(tempProps.getProcessEdition());//ä¿®æ¹å·¥åºç次 |
| | | programNode.setVersionNumber(packageNode.getVersionNumber()); |
| | | } |
| | | ncNodeService.updateBatchById(programNodes); |
| | | |
| | | |
| | | } |
| | | |
| | | String buildNewFilename(String filename,String newProcessEdition){ |
| | | ProgramNameVO pnameVO = ProgramFileNameParser.parseProgramName(filename); |
| | | String ext = FilenameUtils.getExtension(filename); |
| | | String name= pnameVO.getDrawingNo()+"-"+pnameVO.getProcessNo()+"-"+newProcessEdition+"-"+pnameVO.getSegmentCount()+"-"+pnameVO.getSegmentNo(); |
| | | if(StringUtils.isNotBlank(ext)){ |
| | | name += "."+ext; |
| | | } |
| | | return name; |
| | | } |
| | | |
| | | /** |
| | | * ä¿å审æ¹å®æçè®°å½ |
| | |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.entity.NcProgramExchange; |
| | | import org.springblade.mdm.program.mapper.NcProgramExchangeMapper; |
| | | import org.springblade.mdm.program.service.programannotation.AnnotationProcessor; |
| | | import org.springblade.mdm.program.service.programannotation.DefaultProcessor; |
| | | import org.springblade.mdm.program.service.programannotation.FanucProcessor; |
| | | import org.springblade.mdm.program.service.programannotation.MachineAnnotationConfig; |
| | | import org.springblade.mdm.program.vo.DncSendBackData; |
| | | import org.springblade.mdm.program.vo.DncSendBackFile; |
| | | import org.springblade.mdm.program.vo.ProgramAnnotation; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.*; |
| | | import java.lang.annotation.Annotation; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.StandardOpenOption; |
| | | import java.time.Duration; |
| | | import java.util.*; |
| | | import java.util.regex.Pattern; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipFile; |
| | | |
| | |
| | | private final DncBackFileService dncBackFileService; |
| | | private final MachineService machineService; |
| | | private final ParamService paramService; |
| | | private final MachineAnnotationConfig machineAnnotationConfig; |
| | | |
| | | private final FanucProcessor fanucProcessor; |
| | | private final DefaultProcessor defaultProcessor; |
| | | /** |
| | | * å离åæä»¶æ«å°¾ç模å¼ï¼P+æ°å |
| | | */ |
| | |
| | | DncSendBackData progData = new DncSendBackData(); |
| | | String folderName = StringUtils.removeEnd(entryName,"/"); |
| | | |
| | | PackageAndProcessEdition pkgAndEdition = parseProgramPackageFromFolderName(folderName); |
| | | String packageName = pkgAndEdition.getProgramPackageName(); |
| | | String processEdition = pkgAndEdition.getProcessEdition(); |
| | | //PackageAndProcessEdition pkgAndEdition = parseProgramPackageFromFolderName(folderName); |
| | | String packageName = folderName;//pkgAndEdition.getProgramPackageName(); |
| | | //String processEdition = pkgAndEdition.getProcessEdition(); |
| | | /* |
| | | if(StringUtils.isBlank(packageName) || StringUtils.isBlank(processEdition)){ |
| | | throw new ServiceException("å
å
æä»¶å¤¹åæ ¼å¼é误åºè¯¥ä¸º[é¶ç»ä»¶å·-å·¥åºå·-å·¥åºç次]:"+folderName); |
| | | } |
| | | throw new ServiceException("å
å
æä»¶å¤¹åæ ¼å¼é误ï¼åºè¯¥ä¸º[é¶ç»ä»¶å·-å·¥åºå·-å·¥åºç次]:"+folderName); |
| | | }*/ |
| | | |
| | | progData.setProgramName(packageName); |
| | | String statusLine; |
| | |
| | | if(optFilename.isPresent()){ |
| | | entry = zipFile.getEntry(optFilename.get()); |
| | | InputStream ins = zipFile.getInputStream(entry); |
| | | ByteArrayInputStream bais = new ByteArrayInputStream(IOUtils.toByteArray(ins));; |
| | | progData.setFileBackTime(DateUtil.fromInstant(entry.getLastModifiedTime().toInstant())); |
| | | statusLine = FileContentUtil.readLineAt(ins,2); |
| | | //machineAnnotationConfig.getConfigMap().get(machine.getcon) |
| | | Pattern fanucPattern = Pattern.compile("^[oO]\\d{4}"); |
| | | String testLine = FileContentUtil.readLineAt(bais,2);//TODO,fanucè¿è¡æ¯ä¸åè·¯å¾ï¼å
¶ä»æºå¨æ¯ç¶æ |
| | | bais.reset(); |
| | | //boolean isFanuc = fanucPattern.matcher(testLine).matches(); |
| | | boolean isFanuc = !StringUtils.containsAny(testLine,"(SQ)","(GH)","(PL)"); |
| | | if(isFanuc){ |
| | | statusLine = FileContentUtil.readLineAt(bais,3);//fanucçç¶æè¯»ç¬¬4è¡ |
| | | }else{ |
| | | statusLine = testLine; |
| | | } |
| | | |
| | | if(statusLine.contains("SQ")){ |
| | | //è¯å |
| | | programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName,processEdition); |
| | | programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName);//,processEdition |
| | | }else if(statusLine.contains("GH")){ |
| | | //åºå |
| | | programPackageNode = ncNodeService.getLastEditionCuredProgramPackage(packageName,processEdition); |
| | | programPackageNode = ncNodeService.getLastEditionCuredProgramPackage(packageName); |
| | | }else if(statusLine.contains("PL")){ |
| | | //å离 |
| | | programPackageNode =ncNodeService.getLastEditionDeviationProgramPackage(packageName,processEdition); |
| | | programPackageNode =ncNodeService.getLastEditionDeviationProgramPackage(packageName); |
| | | }else{ |
| | | //æ¥è¯¢æ¯å¦è½¦åºï¼æ¯è½¦åºå¯ä»¥æ¾è¿ï¼æè¯åå¤ç |
| | | programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName,processEdition); |
| | | programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName); |
| | | if(programPackageNode!=null){ |
| | | Machine machine = machineService.getByCode(programPackageNode.getMachineCode()); |
| | | String chechuangVal = paramService.turninngValue(); |
| | |
| | | * @param folderName æä»¶å¤¹å |
| | | * @return ç»ææ°æ® |
| | | */ |
| | | /* |
| | | PackageAndProcessEdition parseProgramPackageFromFolderName(String folderName){ |
| | | int index = StringUtils.lastIndexOf(folderName,'-'); |
| | | String processEditon = ""; |
| | | String temp; |
| | | String packageName = ""; |
| | | if(index != -1){ |
| | | processEditon = folderName.substring(index+1); |
| | |
| | | result.setProgramPackageName(packageName); |
| | | result.setProcessEdition(processEditon); |
| | | return result; |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * å
¥åºåä¼ æä»¶,å¹¶å¯å¨åºåæµç¨ |
| | |
| | | for(String dir : dirList){ |
| | | String folderName = StringUtils.removeEnd(dir,"/"); |
| | | |
| | | PackageAndProcessEdition pkgAndEdition = parseProgramPackageFromFolderName(folderName); |
| | | String programPackageName = pkgAndEdition.getProgramPackageName(); |
| | | //PackageAndProcessEdition pkgAndEdition = folderName;//parseProgramPackageFromFolderName(folderName); |
| | | String programPackageName = folderName; //pkgAndEdition.getProgramPackageName(); |
| | | |
| | | Optional<NcNode> optPackageNode = allAcceptPackages.stream().filter(node -> StringUtils.equals(node.getName(),programPackageName)).findFirst(); |
| | | |
| | |
| | | private String programPackageName; |
| | | private String processEdition; |
| | | |
| | | public String programName(){ |
| | | return programPackageName+"-"+processEdition; |
| | | } |
| | | } |
| | |
| | | * @param name èç¹åç§° |
| | | * @return ææ°çæ¬ç¨åºæ¥åèç¹ |
| | | */ |
| | | public NcNode getLastEditionTryingProgramPackage(String name,String processEdition){ |
| | | public NcNode getLastEditionTryingProgramPackage(String name){ |
| | | //.or(NcNode::getIsCured,0) |
| | | List<NcNode> pkgList = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE) |
| | | .eq(NcNode::getName, name).and(i->{ |
| | | i.eq(NcNode::getIsCured, 0).or().isNull(NcNode::getIsCured); |
| | | }).likeRight(NcNode::getParentIds,"0,1,") |
| | | .eq(NcNode::getIsLastEdition,1).eq(NcNode::getProcessEdition,processEdition).orderByDesc(NcNode::getCreateTime).list(); |
| | | .eq(NcNode::getIsLastEdition,1).orderByDesc(NcNode::getCreateTime).list();//.eq(NcNode::getProcessEdition,processEdition) |
| | | |
| | | if(pkgList.isEmpty()){ |
| | | return null; |
| | |
| | | * @param programPkgName |
| | | * @return |
| | | */ |
| | | public NcNode getLastEditionCuredProgramPackage(String programPkgName,String processEdition) { |
| | | public NcNode getLastEditionCuredProgramPackage(String programPkgName) { |
| | | List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE) |
| | | .eq(NcNode::getName, programPkgName).likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1) |
| | | .eq(NcNode::getProcessEdition, processEdition) |
| | | //.eq(NcNode::getProcessEdition, processEdition) |
| | | .eq(NcNode::getIsLastEdition,1).list(); |
| | | |
| | | if(nodes.isEmpty()){ |
| | |
| | | |
| | | /** |
| | | * è·åææ°çåºåç¨åºï¼ä¸ç¨å·¥åºç次å¹é
|
| | | * @param programPkgName |
| | | * @param drawingNo |
| | | * @param processNo |
| | | * @param machineCode |
| | | * @return |
| | | */ |
| | | public NcNode getLastCuredProgramPackageWithoutProcessEdition(String programPkgName,String machineCode) { |
| | | public NcNode getLastCuredProgramWithoutProcessEdition(String drawingNo, String processNo, String machineCode) { |
| | | Machine machine = machineService.getByCode(machineCode); |
| | | List<Machine> sameGroupMachines = machineService.lambdaQuery().eq(Machine::getMachineGroupCode,machine.getMachineGroupCode()).list(); |
| | | List<String> machineCodesInGroup = sameGroupMachines.stream().map(Machine::getCode).toList(); |
| | | List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE) |
| | | .eq(NcNode::getName, programPkgName) |
| | | .eq(NcNode::getDrawingNo, drawingNo).eq(NcNode::getProcessNo, processNo) |
| | | .likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1) |
| | | .in(!machineCodesInGroup.isEmpty(),NcNode::getMachineCode,machineCodesInGroup) |
| | | .eq(NcNode::getIsLastEdition,1).orderByDesc(NcNode::getCreateTime).list(); |
| | |
| | | * @param programPkgName ç¨åºå
å |
| | | * @return å离çç¨åºèç¹ |
| | | */ |
| | | public NcNode getLastEditionDeviationProgramPackage(String programPkgName,String processEdition) { |
| | | public NcNode getLastEditionDeviationProgramPackage(String programPkgName) {//,String processEdition |
| | | List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE) |
| | | .eq(NcNode::getName, programPkgName) |
| | | .eq(NcNode::getProcessEdition, processEdition) |
| | | //.eq(NcNode::getProcessEdition, processEdition) |
| | | .likeRight(NcNode::getParentIds,"0,3,") |
| | | .eq(NcNode::getIsLastEdition,1).list(); |
| | | |
| | |
| | | import org.springblade.mdm.program.entity.NcProgramApproved; |
| | | import org.springblade.mdm.program.entity.NcProgramExchange; |
| | | import org.springblade.mdm.program.mapper.NcProgramExchangeMapper; |
| | | import org.springblade.mdm.program.service.programannotation.AnnotationData; |
| | | import org.springblade.mdm.program.service.programannotation.AnnotationProcessor; |
| | | import org.springblade.mdm.program.service.programannotation.MachineAnnotationConfig; |
| | | import org.springblade.mdm.program.service.programannotation.ProcessorHelper; |
| | | import org.springblade.system.feign.IDictClient; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final ProgramAnnotationService programAnnotationService; |
| | | |
| | | |
| | | private final MachineAnnotationConfig annotationConfig; |
| | | /** |
| | | * 导åºdncå缩å
|
| | | * @param approvedIdArray å¾
导åºå®¡æ¹è¡¨idæ°ç» |
| | |
| | | private void addProgramPackageToZip(ZipOutputStream zipOut, NcProgramApproved approved) throws IOException{ |
| | | NcNode packageNode = ncNodeService.getById(approved.getNcNodeId()); |
| | | |
| | | String packageFolder = packageNode.getName()+"-"+packageNode.getProcessEdition()+"/"; |
| | | String packageFolder = packageNode.getName()+"/"; |
| | | ZipEntry zipEntry = new ZipEntry(packageFolder);// "/"ç»å°¾è¡¨ç¤ºæä»¶å¤¹ |
| | | zipOut.putNextEntry(zipEntry); |
| | | zipOut.closeEntry(); |
| | |
| | | deviationSerial = ncNodeService.getDeviationSerialForNode(packageNode); |
| | | } |
| | | |
| | | List<DictBiz> annotationDictList= programAnnotationService.getAnnotionDictList(); |
| | | //List<DictBiz> annotationDictList= programAnnotationService.getAnnotionDictList(); |
| | | for (NcNode node : programNodes) { |
| | | String filePathInZip = genFilePathInZip(packageFolder,node,deviationSerial); |
| | | programFile = this.flowProgramFileService.getById(node.getFlowProgramFileId()); |
| | | if(programFile.isProgram()) {//ç¨åºæä»¶ï¼æä¼å å
¥å缩å
|
| | | InputStream inputStream = ossTemplate.statFileStream(programFile.getOssName()); |
| | | String sendDir = machine.getProgSendDir()==null? StringUtil.EMPTY:machine.getProgSendDir(); |
| | | |
| | | AnnotationProcessor annoProcessor = ProcessorHelper.getProcessor(machine.getControlSystem(),annotationConfig); |
| | | AnnotationData annoData = new AnnotationData(); |
| | | annoData.setSendPath(sendDir); |
| | | annoData.setProgramStatus(status); |
| | | annoData.setDeviation(programPackageNode.getDeviation()); |
| | | annoData.setFilename(programFile.getName()); |
| | | InputStream addedInsFinal = annoProcessor.setAnnotation(annoData,inputStream); |
| | | addedInsFinal.reset(); |
| | | /* |
| | | InputStream addedInsFinal; |
| | | InputStream addedIns2 = programAnnotationService.setSendDirAndStatusAnnotation(sendDir,status,inputStream,machine.getControlSystem()); |
| | | if(StringUtils.isNotBlank(programPackageNode.getDeviation())) { |
| | |
| | | addedInsFinal = programAnnotationService.setPldAnnotation(programPackageNode.getDeviation(),addedIns2, machine.getControlSystem(), annotationDictList);; |
| | | }else{ |
| | | addedInsFinal = addedIns2; |
| | | } |
| | | }*/ |
| | | this.addInputStreamToZip(zipOut, addedInsFinal, filePathInZip); |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.program.service.programannotation; |
| | | |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.List; |
| | | |
| | | public abstract class AbstractProcessor implements AnnotationProcessor{ |
| | | |
| | | @Autowired |
| | | private ProgramAnnotationService programAnnotationService; |
| | | |
| | | protected AnnotationProperties annotationProperties; |
| | | |
| | | |
| | | @Override |
| | | public InputStream setAnnotation(AnnotationData annoData,InputStream inputStream) throws IOException { |
| | | List<DictBiz> annoDicts = programAnnotationService.getAnnotionDictList(); |
| | | |
| | | InputStream finishedStream; |
| | | try(inputStream){ |
| | | ByteArrayInputStream byteInputStream = new ByteArrayInputStream(IOUtils.toByteArray(inputStream)); |
| | | |
| | | //1å å
¥åéè·¯å¾ç注é |
| | | String sendPathAnnotation = generateAnnotation(annoData.getSendPath(),getControlSystem(),annoDicts);//å äºæ³¨éä¹åçææ¬ |
| | | |
| | | String sendDirLine = FileContentUtil.readLineAt(byteInputStream,annotationProperties.getSendPathLineIndex());//第2è¡æ¯åéè·¯å¾ |
| | | byteInputStream.reset(); |
| | | String statusLine = FileContentUtil.readLineAt(byteInputStream,annotationProperties.getStatusLineIndex());//ç¶ææ³¨é |
| | | byteInputStream.reset(); |
| | | |
| | | InputStream insAfterSetSendDir ; |
| | | if(isAnnotation(sendDirLine,getControlSystem(),annoDicts)){ |
| | | insAfterSetSendDir = FileContentUtil.replaceAtLine(byteInputStream,annotationProperties.getSendPathLineIndex(),sendPathAnnotation); |
| | | }else{ |
| | | insAfterSetSendDir = FileContentUtil.insertLine(byteInputStream,annotationProperties.getSendPathLineIndex(),sendPathAnnotation); |
| | | } |
| | | |
| | | insAfterSetSendDir.reset(); |
| | | //å å
¥ç¶ææ³¨éè¡ |
| | | String statusAnnotation = generateAnnotation(annoData.getProgramStatus(),getControlSystem(),annoDicts);//注éåçç¶æææ¬ |
| | | if(isAnnotation(statusLine,getControlSystem(),annoDicts)){ |
| | | finishedStream = FileContentUtil.replaceAtLine(insAfterSetSendDir,annotationProperties.getStatusLineIndex(),statusAnnotation); |
| | | }else{ |
| | | finishedStream = FileContentUtil.insertLine(insAfterSetSendDir,annotationProperties.getStatusLineIndex(),statusAnnotation); |
| | | } |
| | | } |
| | | |
| | | return finishedStream; |
| | | } |
| | | |
| | | @Override |
| | | public abstract void setControlSystem(String controlSystemDictVal) ; |
| | | |
| | | @Override |
| | | public void setAnnotationProperties(AnnotationProperties annotationProperties) { |
| | | this.annotationProperties= annotationProperties; |
| | | } |
| | | |
| | | public abstract String getControlSystem(); |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.program.service.programannotation; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class AnnotationData { |
| | | /** |
| | | * ä¸åè·¯å¾ |
| | | */ |
| | | private String filename; |
| | | /** |
| | | * ä¸åè·¯å¾ |
| | | */ |
| | | private String sendPath; |
| | | /** |
| | | * ç¨åºç¶æ |
| | | */ |
| | | private String programStatus; |
| | | /** |
| | | * å离åå· |
| | | */ |
| | | private String deviation; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.program.service.programannotation; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | | import org.springblade.mdm.program.vo.ProgramAnnotation; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | |
| | | public interface AnnotationProcessor { |
| | | static final String DEFAULT_ANNOTATION_SETTING = "(,)"; |
| | | |
| | | default String generateAnnotation(String oriTest, String systemDictVal, List<DictBiz> annotationList) { |
| | | ProgramAnnotation progAnnotation = this.getProgramAnnotationFormat(systemDictVal,annotationList); |
| | | return progAnnotation.addAnnotation(oriTest); |
| | | } |
| | | default boolean isAnnotation(String line,String systemDictVal,List<DictBiz> annotationList){ |
| | | ProgramAnnotation progAnnotation = this.getProgramAnnotationFormat(systemDictVal,annotationList); |
| | | |
| | | line = StringUtils.trim(line);//å»é¦å°¾ç©ºæ ¼ |
| | | return progAnnotation.isAnnotation(line); |
| | | } |
| | | |
| | | default ProgramAnnotation getProgramAnnotationFormat(String systemDictVal,List<DictBiz> annoDictList){ |
| | | String begin; |
| | | String end; |
| | | |
| | | Optional<DictBiz> dictOpt = annoDictList.stream().filter(dict -> {return dict.getDictKey().equals(systemDictVal);}).findFirst(); |
| | | String annotationSetting = DEFAULT_ANNOTATION_SETTING; |
| | | if(dictOpt.isPresent()) { |
| | | annotationSetting = dictOpt.get().getRemark(); |
| | | } |
| | | String[] arr = StringUtils.split(annotationSetting,","); |
| | | if(arr.length == 2){ |
| | | begin = arr[0]; |
| | | end = arr[1]; |
| | | }else if(arr.length == 1){ |
| | | begin = arr[0]; |
| | | end = ""; |
| | | }else{ |
| | | throw new ServiceException("æ³¨éæ ¼å¼é
ç½®é误ï¼åºè¯¥ä¸º1å°2段ï¼ä¸é´ç¨éå·åé"); |
| | | } |
| | | |
| | | ProgramAnnotation programAnnotation = new ProgramAnnotation(); |
| | | programAnnotation.setBegin(begin); |
| | | programAnnotation.setEnd(end); |
| | | return programAnnotation; |
| | | } |
| | | void setControlSystem(String controlSystemDictVal); |
| | | void setAnnotationProperties(AnnotationProperties annotationProperties); |
| | | String getControlSystem(); |
| | | InputStream setAnnotation(AnnotationData annoData,InputStream inputStream) throws IOException; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.program.service.programannotation; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class AnnotationProperties { |
| | | private String beanId; |
| | | private int sendPathLineIndex; |
| | | private int statusLineIndex; |
| | | private int deviationLineIndex; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.program.service.programannotation; |
| | | |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | |
| | | @Component("defaultProcessor") |
| | | public class DefaultProcessor extends AbstractProcessor{ |
| | | |
| | | @Autowired |
| | | private ProgramAnnotationService programAnnotationService; |
| | | private String controlSystem; |
| | | private AnnotationProperties annotationPropreties; |
| | | |
| | | |
| | | @Override |
| | | public void setControlSystem(String controlSystemDictVal) { |
| | | this.controlSystem = controlSystemDictVal; |
| | | } |
| | | |
| | | @Override |
| | | public void setAnnotationProperties(AnnotationProperties annotationProperties) { |
| | | this.annotationPropreties= annotationProperties; |
| | | } |
| | | |
| | | @Override |
| | | public String getControlSystem() { |
| | | return this.controlSystem; |
| | | } |
| | | |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.program.service.programannotation; |
| | | |
| | | import com.qiniu.util.IOUtils; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.List; |
| | | import java.util.regex.Pattern; |
| | | |
| | | @Component("fanucProcessor") |
| | | public class FanucProcessor extends AbstractProcessor{ |
| | | @Autowired |
| | | private ProgramAnnotationService programAnnotationService; |
| | | private String controlSystem; |
| | | //AnnotationProperties annotationProperties; |
| | | private Pattern PATTERN = Pattern.compile("^[oO]\\d{4}"); |
| | | private final int O_LINE = 1; |
| | | @Override |
| | | public InputStream setAnnotation(AnnotationData annoData,InputStream inputStream) throws IOException { |
| | | //å¨O0001 è¿ç§æååé¢å¢å æä»¶åï¼ä¸å¸¦æ©å±åï¼ |
| | | ByteArrayInputStream bais = new ByteArrayInputStream(IOUtils.toByteArray(inputStream)); |
| | | String line = FileContentUtil.readLineAt(bais,O_LINE); |
| | | bais.reset(); |
| | | boolean oMatched = PATTERN.matcher(line).matches(); |
| | | InputStream ins1; |
| | | if(oMatched){ |
| | | List<DictBiz> annoDicts = programAnnotationService.getAnnotionDictList(); |
| | | String newline = line + generateAnnotation(FilenameUtils.removeExtension(annoData.getFilename()),getControlSystem(),annoDicts); |
| | | ins1 = FileContentUtil.replaceAtLine(bais,O_LINE,newline); |
| | | }else{ |
| | | ins1 = bais; |
| | | } |
| | | return super.setAnnotation(annoData, ins1); |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void setControlSystem(String controlSystemDictVal) { |
| | | this.controlSystem = controlSystemDictVal; |
| | | } |
| | | |
| | | @Override |
| | | public String getControlSystem() { |
| | | return this.controlSystem; |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.program.service.programannotation; |
| | | |
| | | import lombok.Data; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import java.util.Map; |
| | | |
| | | @Configuration |
| | | @ConfigurationProperties(prefix = "program-annotation") |
| | | @Data |
| | | public class MachineAnnotationConfig { |
| | | private Map<String, AnnotationProperties> configMap; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.program.service.programannotation; |
| | | |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | |
| | | /** |
| | | * è´è´£åæ¢åéçæ³¨éå¤çå¨ |
| | | */ |
| | | public class ProcessorHelper { |
| | | |
| | | public static AnnotationProcessor getProcessor(String controlSystem,MachineAnnotationConfig config){ |
| | | AnnotationProperties props = config.getConfigMap().get(controlSystem); |
| | | AnnotationProcessor processor; |
| | | if(props != null){ |
| | | processor = SpringUtil.getBean(props.getBeanId()); |
| | | }else{ |
| | | processor = SpringUtil.getBean(DefaultProcessor.class); |
| | | } |
| | | processor.setAnnotationProperties(props); |
| | | return processor; |
| | | } |
| | | } |