Commit 9a4bb60a783d5c4f4f4bcaa2e09961ed525aec83
1 parent
129e9868
【功能优化】 修改表单触发器增加条件设置
Showing
4 changed files
with
44 additions
and
20 deletions
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmTriggerTypeEnum.java
| @@ -17,7 +17,7 @@ import java.util.Arrays; | @@ -17,7 +17,7 @@ import java.util.Arrays; | ||
| 17 | public enum BpmTriggerTypeEnum implements ArrayValuable<Integer> { | 17 | public enum BpmTriggerTypeEnum implements ArrayValuable<Integer> { |
| 18 | 18 | ||
| 19 | HTTP_REQUEST(1, "发起 HTTP 请求"), | 19 | HTTP_REQUEST(1, "发起 HTTP 请求"), |
| 20 | - UPDATE_NORMAL_FORM(2, "更新流程表单"); // TODO @jason:FORM_UPDATE | 20 | + FORM_UPDATE(2, "更新流程表单"); |
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | * 触发器执行动作类型 | 23 | * 触发器执行动作类型 |
| @@ -39,5 +39,4 @@ public enum BpmTriggerTypeEnum implements ArrayValuable<Integer> { | @@ -39,5 +39,4 @@ public enum BpmTriggerTypeEnum implements ArrayValuable<Integer> { | ||
| 39 | public static BpmTriggerTypeEnum typeOf(Integer type) { | 39 | public static BpmTriggerTypeEnum typeOf(Integer type) { |
| 40 | return ArrayUtil.firstMatch(item -> item.getType().equals(type), values()); | 40 | return ArrayUtil.firstMatch(item -> item.getType().equals(type), values()); |
| 41 | } | 41 | } |
| 42 | - | ||
| 43 | } | 42 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/simple/BpmSimpleModelNodeVO.java
| @@ -345,12 +345,10 @@ public class BpmSimpleModelNodeVO { | @@ -345,12 +345,10 @@ public class BpmSimpleModelNodeVO { | ||
| 345 | @Valid | 345 | @Valid |
| 346 | private HttpRequestTriggerSetting httpRequestSetting; | 346 | private HttpRequestTriggerSetting httpRequestSetting; |
| 347 | 347 | ||
| 348 | - // TODO @jason:这个要不直接叫 formSetting,更好理解一点哈 | ||
| 349 | - // TODO @jason:如果搞成 List<NormalFormTriggerSetting>,是不是可以做条件组了?微信讨论哈 | ||
| 350 | /** | 348 | /** |
| 351 | * 流程表单触发器设置 | 349 | * 流程表单触发器设置 |
| 352 | */ | 350 | */ |
| 353 | - private NormalFormTriggerSetting normalFormSetting; | 351 | + private List<FormTriggerSetting> formSettings; |
| 354 | 352 | ||
| 355 | @Schema(description = "http 请求触发器设置", example = "{}") | 353 | @Schema(description = "http 请求触发器设置", example = "{}") |
| 356 | @Data | 354 | @Data |
| @@ -383,12 +381,20 @@ public class BpmSimpleModelNodeVO { | @@ -383,12 +381,20 @@ public class BpmSimpleModelNodeVO { | ||
| 383 | 381 | ||
| 384 | @Schema(description = "流程表单触发器设置", example = "{}") | 382 | @Schema(description = "流程表单触发器设置", example = "{}") |
| 385 | @Data | 383 | @Data |
| 386 | - public static class NormalFormTriggerSetting { | 384 | + public static class FormTriggerSetting { |
| 385 | + | ||
| 386 | + @Schema(description = "条件类型", example = "1") | ||
| 387 | + @InEnum(BpmSimpleModeConditionTypeEnum.class) | ||
| 388 | + private Integer conditionType; | ||
| 389 | + | ||
| 390 | + @Schema(description = "条件表达式", example = "${day>3}") | ||
| 391 | + private String conditionExpression; | ||
| 392 | + | ||
| 393 | + @Schema(description = "条件组", example = "{}") | ||
| 394 | + private ConditionGroups conditionGroups; | ||
| 387 | 395 | ||
| 388 | @Schema(description = "修改的表单字段", example = "userName") | 396 | @Schema(description = "修改的表单字段", example = "userName") |
| 389 | private Map<String, Object> updateFormFields; | 397 | private Map<String, Object> updateFormFields; |
| 390 | - | ||
| 391 | } | 398 | } |
| 392 | - | ||
| 393 | } | 399 | } |
| 394 | } | 400 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
| @@ -724,8 +724,8 @@ public class SimpleModelUtils { | @@ -724,8 +724,8 @@ public class SimpleModelUtils { | ||
| 724 | if (node.getTriggerSetting().getHttpRequestSetting() != null) { | 724 | if (node.getTriggerSetting().getHttpRequestSetting() != null) { |
| 725 | addExtensionElementJson(serviceTask, TRIGGER_PARAM, node.getTriggerSetting().getHttpRequestSetting()); | 725 | addExtensionElementJson(serviceTask, TRIGGER_PARAM, node.getTriggerSetting().getHttpRequestSetting()); |
| 726 | } | 726 | } |
| 727 | - if (node.getTriggerSetting().getNormalFormSetting() != null) { | ||
| 728 | - addExtensionElementJson(serviceTask, TRIGGER_PARAM, node.getTriggerSetting().getNormalFormSetting()); | 727 | + if (node.getTriggerSetting().getFormSettings() != null) { |
| 728 | + addExtensionElementJson(serviceTask, TRIGGER_PARAM, node.getTriggerSetting().getFormSettings()); | ||
| 729 | } | 729 | } |
| 730 | } | 730 | } |
| 731 | return serviceTask; | 731 | return serviceTask; |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/trigger/BpmUpdateNormalFormTrigger.java renamed to yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/trigger/BpmFormUpdateTrigger.java
| @@ -2,14 +2,19 @@ package cn.iocoder.yudao.module.bpm.service.task.trigger; | @@ -2,14 +2,19 @@ package cn.iocoder.yudao.module.bpm.service.task.trigger; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 4 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 5 | -import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.TriggerSetting.NormalFormTriggerSetting; | 5 | +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.TriggerSetting.FormTriggerSetting; |
| 6 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum; | 6 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum; |
| 7 | +import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; | ||
| 8 | +import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.SimpleModelUtils; | ||
| 7 | import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; | 9 | import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; |
| 10 | +import com.fasterxml.jackson.core.type.TypeReference; | ||
| 8 | import jakarta.annotation.Resource; | 11 | import jakarta.annotation.Resource; |
| 9 | import lombok.extern.slf4j.Slf4j; | 12 | import lombok.extern.slf4j.Slf4j; |
| 10 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
| 11 | 14 | ||
| 12 | -// TODO @jason:改成 BpmFormUpdateTrigger | 15 | +import java.util.List; |
| 16 | +import java.util.Map; | ||
| 17 | + | ||
| 13 | /** | 18 | /** |
| 14 | * BPM 更新流程表单触发器 | 19 | * BPM 更新流程表单触发器 |
| 15 | * | 20 | * |
| @@ -17,28 +22,42 @@ import org.springframework.stereotype.Component; | @@ -17,28 +22,42 @@ import org.springframework.stereotype.Component; | ||
| 17 | */ | 22 | */ |
| 18 | @Component | 23 | @Component |
| 19 | @Slf4j | 24 | @Slf4j |
| 20 | -public class BpmUpdateNormalFormTrigger implements BpmTrigger { | 25 | +public class BpmFormUpdateTrigger implements BpmTrigger { |
| 21 | 26 | ||
| 22 | @Resource | 27 | @Resource |
| 23 | private BpmProcessInstanceService processInstanceService; | 28 | private BpmProcessInstanceService processInstanceService; |
| 24 | 29 | ||
| 25 | @Override | 30 | @Override |
| 26 | public BpmTriggerTypeEnum getType() { | 31 | public BpmTriggerTypeEnum getType() { |
| 27 | - return BpmTriggerTypeEnum.UPDATE_NORMAL_FORM; | 32 | + return BpmTriggerTypeEnum.FORM_UPDATE; |
| 28 | } | 33 | } |
| 29 | 34 | ||
| 30 | @Override | 35 | @Override |
| 31 | public void execute(String processInstanceId, String param) { | 36 | public void execute(String processInstanceId, String param) { |
| 32 | // 1. 解析更新流程表单配置 | 37 | // 1. 解析更新流程表单配置 |
| 33 | - NormalFormTriggerSetting setting = JsonUtils.parseObject(param, NormalFormTriggerSetting.class); | ||
| 34 | - if (setting == null) { | 38 | + List<FormTriggerSetting> settings = JsonUtils.parseObject(param, new TypeReference<>() {}); |
| 39 | + if (CollUtil.isEmpty(settings)) { | ||
| 35 | log.error("[execute][流程({}) 更新流程表单触发器配置为空]", processInstanceId); | 40 | log.error("[execute][流程({}) 更新流程表单触发器配置为空]", processInstanceId); |
| 36 | return; | 41 | return; |
| 37 | } | 42 | } |
| 38 | - // 2.更新流程变量 | ||
| 39 | - if (CollUtil.isNotEmpty(setting.getUpdateFormFields())) { | ||
| 40 | - processInstanceService.updateProcessInstanceVariables(processInstanceId, setting.getUpdateFormFields()); | 43 | + |
| 44 | + // 2.获取流程变量 | ||
| 45 | + Map<String, Object> processVariables = processInstanceService.getProcessInstance(processInstanceId).getProcessVariables(); | ||
| 46 | + | ||
| 47 | + // 3.更新流程变量 | ||
| 48 | + for (FormTriggerSetting setting : settings) { | ||
| 49 | + if (CollUtil.isEmpty(setting.getUpdateFormFields())) { | ||
| 50 | + continue; | ||
| 51 | + } | ||
| 52 | + boolean isFormUpdateNeeded = true; | ||
| 53 | + if (setting.getConditionType() != null) { // 配置了条件,判断条件是否满足 | ||
| 54 | + String conditionExpression = SimpleModelUtils.buildConditionExpression(setting.getConditionType(), setting.getConditionExpression(), | ||
| 55 | + setting.getConditionGroups()); | ||
| 56 | + isFormUpdateNeeded = BpmnModelUtils.evalConditionExpress(processVariables, conditionExpression); | ||
| 57 | + } | ||
| 58 | + if (isFormUpdateNeeded) { | ||
| 59 | + processInstanceService.updateProcessInstanceVariables(processInstanceId, setting.getUpdateFormFields()); | ||
| 60 | + } | ||
| 41 | } | 61 | } |
| 42 | } | 62 | } |
| 43 | - | ||
| 44 | } | 63 | } |