From 8caa08ac1a1c154fde468f35f01fa0e12fe56bd5 Mon Sep 17 00:00:00 2001 From: wangli <274027703@qq.com> Date: Thu, 30 Nov 2023 16:12:39 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E6=A8=A1=E6=8B=9F=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E8=80=83=E5=8B=A4=E8=A1=A5=E5=8D=A1=E7=9A=84=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B,=20=E5=90=8C=E6=97=B6=E8=B0=83=E6=95=B4JSON?= =?UTF-8?q?=20=E6=A0=BC=E5=BC=8F=E8=BD=AC=E6=8D=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/BpmnProcessInstanceCreateDTO.java | 1 + .../common/utils/BpmnJsonConverterUtil.java | 32 +- .../listener/EngineTaskEventListener.java | 19 +- .../src/main/resources/kaoqing.bpmn20.xml | 321 +++++++++++++ .../src/main/resources/kaoqing.json | 217 ++++----- .../src/main/resources/test.bpmn20.xml | 420 +++++++++--------- 6 files changed, 679 insertions(+), 331 deletions(-) create mode 100644 workflow-engine-server/src/main/resources/kaoqing.bpmn20.xml diff --git a/workflow-engine-common/src/main/java/cn/axzo/workflow/common/model/request/bpmn/process/BpmnProcessInstanceCreateDTO.java b/workflow-engine-common/src/main/java/cn/axzo/workflow/common/model/request/bpmn/process/BpmnProcessInstanceCreateDTO.java index 97148ae5a..7c888357c 100644 --- a/workflow-engine-common/src/main/java/cn/axzo/workflow/common/model/request/bpmn/process/BpmnProcessInstanceCreateDTO.java +++ b/workflow-engine-common/src/main/java/cn/axzo/workflow/common/model/request/bpmn/process/BpmnProcessInstanceCreateDTO.java @@ -61,6 +61,7 @@ public class BpmnProcessInstanceCreateDTO { @ApiModelProperty(value = "发起人信息") @Valid + @NotNull(message = "发起人不能为空") private BpmnTaskDelegateAssigner initiator; /** diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/common/utils/BpmnJsonConverterUtil.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/common/utils/BpmnJsonConverterUtil.java index e17cf2bb7..a620c8e68 100644 --- a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/common/utils/BpmnJsonConverterUtil.java +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/common/utils/BpmnJsonConverterUtil.java @@ -185,16 +185,22 @@ public final class BpmnJsonConverterUtil { mainProcess.addFlowElement(convertJsonToElement(StartEvent.class, mainProcess)); // 解析前端传入的模型设计 json - String lastNodeId = create(bpmnJsonNode, mainProcess, bpmnModel, START_EVENT_ID); + List lastNodeIds = create(bpmnJsonNode, mainProcess, bpmnModel, START_EVENT_ID); // 创建固定的结束节点 mainProcess.addFlowElement(convertJsonToElement(EndEvent.class, mainProcess)); - SequenceFlow sequenceFlow = new SequenceFlow(); - sequenceFlow.setId(id(SEQUENCE_FLOW_ID)); - sequenceFlow.setSourceRef(lastNodeId); - sequenceFlow.setTargetRef(END_EVENT_ID); - mainProcess.addFlowElement(sequenceFlow); + if (CollectionUtils.isEmpty(lastNodeIds)) { + throw new WorkflowEngineException(CONVERTOR_COMMON_ERROR, "未找到链接结束节点的节点数据"); + } + + lastNodeIds.forEach(lastNodeId -> { + SequenceFlow sequenceFlow = new SequenceFlow(); + sequenceFlow.setId(id(SEQUENCE_FLOW_ID)); + sequenceFlow.setSourceRef(lastNodeId); + sequenceFlow.setTargetRef(END_EVENT_ID); + mainProcess.addFlowElement(sequenceFlow); + }); new BpmnAutoLayout(bpmnModel).execute(); return bpmnModel; } @@ -369,7 +375,7 @@ public final class BpmnJsonConverterUtil { * @param bpmnModel 最终的 BPMN model * @return 创建的节点的 ID */ - private static String create(BpmnJsonNode bpmnJsonNode, Process mainProcess, + private static List create(BpmnJsonNode bpmnJsonNode, Process mainProcess, BpmnModel bpmnModel, String... preNodeIds) { FLAT_NODE_MAP.put(bpmnJsonNode.getId(), bpmnJsonNode); // 设置来源节点 @@ -404,7 +410,7 @@ public final class BpmnJsonConverterUtil { case NODE_TRIGGER: // 这个类型目前暂不支持 case NODE_CARBON_COPY: - // 这里可以细化, 带后续有实际场景了,再处理, 现目前只有 "抄送" 功能可能会用到 + // 这里可以细化, 待后续有实际场景了,再处理, 现目前只有 "抄送" 功能可能会用到 clz = ServiceTask.class; break; default: @@ -451,7 +457,7 @@ public final class BpmnJsonConverterUtil { } if (Objects.nonNull(branch.getChildren())) { - branchLastNodeIds.add(create(branch.getChildren(), mainProcess, bpmnModel)); + branchLastNodeIds.addAll(create(branch.getChildren(), mainProcess, bpmnModel)); } } } @@ -459,7 +465,11 @@ public final class BpmnJsonConverterUtil { // 开始处理下级节点 BpmnJsonNode children = bpmnJsonNode.getChildren(); if (Objects.isNull(children) || Objects.equals(NODE_EMPTY, children.getType()) || !StringUtils.hasLength(children.getId())) { - return flowElement.getId(); + if (CollectionUtils.isEmpty(branchLastNodeIds)) { + return Lists.newArrayList(flowElement.getId()); + } else { + return branchLastNodeIds; + } } else { if (CollectionUtils.isEmpty(branchLastNodeIds)) { return create(children, mainProcess, bpmnModel, flowElement.getId()); @@ -522,7 +532,7 @@ public final class BpmnJsonConverterUtil { // String fileName = "/Users/wangli/work/company/yizhi/workflow-engine/workflow-engine-server/src/main" + // "/resources/权限点模型.json"; String fileName = "/Users/wangli/work/company/yizhi/workflow-engine/workflow-engine-server/src/main" + - "/resources/kaoqing.json"; + "/resources/test.json"; byte[] bytes = Files.readAllBytes(Paths.get(fileName)); String content = new String(bytes, StandardCharsets.UTF_8); diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/listener/EngineTaskEventListener.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/listener/EngineTaskEventListener.java index 889c0610b..97b11bd2e 100644 --- a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/listener/EngineTaskEventListener.java +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/listener/EngineTaskEventListener.java @@ -93,15 +93,18 @@ public class EngineTaskEventListener implements TaskListener { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(); FlowableEventDispatcher eventDispatcher = processEngineConfiguration.getEventDispatcher(); - Optional noticeConfig = + Optional optNoticeConfig = BpmnMetaParserHelper.getNoticeConfig(ProcessDefinitionUtil.getProcess(processInstance.getProcessDefinitionId())); - assigners.stream().filter(i -> Objects.equals(delegateTask.getAssignee(), i.buildAssigneeId())).findAny() - .ifPresent(i -> { - MessagePushEventImpl event = MessagePushEventBuilder.createEvent(MessagePushEventType.NOTICE, i, - noticeConfig.orElse(null), processInstance.getProcessInstanceId(), - processInstance.getTenantId(), delegateTask.getId()); - eventDispatcher.dispatchEvent(event, processEngineConfiguration.getEngineCfgKey()); - }); + optNoticeConfig.ifPresent(noticeConf -> { + assigners.stream().filter(i -> Objects.equals(delegateTask.getAssignee(), i.buildAssigneeId())).findAny() + .ifPresent(i -> { + MessagePushEventImpl event = MessagePushEventBuilder.createEvent(MessagePushEventType.PENDING + , i, + noticeConf, processInstance.getProcessInstanceId(), + processInstance.getTenantId(), delegateTask.getId()); + eventDispatcher.dispatchEvent(event, processEngineConfiguration.getEngineCfgKey()); + }); + }); } private List getOrderedListeners() { diff --git a/workflow-engine-server/src/main/resources/kaoqing.bpmn20.xml b/workflow-engine-server/src/main/resources/kaoqing.bpmn20.xml new file mode 100644 index 000000000..f3c127892 --- /dev/null +++ b/workflow-engine-server/src/main/resources/kaoqing.bpmn20.xml @@ -0,0 +1,321 @@ + + + + remark + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${nrOfInstances == nrOfCompletedInstances} + + + + + + + + + + + + + + + + + + + + + ${nrOfInstances == nrOfCompletedInstances} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${nrOfInstances == nrOfCompletedInstances} + + + + + + + + + + + + + + + + + + + + + ${nrOfInstances == nrOfCompletedInstances} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/workflow-engine-server/src/main/resources/kaoqing.json b/workflow-engine-server/src/main/resources/kaoqing.json index cc3abd525..68571574c 100644 --- a/workflow-engine-server/src/main/resources/kaoqing.json +++ b/workflow-engine-server/src/main/resources/kaoqing.json @@ -328,64 +328,74 @@ "id": "5", "parentId": "4", "type": "NODE_TASK", - "name": "排它网关", - "children": { + "name": "班组确认", + "property": { + "approvalMethod": "human", + "approverScope": "projectWorkspace", + "approverSpecify": "identity", + "specifyValue": [ + "{\"assignee\":\"\",\"assigneeType\":\"\"}" + ], + "multiMode": "AND", + "approverEmptyHandleType": "autoPassed" + } + }, + "branches": [ + { "id": "6", - "parentId": "5", - "type": "NODE_TASK", - "name": "班组确认", - "property": {} - }, - "branches": [ - { - "id": "7", - "parentId": "4", - "type": "NODE_CONDITION", - "name": "需分包审核", - "children": { - "id": "9", - "parentId": "7", - "type": "NODE_TASK", - "name": "分包审核", - "property": { - "approvalMethod": "nobody" - } - }, + "parentId": "4", + "type": "NODE_CONDITION", + "name": "需分包审核", + "children": { + "id": "8", + "parentId": "6", + "type": "NODE_TASK", + "name": "分包审核", "property": { - "groups": [ - { - "conditionsType": "or", - "conditions": [ - { - "fieldDataType": "number", - "fieldCode": "type2", - "operator": "eq" - } - ] - } + "approvalMethod": "human", + "approverScope": "projectWorkspace", + "approverSpecify": "position", + "specifyValue": [ + "{\"assignee\":\"\",\"assigneeType\":\"\"}" ], - "defaultBranch": false, - "groupsType": "and" + "multiMode": "AND", + "approverEmptyHandleType": "autoPassed" } }, - { - "id": "8", - "parentId": "4", - "type": "NODE_CONDITION", - "name": "无需分包审核", - "property": { - "defaultBranch": true - } + "property": { + "groups": [ + { + "conditionsType": "or", + "conditions": [ + { + "fieldDataType": "number", + "fieldCode": "type2", + "operator": "eq" + } + ] + } + ], + "defaultBranch": false, + "groupsType": "and" } - ] - } + }, + { + "id": "7", + "parentId": "4", + "type": "NODE_CONDITION", + "name": "无需分包审核", + "property": { + "defaultBranch": true + } + } + ] } }, { "id": "9", "parentId": "2", "type": "NODE_CONDITION", - "name": "总包发起", + "name": "班组发起", "property": { "groups": [ { @@ -399,7 +409,7 @@ ] } ], - "defaultBranch": false, + "defaultBranch": true, "groupsType": "and" }, "children": { @@ -407,67 +417,74 @@ "parentId": "9", "type": "NODE_EXCLUSIVE_GATEWAY", "children": { - "id": "11", - "parentId": "4", + "id": "6", + "parentId": "5", "type": "NODE_TASK", - "name": "排它网关", - "children": { - "id": "6", - "parentId": "5", - "type": "NODE_TASK", - "name": "班组确认", - "property": {} - }, - "branches": [ - { - "id": "7", - "parentId": "4", - "type": "NODE_CONDITION", - "name": "需分包审核", - "children": { - "id": "9", - "parentId": "7", - "type": "NODE_TASK", - "name": "分包审核", - "property": { - "approvalMethod": "nobody" - } - }, + "name": "总包审核", + "property": { + "approvalMethod": "human", + "approverScope": "projectWorkspace", + "approverSpecify": "position", + "specifyValue": [ + "{\"assignee\":\"\",\"assigneeType\":\"\"}" + ], + "multiMode": "AND", + "approverEmptyHandleType": "autoPassed" + } + }, + "branches": [ + { + "id": "11", + "parentId": "9", + "type": "NODE_CONDITION", + "name": "需分包审核", + "children": { + "id": "13", + "parentId": "11", + "type": "NODE_TASK", + "name": "分包审核", "property": { - "groups": [ - { - "conditionsType": "or", - "conditions": [ - { - "fieldDataType": "number", - "fieldCode": "type2", - "operator": "eq" - } - ] - } + "approvalMethod": "human", + "approverScope": "projectWorkspace", + "approverSpecify": "identity", + "specifyValue": [ + "{\"assignee\":\"\",\"assigneeType\":\"\"}" ], - "defaultBranch": false, - "groupsType": "and" + "multiMode": "AND", + "approverEmptyHandleType": "autoPassed" } }, - { - "id": "8", - "parentId": "4", - "type": "NODE_CONDITION", - "name": "无需分包审核", - "property": { - "defaultBranch": true - } + "property": { + "groups": [ + { + "conditionsType": "or", + "conditions": [ + { + "fieldDataType": "number", + "fieldCode": "type2", + "operator": "eq" + } + ] + } + ], + "defaultBranch": false, + "groupsType": "and" } - ] - } + }, + { + "id": "12", + "parentId": "9", + "type": "NODE_CONDITION", + "name": "无需分包审核", + "property": { + "defaultBranch": true + } + } + ] } } - ], - "property": null - }, - "branches": null, - "property": null + ] + } } } } diff --git a/workflow-engine-server/src/main/resources/test.bpmn20.xml b/workflow-engine-server/src/main/resources/test.bpmn20.xml index d6e4da2b9..0fbb54077 100644 --- a/workflow-engine-server/src/main/resources/test.bpmn20.xml +++ b/workflow-engine-server/src/main/resources/test.bpmn20.xml @@ -4,11 +4,10 @@ xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" - targetNamespace="customCategory"> - - 极引非东活已运王点越组油门展总想立。年深江亲联热制者条济它部即月。号线信平和者京两马何标这。 - + targetNamespace="http://www.flowable.org/test"> + + remark @@ -17,44 +16,44 @@ - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + @@ -80,7 +79,7 @@ - @@ -90,70 +89,69 @@ delegateExpression="${engineTaskEventListener}"> - + - + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - + ${nrOfInstances == nrOfCompletedInstances} - + - - + default="SequenceFlowId_89087d614fa7401590d9041c1bdb3ebe"> + + - + @@ -161,55 +159,55 @@ delegateExpression="${engineTaskEventListener}"> - + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - + @@ -223,8 +221,8 @@ - - + + @@ -235,8 +233,7 @@ - + @@ -244,7 +241,7 @@ delegateExpression="${engineTaskEventListener}"> - + @@ -258,7 +255,7 @@ ${nrOfInstances == nrOfCompletedInstances} - + - + + @@ -281,8 +279,8 @@ ${nrOfInstances == nrOfCompletedInstances} - - + + @@ -290,122 +288,120 @@ - - + + - - - + + - + - + - + - + - + - + - - - - - - - - - - + - - - - - + + + + + + + + + + + + + + - - - - - + + + + + - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +