yangys
2025-08-16 8db9b68d0bf4b7ec2e80b580f5931a40788caac7
blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/execute/TryFlowCompleteService.java
@@ -11,11 +11,13 @@
import org.springblade.mdm.flow.constants.FlowContants;
import org.springblade.mdm.flow.service.FlowCommonService;
import org.springblade.mdm.flow.service.FlowProgramFileService;
import org.springblade.mdm.flow.service.FlowProgramProperties;
import org.springblade.mdm.program.entity.NcNode;
import org.springblade.mdm.program.service.NcNodeAutoCreateService;
import org.springblade.mdm.program.service.NcNodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
@@ -33,6 +35,7 @@
   @Autowired
   private FlowCommonService flowCommonService;
   @Transactional
   @Override
   public void completeTask(String taskId, String processInstanceId, String comment, Map<String, Object> variables) {
      Task task = currentTask(taskId);
@@ -56,35 +59,41 @@
      addApproveRecord(taskId,comment,variables);
      //在编制任务时,创建节点(没有节点则创建,有就直接使用
      if(task.getTaskDefinitionKey().equals("programmingTask") && "Y".equals(operateResult)) {
         ncNodeAutoCreateService.createNodeTreeWithProgram(flowCommonService.getProgramProperties(processInstanceId));
      }
      if(!"confirmIsUseableTask".equals(task.getTaskDefinitionKey())){
         variables.remove(FlowContants.PROCESS_EDITION);//TODO 临时错误是,组长提交的时候会提交一个空串,清空了内部数据
      }else{
         //工序版次不一致,并且审核通过(可用)是,才更新为新的工序版次号
         Map<String, Object> currentVars = task.getProcessVariables();
         if(StringUtils.equals(String.valueOf(currentVars.getOrDefault(FlowContants.IS_PROCESS_EDITION_SAME, FlowContants.Y)),FlowContants.N) && operateResult.equals(FlowContants.Y)){
            //工序版次不一致,并且审核通过(可用) 升版,更新为新的工序版本,后续进入 校对 节点
            Object objProcessEdition = variables.get(FlowContants.PROCESS_EDITION);
            if(objProcessEdition == null){
               //应该升版,但前端没有传递该参数
               throw new ServiceException("请录入新的工序版本号");
            }
            String newProcessEdition = String.valueOf(objProcessEdition);
            NcNode programPkgNode= ncNodeService.getByProcessInstanceId(processInstanceId);
            programPkgNode.setProcessEdition(newProcessEdition);
            ncNodeService.updateById(programPkgNode);
      /*
      if(task.getTaskDefinitionKey().equals("programmingTask") && FlowContants.Y.equals(operateResult)) {
         FlowProgramProperties progProperties = flowCommonService.getProgramProperties(processInstanceId);
         ncNodeAutoCreateService.createNodeTreeWithProgram(progProperties);
         //原来版次的程序,此时应该清除,是不是要挪过来呢?版次已经不对了
         //TODO 老节点清除吗
            //创建程序树
            //节点在试切下还是固化下面?确认了,节点建立在试切下,最终走固化流程后才进入固化
            //确认程序可用了,进入校对。这里直接建立节点,因为可能不走编程节点了
            this.ncNodeAutoCreateService.createNodeTreeWithProgram(flowCommonService.getProgramProperties(processInstanceId));
         }else{
            //工序版次一致,但是拒绝了,后续会进入编制节点
            variables.remove(FlowContants.PROCESS_EDITION);
         //走到编制节点,如果是有固化程序且通过了,说明需要升版(重新编写),将固化的原来的程序设置lastEdition=0
         if(FlowContants.Y.equals(progProperties.getHasCuredProgram())) {
            NcNode curedProgramPackage = ncNodeService.getById(Func.toLong(progProperties.getCuredNodeId()));
            curedProgramPackage.setIsLastEdition(0);
            curedProgramPackage.setIsLocked(1);
            ncNodeService.updateById(curedProgramPackage);
         }
      }*/
      if(task.getTaskDefinitionKey().equals("approveTask") && FlowContants.Y.equals(operateResult)) {
         //试切流程,或者 偏离流程 高师通过的时候创建节点
         //createProgramNodes(processInstanceId);
      }
      variables.remove(FlowContants.PROCESS_EDITION);//不要升版了
      //if(!"confirmIsUseableTask".equals(task.getTaskDefinitionKey())){
      if("confirmIsUseableTask".equals(task.getTaskDefinitionKey())){
         //工序版次不一致,并且审核通过(可用)是,才更新为新的versionNumber
         FlowProgramProperties progProperties = flowCommonService.getProgramProperties(processInstanceId);
         variables.put(FlowContants.CURE_PROGRAM_USEABLE,operateResult);
         if(FlowContants.Y.equals(operateResult) && FlowContants.N.equals(progProperties.getIsProcessEditionSame())) {
            //确认程序可用 且 工序版次不一致,进入校对。这里需要升级程序的版本号
            Long curedNodeId = progProperties.getCuredNodeId();
            ncNodeService.upgradeVersionNumber(curedNodeId);
         }
      }
      taskService.complete(taskId, variables);
   }
}