【代码评审】Bpm:触发器的实现

This commit is contained in:
YunaiV 2025-01-23 08:13:06 +08:00
parent 808f23ec49
commit 61e3275231
24 changed files with 165 additions and 155 deletions

View File

@ -13,13 +13,13 @@ import java.util.Arrays;
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BpmAutoApproveType implements IntArrayValuable { public enum BpmAutoApproveTypeEnum implements IntArrayValuable {
NONE(0, "不自动通过"), NONE(0, "不自动通过"),
APPROVE_ALL(1, "仅审批一次,后续重复的审批节点均自动通过"), APPROVE_ALL(1, "仅审批一次,后续重复的审批节点均自动通过"),
APPROVE_SEQUENT(2, "仅针对连续审批的节点自动通过"); APPROVE_SEQUENT(2, "仅针对连续审批的节点自动通过");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmAutoApproveType::getType).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmAutoApproveTypeEnum::getType).toArray();
private final Integer type; private final Integer type;
private final String name; private final String name;

View File

@ -11,7 +11,7 @@ import lombok.Getter;
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BpmBoundaryEventType { public enum BpmBoundaryEventTypeEnum {
USER_TASK_TIMEOUT(1, "用户任务超时"), USER_TASK_TIMEOUT(1, "用户任务超时"),
DELAY_TIMER_TIMEOUT(2, "延迟器超时"); DELAY_TIMER_TIMEOUT(2, "延迟器超时");
@ -19,7 +19,7 @@ public enum BpmBoundaryEventType {
private final Integer type; private final Integer type;
private final String name; private final String name;
public static BpmBoundaryEventType typeOf(Integer type) { public static BpmBoundaryEventTypeEnum typeOf(Integer type) {
return ArrayUtil.firstMatch(eventType -> eventType.getType().equals(type), values()); return ArrayUtil.firstMatch(eventType -> eventType.getType().equals(type), values());
} }

View File

@ -13,7 +13,7 @@ import java.util.Arrays;
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BpmDelayTimerType implements IntArrayValuable { public enum BpmDelayTimerTypeEnum implements IntArrayValuable {
FIXED_TIME_DURATION(1, "固定时长"), FIXED_TIME_DURATION(1, "固定时长"),
FIXED_DATE_TIME(2, "固定日期"); FIXED_DATE_TIME(2, "固定日期");
@ -21,7 +21,7 @@ public enum BpmDelayTimerType implements IntArrayValuable {
private final Integer type; private final Integer type;
private final String name; private final String name;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmDelayTimerType::getType).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmDelayTimerTypeEnum::getType).toArray();
@Override @Override
public int[] array() { public int[] array() {

View File

@ -13,7 +13,7 @@ import java.util.Arrays;
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BpmHttpRequestParamSettingType implements IntArrayValuable { public enum BpmHttpRequestParamTypeEnum implements IntArrayValuable {
FIXED_VALUE(1, "固定值"), FIXED_VALUE(1, "固定值"),
FROM_FORM(2, "表单"); FROM_FORM(2, "表单");
@ -21,7 +21,7 @@ public enum BpmHttpRequestParamSettingType implements IntArrayValuable {
private final Integer type; private final Integer type;
private final String name; private final String name;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmHttpRequestParamSettingType::getType).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmHttpRequestParamTypeEnum::getType).toArray();
@Override @Override
public int[] array() { public int[] array() {

View File

@ -10,7 +10,7 @@ import lombok.Getter;
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BpmProcessListenerType { public enum BpmProcessListenerTypeEnum {
EXECUTION("execution", "执行监听器"), EXECUTION("execution", "执行监听器"),
TASK("task", "任务执行器"); TASK("task", "任务执行器");

View File

@ -10,7 +10,7 @@ import lombok.Getter;
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BpmProcessListenerValueType { public enum BpmProcessListenerValueTypeEnum {
CLASS("class", "Java 类"), CLASS("class", "Java 类"),
DELEGATE_EXPRESSION("delegateExpression", "代理表达式"), DELEGATE_EXPRESSION("delegateExpression", "代理表达式"),

View File

@ -14,18 +14,18 @@ import java.util.Arrays;
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BpmSimpleModeConditionType implements IntArrayValuable { public enum BpmSimpleModeConditionTypeEnum implements IntArrayValuable {
EXPRESSION(1, "条件表达式"), EXPRESSION(1, "条件表达式"),
RULE(2, "条件规则"); RULE(2, "条件规则");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmSimpleModeConditionType::getType).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmSimpleModeConditionTypeEnum::getType).toArray();
private final Integer type; private final Integer type;
private final String name; private final String name;
public static BpmSimpleModeConditionType valueOf(Integer type) { public static BpmSimpleModeConditionTypeEnum valueOf(Integer type) {
return ArrayUtil.firstMatch(nodeType -> nodeType.getType().equals(type), values()); return ArrayUtil.firstMatch(nodeType -> nodeType.getType().equals(type), values());
} }

View File

@ -15,7 +15,7 @@ import java.util.Objects;
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BpmSimpleModelNodeType implements IntArrayValuable { public enum BpmSimpleModelNodeTypeEnum implements IntArrayValuable {
// 0 ~ 1 开始和结束 // 0 ~ 1 开始和结束
START_NODE(0, "开始", "startEvent"), START_NODE(0, "开始", "startEvent"),
@ -37,7 +37,7 @@ public enum BpmSimpleModelNodeType implements IntArrayValuable {
ROUTER_BRANCH_NODE(54, "路由分支", "exclusiveGateway") ROUTER_BRANCH_NODE(54, "路由分支", "exclusiveGateway")
; ;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmSimpleModelNodeType::getType).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmSimpleModelNodeTypeEnum::getType).toArray();
private final Integer type; private final Integer type;
private final String name; private final String name;
@ -55,7 +55,7 @@ public enum BpmSimpleModelNodeType implements IntArrayValuable {
|| Objects.equals(ROUTER_BRANCH_NODE.getType(), type); || Objects.equals(ROUTER_BRANCH_NODE.getType(), type);
} }
public static BpmSimpleModelNodeType valueOf(Integer type) { public static BpmSimpleModelNodeTypeEnum valueOf(Integer type) {
return ArrayUtil.firstMatch(nodeType -> nodeType.getType().equals(type), values()); return ArrayUtil.firstMatch(nodeType -> nodeType.getType().equals(type), values());
} }

View File

@ -14,7 +14,7 @@ import java.util.Arrays;
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BpmTriggerType implements IntArrayValuable { public enum BpmTriggerTypeEnum implements IntArrayValuable {
HTTP_REQUEST(1, "发起 HTTP 请求"); HTTP_REQUEST(1, "发起 HTTP 请求");
@ -28,14 +28,14 @@ public enum BpmTriggerType implements IntArrayValuable {
*/ */
private final String desc; private final String desc;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmTriggerType::getType).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmTriggerTypeEnum::getType).toArray();
@Override @Override
public int[] array() { public int[] array() {
return ARRAYS; return ARRAYS;
} }
public static BpmTriggerType 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());
} }
} }

View File

@ -14,7 +14,7 @@ import java.util.Arrays;
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BpmUserTaskRejectHandlerType implements IntArrayValuable { public enum BpmUserTaskRejectHandlerTypeEnum implements IntArrayValuable {
FINISH_PROCESS_INSTANCE(1, "终止流程"), FINISH_PROCESS_INSTANCE(1, "终止流程"),
RETURN_USER_TASK(2, "驳回到指定任务节点"); RETURN_USER_TASK(2, "驳回到指定任务节点");
@ -22,9 +22,9 @@ public enum BpmUserTaskRejectHandlerType implements IntArrayValuable {
private final Integer type; private final Integer type;
private final String name; private final String name;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmUserTaskRejectHandlerType::getType).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmUserTaskRejectHandlerTypeEnum::getType).toArray();
public static BpmUserTaskRejectHandlerType typeOf(Integer type) { public static BpmUserTaskRejectHandlerTypeEnum typeOf(Integer type) {
return ArrayUtil.firstMatch(item -> item.getType().equals(type), values()); return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
} }

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model; package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmAutoApproveType; import cn.iocoder.yudao.module.bpm.enums.definition.BpmAutoApproveTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum; import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@ -71,7 +71,7 @@ public class BpmModelMetaInfoVO {
private ProcessIdRule processIdRule; private ProcessIdRule processIdRule;
@Schema(description = "自动去重类型", example = "1") @Schema(description = "自动去重类型", example = "1")
@InEnum(BpmAutoApproveType.class) @InEnum(BpmAutoApproveTypeEnum.class)
private Integer autoApprovalType; private Integer autoApprovalType;
@Schema(description = "流程 ID 规则") @Schema(description = "流程 ID 规则")

View File

@ -25,7 +25,7 @@ public class BpmSimpleModelNodeVO {
@Schema(description = "模型节点类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "模型节点类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "模型节点类型不能为空") @NotNull(message = "模型节点类型不能为空")
@InEnum(BpmSimpleModelNodeType.class) @InEnum(BpmSimpleModelNodeTypeEnum.class)
private Integer type; private Integer type;
@Schema(description = "模型节点名称", example = "领导审批") @Schema(description = "模型节点名称", example = "领导审批")
@ -134,18 +134,19 @@ public class BpmSimpleModelNodeVO {
private String path; private String path;
@Schema(description = "请求头", example = "[]") @Schema(description = "请求头", example = "[]")
private List<HttpRequestParamSetting> header; private List<HttpRequestParam> header;
@Schema(description = "请求体", example = "[]") @Schema(description = "请求体", example = "[]")
private List<HttpRequestParamSetting> body; private List<HttpRequestParam> body;
} }
@Schema(description = "HTTP 请求参数设置") @Schema(description = "HTTP 请求参数设置")
@Data @Data
public static class HttpRequestParamSetting { public static class HttpRequestParam {
@Schema(description = "值类型", example = "1") @Schema(description = "值类型", example = "1")
@InEnum(BpmHttpRequestParamSettingType.class) @InEnum(BpmHttpRequestParamTypeEnum.class)
@NotNull(message = "值类型不能为空") @NotNull(message = "值类型不能为空")
private Integer type; private Integer type;
@ -163,7 +164,7 @@ public class BpmSimpleModelNodeVO {
public static class RejectHandler { public static class RejectHandler {
@Schema(description = "拒绝处理类型", example = "1") @Schema(description = "拒绝处理类型", example = "1")
@InEnum(BpmUserTaskRejectHandlerType.class) @InEnum(BpmUserTaskRejectHandlerTypeEnum.class)
private Integer type; private Integer type;
@Schema(description = "任务拒绝后驳回的节点 Id", example = "Activity_1") @Schema(description = "任务拒绝后驳回的节点 Id", example = "Activity_1")
@ -229,7 +230,7 @@ public class BpmSimpleModelNodeVO {
public static class ConditionSetting { public static class ConditionSetting {
@Schema(description = "条件类型", example = "1") @Schema(description = "条件类型", example = "1")
@InEnum(BpmSimpleModeConditionType.class) @InEnum(BpmSimpleModeConditionTypeEnum.class)
private Integer conditionType; private Integer conditionType;
@Schema(description = "条件表达式", example = "${day>3}") @Schema(description = "条件表达式", example = "${day>3}")
@ -297,7 +298,7 @@ public class BpmSimpleModelNodeVO {
@Schema(description = "延迟时间类型", example = "1") @Schema(description = "延迟时间类型", example = "1")
@NotNull(message = "延迟时间类型不能为空") @NotNull(message = "延迟时间类型不能为空")
@InEnum(BpmDelayTimerType.class) @InEnum(BpmDelayTimerTypeEnum.class)
private Integer delayType; private Integer delayType;
@Schema(description = "延迟时间表达式", example = "PT1H,2025-01-01T00:00:00") @Schema(description = "延迟时间表达式", example = "PT1H,2025-01-01T00:00:00")
@ -315,7 +316,7 @@ public class BpmSimpleModelNodeVO {
private String nodeId; private String nodeId;
@Schema(description = "条件类型", example = "1") @Schema(description = "条件类型", example = "1")
@InEnum(BpmSimpleModeConditionType.class) @InEnum(BpmSimpleModeConditionTypeEnum.class)
@NotNull(message = "条件类型不能为空") @NotNull(message = "条件类型不能为空")
private Integer conditionType; private Integer conditionType;
@ -332,7 +333,7 @@ public class BpmSimpleModelNodeVO {
public static class TriggerSetting { public static class TriggerSetting {
@Schema(description = "触发器类型", example = "1") @Schema(description = "触发器类型", example = "1")
@InEnum(BpmTriggerType.class) @InEnum(BpmTriggerTypeEnum.class)
@NotNull(message = "触发器类型不能为空") @NotNull(message = "触发器类型不能为空")
private Integer type; private Integer type;
@ -353,11 +354,12 @@ public class BpmSimpleModelNodeVO {
@Schema(description = "请求头参数设置", example = "[]") @Schema(description = "请求头参数设置", example = "[]")
@Valid @Valid
private List<HttpRequestParamSetting> header; private List<HttpRequestParam> header;
@Schema(description = "请求头参数设置", example = "[]") @Schema(description = "请求头参数设置", example = "[]")
@Valid @Valid
private List<HttpRequestParamSetting> body; private List<HttpRequestParam> body;
} }
} }
} }

View File

@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
import cn.iocoder.yudao.framework.mybatis.core.type.StringListTypeHandler; import cn.iocoder.yudao.framework.mybatis.core.type.StringListTypeHandler;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmAutoApproveTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum; import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
@ -165,7 +166,7 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
/** /**
* 自动去重类型 * 自动去重类型
* *
* 枚举 {@link cn.iocoder.yudao.module.bpm.enums.definition.BpmAutoApproveType} * 枚举 {@link BpmAutoApproveTypeEnum}
*/ */
private Integer autoApprovalType; private Integer autoApprovalType;

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.bpm.dal.dataobject.definition; package cn.iocoder.yudao.module.bpm.dal.dataobject.definition;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmProcessListenerTypeEnum;
import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
@ -42,7 +43,7 @@ public class BpmProcessListenerDO extends BaseDO {
/** /**
* 监听类型 * 监听类型
* *
* 枚举 {@link cn.iocoder.yudao.module.bpm.enums.definition.BpmProcessListenerType} * 枚举 {@link BpmProcessListenerTypeEnum}
* *
* 1. executionExecutionListener <a href="https://tkjohn.github.io/flowable-userguide/#executionListeners">执行监听器</a> * 1. executionExecutionListener <a href="https://tkjohn.github.io/flowable-userguide/#executionListeners">执行监听器</a>
* 2. taskTaskListener <a href="https://tkjohn.github.io/flowable-userguide/#taskListeners">任务监听器</a> * 2. taskTaskListener <a href="https://tkjohn.github.io/flowable-userguide/#taskListeners">任务监听器</a>

View File

@ -104,7 +104,6 @@ public interface BpmnModelConstants {
* BPMN ExtensionElement 的扩展属性用于标记触发器的类型 * BPMN ExtensionElement 的扩展属性用于标记触发器的类型
*/ */
String TRIGGER_TYPE = "triggerType"; String TRIGGER_TYPE = "triggerType";
/** /**
* BPMN ExtensionElement 的扩展属性用于标记触发器参数 * BPMN ExtensionElement 的扩展属性用于标记触发器参数
*/ */

View File

@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmBoundaryEventType; import cn.iocoder.yudao.module.bpm.enums.definition.BpmBoundaryEventTypeEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants; import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService; import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
@ -97,17 +97,17 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
BoundaryEvent boundaryEvent = (BoundaryEvent) element; BoundaryEvent boundaryEvent = (BoundaryEvent) element;
String boundaryEventType = BpmnModelUtils.parseBoundaryEventExtensionElement(boundaryEvent, String boundaryEventType = BpmnModelUtils.parseBoundaryEventExtensionElement(boundaryEvent,
BpmnModelConstants.BOUNDARY_EVENT_TYPE); BpmnModelConstants.BOUNDARY_EVENT_TYPE);
BpmBoundaryEventType bpmTimerBoundaryEventType = BpmBoundaryEventType.typeOf(NumberUtils.parseInt(boundaryEventType)); BpmBoundaryEventTypeEnum bpmTimerBoundaryEventType = BpmBoundaryEventTypeEnum.typeOf(NumberUtils.parseInt(boundaryEventType));
// 2. 处理超时 // 2. 处理超时
if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventType.USER_TASK_TIMEOUT)) { if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.USER_TASK_TIMEOUT)) {
// 2.1 用户任务超时处理 // 2.1 用户任务超时处理
String timeoutHandlerType = BpmnModelUtils.parseBoundaryEventExtensionElement(boundaryEvent, String timeoutHandlerType = BpmnModelUtils.parseBoundaryEventExtensionElement(boundaryEvent,
BpmnModelConstants.USER_TASK_TIMEOUT_HANDLER_TYPE); BpmnModelConstants.USER_TASK_TIMEOUT_HANDLER_TYPE);
String taskKey = boundaryEvent.getAttachedToRefId(); String taskKey = boundaryEvent.getAttachedToRefId();
taskService.processTaskTimeout(event.getProcessInstanceId(), taskKey, NumberUtils.parseInt(timeoutHandlerType)); taskService.processTaskTimeout(event.getProcessInstanceId(), taskKey, NumberUtils.parseInt(timeoutHandlerType));
// 2.2 延迟器超时处理 // 2.2 延迟器超时处理
} else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventType.DELAY_TIMER_TIMEOUT)) { } else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT)) {
String taskKey = boundaryEvent.getAttachedToRefId(); String taskKey = boundaryEvent.getAttachedToRefId();
taskService.processDelayTimerTimeout(event.getProcessInstanceId(), taskKey); taskService.processDelayTimerTimeout(event.getProcessInstanceId(), taskKey);
} }

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener; package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerType; 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.BpmnModelUtils;
import cn.iocoder.yudao.module.bpm.service.task.trigger.BpmTrigger; import cn.iocoder.yudao.module.bpm.service.task.trigger.BpmTrigger;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
@ -33,7 +33,7 @@ public class BpmTriggerTaskDelegate implements JavaDelegate {
@Resource @Resource
private List<BpmTrigger> triggers; private List<BpmTrigger> triggers;
private final EnumMap<BpmTriggerType, BpmTrigger> triggerMap = new EnumMap<>(BpmTriggerType.class); private final EnumMap<BpmTriggerTypeEnum, BpmTrigger> triggerMap = new EnumMap<>(BpmTriggerTypeEnum.class);
@PostConstruct @PostConstruct
private void init() { private void init() {
@ -43,12 +43,13 @@ public class BpmTriggerTaskDelegate implements JavaDelegate {
@Override @Override
public void execute(DelegateExecution execution) { public void execute(DelegateExecution execution) {
FlowElement flowElement = execution.getCurrentFlowElement(); FlowElement flowElement = execution.getCurrentFlowElement();
BpmTriggerType bpmTriggerType = BpmnModelUtils.parserTriggerType(flowElement); BpmTriggerTypeEnum bpmTriggerType = BpmnModelUtils.parserTriggerType(flowElement);
BpmTrigger bpmTrigger = triggerMap.get(bpmTriggerType); BpmTrigger bpmTrigger = triggerMap.get(bpmTriggerType);
if (bpmTrigger == null) { if (bpmTrigger == null) {
log.error("[execute], FlowElement[{}], {} 找不到匹配的 BpmTrigger", execution.getCurrentActivityId(), flowElement); log.error("[execute][FlowElement({}), {} 找不到匹配的触发器]", execution.getCurrentActivityId(), flowElement);
return; return;
} }
bpmTrigger.execute(execution.getProcessInstanceId(), BpmnModelUtils.parserTriggerParam(flowElement)); bpmTrigger.execute(execution.getProcessInstanceId(), BpmnModelUtils.parserTriggerParam(flowElement));
} }
} }

View File

@ -171,9 +171,9 @@ public class BpmnModelUtils {
* @param userTask 任务节点 * @param userTask 任务节点
* @return 任务拒绝处理类型 * @return 任务拒绝处理类型
*/ */
public static BpmUserTaskRejectHandlerType parseRejectHandlerType(FlowElement userTask) { public static BpmUserTaskRejectHandlerTypeEnum parseRejectHandlerType(FlowElement userTask) {
Integer rejectHandlerType = NumberUtils.parseInt(parseExtensionElement(userTask, USER_TASK_REJECT_HANDLER_TYPE)); Integer rejectHandlerType = NumberUtils.parseInt(parseExtensionElement(userTask, USER_TASK_REJECT_HANDLER_TYPE));
return BpmUserTaskRejectHandlerType.typeOf(rejectHandlerType); return BpmUserTaskRejectHandlerTypeEnum.typeOf(rejectHandlerType);
} }
/** /**
@ -394,9 +394,9 @@ public class BpmnModelUtils {
return JsonUtils.parseObject(expressionText, BpmSimpleModelNodeVO.ListenerHandler.class); return JsonUtils.parseObject(expressionText, BpmSimpleModelNodeVO.ListenerHandler.class);
} }
public static BpmTriggerType parserTriggerType(FlowElement flowElement) { public static BpmTriggerTypeEnum parserTriggerType(FlowElement flowElement) {
Integer triggerType = NumberUtils.parseInt(parseExtensionElement(flowElement, TRIGGER_TYPE)); Integer triggerType = NumberUtils.parseInt(parseExtensionElement(flowElement, TRIGGER_TYPE));
return BpmTriggerType.typeOf(triggerType); return BpmTriggerTypeEnum.typeOf(triggerType);
} }
public static String parserTriggerParam(FlowElement flowElement) { public static String parserTriggerParam(FlowElement flowElement) {
@ -834,7 +834,7 @@ public class BpmnModelUtils {
Object result = FlowableUtils.getExpressionValue(variables, express); Object result = FlowableUtils.getExpressionValue(variables, express);
return Boolean.TRUE.equals(result); return Boolean.TRUE.equals(result);
} catch (FlowableException ex) { } catch (FlowableException ex) {
log.error("[evalConditionExpress][条件表达式({}) 变量({}) 解析报错", express, variables, ex); log.error("[evalConditionExpress][条件表达式({}) 变量({}) 解析报错]", express, variables, ex);
return Boolean.FALSE; return Boolean.FALSE;
} }
} }

View File

@ -37,7 +37,7 @@ import static java.util.Arrays.asList;
*/ */
public class SimpleModelUtils { public class SimpleModelUtils {
private static final Map<BpmSimpleModelNodeType, NodeConvert> NODE_CONVERTS = MapUtil.newHashMap(); private static final Map<BpmSimpleModelNodeTypeEnum, NodeConvert> NODE_CONVERTS = MapUtil.newHashMap();
static { static {
List<NodeConvert> converts = asList(new StartNodeConvert(), new EndNodeConvert(), List<NodeConvert> converts = asList(new StartNodeConvert(), new EndNodeConvert(),
@ -89,8 +89,8 @@ public class SimpleModelUtils {
private static BpmSimpleModelNodeVO buildStartNode() { private static BpmSimpleModelNodeVO buildStartNode() {
return new BpmSimpleModelNodeVO().setId(START_EVENT_NODE_ID) return new BpmSimpleModelNodeVO().setId(START_EVENT_NODE_ID)
.setName(BpmSimpleModelNodeType.START_NODE.getName()) .setName(BpmSimpleModelNodeTypeEnum.START_NODE.getName())
.setType(BpmSimpleModelNodeType.START_NODE.getType()); .setType(BpmSimpleModelNodeTypeEnum.START_NODE.getType());
} }
/** /**
@ -104,7 +104,7 @@ public class SimpleModelUtils {
if (!isValidNode(node)) { if (!isValidNode(node)) {
return; return;
} }
BpmSimpleModelNodeType nodeType = BpmSimpleModelNodeType.valueOf(node.getType()); BpmSimpleModelNodeTypeEnum nodeType = BpmSimpleModelNodeTypeEnum.valueOf(node.getType());
Assert.notNull(nodeType, "模型节点类型({})不支持", node.getType()); Assert.notNull(nodeType, "模型节点类型({})不支持", node.getType());
// 2. 处理当前节点 // 2. 处理当前节点
@ -114,7 +114,7 @@ public class SimpleModelUtils {
flowElements.forEach(process::addFlowElement); flowElements.forEach(process::addFlowElement);
// 3.1 情况一如果当前是分支节点并且存在条件节点则处理每个条件的子节点 // 3.1 情况一如果当前是分支节点并且存在条件节点则处理每个条件的子节点
if (BpmSimpleModelNodeType.isBranchNode(node.getType()) if (BpmSimpleModelNodeTypeEnum.isBranchNode(node.getType())
&& CollUtil.isNotEmpty(node.getConditionNodes())) { && CollUtil.isNotEmpty(node.getConditionNodes())) {
// 注意这里的 item.getChildNode() 处理的是每个条件的子节点不是处理条件 // 注意这里的 item.getChildNode() 处理的是每个条件的子节点不是处理条件
node.getConditionNodes().forEach(item -> traverseNodeToBuildFlowNode(item.getChildNode(), process)); node.getConditionNodes().forEach(item -> traverseNodeToBuildFlowNode(item.getChildNode(), process));
@ -137,14 +137,14 @@ public class SimpleModelUtils {
return; return;
} }
// 1.2 END_NODE 直接返回 // 1.2 END_NODE 直接返回
BpmSimpleModelNodeType nodeType = BpmSimpleModelNodeType.valueOf(node.getType()); BpmSimpleModelNodeTypeEnum nodeType = BpmSimpleModelNodeTypeEnum.valueOf(node.getType());
Assert.notNull(nodeType, "模型节点类型不支持"); Assert.notNull(nodeType, "模型节点类型不支持");
if (nodeType == BpmSimpleModelNodeType.END_NODE) { if (nodeType == BpmSimpleModelNodeTypeEnum.END_NODE) {
return; return;
} }
// 2.1 情况一普通节点 // 2.1 情况一普通节点
if (!BpmSimpleModelNodeType.isBranchNode(node.getType())) { if (!BpmSimpleModelNodeTypeEnum.isBranchNode(node.getType())) {
traverseNormalNodeToBuildSequenceFlow(process, node, targetNodeId); traverseNormalNodeToBuildSequenceFlow(process, node, targetNodeId);
} else { } else {
// 2.2 情况二分支节点 // 2.2 情况二分支节点
@ -182,26 +182,26 @@ public class SimpleModelUtils {
* @param targetNodeId 目标节点 ID * @param targetNodeId 目标节点 ID
*/ */
private static void traverseBranchNodeToBuildSequenceFlow(Process process, BpmSimpleModelNodeVO node, String targetNodeId) { private static void traverseBranchNodeToBuildSequenceFlow(Process process, BpmSimpleModelNodeVO node, String targetNodeId) {
BpmSimpleModelNodeType nodeType = BpmSimpleModelNodeType.valueOf(node.getType()); BpmSimpleModelNodeTypeEnum nodeType = BpmSimpleModelNodeTypeEnum.valueOf(node.getType());
BpmSimpleModelNodeVO childNode = node.getChildNode(); BpmSimpleModelNodeVO childNode = node.getChildNode();
List<BpmSimpleModelNodeVO> conditionNodes = node.getConditionNodes(); List<BpmSimpleModelNodeVO> conditionNodes = node.getConditionNodes();
// TODO @芋艿 路由分支没有conditionNodes 这里注释会影响吗@jason一起帮忙瞅瞅 // TODO @芋艿 路由分支没有conditionNodes 这里注释会影响吗@jason一起帮忙瞅瞅
// Assert.notEmpty(conditionNodes, "分支节点的条件节点不能为空"); // Assert.notEmpty(conditionNodes, "分支节点的条件节点不能为空");
// 分支终点节点 ID // 分支终点节点 ID
String branchEndNodeId = null; String branchEndNodeId = null;
if (nodeType == BpmSimpleModelNodeType.CONDITION_BRANCH_NODE if (nodeType == BpmSimpleModelNodeTypeEnum.CONDITION_BRANCH_NODE
|| nodeType == BpmSimpleModelNodeType.ROUTER_BRANCH_NODE) { // 条件分支或路由分支 || nodeType == BpmSimpleModelNodeTypeEnum.ROUTER_BRANCH_NODE) { // 条件分支或路由分支
// 分两种情况 1. 分支节点有孩子节点为孩子节点 Id 2. 分支节点孩子为无效节点时 (分支嵌套且为分支最后一个节点) 为分支终点节点 ID // 分两种情况 1. 分支节点有孩子节点为孩子节点 Id 2. 分支节点孩子为无效节点时 (分支嵌套且为分支最后一个节点) 为分支终点节点 ID
branchEndNodeId = isValidNode(childNode) ? childNode.getId() : targetNodeId; branchEndNodeId = isValidNode(childNode) ? childNode.getId() : targetNodeId;
} else if (nodeType == BpmSimpleModelNodeType.PARALLEL_BRANCH_NODE } else if (nodeType == BpmSimpleModelNodeTypeEnum.PARALLEL_BRANCH_NODE
|| nodeType == BpmSimpleModelNodeType.INCLUSIVE_BRANCH_NODE) { // 并行分支或包容分支 || nodeType == BpmSimpleModelNodeTypeEnum.INCLUSIVE_BRANCH_NODE) { // 并行分支或包容分支
// 分支节点分支终点节点 Id 为程序创建的网关集合节点目前不会从前端传入 // 分支节点分支终点节点 Id 为程序创建的网关集合节点目前不会从前端传入
branchEndNodeId = buildGatewayJoinId(node.getId()); branchEndNodeId = buildGatewayJoinId(node.getId());
} }
Assert.notEmpty(branchEndNodeId, "分支终点节点 Id 不能为空"); Assert.notEmpty(branchEndNodeId, "分支终点节点 Id 不能为空");
// 3. 遍历分支节点 // 3. 遍历分支节点
if (nodeType == BpmSimpleModelNodeType.ROUTER_BRANCH_NODE) { if (nodeType == BpmSimpleModelNodeTypeEnum.ROUTER_BRANCH_NODE) {
// 路由分支遍历 // 路由分支遍历
for (BpmSimpleModelNodeVO.RouterSetting router : node.getRouterGroups()) { for (BpmSimpleModelNodeVO.RouterSetting router : node.getRouterGroups()) {
SequenceFlow sequenceFlow = RouteBranchNodeConvert.buildSequenceFlow(node.getId(), router); SequenceFlow sequenceFlow = RouteBranchNodeConvert.buildSequenceFlow(node.getId(), router);
@ -210,7 +210,7 @@ public class SimpleModelUtils {
} else { } else {
// 下面的注释以如下情况举例子分支 1A->B->C->D->E分支 2A->D->E其中A 为分支节点, D A 孩子节点 // 下面的注释以如下情况举例子分支 1A->B->C->D->E分支 2A->D->E其中A 为分支节点, D A 孩子节点
for (BpmSimpleModelNodeVO item : conditionNodes) { for (BpmSimpleModelNodeVO item : conditionNodes) {
Assert.isTrue(Objects.equals(item.getType(), BpmSimpleModelNodeType.CONDITION_NODE.getType()), Assert.isTrue(Objects.equals(item.getType(), BpmSimpleModelNodeTypeEnum.CONDITION_NODE.getType()),
"条件节点类型({})不符合", item.getType()); "条件节点类型({})不符合", item.getType());
BpmSimpleModelNodeVO conditionChildNode = item.getChildNode(); BpmSimpleModelNodeVO conditionChildNode = item.getChildNode();
// 3.1 分支有后续节点即分支 1: A->B->C->D 的情况 // 3.1 分支有后续节点即分支 1: A->B->C->D 的情况
@ -229,13 +229,13 @@ public class SimpleModelUtils {
} }
// 4.1 如果是并行分支包容分支由于是程序创建的聚合网关需要手工创建聚合网关和下一个节点的连线 // 4.1 如果是并行分支包容分支由于是程序创建的聚合网关需要手工创建聚合网关和下一个节点的连线
if (nodeType == BpmSimpleModelNodeType.PARALLEL_BRANCH_NODE if (nodeType == BpmSimpleModelNodeTypeEnum.PARALLEL_BRANCH_NODE
|| nodeType == BpmSimpleModelNodeType.INCLUSIVE_BRANCH_NODE) { || nodeType == BpmSimpleModelNodeTypeEnum.INCLUSIVE_BRANCH_NODE) {
String nextNodeId = isValidNode(childNode) ? childNode.getId() : targetNodeId; String nextNodeId = isValidNode(childNode) ? childNode.getId() : targetNodeId;
SequenceFlow sequenceFlow = buildBpmnSequenceFlow(branchEndNodeId, nextNodeId); SequenceFlow sequenceFlow = buildBpmnSequenceFlow(branchEndNodeId, nextNodeId);
process.addFlowElement(sequenceFlow); process.addFlowElement(sequenceFlow);
// 4.2 如果是路由分支需要连接后续节点为默认路由 // 4.2 如果是路由分支需要连接后续节点为默认路由
} else if (nodeType == BpmSimpleModelNodeType.ROUTER_BRANCH_NODE) { } else if (nodeType == BpmSimpleModelNodeTypeEnum.ROUTER_BRANCH_NODE) {
SequenceFlow sequenceFlow = buildBpmnSequenceFlow(node.getId(), branchEndNodeId, node.getRouterDefaultFlowId(), SequenceFlow sequenceFlow = buildBpmnSequenceFlow(node.getId(), branchEndNodeId, node.getRouterDefaultFlowId(),
null, null); null, null);
process.addFlowElement(sequenceFlow); process.addFlowElement(sequenceFlow);
@ -274,7 +274,7 @@ public class SimpleModelUtils {
} }
public static boolean isSequentialApproveNode(BpmSimpleModelNodeVO node) { public static boolean isSequentialApproveNode(BpmSimpleModelNodeVO node) {
return BpmSimpleModelNodeType.APPROVE_NODE.getType().equals(node.getType()) return BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType().equals(node.getType())
&& BpmUserTaskApproveMethodEnum.SEQUENTIAL.getMethod().equals(node.getApproveMethod()); && BpmUserTaskApproveMethodEnum.SEQUENTIAL.getMethod().equals(node.getApproveMethod());
} }
@ -290,7 +290,7 @@ public class SimpleModelUtils {
throw new UnsupportedOperationException("请实现该方法"); throw new UnsupportedOperationException("请实现该方法");
} }
BpmSimpleModelNodeType getType(); BpmSimpleModelNodeTypeEnum getType();
} }
@ -305,8 +305,8 @@ public class SimpleModelUtils {
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.START_NODE; return BpmSimpleModelNodeTypeEnum.START_NODE;
} }
} }
@ -323,8 +323,8 @@ public class SimpleModelUtils {
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.END_NODE; return BpmSimpleModelNodeTypeEnum.END_NODE;
} }
} }
@ -352,8 +352,8 @@ public class SimpleModelUtils {
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.START_USER_NODE; return BpmSimpleModelNodeTypeEnum.START_USER_NODE;
} }
} }
@ -376,8 +376,8 @@ public class SimpleModelUtils {
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.APPROVE_NODE; return BpmSimpleModelNodeTypeEnum.APPROVE_NODE;
} }
/** /**
@ -405,7 +405,7 @@ public class SimpleModelUtils {
boundaryEvent.addEventDefinition(eventDefinition); boundaryEvent.addEventDefinition(eventDefinition);
// 2.1 添加定时器边界事件类型 // 2.1 添加定时器边界事件类型
addExtensionElement(boundaryEvent, BOUNDARY_EVENT_TYPE, BpmBoundaryEventType.USER_TASK_TIMEOUT.getType()); addExtensionElement(boundaryEvent, BOUNDARY_EVENT_TYPE, BpmBoundaryEventTypeEnum.USER_TASK_TIMEOUT.getType());
// 2.2 添加超时执行动作元素 // 2.2 添加超时执行动作元素
addExtensionElement(boundaryEvent, USER_TASK_TIMEOUT_HANDLER_TYPE, timeoutHandler.getType()); addExtensionElement(boundaryEvent, USER_TASK_TIMEOUT_HANDLER_TYPE, timeoutHandler.getType());
return boundaryEvent; return boundaryEvent;
@ -533,8 +533,8 @@ public class SimpleModelUtils {
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.COPY_NODE; return BpmSimpleModelNodeTypeEnum.COPY_NODE;
} }
} }
@ -556,8 +556,8 @@ public class SimpleModelUtils {
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.CONDITION_BRANCH_NODE; return BpmSimpleModelNodeTypeEnum.CONDITION_BRANCH_NODE;
} }
} }
@ -578,8 +578,8 @@ public class SimpleModelUtils {
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.PARALLEL_BRANCH_NODE; return BpmSimpleModelNodeTypeEnum.PARALLEL_BRANCH_NODE;
} }
} }
@ -605,8 +605,8 @@ public class SimpleModelUtils {
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.INCLUSIVE_BRANCH_NODE; return BpmSimpleModelNodeTypeEnum.INCLUSIVE_BRANCH_NODE;
} }
} }
@ -620,8 +620,8 @@ public class SimpleModelUtils {
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.CONDITION_NODE; return BpmSimpleModelNodeTypeEnum.CONDITION_NODE;
} }
public static SequenceFlow buildSequenceFlow(String sourceId, String targetId, public static SequenceFlow buildSequenceFlow(String sourceId, String targetId,
@ -647,11 +647,11 @@ public class SimpleModelUtils {
public static String buildConditionExpression(Integer conditionType, String conditionExpression, public static String buildConditionExpression(Integer conditionType, String conditionExpression,
ConditionGroups conditionGroups) { ConditionGroups conditionGroups) {
BpmSimpleModeConditionType conditionTypeEnum = BpmSimpleModeConditionType.valueOf(conditionType); BpmSimpleModeConditionTypeEnum conditionTypeEnum = BpmSimpleModeConditionTypeEnum.valueOf(conditionType);
if (conditionTypeEnum == BpmSimpleModeConditionType.EXPRESSION) { if (conditionTypeEnum == BpmSimpleModeConditionTypeEnum.EXPRESSION) {
return conditionExpression; return conditionExpression;
} }
if (conditionTypeEnum == BpmSimpleModeConditionType.RULE) { if (conditionTypeEnum == BpmSimpleModeConditionTypeEnum.RULE) {
if (conditionGroups == null || CollUtil.isEmpty(conditionGroups.getConditions())) { if (conditionGroups == null || CollUtil.isEmpty(conditionGroups.getConditions())) {
return null; return null;
} }
@ -696,21 +696,21 @@ public class SimpleModelUtils {
boundaryEvent.setAttachedToRef(receiveTask); boundaryEvent.setAttachedToRef(receiveTask);
// 2.2 定义超时时间 // 2.2 定义超时时间
TimerEventDefinition eventDefinition = new TimerEventDefinition(); TimerEventDefinition eventDefinition = new TimerEventDefinition();
if (node.getDelaySetting().getDelayType().equals(BpmDelayTimerType.FIXED_DATE_TIME.getType())) { if (node.getDelaySetting().getDelayType().equals(BpmDelayTimerTypeEnum.FIXED_DATE_TIME.getType())) {
eventDefinition.setTimeDuration(node.getDelaySetting().getDelayTime()); eventDefinition.setTimeDuration(node.getDelaySetting().getDelayTime());
} else if (node.getDelaySetting().getDelayType().equals(BpmDelayTimerType.FIXED_TIME_DURATION.getType())) { } else if (node.getDelaySetting().getDelayType().equals(BpmDelayTimerTypeEnum.FIXED_TIME_DURATION.getType())) {
eventDefinition.setTimeDate(node.getDelaySetting().getDelayTime()); eventDefinition.setTimeDate(node.getDelaySetting().getDelayTime());
} }
boundaryEvent.addEventDefinition(eventDefinition); boundaryEvent.addEventDefinition(eventDefinition);
addExtensionElement(boundaryEvent, BOUNDARY_EVENT_TYPE, BpmBoundaryEventType.DELAY_TIMER_TIMEOUT.getType()); addExtensionElement(boundaryEvent, BOUNDARY_EVENT_TYPE, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT.getType());
flowElements.add(boundaryEvent); flowElements.add(boundaryEvent);
} }
return flowElements; return flowElements;
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.DELAY_TIMER_NODE; return BpmSimpleModelNodeTypeEnum.DELAY_TIMER_NODE;
} }
} }
@ -727,6 +727,7 @@ public class SimpleModelUtils {
if (node.getTriggerSetting() != null) { if (node.getTriggerSetting() != null) {
addExtensionElement(serviceTask, TRIGGER_TYPE, node.getTriggerSetting().getType()); addExtensionElement(serviceTask, TRIGGER_TYPE, node.getTriggerSetting().getType());
if (node.getTriggerSetting().getHttpRequestSetting() != null) { if (node.getTriggerSetting().getHttpRequestSetting() != null) {
// TODO @jason加个 addExtensionElementJson 方法方便设置 JSON 类型的属性
addExtensionElement(serviceTask, TRIGGER_PARAM, addExtensionElement(serviceTask, TRIGGER_PARAM,
JsonUtils.toJsonString(node.getTriggerSetting().getHttpRequestSetting())); JsonUtils.toJsonString(node.getTriggerSetting().getHttpRequestSetting()));
} }
@ -735,8 +736,8 @@ public class SimpleModelUtils {
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.TRIGGER_NODE; return BpmSimpleModelNodeTypeEnum.TRIGGER_NODE;
} }
} }
@ -754,8 +755,8 @@ public class SimpleModelUtils {
} }
@Override @Override
public BpmSimpleModelNodeType getType() { public BpmSimpleModelNodeTypeEnum getType() {
return BpmSimpleModelNodeType.ROUTER_BRANCH_NODE; return BpmSimpleModelNodeTypeEnum.ROUTER_BRANCH_NODE;
} }
public static SequenceFlow buildSequenceFlow(String nodeId, BpmSimpleModelNodeVO.RouterSetting router) { public static SequenceFlow buildSequenceFlow(String nodeId, BpmSimpleModelNodeVO.RouterSetting router) {
@ -785,21 +786,21 @@ public class SimpleModelUtils {
if (!isValidNode(currentNode)) { if (!isValidNode(currentNode)) {
return; return;
} }
BpmSimpleModelNodeType nodeType = BpmSimpleModelNodeType.valueOf(currentNode.getType()); BpmSimpleModelNodeTypeEnum nodeType = BpmSimpleModelNodeTypeEnum.valueOf(currentNode.getType());
Assert.notNull(nodeType, "模型节点类型不支持"); Assert.notNull(nodeType, "模型节点类型不支持");
// 情况START_NODE/START_USER_NODE/APPROVE_NODE/COPY_NODE/END_NODE // 情况START_NODE/START_USER_NODE/APPROVE_NODE/COPY_NODE/END_NODE
if (nodeType == BpmSimpleModelNodeType.START_NODE if (nodeType == BpmSimpleModelNodeTypeEnum.START_NODE
|| nodeType == BpmSimpleModelNodeType.START_USER_NODE || nodeType == BpmSimpleModelNodeTypeEnum.START_USER_NODE
|| nodeType == BpmSimpleModelNodeType.APPROVE_NODE || nodeType == BpmSimpleModelNodeTypeEnum.APPROVE_NODE
|| nodeType == BpmSimpleModelNodeType.COPY_NODE || nodeType == BpmSimpleModelNodeTypeEnum.COPY_NODE
|| nodeType == BpmSimpleModelNodeType.END_NODE) { || nodeType == BpmSimpleModelNodeTypeEnum.END_NODE) {
// 添加元素 // 添加元素
resultNodes.add(currentNode); resultNodes.add(currentNode);
} }
// 情况CONDITION_BRANCH_NODE 排它只有一个满足条件的如果没有就走默认的 // 情况CONDITION_BRANCH_NODE 排它只有一个满足条件的如果没有就走默认的
if (nodeType == BpmSimpleModelNodeType.CONDITION_BRANCH_NODE) { if (nodeType == BpmSimpleModelNodeTypeEnum.CONDITION_BRANCH_NODE) {
// 查找满足条件的 BpmSimpleModelNodeVO 节点 // 查找满足条件的 BpmSimpleModelNodeVO 节点
BpmSimpleModelNodeVO matchConditionNode = CollUtil.findOne(currentNode.getConditionNodes(), BpmSimpleModelNodeVO matchConditionNode = CollUtil.findOne(currentNode.getConditionNodes(),
conditionNode -> !BooleanUtil.isTrue(conditionNode.getConditionSetting().getDefaultFlow()) conditionNode -> !BooleanUtil.isTrue(conditionNode.getConditionSetting().getDefaultFlow())
@ -814,7 +815,7 @@ public class SimpleModelUtils {
} }
// 情况INCLUSIVE_BRANCH_NODE 包容多个满足条件的如果没有就走默认的 // 情况INCLUSIVE_BRANCH_NODE 包容多个满足条件的如果没有就走默认的
if (nodeType == BpmSimpleModelNodeType.INCLUSIVE_BRANCH_NODE) { if (nodeType == BpmSimpleModelNodeTypeEnum.INCLUSIVE_BRANCH_NODE) {
// 查找满足条件的 BpmSimpleModelNodeVO 节点 // 查找满足条件的 BpmSimpleModelNodeVO 节点
Collection<BpmSimpleModelNodeVO> matchConditionNodes = CollUtil.filterNew(currentNode.getConditionNodes(), Collection<BpmSimpleModelNodeVO> matchConditionNodes = CollUtil.filterNew(currentNode.getConditionNodes(),
conditionNode -> !BooleanUtil.isTrue(conditionNode.getConditionSetting().getDefaultFlow()) conditionNode -> !BooleanUtil.isTrue(conditionNode.getConditionSetting().getDefaultFlow())
@ -830,7 +831,7 @@ public class SimpleModelUtils {
} }
// 情况PARALLEL_BRANCH_NODE 并行都满足都走 // 情况PARALLEL_BRANCH_NODE 并行都满足都走
if (nodeType == BpmSimpleModelNodeType.PARALLEL_BRANCH_NODE) { if (nodeType == BpmSimpleModelNodeTypeEnum.PARALLEL_BRANCH_NODE) {
// 遍历所有 BpmSimpleModelNodeVO 节点 // 遍历所有 BpmSimpleModelNodeVO 节点
currentNode.getConditionNodes().forEach(matchConditionNode -> currentNode.getConditionNodes().forEach(matchConditionNode ->
simulateNextNode(matchConditionNode.getChildNode(), variables, resultNodes)); simulateNextNode(matchConditionNode.getChildNode(), variables, resultNodes));
@ -844,6 +845,7 @@ public class SimpleModelUtils {
return BpmnModelUtils.evalConditionExpress(variables, ConditionNodeConvert.buildConditionExpression(conditionNode)); return BpmnModelUtils.evalConditionExpress(variables, ConditionNodeConvert.buildConditionExpression(conditionNode));
} }
// TODO @芋艿要不要优化下抽个 HttpUtils
/** /**
* 添加 HTTP 请求参数请求头或者请求体 * 添加 HTTP 请求参数请求头或者请求体
* *
@ -852,15 +854,15 @@ public class SimpleModelUtils {
* @param processVariables 流程变量 * @param processVariables 流程变量
*/ */
public static void addHttpRequestParam(MultiValueMap<String, String> params, public static void addHttpRequestParam(MultiValueMap<String, String> params,
List<BpmSimpleModelNodeVO.HttpRequestParamSetting> paramSettings, List<BpmSimpleModelNodeVO.HttpRequestParam> paramSettings,
Map<String, Object> processVariables) { Map<String, Object> processVariables) {
if (CollUtil.isEmpty(paramSettings)) { if (CollUtil.isEmpty(paramSettings)) {
return; return;
} }
paramSettings.forEach(item -> { paramSettings.forEach(item -> {
if (item.getType().equals(BpmHttpRequestParamSettingType.FIXED_VALUE.getType())) { if (item.getType().equals(BpmHttpRequestParamTypeEnum.FIXED_VALUE.getType())) {
params.add(item.getKey(), item.getValue()); params.add(item.getKey(), item.getValue());
} else if (item.getType().equals(BpmHttpRequestParamSettingType.FROM_FORM.getType())) { } else if (item.getType().equals(BpmHttpRequestParamTypeEnum.FROM_FORM.getType())) {
params.add(item.getKey(), processVariables.get(item.getValue()).toString()); params.add(item.getKey(), processVariables.get(item.getValue()).toString());
} }
}); });

View File

@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener.BpmPr
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerSaveReqVO; import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerSaveReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessListenerDO; import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessListenerDO;
import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmProcessListenerMapper; import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmProcessListenerMapper;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmProcessListenerType; import cn.iocoder.yudao.module.bpm.enums.definition.BpmProcessListenerTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmProcessListenerValueType; import cn.iocoder.yudao.module.bpm.enums.definition.BpmProcessListenerValueTypeEnum;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.flowable.engine.delegate.JavaDelegate; import org.flowable.engine.delegate.JavaDelegate;
import org.flowable.engine.delegate.TaskListener; import org.flowable.engine.delegate.TaskListener;
@ -52,14 +52,14 @@ public class BpmProcessListenerServiceImpl implements BpmProcessListenerService
private void validateCreateProcessListenerValue(BpmProcessListenerSaveReqVO createReqVO) { private void validateCreateProcessListenerValue(BpmProcessListenerSaveReqVO createReqVO) {
// class 类型 // class 类型
if (createReqVO.getValueType().equals(BpmProcessListenerValueType.CLASS.getType())) { if (createReqVO.getValueType().equals(BpmProcessListenerValueTypeEnum.CLASS.getType())) {
try { try {
Class<?> clazz = Class.forName(createReqVO.getValue()); Class<?> clazz = Class.forName(createReqVO.getValue());
if (createReqVO.getType().equals(BpmProcessListenerType.EXECUTION.getType()) if (createReqVO.getType().equals(BpmProcessListenerTypeEnum.EXECUTION.getType())
&& !JavaDelegate.class.isAssignableFrom(clazz)) { && !JavaDelegate.class.isAssignableFrom(clazz)) {
throw exception(PROCESS_LISTENER_CLASS_IMPLEMENTS_ERROR, createReqVO.getValue(), throw exception(PROCESS_LISTENER_CLASS_IMPLEMENTS_ERROR, createReqVO.getValue(),
JavaDelegate.class.getName()); JavaDelegate.class.getName());
} else if (createReqVO.getType().equals(BpmProcessListenerType.TASK.getType()) } else if (createReqVO.getType().equals(BpmProcessListenerTypeEnum.TASK.getType())
&& !TaskListener.class.isAssignableFrom(clazz)) { && !TaskListener.class.isAssignableFrom(clazz)) {
throw exception(PROCESS_LISTENER_CLASS_IMPLEMENTS_ERROR, createReqVO.getValue(), throw exception(PROCESS_LISTENER_CLASS_IMPLEMENTS_ERROR, createReqVO.getValue(),
TaskListener.class.getName()); TaskListener.class.getName());

View File

@ -22,7 +22,7 @@ import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitio
import cn.iocoder.yudao.module.bpm.dal.redis.BpmProcessIdRedisDAO; import cn.iocoder.yudao.module.bpm.dal.redis.BpmProcessIdRedisDAO;
import cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants; import cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType; import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceStatusEnum;
import cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum;
import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum;
@ -294,7 +294,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
FlowElement flowNode = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey()); FlowElement flowNode = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
ActivityNode activityNode = new ActivityNode().setId(task.getTaskDefinitionKey()).setName(task.getName()) ActivityNode activityNode = new ActivityNode().setId(task.getTaskDefinitionKey()).setName(task.getName())
.setNodeType(START_USER_NODE_ID.equals(task.getTaskDefinitionKey()) ? .setNodeType(START_USER_NODE_ID.equals(task.getTaskDefinitionKey()) ?
BpmSimpleModelNodeType.START_USER_NODE.getType() : BpmSimpleModelNodeType.APPROVE_NODE.getType()) BpmSimpleModelNodeTypeEnum.START_USER_NODE.getType() : BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType())
.setStatus(FlowableUtils.getTaskStatus(task)) .setStatus(FlowableUtils.getTaskStatus(task))
.setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(flowNode)) .setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(flowNode))
.setStartTime(DateUtils.of(task.getCreateTime())).setEndTime(DateUtils.of(task.getEndTime())) .setStartTime(DateUtils.of(task.getCreateTime())).setEndTime(DateUtils.of(task.getEndTime()))
@ -316,8 +316,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
ActivityNodeTask startTask = new ActivityNodeTask().setId(BpmnModelConstants.START_USER_NODE_ID) ActivityNodeTask startTask = new ActivityNodeTask().setId(BpmnModelConstants.START_USER_NODE_ID)
.setAssignee(startUserId).setStatus(BpmTaskStatusEnum.APPROVE.getStatus()); .setAssignee(startUserId).setStatus(BpmTaskStatusEnum.APPROVE.getStatus());
ActivityNode startNode = new ActivityNode().setId(startTask.getId()) ActivityNode startNode = new ActivityNode().setId(startTask.getId())
.setName(BpmSimpleModelNodeType.START_USER_NODE.getName()) .setName(BpmSimpleModelNodeTypeEnum.START_USER_NODE.getName())
.setNodeType(BpmSimpleModelNodeType.START_USER_NODE.getType()) .setNodeType(BpmSimpleModelNodeTypeEnum.START_USER_NODE.getType())
.setStatus(startTask.getStatus()).setTasks(ListUtil.of(startTask)) .setStatus(startTask.getStatus()).setTasks(ListUtil.of(startTask))
.setStartTime(DateUtils.of(activity.getStartTime())).setEndTime(DateUtils.of(activity.getEndTime())); .setStartTime(DateUtils.of(activity.getStartTime())).setEndTime(DateUtils.of(activity.getEndTime()));
approvalNodes.add(0, startNode); approvalNodes.add(0, startNode);
@ -330,8 +330,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
return; return;
} }
ActivityNode endNode = new ActivityNode().setId(activity.getId()) ActivityNode endNode = new ActivityNode().setId(activity.getId())
.setName(BpmSimpleModelNodeType.END_NODE.getName()) .setName(BpmSimpleModelNodeTypeEnum.END_NODE.getName())
.setNodeType(BpmSimpleModelNodeType.END_NODE.getType()).setStatus(processInstanceStatus) .setNodeType(BpmSimpleModelNodeTypeEnum.END_NODE.getType()).setStatus(processInstanceStatus)
.setStartTime(DateUtils.of(activity.getStartTime())).setEndTime(DateUtils.of(activity.getEndTime())); .setStartTime(DateUtils.of(activity.getStartTime())).setEndTime(DateUtils.of(activity.getEndTime()));
String reason = FlowableUtils.getProcessInstanceReason(historicProcessInstance); String reason = FlowableUtils.getProcessInstanceReason(historicProcessInstance);
if (StrUtil.isNotEmpty(reason)) { if (StrUtil.isNotEmpty(reason)) {
@ -367,7 +367,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
FlowElement flowNode = BpmnModelUtils.getFlowElementById(bpmnModel, activityId); FlowElement flowNode = BpmnModelUtils.getFlowElementById(bpmnModel, activityId);
HistoricActivityInstance firstActivity = CollUtil.getFirst(taskActivities); // 取第一个任务会签/或签的任务开始时间相同 HistoricActivityInstance firstActivity = CollUtil.getFirst(taskActivities); // 取第一个任务会签/或签的任务开始时间相同
ActivityNode activityNode = new ActivityNode().setId(firstActivity.getActivityId()).setName(firstActivity.getActivityName()) ActivityNode activityNode = new ActivityNode().setId(firstActivity.getActivityId()).setName(firstActivity.getActivityName())
.setNodeType(BpmSimpleModelNodeType.APPROVE_NODE.getType()).setStatus(BpmTaskStatusEnum.RUNNING.getStatus()) .setNodeType(BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType()).setStatus(BpmTaskStatusEnum.RUNNING.getStatus())
.setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(flowNode)) .setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(flowNode))
.setStartTime(DateUtils.of(CollUtil.getFirst(taskActivities).getStartTime())) .setStartTime(DateUtils.of(CollUtil.getFirst(taskActivities).getStartTime()))
.setTasks(new ArrayList<>()); .setTasks(new ArrayList<>());
@ -437,8 +437,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
// 1. 开始节点/审批节点 // 1. 开始节点/审批节点
if (ObjectUtils.equalsAny(node.getType(), if (ObjectUtils.equalsAny(node.getType(),
BpmSimpleModelNodeType.START_USER_NODE.getType(), BpmSimpleModelNodeTypeEnum.START_USER_NODE.getType(),
BpmSimpleModelNodeType.APPROVE_NODE.getType())) { BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType())) {
List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(), List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(),
startUserId, processDefinitionInfo.getProcessDefinitionId(), processVariables); startUserId, processDefinitionInfo.getProcessDefinitionId(), processVariables);
activityNode.setCandidateUserIds(candidateUserIds); activityNode.setCandidateUserIds(candidateUserIds);
@ -446,13 +446,13 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
} }
// 2. 结束节点 // 2. 结束节点
if (BpmSimpleModelNodeType.END_NODE.getType().equals(node.getType())) { if (BpmSimpleModelNodeTypeEnum.END_NODE.getType().equals(node.getType())) {
return activityNode; return activityNode;
} }
// 3. 抄送节点 // 3. 抄送节点
if (CollUtil.isEmpty(runActivityIds) && // 流程发起时需要展示抄送节点用于选择抄送人 if (CollUtil.isEmpty(runActivityIds) && // 流程发起时需要展示抄送节点用于选择抄送人
BpmSimpleModelNodeType.COPY_NODE.getType().equals(node.getType())) { BpmSimpleModelNodeTypeEnum.COPY_NODE.getType().equals(node.getType())) {
return activityNode; return activityNode;
} }
return null; return null;
@ -468,23 +468,23 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
// 1. 开始节点 // 1. 开始节点
if (node instanceof StartEvent) { if (node instanceof StartEvent) {
return activityNode.setName(BpmSimpleModelNodeType.START_USER_NODE.getName()) return activityNode.setName(BpmSimpleModelNodeTypeEnum.START_USER_NODE.getName())
.setNodeType(BpmSimpleModelNodeType.START_USER_NODE.getType()); .setNodeType(BpmSimpleModelNodeTypeEnum.START_USER_NODE.getType());
} }
// 2. 审批节点 // 2. 审批节点
if (node instanceof UserTask) { if (node instanceof UserTask) {
List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(), List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(),
startUserId, processDefinitionInfo.getProcessDefinitionId(), processVariables); startUserId, processDefinitionInfo.getProcessDefinitionId(), processVariables);
return activityNode.setName(node.getName()).setNodeType(BpmSimpleModelNodeType.APPROVE_NODE.getType()) return activityNode.setName(node.getName()).setNodeType(BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType())
.setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(node)) .setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(node))
.setCandidateUserIds(candidateUserIds); .setCandidateUserIds(candidateUserIds);
} }
// 3. 结束节点 // 3. 结束节点
if (node instanceof EndEvent) { if (node instanceof EndEvent) {
return activityNode.setName(BpmSimpleModelNodeType.END_NODE.getName()) return activityNode.setName(BpmSimpleModelNodeTypeEnum.END_NODE.getName())
.setNodeType(BpmSimpleModelNodeType.END_NODE.getType()); .setNodeType(BpmSimpleModelNodeTypeEnum.END_NODE.getType());
} }
return null; return null;
} }

View File

@ -656,8 +656,8 @@ public class BpmTaskServiceImpl implements BpmTaskService {
BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(task.getProcessDefinitionId()); BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(task.getProcessDefinitionId());
FlowElement userTaskElement = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey()); FlowElement userTaskElement = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
// 3.1 情况一驳回到指定的任务节点 // 3.1 情况一驳回到指定的任务节点
BpmUserTaskRejectHandlerType userTaskRejectHandlerType = BpmnModelUtils.parseRejectHandlerType(userTaskElement); BpmUserTaskRejectHandlerTypeEnum userTaskRejectHandlerType = BpmnModelUtils.parseRejectHandlerType(userTaskElement);
if (userTaskRejectHandlerType == BpmUserTaskRejectHandlerType.RETURN_USER_TASK) { if (userTaskRejectHandlerType == BpmUserTaskRejectHandlerTypeEnum.RETURN_USER_TASK) {
String returnTaskId = BpmnModelUtils.parseReturnTaskId(userTaskElement); String returnTaskId = BpmnModelUtils.parseReturnTaskId(userTaskElement);
Assert.notNull(returnTaskId, "退回的节点不能为空"); Assert.notNull(returnTaskId, "退回的节点不能为空");
returnTask(userId, new BpmTaskReturnReqVO().setId(task.getId()) returnTask(userId, new BpmTaskReturnReqVO().setId(task.getId())
@ -1184,23 +1184,24 @@ public class BpmTaskServiceImpl implements BpmTaskService {
.taskAssignee(task.getAssignee()) // 相同审批人 .taskAssignee(task.getAssignee()) // 相同审批人
.taskVariableValueEquals(BpmnVariableConstants.TASK_VARIABLE_STATUS, BpmTaskStatusEnum.APPROVE.getStatus()) .taskVariableValueEquals(BpmnVariableConstants.TASK_VARIABLE_STATUS, BpmTaskStatusEnum.APPROVE.getStatus())
.finished(); .finished();
if (BpmAutoApproveType.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType()) if (BpmAutoApproveTypeEnum.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType())
&& sameAssigneeQuery.count() > 0) { && sameAssigneeQuery.count() > 0) {
getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
.setReason(BpmAutoApproveType.APPROVE_ALL.getName())); .setReason(BpmAutoApproveTypeEnum.APPROVE_ALL.getName()));
return; return;
} }
if (BpmAutoApproveType.APPROVE_SEQUENT.getType().equals(processDefinitionInfo.getAutoApprovalType())) { if (BpmAutoApproveTypeEnum.APPROVE_SEQUENT.getType().equals(processDefinitionInfo.getAutoApprovalType())) {
BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId()); BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId());
if (bpmnModel == null) { if (bpmnModel == null) {
log.error("[processTaskAssigned][taskId({}) 没有找到流程模型({})]", task.getId(), task.getProcessDefinitionId()); log.error("[processTaskAssigned][taskId({}) 没有找到流程模型({})]", task.getId(), task.getProcessDefinitionId());
return; return;
} }
List<String> sourceTaskIds = getElementIncomingFlows(getFlowElementById(bpmnModel, task.getTaskDefinitionKey())) List<String> sourceTaskIds = convertList(BpmnModelUtils.getElementIncomingFlows( // 获取所有上一个节点
.stream().map(SequenceFlow::getSourceRef).toList(); BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey())),
SequenceFlow::getSourceRef);
if (sameAssigneeQuery.taskDefinitionKeys(sourceTaskIds).count() > 0) { if (sameAssigneeQuery.taskDefinitionKeys(sourceTaskIds).count() > 0) {
getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
.setReason(BpmAutoApproveType.APPROVE_SEQUENT.getName())); .setReason(BpmAutoApproveTypeEnum.APPROVE_SEQUENT.getName()));
return; return;
} }
} }

View File

@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.bpm.service.task.trigger;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.TriggerSetting.HttpRequestTriggerSetting; import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO.TriggerSetting.HttpRequestTriggerSetting;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerType; import cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.SimpleModelUtils; import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.SimpleModelUtils;
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -37,16 +37,16 @@ public class BpmHttpRequestTrigger implements BpmTrigger {
private RestTemplate restTemplate; private RestTemplate restTemplate;
@Override @Override
public BpmTriggerType getType() { public BpmTriggerTypeEnum getType() {
return BpmTriggerType.HTTP_REQUEST; return BpmTriggerTypeEnum.HTTP_REQUEST;
} }
@Override @Override
public void execute(String processInstanceId, String param) { public void execute(String processInstanceId, String param) {
// 1. 解析 http 请求配置 // 1. 解析 http 请求配置
HttpRequestTriggerSetting httpRequestSetting = JsonUtils.parseObject(param, HttpRequestTriggerSetting.class); HttpRequestTriggerSetting setting = JsonUtils.parseObject(param, HttpRequestTriggerSetting.class);
if (httpRequestSetting == null) { if (setting == null) {
log.error("[execute] HTTP 触发器请求配置为空"); log.error("[execute][流程({}) HTTP 触发器请求配置为空]", processInstanceId);
return; return;
} }
// 2.1 设置请求头 // 2.1 设置请求头
@ -54,20 +54,22 @@ public class BpmHttpRequestTrigger implements BpmTrigger {
Map<String, Object> processVariables = processInstance.getProcessVariables(); Map<String, Object> processVariables = processInstance.getProcessVariables();
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add(HEADER_TENANT_ID, processInstance.getTenantId()); headers.add(HEADER_TENANT_ID, processInstance.getTenantId());
SimpleModelUtils.addHttpRequestParam(headers, httpRequestSetting.getHeader(), processVariables); SimpleModelUtils.addHttpRequestParam(headers, setting.getHeader(), processVariables);
// 2.2 设置请求体 // 2.2 设置请求体
MultiValueMap<String, String> body = new LinkedMultiValueMap<>(); MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
SimpleModelUtils.addHttpRequestParam(body, httpRequestSetting.getBody(), processVariables); SimpleModelUtils.addHttpRequestParam(body, setting.getBody(), processVariables);
body.add("processInstanceId", processInstanceId); body.add("processInstanceId", processInstanceId);
// TODO @芋艿要不要抽象一个 Http 请求的工具类方便复用呢
// 3. 发起请求 // 3. 发起请求
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers);
try { try {
ResponseEntity<String> responseEntity = restTemplate.exchange(httpRequestSetting.getUrl(), HttpMethod.POST, ResponseEntity<String> responseEntity = restTemplate.exchange(setting.getUrl(), HttpMethod.POST,
requestEntity, String.class); requestEntity, String.class);
log.info("[execute][HTTP 触发器,请求头:{},请求体:{},响应结果:{}]", headers, body, responseEntity); log.info("[execute][HTTP 触发器,请求头:{},请求体:{},响应结果:{}]", headers, body, responseEntity);
} catch (RestClientException e) { } catch (RestClientException e) {
log.error("[execute][HTTP 触发器,请求头:{},请求体:{},请求出错:{}]", headers, body, e.getMessage()); log.error("[execute][HTTP 触发器,请求头:{},请求体:{},请求出错:{}]", headers, body, e.getMessage());
} }
} }
} }

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.module.bpm.service.task.trigger; package cn.iocoder.yudao.module.bpm.service.task.trigger;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerType; import cn.iocoder.yudao.module.bpm.enums.definition.BpmTriggerTypeEnum;
/** /**
* BPM 触发器接口 * BPM 触发器接口
@ -16,7 +16,7 @@ public interface BpmTrigger {
* *
* @return 触发器类型 * @return 触发器类型
*/ */
BpmTriggerType getType(); BpmTriggerTypeEnum getType();
/** /**
* 触发器执行 * 触发器执行
@ -25,4 +25,5 @@ public interface BpmTrigger {
* @param param 触发器参数 * @param param 触发器参数
*/ */
void execute(String processInstanceId, String param); void execute(String processInstanceId, String param);
} }