fix - 利用引擎 AsyncCmd 的能力解决通过监听事务状态不能正确发送 MQ 的问题
This commit is contained in:
parent
4935e3f8d2
commit
248ce361d1
@ -76,4 +76,10 @@ public class BpmnTaskAuditDTO {
|
||||
@ApiModelProperty(value = "指定节点类型", notes = "指定节点类型,类型不匹配抛出异常")
|
||||
@Deprecated
|
||||
private List<BpmnFlowNodeType> nodeTypes;
|
||||
|
||||
/**
|
||||
* 操作描述,该属性为流程服务内部使用
|
||||
*/
|
||||
@Deprecated
|
||||
private String operationDesc;
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.flowable.common.engine.impl.identity.Authentication;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandContext;
|
||||
import org.flowable.common.engine.impl.transaction.TransactionContextHolder;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
||||
@ -85,7 +84,7 @@ public class CustomApproveTaskCmd extends AbstractCommand<Void> implements Seria
|
||||
}
|
||||
|
||||
public CustomApproveTaskCmd(BpmnTaskAuditDTO dto) {
|
||||
this(dto, null);
|
||||
this(dto, dto.getOperationDesc());
|
||||
}
|
||||
|
||||
public CustomApproveTaskCmd(BpmnTaskAuditDTO dto, String operationDesc) {
|
||||
@ -121,7 +120,6 @@ public class CustomApproveTaskCmd extends AbstractCommand<Void> implements Seria
|
||||
|
||||
@Override
|
||||
public Void execute(CommandContext commandContext) {
|
||||
log.warn("CustomApproveTaskCmd current transaction status :{}", TransactionContextHolder.isTransactionContextActive());
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration =
|
||||
CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
HistoricTaskInstanceQuery taskQuery =
|
||||
|
||||
@ -16,6 +16,7 @@ import org.flowable.task.api.Task;
|
||||
import org.flowable.task.api.history.HistoricTaskInstance;
|
||||
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
|
||||
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
@ -46,7 +47,7 @@ public class CustomRejectionTaskCmd extends AbstractCommand<Void> implements Ser
|
||||
|
||||
private final String taskId;
|
||||
private final String advice;
|
||||
private final String operationDesc;
|
||||
private String operationDesc = "已驳回";
|
||||
private final List<AttachmentDTO> attachmentList;
|
||||
private final BpmnTaskDelegateAssigner approver;
|
||||
private final ExtAxHiTaskInstService extAxHiTaskInstService;
|
||||
@ -56,13 +57,15 @@ public class CustomRejectionTaskCmd extends AbstractCommand<Void> implements Ser
|
||||
private final List<BpmnFlowNodeType> nodeTypes;
|
||||
|
||||
public CustomRejectionTaskCmd(BpmnTaskAuditDTO dto, ExtAxHiTaskInstService extAxHiTaskInstService) {
|
||||
this(dto, extAxHiTaskInstService, "已驳回");
|
||||
this(dto, extAxHiTaskInstService, dto.getOperationDesc());
|
||||
}
|
||||
|
||||
public CustomRejectionTaskCmd(BpmnTaskAuditDTO dto, ExtAxHiTaskInstService extAxHiTaskInstService, String operationDesc) {
|
||||
this.taskId = dto.getTaskId();
|
||||
this.advice = dto.getAdvice();
|
||||
this.operationDesc = operationDesc;
|
||||
if (StringUtils.hasText(operationDesc)) {
|
||||
this.operationDesc = operationDesc;
|
||||
}
|
||||
this.attachmentList = dto.getAttachmentList();
|
||||
this.approver = dto.getApprover();
|
||||
this.extAxHiTaskInstService = extAxHiTaskInstService;
|
||||
|
||||
@ -44,7 +44,7 @@ public class AsyncApproveTaskJobHandler extends AbstractExecuteWithLockJobHandle
|
||||
}
|
||||
CustomApproveTaskCmd command = new CustomApproveTaskCmd(dto);
|
||||
if (Objects.equals(task.getTaskDefinitionKey(), NODE_STARTER.getType())) {
|
||||
command = new CustomApproveTaskCmd(dto, "");
|
||||
command = new CustomApproveTaskCmd(dto);
|
||||
}
|
||||
processEngineConfiguration.getCommandExecutor().execute(command);
|
||||
}
|
||||
|
||||
@ -44,17 +44,15 @@ public class AutoPassTransactionListener implements TransactionListener {
|
||||
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
|
||||
BpmnTaskDelegateAssigner assigner = BpmnTaskDelegateAssigner.toObjectCompatible(
|
||||
runtimeService.getVariable(delegateTask.getProcessInstanceId(), INTERNAL_TASK_RELATION_ASSIGNEE_INFO + delegateTask.getId()));
|
||||
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
|
||||
|
||||
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
|
||||
BpmnTaskAuditDTO pass = new BpmnTaskAuditDTO();
|
||||
pass.setTaskId(delegateTask.getId());
|
||||
pass.setAdvice(advice);
|
||||
pass.setApprover(assigner);
|
||||
pass.setOperationDesc("自动通过");
|
||||
commandExecutor.execute(new CustomApproveTaskAsyncCmd(pass));
|
||||
|
||||
// commandExecutor.execute(commandConfig, new CustomApproveTaskCmd(delegateTask.getId(), advice, "自动通过",
|
||||
// Collections.emptyList(), assigner, null));
|
||||
|
||||
log.info("exec auto pass transaction listener end");
|
||||
}
|
||||
|
||||
|
||||
@ -2,13 +2,11 @@ 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.engine.cmd.CustomRejectionTaskAsyncCmd;
|
||||
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.TransactionState;
|
||||
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.ProcessEngineConfiguration;
|
||||
@ -31,21 +29,18 @@ public class AutoRejectTransactionListener implements TransactionListener {
|
||||
private final ProcessEngineConfiguration processEngineConfiguration;
|
||||
private final DelegateTask delegateTask;
|
||||
private final ExtAxHiTaskInstService extAxHiTaskInstService;
|
||||
private final TransactionState transactionState;
|
||||
|
||||
@Override
|
||||
public void execute(CommandContext commandContext) {
|
||||
log.info("exec auto reject transaction listener start, processInstanceId: {}, taskId: {}, transaction: {}",
|
||||
delegateTask.getProcessInstanceId(), delegateTask.getId(), transactionState);
|
||||
|
||||
log.info("exec auto reject transaction listener start, processInstanceId: {}, taskId: {}",
|
||||
delegateTask.getProcessInstanceId(), delegateTask.getId());
|
||||
|
||||
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
|
||||
BpmnTaskAuditDTO taskAudit = new BpmnTaskAuditDTO();
|
||||
taskAudit.setTaskId(delegateTask.getId());
|
||||
taskAudit.setApprover(new BpmnTaskDelegateAssigner("系统", "system", delegateTask.getTenantId()));
|
||||
|
||||
CommandConfig commandConfig = new CommandConfig().transactionRequiresNew();
|
||||
commandExecutor.execute(commandConfig, new CustomRejectionTaskCmd(taskAudit, extAxHiTaskInstService, "自动驳回"));
|
||||
BpmnTaskAuditDTO reject = new BpmnTaskAuditDTO();
|
||||
reject.setTaskId(delegateTask.getId());
|
||||
reject.setApprover(new BpmnTaskDelegateAssigner("系统", "system", delegateTask.getTenantId()));
|
||||
reject.setOperationDesc("自动驳回");
|
||||
commandExecutor.execute(new CustomRejectionTaskAsyncCmd(reject));
|
||||
|
||||
log.info("exec auto reject transaction listener end");
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ import org.flowable.bpmn.model.Process;
|
||||
import org.flowable.bpmn.model.UserTask;
|
||||
import org.flowable.common.engine.impl.cfg.TransactionState;
|
||||
import org.flowable.common.engine.impl.context.Context;
|
||||
import org.flowable.common.engine.impl.transaction.TransactionContextHolder;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
@ -188,9 +187,8 @@ public class AutoOperatorEvent_101_Listener extends AbstractBpmnEventListener<Ta
|
||||
* @param delegateTask 自动操作的任务
|
||||
*/
|
||||
private void autoReject(DelegateTask delegateTask, TransactionState transactionState) {
|
||||
log.warn("autoReject current transaction status :{}", TransactionContextHolder.isTransactionContextActive());
|
||||
Context.getTransactionContext().addTransactionListener(transactionState,
|
||||
new AutoRejectTransactionListener(CommandContextUtil.getProcessEngineConfiguration(), delegateTask, extAxHiTaskInstService, TransactionState.COMMITTED));
|
||||
new AutoRejectTransactionListener(CommandContextUtil.getProcessEngineConfiguration(), delegateTask, extAxHiTaskInstService));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,7 +200,6 @@ public class AutoOperatorEvent_101_Listener extends AbstractBpmnEventListener<Ta
|
||||
* @param advice 添加自动操作任务时的额外意见
|
||||
*/
|
||||
private void autoPass(DelegateTask delegateTask, TransactionState transactionState, @Nullable String advice) {
|
||||
log.warn("autoPass current transaction status :{}", TransactionContextHolder.isTransactionContextActive());
|
||||
Context.getTransactionContext().addTransactionListener(transactionState,
|
||||
new AutoPassTransactionListener(CommandContextUtil.getProcessEngineConfiguration(), delegateTask, advice));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user