From b4e1e32d207b61da05d738c68494daa4fc7f18c7 Mon Sep 17 00:00:00 2001 From: gssong <1742057357@qq.com> Date: 星期六, 09 三月 2024 13:40:41 +0800 Subject: [PATCH] add 添加查询流程变量接口 --- ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java | 37 ++++++++++++++++++++++++++++--------- 1 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java index 700dab5..8890279 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActTaskServiceImpl.java @@ -23,6 +23,7 @@ import org.dromara.workflow.domain.bo.*; import org.dromara.workflow.domain.vo.MultiInstanceVo; import org.dromara.workflow.domain.vo.TaskVo; +import org.dromara.workflow.domain.vo.VariableVo; import org.dromara.workflow.domain.vo.WfCopy; import org.dromara.workflow.flowable.cmd.*; import org.dromara.workflow.flowable.strategy.FlowEventStrategy; @@ -46,6 +47,7 @@ import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.api.history.HistoricTaskInstanceQuery; import org.flowable.task.service.impl.persistence.entity.TaskEntity; +import org.flowable.variable.api.persistence.entity.VariableInstance; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -53,8 +55,7 @@ import java.util.*; import java.util.stream.Collectors; -import static org.dromara.workflow.common.constant.FlowConstant.FLOWABLE_SKIP_EXPRESSION_ENABLED; -import static org.dromara.workflow.common.constant.FlowConstant.INITIATOR; +import static org.dromara.workflow.common.constant.FlowConstant.*; /** * 浠诲姟 鏈嶅姟灞傚疄鐜� @@ -96,7 +97,7 @@ if (CollUtil.isNotEmpty(startProcessBo.getVariables())) { taskService.setVariables(taskResult.get(0).getId(), startProcessBo.getVariables()); } - map.put("processInstanceId", taskResult.get(0).getProcessInstanceId()); + map.put(PROCESS_INSTANCE_ID, taskResult.get(0).getProcessInstanceId()); map.put("taskId", taskResult.get(0).getId()); return map; } @@ -129,7 +130,8 @@ runtimeService.updateBusinessStatus(pi.getProcessInstanceId(), BusinessStatusEnum.DRAFT.getStatus()); taskService.setAssignee(taskList.get(0).getId(), LoginHelper.getUserId().toString()); - taskService.setVariable(taskList.get(0).getId(), "processInstanceId", pi.getProcessInstanceId()); + taskService.setVariable(taskList.get(0).getId(), PROCESS_INSTANCE_ID, pi.getProcessInstanceId()); + taskService.setVariable(taskList.get(0).getId(), BUSINESS_KEY, pi.getBusinessKey()); map.put("processInstanceId", pi.getProcessInstanceId()); map.put("taskId", taskList.get(0).getId()); return map; @@ -473,7 +475,7 @@ throw new ServiceException(FlowConstant.MESSAGE_SUSPENDED); } HistoricProcessInstance historicProcessInstance = QueryUtils.hisInstanceQuery() - .processInstanceBusinessKey(task.getProcessInstanceId()).singleResult(); + .processInstanceId(task.getProcessInstanceId()).singleResult(); BusinessStatusEnum.checkInvalidStatus(historicProcessInstance.getBusinessStatus()); try { if (StringUtils.isBlank(terminationBo.getComment())) { @@ -488,9 +490,9 @@ if (CollectionUtil.isNotEmpty(subTasks)) { subTasks.forEach(e -> taskService.deleteTask(e.getId())); } + runtimeService.updateBusinessStatus(task.getProcessInstanceId(), BusinessStatusEnum.TERMINATION.getStatus()); runtimeService.deleteProcessInstance(task.getProcessInstanceId(), StrUtil.EMPTY); } - runtimeService.updateBusinessStatus(task.getProcessInstanceId(), BusinessStatusEnum.TERMINATION.getStatus()); FlowProcessEventHandler processHandler = flowEventStrategy.getProcessHandler(historicProcessInstance.getProcessDefinitionKey()); if (processHandler != null) { processHandler.handleProcess(historicProcessInstance.getBusinessKey(), BusinessStatusEnum.TERMINATION.getStatus(), false); @@ -649,9 +651,6 @@ ExecutionChildByExecutionIdCmd childByExecutionIdCmd = new ExecutionChildByExecutionIdCmd(task.getExecutionId()); List<ExecutionEntity> executionEntities = managementService.executeCommand(childByExecutionIdCmd); //鏍¢獙鍗曟嵁 - if (BusinessStatusEnum.BACK.getStatus().equals(processInstance.getBusinessStatus())) { - throw new ServiceException("璇ュ崟鎹凡閫�鍥烇紒"); - } BusinessStatusEnum.checkBackStatus(processInstance.getBusinessStatus()); //鍒ゆ柇鏄惁鏈夊涓换鍔� List<Task> taskList = QueryUtils.taskQuery(processInstanceId).list(); @@ -708,4 +707,24 @@ } return true; } + + /** + * 鏌ヨ娴佺▼鍙橀噺 + * + * @param taskId 浠诲姟id + */ + @Override + public List<VariableVo> getInstanceVariable(String taskId) { + List<VariableVo> variableVoList = new ArrayList<>(); + Map<String, VariableInstance> variableInstances = taskService.getVariableInstances(taskId); + if (CollectionUtil.isNotEmpty(variableInstances)) { + for (Map.Entry<String, VariableInstance> entry : variableInstances.entrySet()) { + VariableVo variableVo = new VariableVo(); + variableVo.setKey(entry.getKey()); + variableVo.setValue(entry.getValue().getValue().toString()); + variableVoList.add(variableVo); + } + } + return variableVoList; + } } -- Gitblit v1.9.3