yangys
2025-08-10 a638cb450abb78346ecf19754b639fc945bc486b
blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/ReplaceFlowService.java
@@ -18,11 +18,14 @@
import org.springblade.mdm.flow.vo.TaskAssignVO;
import org.springblade.mdm.program.entity.NcNode;
import org.springblade.mdm.program.service.NcNodeService;
import org.springblade.mdm.program.service.NodeDeptQueryService;
import org.springblade.mdm.program.vo.NcNodeVO;
import org.springblade.mdm.utils.EntityUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -37,15 +40,16 @@
   private final IdentityService identityService;
   private final FlowProgramFileService flowProgramFileService;
   private final ReplaceProgramFileService replaceProgramFileService;
   private final MachineService machineService;
   private final NodeDeptQueryService nodeDeptQueryService;
   public static final String NODE_ID = "nodeId";
   /**
     * 转派,并记录自己的备注信息
    * @param nodeId 替换的节点id
    */
   /*
   @Transactional
   public void pre(long nodeId,String tempInstanceId) {
   public void prestart(long nodeId,String tempInstanceId) {
      List<NcNode> fileNodes = nodeService.lambdaQuery()
         .eq(NcNode::getParentId, nodeId)
         .eq(NcNode::getIsLastEdition,1)
@@ -58,21 +62,48 @@
      //将现有文件复制到独立的表中,后续作为审批的文件,审批界面调用的接口也不同,最好单独开发
      for(FlowProgramFile programFile : programFiles) {
         /*
         ReplaceProgramFile replaceProgramFile = new ReplaceProgramFile();
         BeanUtils.copyProperties(programFile, replaceProgramFile);
         EntityUtil.clearBaseProperties(replaceProgramFile);
         replaceProgramFile.setTempId(tempId);
         replaceProgramFileService.save(replaceProgramFile);
          */
         FlowProgramFile newFile = new FlowProgramFile();
         BeanUtils.copyProperties(programFile, newFile);
         EntityUtil.clearBaseProperties(newFile);
         newFile.setProcessInstanceId(tempInstanceId);
         flowProgramFileService.save(newFile);
      }
   }
    */
   @Transactional
   public NcNodeVO pre(long nodeId, String tempInstanceId) {
      List<NcNode> fileNodes = nodeService.lambdaQuery()
         .eq(NcNode::getParentId, nodeId)
         .eq(NcNode::getIsLastEdition,1)
         .eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_FILE).list();
      List<Long> fileIds = fileNodes.stream().map(NcNode::getFlowProgramFileId).toList();
      if(fileIds.isEmpty()){
         throw new RuntimeException("未找到程序文件");
      }
      List<FlowProgramFile> programFiles = flowProgramFileService.lambdaQuery()
         .in(FlowProgramFile::getId, fileIds).list();
      //将现有文件复制到独立的表中,后续作为审批的文件,审批界面调用的接口也不同,最好单独开发
      for(FlowProgramFile programFile : programFiles) {
         FlowProgramFile newFile = new FlowProgramFile();
         BeanUtils.copyProperties(programFile, newFile);
         EntityUtil.clearBaseProperties(newFile);
         newFile.setProcessInstanceId(tempInstanceId);
         flowProgramFileService.save(newFile);
      }
      NcNode node = nodeService.getById(nodeId);
      NcNodeVO vo = new NcNodeVO();
      BeanUtils.copyProperties(node, vo);
      vo.setProcessInstanceId(tempInstanceId);
      vo.setWorkshop(nodeDeptQueryService.getWorkshopNameByMachineCode(node.getMachineCode()));
      return vo;
   }
   /**
@@ -85,23 +116,25 @@
      vars.put(FlowContants.ASSIGNEE,startVO.getAssignee());//第一个审批用户
      vars.put(FlowContants.TITLE,startVO.getTitle());
      NcNode programPackge = nodeService.getById(startVO.getNodeId());
      NcNode programPackage = nodeService.getById(startVO.getNodeId());
      //机床编号
      vars.put(FlowContants.MACHINE_CODE,programPackge.getMachineCode());
      vars.put(FlowContants.MACHINE_CODE,programPackage.getMachineCode());
      //Machine machine = machineService.getByCode(programPackge.getMachineCode());
      //机床型号
      //if(machine != null) {
         //vars.put(FlowContants.MACHINE_MODE, programPackge.getMachineMode());
      //}
      vars.put(FlowContants.PROCESS_NO,programPackge.getProcessNo());
      vars.put(FlowContants.PROCESS_NAME,programPackge.getProcessName());
      vars.put(FlowContants.PROCESS_EDITION,programPackge.getProcessEdition());
      vars.put(FlowContants.CRAFT_EDITION,programPackge.getCraftEdition());
      vars.put(FlowContants.PROCESS_NO,programPackage.getProcessNo());
      vars.put(FlowContants.PROCESS_NAME,programPackage.getProcessName());
      vars.put(FlowContants.PROCESS_EDITION,programPackage.getProcessEdition());
      vars.put(FlowContants.CRAFT_EDITION,programPackage.getCraftEdition());
      vars.put(FlowContants.DRAWING_NO,programPackge.getDrawingNo());
      vars.put(FlowContants.DRAWING_NO_EDITION,programPackge.getDrawingNoEdition());
      vars.put(FlowContants.DRAWING_NO,programPackage.getDrawingNo());
      vars.put(FlowContants.DRAWING_NO_EDITION,programPackage.getDrawingNoEdition());
      vars.put(FlowContants.PRODUCT_MODEL,programPackge.getProductModel());
      vars.put(FlowContants.PROGRAM_PACKAGE_NAME,programPackage.getName());
      vars.put(FlowContants.PRODUCT_MODEL,programPackage.getProductModel());
      vars.put(NODE_ID, startVO.getNodeId());
      identityService.setAuthenticatedUserId(String.valueOf(AuthUtil.getUserId()));//设置流程发起人
      ProcessInstance inst = runtimeService.startProcessInstanceByKey(FlowContants.REPLACE_PROCESS_KEY,startVO.getNodeId()+"",vars);