update - 优化加签功能, 通过评论节点类型来生成日志, 且当前任务的待办不再完成, 从而优化移动端在加签后,必须返回到待办列表才能正常显示按钮的问题

This commit is contained in:
wangli 2024-01-12 23:48:31 +08:00
parent 614d8e15f2
commit cd14bdbe0a
3 changed files with 39 additions and 15 deletions

View File

@ -4,6 +4,7 @@ import cn.axzo.workflow.common.enums.BpmnCountersignTypeEnum;
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.cmd.helper.CustomTaskHelper;
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.impl.identity.Authentication;
@ -21,13 +22,11 @@ import java.io.Serializable;
import java.util.List;
import static cn.axzo.workflow.common.constant.BpmnConstants.COMMENT_TYPE_ADVICE;
import static cn.axzo.workflow.common.constant.BpmnConstants.COMMENT_TYPE_OPERATION_DESC;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT;
import static cn.axzo.workflow.common.constant.BpmnConstants.TASK_ASSIGNEE_SKIP_FLAT;
import static cn.axzo.workflow.common.constant.BpmnConstants.TASK_COMPLETE_OPERATION_TYPE;
import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.COUNTERSIGN;
import static cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner.buildDummyAssigner;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.batchAddAttachment;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.createVirtualTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.deleteMultiTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTaskAssignerDuplicated;
@ -49,17 +48,19 @@ public class CustomCountersignUserTaskCmd implements Command<Void>, Serializable
private final String advice;
private final List<AttachmentDTO> attachmentList;
private final List<BpmnTaskDelegateAssigner> targetTaskAssigneeList;
private final ExtAxHiTaskInstService extAxHiTaskInstService;
public CustomCountersignUserTaskCmd(BpmnCountersignTypeEnum countersignType, String originTaskId,
BpmnTaskDelegateAssigner originTaskAssignee, String advice,
List<AttachmentDTO> attachmentList,
List<BpmnTaskDelegateAssigner> targetTaskAssigneeList) {
List<BpmnTaskDelegateAssigner> targetTaskAssigneeList, ExtAxHiTaskInstService extAxHiTaskInstService) {
this.countersignType = countersignType;
this.originTaskId = originTaskId;
this.originTaskAssignee = originTaskAssignee;
this.advice = advice;
this.attachmentList = attachmentList;
this.targetTaskAssigneeList = targetTaskAssigneeList;
this.extAxHiTaskInstService = extAxHiTaskInstService;
}
@Override
@ -74,7 +75,7 @@ public class CustomCountersignUserTaskCmd implements Command<Void>, Serializable
List<BpmnTaskDelegateAssigner> taskDelegateAssigners =
validTaskAssignerDuplicated(commandContext, (TaskEntity) task, targetTaskAssigneeList);
resolveOriginTask(taskService, task);
resolveOriginTaskV2(commandContext, extAxHiTaskInstService, taskService, task);
batchAddAttachment(commandContext, task.getProcessInstanceId(), task.getId(), attachmentList,
originTaskAssignee);
@ -117,18 +118,40 @@ public class CustomCountersignUserTaskCmd implements Command<Void>, Serializable
log.info("正在进行加签任务:{},待加签人合并列表:{}", taskEntity.getId(), JSONUtil.toJsonStr(taskDelegateAssigners));
// 因为当前的审批人会帮他结束任务,以便生成加签日志, 所以在这里重新加入审批人
targetTaskAssigneeList.add(originTaskAssignee);
// targetTaskAssigneeList.add(originTaskAssignee);
targetTaskAssigneeList.forEach(assigner -> {
CustomTaskHelper.addMultiTask(commandContext, taskEntity, assigner);
});
}
private void resolveOriginTask(TaskService taskService, Task task) {
BpmnTaskDelegateAssigner assigner = buildDummyAssigner("countersign", TASK_ASSIGNEE_SKIP_FLAT, "dummyApprover");
task.setAssignee(assigner.buildAssigneeId());
((TaskEntity) task).setScopeType(countersignType.getType());
taskService.saveTask(task);
// BpmnTaskDelegateAssigner assigner = buildDummyAssigner("countersign", TASK_ASSIGNEE_SKIP_FLAT, "dummyApprover");
// task.setAssignee(assigner.buildAssigneeId());
// ((TaskEntity) task).setScopeType(countersignType.getType());
// taskService.saveTask(task);
//
// // 构建评论内容
// StringBuilder message = new StringBuilder("添加");
// for (int i = 0; i < targetTaskAssigneeList.size(); i++) {
// message.append(targetTaskAssigneeList.get(i).getAssignerName());
// if (i < targetTaskAssigneeList.size() - 1) {
// message.append("");
// }
// }
// message.append("").append(targetTaskAssigneeList.size()).append("人进行审批");
//
// // 新增评论
// Authentication.setAuthenticatedUserId(originTaskAssignee.buildAssigneeId());
// taskService.addComment(task.getId(), task.getProcessInstanceId(), COMMENT_TYPE_OPERATION_DESC,
// message.toString());
// if (StringUtils.hasLength(advice)) {
// taskService.addComment(originTaskId, task.getProcessInstanceId(), COMMENT_TYPE_ADVICE, advice);
// }
// Authentication.setAuthenticatedUserId(null);
}
private void resolveOriginTaskV2(CommandContext commandContext, ExtAxHiTaskInstService extAxHiTaskInstService,
TaskService taskService, Task task) {
// 构建评论内容
StringBuilder message = new StringBuilder("添加");
for (int i = 0; i < targetTaskAssigneeList.size(); i++) {
@ -138,14 +161,15 @@ public class CustomCountersignUserTaskCmd implements Command<Void>, Serializable
}
}
message.append("").append(targetTaskAssigneeList.size()).append("人进行审批");
createVirtualTask(commandContext, extAxHiTaskInstService, task.getProcessInstanceId(), task.getName(),
task.getTaskDefinitionKey(), message.toString(),
originTaskAssignee, COUNTERSIGN.getStatus());
// 新增评论
Authentication.setAuthenticatedUserId(originTaskAssignee.buildAssigneeId());
taskService.addComment(task.getId(), task.getProcessInstanceId(), COMMENT_TYPE_OPERATION_DESC,
message.toString());
if (StringUtils.hasLength(advice)) {
taskService.addComment(originTaskId, task.getProcessInstanceId(), COMMENT_TYPE_ADVICE, advice);
}
batchAddAttachment(commandContext, task.getProcessInstanceId(), task.getId(), attachmentList, originTaskAssignee);
Authentication.setAuthenticatedUserId(null);
}
}

View File

@ -187,7 +187,7 @@ public class CustomTaskHelper {
return comment;
}
public static Attachment batchAddAttachment(CommandContext commandContext, Task task, AttachmentDTO attachmentDto) {
public static Attachment addAttachment(CommandContext commandContext, Task task, AttachmentDTO attachmentDto) {
ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
AttachmentEntity attachment = processEngineConfiguration.getAttachmentEntityManager().create();

View File

@ -483,7 +483,7 @@ public class BpmnProcessTaskServiceImpl implements BpmnProcessTaskService {
public void countersignTask(BpmnTaskCountersignDTO dto) {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
commandExecutor.execute(new CustomCountersignUserTaskCmd(SHARE_COUNTERSIGN, dto.getTaskId(),
dto.getOriginAssigner(), dto.getAdvice(), dto.getAttachmentList(), dto.getTargetAssignerList()));
dto.getOriginAssigner(), dto.getAdvice(), dto.getAttachmentList(), dto.getTargetAssignerList(), extAxHiTaskInstService));
}
@Override