| | |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.SerializationException; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.flowable.engine.TaskService; |
| | | 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.api.R; |
| | | import org.springblade.core.tool.support.Kv; |
| | |
| | | import org.springblade.mdm.flow.excution.StartDispatcher; |
| | | import org.springblade.mdm.flow.service.ApproveRecordService; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | | import org.springblade.mdm.flow.service.FlowProgramFileService; |
| | | import org.springblade.mdm.flow.service.TaskDispatchService; |
| | | import org.springblade.mdm.flow.service.execute.*; |
| | | import org.springblade.mdm.flow.vo.BatchDispatchVO; |
| | | import org.springblade.mdm.flow.vo.TaskAssignVO; |
| | | import org.springblade.mdm.program.entity.ProcessProgRef; |
| | | import org.springblade.mdm.program.service.NcNodeAutoCreateService; |
| | | import org.springblade.mdm.program.service.ProcessProgRefService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | |
| | | private final TaskService taskService; |
| | | private final RuntimeService runtimeService; |
| | | private final ProcessProgRefService processProgRefService; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | |
| | | private ApproveRecordService approveRecordService; |
| | | private final FlowCommonService flowCommonService; |
| | | |
| | | private final TryFlowCompleteService tryFlowCompleteService; |
| | | private final DefaultFlowCompleteService defaultFlowCompleteService; |
| | | private final TaskDispatchService taskDispatchService; |
| | | private final BatchDispatchService dispatchService; |
| | | private final ReplaceFlowCompleteService replaceFlowCompleteService; |
| | | private final TempFlowCompleteService tempFlowCompleteService; |
| | | /** |
| | | * 新增 |
| | | * 发起派工流程 |
| | | */ |
| | | @PostMapping("/start") |
| | | @Operation(summary = "任务计划(派工流程)", description = "启动派工流程") |
| | | public R<Boolean> start(@RequestBody TaskAssignVO startVO) { |
| | | dispatcher.start(startVO); |
| | | return R.status(true); |
| | | try { |
| | | long id= taskDispatchService.saveTask(startVO); |
| | | String instId = dispatcher.start(startVO); |
| | | taskDispatchService.updateSuccess(id,instId); |
| | | return R.data(true); |
| | | }catch(Exception e){ |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | AbstractFlowCompleteService getActualService(String processInstanceId){ |
| | | ProcessInstance inst = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).includeProcessVariables().singleResult(); |
| | | if(inst.getProcessDefinitionKey().equals(FlowContants.TRY_PROCESS_KEY) || inst.getProcessDefinitionKey().equals(FlowContants.CURE_PROCESS_KEY) |
| | | || inst.getProcessDefinitionKey().equals(FlowContants.UNLOCK_PROCESS_KEY)){ |
| | | String isTempFlow = Func.toStr(inst.getProcessVariables().get(FlowContants.IS_TEMP_FLOW)); |
| | | if(FlowContants.N.equals(isTempFlow)){ |
| | | return tryFlowCompleteService; |
| | | }else{ |
| | | return tempFlowCompleteService; |
| | | } |
| | | }else if(inst.getProcessDefinitionKey().equals(FlowContants.REPLACE_PROCESS_KEY)){ |
| | | return replaceFlowCompleteService; |
| | | }else{ |
| | | return defaultFlowCompleteService; |
| | | } |
| | | } |
| | | @Operation(summary = "完成任务", description = "流向下一个节点") |
| | | @PostMapping("completeTask") |
| | | public R<Void> completeTask(String taskId, String processInstanceId, String comment,@Parameter(name = "variables", description = "任务变量") @RequestBody Map<String, Object> variables) { |
| | | // 增加评论 |
| | | if (StringUtil.isNoneBlank(processInstanceId, comment)) { |
| | | taskService.addComment(taskId, processInstanceId, comment); |
| | | } |
| | | // 非空判断 |
| | | if (Func.isEmpty(variables)) { |
| | | variables = Kv.create(); |
| | | } |
| | | String programIds = null; |
| | | if(variables.containsKey(FlowContants.PROGRAM_IDS_KEY)){ |
| | | programIds = variables.get("programIds").toString(); |
| | | runtimeService.setVariable(taskId, FlowContants.PROGRAM_IDS_KEY, programIds); |
| | | } |
| | | if(StringUtils.isNotEmpty(programIds)) { |
| | | processProgRefService.addRelations(processInstanceId,Func.toLongList(programIds)); |
| | | } |
| | | try { |
| | | AbstractFlowCompleteService completeService = getActualService(processInstanceId); |
| | | completeService.completeTask(taskId, processInstanceId, comment, variables); |
| | | |
| | | //加入审批用户 |
| | | variables.put("approveUserNickName",AuthUtil.getNickName()); |
| | | |
| | | if(variables.containsKey("assignee")){ |
| | | |
| | | addApproveRecord(taskId,processInstanceId,comment,variables); |
| | | //指定了下一步执行人 |
| | | taskService.complete(taskId, variables); |
| | | |
| | | return R.success("流程提交成功"); |
| | | }else { |
| | | // 完成任务,给默认用户 |
| | | return R.fail("请指定流程下一步处理人"); |
| | | }catch(Exception e){ |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Operation(summary = "手动批量派工", description = "组长手动批量派工") |
| | | @PostMapping("batchDispatch") |
| | | public R<Void> batchDispatch(@RequestBody BatchDispatchVO batchDispatchVO) { |
| | | try { |
| | | dispatchService.batchDispatchTask(batchDispatchVO); |
| | | return R.success("流程提交成功"); |
| | | }catch(Exception e){ |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | void addApproveRecord(String taskId, String processInstanceId, String comment,Map<String, Object> variables){ |
| | | @Operation(summary = "自动批量派工", description = "组长批量派工,后端自动查找处理人") |
| | | @PostMapping("batchDispatchAuto") |
| | | public R<Void> batchDispatchAuto(@RequestBody BatchDispatchVO batchDispatchVO) { |
| | | try { |
| | | dispatchService.batchAutoDispatchTask(batchDispatchVO); |
| | | return R.success("流程提交成功"); |
| | | }catch(Exception e){ |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Operation(summary = "批量审批", description = "高师批量审批") |
| | | @PostMapping("batchApprove") |
| | | public R<Void> batchApprove(@RequestBody BatchDispatchVO batchDispatchVO) { |
| | | try { |
| | | dispatchService.batchApprove(batchDispatchVO); |
| | | return R.success("流程提交成功"); |
| | | }catch(Exception e){ |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | /* |
| | | void addApproveRecord(String taskId,String comment,Map<String, Object> variables){ |
| | | String operateResult = variables.get("approve")+""; |
| | | |
| | | Task task = taskService.createTaskQuery() |
| | | .taskId(taskId) |
| | | .singleResult(); |
| | | approveRecordService.saveApproveRecords(task,processInstanceId,operateResult,comment); |
| | | approveRecordService.saveApproveRecords(task,operateResult,comment); |
| | | |
| | | } |
| | | }*/ |
| | | } |