【代码评审】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
@AllArgsConstructor
public enum BpmAutoApproveType implements IntArrayValuable {
public enum BpmAutoApproveTypeEnum implements IntArrayValuable {
NONE(0, "不自动通过"),
APPROVE_ALL(1, "仅审批一次,后续重复的审批节点均自动通过"),
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 String name;

View File

@ -11,7 +11,7 @@ import lombok.Getter;
*/
@Getter
@AllArgsConstructor
public enum BpmBoundaryEventType {
public enum BpmBoundaryEventTypeEnum {
USER_TASK_TIMEOUT(1, "用户任务超时"),
DELAY_TIMER_TIMEOUT(2, "延迟器超时");
@ -19,7 +19,7 @@ public enum BpmBoundaryEventType {
private final Integer type;
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());
}

View File

@ -13,7 +13,7 @@ import java.util.Arrays;
*/
@Getter
@AllArgsConstructor
public enum BpmDelayTimerType implements IntArrayValuable {
public enum BpmDelayTimerTypeEnum implements IntArrayValuable {
FIXED_TIME_DURATION(1, "固定时长"),
FIXED_DATE_TIME(2, "固定日期");
@ -21,7 +21,7 @@ public enum BpmDelayTimerType implements IntArrayValuable {
private final Integer type;
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
public int[] array() {

View File

@ -13,7 +13,7 @@ import java.util.Arrays;
*/
@Getter
@AllArgsConstructor
public enum BpmHttpRequestParamSettingType implements IntArrayValuable {
public enum BpmHttpRequestParamTypeEnum implements IntArrayValuable {
FIXED_VALUE(1, "固定值"),
FROM_FORM(2, "表单");
@ -21,7 +21,7 @@ public enum BpmHttpRequestParamSettingType implements IntArrayValuable {
private final Integer type;
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
public int[] array() {

View File

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

View File

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

View File

@ -14,18 +14,18 @@ import java.util.Arrays;
*/
@Getter
@AllArgsConstructor
public enum BpmSimpleModeConditionType implements IntArrayValuable {
public enum BpmSimpleModeConditionTypeEnum implements IntArrayValuable {
EXPRESSION(1, "条件表达式"),
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 String name;
public static BpmSimpleModeConditionType valueOf(Integer type) {
public static BpmSimpleModeConditionTypeEnum valueOf(Integer type) {
return ArrayUtil.firstMatch(nodeType -> nodeType.getType().equals(type), values());
}

View File

@ -15,7 +15,7 @@ import java.util.Objects;
*/
@Getter
@AllArgsConstructor
public enum BpmSimpleModelNodeType implements IntArrayValuable {
public enum BpmSimpleModelNodeTypeEnum implements IntArrayValuable {
// 0 ~ 1 开始和结束
START_NODE(0, "开始", "startEvent"),
@ -37,7 +37,7 @@ public enum BpmSimpleModelNodeType implements IntArrayValuable {
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 String name;
@ -55,7 +55,7 @@ public enum BpmSimpleModelNodeType implements IntArrayValuable {
|| 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());
}

View File

@ -14,7 +14,7 @@ import java.util.Arrays;
*/
@Getter
@AllArgsConstructor
public enum BpmTriggerType implements IntArrayValuable {
public enum BpmTriggerTypeEnum implements IntArrayValuable {
HTTP_REQUEST(1, "发起 HTTP 请求");
@ -28,14 +28,14 @@ public enum BpmTriggerType implements IntArrayValuable {
*/
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
public int[] array() {
return ARRAYS;
}
public static BpmTriggerType typeOf(Integer type) {
public static BpmTriggerTypeEnum typeOf(Integer type) {
return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
}
}

View File

@ -14,7 +14,7 @@ import java.util.Arrays;
*/
@Getter
@AllArgsConstructor
public enum BpmUserTaskRejectHandlerType implements IntArrayValuable {
public enum BpmUserTaskRejectHandlerTypeEnum implements IntArrayValuable {
FINISH_PROCESS_INSTANCE(1, "终止流程"),
RETURN_USER_TASK(2, "驳回到指定任务节点");
@ -22,9 +22,9 @@ public enum BpmUserTaskRejectHandlerType implements IntArrayValuable {
private final Integer type;
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());
}

View File

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

View File

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

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.bpm.dal.dataobject.definition;
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.TableId;
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>
* 2. taskTaskListener <a href="https://tkjohn.github.io/flowable-userguide/#taskListeners">任务监听器</a>

View File

@ -104,7 +104,6 @@ public interface BpmnModelConstants {
* BPMN ExtensionElement 的扩展属性用于标记触发器的类型
*/
String TRIGGER_TYPE = "triggerType";
/**
* 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.StrUtil;
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.util.BpmnModelUtils;
import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
@ -97,17 +97,17 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
BoundaryEvent boundaryEvent = (BoundaryEvent) element;
String boundaryEventType = BpmnModelUtils.parseBoundaryEventExtensionElement(boundaryEvent,
BpmnModelConstants.BOUNDARY_EVENT_TYPE);
BpmBoundaryEventType bpmTimerBoundaryEventType = BpmBoundaryEventType.typeOf(NumberUtils.parseInt(boundaryEventType));
BpmBoundaryEventTypeEnum bpmTimerBoundaryEventType = BpmBoundaryEventTypeEnum.typeOf(NumberUtils.parseInt(boundaryEventType));
// 2. 处理超时
if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventType.USER_TASK_TIMEOUT)) {
if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.USER_TASK_TIMEOUT)) {
// 2.1 用户任务超时处理
String timeoutHandlerType = BpmnModelUtils.parseBoundaryEventExtensionElement(boundaryEvent,
BpmnModelConstants.USER_TASK_TIMEOUT_HANDLER_TYPE);
String taskKey = boundaryEvent.getAttachedToRefId();
taskService.processTaskTimeout(event.getProcessInstanceId(), taskKey, NumberUtils.parseInt(timeoutHandlerType));
// 2.2 延迟器超时处理
} else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventType.DELAY_TIMER_TIMEOUT)) {
} else if (ObjectUtil.equal(bpmTimerBoundaryEventType, BpmBoundaryEventTypeEnum.DELAY_TIMER_TIMEOUT)) {
String taskKey = boundaryEvent.getAttachedToRefId();
taskService.processDelayTimerTimeout(event.getProcessInstanceId(), taskKey);
}

View File

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

View File

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

View File

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

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.dal.dataobject.definition.BpmProcessListenerDO;
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.BpmProcessListenerValueType;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmProcessListenerTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmProcessListenerValueTypeEnum;
import jakarta.annotation.Resource;
import org.flowable.engine.delegate.JavaDelegate;
import org.flowable.engine.delegate.TaskListener;
@ -52,14 +52,14 @@ public class BpmProcessListenerServiceImpl implements BpmProcessListenerService
private void validateCreateProcessListenerValue(BpmProcessListenerSaveReqVO createReqVO) {
// class 类型
if (createReqVO.getValueType().equals(BpmProcessListenerValueType.CLASS.getType())) {
if (createReqVO.getValueType().equals(BpmProcessListenerValueTypeEnum.CLASS.getType())) {
try {
Class<?> clazz = Class.forName(createReqVO.getValue());
if (createReqVO.getType().equals(BpmProcessListenerType.EXECUTION.getType())
if (createReqVO.getType().equals(BpmProcessListenerTypeEnum.EXECUTION.getType())
&& !JavaDelegate.class.isAssignableFrom(clazz)) {
throw exception(PROCESS_LISTENER_CLASS_IMPLEMENTS_ERROR, createReqVO.getValue(),
JavaDelegate.class.getName());
} else if (createReqVO.getType().equals(BpmProcessListenerType.TASK.getType())
} else if (createReqVO.getType().equals(BpmProcessListenerTypeEnum.TASK.getType())
&& !TaskListener.class.isAssignableFrom(clazz)) {
throw exception(PROCESS_LISTENER_CLASS_IMPLEMENTS_ERROR, createReqVO.getValue(),
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.enums.ErrorCodeConstants;
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.BpmReasonEnum;
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());
ActivityNode activityNode = new ActivityNode().setId(task.getTaskDefinitionKey()).setName(task.getName())
.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))
.setCandidateStrategy(BpmnModelUtils.parseCandidateStrategy(flowNode))
.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)
.setAssignee(startUserId).setStatus(BpmTaskStatusEnum.APPROVE.getStatus());
ActivityNode startNode = new ActivityNode().setId(startTask.getId())
.setName(BpmSimpleModelNodeType.START_USER_NODE.getName())
.setNodeType(BpmSimpleModelNodeType.START_USER_NODE.getType())
.setName(BpmSimpleModelNodeTypeEnum.START_USER_NODE.getName())
.setNodeType(BpmSimpleModelNodeTypeEnum.START_USER_NODE.getType())
.setStatus(startTask.getStatus()).setTasks(ListUtil.of(startTask))
.setStartTime(DateUtils.of(activity.getStartTime())).setEndTime(DateUtils.of(activity.getEndTime()));
approvalNodes.add(0, startNode);
@ -330,8 +330,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
return;
}
ActivityNode endNode = new ActivityNode().setId(activity.getId())
.setName(BpmSimpleModelNodeType.END_NODE.getName())
.setNodeType(BpmSimpleModelNodeType.END_NODE.getType()).setStatus(processInstanceStatus)
.setName(BpmSimpleModelNodeTypeEnum.END_NODE.getName())
.setNodeType(BpmSimpleModelNodeTypeEnum.END_NODE.getType()).setStatus(processInstanceStatus)
.setStartTime(DateUtils.of(activity.getStartTime())).setEndTime(DateUtils.of(activity.getEndTime()));
String reason = FlowableUtils.getProcessInstanceReason(historicProcessInstance);
if (StrUtil.isNotEmpty(reason)) {
@ -367,7 +367,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
FlowElement flowNode = BpmnModelUtils.getFlowElementById(bpmnModel, activityId);
HistoricActivityInstance firstActivity = CollUtil.getFirst(taskActivities); // 取第一个任务会签/或签的任务开始时间相同
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))
.setStartTime(DateUtils.of(CollUtil.getFirst(taskActivities).getStartTime()))
.setTasks(new ArrayList<>());
@ -437,8 +437,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
// 1. 开始节点/审批节点
if (ObjectUtils.equalsAny(node.getType(),
BpmSimpleModelNodeType.START_USER_NODE.getType(),
BpmSimpleModelNodeType.APPROVE_NODE.getType())) {
BpmSimpleModelNodeTypeEnum.START_USER_NODE.getType(),
BpmSimpleModelNodeTypeEnum.APPROVE_NODE.getType())) {
List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(),
startUserId, processDefinitionInfo.getProcessDefinitionId(), processVariables);
activityNode.setCandidateUserIds(candidateUserIds);
@ -446,13 +446,13 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
}
// 2. 结束节点
if (BpmSimpleModelNodeType.END_NODE.getType().equals(node.getType())) {
if (BpmSimpleModelNodeTypeEnum.END_NODE.getType().equals(node.getType())) {
return activityNode;
}
// 3. 抄送节点
if (CollUtil.isEmpty(runActivityIds) && // 流程发起时需要展示抄送节点用于选择抄送人
BpmSimpleModelNodeType.COPY_NODE.getType().equals(node.getType())) {
BpmSimpleModelNodeTypeEnum.COPY_NODE.getType().equals(node.getType())) {
return activityNode;
}
return null;
@ -468,23 +468,23 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
// 1. 开始节点
if (node instanceof StartEvent) {
return activityNode.setName(BpmSimpleModelNodeType.START_USER_NODE.getName())
.setNodeType(BpmSimpleModelNodeType.START_USER_NODE.getType());
return activityNode.setName(BpmSimpleModelNodeTypeEnum.START_USER_NODE.getName())
.setNodeType(BpmSimpleModelNodeTypeEnum.START_USER_NODE.getType());
}
// 2. 审批节点
if (node instanceof UserTask) {
List<Long> candidateUserIds = getTaskCandidateUserList(bpmnModel, node.getId(),
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))
.setCandidateUserIds(candidateUserIds);
}
// 3. 结束节点
if (node instanceof EndEvent) {
return activityNode.setName(BpmSimpleModelNodeType.END_NODE.getName())
.setNodeType(BpmSimpleModelNodeType.END_NODE.getType());
return activityNode.setName(BpmSimpleModelNodeTypeEnum.END_NODE.getName())
.setNodeType(BpmSimpleModelNodeTypeEnum.END_NODE.getType());
}
return null;
}

View File

@ -656,8 +656,8 @@ public class BpmTaskServiceImpl implements BpmTaskService {
BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(task.getProcessDefinitionId());
FlowElement userTaskElement = BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey());
// 3.1 情况一驳回到指定的任务节点
BpmUserTaskRejectHandlerType userTaskRejectHandlerType = BpmnModelUtils.parseRejectHandlerType(userTaskElement);
if (userTaskRejectHandlerType == BpmUserTaskRejectHandlerType.RETURN_USER_TASK) {
BpmUserTaskRejectHandlerTypeEnum userTaskRejectHandlerType = BpmnModelUtils.parseRejectHandlerType(userTaskElement);
if (userTaskRejectHandlerType == BpmUserTaskRejectHandlerTypeEnum.RETURN_USER_TASK) {
String returnTaskId = BpmnModelUtils.parseReturnTaskId(userTaskElement);
Assert.notNull(returnTaskId, "退回的节点不能为空");
returnTask(userId, new BpmTaskReturnReqVO().setId(task.getId())
@ -1184,23 +1184,24 @@ public class BpmTaskServiceImpl implements BpmTaskService {
.taskAssignee(task.getAssignee()) // 相同审批人
.taskVariableValueEquals(BpmnVariableConstants.TASK_VARIABLE_STATUS, BpmTaskStatusEnum.APPROVE.getStatus())
.finished();
if (BpmAutoApproveType.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType())
if (BpmAutoApproveTypeEnum.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType())
&& sameAssigneeQuery.count() > 0) {
getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
.setReason(BpmAutoApproveType.APPROVE_ALL.getName()));
.setReason(BpmAutoApproveTypeEnum.APPROVE_ALL.getName()));
return;
}
if (BpmAutoApproveType.APPROVE_SEQUENT.getType().equals(processDefinitionInfo.getAutoApprovalType())) {
if (BpmAutoApproveTypeEnum.APPROVE_SEQUENT.getType().equals(processDefinitionInfo.getAutoApprovalType())) {
BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId());
if (bpmnModel == null) {
log.error("[processTaskAssigned][taskId({}) 没有找到流程模型({})]", task.getId(), task.getProcessDefinitionId());
return;
}
List<String> sourceTaskIds = getElementIncomingFlows(getFlowElementById(bpmnModel, task.getTaskDefinitionKey()))
.stream().map(SequenceFlow::getSourceRef).toList();
List<String> sourceTaskIds = convertList(BpmnModelUtils.getElementIncomingFlows( // 获取所有上一个节点
BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey())),
SequenceFlow::getSourceRef);
if (sameAssigneeQuery.taskDefinitionKeys(sourceTaskIds).count() > 0) {
getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId())
.setReason(BpmAutoApproveType.APPROVE_SEQUENT.getName()));
.setReason(BpmAutoApproveTypeEnum.APPROVE_SEQUENT.getName()));
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.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.service.task.BpmProcessInstanceService;
import jakarta.annotation.Resource;
@ -37,16 +37,16 @@ public class BpmHttpRequestTrigger implements BpmTrigger {
private RestTemplate restTemplate;
@Override
public BpmTriggerType getType() {
return BpmTriggerType.HTTP_REQUEST;
public BpmTriggerTypeEnum getType() {
return BpmTriggerTypeEnum.HTTP_REQUEST;
}
@Override
public void execute(String processInstanceId, String param) {
// 1. 解析 http 请求配置
HttpRequestTriggerSetting httpRequestSetting = JsonUtils.parseObject(param, HttpRequestTriggerSetting.class);
if (httpRequestSetting == null) {
log.error("[execute] HTTP 触发器请求配置为空");
HttpRequestTriggerSetting setting = JsonUtils.parseObject(param, HttpRequestTriggerSetting.class);
if (setting == null) {
log.error("[execute][流程({}) HTTP 触发器请求配置为空]", processInstanceId);
return;
}
// 2.1 设置请求头
@ -54,20 +54,22 @@ public class BpmHttpRequestTrigger implements BpmTrigger {
Map<String, Object> processVariables = processInstance.getProcessVariables();
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add(HEADER_TENANT_ID, processInstance.getTenantId());
SimpleModelUtils.addHttpRequestParam(headers, httpRequestSetting.getHeader(), processVariables);
SimpleModelUtils.addHttpRequestParam(headers, setting.getHeader(), processVariables);
// 2.2 设置请求体
MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
SimpleModelUtils.addHttpRequestParam(body, httpRequestSetting.getBody(), processVariables);
SimpleModelUtils.addHttpRequestParam(body, setting.getBody(), processVariables);
body.add("processInstanceId", processInstanceId);
// TODO @芋艿要不要抽象一个 Http 请求的工具类方便复用呢
// 3. 发起请求
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(body, headers);
try {
ResponseEntity<String> responseEntity = restTemplate.exchange(httpRequestSetting.getUrl(), HttpMethod.POST,
ResponseEntity<String> responseEntity = restTemplate.exchange(setting.getUrl(), HttpMethod.POST,
requestEntity, String.class);
log.info("[execute][HTTP 触发器,请求头:{},请求体:{},响应结果:{}]", headers, body, responseEntity);
} catch (RestClientException e) {
log.error("[execute][HTTP 触发器,请求头:{},请求体:{},请求出错:{}]", headers, body, e.getMessage());
}
}
}

View File

@ -1,6 +1,6 @@
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 触发器接口
@ -16,7 +16,7 @@ public interface BpmTrigger {
*
* @return 触发器类型
*/
BpmTriggerType getType();
BpmTriggerTypeEnum getType();
/**
* 触发器执行
@ -25,4 +25,5 @@ public interface BpmTrigger {
* @param param 触发器参数
*/
void execute(String processInstanceId, String param);
}