yangys
2025-09-06 a5f944c2bc0107e5df936937f1c33e5e03eb8fed
blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/execute/TryFlowCompleteService.java
@@ -8,14 +8,18 @@
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.mdm.basesetting.machine.entity.Machine;
import org.springblade.mdm.basesetting.machine.service.MachineService;
import org.springblade.mdm.commons.service.ParamService;
import org.springblade.mdm.commons.service.UserCommonService;
import org.springblade.mdm.flow.constants.FlowContants;
import org.springblade.mdm.flow.constants.FlowVariableContants;
import org.springblade.mdm.flow.service.FlowCommonService;
import org.springblade.mdm.flow.service.FlowProgramFileService;
import org.springblade.mdm.program.entity.NcNode;
import org.springblade.mdm.program.service.NcNodeAutoCreateService;
import org.springblade.mdm.program.service.NcNodeService;
import org.springblade.mdm.flow.service.FlowProgramProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
@@ -26,65 +30,79 @@
public class TryFlowCompleteService extends AbstractFlowCompleteService {
   @Autowired
   private FlowProgramFileService flowProgramFileService;
   @Autowired
   private NcNodeService ncNodeService;
   @Autowired
   private NcNodeAutoCreateService ncNodeAutoCreateService;
   private ParamService paramService;
   @Autowired
   private FlowCommonService flowCommonService;
   @Autowired
   private UserCommonService userCommonService;
   @Autowired
   private MachineService machineService;
   @Transactional
   @Override
   public void completeTask(String taskId, String processInstanceId, String comment, Map<String, Object> variables) {
      Task task = currentTask(taskId);
      String operateResult = this.getApproveResult(variables);
      if(task.getTaskDefinitionKey().equals("programmingTask")) {//编制节点
         flowProgramFileService.checkProgramFiles(processInstanceId,"Y".equals(operateResult));
      FlowProgramProperties props = flowCommonService.getProgramProperties(processInstanceId);
      if(!variables.containsKey("assignee")) {
         throw new ServiceException("请指定流程下一步处理人");
      }
      if (StringUtil.isNoneBlank(processInstanceId, comment)) {
         taskService.addComment(taskId, processInstanceId, comment);
      }
      // 非空判断
      if (Func.isEmpty(variables)) {
         variables = Kv.create();
      }
      if(task.getTaskDefinitionKey().equals("programmingTask") ) {//编制节点
         //记录实际编程员
         variables.put(FlowVariableContants.ACT_PROGRAMMER,Func.toStr(AuthUtil.getUserId()));
         if(this.needUploadProgramFile(props.getMachineCode())) {
            flowProgramFileService.checkProgramFiles(processInstanceId, FlowContants.Y.equals(operateResult));
         }
      }else if(task.getTaskDefinitionKey().equals("teamLeaderTask")){
         if(FlowContants.Y.equals(operateResult)) {
            runtimeService.setVariable(task.getExecutionId(),FlowContants.PROGRAMMER_NAME,userCommonService.getUserNameById(Func.toLong(variables.get("assignee"))));
         }
      }
      if (StringUtil.isNoneBlank(processInstanceId, comment)) {
         taskService.addComment(taskId, processInstanceId, comment);
      }
      variables.put(FlowContants.LAST_STEP_USER_NICKNAME, AuthUtil.getNickName());
      if(!variables.containsKey("assignee")) {
         throw new ServiceException("请指定流程下一步处理人");
      }
      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);
      variables.remove(FlowContants.PROCESS_EDITION);//不要升版了
            //创建程序树
            //节点在试切下还是固化下面?确认了,节点建立在试切下,最终走固化流程后才进入固化
            //确认程序可用了,进入校对。这里直接建立节点,因为可能不走编程节点了
            this.ncNodeAutoCreateService.createNodeTreeWithProgram(flowCommonService.getProgramProperties(processInstanceId));
         }else{
            //工序版次一致,但是拒绝了,后续会进入编制节点
            variables.remove(FlowContants.PROCESS_EDITION);
      if("confirmIsUseableTask".equals(task.getTaskDefinitionKey())){
         variables.put(FlowContants.CURE_PROGRAM_USEABLE,operateResult);
         if(FlowContants.Y.equals(operateResult)) {
            //判定可用,记录为实际编程员
            variables.put(FlowVariableContants.ACT_PROGRAMMER,Func.toStr(AuthUtil.getUserId()));
         }
      }
      taskService.complete(taskId, variables);
   }
   /**
    * 是否需要上传文件(车床不需要)
    * @param machineCode 机床编码
    * @return 是否需要上传
    */
   boolean needUploadProgramFile(String machineCode){
      boolean need;
      Machine machine = machineService.getByCode(machineCode);
      String turning = paramService.turninngValue();
      need = !StringUtils.equals(turning,machine.getMachineSpec());
      return need;
   }
}