| | |
| | | |
| | | package org.springblade.mdm.program.service; |
| | | |
| | | import jodd.util.annotation.AnnotationParser; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.commons.contants.RegExpConstants; |
| | | import org.springblade.mdm.commons.contants.ZipConstants; |
| | | import org.springblade.mdm.gkw.programnode.vo.ProgramNameVO; |
| | | import org.springblade.mdm.gkw.task.entity.MachineBackTask; |
| | |
| | | import java.time.Duration; |
| | | import java.util.*; |
| | | import java.nio.file.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.stream.Stream; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipInputStream; |
| | |
| | | MdmProgramImportVO vo = new MdmProgramImportVO(); |
| | | vo.setFilename(path.getFileName().toString()); |
| | | |
| | | ProgramNameVO pnmameVO = tryParseProgramName(vo.getFilename()); |
| | | vo.setDrawingNo(pnmameVO.getDrawingNo()); |
| | | ProgramNameVO progNmameVO = tryParseProgramName(vo.getFilename()); |
| | | vo.setDrawingNo(progNmameVO.getDrawingNo()); |
| | | |
| | | try (InputStream inputStream = Files.newInputStream(path)) { |
| | | // 使用输入流读取文件内容 |
| | |
| | | Machine matchedMachine = machineService.getMachineBySendPathAnnotation(sendPathLine); |
| | | |
| | | if (matchedMachine != null) { |
| | | vo.setName(pnmameVO.logicProgramName()); |
| | | vo.setName(progNmameVO.logicProgramName()); |
| | | vo.setMachineCode(matchedMachine.getCode()); |
| | | |
| | | vo.setFullPath(path.toString());//文件地址 |
| | |
| | | } |
| | | return vo; |
| | | } |
| | | /** |
| | | * 解析出零组件好 |
| | | * @param filename |
| | | * @return |
| | | */ |
| | | /* |
| | | String parseDrawingNo(String filename){ |
| | | |
| | | /* |
| | | String drawingNo = ""; |
| | | int idx = filename.lastIndexOf("-"); |
| | | String temp; |
| | | if(idx != -1){ |
| | | temp = filename.substring(0,idx); |
| | | |
| | | idx = temp.lastIndexOf("-"); |
| | | if(idx != -1){ |
| | | temp = temp.substring(0,idx); |
| | | |
| | | //去掉工序版次 |
| | | idx = temp.lastIndexOf("-"); |
| | | if(idx != -1){ |
| | | temp = temp.substring(0,idx); |
| | | |
| | | //去掉工序号 |
| | | idx = temp.lastIndexOf("-"); |
| | | if(idx != -1){ |
| | | drawingNo = temp.substring(0,idx); |
| | | } |
| | | } |
| | | } |
| | | //以上去掉了最后2段段数和段号 |
| | | |
| | | |
| | | } |
| | | return drawingNo; |
| | | |
| | | |
| | | } |
| | | |
| | | String parseProgramName(String filename){ |
| | | String programName = ""; |
| | | int idx = filename.lastIndexOf("-"); |
| | | String temp; |
| | | if(idx != -1){ |
| | | temp = filename.substring(0,idx); |
| | | |
| | | idx = temp.lastIndexOf("-"); |
| | | if(idx != -1){ |
| | | temp = temp.substring(0,idx); |
| | | |
| | | //去掉工序版次 |
| | | idx = temp.lastIndexOf("-"); |
| | | if(idx != -1){ |
| | | programName = temp.substring(0,idx); |
| | | } |
| | | } |
| | | //以上去掉了最后2段段数和段号 |
| | | } |
| | | return programName; |
| | | } |
| | | */ |
| | | /** |
| | | * 入库mdm涉密网文件 |
| | | * @param ids id列表逗号分隔 |
| | |
| | | Path extractDir = Paths.get(dictStr); |
| | | List<MdmProgramImportVO> list = readTempDir(extractDir); |
| | | |
| | | List<DictBiz> annoDictList = programAnnotationService.getAnnotionDictList(); |
| | | //List<DictBiz> annoDictList = programAnnotationService.getAnnotionDictList(); |
| | | String destFileFull; |
| | | for(String str : idList){ |
| | | Optional<MdmProgramImportVO> optVO = list.stream().filter(vo -> vo.getId().equals(str)).findFirst(); |
| | |
| | | |
| | | destFileFull = vo.getSendPath()+File.separator+vo.getFilename(); |
| | | File destFile = new File(destFileFull); |
| | | |
| | | FileUtils.forceMkdirParent(destFile); |
| | | FileUtils.copyFile(new File(str),destFile); |
| | | |
| | |
| | | Machine machine = this.machineService.getByCode(record.getMachineCode()); |
| | | AnnotationProcessor processor = annotationProcessorHelper.getProcessor(machine.getControlSystem()); |
| | | AnnotationData annotationData = processor.readAnnotationData(inputStream); |
| | | /* |
| | | |
| | | record.setDeviation(annotationData.getDeviation()); |
| | | ProgramNameVO nameVO = ProgramFileNameParser.parseProgramName(record.getName()); |
| | | if(StringUtils.isNotBlank(nameVO.getLgPart())) { |
| | | record.setDeviation(annotationData.getDeviation()); |
| | | }*/ |
| | | record.setDeviationSerial(nameVO.lgSerial()); |
| | | |
| | | record.setProgramStatus(annotationData.getProgramStatus()); |
| | | } |
| | | fileSendRecordService.save(record); |
| | |
| | | |
| | | /** |
| | | * 创建机床回传任务 |
| | | * @param importedRecords |
| | | * @param importedRecords 导入记录列表 |
| | | */ |
| | | List<MachineBackTask> parseMachineBackTask(List<FileSendRecord> importedRecords){ |
| | | List<FileSendRecord> recList = importedRecords.stream().filter(r ->{ |
| | | return AnnotationUtil.SQ.equals(r.getProgramStatus()) |
| | | || AnnotationUtil.LG.equals(r.getProgramStatus());}).toList(); |
| | | List<FileSendRecord> recList = importedRecords.stream().filter(r -> AnnotationUtil.SQ.equals(r.getProgramStatus()) |
| | | || AnnotationUtil.LG.equals(r.getProgramStatus())).toList(); |
| | | |
| | | Map<String,FileSendRecord> map = new HashMap<>(); |
| | | for(FileSendRecord record : recList){ |
| | | ProgramNameVO nameVO = ProgramFileNameParser.parseProgramName(record.getName()); |
| | | String key = record.getMachineCode()+","+nameVO.logicProgramName(); |
| | | |
| | | map.put(key,record); |
| | | } |
| | | |
| | |
| | | task.setMachineCode(record.getMachineCode()); |
| | | |
| | | ProgramNameVO nameVO = ProgramFileNameParser.parseProgramName(record.getName()); |
| | | task.setDeviation(record.getDeviation()); |
| | | task.setDeviationSerial(record.getDeviationSerial()); |
| | | |
| | | task.setProgramName(nameVO.logicProgramName()); |
| | | task.setSegCount(nameVO.getSegmentCount()); |
| | | backTasks.add(task); |