feat(REQ-2924) - 调整 Task 为 TaskEntity

This commit is contained in:
wangli 2024-09-06 10:30:33 +08:00
parent 53a17ed100
commit 9e63eb6a06
6 changed files with 24 additions and 24 deletions

View File

@ -115,8 +115,8 @@ public class CustomApproveTaskCmd extends AbstractCommand<Void> implements Seria
HistoricTaskInstance historicTaskInstance = taskQuery.taskId(taskId).singleResult();
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
validTask(historicTaskInstance, (TaskEntity) task, approver, nodeTypes);
TaskEntity task = (TaskEntity) taskService.createTaskQuery().taskId(taskId).singleResult();
validTask(historicTaskInstance, task, approver, nodeTypes);
// TODO 所有的跟 Task 相关的动作都可以在这里进行扩展用于扩展八大按钮标准动作以外的一些逻辑但这里需要结合 Spring 能力需设计好扩展点否则无法进行扩展
// 其他动态也应该在类似的地方预留扩展点

View File

@ -9,7 +9,6 @@ import org.flowable.engine.RuntimeService;
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;
@ -76,8 +75,8 @@ public class CustomBackTaskCmd extends AbstractCommand<Void> implements Serializ
HistoricTaskInstance historicTaskInstance = taskQuery.taskId(dto.getTaskId()).singleResult();
Task task = taskService.createTaskQuery().taskId(dto.getTaskId()).singleResult();
validTask(historicTaskInstance, (TaskEntity) task, dto.getApprover(), dto.getNodeTypes());
TaskEntity task = (TaskEntity) taskService.createTaskQuery().taskId(dto.getTaskId()).singleResult();
validTask(historicTaskInstance, task, dto.getApprover(), dto.getNodeTypes());
if (StringUtils.hasLength(dto.getAdvice())) {
Authentication.setAuthenticatedUserId(dto.getApprover().buildAssigneeId());
addComment(commandContext, task, COMMENT_TYPE_ADVICE, dto.getAdvice());
@ -91,7 +90,7 @@ public class CustomBackTaskCmd extends AbstractCommand<Void> implements Serializ
Authentication.setAuthenticatedUserId(null);
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
((TaskEntity) task).setTransientVariable(TASK_COMPLETE_OPERATION_TYPE + dto.getTaskId(), BACKED.getStatus());
task.setTransientVariable(TASK_COMPLETE_OPERATION_TYPE + dto.getTaskId(), BACKED.getStatus());
runtimeService.createChangeActivityStateBuilder()
.processInstanceId(task.getProcessInstanceId())

View File

@ -7,12 +7,12 @@ import cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper;
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
import com.alibaba.fastjson.JSON;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
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.service.impl.persistence.entity.TaskEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@ -65,7 +65,7 @@ public class CustomCompleteDummyTaskCmd extends AbstractCommand<Void> implements
CommandContextUtil.getProcessEngineConfiguration(commandContext);
TaskService taskService = processEngineConfiguration.getTaskService();
Task task = taskService.createTaskQuery().processInstanceId(processInstanceId)
TaskEntity task = (TaskEntity) taskService.createTaskQuery().processInstanceId(processInstanceId)
.taskId(taskId).singleResult();
if (Objects.isNull(task)) {
throw new WorkflowEngineException(DUMMY_TASK_NOT_EXISTS, processInstanceId, taskId);

View File

@ -6,7 +6,6 @@ import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
@ -83,11 +82,11 @@ public class CustomTransferUserTaskCmd extends AbstractCommand<Void> implements
HistoricTaskInstance historicTaskInstance = taskQuery.taskId(originTaskId).singleResult();
TaskService taskService = processEngineConfiguration.getTaskService();
Task task = taskService.createTaskQuery().taskId(originTaskId).singleResult();
TaskEntity task = (TaskEntity) taskService.createTaskQuery().taskId(originTaskId).singleResult();
validTask(historicTaskInstance, (TaskEntity) task, originTaskAssignee, null);
validTask(historicTaskInstance, task, originTaskAssignee, null);
validTaskAssignerDuplicated(commandContext, (TaskEntity) task, Lists.newArrayList(targetTaskAssignee));
validTaskAssignerDuplicated(commandContext, task, Lists.newArrayList(targetTaskAssignee));
processAssignee(processEngineConfiguration, task);
@ -103,7 +102,7 @@ public class CustomTransferUserTaskCmd extends AbstractCommand<Void> implements
return null;
}
private void resolveOriginTask(CommandContext commandContext, TaskService taskService, Task task) {
private void resolveOriginTask(CommandContext commandContext, TaskService taskService, TaskEntity task) {
BpmnTaskDelegateAssigner assigner = buildDummyAssigner("transfer", TASK_ASSIGNEE_SKIP_FLAT, "dummyApprover");
task.setAssignee(assigner.buildAssigneeId());
((TaskEntity) task).setScopeType("TRANSFER");

View File

@ -247,10 +247,11 @@ public class CustomTaskHelper {
addComment(commandContext, task, type, message);
}
public static void addComment(CommandContext commandContext, Task task, AddComment addComment) {
public static void addComment(CommandContext commandContext, TaskEntity task, AddComment addComment) {
addComment(commandContext, task, addComment.getCommentType(), addComment.getContent());
}
public static void addComment(CommandContext commandContext, Task task, String type, String message) {
public static void addComment(CommandContext commandContext, TaskEntity task, String type, String message) {
if (!StringUtils.hasText(type) || !StringUtils.hasText(message)) {
return;
}
@ -276,6 +277,7 @@ public class CustomTaskHelper {
processEngineConfiguration.getCommentEntityManager().insert(comment);
task.setTransientVariable(type, message);
}
public static Attachment addAttachment(CommandContext commandContext, Task task, AttachmentDTO attachmentDto) {
@ -341,8 +343,7 @@ public class CustomTaskHelper {
task.setTaskDefinitionKey(taskDefinitionKey);
task.setPriority(DEFAULT_PRIORITY);
task.setCreateTime(new Date());
// 创建临时节点
taskService.saveTask(task);
if (Objects.nonNull(assigner)) {
CommandContextUtil.getEntityCache().findInCache(TaskEntity.class).stream()
@ -382,10 +383,11 @@ public class CustomTaskHelper {
return task;
}
private static void addAdvice(CommandContext commandContext, Task task, String comment, String userId) {
private static void addAdvice(CommandContext commandContext, TaskEntity task, String comment, String userId) {
if (StringUtils.hasLength(comment)) {
Authentication.setAuthenticatedUserId(userId);
addComment(commandContext, task, COMMENT_TYPE_ADVICE, comment);
task.setTransientVariable(COMMENT_TYPE_ADVICE + task.getId(), comment);
Authentication.setAuthenticatedUserId(null);
}
}

View File

@ -18,17 +18,15 @@ import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.cmd.GetTaskCommentsByTypeCmd;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.task.Comment;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.stereotype.Component;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import static cn.axzo.workflow.common.constant.BpmnConstants.AND_SIGN_EXPRESSION;
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.HIDDEN_ASSIGNEE_ID;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT;
@ -98,11 +96,13 @@ public class TaskEntityEventHandle implements EntityEventHandle<TaskEntity> {
if (Objects.equals(taskEntity.getTaskDefinitionKey(), NODE_STARTER.getType())) {
update.setStatus(APPROVED.getStatus());
} else {
List<Comment> comments = processEngineConfiguration.getCommandExecutor()
.execute(new GetTaskCommentsByTypeCmd(taskEntity.getId(), COMMENT_TYPE_OPERATION_DESC));
comments.stream().max(Comparator.comparing(Comment::getTime)).ifPresent(e -> update.setOperationDesc(e.getFullMessage()));
String completionType = taskEntity.getVariable(TASK_COMPLETE_OPERATION_TYPE + taskEntity.getId(), String.class);
log.info("TASK_COMPLETE_OPERATION_TYPE: {}", completionType);
Object advice = taskEntity.getTransientVariable(COMMENT_TYPE_ADVICE);
log.info("COMMENT_TYPE_ADVICE: {}", advice);
Object operationDesc = taskEntity.getTransientVariable(COMMENT_TYPE_OPERATION_DESC);
log.info("COMMENT_TYPE_OPERATION_DESC: {}", operationDesc);
update.setStatus(completionType);
queryLog.setOperationDesc(PENDING.getDesc());