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 = "发起人信息")
@Valid
@NotNull(message = "发起人不能为空")
private BpmnTaskDelegateAssigner initiator;
/**

View File

@ -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<String> lastNodeIds = create(bpmnJsonNode, mainProcess, bpmnModel, START_EVENT_ID);
// 创建固定的结束节点
mainProcess.addFlowElement(convertJsonToElement(EndEvent.class, mainProcess));
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<String> 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);

View File

@ -93,15 +93,18 @@ public class EngineTaskEventListener implements TaskListener {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
FlowableEventDispatcher eventDispatcher = processEngineConfiguration.getEventDispatcher();
Optional<BpmnNoticeConf> noticeConfig =
Optional<BpmnNoticeConf> optNoticeConfig =
BpmnMetaParserHelper.getNoticeConfig(ProcessDefinitionUtil.getProcess(processInstance.getProcessDefinitionId()));
optNoticeConfig.ifPresent(noticeConf -> {
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(),
MessagePushEventImpl event = MessagePushEventBuilder.createEvent(MessagePushEventType.PENDING
, i,
noticeConf, processInstance.getProcessInstanceId(),
processInstance.getTenantId(), delegateTask.getId());
eventDispatcher.dispatchEvent(event, processEngineConfiguration.getEngineCfgKey());
});
});
}
private List<BpmnTaskEventListener> getOrderedListeners() {

File diff suppressed because one or more lines are too long

View File

@ -328,27 +328,38 @@
"id": "5",
"parentId": "4",
"type": "NODE_TASK",
"name": "排它网关",
"children": {
"id": "6",
"parentId": "5",
"type": "NODE_TASK",
"name": "班组确认",
"property": {}
"property": {
"approvalMethod": "human",
"approverScope": "projectWorkspace",
"approverSpecify": "identity",
"specifyValue": [
"{\"assignee\":\"\",\"assigneeType\":\"\"}"
],
"multiMode": "AND",
"approverEmptyHandleType": "autoPassed"
}
},
"branches": [
{
"id": "7",
"id": "6",
"parentId": "4",
"type": "NODE_CONDITION",
"name": "需分包审核",
"children": {
"id": "9",
"parentId": "7",
"id": "8",
"parentId": "6",
"type": "NODE_TASK",
"name": "分包审核",
"property": {
"approvalMethod": "nobody"
"approvalMethod": "human",
"approverScope": "projectWorkspace",
"approverSpecify": "position",
"specifyValue": [
"{\"assignee\":\"\",\"assigneeType\":\"\"}"
],
"multiMode": "AND",
"approverEmptyHandleType": "autoPassed"
}
},
"property": {
@ -369,7 +380,7 @@
}
},
{
"id": "8",
"id": "7",
"parentId": "4",
"type": "NODE_CONDITION",
"name": "无需分包审核",
@ -379,13 +390,12 @@
}
]
}
}
},
{
"id": "9",
"parentId": "2",
"type": "NODE_CONDITION",
"name": "总包发起",
"name": "班组发起",
"property": {
"groups": [
{
@ -399,38 +409,49 @@
]
}
],
"defaultBranch": false,
"defaultBranch": true,
"groupsType": "and"
},
"children": {
"id": "10",
"parentId": "9",
"type": "NODE_EXCLUSIVE_GATEWAY",
"children": {
"id": "11",
"parentId": "4",
"type": "NODE_TASK",
"name": "排它网关",
"children": {
"id": "6",
"parentId": "5",
"type": "NODE_TASK",
"name": "班组确认",
"property": {}
"name": "总包审核",
"property": {
"approvalMethod": "human",
"approverScope": "projectWorkspace",
"approverSpecify": "position",
"specifyValue": [
"{\"assignee\":\"\",\"assigneeType\":\"\"}"
],
"multiMode": "AND",
"approverEmptyHandleType": "autoPassed"
}
},
"branches": [
{
"id": "7",
"parentId": "4",
"id": "11",
"parentId": "9",
"type": "NODE_CONDITION",
"name": "需分包审核",
"children": {
"id": "9",
"parentId": "7",
"id": "13",
"parentId": "11",
"type": "NODE_TASK",
"name": "分包审核",
"property": {
"approvalMethod": "nobody"
"approvalMethod": "human",
"approverScope": "projectWorkspace",
"approverSpecify": "identity",
"specifyValue": [
"{\"assignee\":\"\",\"assigneeType\":\"\"}"
],
"multiMode": "AND",
"approverEmptyHandleType": "autoPassed"
}
},
"property": {
@ -451,8 +472,8 @@
}
},
{
"id": "8",
"parentId": "4",
"id": "12",
"parentId": "9",
"type": "NODE_CONDITION",
"name": "无需分包审核",
"property": {
@ -462,12 +483,8 @@
]
}
}
]
}
],
"property": null
},
"branches": null,
"property": null
}
}
}

File diff suppressed because one or more lines are too long