From 4e871e02e6057a7fddf07aa02becad73dbfd2d9f Mon Sep 17 00:00:00 2001 From: Liang <545073804@qq.com> Date: 星期三, 03 四月 2024 09:05:39 +0800 Subject: [PATCH] update 优化Mapper.xml结果集定义 --- ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/utils/ModelUtils.java | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 49 insertions(+), 3 deletions(-) diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/utils/ModelUtils.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/utils/ModelUtils.java index 5f2551a..dff3e4e 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/utils/ModelUtils.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/utils/ModelUtils.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.json.utils.JsonUtils; @@ -17,7 +18,7 @@ import org.flowable.bpmn.model.*; import org.flowable.bpmn.model.Process; import org.flowable.editor.language.json.converter.BpmnJsonConverter; -import org.flowable.engine.impl.util.ProcessDefinitionUtil; +import org.flowable.engine.ProcessEngine; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; @@ -36,6 +37,8 @@ */ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ModelUtils { + + private static final ProcessEngine PROCESS_ENGINE = SpringUtils.getBean(ProcessEngine.class); public static BpmnModel xmlToBpmnModel(String xml) throws IOException { if (xml == null) { @@ -161,12 +164,43 @@ } /** + * 鑾峰彇娴佺▼鍏ㄩ儴鐢ㄦ埛鑺傜偣 + * + * @param processDefinitionId 娴佺▼瀹氫箟id + */ + public static List<UserTask> getuserTaskFlowElements(String processDefinitionId) { + BpmnModel bpmnModel = PROCESS_ENGINE.getRepositoryService().getBpmnModel(processDefinitionId); + List<UserTask> list = new ArrayList<>(); + List<Process> processes = bpmnModel.getProcesses(); + Collection<FlowElement> flowElements = processes.get(0).getFlowElements(); + buildUserTaskFlowElements(flowElements, list); + return list; + } + + /** + * 閫掑綊鑾峰彇鎵�鏈夎妭鐐� + * + * @param flowElements 鑺傜偣淇℃伅 + * @param list 闆嗗悎 + */ + private static void buildUserTaskFlowElements(Collection<FlowElement> flowElements, List<UserTask> list) { + for (FlowElement flowElement : flowElements) { + if (flowElement instanceof SubProcess) { + Collection<FlowElement> subFlowElements = ((SubProcess) flowElement).getFlowElements(); + buildUserTaskFlowElements(subFlowElements, list); + } else if (flowElement instanceof UserTask) { + list.add((UserTask) flowElement); + } + } + } + + /** * 鑾峰彇娴佺▼鍏ㄩ儴鑺傜偣 * * @param processDefinitionId 娴佺▼瀹氫箟id */ public static List<FlowElement> getFlowElements(String processDefinitionId) { - BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(processDefinitionId); + BpmnModel bpmnModel = PROCESS_ENGINE.getRepositoryService().getBpmnModel(processDefinitionId); List<FlowElement> list = new ArrayList<>(); List<Process> processes = bpmnModel.getProcesses(); Collection<FlowElement> flowElements = processes.get(0).getFlowElements(); @@ -213,9 +247,21 @@ * @param flowElementId 鑺傜偣id */ public static Map<String, List<ExtensionElement>> getExtensionElement(String processDefinitionId, String flowElementId) { - BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(processDefinitionId); + BpmnModel bpmnModel = PROCESS_ENGINE.getRepositoryService().getBpmnModel(processDefinitionId); Process process = bpmnModel.getMainProcess(); FlowElement flowElement = process.getFlowElement(flowElementId); return flowElement.getExtensionElements(); } + + /** + * 鍒ゆ柇褰撳墠鑺傜偣鏄惁涓虹敤鎴蜂换鍔� + * + * @param processDefinitionId 娴佺▼瀹氫箟id + * @param taskDefinitionKey 娴佺▼瀹氫箟id + */ + public static boolean isUserTask(String processDefinitionId, String taskDefinitionKey) { + BpmnModel bpmnModel = PROCESS_ENGINE.getRepositoryService().getBpmnModel(processDefinitionId); + FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(taskDefinitionKey); + return flowNode instanceof UserTask; + } } -- Gitblit v1.9.3