fix - 新增两个事务监听实现,用于处理自动通过和自动驳回。
This commit is contained in:
parent
c8d849ab18
commit
67bed9d052
@ -0,0 +1,58 @@
|
||||
package cn.axzo.workflow.core.engine.tx.listener;
|
||||
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import cn.axzo.workflow.core.engine.cmd.CustomApproveTaskCmd;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.common.engine.impl.cfg.TransactionListener;
|
||||
import org.flowable.common.engine.impl.cfg.TransactionPropagation;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandConfig;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandContext;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
|
||||
import org.flowable.engine.impl.cmd.GetExecutionVariableCmd;
|
||||
import org.flowable.task.service.delegate.DelegateTask;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO;
|
||||
|
||||
/**
|
||||
* 自动过审的事务监听器
|
||||
* <p>
|
||||
* 在节点会签模式下,业务指定审批人、加签时,由于这两个动作的内部是先进行 addMultiTask ,对当前节点加了新的实例数,
|
||||
* 而该动作默认会触发多种内外部实现的监听,其中一个监听是自动过审,此时,节点的完成条件 nrOfInstance == nrOfCompleteInstances 一定不满足,
|
||||
* 所以无法跳出当前节点。当 addMultiTask 执行完后,便会再执行 deleteMultiTask,但该动作只是把 nrOfInstance == nrOfCompleteInstances
|
||||
* 表达式中的两个变量值变成了可以为 true 的结果。但并不会再触发节点的 leave 动作。
|
||||
*
|
||||
* <pre>
|
||||
* 使用示例:
|
||||
* Context.getTransactionContext().addTransactionListener(TransactionState.COMMITTED, new AutoPassTransactionListener(delegateTask, ["advice"]));
|
||||
* </pre>
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024-08-07 10:24
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class AutoPassTransactionListener implements TransactionListener {
|
||||
private final DelegateTask delegateTask;
|
||||
private final String advice;
|
||||
|
||||
@Override
|
||||
public void execute(CommandContext commandContext) {
|
||||
log.info("exec auto pass transaction listener start, processInstanceId: {}, taskId: {}", delegateTask.getProcessInstanceId(), delegateTask.getId());
|
||||
|
||||
// 必须开启新的事务
|
||||
CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
|
||||
CommandExecutor commandExecutor = commandContext.getCommandExecutor();
|
||||
BpmnTaskDelegateAssigner assigner = BpmnTaskDelegateAssigner.toObjectCompatible(commandExecutor.execute(getVariableCmd()));
|
||||
commandExecutor.execute(commandConfig, new CustomApproveTaskCmd(delegateTask.getId(), advice, "自动通过",
|
||||
Collections.emptyList(), assigner, null));
|
||||
|
||||
log.info("exec auto pass transaction listener end");
|
||||
}
|
||||
|
||||
private GetExecutionVariableCmd getVariableCmd() {
|
||||
return new GetExecutionVariableCmd(delegateTask.getProcessInstanceId(), INTERNAL_TASK_RELATION_ASSIGNEE_INFO + delegateTask.getId(), false);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package cn.axzo.workflow.core.engine.tx.listener;
|
||||
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskAuditDTO;
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import cn.axzo.workflow.core.engine.cmd.CustomRejectionTaskCmd;
|
||||
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.common.engine.impl.cfg.TransactionListener;
|
||||
import org.flowable.common.engine.impl.cfg.TransactionPropagation;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandConfig;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandContext;
|
||||
import org.flowable.task.service.delegate.DelegateTask;
|
||||
|
||||
/**
|
||||
* 自动拒绝的事务监听
|
||||
*
|
||||
* <pre>
|
||||
* 使用示例:
|
||||
* Context.getTransactionContext().addTransactionListener(TransactionState.COMMITTED, new AutoRejectTransactionListener(delegateTask, extAxHiTaskInstService));
|
||||
* </pre>
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024-08-07 10:26
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class AutoRejectTransactionListener implements TransactionListener {
|
||||
private final DelegateTask delegateTask;
|
||||
private final ExtAxHiTaskInstService extAxHiTaskInstService;
|
||||
|
||||
@Override
|
||||
public void execute(CommandContext commandContext) {
|
||||
log.info("exec auto reject transaction listener start, processInstanceId: {}, taskId: {}",
|
||||
delegateTask.getProcessInstanceId(), delegateTask.getId());
|
||||
|
||||
// 必须开启新的事务
|
||||
CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
|
||||
BpmnTaskAuditDTO taskAudit = new BpmnTaskAuditDTO();
|
||||
taskAudit.setTaskId(delegateTask.getId());
|
||||
taskAudit.setApprover(new BpmnTaskDelegateAssigner("系统", "system", delegateTask.getTenantId()));
|
||||
commandContext.getCommandExecutor().execute(commandConfig, new CustomRejectionTaskCmd(taskAudit, extAxHiTaskInstService, "自动驳回"));
|
||||
|
||||
log.info("exec auto reject transaction listener end");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user