update - 调整 JSON 转 Bpmn 协议内容的逻辑.
This commit is contained in:
parent
2fc0d683da
commit
65f14188cb
@ -40,11 +40,8 @@ public class BpmTransformUtil {
|
||||
process.setId(model.getKey());
|
||||
process.setName(model.getName());
|
||||
|
||||
StartEvent startEvent = new StartEvent();
|
||||
if (BpmFlowNodeType.NODE_STARTER.getType().equals(bpmnJson.getType())) {
|
||||
startEvent.setId(bpmnJson.getId());
|
||||
startEvent.setInitiator("applyUserId");
|
||||
process.addFlowElement(startEvent);
|
||||
process.addFlowElement(createStartEvent(bpmnJson.getId()));
|
||||
}
|
||||
|
||||
List<SequenceFlow> sequenceFlows = Lists.newArrayList();
|
||||
@ -59,7 +56,7 @@ public class BpmTransformUtil {
|
||||
|
||||
String lastNode = null;
|
||||
try {
|
||||
lastNode = create(startEvent.getId(), bpmnJson.getChildren(), process, bpmnModel, sequenceFlows,
|
||||
lastNode = create(bpmnJson.getId(), bpmnJson.getChildren(), process, bpmnModel, sequenceFlows,
|
||||
childNodeMap);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -67,7 +64,7 @@ public class BpmTransformUtil {
|
||||
}
|
||||
EndEvent endEvent = createEndEvent();
|
||||
process.addFlowElement(endEvent);
|
||||
process.addFlowElement(connect(lastNode, endEvent.getId(), sequenceFlows, childNodeMap, process));
|
||||
process.addFlowElement(sequenceFlow(lastNode, endEvent.getId(), sequenceFlows, childNodeMap, process));
|
||||
|
||||
|
||||
new BpmnAutoLayout(bpmnModel).execute();
|
||||
@ -87,7 +84,7 @@ public class BpmTransformUtil {
|
||||
return serviceTask;
|
||||
}
|
||||
|
||||
public static SequenceFlow connect(String from, String to, List<SequenceFlow> sequenceFlows, Map<String,
|
||||
public static SequenceFlow sequenceFlow(String from, String to, List<SequenceFlow> sequenceFlows, Map<String,
|
||||
BpmJsonNode> childNodeMap, Process process) {
|
||||
SequenceFlow flow = new SequenceFlow();
|
||||
String sequenceFlowId = id("sequenceFlow");
|
||||
@ -105,7 +102,7 @@ public class BpmTransformUtil {
|
||||
//解析条件表达式
|
||||
StringBuffer conditionExpression = new StringBuffer();
|
||||
conditionExpression.append("${ ");
|
||||
conditionExpression.append("var:eq('" + parentNode.getProperty().getConditionBranchKey() + "', " + parentNode.getProperty().getConditionBranchValue() + ") ");
|
||||
conditionExpression.append("var:eq('" + parentNode.getProperty().getConditionBranchKey() + "', " + parentNode.getProperty().getConditionBranchValue() + ")");
|
||||
conditionExpression.append(" }");
|
||||
|
||||
flow.setConditionExpression(conditionExpression.toString());
|
||||
@ -122,6 +119,13 @@ public class BpmTransformUtil {
|
||||
return flow;
|
||||
}
|
||||
|
||||
public static StartEvent createStartEvent(String id) {
|
||||
StartEvent startEvent = new StartEvent();
|
||||
startEvent.setId(id);
|
||||
startEvent.setInitiator("applyUserId");
|
||||
return startEvent;
|
||||
}
|
||||
|
||||
public static EndEvent createEndEvent() {
|
||||
EndEvent endEvent = new EndEvent();
|
||||
endEvent.setId(END_EVENT_ID);
|
||||
@ -180,15 +184,15 @@ public class BpmTransformUtil {
|
||||
exclusiveGateway.setId(exclusiveGatewayId);
|
||||
exclusiveGateway.setName(name);
|
||||
process.addFlowElement(exclusiveGateway);
|
||||
process.addFlowElement(connect(formId, exclusiveGatewayId, sequenceFlows, childNodeMap, process));
|
||||
process.addFlowElement(sequenceFlow(formId, exclusiveGatewayId, sequenceFlows, childNodeMap, process));
|
||||
|
||||
if (Objects.isNull(flowNode.getBranches()) && Objects.isNull(flowNode.getChildren())) {
|
||||
return exclusiveGatewayId;
|
||||
}
|
||||
List<BpmJsonNode> flowNodes = flowNode.getBranches();
|
||||
List<String> incoming = Lists.newArrayListWithCapacity(flowNodes.size());
|
||||
List<BpmJsonNode> branches = flowNode.getBranches();
|
||||
List<String> incoming = Lists.newArrayListWithCapacity(branches.size());
|
||||
List<Map> conditions = Lists.newCopyOnWriteArrayList();
|
||||
for (BpmJsonNode element : flowNodes) {
|
||||
for (BpmJsonNode element : branches) {
|
||||
if (!ObjectUtils.isEmpty(element.getProperty())) {
|
||||
Boolean typeElse = element.getProperty().getDefaultCondition();
|
||||
if (Boolean.TRUE.equals(typeElse)) {
|
||||
@ -197,10 +201,10 @@ public class BpmTransformUtil {
|
||||
}
|
||||
|
||||
childNodeMap.put(element.getId(), element);
|
||||
BpmJsonNode childNode = element.getChildren();
|
||||
BpmJsonNode children = element.getChildren();
|
||||
String nodeName = element.getName();
|
||||
|
||||
if (!ObjectUtils.isEmpty(element.getProperty()) && (Objects.isNull(childNode) || StringUtils.isBlank(childNode.getId()))) {
|
||||
if (!ObjectUtils.isEmpty(element.getProperty()) && (Objects.isNull(children) || StringUtils.isBlank(children.getId()))) {
|
||||
|
||||
incoming.add(exclusiveGatewayId);
|
||||
Map condition = new HashMap();
|
||||
@ -217,9 +221,9 @@ public class BpmTransformUtil {
|
||||
continue;
|
||||
}
|
||||
// 只生成一个任务,同时设置当前任务的条件
|
||||
Map incomingObj = childNode.getIncoming();
|
||||
Map incomingObj = children.getIncoming();
|
||||
incomingObj.put("incoming", Collections.singletonList(exclusiveGatewayId));
|
||||
String identifier = create(exclusiveGatewayId, childNode, process, bpmnModel, sequenceFlows, childNodeMap);
|
||||
String identifier = create(exclusiveGatewayId, children, process, bpmnModel, sequenceFlows, childNodeMap);
|
||||
List<SequenceFlow> flows = sequenceFlows.stream().filter(flow -> StringUtils.equals(exclusiveGatewayId,
|
||||
flow.getSourceRef()))
|
||||
.collect(Collectors.toList());
|
||||
@ -263,7 +267,7 @@ public class BpmTransformUtil {
|
||||
childNode.setChildren(null);
|
||||
String identifier = endExId;
|
||||
for (int i = 0; i < incoming.size(); i++) {
|
||||
process.addFlowElement(connect(incoming.get(i), identifier, sequenceFlows, childNodeMap,
|
||||
process.addFlowElement(sequenceFlow(incoming.get(i), identifier, sequenceFlows, childNodeMap,
|
||||
process));
|
||||
}
|
||||
|
||||
@ -298,8 +302,8 @@ public class BpmTransformUtil {
|
||||
}
|
||||
|
||||
// 1.1 边连接完成后,在进行 nextNode 创建
|
||||
if (Objects.nonNull(nextNode) && StringUtils.isNotBlank(nextNode.getId())) {
|
||||
return create(identifier, nextNode, process, bpmnModel, sequenceFlows,
|
||||
if (Objects.nonNull(childNode) && StringUtils.isNotBlank(childNode.getId())) {
|
||||
return create(identifier, childNode, process, bpmnModel, sequenceFlows,
|
||||
childNodeMap);
|
||||
} else {
|
||||
return identifier;
|
||||
@ -323,7 +327,7 @@ public class BpmTransformUtil {
|
||||
userTask.setName(flowNode.getName());
|
||||
userTask.setId(id);
|
||||
process.addFlowElement(userTask);
|
||||
process.addFlowElement(connect(incoming.get(0), id, sequenceFlows, childNodeMap, process));
|
||||
process.addFlowElement(sequenceFlow(incoming.get(0), id, sequenceFlows, childNodeMap, process));
|
||||
|
||||
FlowableListener createTaskListener = new FlowableListener();
|
||||
createTaskListener.setEvent(TaskListener.EVENTNAME_ALL_EVENTS);
|
||||
@ -366,7 +370,7 @@ public class BpmTransformUtil {
|
||||
}
|
||||
}
|
||||
// 设置审批人为空时,允许自动通过
|
||||
if (ObjectUtils.isEmpty(flowNode.getProperty()) && Boolean.TRUE.equals(flowNode.getProperty().getAllowSkip())) {
|
||||
if (!ObjectUtils.isEmpty(flowNode.getProperty()) && flowNode.getProperty().getAllowSkip()) {
|
||||
userTask.setSkipExpression("${" + BPM_ALLOW_SKIP_USER_TASK + "}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ public class BpmJsonNodeProperty {
|
||||
/**
|
||||
* 审批人为空是否允许自动跳过
|
||||
*/
|
||||
private Boolean allowSkip;
|
||||
private Boolean allowSkip = false;
|
||||
|
||||
/**
|
||||
* 条件节点中是否是默认分支,可以都不传;
|
||||
|
||||
@ -116,9 +116,6 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
throw new WorkflowEngineException(MODEL_NOT_EXISTS);
|
||||
}
|
||||
|
||||
processDefinitionService.createProcessDefinition(model, bpmnBytes);
|
||||
|
||||
// TODO 没跑通
|
||||
String definitionId = this.processDefinitionService.createProcessDefinition(model, bpmnBytes);
|
||||
// 挂起原来的流程定义
|
||||
this.updateProcessDefinitionSuspended(model.getDeploymentId());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user