Merge branch 'refs/heads/1.3.2-SNAPSHOT'
# Conflicts: # workflow-engine-core/src/main/java/cn/axzo/workflow/core/listener/impl/ExtTaskInstEventListener.java
This commit is contained in:
commit
f652f5f1b2
@ -36,6 +36,6 @@ public class BpmnProcessInstanceAbortDTO {
|
||||
*/
|
||||
@ApiModelProperty(value = "中止原因")
|
||||
@NotBlank(message = "中止原因不能为空")
|
||||
@Length(max = 15, message = "中止原因长度不能超过 15 个字符")
|
||||
@Length(max = 100, message = "中止原因长度不能超过 100 个字符")
|
||||
private String reason;
|
||||
}
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
package cn.axzo.workflow.core.common.code;
|
||||
|
||||
import cn.axzo.framework.domain.web.code.IModuleRespCode;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 异步任务相关响应码
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/4/29 20:30
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AsyncJobRespCode implements IModuleRespCode {
|
||||
DATA_NOT_EXISTS("001", "ExtTaskInst 数据不存在, instId: {}, taskId: {}"),
|
||||
;
|
||||
private String code;
|
||||
private String message;
|
||||
|
||||
@Override
|
||||
public String getModuleCode() {
|
||||
return "11";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProjectCode() {
|
||||
return "998";
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,7 @@ import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* 事件处理器中通用的上下文
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/4/9 21:00
|
||||
|
||||
@ -2,7 +2,7 @@ package cn.axzo.workflow.core.common.context;
|
||||
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* 操作上下文接口
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/4/9 10:05
|
||||
|
||||
@ -170,7 +170,6 @@ public final class BpmnJsonConverterUtil {
|
||||
|
||||
ExtensionAttribute serverVersion = new ExtensionAttribute();
|
||||
serverVersion.setName(FLOW_SERVER_VERSION);
|
||||
//FIXME: 尽量在每次版本迭代时, 都修改这里的版本号, 用于以后特殊场景下消息流程相关数据时, 能区别不同时期的处理办法,还需要动态起来
|
||||
serverVersion.setValue(serverVersionStr);
|
||||
ExtensionAttribute jsonMetaValue = new ExtensionAttribute();
|
||||
jsonMetaValue.setName(FLOW_NODE_JSON);
|
||||
|
||||
@ -3,6 +3,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.job.AsyncExtTaskInstJobHandler;
|
||||
import cn.axzo.workflow.core.engine.job.AsyncRejectTaskJobHandler;
|
||||
import cn.axzo.workflow.core.engine.job.exception.handler.CustomAsyncRunnableExecutionExceptionHandler;
|
||||
import cn.axzo.workflow.core.engine.persistence.CustomMybatisHistoricProcessInstanceDataManager;
|
||||
@ -44,10 +45,16 @@ public class FlowableConfiguration {
|
||||
configuration.setDatabaseSchemaUpdate(DB_SCHEMA_UPDATE_TRUE);
|
||||
configuration.setEnableSafeBpmnXml(false);
|
||||
// configuration.setCreateDiagramOnDeploy(false);
|
||||
// configuration.setIdGenerator(new TimeBasedIdGenerator());
|
||||
configuration.setIdGenerator(new DistributedTimeBasedIdGenerator(stringRedisTemplate));
|
||||
configuration.setHistoricProcessInstanceDataManager(new CustomMybatisHistoricProcessInstanceDataManager(configuration));
|
||||
// 自定义的异步任务处理器
|
||||
configuration.addCustomJobHandler(new AsyncApproveTaskJobHandler());
|
||||
configuration.addCustomJobHandler(new AsyncRejectTaskJobHandler(extAxHiTaskInstService));
|
||||
configuration.addCustomJobHandler(new AsyncExtTaskInstJobHandler(extAxHiTaskInstService));
|
||||
// 异步任务异常重试时间间隔
|
||||
configuration.setDefaultFailedJobWaitTime(30);
|
||||
configuration.setAsyncFailedJobWaitTime(30);
|
||||
configuration.setCustomAsyncRunnableExecutionExceptionHandlers(Lists.newArrayList(new CustomAsyncRunnableExecutionExceptionHandler()));
|
||||
};
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* 自定义线程配置器
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/4/9 23:10
|
||||
|
||||
@ -2,6 +2,7 @@ package cn.axzo.workflow.core.engine.event;
|
||||
|
||||
import cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEventType;
|
||||
|
||||
/**
|
||||
* 接收任务的扩展任务记录表创建的事件
|
||||
@ -10,6 +11,8 @@ import org.flowable.common.engine.api.delegate.event.FlowableEvent;
|
||||
* @since 2024/2/5 18:26
|
||||
*/
|
||||
public interface ExtTaskInstEvent extends FlowableEvent {
|
||||
@Override
|
||||
FlowableEventType getType();
|
||||
|
||||
String getProcessInstanceId();
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package cn.axzo.workflow.core.engine.event;
|
||||
|
||||
import cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum;
|
||||
import lombok.Data;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEventType;
|
||||
|
||||
import static cn.axzo.workflow.core.engine.event.ReceiveTaskEventType.UPDATE;
|
||||
@ -11,6 +12,7 @@ import static cn.axzo.workflow.core.engine.event.ReceiveTaskEventType.UPDATE;
|
||||
* @author wangli
|
||||
* @since 27/03/2024 15:02
|
||||
*/
|
||||
@Data
|
||||
public class ExtTaskInstUpdateEvent implements ExtTaskInstEvent {
|
||||
private final String processInstanceId;
|
||||
private final String activityId;
|
||||
@ -35,31 +37,6 @@ public class ExtTaskInstUpdateEvent implements ExtTaskInstEvent {
|
||||
this.resultEnum = resultEnum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProcessInstanceId() {
|
||||
return processInstanceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActivityId() {
|
||||
return activityId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAssignee() {
|
||||
return assignee;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BpmnProcessInstanceResultEnum getResultEnum() {
|
||||
return resultEnum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlowableEventType getType() {
|
||||
return UPDATE;
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
package cn.axzo.workflow.core.engine.job;
|
||||
|
||||
import cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum;
|
||||
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
|
||||
import cn.axzo.workflow.core.engine.event.ExtTaskInstUpdateEvent;
|
||||
import cn.axzo.workflow.core.repository.entity.ExtAxHiTaskInst;
|
||||
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandContext;
|
||||
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;
|
||||
|
||||
import static cn.axzo.workflow.core.common.code.AsyncJobRespCode.DATA_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 异步操作扩展任务表的处理器
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/4/29 20:22
|
||||
*/
|
||||
@Slf4j
|
||||
public class AsyncExtTaskInstJobHandler implements JobHandler {
|
||||
public static final String TYPE = "async-update-ext-task-inst";
|
||||
private final ExtAxHiTaskInstService extAxHiTaskInstService;
|
||||
|
||||
public AsyncExtTaskInstJobHandler(ExtAxHiTaskInstService extAxHiTaskInstService) {
|
||||
this.extAxHiTaskInstService = extAxHiTaskInstService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
|
||||
ExtTaskInstUpdateEvent event = JSONObject.parseObject(job.getCustomValues(), ExtTaskInstUpdateEvent.class);
|
||||
String taskId = event.getTaskId();
|
||||
String processInstanceId = event.getProcessInstanceId();
|
||||
String assignee = event.getAssignee();
|
||||
BpmnProcessInstanceResultEnum resultEnum = event.getResultEnum();
|
||||
|
||||
ExtAxHiTaskInst existence = extAxHiTaskInstService.getByTaskId(taskId, processInstanceId);
|
||||
if (Objects.nonNull(existence)) {
|
||||
log.info("更新扩展任务实例表数据: taskId:{}, instanceId:{}, currentStatus:{}, anticipateStatus: {}",
|
||||
taskId, processInstanceId, existence.getStatus(), resultEnum.getStatus());
|
||||
} else {
|
||||
log.warn("无法正确更新扩展任务表数据: taskId:{}, instanceId:{}, anticipateStatus: {}",
|
||||
taskId, processInstanceId, resultEnum.getStatus());
|
||||
throw new WorkflowEngineException(DATA_NOT_EXISTS, processInstanceId, taskId);
|
||||
}
|
||||
extAxHiTaskInstService.updateByTaskIdAndInstanceId(taskId, processInstanceId, assignee, resultEnum);
|
||||
}
|
||||
}
|
||||
@ -57,8 +57,8 @@ public class EngineTaskEventListener implements TaskListener {
|
||||
default:
|
||||
}
|
||||
});
|
||||
stopWatch.stop();
|
||||
log.info("StopWatch '" + stopWatch.currentTaskName() + "': running time = " + stopWatch.getTotalTimeSeconds() + " s");
|
||||
stopWatch.stop();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
||||
import org.flowable.engine.impl.util.CommandContextUtil;
|
||||
import org.flowable.task.api.history.HistoricTaskInstance;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -25,6 +26,7 @@ import static cn.axzo.workflow.common.constant.BpmnConstants.HIDDEN_ASSIGNEE_ID;
|
||||
public class DeleteProcessInstanceOperation extends AbstractOperation {
|
||||
private final String processInstanceId;
|
||||
private final ExtAxHiTaskInstService extAxHiTaskInstService;
|
||||
private String customDeleteReason;
|
||||
|
||||
public DeleteProcessInstanceOperation(CommandContext commandContext, String processInstanceId,
|
||||
ExtAxHiTaskInstService extAxHiTaskInstService) {
|
||||
@ -33,6 +35,15 @@ public class DeleteProcessInstanceOperation extends AbstractOperation {
|
||||
this.extAxHiTaskInstService = extAxHiTaskInstService;
|
||||
}
|
||||
|
||||
public DeleteProcessInstanceOperation(CommandContext commandContext, String processInstanceId,
|
||||
ExtAxHiTaskInstService extAxHiTaskInstService,
|
||||
String customDeleteReason) {
|
||||
super(commandContext, null);
|
||||
this.processInstanceId = processInstanceId;
|
||||
this.extAxHiTaskInstService = extAxHiTaskInstService;
|
||||
this.customDeleteReason = customDeleteReason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration =
|
||||
@ -54,7 +65,7 @@ public class DeleteProcessInstanceOperation extends AbstractOperation {
|
||||
}
|
||||
|
||||
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
|
||||
runtimeService.deleteProcessInstance(processInstanceId, HIDDEN_ASSIGNEE_ID);
|
||||
runtimeService.deleteProcessInstance(processInstanceId, StringUtils.hasText(customDeleteReason) ? customDeleteReason : HIDDEN_ASSIGNEE_ID);
|
||||
// 将结束流程实例的原因记录下来
|
||||
// runtimeService.deleteProcessInstance(processInstanceId, reason);
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import org.slf4j.MDC;
|
||||
import static cn.azxo.framework.common.constatns.Constants.CTX_LOG_ID_MDC;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* 操作上下文的抽象实现
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/4/9 14:21
|
||||
|
||||
@ -4,6 +4,7 @@ import cn.axzo.workflow.core.engine.event.ExtTaskInstCreateEvent;
|
||||
import cn.axzo.workflow.core.engine.event.ExtTaskInstEvent;
|
||||
import cn.axzo.workflow.core.engine.event.ExtTaskInstUpdateEvent;
|
||||
import cn.axzo.workflow.core.engine.event.ReceiveTaskEventType;
|
||||
import cn.axzo.workflow.core.engine.job.AsyncExtTaskInstJobHandler;
|
||||
import cn.axzo.workflow.core.repository.entity.ExtAxHiTaskInst;
|
||||
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
@ -12,6 +13,10 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.common.engine.api.delegate.event.AbstractFlowableEventListener;
|
||||
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
|
||||
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.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@ -40,10 +45,15 @@ public class ExtTaskInstEventListener extends AbstractFlowableEventListener {
|
||||
.add(UPDATE)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* 不要将该类的方法异步化, 否则有一连串的坑
|
||||
*
|
||||
* @param flowableEvent
|
||||
*/
|
||||
@Override
|
||||
public void onEvent(FlowableEvent flowableEvent) {
|
||||
if (flowableEvent instanceof ExtTaskInstEvent) {
|
||||
log.info("Ext Task Inst Event : {}", JSONUtil.toJsonStr(flowableEvent));
|
||||
log.info("Ext Task Inst Event : {}, eventType: {}", JSONUtil.toJsonStr(flowableEvent), flowableEvent.getType());
|
||||
ExtTaskInstEvent event = (ExtTaskInstEvent) flowableEvent;
|
||||
ReceiveTaskEventType eventType = (ReceiveTaskEventType) flowableEvent.getType();
|
||||
if (SUPPORT_EVENTS.contains(eventType)) {
|
||||
@ -78,9 +88,51 @@ public class ExtTaskInstEventListener extends AbstractFlowableEventListener {
|
||||
}
|
||||
|
||||
private void updateExtTaskInst(ExtTaskInstUpdateEvent event) {
|
||||
extAxHiTaskInstService.updateByTaskIdAndInstanceId(event.getTaskId(),
|
||||
event.getProcessInstanceId(),
|
||||
event.getAssignee(),
|
||||
event.getResultEnum());
|
||||
// extAxHiTaskInstService.updateByTaskIdAndInstanceId(event.getTaskId(), event.getProcessInstanceId(),
|
||||
// event.getAssignee(), event.getResultEnum());
|
||||
// 利用引擎异步任务的重试能力, 去正确更新扩展任务表的状态
|
||||
createAsyncJob(event);
|
||||
}
|
||||
|
||||
private void createAsyncJob(ExtTaskInstUpdateEvent event) {
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
|
||||
processEngineConfiguration.getCommandExecutor().execute(commandContext -> {
|
||||
JobService jobService = CommandContextUtil.getJobService(commandContext);
|
||||
JobEntity job = jobService.createJob();
|
||||
job.setJobHandlerType(AsyncExtTaskInstJobHandler.TYPE);
|
||||
|
||||
// 携带自定义的数据
|
||||
job.setCustomValues(JSONUtil.toJsonStr(event));
|
||||
|
||||
// 创建异步任务并调度
|
||||
jobService.createAsyncJob(job, false);
|
||||
jobService.scheduleAsyncJob(job);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/*private void externalJob(ExtTaskInstUpdateEvent event) {
|
||||
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
|
||||
ManagementService managementService = processEngineConfiguration.getManagementService();
|
||||
commandExecutor.execute((Command<Void>) commandContext -> {
|
||||
JobService jobService = CommandContextUtil.getJobService(commandContext);
|
||||
JobServiceConfiguration jobServiceConfiguration = processEngineConfiguration.getJobServiceConfiguration();
|
||||
ExternalWorkerJobEntity workerJob = jobService.createExternalWorkerJob();
|
||||
workerJob.setJobHandlerConfiguration("extHiTaskInst");
|
||||
workerJob.setJobType(Job.JOB_TYPE_EXTERNAL_WORKER);
|
||||
workerJob.setRetries(jobServiceConfiguration.getAsyncExecutorNumberOfRetries());
|
||||
workerJob.setJobHandlerType(AsyncExtTaskInstJobHandler.TYPE);
|
||||
workerJob.setProcessInstanceId(event.getProcessInstanceId());
|
||||
workerJob.setCustomValues(JSONUtil.toJsonStr(event));
|
||||
jobService.insertExternalWorkerJob(workerJob);
|
||||
return null;
|
||||
});
|
||||
|
||||
List<AcquiredExternalWorkerJob> acquiredJobs = managementService.createExternalWorkerJobAcquireBuilder()
|
||||
.topic("extHiTaskInst", Duration.ofMinutes(30))
|
||||
.acquireAndLock(3, "testWorker");
|
||||
acquiredJobs.forEach(i -> {
|
||||
managementService.createExternalWorkerCompletionBuilder(i.getId(), "testWorker").complete();
|
||||
});
|
||||
}*/
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* 适用于通用的操作 mapper
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/4/28 14:44
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package cn.axzo.workflow.server.common.config;
|
||||
|
||||
import cn.azxo.framework.common.annotation.OnlyPodsEnvironment;
|
||||
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -13,6 +14,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author wangli
|
||||
* @since 2024/4/28 14:02
|
||||
*/
|
||||
@OnlyPodsEnvironment
|
||||
@Configuration
|
||||
public class XxlJobConfiguration {
|
||||
Logger logger = LoggerFactory.getLogger(XxlJobConfiguration.class);
|
||||
|
||||
@ -8,6 +8,7 @@ import cn.axzo.workflow.core.common.context.TaskOperationContext;
|
||||
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
|
||||
import cn.axzo.workflow.core.engine.cmd.CustomApproveTaskCmd;
|
||||
import cn.axzo.workflow.core.engine.job.AsyncApproveTaskJobHandler;
|
||||
import cn.axzo.workflow.core.engine.operation.DeleteProcessInstanceOperation;
|
||||
import cn.axzo.workflow.core.listener.AbstractBpmnEventListener;
|
||||
import cn.axzo.workflow.core.listener.BpmnTaskEventListener;
|
||||
import cn.axzo.workflow.core.repository.entity.ExtAxHiTaskInst;
|
||||
@ -18,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.bpmn.model.FlowElement;
|
||||
import org.flowable.bpmn.model.Process;
|
||||
import org.flowable.bpmn.model.UserTask;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandContext;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
@ -28,17 +30,14 @@ import org.flowable.engine.impl.persistence.entity.ActivityInstanceEntity;
|
||||
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.history.HistoricTaskInstance;
|
||||
import org.flowable.task.service.delegate.DelegateTask;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -86,37 +85,7 @@ public class AutoOperatorEvent_101_Listener extends AbstractBpmnEventListener<Ta
|
||||
log.info("AutoOperatorEventListener#onCreated...{}", delegateTask.getTaskDefinitionKey());
|
||||
|
||||
if (Objects.equals(NODE_STARTER.getType(), delegateTask.getTaskDefinitionKey())) {
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
|
||||
JobService jobService = processEngineConfiguration.getJobServiceConfiguration().getJobService();
|
||||
|
||||
JobEntity job = jobService.createJob();
|
||||
// 这里的 executionId 可为 null
|
||||
job.setExecutionId(delegateTask.getExecutionId());
|
||||
job.setProcessInstanceId(delegateTask.getProcessInstanceId());
|
||||
job.setProcessDefinitionId(delegateTask.getProcessDefinitionId());
|
||||
job.setElementId(delegateTask.getTaskDefinitionKey());
|
||||
job.setElementName(delegateTask.getName());
|
||||
job.setJobHandlerType(AsyncApproveTaskJobHandler.TYPE);
|
||||
job.setTenantId(delegateTask.getTenantId());
|
||||
|
||||
BpmnTaskAuditDTO dto = new BpmnTaskAuditDTO();
|
||||
dto.setTaskId(delegateTask.getId());
|
||||
|
||||
BpmnTaskDelegateAssigner initiator = getContext().getInitiator(() -> BpmnTaskDelegateAssigner.toObjectCompatible(delegateTask.getVariable(INTERNAL_INITIATOR)));
|
||||
if (Objects.nonNull(initiator)) {
|
||||
delegateTask.setVariable(INTERNAL_TASK_RELATION_ASSIGNEE_INFO + delegateTask.getId(),
|
||||
initiator.toJson());
|
||||
}
|
||||
dto.setApprover(initiator);
|
||||
// 携带自定义的数据
|
||||
job.setCustomValues(JSONUtil.toJsonStr(dto));
|
||||
|
||||
// 创建异步任务并调度
|
||||
jobService.createAsyncJob(job, false);
|
||||
jobService.scheduleAsyncJob(job);
|
||||
|
||||
|
||||
|
||||
createAsyncApproveJob(delegateTask);
|
||||
/*BpmnTaskDelegateAssigner initiator = getContext().getInitiator(() -> BpmnTaskDelegateAssigner.toObjectCompatible(delegateTask.getVariable(INTERNAL_INITIATOR)));
|
||||
if (Objects.nonNull(initiator)) {
|
||||
delegateTask.setVariable(INTERNAL_TASK_RELATION_ASSIGNEE_INFO + delegateTask.getId(),
|
||||
@ -147,6 +116,37 @@ public class AutoOperatorEvent_101_Listener extends AbstractBpmnEventListener<Ta
|
||||
log.info("AutoOperatorEventListener#onCreated...end: {}", delegateTask.getTaskDefinitionKey());
|
||||
}
|
||||
|
||||
private void createAsyncApproveJob(DelegateTask delegateTask) {
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
|
||||
JobService jobService = processEngineConfiguration.getJobServiceConfiguration().getJobService();
|
||||
|
||||
JobEntity job = jobService.createJob();
|
||||
// 这里的 executionId 可为 null
|
||||
job.setExecutionId(delegateTask.getExecutionId());
|
||||
job.setProcessInstanceId(delegateTask.getProcessInstanceId());
|
||||
job.setProcessDefinitionId(delegateTask.getProcessDefinitionId());
|
||||
job.setElementId(delegateTask.getTaskDefinitionKey());
|
||||
job.setElementName(delegateTask.getName());
|
||||
job.setJobHandlerType(AsyncApproveTaskJobHandler.TYPE);
|
||||
job.setTenantId(delegateTask.getTenantId());
|
||||
|
||||
BpmnTaskAuditDTO dto = new BpmnTaskAuditDTO();
|
||||
dto.setTaskId(delegateTask.getId());
|
||||
|
||||
BpmnTaskDelegateAssigner initiator = getContext().getInitiator(() -> BpmnTaskDelegateAssigner.toObjectCompatible(delegateTask.getVariable(INTERNAL_INITIATOR)));
|
||||
if (Objects.nonNull(initiator)) {
|
||||
delegateTask.setVariable(INTERNAL_TASK_RELATION_ASSIGNEE_INFO + delegateTask.getId(),
|
||||
initiator.toJson());
|
||||
}
|
||||
dto.setApprover(initiator);
|
||||
// 携带自定义的数据
|
||||
job.setCustomValues(JSONUtil.toJsonStr(dto));
|
||||
|
||||
// 创建异步任务并调度
|
||||
jobService.createAsyncJob(job, false);
|
||||
jobService.scheduleAsyncJob(job);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验当前的审批人是否存在过前一个节点
|
||||
*
|
||||
@ -279,15 +279,20 @@ public class AutoOperatorEvent_101_Listener extends AbstractBpmnEventListener<Ta
|
||||
runtimeService.setVariables(delegateTask.getProcessInstanceId(), variables);
|
||||
|
||||
// FIXME 这里的删除流程实例, 应该利用 DeleteProcessInstanceOperation 实现
|
||||
List<HistoricTaskInstance> historyTaskList =
|
||||
historyService.createHistoricTaskInstanceQuery().unfinished().list();
|
||||
if (!CollectionUtils.isEmpty(historyTaskList)) {
|
||||
historyTaskList.stream().filter(i -> Objects.isNull(i.getExecutionId()))
|
||||
.forEach(i -> taskService.complete(i.getId()));
|
||||
}
|
||||
// 删除流程实例,以实现驳回任务时,中止整个审批流程
|
||||
runtimeService.deleteProcessInstance(delegateTask.getProcessInstanceId(), REJECTION_AUTO_COMPLETED.getDesc());
|
||||
|
||||
// List<HistoricTaskInstance> historyTaskList =
|
||||
// historyService.createHistoricTaskInstanceQuery()
|
||||
// .processInstanceId(delegateTask.getProcessInstanceId())
|
||||
// .unfinished()
|
||||
// .list();
|
||||
// if (!CollectionUtils.isEmpty(historyTaskList)) {
|
||||
// historyTaskList.stream().filter(i -> Objects.isNull(i.getExecutionId()))
|
||||
// .forEach(i -> taskService.complete(i.getId()));
|
||||
// }
|
||||
// // 删除流程实例,以实现驳回任务时,中止整个审批流程
|
||||
// runtimeService.deleteProcessInstance(delegateTask.getProcessInstanceId(), REJECTION_AUTO_COMPLETED.getDesc());
|
||||
CommandContext commandContext = CommandContextUtil.getCommandContext();
|
||||
CommandContextUtil.getAgenda(commandContext).planOperation(new DeleteProcessInstanceOperation(commandContext,
|
||||
delegateTask.getProcessInstanceId(), extAxHiTaskInstService, REJECTION_AUTO_COMPLETED.getDesc()));
|
||||
log.info("AutoOperatorEventListener#autoReject...end: {}", delegateTask.getTaskDefinitionKey());
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user