Merge branch 'refs/heads/1.3.2-SNAPSHOT' into REQ-2393

This commit is contained in:
wangli 2024-04-30 15:44:22 +08:00
commit 55685a890b
2 changed files with 28 additions and 15 deletions

View File

@ -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);
}

View File

@ -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;
@ -268,7 +267,6 @@ public class AutoOperatorEvent_101_Listener extends AbstractBpmnEventListener<Ta
}
private void autoReject(DelegateTask delegateTask) {
// TODO 应该用异步任务实现
log.info("AutoOperatorEventListener#autoReject...{}", delegateTask.getTaskDefinitionKey());
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);
// 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());
}
private void autoPass(DelegateTask delegateTask) {
// TODO 用异步任务实现
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
BpmnTaskDelegateAssigner assigner = BpmnTaskDelegateAssigner.toObjectCompatible(