diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/common/utils/BpmnExpressionTranslator.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/common/utils/BpmnExpressionTranslator.java new file mode 100644 index 000000000..c2fee270e --- /dev/null +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/common/utils/BpmnExpressionTranslator.java @@ -0,0 +1,63 @@ +package cn.axzo.workflow.core.common.utils; + +import cn.axzo.workflow.common.model.request.bpmn.BpmnCondition; + +/** + * 表达式翻译器 + * + * @author wangli + * @since 2023/11/16 23:30 + */ +public final class BpmnExpressionTranslator { + private BpmnExpressionTranslator() {} + + public static String translateNumber(BpmnCondition condition) { + StringBuilder sb = new StringBuilder(); + + if ("between".equals(condition.getOperator())) { + sb.append("var:") + .append(condition.getLeftOperator()) + .append("('") + .append(condition.getFieldCode()) + .append("', ") + .append(condition.getLeftValue()) + .append(")") + .append(" && ") + .append("var:") + .append(condition.getRightOperator()) + .append("('") + .append(condition.getFieldCode()) + .append("', ") + .append(condition.getRightValue()) + .append(")"); + } else { + sb.append("var:") + .append(condition.getOperator()) + .append("('") + .append(condition.getFieldCode()) + .append("', ") + .append(condition.getDefaultValue()) + .append(")"); + } + return sb.toString(); + } + + public static String translateRadio(BpmnCondition condition) { + StringBuilder sb = new StringBuilder(); + //TODO + return sb.toString(); + } + + public static String translateCheckbox(BpmnCondition condition) { + StringBuilder sb = new StringBuilder(); + //TODO + return sb.toString(); + } + + public static String translateString(BpmnCondition condition) { + StringBuilder sb = new StringBuilder(); + //TODO + return sb.toString(); + } + +} 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 fcd2bbbf9..f094dca69 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 @@ -393,36 +393,37 @@ public final class BpmnJsonConverterUtil { } else if (Lists.newArrayList(preNodeIds).size() == 1 && !NODE_CONDITION.equals(bpmnJsonNode.getType())) { mainProcess.addFlowElement(convertJsonToElement(SequenceFlow.class, bpmnJsonNode, mainProcess)); } else { - // 网关的 SequenceFlow, 需要在这里设置网关的 DefaultFlow, 同时也需要解析这些 SequenceFlow 的条件 + // 将网关分支的最末级节点 ID 关联到网关的 children 节点上,网关协议转换才算闭环 Arrays.stream(preNodeIds).forEach(income -> { bpmnJsonNode.setIncoming(Lists.newArrayList(income)); FlowElement sequenceFlow = convertJsonToElement(SequenceFlow.class, bpmnJsonNode, mainProcess); mainProcess.addFlowElement(sequenceFlow); - - setDefaultFlow(bpmnJsonNode, mainProcess, sequenceFlow); - }); } // 只有网关才会涉及到 branch - List conditions = new ArrayList<>(); + List branchLastNodeIds = new ArrayList<>(); if (!CollectionUtils.isEmpty(bpmnJsonNode.getBranches())) { + Gateway gateway = (Gateway) flowElement; for (BpmnJsonNode branch : bpmnJsonNode.getBranches()) { - // branch == node_condition - if (Objects.nonNull(branch.getChildren())) { - conditions.add(create(branch.getChildren(), mainProcess, bpmnModel, flowElement.getId())); - } else { - bpmnJsonNode.getChildren().setIncoming(Lists.newArrayList(bpmnJsonNode.getId())); - FlowElement sequenceFlow = convertJsonToElement(SequenceFlow.class, bpmnJsonNode.getChildren(), - mainProcess); - mainProcess.addFlowElement(sequenceFlow); + BpmnJsonNode nextJsonNode = Objects.isNull(branch.getChildren()) ? bpmnJsonNode.getChildren() : + branch.getChildren(); + nextJsonNode.setIncoming(Lists.newArrayList(gateway.getId())); - // 判断这个是不是默认流 - if (Objects.nonNull(branch.getProperty()) && Boolean.TRUE.equals(branch.getProperty().getDefaultBranch())) { - Gateway gateway = (Gateway) flowElement; - gateway.setDefaultFlow(sequenceFlow.getId()); - } + // 将 node_condition 放入计算节点的上级属性中,方便顺序流转换器对条件进行处理 + nextJsonNode.setPreJsonNode(branch); + SequenceFlow sequenceFlow = (SequenceFlow) convertJsonToElement(SequenceFlow.class, nextJsonNode, + mainProcess); + mainProcess.addFlowElement(sequenceFlow); + + // 设置网关默认流 + if (Objects.nonNull(branch.getProperty()) && Boolean.TRUE.equals(branch.getProperty().getDefaultBranch())) { + gateway.setDefaultFlow(sequenceFlow.getId()); + } + + if (Objects.nonNull(branch.getChildren())) { + branchLastNodeIds.add(create(branch.getChildren(), mainProcess, bpmnModel)); } } } @@ -432,12 +433,10 @@ public final class BpmnJsonConverterUtil { if (Objects.isNull(children) || Objects.equals(NODE_EMPTY, children.getType()) || !StringUtils.hasLength(children.getId())) { return flowElement.getId(); } else { - if (!CollectionUtils.isEmpty(conditions)) { - // 由于不是通过 create 方法解析 node_condition, 所以单独用一个字段来传递它 - children.setPreJsonNode(bpmnJsonNode); - return create(children, mainProcess, bpmnModel, conditions.toArray(new String[0])); + if (CollectionUtils.isEmpty(branchLastNodeIds)) { + return create(children, mainProcess, bpmnModel, flowElement.getId()); } - return create(children, mainProcess, bpmnModel, flowElement.getId()); + return create(children, mainProcess, bpmnModel, branchLastNodeIds.toArray(new String[0])); } } diff --git a/workflow-engine-server/src/main/resources/test.bpmn20.xml b/workflow-engine-server/src/main/resources/test.bpmn20.xml index de5c7e99f..8a2c5a76b 100644 --- a/workflow-engine-server/src/main/resources/test.bpmn20.xml +++ b/workflow-engine-server/src/main/resources/test.bpmn20.xml @@ -79,7 +79,7 @@ - @@ -145,10 +145,11 @@ ${nrOfInstances == nrOfCompletedInstances} - + - + default="SequenceFlowId_180b9ce16f3049cd8e93036ab3b7d93a"> + + @@ -213,7 +214,6 @@ ${nrOfInstances == nrOfCompletedInstances} - @@ -221,7 +221,8 @@ - + + @@ -229,7 +230,6 @@ - @@ -253,7 +253,7 @@ ${nrOfInstances == nrOfCompletedInstances} - + ${nrOfInstances == nrOfCompletedInstances} - - + + @@ -285,16 +285,16 @@ - - + + - - + @@ -303,7 +303,7 @@ - + @@ -312,94 +312,94 @@ - - - - - - - - - - + - - - - - - - + + + + + + + + + + - - - - - + - - - - - - - + - - - - - - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + - - + + - + + + + + + + + + + +