feat(REQ-4418) - 优化业务节点最顶部配置的冲突问题

This commit is contained in:
wangli 2025-08-26 14:44:29 +08:00
parent 8645b0a86b
commit 04035295b4
5 changed files with 62 additions and 6 deletions

View File

@ -19,6 +19,7 @@ public enum ApprovalMethodEnum {
nobody("nobody", "不设置审批人", "[仅业务节点可能有该值]"),
bizSpecify("bizSpecify", "业务指定审批人", "[仅业务节点可能有该值]"),
transferToAdmin("transferToAdmin", "转办给管理员", "该枚举仅日志处理使用"),
unknown("unknown", "未知", "兜底")
;
private String type;

View File

@ -1,17 +1,15 @@
package cn.axzo.workflow.core.engine.cmd;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnActivityTriggerDTO;
import cn.axzo.workflow.common.exception.WorkflowEngineException;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnActivityTriggerDTO;
import cn.axzo.workflow.core.engine.job.AsyncActivityTriggerJobHandler;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.runtime.Execution;
import org.flowable.job.service.JobService;
import org.flowable.job.service.impl.persistence.entity.JobEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
@ -22,6 +20,7 @@ import java.io.Serializable;
import java.util.Objects;
import static cn.axzo.workflow.common.code.BpmnTaskRespCode.ACTIVITY_TRIGGER_NOT_EXISTS;
import static cn.axzo.workflow.core.engine.cmd.CustomActivityTriggerCmd.validateActivityConfig;
/**
* 自定义(异步)流转业务姐弟那的命令器实现
@ -47,7 +46,7 @@ public class CustomActivityTriggerAsyncCmd extends AbstractCommand<String> imple
@Override
public String execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
CommandContextUtil.getProcessEngineConfiguration(commandContext);
TaskEntity task = (TaskEntity) processEngineConfiguration.getTaskService().createTaskQuery()
.executionId(dto.getTriggerId())
.taskDefinitionKey(StringUtils.isBlank(dto.getActivityId()) ? null : dto.getActivityId())
@ -56,12 +55,17 @@ public class CustomActivityTriggerAsyncCmd extends AbstractCommand<String> imple
throw new WorkflowEngineException(ACTIVITY_TRIGGER_NOT_EXISTS, dto.getTriggerId());
}
if (!validateActivityConfig(task)) {
log.info("业务节点唤醒时发现节点已经修改配置无法继续唤醒processInstanceId:{}, taskDefinitionKey={}", task.getProcessInstanceId(), task.getTaskDefinitionKey());
return "";
}
return startAsync(commandContext);
}
private String startAsync(CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
CommandContextUtil.getProcessEngineConfiguration(commandContext);
TaskService taskService = processEngineConfiguration.getTaskService();
TaskEntity task = (TaskEntity) taskService.createTaskQuery()
.executionId(dto.getTriggerId())

View File

@ -1,13 +1,18 @@
package cn.axzo.workflow.core.engine.cmd;
import cn.axzo.workflow.common.enums.ApprovalMethodEnum;
import cn.axzo.workflow.common.exception.WorkflowEngineException;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnActivityTriggerDTO;
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -52,9 +57,24 @@ public class CustomActivityTriggerCmd extends AbstractCommand<Void> implements S
if (Objects.isNull(task)) {
throw new WorkflowEngineException(ACTIVITY_TRIGGER_NOT_EXISTS, dto.getTriggerId());
}
if (!validateActivityConfig(task)) {
log.info("业务节点唤醒时发现节点已经修改配置无法继续唤醒processInstanceId:{}, taskDefinitionKey={}", task.getProcessInstanceId(), task.getTaskDefinitionKey());
return null;
}
addComment(commandContext, task, COMMENT_TYPE_OPERATION_DESC, "已同意");
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
runtimeService.trigger(dto.getTriggerId());
return null;
}
public static boolean validateActivityConfig(TaskEntity task) {
BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(task.getProcessDefinitionId());
FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
ApprovalMethodEnum approvalMethodEnum = BpmnMetaParserHelper.getApprovalMethod(flowElement).orElse(ApprovalMethodEnum.unknown);
return Objects.equals(approvalMethodEnum, ApprovalMethodEnum.nobody);
}
}

View File

@ -11,12 +11,15 @@ import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.job.service.JobService;
import org.flowable.job.service.impl.persistence.entity.JobEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Serializable;
import static cn.axzo.workflow.core.engine.cmd.CustomBizSpecifyAssigneeToTaskCmd.getOperateTask;
import static cn.axzo.workflow.core.engine.cmd.CustomBizSpecifyAssigneeToTaskCmd.validProcessInstance;
import static cn.axzo.workflow.core.engine.cmd.CustomBizSpecifyAssigneeToTaskCmd.validate;
import static cn.axzo.workflow.core.engine.cmd.CustomBizSpecifyAssigneeToTaskCmd.validateActivityConfig;
/**
* 自定的业务指定审批人命令实现
@ -26,6 +29,7 @@ import static cn.axzo.workflow.core.engine.cmd.CustomBizSpecifyAssigneeToTaskCmd
*/
public class CustomBizSpecifyAssigneeToTaskAsyncCmd extends AbstractCommand<String> implements Serializable {
private static final Logger log = LoggerFactory.getLogger(CustomBizSpecifyAssigneeToTaskAsyncCmd.class);
private final BpmnActivitySetAssigneeDTO dto;
public CustomBizSpecifyAssigneeToTaskAsyncCmd(BpmnActivitySetAssigneeDTO dto) {
@ -46,6 +50,12 @@ public class CustomBizSpecifyAssigneeToTaskAsyncCmd extends AbstractCommand<Stri
//校验
validate(processEngineConfiguration.getRuntimeService(), dto.getTriggerId(), task, dto.getAssigners());
// 校验节点真实的节点配置还是否是指定人
if (!validateActivityConfig(task)) {
log.info("业务节点设置审批人时发现节点已经修改配置无法继续设置审批人processInstanceId:{}, taskDefinitionKey={}", task.getProcessInstanceId(), task.getTaskDefinitionKey());
return "";
}
validProcessInstance(commandContext, task, dto.getAssigners());
return startAsync(processEngineConfiguration, task);

View File

@ -1,12 +1,15 @@
package cn.axzo.workflow.core.engine.cmd;
import cn.axzo.workflow.common.enums.ApprovalMethodEnum;
import cn.axzo.workflow.common.exception.WorkflowEngineException;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
import cn.axzo.workflow.core.common.utils.SpringContextUtils;
import cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper;
import cn.axzo.workflow.core.service.CategoryService;
import com.alibaba.fastjson.JSON;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.HistoryService;
import org.flowable.engine.ManagementService;
@ -20,6 +23,8 @@ import org.flowable.job.api.Job;
import org.flowable.job.service.impl.persistence.entity.TimerJobEntity;
import org.flowable.task.api.Task;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@ -53,7 +58,7 @@ import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTask
* @since 2023/12/22 13:51
*/
public class CustomBizSpecifyAssigneeToTaskCmd extends AbstractCommand<Boolean> implements Serializable {
private static final Logger log = LoggerFactory.getLogger(CustomBizSpecifyAssigneeToTaskCmd.class);
private final String executionId;
private final List<BpmnTaskDelegateAssigner> addedAssigners;
@ -103,6 +108,12 @@ public class CustomBizSpecifyAssigneeToTaskCmd extends AbstractCommand<Boolean>
//校验
validate(processEngineConfiguration.getRuntimeService(), executionId, task, addedAssigners);
// 校验节点真实的节点配置还是否是指定人
if (!validateActivityConfig(task)) {
log.info("业务节点设置审批人时发现节点已经修改配置无法继续设置审批人processInstanceId:{}, taskDefinitionKey={}", task.getProcessInstanceId(), task.getTaskDefinitionKey());
return true;
}
validProcessInstance(commandContext, task, addedAssigners);
changeAssigneeSnapshot(commandContext, task);
@ -114,12 +125,22 @@ public class CustomBizSpecifyAssigneeToTaskCmd extends AbstractCommand<Boolean>
return true;
}
public static boolean validateActivityConfig(TaskEntity task) {
BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(task.getProcessDefinitionId());
FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
ApprovalMethodEnum approvalMethodEnum = BpmnMetaParserHelper.getApprovalMethod(flowElement).orElse(ApprovalMethodEnum.unknown);
return Objects.equals(approvalMethodEnum, ApprovalMethodEnum.bizSpecify);
}
/**
* 清空告警的任务
* <p>
* 这个方法在最新的告警功能中应该已经失效了这里保留只是为了暂时兼容
*
* @param commandContext
* @param task
*/
@Deprecated
private void clearAlterTimeJob(CommandContext commandContext, TaskEntity task) {
ManagementService managementService = CommandContextUtil.getProcessEngineConfiguration(commandContext).getManagementService();
Job timerJob = managementService.createTimerJobQuery().elementId(task.getTaskDefinitionKey()).processInstanceId(task.getProcessInstanceId()).singleResult();