fix - 利用引擎 AsyncCmd 的能力解决通过监听事务状态不能正确发送 MQ 的问题
This commit is contained in:
parent
37ed9a594d
commit
ee718f7882
@ -4,7 +4,6 @@ import cn.axzo.framework.jackson.utility.JSON;
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskAuditDTO;
|
||||
import cn.axzo.workflow.core.engine.job.AsyncRejectTaskJobHandler;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandContext;
|
||||
import org.flowable.engine.TaskService;
|
||||
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
||||
@ -26,7 +25,7 @@ import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTask
|
||||
* @author wangli
|
||||
* @since 2024/1/4 13:36
|
||||
*/
|
||||
public class CustomRejectionTaskAsyncCmd extends AbstractCommand<Void> implements Serializable {
|
||||
public class CustomRejectionTaskAsyncCmd extends AbstractCommand<String> implements Serializable {
|
||||
private final BpmnTaskAuditDTO dto;
|
||||
|
||||
public CustomRejectionTaskAsyncCmd(BpmnTaskAuditDTO dto) {
|
||||
@ -39,7 +38,7 @@ public class CustomRejectionTaskAsyncCmd extends AbstractCommand<Void> implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void execute(CommandContext commandContext) {
|
||||
public String execute(CommandContext commandContext) {
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration =
|
||||
CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
HistoricTaskInstanceQuery taskQuery =
|
||||
@ -55,7 +54,7 @@ public class CustomRejectionTaskAsyncCmd extends AbstractCommand<Void> implement
|
||||
return null;
|
||||
}
|
||||
|
||||
private void startAsync(ProcessEngineConfigurationImpl processEngineConfiguration, Task task) {
|
||||
private String startAsync(ProcessEngineConfigurationImpl processEngineConfiguration, Task task) {
|
||||
JobService jobService = processEngineConfiguration.getJobServiceConfiguration().getJobService();
|
||||
|
||||
JobEntity job = jobService.createJob();
|
||||
@ -74,6 +73,7 @@ public class CustomRejectionTaskAsyncCmd extends AbstractCommand<Void> implement
|
||||
// 创建异步任务并调度
|
||||
jobService.createAsyncJob(job, false);
|
||||
jobService.scheduleAsyncJob(job);
|
||||
return job.getId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -9,9 +9,13 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.common.engine.impl.cfg.TransactionListener;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandContext;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
|
||||
import org.flowable.job.service.JobServiceConfiguration;
|
||||
import org.flowable.job.service.impl.asyncexecutor.ResetExpiredJobsCmd;
|
||||
import org.flowable.spring.SpringProcessEngineConfiguration;
|
||||
import org.flowable.task.service.delegate.DelegateTask;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* 自动拒绝的事务监听
|
||||
*
|
||||
@ -40,7 +44,10 @@ public class AutoRejectTransactionListener implements TransactionListener {
|
||||
reject.setTaskId(delegateTask.getId());
|
||||
reject.setApprover(new BpmnTaskDelegateAssigner("系统", "system", delegateTask.getTenantId()));
|
||||
reject.setOperationDesc("自动驳回");
|
||||
commandExecutor.execute(new CustomRejectionTaskAsyncCmd(reject));
|
||||
String jobId = commandExecutor.execute(new CustomRejectionTaskAsyncCmd(reject));
|
||||
|
||||
JobServiceConfiguration jobServiceConfiguration = springProcessEngineConfiguration.getJobServiceConfiguration();
|
||||
commandExecutor.execute(new ResetExpiredJobsCmd(Collections.singletonList(jobId), jobServiceConfiguration.getJobEntityManager(), jobServiceConfiguration));
|
||||
|
||||
log.info("exec auto reject transaction listener end");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user