update - 异步化通过按钮的操作
This commit is contained in:
parent
01fc2eee8b
commit
1201a48498
@ -2,6 +2,7 @@ package cn.axzo.workflow.core.conf;
|
||||
|
||||
import cn.axzo.workflow.core.engine.behavior.CustomActivityBehaviorFactory;
|
||||
import cn.axzo.workflow.core.engine.id.DistributedTimeBasedIdGenerator;
|
||||
import cn.axzo.workflow.core.engine.job.AsyncApproveTaskJobHandler;
|
||||
import cn.axzo.workflow.core.engine.persistence.CustomMybatisHistoricProcessInstanceDataManager;
|
||||
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -42,6 +43,7 @@ public class FlowableConfiguration {
|
||||
// configuration.setCreateDiagramOnDeploy(false);
|
||||
configuration.setIdGenerator(new DistributedTimeBasedIdGenerator(stringRedisTemplate));
|
||||
configuration.setHistoricProcessInstanceDataManager(new CustomMybatisHistoricProcessInstanceDataManager(configuration));
|
||||
configuration.addCustomJobHandler(new AsyncApproveTaskJobHandler());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package cn.axzo.workflow.core.engine.cmd;
|
||||
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.AttachmentDTO;
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import cn.axzo.workflow.core.engine.job.AsyncApproveTaskJobHandler;
|
||||
import org.flowable.common.engine.impl.identity.Authentication;
|
||||
import org.flowable.common.engine.impl.interceptor.Command;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandContext;
|
||||
@ -9,6 +10,8 @@ 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.job.service.JobService;
|
||||
import org.flowable.job.service.impl.persistence.entity.JobEntity;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.flowable.task.api.history.HistoricTaskInstance;
|
||||
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
|
||||
@ -112,9 +115,9 @@ public class CustomApproveTaskCmd implements Command<Void>, Serializable {
|
||||
}
|
||||
((TaskEntity) task).setTransientVariable(TASK_COMPLETE_OPERATION_TYPE + taskId, APPROVED.getStatus());
|
||||
|
||||
|
||||
// TODO 这个范围需要扩大到整个 Command, 而不是在这里, 否则此前的代码逻辑会持久化数据库.
|
||||
if (async) {
|
||||
|
||||
executeAsynchronous(commandContext, runtimeService, task);
|
||||
} else {
|
||||
executeSynchronous(task, taskService, runtimeService);
|
||||
}
|
||||
@ -122,7 +125,7 @@ public class CustomApproveTaskCmd implements Command<Void>, Serializable {
|
||||
}
|
||||
|
||||
private void executeSynchronous(Task task, TaskService taskService, RuntimeService runtimeService) {
|
||||
if (StringUtils.hasLength(task.getExecutionId())) {
|
||||
if (StringUtils.hasText(task.getExecutionId())) {
|
||||
// 正常完成流程任务,审批通过
|
||||
taskService.complete(task.getId(), runtimeService.getVariables(task.getExecutionId()));
|
||||
} else {
|
||||
@ -131,8 +134,26 @@ public class CustomApproveTaskCmd implements Command<Void>, Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
private void executeAsynchronous() {
|
||||
private void executeAsynchronous(CommandContext commandContext, RuntimeService runtimeService, Task task) {
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
JobService jobService = processEngineConfiguration.getJobServiceConfiguration().getJobService();
|
||||
|
||||
JobEntity job = jobService.createJob();
|
||||
// 这里的 executionId 可为 null
|
||||
job.setExecutionId(task.getExecutionId());
|
||||
job.setProcessInstanceId(task.getProcessInstanceId());
|
||||
job.setProcessDefinitionId(task.getProcessDefinitionId());
|
||||
job.setElementId(task.getTaskDefinitionKey());
|
||||
job.setElementName(task.getName());
|
||||
job.setJobHandlerType(AsyncApproveTaskJobHandler.TYPE);
|
||||
job.setTenantId(task.getTenantId());
|
||||
|
||||
// 携带自定义的数据
|
||||
job.setCustomValues(task.getId());
|
||||
|
||||
// 创建异步任务并调度
|
||||
jobService.createAsyncJob(job, false);
|
||||
jobService.scheduleAsyncJob(job);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
package cn.axzo.workflow.core.engine.job;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.job.service.JobHandler;
|
||||
import org.flowable.job.service.impl.persistence.entity.JobEntity;
|
||||
import org.flowable.variable.api.delegate.VariableScope;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/4/15 22:41
|
||||
*/
|
||||
@Slf4j
|
||||
public class AsyncApproveTaskJobHandler implements JobHandler {
|
||||
public static final String TYPE = "async-approve-task";
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
|
||||
log.info("AsyncApproveTaskJobHandler executing...");
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration =
|
||||
CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
|
||||
TaskService taskService = processEngineConfiguration.getTaskService();
|
||||
if (Objects.nonNull(variableScope)) {
|
||||
// 正常完成流程任务,审批通过
|
||||
taskService.complete(job.getCustomValues(), runtimeService.getVariables(job.getExecutionId()));
|
||||
} else {
|
||||
// 特殊的完成单独创建的任务
|
||||
taskService.complete(job.getCustomValues());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user