yangys
2025-09-29 4c7296d45efe849dc70a3b2e2240c905481a91c9
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java
@@ -1,11 +1,9 @@
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;
@@ -16,7 +14,6 @@
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;
@@ -43,7 +40,6 @@
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;
@@ -260,8 +256,8 @@
      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)) {
         // 使用输入流读取文件内容
@@ -286,7 +282,7 @@
         Machine matchedMachine = machineService.getMachineBySendPathAnnotation(sendPathLine);
         if (matchedMachine != null) {
            vo.setName(pnmameVO.logicProgramName());
            vo.setName(progNmameVO.logicProgramName());
            vo.setMachineCode(matchedMachine.getCode());
            vo.setFullPath(path.toString());//文件地址
@@ -300,68 +296,7 @@
      }
      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列表逗号分隔
@@ -378,7 +313,7 @@
      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();
@@ -391,6 +326,7 @@
         destFileFull = vo.getSendPath()+File.separator+vo.getFilename();
         File destFile = new File(destFileFull);
         FileUtils.forceMkdirParent(destFile);
         FileUtils.copyFile(new File(str),destFile);
@@ -410,11 +346,11 @@
            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);
@@ -427,17 +363,17 @@
   /**
    * 创建机床回传任务
    * @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);
      }
@@ -450,6 +386,9 @@
         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);