REQ-3290-调整加签逻辑,被加签人已存在,产生多余任务后,结束待办

This commit is contained in:
yangqicheng 2024-11-20 16:16:12 +08:00
parent c2bfb0bbfa
commit 22862fe24f
3 changed files with 39 additions and 21 deletions

View File

@ -19,7 +19,6 @@ import java.io.Serializable;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTaskAssignerCount;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTaskAssignerDuplicated;
public class CustomCountersignUserTaskAsyncCmd extends AbstractCommand<Void> implements Serializable {
private final BpmnTaskCountersignDTO dto;
@ -46,7 +45,7 @@ public class CustomCountersignUserTaskAsyncCmd extends AbstractCommand<Void> imp
validTask(historicTaskInstance, (TaskEntity) task, dto.getOriginAssigner(), null);
validTaskAssignerDuplicated(commandContext, (TaskEntity) task, dto.getTargetAssignerList());
// validTaskAssignerDuplicated(commandContext, (TaskEntity) task, dto.getTargetAssignerList());
validTaskAssignerCount(processEngineConfiguration.getRuntimeService(), (TaskEntity) task, dto.getTargetAssignerList());

View File

@ -20,9 +20,12 @@ import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static cn.axzo.workflow.common.constant.BpmnConstants.COUNTERSIGN_ASSIGNER_SHOW_NUMBER;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT;
@ -30,9 +33,10 @@ import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.COUNTE
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.batchAddAttachment;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.completeVirtualTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.createVirtualTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.deleteMultiTasks;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.getDuplicatePendingTasks;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTaskAssignerCount;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTaskAssignerDuplicated;
/**
* 自定义的加签用户任务命令实现
@ -45,6 +49,7 @@ import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTask
@Slf4j
public class CustomCountersignUserTaskCmd extends AbstractCommand<Void> implements Serializable {
private static final long serialVersionUID = -2354973133616698898L;
private final BpmnCountersignTypeEnum countersignType;
private final String originTaskId;
private final BpmnTaskDelegateAssigner originTaskAssignee;
@ -81,9 +86,9 @@ public class CustomCountersignUserTaskCmd extends AbstractCommand<Void> implemen
@Override
public Void execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
CommandContextUtil.getProcessEngineConfiguration(commandContext);
HistoricTaskInstanceQuery taskQuery =
processEngineConfiguration.getHistoryService().createHistoricTaskInstanceQuery();
processEngineConfiguration.getHistoryService().createHistoricTaskInstanceQuery();
HistoricTaskInstance historicTaskInstance = taskQuery.taskId(originTaskId).singleResult();
TaskService taskService = processEngineConfiguration.getTaskService();
@ -93,14 +98,14 @@ public class CustomCountersignUserTaskCmd extends AbstractCommand<Void> implemen
validTaskAssignerCount(processEngineConfiguration.getRuntimeService(), task, targetTaskAssigneeList);
List<BpmnTaskDelegateAssigner> taskDelegateAssigners =
validTaskAssignerDuplicated(commandContext, task, targetTaskAssigneeList);
resolveOriginTask(commandContext, extAxHiTaskInstService, taskService, task);
batchAddAttachment(commandContext, task.getProcessInstanceId(), task, attachmentList,
originTaskAssignee);
//查询重复任务
List<Task> duplicatePendingTasks = getDuplicatePendingTasks(commandContext, task, targetTaskAssigneeList);
switch (countersignType) {
case FORWARD_COUNTERSIGN:
// TODO
@ -110,10 +115,16 @@ public class CustomCountersignUserTaskCmd extends AbstractCommand<Void> implemen
break;
default:
// share_counterSign
shareCountSign(commandContext, task, taskDelegateAssigners);
shareCountSign(commandContext, task);
break;
}
if (duplicatePendingTasks == null) {
duplicatePendingTasks = new ArrayList<>();
}
duplicatePendingTasks.add(task);
// 结束被多余任务
deleteMultiTasks(commandContext, duplicatePendingTasks);
return null;
}
@ -122,23 +133,31 @@ public class CustomCountersignUserTaskCmd extends AbstractCommand<Void> implemen
*
* @param commandContext
* @param taskEntity
* @param taskDelegateAssigners 当前任务的原审批人列表
*/
private void shareCountSign(CommandContext commandContext, TaskEntity taskEntity,
List<BpmnTaskDelegateAssigner> taskDelegateAssigners) {
private void shareCountSign(CommandContext commandContext, TaskEntity taskEntity) {
ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
CommandContextUtil.getProcessEngineConfiguration(commandContext);
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
// 这个节点下所有审批人快照
String activityListSnapshot =
INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT + taskEntity.getTaskDefinitionKey();
INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT + taskEntity.getTaskDefinitionKey();
List<BpmnTaskDelegateAssigner> taskDelegateAssigners =
processEngineConfiguration.getRuntimeService().getVariable(taskEntity.getProcessInstanceId(), activityListSnapshot, List.class);
taskDelegateAssigners.addAll(targetTaskAssigneeList);
runtimeService.setVariable(taskEntity.getProcessInstanceId(), activityListSnapshot, taskDelegateAssigners);
log.info("正在进行加签任务:{},待加签人合并列表:{}", taskEntity.getId(), JSONUtil.toJsonStr(taskDelegateAssigners));
List<BpmnTaskDelegateAssigner> resultAssignerList = new ArrayList<>();
Set<String> existAssignerIds = new HashSet<>();
//去除重复assigner
for (BpmnTaskDelegateAssigner assigner : taskDelegateAssigners) {
if (existAssignerIds.contains(assigner.buildAssigneeId())) {
continue;
}
resultAssignerList.add(assigner);
existAssignerIds.add(assigner.buildAssigneeId());
}
runtimeService.setVariable(taskEntity.getProcessInstanceId(), activityListSnapshot, resultAssignerList);
log.info("正在进行加签任务:{},待加签人合并列表:{}", taskEntity.getId(), JSONUtil.toJsonStr(resultAssignerList));
targetTaskAssigneeList.forEach(assigner -> {
CustomTaskHelper.addMultiTask(commandContext, taskEntity, assigner);
});
targetTaskAssigneeList.forEach(assigner -> CustomTaskHelper.addMultiTask(commandContext, taskEntity, assigner));
}
private void resolveOriginTask(CommandContext commandContext, ExtAxHiTaskInstService extAxHiTaskInstService,
@ -155,7 +174,7 @@ public class CustomCountersignUserTaskCmd extends AbstractCommand<Void> implemen
}
message.append("").append(targetTaskAssigneeList.size()).append("人进行审批");
Task virtualTask = createVirtualTask(commandContext, extAxHiTaskInstService, task.getProcessInstanceId(), task.getName(),
task.getTaskDefinitionKey(), advice, originTaskAssignee, COUNTERSIGN.getStatus(), new AddComment(message.toString()));
task.getTaskDefinitionKey(), advice, originTaskAssignee, COUNTERSIGN.getStatus(), new AddComment(message.toString()));
batchAddAttachment(commandContext, task.getProcessInstanceId(), task, attachmentList, originTaskAssignee);
completeVirtualTask(commandContext, virtualTask);
}

View File

@ -100,11 +100,11 @@ public class CustomTransferUserTaskCmd extends AbstractCommand<Void> implements
batchAddAttachment(commandContext, task.getProcessInstanceId(), task, attachmentList,
originTaskAssignee);
List<Task> duplicatePendingTasks = getDuplicatePendingTasks(commandContext, task, Lists.newArrayList(targetTaskAssignee));
// 生成转交任务
addMultiTask(commandContext, task, targetTaskAssignee);
task.setTransientVariable(TASK_COMPLETE_OPERATION_TYPE + task.getId(), TRANSFER.getStatus());
List<Task> duplicatePendingTasks = getDuplicatePendingTasks(commandContext, task, Lists.newArrayList(targetTaskAssignee));
if (duplicatePendingTasks == null) {
duplicatePendingTasks = new ArrayList<>();
}