update - 优化操作任务时, 对任务的校验逻辑, 细化提示文案

This commit is contained in:
wangli 2024-03-25 13:47:53 +08:00
parent baa02ad371
commit 37a334413c
6 changed files with 42 additions and 7 deletions

View File

@ -29,6 +29,7 @@ public enum BpmnTaskRespCode implements IModuleRespCode {
DUMMY_TASK_CANT_REPEAT_CREATE("014", "已存在运行中的机器人节点, 不允许重复创建!"),
ACTIVITY_BIZ_SET_ASSIGNEE_HAS_REPEAT("015", "业务传入的指定审批人存在重复, 请主动根据 personId 去重! "),
DUMMY_TASK_CREATED_ERROR("016", "流程实例 ID【{}】: 不存在, 不允许创建机器人节点"),
TASK_HAS_BEEN_COMPLETE("017", "审批任务已被处理"),
;
private String code;

View File

@ -10,6 +10,8 @@ import org.flowable.engine.TaskService;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.util.StringUtils;
@ -53,10 +55,14 @@ public class CustomApproveTaskCmd implements Command<Void>, Serializable {
public Void execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
HistoricTaskInstanceQuery taskQuery =
processEngineConfiguration.getHistoryService().createHistoricTaskInstanceQuery();
TaskService taskService = processEngineConfiguration.getTaskService();
HistoricTaskInstance historicTaskInstance = taskQuery.taskId(taskId).singleResult();
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
validTask((TaskEntity) task, approver);
validTask(historicTaskInstance, (TaskEntity) task, approver);
if (StringUtils.hasLength(advice)) {
Authentication.setAuthenticatedUserId(approver.buildAssigneeId());

View File

@ -14,6 +14,8 @@ import org.flowable.engine.TaskService;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import java.io.Serializable;
@ -64,10 +66,14 @@ public class CustomCountersignUserTaskCmd implements Command<Void>, Serializable
public Void execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
HistoricTaskInstanceQuery taskQuery =
processEngineConfiguration.getHistoryService().createHistoricTaskInstanceQuery();
HistoricTaskInstance historicTaskInstance = taskQuery.taskId(originTaskId).singleResult();
TaskService taskService = processEngineConfiguration.getTaskService();
Task task = taskService.createTaskQuery().taskId(originTaskId).singleResult();
validTask((TaskEntity) task, originTaskAssignee);
validTask(historicTaskInstance, (TaskEntity) task, originTaskAssignee);
List<BpmnTaskDelegateAssigner> taskDelegateAssigners =
validTaskAssignerDuplicated(commandContext, (TaskEntity) task, targetTaskAssigneeList);

View File

@ -11,6 +11,8 @@ import org.flowable.engine.TaskService;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import java.io.Serializable;
@ -58,10 +60,15 @@ public class CustomRejectionTaskCmd implements Command<Void>, Serializable {
public Void execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
TaskService taskService = processEngineConfiguration.getTaskService();
HistoricTaskInstanceQuery taskQuery =
processEngineConfiguration.getHistoryService().createHistoricTaskInstanceQuery();
HistoricTaskInstance historicTaskInstance = taskQuery.taskId(taskId).singleResult();
TaskService taskService = processEngineConfiguration.getTaskService();
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
validTask((TaskEntity) task, approver);
validTask(historicTaskInstance, (TaskEntity) task, approver);
((TaskEntity) task).setTransientVariable(TASK_COMPLETE_OPERATION_TYPE + task.getId(), REJECTED.getStatus());
Task virtualTask = createVirtualTask(commandContext, extAxHiTaskInstService, task.getProcessInstanceId(), task.getName(),

View File

@ -12,6 +12,8 @@ import org.flowable.engine.TaskService;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.util.StringUtils;
@ -63,9 +65,14 @@ public class CustomTransferUserTaskCmd implements Command<Void>, Serializable {
public Void execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
HistoricTaskInstanceQuery taskQuery =
processEngineConfiguration.getHistoryService().createHistoricTaskInstanceQuery();
HistoricTaskInstance historicTaskInstance = taskQuery.taskId(originTaskId).singleResult();
TaskService taskService = processEngineConfiguration.getTaskService();
Task task = taskService.createTaskQuery().taskId(originTaskId).singleResult();
validTask((TaskEntity) task, originTaskAssignee);
validTask(historicTaskInstance, (TaskEntity) task, originTaskAssignee);
validTaskAssignerDuplicated(commandContext, (TaskEntity) task, Lists.newArrayList(targetTaskAssignee));

View File

@ -22,6 +22,7 @@ import org.flowable.engine.task.Attachment;
import org.flowable.engine.task.Comment;
import org.flowable.engine.task.Event;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.util.CollectionUtils;
@ -45,6 +46,7 @@ import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.PROCES
import static cn.axzo.workflow.core.common.code.BpmnTaskRespCode.ASSIGNEE_HAS_BEEN_EXISTS;
import static cn.axzo.workflow.core.common.code.BpmnTaskRespCode.TASK_COMPLETE_FAIL_ASSIGN_NOT_SELF;
import static cn.axzo.workflow.core.common.code.BpmnTaskRespCode.TASK_COMPLETE_FAIL_NOT_EXISTS;
import static cn.axzo.workflow.core.common.code.BpmnTaskRespCode.TASK_HAS_BEEN_COMPLETE;
import static org.flowable.task.api.Task.DEFAULT_PRIORITY;
/**
@ -91,13 +93,19 @@ public class CustomTaskHelper {
/**
* 校验任务归属信息
*
* @param taskEntity
* @param historicTaskInstance 历史表当前 id 任务
* @param taskEntity 在途表当前 id 任务
* @param originTaskAssigner
*/
public static void validTask(TaskEntity taskEntity, BpmnTaskDelegateAssigner originTaskAssigner) {
public static void validTask(HistoricTaskInstance historicTaskInstance, TaskEntity taskEntity,
BpmnTaskDelegateAssigner originTaskAssigner) {
if (Objects.isNull(taskEntity)) {
throw new WorkflowEngineException(TASK_COMPLETE_FAIL_NOT_EXISTS);
}
if (Objects.nonNull(historicTaskInstance) && Objects.nonNull(historicTaskInstance.getEndTime())) {
throw new WorkflowEngineException(TASK_HAS_BEEN_COMPLETE);
}
// FIXME by wangli: currentAssignee 去掉 OUID 前的代码
// if (Objects.nonNull(originTaskAssigner) &&
// !Objects.equals(taskEntity.getAssignee(), originTaskAssigner.buildAssigneeId())) {