hotfix - 修复审批记录中任务节点的状态不准确的问题

This commit is contained in:
wangli 2023-11-03 18:40:47 +08:00
parent 613b5f6623
commit bb1e41aaa1
2 changed files with 52 additions and 8 deletions

View File

@ -43,4 +43,6 @@ public interface BpmConstants {
String NUMBER_OF_INSTANCES = "nrOfInstances";
String MULTI_INSTANCE_LOOP_COUNTER = "loopCounter";
String TASK_COMPLETE_OPERATION_TYPE = "_TASK_COMPLETE_TYPE";
}

View File

@ -3,13 +3,21 @@ package cn.axzo.workflow.core.service.impl;
import cn.axzo.workflow.core.common.enums.BpmProcessInstanceResultEnum;
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import cn.axzo.workflow.core.service.BpmnTaskService;
import cn.axzo.workflow.core.service.converter.*;
import cn.axzo.workflow.core.service.converter.BpmnHistoricCommentConverter;
import cn.axzo.workflow.core.service.converter.BpmnHistoricTaskInstanceConverter;
import cn.axzo.workflow.core.service.converter.BpmnTaskConverter;
import cn.axzo.workflow.core.service.converter.BpmnTaskDonePageItemConverter;
import cn.axzo.workflow.core.service.converter.BpmnTaskTodoPageItemConverter;
import cn.axzo.workflow.core.service.dto.request.bpmn.task.BpmnTaskAssigneeDTO;
import cn.axzo.workflow.core.service.dto.request.bpmn.task.BpmnTaskAuditDTO;
import cn.axzo.workflow.core.service.dto.request.bpmn.task.BpmnTaskCommentDTO;
import cn.axzo.workflow.core.service.dto.request.bpmn.task.BpmnTaskPageSearchDTO;
import cn.axzo.workflow.core.service.dto.response.BpmPageResult;
import cn.axzo.workflow.core.service.dto.response.bpmn.task.*;
import cn.axzo.workflow.core.service.dto.response.bpmn.task.BpmnHistoricTaskInstanceGroupVO;
import cn.axzo.workflow.core.service.dto.response.bpmn.task.BpmnHistoricTaskInstanceVO;
import cn.axzo.workflow.core.service.dto.response.bpmn.task.BpmnTaskDonePageItemVO;
import cn.axzo.workflow.core.service.dto.response.bpmn.task.BpmnTaskInstanceVO;
import cn.axzo.workflow.core.service.dto.response.bpmn.task.BpmnTaskTodoPageItemVO;
import cn.hutool.core.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.Activity;
@ -17,7 +25,11 @@ import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.UserTask;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.engine.*;
import org.flowable.engine.HistoryService;
import org.flowable.engine.ManagementService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.history.HistoricProcessInstanceQuery;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
@ -36,12 +48,36 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import static cn.axzo.workflow.core.common.BpmConstants.*;
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.*;
import static cn.axzo.workflow.core.common.enums.BpmProcessInstanceResultEnum.*;
import static cn.axzo.workflow.core.common.BpmConstants.APPROVAL_ENDS_AUTOMATICALLY;
import static cn.axzo.workflow.core.common.BpmConstants.COMMENT_TYPE_ADVICE;
import static cn.axzo.workflow.core.common.BpmConstants.INTERNAL_DELETE_PROCESS_FLAG;
import static cn.axzo.workflow.core.common.BpmConstants.INTERNAL_END_TENANT_ID;
import static cn.axzo.workflow.core.common.BpmConstants.INTERNAL_END_USER_ID;
import static cn.axzo.workflow.core.common.BpmConstants.INTERNAL_END_USER_NAME;
import static cn.axzo.workflow.core.common.BpmConstants.INTERNAL_PROCESS_TYPE_REJECT;
import static cn.axzo.workflow.core.common.BpmConstants.MULTI_INSTANCE_LOOP_COUNTER;
import static cn.axzo.workflow.core.common.BpmConstants.NUMBER_OF_INSTANCES;
import static cn.axzo.workflow.core.common.BpmConstants.TASK_COMPLETE_OPERATION_TYPE;
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.PROCESS_INSTANCE_ID_NOT_EXISTS;
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.PROCESS_INSTANCE_NOT_EXISTS;
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.TASK_COMPLETE_FAIL_ASSIGN_NOT_SELF;
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.TASK_COMPLETE_FAIL_NOT_EXISTS;
import static cn.axzo.workflow.core.common.enums.BpmProcessInstanceResultEnum.APPROVED;
import static cn.axzo.workflow.core.common.enums.BpmProcessInstanceResultEnum.CANCELLED;
import static cn.axzo.workflow.core.common.enums.BpmProcessInstanceResultEnum.REJECTED;
import static cn.axzo.workflow.core.common.enums.BpmProcessInstanceResultEnum.valueOfStatus;
import static cn.axzo.workflow.core.common.utils.BpmCollectionUtils.convertSet;
import static cn.axzo.workflow.core.service.impl.BpmnProcessInstanceServiceImpl.countSql;
import static cn.axzo.workflow.core.service.impl.BpmnProcessInstanceServiceImpl.sqlConnectors;
@ -278,6 +314,7 @@ public class BpmnTaskServiceImpl implements BpmnTaskService {
Authentication.setAuthenticatedUserId(dto.getUserId());
taskService.addComment(dto.getTaskId(), instance.getId(), COMMENT_TYPE_ADVICE, dto.getAdvice());
}
runtimeService.setVariable(task.getExecutionId(), TASK_COMPLETE_OPERATION_TYPE + task.getId(), REJECTED);
// 多实例
Activity activity;
if (isMultiInstance(activity = getActivity((TaskEntity) task))) {
@ -331,7 +368,9 @@ public class BpmnTaskServiceImpl implements BpmnTaskService {
query.taskTenantId(tenantId);
}
HistoricProcessInstanceQuery instanceQuery =
historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId);
historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstanceId)
.includeProcessVariables();
if (StringUtils.hasLength(tenantId)) {
instanceQuery.processInstanceTenantId(tenantId);
}
@ -354,6 +393,9 @@ public class BpmnTaskServiceImpl implements BpmnTaskService {
for (BpmnHistoricTaskInstanceVO vo : vos) {
if (count == 0 || taskDefinitionKeys.contains(vo.getTaskDefinitionKey())) {
vo.setResult(finalBusinessStatus);
if (Objects.nonNull(vo.getEndTime())) {
vo.setResult((BpmProcessInstanceResultEnum) instance.getProcessVariables().getOrDefault(TASK_COMPLETE_OPERATION_TYPE + vo.getTaskId(), APPROVED));
}
if (Objects.nonNull(vo.getEndTime()) && !Objects.equals(finalBusinessStatus, REJECTED)
&& !Objects.equals(finalBusinessStatus, CANCELLED)) {
vo.setResult(APPROVED);