yangys
2025-09-18 0d61b9bfca526e9c3da2209de8f9f367e76fd013
blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/execute/BatchDispatchService.java
@@ -6,12 +6,13 @@
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.secure.utils.AuthUtil;
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.commons.service.UserCommonService;
import org.springblade.mdm.flow.constants.FlowContants;
import org.springblade.mdm.flow.constants.FlowVariableContants;
import org.springblade.mdm.flow.constants.FlowConstant;
import org.springblade.mdm.flow.constants.FlowVariableConstant;
import org.springblade.mdm.flow.service.FlowCommonService;
import org.springblade.mdm.flow.vo.BatchDispatchVO;
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,7 +44,7 @@
      Map<String, Object> variables = Kv.create();
      variables.put("assignee", batchDispatchVO.getAssignee());
      variables.put("approve", FlowContants.Y);//默认就是通过
      variables.put("approve", FlowConstant.Y);//默认就是通过
      String taskId;
      String processInstanceId;
      String comment = batchDispatchVO.getComment();
@@ -52,7 +53,7 @@
         taskId = taskIds[i];
         processInstanceId = batchDispatchVO.getProcessInstanceIds()[i];
         runtimeService.setVariable(processInstanceId,FlowContants.PROGRAMMER_NAME,userCommonService.getUserNameById(Func.toLong(batchDispatchVO.getAssignee())));
         runtimeService.setVariable(processInstanceId, FlowConstant.PROGRAMMER_NAME,userCommonService.getUserNameById(Func.toLong(batchDispatchVO.getAssignee())));
         Task task = getTask(taskId);
@@ -81,8 +82,8 @@
      Map<String, Object> variables = Kv.create();
      //variables.put("assignee", batchDispatchVO.getAssignee());
      variables.put("approve", FlowContants.Y);//自动分派默认就是通过
      variables.put(FlowVariableContants.COMMENT,batchDispatchVO.getComment());
      variables.put("approve", FlowConstant.Y);//自动分派默认就是通过
      variables.put(FlowVariableConstant.COMMENT,batchDispatchVO.getComment());
      ProcessInstance processInstance;
      Object programmer;
      for(int i=0;i<taskIds.length;i++) {
@@ -97,7 +98,7 @@
         Object programmerId = getAutoProgrammer(processInstanceId);
         variables.put("assignee", programmerId);
         runtimeService.setVariable(processInstanceId,FlowContants.PROGRAMMER_NAME,userCommonService.getUserNameById(Func.toLong(programmerId)));
         runtimeService.setVariable(processInstanceId, FlowConstant.PROGRAMMER_NAME,userCommonService.getUserNameById(Func.toLong(programmerId)));
         if (StringUtil.isNoneBlank(processInstanceId, batchDispatchVO.getComment())) {
@@ -124,9 +125,9 @@
      ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
         .processInstanceId(processInstanceId)
         .singleResult();
      Object programmer = processInstance.getProcessVariables().get(FlowContants.PROGRAMMER);
      Object programmer = processInstance.getProcessVariables().get(FlowVariableConstant.PROGRAMMER);
      if(programmer == null){
         throw new ServiceException(processInstance.getProcessVariables().get(FlowContants.TITLE)+":未找到编程人员");
         throw new ServiceException(processInstance.getProcessVariables().get(FlowVariableConstant.TITLE)+":未找到编程人员");
      }
      return programmer;
   }
@@ -144,8 +145,8 @@
      //审批结果和处理人都一样的
      Map<String, Object> variables = Kv.create();
      variables.put(FlowVariableContants.APPROVE, batchDispatchVO.getApprove());
      variables.put(FlowVariableContants.COMMENT, batchDispatchVO.getComment());
      variables.put(FlowVariableConstant.APPROVE, batchDispatchVO.getApprove());
      variables.put(FlowVariableConstant.COMMENT, batchDispatchVO.getComment());
      for(int i=0;i<taskIds.length;i++) {
         taskId = taskIds[i];
@@ -156,11 +157,10 @@
         if (StringUtil.isNoneBlank(processInstanceId, batchDispatchVO.getComment())) {
            taskService.addComment(taskId, processInstanceId, batchDispatchVO.getComment());
         }
         if(FlowContants.N.equals(batchDispatchVO.getApprove())) {
         if(FlowConstant.N.equals(batchDispatchVO.getApprove())) {
            //驳回,查询实际编程人员 驳回
            variables.put(FlowVariableContants.ASSIGNEE, getActualProgrammer(processInstanceId));
            variables.put(FlowVariableConstant.ASSIGNEE, getActualProgrammer(processInstanceId));
         }
         //approveRecordService.saveApproveRecords(task,FlowContants.Y,batchDispatchVO.getComment());
         taskService.complete(taskId, variables);
      }
@@ -175,9 +175,9 @@
      ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables()
         .processInstanceId(processInstanceId)
         .singleResult();
      Object actProgrammer = processInstance.getProcessVariables().get(FlowVariableContants.ACT_PROGRAMMER);
      Object actProgrammer = processInstance.getProcessVariables().get(FlowVariableConstant.ACT_PROGRAMMER);
      if(actProgrammer == null){
         throw new ServiceException(processInstance.getProcessVariables().get(FlowContants.TITLE)+":未找到编程人员");
         throw new ServiceException(processInstance.getProcessVariables().get(FlowVariableConstant.TITLE)+":未找到编程人员");
      }
      return actProgrammer;
   }
@@ -198,4 +198,37 @@
         throw new ServiceException("任务id与流程实例id数量不一致");
      }
   }
   /**
    * 排练通过现场编制
    * @param batchDispatchVO
    */
    public void batchProgramOnMachine(BatchDispatchVO batchDispatchVO) {
      checkBatchParameter(batchDispatchVO);
      String[] taskIds = batchDispatchVO.getTaskIds();
      String taskId;
      String processInstanceId;
      //审批结果和处理人都一样的
      Map<String, Object> variables = Kv.create();
      variables.put(FlowVariableConstant.APPROVE, FlowConstant.Y);
      variables.put(FlowVariableConstant.COMMENT, batchDispatchVO.getComment());
      variables.put(FlowVariableConstant.PROGRAM_ON_MACHINE, FlowConstant.Y);//现场编制:是
      variables.put(FlowVariableConstant.ACT_PROGRAMMER, AuthUtil.getUserId()+"");//实际编制
      variables.put(FlowVariableConstant.ASSIGNEE,batchDispatchVO.getAssignee());
      for(int i=0;i<taskIds.length;i++) {
         taskId = taskIds[i];
         processInstanceId = batchDispatchVO.getProcessInstanceIds()[i];
         Task task = getTask(taskId);
         if(!task.getTaskDefinitionKey().equals("programmingTask")){
            throw new ServiceException("非编制任务,不能指定现场编制");
         }
         if (StringUtil.isNoneBlank(processInstanceId, batchDispatchVO.getComment())) {
            taskService.addComment(taskId, processInstanceId, batchDispatchVO.getComment());
         }
         taskService.complete(taskId, variables);
      }
    }
}