| | |
| | | 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.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.constants.FlowVariableContants; |
| | | import org.springblade.mdm.flow.service.ApproveRecordService; |
| | | import org.springblade.mdm.commons.service.UserCommonService; |
| | | 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.service.FlowProgramFileService; |
| | | import org.springblade.mdm.flow.vo.BatchDispatchVO; |
| | | import org.springblade.mdm.program.service.NcNodeAutoCreateService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | */ |
| | | @Service |
| | | public class BatchDispatchService { |
| | | |
| | | @Autowired |
| | | private ApproveRecordService approveRecordService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private RuntimeService runtimeService; |
| | | @Autowired |
| | | private FlowCommonService flowCommonService; |
| | | @Autowired |
| | | private UserCommonService userCommonService; |
| | | @Transactional |
| | | public void batchDispatchTask(BatchDispatchVO batchDispatchVO) { |
| | | //String[] taskIds, String[] processInstanceIds, String comment, String assignee |
| | |
| | | |
| | | 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(); |
| | |
| | | taskId = taskIds[i]; |
| | | processInstanceId = batchDispatchVO.getProcessInstanceIds()[i]; |
| | | |
| | | runtimeService.setVariable(processInstanceId, FlowConstant.PROGRAMMER_NAME,userCommonService.getUserNameById(Func.toLong(batchDispatchVO.getAssignee()))); |
| | | |
| | | Task task = getTask(taskId); |
| | | |
| | | if(!task.getTaskDefinitionKey().equals("teamLeaderTask")){ |
| | | throw new ServiceException("非[任务分派]节点的任务不能批量派工"); |
| | | } |
| | | if (StringUtil.isNoneBlank(processInstanceId, comment)) { |
| | | taskService.addComment(taskId, processInstanceId, comment); |
| | | } |
| | | approveRecordService.saveApproveRecords(task,FlowContants.Y,comment); |
| | | |
| | | taskService.complete(taskId, variables); |
| | | } |
| | |
| | | |
| | | 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++) { |
| | | taskId = taskIds[i]; |
| | | processInstanceId = batchDispatchVO.getProcessInstanceIds()[i]; |
| | | |
| | | variables.put("assignee", getAutoProgrammer(processInstanceId)); |
| | | |
| | | Task task = getTask(taskId); |
| | | if(!task.getTaskDefinitionKey().equals("teamLeaderTask")){ |
| | | throw new ServiceException("非[任务分派]节点的任务不能批量派工"); |
| | | } |
| | | |
| | | Object programmerId = getAutoProgrammer(processInstanceId); |
| | | variables.put("assignee", programmerId); |
| | | |
| | | runtimeService.setVariable(processInstanceId, FlowConstant.PROGRAMMER_NAME,userCommonService.getUserNameById(Func.toLong(programmerId))); |
| | | |
| | | |
| | | if (StringUtil.isNoneBlank(processInstanceId, batchDispatchVO.getComment())) { |
| | | taskService.addComment(taskId, processInstanceId, batchDispatchVO.getComment()); |
| | | } |
| | | approveRecordService.saveApproveRecords(task,FlowContants.Y,batchDispatchVO.getComment()); |
| | | |
| | | //最后一步完成 |
| | | taskService.complete(taskId, variables); |
| | |
| | | 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; |
| | | } |
| | |
| | | |
| | | //审批结果和处理人都一样的 |
| | | 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]; |
| | |
| | | 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); |
| | | } |
| | |
| | | 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; |
| | | } |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |