| | |
| | | |
| | | 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.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 org.springblade.mdm.gkw.task.service.MachineBackTaskService; |
| | | import org.springblade.mdm.machinefile.entity.FileSendRecord; |
| | | import org.springblade.mdm.machinefile.service.FileSendRecordService; |
| | | import org.springblade.mdm.program.entity.NcProgramExchange; |
| | | import org.springblade.mdm.program.mapper.NcProgramExchangeMapper; |
| | | import org.springblade.mdm.program.service.programannotation.AnnotationProperties; |
| | | import org.springblade.mdm.program.service.programannotation.*; |
| | | import org.springblade.mdm.program.vo.MdmProgramImportVO; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.mdm.utils.ProgramFileNameParser; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | private FileSendRecordService fileSendRecordService; |
| | | @Autowired |
| | | private OssTemplate ossTemplate; |
| | | @Autowired |
| | | private AnnotationProcessorHelper annotationProcessorHelper; |
| | | @Autowired |
| | | private MachineBackTaskService machineBackTaskService; |
| | | |
| | | private String getFileKey(){ |
| | | return "mdmgkwimpfile-"+ AuthUtil.getUserId(); |
| | | } |
| | |
| | | Path extractDir = Paths.get(dictStr); |
| | | List<MdmProgramImportVO> list = readTempDir(extractDir); |
| | | |
| | | List<DictBiz> annoDictList = programAnnotationService.getAnnotionDictList(); |
| | | String destFileFull; |
| | | for(String str : idList){ |
| | | Optional<MdmProgramImportVO> optVO = list.stream().filter(vo -> vo.getId().equals(str)).findFirst(); |
| | |
| | | BladeFile bFile = ossTemplate.putFile(record.getName(), inputStream); |
| | | record.setOssName(bFile.getName()); |
| | | } |
| | | |
| | | try(InputStream inputStream = ossTemplate.statFileStream(record.getOssName())){ |
| | | //读取程序状态 |
| | | Machine machine = this.machineService.getByCode(record.getMachineCode()); |
| | | AnnotationProcessor processor = annotationProcessorHelper.getProcessor(machine.getControlSystem()); |
| | | AnnotationData annotationData = processor.readAnnotationData(inputStream); |
| | | /* |
| | | ProgramNameVO nameVO = ProgramFileNameParser.parseProgramName(record.getName()); |
| | | if(StringUtils.isNotBlank(nameVO.getLgPart())) { |
| | | record.setDeviation(annotationData.getDeviation()); |
| | | }*/ |
| | | record.setProgramStatus(annotationData.getProgramStatus()); |
| | | } |
| | | fileSendRecordService.save(record); |
| | | |
| | | importedRecords.add(record); |
| | | } |
| | | |
| | | machineBackTaskService.saveBatch(parseMachineBackTask(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(); |
| | | |
| | | 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); |
| | | } |
| | | |
| | | List<MachineBackTask> backTasks = new ArrayList<>(); |
| | | for(String key : map.keySet()){ |
| | | MachineBackTask task = new MachineBackTask(); |
| | | task.setTaskType(MachineBackTask.TASK_TYPE_PROGRAM); |
| | | |
| | | FileSendRecord record = map.get(key); |
| | | task.setMachineCode(record.getMachineCode()); |
| | | |
| | | ProgramNameVO nameVO = ProgramFileNameParser.parseProgramName(record.getName()); |
| | | task.setProgramName(nameVO.logicProgramName()); |
| | | task.setSegCount(nameVO.getSegmentCount()); |
| | | backTasks.add(task); |
| | | } |
| | | //提取程序包名,机床编码集合 |
| | | return backTasks; |
| | | } |
| | | } |