| | |
| | | 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.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | |
| | | 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.AbstractFlowCompleteService; |
| | | import org.springblade.mdm.flow.service.execute.DefaultFlowCompleteService; |
| | | import org.springblade.mdm.flow.service.execute.TryFlowCompleteService; |
| | | import org.springblade.mdm.flow.vo.TaskAssignVO; |
| | | import org.springblade.mdm.program.entity.ProcessProgRef; |
| | | import org.springblade.mdm.program.service.NcNodeAutoCreateService; |
| | |
| | | private final ProcessProgRefService processProgRefService; |
| | | |
| | | private final ApproveRecordService approveRecordService; |
| | | private final FlowCommonService flowCommonService; |
| | | |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | |
| | | private final NcNodeAutoCreateService ncNodeAutoCreateService; |
| | | |
| | | private final TryFlowCompleteService tryFlowCompleteService; |
| | | private final DefaultFlowCompleteService defaultFlowCompleteService; |
| | | private final TaskDispatchService taskDispatchService; |
| | | /** |
| | | * 发起派工流程 |
| | | */ |
| | | @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).singleResult(); |
| | | if(inst.getProcessDefinitionKey().equals(FlowContants.TRY_PROCESS_KEY) || inst.getProcessDefinitionKey().equals(FlowContants.CURE_PROCESS_KEY)){ |
| | | return tryFlowCompleteService; |
| | | }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) { |
| | | |
| | | try { |
| | | AbstractFlowCompleteService completeService = getActualService(processInstanceId); |
| | | completeService.completeTask(taskId, processInstanceId, comment, variables); |
| | | return R.success("流程提交成功"); |
| | | }catch(Exception e){ |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | /* |
| | | Task task = taskService.createTaskQuery() |
| | | .taskId(taskId) |
| | | .singleResult(); |
| | |
| | | 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)); |
| | | } |
| | | */ |
| | | |
| | | //加入审批用户 |
| | | variables.put("approveUserNickName",AuthUtil.getNickName()); |
| | | variables.put(FlowContants.LAST_STEP_USER_NICKNAME,AuthUtil.getNickName()); |
| | | |
| | | if(variables.containsKey("assignee")){ |
| | | addApproveRecord(taskId,processInstanceId,comment,variables); |
| | | //指定了下一步执行人 |
| | | taskService.complete(taskId, variables); |
| | | addApproveRecord(taskId,comment,variables); |
| | | |
| | | //在编制任务时,创建节点(没有节点则创建,有就直接使用 |
| | | if(task.getTaskDefinitionKey().equals("programmingTask") && "Y".equals(operateResult)) { |
| | | ncNodeAutoCreateService.createNodeTree(processInstanceId); |
| | | ncNodeAutoCreateService.createNodeTreeWithProgram(flowCommonService.getProgramProperties(processInstanceId)); |
| | | } |
| | | if(!"confirmIsUseableTask".equals(task.getTaskDefinitionKey())){ |
| | | |
| | | variables.remove(FlowContants.PROCESS_EDITION);//TODO 临时错误是,组长提交的时候会提交一个空串,清空了内部数据 |
| | | }else{ |
| | | //升版 |
| | | |
| | | } |
| | | |
| | | //指定了下一步执行人 |
| | | taskService.complete(taskId, variables); |
| | | |
| | | return R.success("流程提交成功"); |
| | | }else { |
| | | // 完成任务,给默认用户 |
| | | return R.fail("请指定流程下一步处理人"); |
| | | } |
| | | }*/ |
| | | |
| | | |
| | | } |
| | | |
| | | void addApproveRecord(String taskId, String processInstanceId, String comment,Map<String, Object> variables){ |
| | | 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); |
| | | |
| | | } |
| | | } |