|
@@ -5,17 +5,22 @@ import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.*;
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
+import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
|
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.ConditionGroups;
|
|
|
import cn.iocoder.yudao.module.bpm.enums.definition.*;
|
|
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
|
|
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
|
|
|
+import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants;
|
|
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.BpmCopyTaskDelegate;
|
|
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.BpmTriggerTaskDelegate;
|
|
|
+import cn.iocoder.yudao.module.bpm.service.task.listener.BpmCallActivityListener;
|
|
|
+import cn.iocoder.yudao.module.bpm.service.task.listener.BpmUserTaskListener;
|
|
|
import org.flowable.bpmn.BpmnAutoLayout;
|
|
|
import org.flowable.bpmn.constants.BpmnXMLConstants;
|
|
|
import org.flowable.bpmn.model.Process;
|
|
|
import org.flowable.bpmn.model.*;
|
|
|
+import org.flowable.engine.delegate.ExecutionListener;
|
|
|
import org.flowable.engine.delegate.TaskListener;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
@@ -24,7 +29,6 @@ import java.util.*;
|
|
|
import static cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum.ASYNC_HTTP_REQUEST;
|
|
|
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants.*;
|
|
|
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.*;
|
|
|
-import static cn.iocoder.yudao.module.bpm.service.task.listener.BpmUserTaskListener.DELEGATE_EXPRESSION;
|
|
|
import static java.util.Arrays.asList;
|
|
|
|
|
|
/**
|
|
@@ -43,7 +47,8 @@ public class SimpleModelUtils {
|
|
|
List<NodeConvert> converts = asList(new StartNodeConvert(), new EndNodeConvert(),
|
|
|
new StartUserNodeConvert(), new ApproveNodeConvert(), new CopyNodeConvert(), new TransactorNodeConvert(),
|
|
|
new DelayTimerNodeConvert(), new TriggerNodeConvert(),
|
|
|
- new ConditionBranchNodeConvert(), new ParallelBranchNodeConvert(), new InclusiveBranchNodeConvert(), new RouteBranchNodeConvert());
|
|
|
+ new ConditionBranchNodeConvert(), new ParallelBranchNodeConvert(), new InclusiveBranchNodeConvert(), new RouteBranchNodeConvert(),
|
|
|
+ new ChildProcessConvert(), new AsyncChildProcessConvert());
|
|
|
converts.forEach(convert -> NODE_CONVERTS.put(convert.getType(), convert));
|
|
|
}
|
|
|
|
|
@@ -478,7 +483,7 @@ public class SimpleModelUtils {
|
|
|
FlowableListener flowableListener = new FlowableListener();
|
|
|
flowableListener.setEvent(TaskListener.EVENTNAME_CREATE);
|
|
|
flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
|
|
|
- flowableListener.setImplementation(DELEGATE_EXPRESSION);
|
|
|
+ flowableListener.setImplementation(BpmUserTaskListener.DELEGATE_EXPRESSION);
|
|
|
addListenerConfig(flowableListener, node.getTaskCreateListener());
|
|
|
flowableListeners.add(flowableListener);
|
|
|
}
|
|
@@ -487,7 +492,7 @@ public class SimpleModelUtils {
|
|
|
FlowableListener flowableListener = new FlowableListener();
|
|
|
flowableListener.setEvent(TaskListener.EVENTNAME_ASSIGNMENT);
|
|
|
flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
|
|
|
- flowableListener.setImplementation(DELEGATE_EXPRESSION);
|
|
|
+ flowableListener.setImplementation(BpmUserTaskListener.DELEGATE_EXPRESSION);
|
|
|
addListenerConfig(flowableListener, node.getTaskAssignListener());
|
|
|
flowableListeners.add(flowableListener);
|
|
|
}
|
|
@@ -496,7 +501,7 @@ public class SimpleModelUtils {
|
|
|
FlowableListener flowableListener = new FlowableListener();
|
|
|
flowableListener.setEvent(TaskListener.EVENTNAME_COMPLETE);
|
|
|
flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
|
|
|
- flowableListener.setImplementation(DELEGATE_EXPRESSION);
|
|
|
+ flowableListener.setImplementation(BpmUserTaskListener.DELEGATE_EXPRESSION);
|
|
|
addListenerConfig(flowableListener, node.getTaskCompleteListener());
|
|
|
flowableListeners.add(flowableListener);
|
|
|
}
|
|
@@ -809,6 +814,88 @@ public class SimpleModelUtils {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private static class ChildProcessConvert implements NodeConvert {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CallActivity convert(BpmSimpleModelNodeVO node) {
|
|
|
+ BpmSimpleModelNodeVO.ChildProcessSetting childProcessSetting = node.getChildProcessSetting();
|
|
|
+ List<IOParameter> inVariable = childProcessSetting.getInVariable() == null ?
|
|
|
+ new ArrayList<>() : new ArrayList<>(childProcessSetting.getInVariable());
|
|
|
+ CallActivity callActivity = new CallActivity();
|
|
|
+ callActivity.setId(node.getId());
|
|
|
+ callActivity.setName(node.getName());
|
|
|
+ callActivity.setCalledElementType("key"); // TODO @lesan:这里为啥是 key 哈?
|
|
|
+ // 1. 是否异步
|
|
|
+ callActivity.setAsynchronous(node.getChildProcessSetting().getAsync());
|
|
|
+
|
|
|
+ // 2. 调用的子流程
|
|
|
+ callActivity.setCalledElement(childProcessSetting.getCalledElement());
|
|
|
+ callActivity.setProcessInstanceName(childProcessSetting.getCalledElementName());
|
|
|
+
|
|
|
+ // 3. 是否自动跳过子流程发起节点
|
|
|
+ // TODO @lesan:貌似只有 SourceExpression 的区别,直接通过 valueOf childProcessSetting.getSkipStartUserNode()???
|
|
|
+ if (Boolean.TRUE.equals(childProcessSetting.getSkipStartUserNode())) {
|
|
|
+ IOParameter ioParameter = new IOParameter();
|
|
|
+ ioParameter.setSourceExpression("true");
|
|
|
+ ioParameter.setTarget(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_SKIP_START_USER_NODE);
|
|
|
+ inVariable.add(ioParameter);
|
|
|
+ } else {
|
|
|
+ IOParameter ioParameter = new IOParameter();
|
|
|
+ ioParameter.setSourceExpression("false");
|
|
|
+ ioParameter.setTarget(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_SKIP_START_USER_NODE);
|
|
|
+ inVariable.add(ioParameter);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 主→子变量传递
|
|
|
+ // 4.1 【默认需要传递的一些变量】流程状态
|
|
|
+ // TODO @lesan:4.1 这个要不,单独一个序号,类似 3. 这个。然后下面,就是把 主→子变量传递、子→主变量传递;这样逻辑连贯点哈
|
|
|
+ IOParameter ioParameter = new IOParameter();
|
|
|
+ ioParameter.setSource(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS);
|
|
|
+ ioParameter.setTarget(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_STATUS);
|
|
|
+ inVariable.add(ioParameter);
|
|
|
+ callActivity.setInParameters(inVariable);
|
|
|
+
|
|
|
+ // 5. 子→主变量传递
|
|
|
+ // TODO @lesan:通过 isNotEmpty 这种哈
|
|
|
+ if (childProcessSetting.getOutVariable() != null && !childProcessSetting.getOutVariable().isEmpty()) {
|
|
|
+ callActivity.setOutParameters(childProcessSetting.getOutVariable());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 子流程发起人配置
|
|
|
+ List<FlowableListener> executionListeners = new ArrayList<>();
|
|
|
+ FlowableListener flowableListener = new FlowableListener();
|
|
|
+ flowableListener.setEvent(ExecutionListener.EVENTNAME_START);
|
|
|
+ flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
|
|
|
+ flowableListener.setImplementation(BpmCallActivityListener.DELEGATE_EXPRESSION);
|
|
|
+ FieldExtension fieldExtension = new FieldExtension();
|
|
|
+ fieldExtension.setFieldName("listenerConfig");
|
|
|
+ fieldExtension.setStringValue(JsonUtils.toJsonString(childProcessSetting.getStartUserSetting()));
|
|
|
+ flowableListener.getFieldExtensions().add(fieldExtension);
|
|
|
+ executionListeners.add(flowableListener);
|
|
|
+ callActivity.setExecutionListeners(executionListeners);
|
|
|
+
|
|
|
+ // 添加节点类型
|
|
|
+ addNodeType(node.getType(), callActivity);
|
|
|
+ return callActivity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BpmSimpleModelNodeTypeEnum getType() {
|
|
|
+ return BpmSimpleModelNodeTypeEnum.CHILD_PROCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class AsyncChildProcessConvert extends ChildProcessConvert {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BpmSimpleModelNodeTypeEnum getType() {
|
|
|
+ return BpmSimpleModelNodeTypeEnum.ASYNC_CHILD_PROCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private static String buildGatewayJoinId(String id) {
|
|
|
return id + "_join";
|
|
|
}
|
|
@@ -838,6 +925,8 @@ public class SimpleModelUtils {
|
|
|
|| nodeType == BpmSimpleModelNodeTypeEnum.APPROVE_NODE
|
|
|
|| nodeType == BpmSimpleModelNodeTypeEnum.TRANSACTOR_NODE
|
|
|
|| nodeType == BpmSimpleModelNodeTypeEnum.COPY_NODE
|
|
|
+ || nodeType == BpmSimpleModelNodeTypeEnum.CHILD_PROCESS
|
|
|
+ || nodeType == BpmSimpleModelNodeTypeEnum.ASYNC_CHILD_PROCESS
|
|
|
|| nodeType == BpmSimpleModelNodeTypeEnum.END_NODE) {
|
|
|
// 添加元素
|
|
|
resultNodes.add(currentNode);
|