Commit 62aabc633c857a21cd2ef0449e11829fbdc2d1a7

Authored by YunaiV
1 parent adc05cad

【代码评审】BPM:Simple 设计器 - 签名实现

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/simple/BpmSimpleModelNodeVO.java
@@ -119,6 +119,7 @@ public class BpmSimpleModelNodeVO { @@ -119,6 +119,7 @@ public class BpmSimpleModelNodeVO {
119 @Schema(description = "路由分支组", example = "[]") 119 @Schema(description = "路由分支组", example = "[]")
120 private List<RouteCondition> routerGroups; 120 private List<RouteCondition> routerGroups;
121 121
  122 + // TODO @lesan:这个目前前端是随机生成的。可以后端来随机么?
122 @Schema(description = "默认分支 ID", example = "Flow_xxx") 123 @Schema(description = "默认分支 ID", example = "Flow_xxx")
123 private String defaultFlowId; // 仅用于路由分支节点 BpmSimpleModelNodeType.ROUTE_BRANCH_NODE 124 private String defaultFlowId; // 仅用于路由分支节点 BpmSimpleModelNodeType.ROUTE_BRANCH_NODE
124 125
@@ -289,6 +290,7 @@ public class BpmSimpleModelNodeVO { @@ -289,6 +290,7 @@ public class BpmSimpleModelNodeVO {
289 290
290 } 291 }
291 292
  293 + // TODO @lesan:还有相关的也要改下哈。route 到 router
292 @Schema(description = "路由分支") 294 @Schema(description = "路由分支")
293 @Data 295 @Data
294 @Valid 296 @Valid
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
@@ -3,11 +3,8 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.util; @@ -3,11 +3,8 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.util;
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.convert.Convert; 4 import cn.hutool.core.convert.Convert;
5 import cn.hutool.core.map.MapUtil; 5 import cn.hutool.core.map.MapUtil;
6 -import cn.hutool.core.util.ArrayUtil;  
7 -import cn.hutool.core.util.ObjUtil;  
8 -import cn.hutool.core.util.StrUtil; 6 +import cn.hutool.core.util.*;
9 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 7 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
10 -import cn.iocoder.yudao.framework.common.util.json.JsonUtils;  
11 import cn.iocoder.yudao.framework.common.util.number.NumberUtils; 8 import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
12 import cn.iocoder.yudao.framework.common.util.string.StrUtils; 9 import cn.iocoder.yudao.framework.common.util.string.StrUtils;
13 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; 10 import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
@@ -58,18 +55,6 @@ public class BpmnModelUtils { @@ -58,18 +55,6 @@ public class BpmnModelUtils {
58 element.addExtensionElement(extensionElement); 55 element.addExtensionElement(extensionElement);
59 } 56 }
60 57
61 - public static void addExtensionElementJson(FlowElement element, String name, Object value) {  
62 - if (value == null) {  
63 - return;  
64 - }  
65 - ExtensionElement extensionElement = new ExtensionElement();  
66 - extensionElement.setNamespace(FLOWABLE_EXTENSIONS_NAMESPACE);  
67 - extensionElement.setNamespacePrefix(FLOWABLE_EXTENSIONS_PREFIX);  
68 - extensionElement.setElementText(JsonUtils.toJsonString(value));  
69 - extensionElement.setName(name);  
70 - element.addExtensionElement(extensionElement);  
71 - }  
72 -  
73 public static void addExtensionElement(FlowElement element, String name, Integer value) { 58 public static void addExtensionElement(FlowElement element, String name, Integer value) {
74 if (value == null) { 59 if (value == null) {
75 return; 60 return;
@@ -107,14 +92,6 @@ public class BpmnModelUtils { @@ -107,14 +92,6 @@ public class BpmnModelUtils {
107 return element != null ? element.getElementText() : null; 92 return element != null ? element.getElementText() : null;
108 } 93 }
109 94
110 - public static <T> T parseExtensionElementJson(FlowElement flowElement, String elementName, Class<T> clazz) {  
111 - if (flowElement == null) {  
112 - return null;  
113 - }  
114 - ExtensionElement element = CollUtil.getFirst(flowElement.getExtensionElements().get(elementName));  
115 - return element != null ? JsonUtils.parseObject(element.getElementText(), clazz) : null;  
116 - }  
117 -  
118 /** 95 /**
119 * 给节点添加候选人元素 96 * 给节点添加候选人元素
120 * 97 *
@@ -369,6 +346,7 @@ public class BpmnModelUtils { @@ -369,6 +346,7 @@ public class BpmnModelUtils {
369 } 346 }
370 347
371 public static void addSignEnable(Boolean signEnable, FlowElement userTask) { 348 public static void addSignEnable(Boolean signEnable, FlowElement userTask) {
  349 + // TODO @lesan:是不是改成表达式会好点 addExtensionElement(userTask, SIGN_ENABLE, ObjUtil.isNotNull(signEnable) ? )
372 if (ObjUtil.isNotNull(signEnable)) { 350 if (ObjUtil.isNotNull(signEnable)) {
373 addExtensionElement(userTask, SIGN_ENABLE, signEnable.toString()); 351 addExtensionElement(userTask, SIGN_ENABLE, signEnable.toString());
374 } else { 352 } else {
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
@@ -465,6 +465,7 @@ public class SimpleModelUtils { @@ -465,6 +465,7 @@ public class SimpleModelUtils {
465 flowableListener.setEvent(TaskListener.EVENTNAME_ASSIGNMENT); 465 flowableListener.setEvent(TaskListener.EVENTNAME_ASSIGNMENT);
466 flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); 466 flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
467 flowableListener.setImplementation(DELEGATE_EXPRESSION); 467 flowableListener.setImplementation(DELEGATE_EXPRESSION);
  468 + // TODO @lesan:可以在 BpmnModelUtils 搞个方法,类似 public static Integer parseCandidateStrategy。这样,就收敛啦!
468 FieldExtension fieldExtension = new FieldExtension(); 469 FieldExtension fieldExtension = new FieldExtension();
469 fieldExtension.setFieldName("listenerConfig"); 470 fieldExtension.setFieldName("listenerConfig");
470 fieldExtension.setStringValue(JsonUtils.toJsonString(node.getTaskAssignListener())); 471 fieldExtension.setStringValue(JsonUtils.toJsonString(node.getTaskAssignListener()));
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
@@ -170,9 +170,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { @@ -170,9 +170,8 @@ public class BpmTaskServiceImpl implements BpmTaskService {
170 taskForm = formService.getForm(NumberUtils.parseLong(todoTask.getFormKey())); 170 taskForm = formService.getForm(NumberUtils.parseLong(todoTask.getFormKey()));
171 } 171 }
172 172
173 - BpmTaskRespVO bpmTaskRespVO = BpmTaskConvert.INSTANCE.buildTodoTask(todoTask, childrenTasks, buttonsSetting, taskForm);  
174 - bpmTaskRespVO.setSignEnable(signEnable);  
175 - return bpmTaskRespVO; 173 + return BpmTaskConvert.INSTANCE.buildTodoTask(todoTask, childrenTasks, buttonsSetting, taskForm)
  174 + .setSignEnable(signEnable);
176 } 175 }
177 176
178 @Override 177 @Override
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/listener/BpmUserTaskListener.java
@@ -71,7 +71,7 @@ public class BpmUserTaskListener implements TaskListener { @@ -71,7 +71,7 @@ public class BpmUserTaskListener implements TaskListener {
71 headers.add(HEADER_TENANT_ID, delegateTask.getTenantId()); 71 headers.add(HEADER_TENANT_ID, delegateTask.getTenantId());
72 } 72 }
73 // 2.2 请求体默认参数 73 // 2.2 请求体默认参数
74 - // TODO @芋艿:哪些默认参数,后续再调研下; 74 + // TODO @芋艿:哪些默认参数,后续再调研下;感觉可以搞个 task 字段,把整个 delegateTask 放进去;
75 body.add("processInstanceId", delegateTask.getProcessInstanceId()); 75 body.add("processInstanceId", delegateTask.getProcessInstanceId());
76 body.add("assignee", delegateTask.getAssignee()); 76 body.add("assignee", delegateTask.getAssignee());
77 body.add("taskDefinitionKey", delegateTask.getTaskDefinitionKey()); 77 body.add("taskDefinitionKey", delegateTask.getTaskDefinitionKey());
@@ -80,6 +80,7 @@ public class BpmUserTaskListener implements TaskListener { @@ -80,6 +80,7 @@ public class BpmUserTaskListener implements TaskListener {
80 // 3. 异步发起请求 80 // 3. 异步发起请求
81 // TODO @芋艿:确认要同步,还是异步 81 // TODO @芋艿:确认要同步,还是异步
82 HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers); 82 HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers);
  83 + // TODO @lesan:可能需要 try catch 哇? RestClientException
83 ResponseEntity<String> responseEntity = restTemplate.exchange(listenerHandler.getPath(), HttpMethod.POST, 84 ResponseEntity<String> responseEntity = restTemplate.exchange(listenerHandler.getPath(), HttpMethod.POST,
84 requestEntity, String.class); 85 requestEntity, String.class);
85 log.info("[notify][监听器:{},事件类型:{},请求头:{},请求体:{},响应结果:{}]", 86 log.info("[notify][监听器:{},事件类型:{},请求头:{},请求体:{},响应结果:{}]",
@@ -111,6 +112,7 @@ public class BpmUserTaskListener implements TaskListener { @@ -111,6 +112,7 @@ public class BpmUserTaskListener implements TaskListener {
111 .filter(item -> item.getEvent().equals(eventName)) 112 .filter(item -> item.getEvent().equals(eventName))
112 .findFirst().orElse(null); 113 .findFirst().orElse(null);
113 Assert.notNull(flowableListener, "监听器({})不能为空", flowableListener); 114 Assert.notNull(flowableListener, "监听器({})不能为空", flowableListener);
  115 + // TODO @lesan:BpmnModelUtils 提供一个 BpmSimpleModelNodeVO.ListenerHandler 解析方法,尽量收敛掉。
114 FieldExtension fieldExtension = flowableListener.getFieldExtensions().stream() 116 FieldExtension fieldExtension = flowableListener.getFieldExtensions().stream()
115 .filter(item -> item.getFieldName().equals("listenerConfig")) 117 .filter(item -> item.getFieldName().equals("listenerConfig"))
116 .findFirst().orElse(null); 118 .findFirst().orElse(null);