From 547de0f2d2e8c2d09a114f7b217a277049219bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Wed, 24 Apr 2024 17:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E5=8D=8F=E5=90=8C=E5=8A=9E?= =?UTF-8?q?=E5=85=AC=E6=88=91=E7=9A=84=E5=B7=B2=E5=8A=9E=E5=9B=9E=E6=98=BE?= =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/EngineTaskController.java | 189 +++++++++--------- 1 file changed, 100 insertions(+), 89 deletions(-) diff --git a/pigx-flow/pigx-flow-engine/pigx-flow-engine-biz/src/main/java/com/pig4cloud/pigx/flow/engine/controller/EngineTaskController.java b/pigx-flow/pigx-flow-engine/pigx-flow-engine-biz/src/main/java/com/pig4cloud/pigx/flow/engine/controller/EngineTaskController.java index 4132b9167..470ba04df 100644 --- a/pigx-flow/pigx-flow-engine/pigx-flow-engine-biz/src/main/java/com/pig4cloud/pigx/flow/engine/controller/EngineTaskController.java +++ b/pigx-flow/pigx-flow-engine/pigx-flow-engine-biz/src/main/java/com/pig4cloud/pigx/flow/engine/controller/EngineTaskController.java @@ -16,6 +16,7 @@ import org.flowable.task.api.DelegationState; import org.flowable.task.api.Task; import org.flowable.task.api.TaskQuery; import org.flowable.task.api.history.HistoricTaskInstance; +import org.flowable.variable.api.history.HistoricVariableInstance; import org.springframework.web.bind.annotation.*; import java.util.HashMap; @@ -32,115 +33,125 @@ import java.util.Optional; @RequestMapping("/task") public class EngineTaskController { - private final TaskService taskService; + private final TaskService taskService; - private final HistoryService historyService; + private final HistoryService historyService; - private final RuntimeService runtimeService; + private final RuntimeService runtimeService; - /** - * 查询任务变量 - * @param paramDto 参数DTO - * @return 变量Map - */ - @PostMapping("queryTaskVariables") - public R queryTaskVariables(@RequestBody VariableQueryParamDto paramDto) { + /** + * 查询任务变量 + * + * @param paramDto 参数DTO + * @return 变量Map + */ + @PostMapping("queryTaskVariables") + public R queryTaskVariables(@RequestBody VariableQueryParamDto paramDto) { - List keyList = paramDto.getKeyList(); - if (CollUtil.isEmpty(keyList)) { - TaskQuery taskQuery = taskService.createTaskQuery(); + List keyList = paramDto.getKeyList(); + if (CollUtil.isEmpty(keyList)) { + TaskQuery taskQuery = taskService.createTaskQuery(); - Task task = taskQuery.taskId(paramDto.getTaskId()).singleResult(); - if (task == null) { - return R.failed("任务不存在"); - } + Task task = taskQuery.taskId(paramDto.getTaskId()).singleResult(); + if (task == null) { + return R.failed("任务不存在"); + } - Map variables = runtimeService.getVariables(task.getExecutionId()); + Map variables = runtimeService.getVariables(task.getExecutionId()); - return R.ok(variables); - } + return R.ok(variables); + } - Map variables = taskService.getVariables(paramDto.getTaskId(), keyList); - return R.ok(variables); + Map variables = taskService.getVariables(paramDto.getTaskId(), keyList); + return R.ok(variables); - } + } - /** - * 查询任务详情 - * @param taskId 任务ID - * @param userId 用户ID - * @return 任务结果DTO - */ - @GetMapping("/engine/queryTask") - public R queryTask(String taskId, String userId) { - Optional task = Optional - .ofNullable(taskService.createTaskQuery().taskId(taskId).taskAssignee(userId).singleResult()); + /** + * 查询任务详情 + * + * @param taskId 任务ID + * @param userId 用户ID + * @return 任务结果DTO + */ + @GetMapping("/engine/queryTask") + public R queryTask(String taskId, String userId) { + Optional task = Optional + .ofNullable(taskService.createTaskQuery().taskId(taskId).taskAssignee(userId).singleResult()); - if (task.isPresent()) { - String processDefinitionId = task.get().getProcessDefinitionId(); - String taskDefinitionKey = task.get().getTaskDefinitionKey(); - DelegationState delegationState = task.get().getDelegationState(); - String processInstanceId = task.get().getProcessInstanceId(); - Object delegateVariable = taskService.getVariableLocal(taskId, "delegate"); + if (task.isPresent()) { + String processDefinitionId = task.get().getProcessDefinitionId(); + String taskDefinitionKey = task.get().getTaskDefinitionKey(); + DelegationState delegationState = task.get().getDelegationState(); + String processInstanceId = task.get().getProcessInstanceId(); + Object delegateVariable = taskService.getVariableLocal(taskId, "delegate"); - String flowId = NodeUtil.getFlowId(processDefinitionId); - Map variables = taskService.getVariables(taskId); - Map variableAll = new HashMap<>(variables); + String flowId = NodeUtil.getFlowId(processDefinitionId); + Map variables = taskService.getVariables(taskId); + Map variableAll = new HashMap<>(variables); - TaskResultDto taskResultDto = new TaskResultDto(); - taskResultDto.setFlowId(flowId); - taskResultDto.setProcessInstanceId(processDefinitionId); - taskResultDto.setNodeId(taskDefinitionKey); - taskResultDto.setCurrentTask(true); - taskResultDto.setDelegate(Convert.toBool(delegateVariable, false)); - taskResultDto.setVariableAll(variableAll); - taskResultDto.setProcessInstanceId(processInstanceId); - taskResultDto.setDelegationState(delegationState == null ? null : delegationState.toString()); + TaskResultDto taskResultDto = new TaskResultDto(); + taskResultDto.setFlowId(flowId); + taskResultDto.setProcessInstanceId(processDefinitionId); + taskResultDto.setNodeId(taskDefinitionKey); + taskResultDto.setCurrentTask(true); + taskResultDto.setDelegate(Convert.toBool(delegateVariable, false)); + taskResultDto.setVariableAll(variableAll); + taskResultDto.setProcessInstanceId(processInstanceId); + taskResultDto.setDelegationState(delegationState == null ? null : delegationState.toString()); - return R.ok(taskResultDto); - } - else { - Optional historicTaskInstance = Optional.ofNullable(historyService - .createHistoricTaskInstanceQuery().taskId(taskId).taskAssignee(userId).singleResult()); + return R.ok(taskResultDto); + } else { + Optional historicTaskInstance = Optional + .ofNullable(historyService.createHistoricTaskInstanceQuery() + .taskId(taskId) + .taskAssignee(userId) + .singleResult()); - if (historicTaskInstance.isPresent()) { - String processDefinitionId = historicTaskInstance.get().getProcessDefinitionId(); - String taskDefinitionKey = historicTaskInstance.get().getTaskDefinitionKey(); - String processInstanceId = historicTaskInstance.get().getProcessInstanceId(); + if (historicTaskInstance.isPresent()) { + String processDefinitionId = historicTaskInstance.get().getProcessDefinitionId(); + String taskDefinitionKey = historicTaskInstance.get().getTaskDefinitionKey(); + String processInstanceId = historicTaskInstance.get().getProcessInstanceId(); - String flowId = NodeUtil.getFlowId(processDefinitionId); - Map variableAll = new HashMap<>(); + String flowId = NodeUtil.getFlowId(processDefinitionId); - TaskResultDto taskResultDto = new TaskResultDto(); - taskResultDto.setFlowId(flowId); - taskResultDto.setNodeId(taskDefinitionKey); - taskResultDto.setCurrentTask(false); - taskResultDto.setVariableAll(variableAll); - taskResultDto.setProcessInstanceId(processInstanceId); + List variableInstanceList = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list(); + Map variableAll = new HashMap<>(); - return R.ok(taskResultDto); - } - else { - return R.failed("任务不存在"); - } - } - } + if (CollUtil.isNotEmpty(variableInstanceList)) { + variableInstanceList.forEach(historicVariableInstance -> variableAll.put(historicVariableInstance.getVariableName(), historicVariableInstance.getValue())); + } - /** - * 完成任务 - * @param taskParamDto 任务参数DTO - * @return 操作结果 - */ - @PostMapping("/complete") - public R complete(@RequestBody TaskParamDto taskParamDto) { - Map taskLocalParamMap = taskParamDto.getTaskLocalParamMap(); - if (CollUtil.isNotEmpty(taskLocalParamMap)) { - taskService.setVariablesLocal(taskParamDto.getTaskId(), taskLocalParamMap); - } + TaskResultDto taskResultDto = new TaskResultDto(); + taskResultDto.setFlowId(flowId); + taskResultDto.setNodeId(taskDefinitionKey); + taskResultDto.setCurrentTask(false); + taskResultDto.setVariableAll(variableAll); + taskResultDto.setProcessInstanceId(processInstanceId); - taskService.complete(taskParamDto.getTaskId(), taskParamDto.getParamMap()); + return R.ok(taskResultDto); + } else { + return R.failed("任务不存在"); + } + } + } - return R.ok(); - } + /** + * 完成任务 + * + * @param taskParamDto 任务参数DTO + * @return 操作结果 + */ + @PostMapping("/complete") + public R complete(@RequestBody TaskParamDto taskParamDto) { + Map taskLocalParamMap = taskParamDto.getTaskLocalParamMap(); + if (CollUtil.isNotEmpty(taskLocalParamMap)) { + taskService.setVariablesLocal(taskParamDto.getTaskId(), taskLocalParamMap); + } + + taskService.complete(taskParamDto.getTaskId(), taskParamDto.getParamMap()); + + return R.ok(); + } }