Commit adc05cad66156e3d0be37fa7c890e2449480e45a
Committed by
Gitee
!1189 Simple设计器功能完善
Merge pull request !1189 from Lesan/feature/bpm-n
Showing
8 changed files
with
89 additions
and
57 deletions
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmListenerMapType.java renamed to yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmListenerParamTypeEnum.java
| @@ -6,7 +6,6 @@ import lombok.Getter; | @@ -6,7 +6,6 @@ import lombok.Getter; | ||
| 6 | 6 | ||
| 7 | import java.util.Arrays; | 7 | import java.util.Arrays; |
| 8 | 8 | ||
| 9 | -// TODO @lesan:BpmListenerParamTypeEnum | ||
| 10 | /** | 9 | /** |
| 11 | * BPM 任务监听器键值对类型 | 10 | * BPM 任务监听器键值对类型 |
| 12 | * | 11 | * |
| @@ -14,7 +13,7 @@ import java.util.Arrays; | @@ -14,7 +13,7 @@ import java.util.Arrays; | ||
| 14 | */ | 13 | */ |
| 15 | @Getter | 14 | @Getter |
| 16 | @AllArgsConstructor | 15 | @AllArgsConstructor |
| 17 | -public enum BpmListenerMapType implements IntArrayValuable { | 16 | +public enum BpmListenerParamTypeEnum implements IntArrayValuable { |
| 18 | 17 | ||
| 19 | FIXED_VALUE(1, "固定值"), | 18 | FIXED_VALUE(1, "固定值"), |
| 20 | FROM_FORM(2, "表单"); | 19 | FROM_FORM(2, "表单"); |
| @@ -22,7 +21,7 @@ public enum BpmListenerMapType implements IntArrayValuable { | @@ -22,7 +21,7 @@ public enum BpmListenerMapType implements IntArrayValuable { | ||
| 22 | private final Integer type; | 21 | private final Integer type; |
| 23 | private final String name; | 22 | private final String name; |
| 24 | 23 | ||
| 25 | - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmListenerMapType::getType).toArray(); | 24 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmListenerParamTypeEnum::getType).toArray(); |
| 26 | 25 | ||
| 27 | @Override | 26 | @Override |
| 28 | public int[] array() { | 27 | public int[] array() { |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/simple/BpmSimpleModelNodeVO.java
| @@ -60,6 +60,9 @@ public class BpmSimpleModelNodeVO { | @@ -60,6 +60,9 @@ public class BpmSimpleModelNodeVO { | ||
| 60 | @Schema(description = "操作按钮设置", example = "[]") | 60 | @Schema(description = "操作按钮设置", example = "[]") |
| 61 | private List<OperationButtonSetting> buttonsSetting; // 用于审批节点 | 61 | private List<OperationButtonSetting> buttonsSetting; // 用于审批节点 |
| 62 | 62 | ||
| 63 | + @Schema(description = "是否需要签名", example = "false") | ||
| 64 | + private Boolean signEnable; | ||
| 65 | + | ||
| 63 | /** | 66 | /** |
| 64 | * 审批节点拒绝处理 | 67 | * 审批节点拒绝处理 |
| 65 | */ | 68 | */ |
| @@ -113,13 +116,9 @@ public class BpmSimpleModelNodeVO { | @@ -113,13 +116,9 @@ public class BpmSimpleModelNodeVO { | ||
| 113 | */ | 116 | */ |
| 114 | private ConditionGroups conditionGroups; // 仅用于条件节点 BpmSimpleModelNodeType.CONDITION_NODE | 117 | private ConditionGroups conditionGroups; // 仅用于条件节点 BpmSimpleModelNodeType.CONDITION_NODE |
| 115 | 118 | ||
| 116 | - // TODO @lesan:route 改成 router 会不会好点。因为触发器、延迟器,都带了类似 r | ||
| 117 | - | ||
| 118 | - // TODO @lesan:routeGroups | ||
| 119 | @Schema(description = "路由分支组", example = "[]") | 119 | @Schema(description = "路由分支组", example = "[]") |
| 120 | - private List<RouteCondition> routeGroup; | 120 | + private List<RouteCondition> routerGroups; |
| 121 | 121 | ||
| 122 | - // TODO @lesan:貌似没用??? | ||
| 123 | @Schema(description = "默认分支 ID", example = "Flow_xxx") | 122 | @Schema(description = "默认分支 ID", example = "Flow_xxx") |
| 124 | private String defaultFlowId; // 仅用于路由分支节点 BpmSimpleModelNodeType.ROUTE_BRANCH_NODE | 123 | private String defaultFlowId; // 仅用于路由分支节点 BpmSimpleModelNodeType.ROUTE_BRANCH_NODE |
| 125 | 124 | ||
| @@ -136,20 +135,19 @@ public class BpmSimpleModelNodeVO { | @@ -136,20 +135,19 @@ public class BpmSimpleModelNodeVO { | ||
| 136 | private String path; | 135 | private String path; |
| 137 | 136 | ||
| 138 | @Schema(description = "请求头", example = "[]") | 137 | @Schema(description = "请求头", example = "[]") |
| 139 | - private List<ListenerMap> header; | 138 | + private List<ListenerParam> header; |
| 140 | 139 | ||
| 141 | @Schema(description = "请求体", example = "[]") | 140 | @Schema(description = "请求体", example = "[]") |
| 142 | - private List<ListenerMap> body; | 141 | + private List<ListenerParam> body; |
| 143 | 142 | ||
| 144 | // TODO @芋艿:这里后续要不要复用; | 143 | // TODO @芋艿:这里后续要不要复用; |
| 145 | 144 | ||
| 146 | - // TODO @lesan:ListenerParam 更合适哈。首先它是参数配置,然后形式是键值对 | ||
| 147 | @Schema(description = "任务监听器键值对") | 145 | @Schema(description = "任务监听器键值对") |
| 148 | @Data | 146 | @Data |
| 149 | - public static class ListenerMap { | 147 | + public static class ListenerParam { |
| 150 | 148 | ||
| 151 | @Schema(description = "值类型", example = "1") | 149 | @Schema(description = "值类型", example = "1") |
| 152 | - @InEnum(BpmListenerMapType.class) | 150 | + @InEnum(BpmListenerParamTypeEnum.class) |
| 153 | private Integer type; | 151 | private Integer type; |
| 154 | 152 | ||
| 155 | @Schema(description = "键", example = "xxx") | 153 | @Schema(description = "键", example = "xxx") |
| @@ -300,7 +298,6 @@ public class BpmSimpleModelNodeVO { | @@ -300,7 +298,6 @@ public class BpmSimpleModelNodeVO { | ||
| 300 | @NotEmpty(message = "节点 Id 不能为空") | 298 | @NotEmpty(message = "节点 Id 不能为空") |
| 301 | private String nodeId; | 299 | private String nodeId; |
| 302 | 300 | ||
| 303 | - // TODO @lesan:type、expression、groups; | ||
| 304 | @Schema(description = "条件类型", example = "1") | 301 | @Schema(description = "条件类型", example = "1") |
| 305 | @InEnum(BpmSimpleModeConditionType.class) | 302 | @InEnum(BpmSimpleModeConditionType.class) |
| 306 | @NotNull(message = "条件类型不能为空") | 303 | @NotNull(message = "条件类型不能为空") |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/vo/task/BpmTaskRespVO.java
| @@ -78,6 +78,9 @@ public class BpmTaskRespVO { | @@ -78,6 +78,9 @@ public class BpmTaskRespVO { | ||
| 78 | @Schema(description = "操作按钮设置值") | 78 | @Schema(description = "操作按钮设置值") |
| 79 | private Map<Integer, OperationButtonSetting> buttonsSetting; | 79 | private Map<Integer, OperationButtonSetting> buttonsSetting; |
| 80 | 80 | ||
| 81 | + @Schema(description = "是否需要签名") | ||
| 82 | + private Boolean signEnable; | ||
| 83 | + | ||
| 81 | @Data | 84 | @Data |
| 82 | @Schema(description = "流程实例") | 85 | @Schema(description = "流程实例") |
| 83 | public static class ProcessInstance { | 86 | public static class ProcessInstance { |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/enums/BpmnModelConstants.java
| @@ -110,4 +110,9 @@ public interface BpmnModelConstants { | @@ -110,4 +110,9 @@ public interface BpmnModelConstants { | ||
| 110 | */ | 110 | */ |
| 111 | String START_USER_NODE_ID = "StartUserNode"; | 111 | String START_USER_NODE_ID = "StartUserNode"; |
| 112 | 112 | ||
| 113 | + /** | ||
| 114 | + * 是否需要签名 | ||
| 115 | + */ | ||
| 116 | + String SIGN_ENABLE = "signEnable"; | ||
| 117 | + | ||
| 113 | } | 118 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
| 1 | package cn.iocoder.yudao.module.bpm.framework.flowable.core.util; | 1 | package cn.iocoder.yudao.module.bpm.framework.flowable.core.util; |
| 2 | 2 | ||
| 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.map.MapUtil; | 5 | import cn.hutool.core.map.MapUtil; |
| 5 | import cn.hutool.core.util.ArrayUtil; | 6 | import cn.hutool.core.util.ArrayUtil; |
| 6 | import cn.hutool.core.util.ObjUtil; | 7 | import cn.hutool.core.util.ObjUtil; |
| @@ -115,25 +116,6 @@ public class BpmnModelUtils { | @@ -115,25 +116,6 @@ public class BpmnModelUtils { | ||
| 115 | } | 116 | } |
| 116 | 117 | ||
| 117 | /** | 118 | /** |
| 118 | - * 给节点添加Simple设计器配置Json | ||
| 119 | - * | ||
| 120 | - * @param userTask 节点 | ||
| 121 | - * @param node 节点对象 | ||
| 122 | - */ | ||
| 123 | - public static void addSimpleConfigInfo(FlowElement userTask, Object node) { | ||
| 124 | - addExtensionElementJson(userTask, "config", node); | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - /** | ||
| 128 | - * 解析Simple设计器配置Json | ||
| 129 | - * | ||
| 130 | - * @param userTask 节点 | ||
| 131 | - */ | ||
| 132 | - public static BpmSimpleModelNodeVO parseSimpleConfigInfo(FlowElement userTask) { | ||
| 133 | - return parseExtensionElementJson(userTask, "config", BpmSimpleModelNodeVO.class); | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - /** | ||
| 137 | * 给节点添加候选人元素 | 119 | * 给节点添加候选人元素 |
| 138 | * | 120 | * |
| 139 | * @param candidateStrategy 候选人策略 | 121 | * @param candidateStrategy 候选人策略 |
| @@ -386,6 +368,26 @@ public class BpmnModelUtils { | @@ -386,6 +368,26 @@ public class BpmnModelUtils { | ||
| 386 | return Optional.ofNullable(extensionElement).map(ExtensionElement::getElementText).orElse(null); | 368 | return Optional.ofNullable(extensionElement).map(ExtensionElement::getElementText).orElse(null); |
| 387 | } | 369 | } |
| 388 | 370 | ||
| 371 | + public static void addSignEnable(Boolean signEnable, FlowElement userTask) { | ||
| 372 | + if (ObjUtil.isNotNull(signEnable)) { | ||
| 373 | + addExtensionElement(userTask, SIGN_ENABLE, signEnable.toString()); | ||
| 374 | + } else { | ||
| 375 | + addExtensionElement(userTask, SIGN_ENABLE, "false"); | ||
| 376 | + } | ||
| 377 | + } | ||
| 378 | + | ||
| 379 | + public static Boolean parseSignEnable(BpmnModel bpmnModel, String flowElementId) { | ||
| 380 | + FlowElement flowElement = getFlowElementById(bpmnModel, flowElementId); | ||
| 381 | + if (flowElement == null) { | ||
| 382 | + return false; | ||
| 383 | + } | ||
| 384 | + List<ExtensionElement> extensionElements = flowElement.getExtensionElements().get(SIGN_ENABLE); | ||
| 385 | + if (CollUtil.isEmpty(extensionElements)) { | ||
| 386 | + return false; | ||
| 387 | + } | ||
| 388 | + return Convert.toBool(extensionElements.get(0).getElementText(), false); | ||
| 389 | + } | ||
| 390 | + | ||
| 389 | // ========== BPM 简单查找相关的方法 ========== | 391 | // ========== BPM 简单查找相关的方法 ========== |
| 390 | 392 | ||
| 391 | /** | 393 | /** |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
| @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Assert; | @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Assert; | ||
| 5 | import cn.hutool.core.map.MapUtil; | 5 | import cn.hutool.core.map.MapUtil; |
| 6 | import cn.hutool.core.util.*; | 6 | import cn.hutool.core.util.*; |
| 7 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 7 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 8 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 8 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; | 9 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
| 9 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.ConditionGroups; | 10 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.ConditionGroups; |
| 10 | import cn.iocoder.yudao.module.bpm.enums.definition.*; | 11 | import cn.iocoder.yudao.module.bpm.enums.definition.*; |
| @@ -200,7 +201,7 @@ public class SimpleModelUtils { | @@ -200,7 +201,7 @@ public class SimpleModelUtils { | ||
| 200 | // 3. 遍历分支节点 | 201 | // 3. 遍历分支节点 |
| 201 | if (nodeType == BpmSimpleModelNodeType.ROUTE_BRANCH_NODE) { | 202 | if (nodeType == BpmSimpleModelNodeType.ROUTE_BRANCH_NODE) { |
| 202 | // 路由分支遍历 | 203 | // 路由分支遍历 |
| 203 | - for (BpmSimpleModelNodeVO.RouteCondition route : node.getRouteGroup()) { | 204 | + for (BpmSimpleModelNodeVO.RouteCondition route : node.getRouterGroups()) { |
| 204 | SequenceFlow sequenceFlow = RouteBranchNodeConvert.buildSequenceFlow(node.getId(), route); | 205 | SequenceFlow sequenceFlow = RouteBranchNodeConvert.buildSequenceFlow(node.getId(), route); |
| 205 | process.addFlowElement(sequenceFlow); | 206 | process.addFlowElement(sequenceFlow); |
| 206 | } | 207 | } |
| @@ -439,9 +440,8 @@ public class SimpleModelUtils { | @@ -439,9 +440,8 @@ public class SimpleModelUtils { | ||
| 439 | } | 440 | } |
| 440 | // 设置监听器 | 441 | // 设置监听器 |
| 441 | addUserTaskListener(node, userTask); | 442 | addUserTaskListener(node, userTask); |
| 442 | - // 设置 Simple 设计器节点配置 | ||
| 443 | - // TODO @lesan:只设置到 flowableListener 里面,整个 node 太大了!因为很多都保存过啦。 | ||
| 444 | - addSimpleConfigInfo(userTask, node); | 443 | + // 添加是否需要签名 |
| 444 | + addSignEnable(node.getSignEnable(), userTask); | ||
| 445 | return userTask; | 445 | return userTask; |
| 446 | } | 446 | } |
| 447 | 447 | ||
| @@ -453,6 +453,10 @@ public class SimpleModelUtils { | @@ -453,6 +453,10 @@ public class SimpleModelUtils { | ||
| 453 | flowableListener.setEvent(TaskListener.EVENTNAME_CREATE); | 453 | flowableListener.setEvent(TaskListener.EVENTNAME_CREATE); |
| 454 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); | 454 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); |
| 455 | flowableListener.setImplementation(DELEGATE_EXPRESSION); | 455 | flowableListener.setImplementation(DELEGATE_EXPRESSION); |
| 456 | + FieldExtension fieldExtension = new FieldExtension(); | ||
| 457 | + fieldExtension.setFieldName("listenerConfig"); | ||
| 458 | + fieldExtension.setStringValue(JsonUtils.toJsonString(node.getTaskCreateListener())); | ||
| 459 | + flowableListener.getFieldExtensions().add(fieldExtension); | ||
| 456 | flowableListeners.add(flowableListener); | 460 | flowableListeners.add(flowableListener); |
| 457 | } | 461 | } |
| 458 | if (node.getTaskAssignListener() != null | 462 | if (node.getTaskAssignListener() != null |
| @@ -461,6 +465,10 @@ public class SimpleModelUtils { | @@ -461,6 +465,10 @@ public class SimpleModelUtils { | ||
| 461 | flowableListener.setEvent(TaskListener.EVENTNAME_ASSIGNMENT); | 465 | flowableListener.setEvent(TaskListener.EVENTNAME_ASSIGNMENT); |
| 462 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); | 466 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); |
| 463 | flowableListener.setImplementation(DELEGATE_EXPRESSION); | 467 | flowableListener.setImplementation(DELEGATE_EXPRESSION); |
| 468 | + FieldExtension fieldExtension = new FieldExtension(); | ||
| 469 | + fieldExtension.setFieldName("listenerConfig"); | ||
| 470 | + fieldExtension.setStringValue(JsonUtils.toJsonString(node.getTaskAssignListener())); | ||
| 471 | + flowableListener.getFieldExtensions().add(fieldExtension); | ||
| 464 | flowableListeners.add(flowableListener); | 472 | flowableListeners.add(flowableListener); |
| 465 | } | 473 | } |
| 466 | if (node.getTaskCompleteListener() != null | 474 | if (node.getTaskCompleteListener() != null |
| @@ -469,6 +477,10 @@ public class SimpleModelUtils { | @@ -469,6 +477,10 @@ public class SimpleModelUtils { | ||
| 469 | flowableListener.setEvent(TaskListener.EVENTNAME_COMPLETE); | 477 | flowableListener.setEvent(TaskListener.EVENTNAME_COMPLETE); |
| 470 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); | 478 | flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); |
| 471 | flowableListener.setImplementation(DELEGATE_EXPRESSION); | 479 | flowableListener.setImplementation(DELEGATE_EXPRESSION); |
| 480 | + FieldExtension fieldExtension = new FieldExtension(); | ||
| 481 | + fieldExtension.setFieldName("listenerConfig"); | ||
| 482 | + fieldExtension.setStringValue(JsonUtils.toJsonString(node.getTaskCompleteListener())); | ||
| 483 | + flowableListener.getFieldExtensions().add(fieldExtension); | ||
| 472 | flowableListeners.add(flowableListener); | 484 | flowableListeners.add(flowableListener); |
| 473 | } | 485 | } |
| 474 | if (CollUtil.isNotEmpty(flowableListeners)) { | 486 | if (CollUtil.isNotEmpty(flowableListeners)) { |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| @@ -64,6 +64,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU | @@ -64,6 +64,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU | ||
| 64 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | 64 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; |
| 65 | import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*; | 65 | import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*; |
| 66 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_RETURN_FLAG; | 66 | import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_RETURN_FLAG; |
| 67 | +import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.parseSignEnable; | ||
| 67 | 68 | ||
| 68 | /** | 69 | /** |
| 69 | * 流程任务实例 Service 实现类 | 70 | * 流程任务实例 Service 实现类 |
| @@ -161,13 +162,17 @@ public class BpmTaskServiceImpl implements BpmTaskService { | @@ -161,13 +162,17 @@ public class BpmTaskServiceImpl implements BpmTaskService { | ||
| 161 | BpmnModel bpmnModel = bpmProcessDefinitionService.getProcessDefinitionBpmnModel(todoTask.getProcessDefinitionId()); | 162 | BpmnModel bpmnModel = bpmProcessDefinitionService.getProcessDefinitionBpmnModel(todoTask.getProcessDefinitionId()); |
| 162 | Map<Integer, BpmTaskRespVO.OperationButtonSetting> buttonsSetting = BpmnModelUtils.parseButtonsSetting( | 163 | Map<Integer, BpmTaskRespVO.OperationButtonSetting> buttonsSetting = BpmnModelUtils.parseButtonsSetting( |
| 163 | bpmnModel, todoTask.getTaskDefinitionKey()); | 164 | bpmnModel, todoTask.getTaskDefinitionKey()); |
| 165 | + Boolean signEnable = parseSignEnable(bpmnModel, todoTask.getTaskDefinitionKey()); | ||
| 164 | 166 | ||
| 165 | // 4. 任务表单 | 167 | // 4. 任务表单 |
| 166 | BpmFormDO taskForm = null; | 168 | BpmFormDO taskForm = null; |
| 167 | if (StrUtil.isNotBlank(todoTask.getFormKey())){ | 169 | if (StrUtil.isNotBlank(todoTask.getFormKey())){ |
| 168 | taskForm = formService.getForm(NumberUtils.parseLong(todoTask.getFormKey())); | 170 | taskForm = formService.getForm(NumberUtils.parseLong(todoTask.getFormKey())); |
| 169 | } | 171 | } |
| 170 | - return BpmTaskConvert.INSTANCE.buildTodoTask(todoTask, childrenTasks, buttonsSetting, taskForm); | 172 | + |
| 173 | + BpmTaskRespVO bpmTaskRespVO = BpmTaskConvert.INSTANCE.buildTodoTask(todoTask, childrenTasks, buttonsSetting, taskForm); | ||
| 174 | + bpmTaskRespVO.setSignEnable(signEnable); | ||
| 175 | + return bpmTaskRespVO; | ||
| 171 | } | 176 | } |
| 172 | 177 | ||
| 173 | @Override | 178 | @Override |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/listener/BpmUserTaskListener.java
| 1 | package cn.iocoder.yudao.module.bpm.service.task.listener; | 1 | package cn.iocoder.yudao.module.bpm.service.task.listener; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.lang.Assert; | ||
| 4 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
| 6 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 5 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; | 7 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
| 6 | -import cn.iocoder.yudao.module.bpm.enums.definition.BpmListenerMapType; | 8 | +import cn.iocoder.yudao.module.bpm.enums.definition.BpmListenerParamTypeEnum; |
| 7 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; | 9 | import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; |
| 8 | import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService; | 10 | import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService; |
| 9 | import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; | 11 | import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; |
| 10 | import jakarta.annotation.Resource; | 12 | import jakarta.annotation.Resource; |
| 11 | import lombok.extern.slf4j.Slf4j; | 13 | import lombok.extern.slf4j.Slf4j; |
| 12 | import org.flowable.bpmn.model.BpmnModel; | 14 | import org.flowable.bpmn.model.BpmnModel; |
| 13 | -import org.flowable.bpmn.model.FlowElement; | 15 | +import org.flowable.bpmn.model.FieldExtension; |
| 16 | +import org.flowable.bpmn.model.FlowableListener; | ||
| 17 | +import org.flowable.bpmn.model.UserTask; | ||
| 14 | import org.flowable.engine.delegate.TaskListener; | 18 | import org.flowable.engine.delegate.TaskListener; |
| 15 | import org.flowable.engine.history.HistoricProcessInstance; | 19 | import org.flowable.engine.history.HistoricProcessInstance; |
| 16 | import org.flowable.task.service.delegate.DelegateTask; | 20 | import org.flowable.task.service.delegate.DelegateTask; |
| @@ -26,7 +30,6 @@ import java.util.List; | @@ -26,7 +30,6 @@ import java.util.List; | ||
| 26 | import java.util.Map; | 30 | import java.util.Map; |
| 27 | 31 | ||
| 28 | import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; | 32 | import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; |
| 29 | -import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils.parseSimpleConfigInfo; | ||
| 30 | 33 | ||
| 31 | /** | 34 | /** |
| 32 | * BPM 用户任务通用监听器 | 35 | * BPM 用户任务通用监听器 |
| @@ -53,9 +56,9 @@ public class BpmUserTaskListener implements TaskListener { | @@ -53,9 +56,9 @@ public class BpmUserTaskListener implements TaskListener { | ||
| 53 | // 1. 获取所需基础信息 | 56 | // 1. 获取所需基础信息 |
| 54 | HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(delegateTask.getProcessInstanceId()); | 57 | HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(delegateTask.getProcessInstanceId()); |
| 55 | BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(delegateTask.getProcessDefinitionId()); | 58 | BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(delegateTask.getProcessDefinitionId()); |
| 56 | - FlowElement userTask = BpmnModelUtils.getFlowElementById(bpmnModel, delegateTask.getTaskDefinitionKey()); | ||
| 57 | - BpmSimpleModelNodeVO node = parseSimpleConfigInfo(userTask); | ||
| 58 | - BpmSimpleModelNodeVO.ListenerHandler listenerHandler = getListenerHandlerByEvent(delegateTask.getEventName(), node); | 59 | + UserTask userTask = (UserTask) BpmnModelUtils.getFlowElementById(bpmnModel, delegateTask.getTaskDefinitionKey()); |
| 60 | + BpmSimpleModelNodeVO.ListenerHandler listenerHandler = getListenerHandlerByEvent(delegateTask.getEventName(), | ||
| 61 | + userTask.getTaskListeners()); | ||
| 59 | 62 | ||
| 60 | // 2. 获取请求头和请求体 | 63 | // 2. 获取请求头和请求体 |
| 61 | Map<String, Object> processVariables = processInstance.getProcessVariables(); | 64 | Map<String, Object> processVariables = processInstance.getProcessVariables(); |
| @@ -79,34 +82,40 @@ public class BpmUserTaskListener implements TaskListener { | @@ -79,34 +82,40 @@ public class BpmUserTaskListener implements TaskListener { | ||
| 79 | HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers); | 82 | HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers); |
| 80 | ResponseEntity<String> responseEntity = restTemplate.exchange(listenerHandler.getPath(), HttpMethod.POST, | 83 | ResponseEntity<String> responseEntity = restTemplate.exchange(listenerHandler.getPath(), HttpMethod.POST, |
| 81 | requestEntity, String.class); | 84 | requestEntity, String.class); |
| 82 | - // TODO @lesan:日志打印,可以更全哈,例如说,请求参数、对应的 task id,哪个 listener | ||
| 83 | - log.info("[notify][的响应结果({})]", responseEntity); | 85 | + log.info("[notify][监听器:{},事件类型:{},请求头:{},请求体:{},响应结果:{}]", |
| 86 | + DELEGATE_EXPRESSION, | ||
| 87 | + delegateTask.getEventName(), | ||
| 88 | + headers, | ||
| 89 | + body, | ||
| 90 | + responseEntity); | ||
| 84 | // 4. 是否需要后续操作?TODO 芋艿:待定! | 91 | // 4. 是否需要后续操作?TODO 芋艿:待定! |
| 85 | } | 92 | } |
| 86 | 93 | ||
| 87 | - private void parseListenerMap(List<BpmSimpleModelNodeVO.ListenerHandler.ListenerMap> list, | 94 | + private void parseListenerMap(List<BpmSimpleModelNodeVO.ListenerHandler.ListenerParam> list, |
| 88 | Map<String, Object> processVariables, | 95 | Map<String, Object> processVariables, |
| 89 | MultiValueMap<String, String> to) { | 96 | MultiValueMap<String, String> to) { |
| 90 | if (CollUtil.isEmpty(list)) { | 97 | if (CollUtil.isEmpty(list)) { |
| 91 | return; | 98 | return; |
| 92 | } | 99 | } |
| 93 | list.forEach(item -> { | 100 | list.forEach(item -> { |
| 94 | - if (item.getType().equals(BpmListenerMapType.FIXED_VALUE.getType())) { | 101 | + if (item.getType().equals(BpmListenerParamTypeEnum.FIXED_VALUE.getType())) { |
| 95 | to.add(item.getKey(), item.getValue()); | 102 | to.add(item.getKey(), item.getValue()); |
| 96 | - } else if (item.getType().equals(BpmListenerMapType.FROM_FORM.getType())) { | 103 | + } else if (item.getType().equals(BpmListenerParamTypeEnum.FROM_FORM.getType())) { |
| 97 | to.add(item.getKey(), processVariables.get(item.getValue()).toString()); | 104 | to.add(item.getKey(), processVariables.get(item.getValue()).toString()); |
| 98 | } | 105 | } |
| 99 | }); | 106 | }); |
| 100 | } | 107 | } |
| 101 | 108 | ||
| 102 | - // TODO @lesan:改成 jdk8 写法哈。主要考虑好兼容! | ||
| 103 | - private BpmSimpleModelNodeVO.ListenerHandler getListenerHandlerByEvent(String eventName, BpmSimpleModelNodeVO node) { | ||
| 104 | - return switch (eventName) { | ||
| 105 | - case TaskListener.EVENTNAME_CREATE -> node.getTaskCreateListener(); | ||
| 106 | - case TaskListener.EVENTNAME_ASSIGNMENT -> node.getTaskAssignListener(); | ||
| 107 | - case TaskListener.EVENTNAME_COMPLETE -> node.getTaskCompleteListener(); | ||
| 108 | - default -> null; // TODO @lesan:这个抛出异常,可控一点 | ||
| 109 | - }; | 109 | + private BpmSimpleModelNodeVO.ListenerHandler getListenerHandlerByEvent(String eventName, List<FlowableListener> node) { |
| 110 | + FlowableListener flowableListener = node.stream() | ||
| 111 | + .filter(item -> item.getEvent().equals(eventName)) | ||
| 112 | + .findFirst().orElse(null); | ||
| 113 | + Assert.notNull(flowableListener, "监听器({})不能为空", flowableListener); | ||
| 114 | + FieldExtension fieldExtension = flowableListener.getFieldExtensions().stream() | ||
| 115 | + .filter(item -> item.getFieldName().equals("listenerConfig")) | ||
| 116 | + .findFirst().orElse(null); | ||
| 117 | + Assert.notNull(fieldExtension, "监听器扩展字段({})不能为空", fieldExtension); | ||
| 118 | + return JsonUtils.parseObject(fieldExtension.getStringValue(), BpmSimpleModelNodeVO.ListenerHandler.class); | ||
| 110 | } | 119 | } |
| 111 | 120 | ||
| 112 | } | 121 | } |
| 113 | \ No newline at end of file | 122 | \ No newline at end of file |