update - 调整自动操作事件中,自动拒绝时,使用完整功能的 DeleteProcessInstanceOperation 操作类
This commit is contained in:
parent
27fcc9e52b
commit
f0c1b53acc
@ -10,6 +10,7 @@ import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
|||||||
import org.flowable.engine.impl.util.CommandContextUtil;
|
import org.flowable.engine.impl.util.CommandContextUtil;
|
||||||
import org.flowable.task.api.history.HistoricTaskInstance;
|
import org.flowable.task.api.history.HistoricTaskInstance;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -25,6 +26,7 @@ import static cn.axzo.workflow.common.constant.BpmnConstants.HIDDEN_ASSIGNEE_ID;
|
|||||||
public class DeleteProcessInstanceOperation extends AbstractOperation {
|
public class DeleteProcessInstanceOperation extends AbstractOperation {
|
||||||
private final String processInstanceId;
|
private final String processInstanceId;
|
||||||
private final ExtAxHiTaskInstService extAxHiTaskInstService;
|
private final ExtAxHiTaskInstService extAxHiTaskInstService;
|
||||||
|
private String customDeleteReason;
|
||||||
|
|
||||||
public DeleteProcessInstanceOperation(CommandContext commandContext, String processInstanceId,
|
public DeleteProcessInstanceOperation(CommandContext commandContext, String processInstanceId,
|
||||||
ExtAxHiTaskInstService extAxHiTaskInstService) {
|
ExtAxHiTaskInstService extAxHiTaskInstService) {
|
||||||
@ -33,6 +35,15 @@ public class DeleteProcessInstanceOperation extends AbstractOperation {
|
|||||||
this.extAxHiTaskInstService = extAxHiTaskInstService;
|
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
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ProcessEngineConfigurationImpl processEngineConfiguration =
|
ProcessEngineConfigurationImpl processEngineConfiguration =
|
||||||
@ -54,7 +65,7 @@ public class DeleteProcessInstanceOperation extends AbstractOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
|
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
|
||||||
runtimeService.deleteProcessInstance(processInstanceId, HIDDEN_ASSIGNEE_ID);
|
runtimeService.deleteProcessInstance(processInstanceId, StringUtils.hasText(customDeleteReason) ? customDeleteReason : HIDDEN_ASSIGNEE_ID);
|
||||||
// 将结束流程实例的原因记录下来
|
// 将结束流程实例的原因记录下来
|
||||||
// runtimeService.deleteProcessInstance(processInstanceId, reason);
|
// runtimeService.deleteProcessInstance(processInstanceId, reason);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.common.utils.BpmnMetaParserHelper;
|
||||||
import cn.axzo.workflow.core.engine.cmd.CustomApproveTaskCmd;
|
import cn.axzo.workflow.core.engine.cmd.CustomApproveTaskCmd;
|
||||||
import cn.axzo.workflow.core.engine.job.AsyncApproveTaskJobHandler;
|
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.AbstractBpmnEventListener;
|
||||||
import cn.axzo.workflow.core.listener.BpmnTaskEventListener;
|
import cn.axzo.workflow.core.listener.BpmnTaskEventListener;
|
||||||
import cn.axzo.workflow.core.repository.entity.ExtAxHiTaskInst;
|
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.FlowElement;
|
||||||
import org.flowable.bpmn.model.Process;
|
import org.flowable.bpmn.model.Process;
|
||||||
import org.flowable.bpmn.model.UserTask;
|
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.common.engine.impl.interceptor.CommandExecutor;
|
||||||
import org.flowable.engine.HistoryService;
|
import org.flowable.engine.HistoryService;
|
||||||
import org.flowable.engine.RepositoryService;
|
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.engine.impl.util.CommandContextUtil;
|
||||||
import org.flowable.job.service.JobService;
|
import org.flowable.job.service.JobService;
|
||||||
import org.flowable.job.service.impl.persistence.entity.JobEntity;
|
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.flowable.task.service.delegate.DelegateTask;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@ -268,7 +267,6 @@ public class AutoOperatorEvent_101_Listener extends AbstractBpmnEventListener<Ta
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void autoReject(DelegateTask delegateTask) {
|
private void autoReject(DelegateTask delegateTask) {
|
||||||
// TODO 应该用异步任务实现
|
|
||||||
log.info("AutoOperatorEventListener#autoReject...{}", delegateTask.getTaskDefinitionKey());
|
log.info("AutoOperatorEventListener#autoReject...{}", delegateTask.getTaskDefinitionKey());
|
||||||
taskService.addComment(delegateTask.getId(), delegateTask.getProcessInstanceId(), COMMENT_TYPE_OPERATION_DESC
|
taskService.addComment(delegateTask.getId(), delegateTask.getProcessInstanceId(), COMMENT_TYPE_OPERATION_DESC
|
||||||
, "自动驳回");
|
, "自动驳回");
|
||||||
@ -281,21 +279,25 @@ public class AutoOperatorEvent_101_Listener extends AbstractBpmnEventListener<Ta
|
|||||||
runtimeService.setVariables(delegateTask.getProcessInstanceId(), variables);
|
runtimeService.setVariables(delegateTask.getProcessInstanceId(), variables);
|
||||||
|
|
||||||
// FIXME 这里的删除流程实例, 应该利用 DeleteProcessInstanceOperation 实现
|
// FIXME 这里的删除流程实例, 应该利用 DeleteProcessInstanceOperation 实现
|
||||||
List<HistoricTaskInstance> historyTaskList =
|
// List<HistoricTaskInstance> historyTaskList =
|
||||||
historyService.createHistoricTaskInstanceQuery().unfinished().list();
|
// historyService.createHistoricTaskInstanceQuery()
|
||||||
if (!CollectionUtils.isEmpty(historyTaskList)) {
|
// .processInstanceId(delegateTask.getProcessInstanceId())
|
||||||
historyTaskList.stream().filter(i -> Objects.isNull(i.getExecutionId()))
|
// .unfinished()
|
||||||
.forEach(i -> taskService.complete(i.getId()));
|
// .list();
|
||||||
}
|
// if (!CollectionUtils.isEmpty(historyTaskList)) {
|
||||||
// 删除流程实例,以实现驳回任务时,中止整个审批流程
|
// historyTaskList.stream().filter(i -> Objects.isNull(i.getExecutionId()))
|
||||||
runtimeService.deleteProcessInstance(delegateTask.getProcessInstanceId(), REJECTION_AUTO_COMPLETED.getDesc());
|
// .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());
|
log.info("AutoOperatorEventListener#autoReject...end: {}", delegateTask.getTaskDefinitionKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void autoPass(DelegateTask delegateTask) {
|
private void autoPass(DelegateTask delegateTask) {
|
||||||
// TODO 用异步任务实现
|
|
||||||
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
|
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
|
||||||
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
|
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
|
||||||
BpmnTaskDelegateAssigner assigner = BpmnTaskDelegateAssigner.toObjectCompatible(
|
BpmnTaskDelegateAssigner assigner = BpmnTaskDelegateAssigner.toObjectCompatible(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user