add - 模拟创建考勤补卡的流程模型, 同时调整JSON 格式转换逻辑

This commit is contained in:
wangli 2023-11-30 16:12:39 +08:00
parent 35822fcd86
commit 8caa08ac1a
6 changed files with 679 additions and 331 deletions

View File

@ -61,6 +61,7 @@ public class BpmnProcessInstanceCreateDTO {
@ApiModelProperty(value = "发起人信息") @ApiModelProperty(value = "发起人信息")
@Valid @Valid
@NotNull(message = "发起人不能为空")
private BpmnTaskDelegateAssigner initiator; private BpmnTaskDelegateAssigner initiator;
/** /**

View File

@ -185,16 +185,22 @@ public final class BpmnJsonConverterUtil {
mainProcess.addFlowElement(convertJsonToElement(StartEvent.class, mainProcess)); mainProcess.addFlowElement(convertJsonToElement(StartEvent.class, mainProcess));
// 解析前端传入的模型设计 json // 解析前端传入的模型设计 json
String lastNodeId = create(bpmnJsonNode, mainProcess, bpmnModel, START_EVENT_ID); List<String> lastNodeIds = create(bpmnJsonNode, mainProcess, bpmnModel, START_EVENT_ID);
// 创建固定的结束节点 // 创建固定的结束节点
mainProcess.addFlowElement(convertJsonToElement(EndEvent.class, mainProcess)); mainProcess.addFlowElement(convertJsonToElement(EndEvent.class, mainProcess));
SequenceFlow sequenceFlow = new SequenceFlow(); if (CollectionUtils.isEmpty(lastNodeIds)) {
sequenceFlow.setId(id(SEQUENCE_FLOW_ID)); throw new WorkflowEngineException(CONVERTOR_COMMON_ERROR, "未找到链接结束节点的节点数据");
sequenceFlow.setSourceRef(lastNodeId); }
sequenceFlow.setTargetRef(END_EVENT_ID);
mainProcess.addFlowElement(sequenceFlow); 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(); new BpmnAutoLayout(bpmnModel).execute();
return bpmnModel; return bpmnModel;
} }
@ -369,7 +375,7 @@ public final class BpmnJsonConverterUtil {
* @param bpmnModel 最终的 BPMN model * @param bpmnModel 最终的 BPMN model
* @return 创建的节点的 ID * @return 创建的节点的 ID
*/ */
private static String create(BpmnJsonNode bpmnJsonNode, Process mainProcess, private static List<String> create(BpmnJsonNode bpmnJsonNode, Process mainProcess,
BpmnModel bpmnModel, String... preNodeIds) { BpmnModel bpmnModel, String... preNodeIds) {
FLAT_NODE_MAP.put(bpmnJsonNode.getId(), bpmnJsonNode); FLAT_NODE_MAP.put(bpmnJsonNode.getId(), bpmnJsonNode);
// 设置来源节点 // 设置来源节点
@ -404,7 +410,7 @@ public final class BpmnJsonConverterUtil {
case NODE_TRIGGER: case NODE_TRIGGER:
// 这个类型目前暂不支持 // 这个类型目前暂不支持
case NODE_CARBON_COPY: case NODE_CARBON_COPY:
// 这里可以细化, 后续有实际场景了,再处理, 现目前只有 "抄送" 功能可能会用到 // 这里可以细化, 后续有实际场景了,再处理, 现目前只有 "抄送" 功能可能会用到
clz = ServiceTask.class; clz = ServiceTask.class;
break; break;
default: default:
@ -451,7 +457,7 @@ public final class BpmnJsonConverterUtil {
} }
if (Objects.nonNull(branch.getChildren())) { 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(); BpmnJsonNode children = bpmnJsonNode.getChildren();
if (Objects.isNull(children) || Objects.equals(NODE_EMPTY, children.getType()) || !StringUtils.hasLength(children.getId())) { 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 { } else {
if (CollectionUtils.isEmpty(branchLastNodeIds)) { if (CollectionUtils.isEmpty(branchLastNodeIds)) {
return create(children, mainProcess, bpmnModel, flowElement.getId()); 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" + // String fileName = "/Users/wangli/work/company/yizhi/workflow-engine/workflow-engine-server/src/main" +
// "/resources/权限点模型.json"; // "/resources/权限点模型.json";
String fileName = "/Users/wangli/work/company/yizhi/workflow-engine/workflow-engine-server/src/main" + 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)); byte[] bytes = Files.readAllBytes(Paths.get(fileName));
String content = new String(bytes, StandardCharsets.UTF_8); String content = new String(bytes, StandardCharsets.UTF_8);

View File

@ -93,15 +93,18 @@ public class EngineTaskEventListener implements TaskListener {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(); ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
FlowableEventDispatcher eventDispatcher = processEngineConfiguration.getEventDispatcher(); FlowableEventDispatcher eventDispatcher = processEngineConfiguration.getEventDispatcher();
Optional<BpmnNoticeConf> noticeConfig = Optional<BpmnNoticeConf> optNoticeConfig =
BpmnMetaParserHelper.getNoticeConfig(ProcessDefinitionUtil.getProcess(processInstance.getProcessDefinitionId())); BpmnMetaParserHelper.getNoticeConfig(ProcessDefinitionUtil.getProcess(processInstance.getProcessDefinitionId()));
assigners.stream().filter(i -> Objects.equals(delegateTask.getAssignee(), i.buildAssigneeId())).findAny() optNoticeConfig.ifPresent(noticeConf -> {
.ifPresent(i -> { assigners.stream().filter(i -> Objects.equals(delegateTask.getAssignee(), i.buildAssigneeId())).findAny()
MessagePushEventImpl event = MessagePushEventBuilder.createEvent(MessagePushEventType.NOTICE, i, .ifPresent(i -> {
noticeConfig.orElse(null), processInstance.getProcessInstanceId(), MessagePushEventImpl event = MessagePushEventBuilder.createEvent(MessagePushEventType.PENDING
processInstance.getTenantId(), delegateTask.getId()); , i,
eventDispatcher.dispatchEvent(event, processEngineConfiguration.getEngineCfgKey()); noticeConf, processInstance.getProcessInstanceId(),
}); processInstance.getTenantId(), delegateTask.getId());
eventDispatcher.dispatchEvent(event, processEngineConfiguration.getEngineCfgKey());
});
});
} }
private List<BpmnTaskEventListener> getOrderedListeners() { private List<BpmnTaskEventListener> getOrderedListeners() {

File diff suppressed because one or more lines are too long

View File

@ -328,64 +328,74 @@
"id": "5", "id": "5",
"parentId": "4", "parentId": "4",
"type": "NODE_TASK", "type": "NODE_TASK",
"name": "排它网关", "name": "班组确认",
"children": { "property": {
"approvalMethod": "human",
"approverScope": "projectWorkspace",
"approverSpecify": "identity",
"specifyValue": [
"{\"assignee\":\"\",\"assigneeType\":\"\"}"
],
"multiMode": "AND",
"approverEmptyHandleType": "autoPassed"
}
},
"branches": [
{
"id": "6", "id": "6",
"parentId": "5", "parentId": "4",
"type": "NODE_TASK", "type": "NODE_CONDITION",
"name": "班组确认", "name": "需分包审核",
"property": {} "children": {
}, "id": "8",
"branches": [ "parentId": "6",
{ "type": "NODE_TASK",
"id": "7", "name": "分包审核",
"parentId": "4",
"type": "NODE_CONDITION",
"name": "需分包审核",
"children": {
"id": "9",
"parentId": "7",
"type": "NODE_TASK",
"name": "分包审核",
"property": {
"approvalMethod": "nobody"
}
},
"property": { "property": {
"groups": [ "approvalMethod": "human",
{ "approverScope": "projectWorkspace",
"conditionsType": "or", "approverSpecify": "position",
"conditions": [ "specifyValue": [
{ "{\"assignee\":\"\",\"assigneeType\":\"\"}"
"fieldDataType": "number",
"fieldCode": "type2",
"operator": "eq"
}
]
}
], ],
"defaultBranch": false, "multiMode": "AND",
"groupsType": "and" "approverEmptyHandleType": "autoPassed"
} }
}, },
{ "property": {
"id": "8", "groups": [
"parentId": "4", {
"type": "NODE_CONDITION", "conditionsType": "or",
"name": "无需分包审核", "conditions": [
"property": { {
"defaultBranch": true "fieldDataType": "number",
} "fieldCode": "type2",
"operator": "eq"
}
]
}
],
"defaultBranch": false,
"groupsType": "and"
} }
] },
} {
"id": "7",
"parentId": "4",
"type": "NODE_CONDITION",
"name": "无需分包审核",
"property": {
"defaultBranch": true
}
}
]
} }
}, },
{ {
"id": "9", "id": "9",
"parentId": "2", "parentId": "2",
"type": "NODE_CONDITION", "type": "NODE_CONDITION",
"name": "总包发起", "name": "班组发起",
"property": { "property": {
"groups": [ "groups": [
{ {
@ -399,7 +409,7 @@
] ]
} }
], ],
"defaultBranch": false, "defaultBranch": true,
"groupsType": "and" "groupsType": "and"
}, },
"children": { "children": {
@ -407,67 +417,74 @@
"parentId": "9", "parentId": "9",
"type": "NODE_EXCLUSIVE_GATEWAY", "type": "NODE_EXCLUSIVE_GATEWAY",
"children": { "children": {
"id": "11", "id": "6",
"parentId": "4", "parentId": "5",
"type": "NODE_TASK", "type": "NODE_TASK",
"name": "排它网关", "name": "总包审核",
"children": { "property": {
"id": "6", "approvalMethod": "human",
"parentId": "5", "approverScope": "projectWorkspace",
"type": "NODE_TASK", "approverSpecify": "position",
"name": "班组确认", "specifyValue": [
"property": {} "{\"assignee\":\"\",\"assigneeType\":\"\"}"
}, ],
"branches": [ "multiMode": "AND",
{ "approverEmptyHandleType": "autoPassed"
"id": "7", }
"parentId": "4", },
"type": "NODE_CONDITION", "branches": [
"name": "需分包审核", {
"children": { "id": "11",
"id": "9", "parentId": "9",
"parentId": "7", "type": "NODE_CONDITION",
"type": "NODE_TASK", "name": "需分包审核",
"name": "分包审核", "children": {
"property": { "id": "13",
"approvalMethod": "nobody" "parentId": "11",
} "type": "NODE_TASK",
}, "name": "分包审核",
"property": { "property": {
"groups": [ "approvalMethod": "human",
{ "approverScope": "projectWorkspace",
"conditionsType": "or", "approverSpecify": "identity",
"conditions": [ "specifyValue": [
{ "{\"assignee\":\"\",\"assigneeType\":\"\"}"
"fieldDataType": "number",
"fieldCode": "type2",
"operator": "eq"
}
]
}
], ],
"defaultBranch": false, "multiMode": "AND",
"groupsType": "and" "approverEmptyHandleType": "autoPassed"
} }
}, },
{ "property": {
"id": "8", "groups": [
"parentId": "4", {
"type": "NODE_CONDITION", "conditionsType": "or",
"name": "无需分包审核", "conditions": [
"property": { {
"defaultBranch": true "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
} }
} }
} }

File diff suppressed because one or more lines are too long