【功能优化】 修改表单触发器增加条件设置
This commit is contained in:
parent
129e9868fb
commit
9a4bb60a78
|
@ -17,7 +17,7 @@ import java.util.Arrays;
|
||||||
public enum BpmTriggerTypeEnum implements ArrayValuable<Integer> {
|
public enum BpmTriggerTypeEnum implements ArrayValuable<Integer> {
|
||||||
|
|
||||||
HTTP_REQUEST(1, "发起 HTTP 请求"),
|
HTTP_REQUEST(1, "发起 HTTP 请求"),
|
||||||
UPDATE_NORMAL_FORM(2, "更新流程表单"); // TODO @jason:FORM_UPDATE
|
FORM_UPDATE(2, "更新流程表单");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 触发器执行动作类型
|
* 触发器执行动作类型
|
||||||
|
@ -39,5 +39,4 @@ public enum BpmTriggerTypeEnum implements ArrayValuable<Integer> {
|
||||||
public static BpmTriggerTypeEnum typeOf(Integer type) {
|
public static BpmTriggerTypeEnum typeOf(Integer type) {
|
||||||
return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
|
return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,12 +345,10 @@ public class BpmSimpleModelNodeVO {
|
||||||
@Valid
|
@Valid
|
||||||
private HttpRequestTriggerSetting httpRequestSetting;
|
private HttpRequestTriggerSetting httpRequestSetting;
|
||||||
|
|
||||||
// TODO @jason:这个要不直接叫 formSetting,更好理解一点哈
|
|
||||||
// TODO @jason:如果搞成 List<NormalFormTriggerSetting>,是不是可以做条件组了?微信讨论哈
|
|
||||||
/**
|
/**
|
||||||
* 流程表单触发器设置
|
* 流程表单触发器设置
|
||||||
*/
|
*/
|
||||||
private NormalFormTriggerSetting normalFormSetting;
|
private List<FormTriggerSetting> formSettings;
|
||||||
|
|
||||||
@Schema(description = "http 请求触发器设置", example = "{}")
|
@Schema(description = "http 请求触发器设置", example = "{}")
|
||||||
@Data
|
@Data
|
||||||
|
@ -383,12 +381,20 @@ public class BpmSimpleModelNodeVO {
|
||||||
|
|
||||||
@Schema(description = "流程表单触发器设置", example = "{}")
|
@Schema(description = "流程表单触发器设置", example = "{}")
|
||||||
@Data
|
@Data
|
||||||
public static class NormalFormTriggerSetting {
|
public static class FormTriggerSetting {
|
||||||
|
|
||||||
|
@Schema(description = "条件类型", example = "1")
|
||||||
|
@InEnum(BpmSimpleModeConditionTypeEnum.class)
|
||||||
|
private Integer conditionType;
|
||||||
|
|
||||||
|
@Schema(description = "条件表达式", example = "${day>3}")
|
||||||
|
private String conditionExpression;
|
||||||
|
|
||||||
|
@Schema(description = "条件组", example = "{}")
|
||||||
|
private ConditionGroups conditionGroups;
|
||||||
|
|
||||||
@Schema(description = "修改的表单字段", example = "userName")
|
@Schema(description = "修改的表单字段", example = "userName")
|
||||||
private Map<String, Object> updateFormFields;
|
private Map<String, Object> updateFormFields;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -724,8 +724,8 @@ public class SimpleModelUtils {
|
||||||
if (node.getTriggerSetting().getHttpRequestSetting() != null) {
|
if (node.getTriggerSetting().getHttpRequestSetting() != null) {
|
||||||
addExtensionElementJson(serviceTask, TRIGGER_PARAM, node.getTriggerSetting().getHttpRequestSetting());
|
addExtensionElementJson(serviceTask, TRIGGER_PARAM, node.getTriggerSetting().getHttpRequestSetting());
|
||||||
}
|
}
|
||||||
if (node.getTriggerSetting().getNormalFormSetting() != null) {
|
if (node.getTriggerSetting().getFormSettings() != null) {
|
||||||
addExtensionElementJson(serviceTask, TRIGGER_PARAM, node.getTriggerSetting().getNormalFormSetting());
|
addExtensionElementJson(serviceTask, TRIGGER_PARAM, node.getTriggerSetting().getFormSettings());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return serviceTask;
|
return serviceTask;
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package cn.iocoder.yudao.module.bpm.service.task.trigger;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||||
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.TriggerSetting.FormTriggerSetting;
|
||||||
|
import cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum;
|
||||||
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
|
||||||
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.SimpleModelUtils;
|
||||||
|
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BPM 更新流程表单触发器
|
||||||
|
*
|
||||||
|
* @author jason
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class BpmFormUpdateTrigger implements BpmTrigger {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private BpmProcessInstanceService processInstanceService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BpmTriggerTypeEnum getType() {
|
||||||
|
return BpmTriggerTypeEnum.FORM_UPDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(String processInstanceId, String param) {
|
||||||
|
// 1. 解析更新流程表单配置
|
||||||
|
List<FormTriggerSetting> settings = JsonUtils.parseObject(param, new TypeReference<>() {});
|
||||||
|
if (CollUtil.isEmpty(settings)) {
|
||||||
|
log.error("[execute][流程({}) 更新流程表单触发器配置为空]", processInstanceId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.获取流程变量
|
||||||
|
Map<String, Object> processVariables = processInstanceService.getProcessInstance(processInstanceId).getProcessVariables();
|
||||||
|
|
||||||
|
// 3.更新流程变量
|
||||||
|
for (FormTriggerSetting setting : settings) {
|
||||||
|
if (CollUtil.isEmpty(setting.getUpdateFormFields())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
boolean isFormUpdateNeeded = true;
|
||||||
|
if (setting.getConditionType() != null) { // 配置了条件,判断条件是否满足
|
||||||
|
String conditionExpression = SimpleModelUtils.buildConditionExpression(setting.getConditionType(), setting.getConditionExpression(),
|
||||||
|
setting.getConditionGroups());
|
||||||
|
isFormUpdateNeeded = BpmnModelUtils.evalConditionExpress(processVariables, conditionExpression);
|
||||||
|
}
|
||||||
|
if (isFormUpdateNeeded) {
|
||||||
|
processInstanceService.updateProcessInstanceVariables(processInstanceId, setting.getUpdateFormFields());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,44 +0,0 @@
|
||||||
package cn.iocoder.yudao.module.bpm.service.task.trigger;
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.TriggerSetting.NormalFormTriggerSetting;
|
|
||||||
import cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum;
|
|
||||||
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
// TODO @jason:改成 BpmFormUpdateTrigger
|
|
||||||
/**
|
|
||||||
* BPM 更新流程表单触发器
|
|
||||||
*
|
|
||||||
* @author jason
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class BpmUpdateNormalFormTrigger implements BpmTrigger {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private BpmProcessInstanceService processInstanceService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BpmTriggerTypeEnum getType() {
|
|
||||||
return BpmTriggerTypeEnum.UPDATE_NORMAL_FORM;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(String processInstanceId, String param) {
|
|
||||||
// 1. 解析更新流程表单配置
|
|
||||||
NormalFormTriggerSetting setting = JsonUtils.parseObject(param, NormalFormTriggerSetting.class);
|
|
||||||
if (setting == null) {
|
|
||||||
log.error("[execute][流程({}) 更新流程表单触发器配置为空]", processInstanceId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 2.更新流程变量
|
|
||||||
if (CollUtil.isNotEmpty(setting.getUpdateFormFields())) {
|
|
||||||
processInstanceService.updateProcessInstanceVariables(processInstanceId, setting.getUpdateFormFields());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue