| | |
| | | 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.*; |
| | | import org.springblade.mdm.program.vo.DncSendBackData; |
| | | import org.springblade.mdm.program.vo.DncSendBackFile; |
| | | import org.springblade.mdm.program.vo.ProgramAnnotation; |
| | |
| | | private final DncBackFileService dncBackFileService; |
| | | private final MachineService machineService; |
| | | private final ParamService paramService; |
| | | |
| | | /** |
| | | * 偏离单文件末尾的模式:P+数字 |
| | | */ |
| | |
| | | //目录列表,即程序包列表 |
| | | for(String entryName : dirEntryNameList){ |
| | | DncSendBackData progData = new DncSendBackData(); |
| | | String folderName = StringUtils.removeEnd(entryName,"/"); |
| | | |
| | | PackageAndProcessEdition pkgAndEdition = parseProgramPackageFromFolderName(folderName); |
| | | String packageName = pkgAndEdition.getProgramPackageName(); |
| | | String processEdition = pkgAndEdition.getProcessEdition(); |
| | | if(StringUtils.isBlank(packageName) || StringUtils.isBlank(processEdition)){ |
| | | throw new ServiceException("包内文件夹名格式错误应该为[零组件号-工序号-工序版次]:"+folderName); |
| | | } |
| | | String packageName = StringUtils.removeEnd(entryName,"/"); |
| | | |
| | | progData.setProgramName(packageName); |
| | | String statusLine; |
| | | Optional<String> optFilename = fileEntryNameList.stream().filter(n -> n.startsWith(entryName)).findFirst(); |
| | | 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); |
| | | if(statusLine.contains("SQ")){ |
| | | |
| | | AnnotationProperties defAnnoProperties =AnnotationProperties.getDefault(); |
| | | String statusLine = FileContentUtil.readLineAt(bais,defAnnoProperties.getStatusLineIndex());//状态注释行 |
| | | bais.reset(); |
| | | String sendPathLine = FileContentUtil.readLineAt(bais,defAnnoProperties.getSendPathLineIndex());//状态注释行 |
| | | bais.reset(); |
| | | |
| | | if(statusLine.contains("GH")){ |
| | | //固化,不应回传,忽略 |
| | | log.warn("状态{},不应回传,忽略",statusLine); |
| | | continue; |
| | | } |
| | | |
| | | Machine machine = this.machineService.getMachineBySendPathAnnotation(sendPathLine); |
| | | if(machine == null){ |
| | | throw new ServiceException("根据下发路径未找到程序对应的机床:"+sendPathLine); |
| | | } |
| | | |
| | | if(statusLine.contains(AnnotationUtil.SQ)){ |
| | | //试切 |
| | | programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName,processEdition); |
| | | }else if(statusLine.contains("GH")){ |
| | | //固化 |
| | | programPackageNode = ncNodeService.getLastEditionCuredProgramPackage(packageName,processEdition); |
| | | }else if(statusLine.contains("PL")){ |
| | | //偏离 |
| | | programPackageNode =ncNodeService.getLastEditionDeviationProgramPackage(packageName,processEdition); |
| | | programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName);//TODO 还需根据机床组(如何获取?根据下发路径获取机床,进而获取),,processEdition |
| | | }else if(statusLine.contains(AnnotationUtil.LG)){ |
| | | //临时更改单 |
| | | programPackageNode =ncNodeService.getLastEditionDeviationProgramPackage(packageName); |
| | | }else{ |
| | | //查询是否车床,是车床可以放过,按试切处理 |
| | | programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName,processEdition); |
| | | if(programPackageNode!=null){ |
| | | Machine machine = machineService.getByCode(programPackageNode.getMachineCode()); |
| | | String chechuangVal = paramService.turninngValue(); |
| | | if(StringUtils.equals(machine.getMachineSpec(),chechuangVal)){ |
| | | //车床 |
| | | ProgramAnnotation pa = programAnnotationService.getProgramAnnotationFormat(machine.getControlSystem(),annotionDictList); |
| | | statusLine = pa.addAnnotation(ProgramAnnotationService.SQ); |
| | | } |
| | | } |
| | | throw new ServiceException("状态注释不在范围内:"+statusLine+",仅试切、临时更改单可以回传"); |
| | | } |
| | | |
| | | if(programPackageNode != null) { |
| | |
| | | * @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; |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * 入库回传文件,并启动固化流程 |
| | |
| | | //根据内部文件,读取和分析程序包和程序文件数据 |
| | | List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList(); |
| | | for(String dir : dirList){ |
| | | String folderName = StringUtils.removeEnd(dir,"/"); |
| | | |
| | | PackageAndProcessEdition pkgAndEdition = parseProgramPackageFromFolderName(folderName); |
| | | String programPackageName = pkgAndEdition.getProgramPackageName(); |
| | | String programPackageName = StringUtils.removeEnd(dir,"/"); |
| | | |
| | | Optional<NcNode> optPackageNode = allAcceptPackages.stream().filter(node -> StringUtils.equals(node.getName(),programPackageName)).findFirst(); |
| | | |
| | |
| | | FlowProgramFile newFlowFile = new FlowProgramFile(); |
| | | newFlowFile.setProgramName(packageNode.getName()); |
| | | newFlowFile.setProcessInstanceId(null);//先置为空,启动流程后设置该值 |
| | | newFlowFile.setFileType("program"); |
| | | newFlowFile.setFileType(FlowProgramFile.TYPE_PROGRAM); |
| | | newFlowFile.setName(fileName); |
| | | InputStream ins = zipFile.getInputStream(zipFile.getEntry(entryName)); |
| | | BladeFile newOssFile = ossTemplate.putFile("mdm",fileName,ins); |
| | |
| | | private String programPackageName; |
| | | private String processEdition; |
| | | |
| | | public String programName(){ |
| | | return programPackageName+"-"+processEdition; |
| | | } |
| | | } |