feat(REQ-2924) - 完善评论功能的日志逻辑
This commit is contained in:
parent
879e1a8caf
commit
f610bc9a97
@ -4,13 +4,11 @@ import cn.axzo.workflow.common.model.request.bpmn.task.AttachmentDTO;
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskCommentExtDTO;
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
|
||||
import cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper;
|
||||
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.flowable.common.engine.impl.cfg.IdGenerator;
|
||||
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.HistoryService;
|
||||
import org.flowable.engine.TaskService;
|
||||
@ -22,7 +20,6 @@ import org.flowable.task.service.impl.persistence.entity.TaskEntity;
|
||||
import org.flowable.variable.service.HistoricVariableService;
|
||||
import org.flowable.variable.service.impl.persistence.entity.HistoricVariableInstanceEntity;
|
||||
import org.flowable.variable.service.impl.types.StringType;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
@ -36,9 +33,13 @@ import java.util.Objects;
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.COMMENT_TYPE_ADVICE;
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.COMMENT_TYPE_COMMENT_EXT;
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO;
|
||||
import static cn.axzo.workflow.common.constant.BpmnConstants.TASK_COMPLETE_OPERATION_TYPE;
|
||||
import static cn.axzo.workflow.common.enums.BpmnFlowNodeType.NODE_COMMENT;
|
||||
import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.COMMENTED;
|
||||
import static cn.axzo.workflow.core.common.code.BpmnInstanceRespCode.TASK_CANT_COMMENT_INSTANCE_NOT_EXISTS;
|
||||
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.addComment;
|
||||
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.batchAddAttachment;
|
||||
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.createExtTaskInst;
|
||||
import static org.flowable.task.api.Task.DEFAULT_PRIORITY;
|
||||
|
||||
/**
|
||||
@ -80,11 +81,11 @@ public class CustomCommentTaskCmd extends AbstractCommand<Void> implements Seria
|
||||
@Override
|
||||
public Void execute(CommandContext commandContext) {
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration =
|
||||
CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
CommandContextUtil.getProcessEngineConfiguration(commandContext);
|
||||
HistoryService historyService = processEngineConfiguration.getHistoryService();
|
||||
|
||||
HistoricProcessInstance processInstance =
|
||||
historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
|
||||
historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
|
||||
if (Objects.isNull(processInstance)) {
|
||||
throw new WorkflowEngineException(TASK_CANT_COMMENT_INSTANCE_NOT_EXISTS, processInstanceId);
|
||||
}
|
||||
@ -103,32 +104,35 @@ public class CustomCommentTaskCmd extends AbstractCommand<Void> implements Seria
|
||||
task.setTaskDefinitionKey(NODE_COMMENT.getType());
|
||||
task.setPriority(DEFAULT_PRIORITY);
|
||||
task.setCreateTime(new Date());
|
||||
// 创建临时节点
|
||||
taskService.saveTask(task);
|
||||
|
||||
// 处理该评论节点的评论人
|
||||
buildAndInsertHistoryVariable(task, processInstance, processEngineConfiguration);
|
||||
|
||||
CommandContextUtil.getEntityCache().findInCache(HistoricTaskInstanceEntity.class).stream()
|
||||
.filter(i -> Objects.equals(i.getId(), task.getId())).findAny()
|
||||
.ifPresent(i -> i.setAssignee(operator.buildAssigneeId()));
|
||||
// 完成临时节点
|
||||
taskService.complete(task.getId());
|
||||
.filter(i -> Objects.equals(i.getId(), task.getId())).findAny()
|
||||
.ifPresent(i -> i.setAssignee(operator.buildAssigneeId()));
|
||||
|
||||
// 新增评论
|
||||
Authentication.setAuthenticatedUserId(operator.buildAssigneeId());
|
||||
if (StringUtils.hasText(comment)) {
|
||||
CustomTaskHelper.addComment(commandContext, task, COMMENT_TYPE_ADVICE, comment);
|
||||
}
|
||||
if (Objects.nonNull(commentExt)) {
|
||||
CustomTaskHelper.addComment(commandContext, task, COMMENT_TYPE_COMMENT_EXT, JSONUtil.toJsonStr(commentExt));
|
||||
}
|
||||
addComment(commandContext, task, COMMENT_TYPE_ADVICE, comment);
|
||||
addComment(commandContext, task, COMMENT_TYPE_COMMENT_EXT, JSONUtil.toJsonStr(commentExt));
|
||||
Authentication.setAuthenticatedUserId(null);
|
||||
|
||||
// 处理附件
|
||||
CustomTaskHelper.batchAddAttachment(commandContext, processInstanceId, task.getId(), attachmentList, operator);
|
||||
batchAddAttachment(commandContext, processInstanceId, task.getId(), attachmentList, operator);
|
||||
|
||||
CustomTaskHelper.createExtTaskInst(extAxHiTaskInstService, processInstanceId,
|
||||
task.getId(), task.getTaskDefinitionKey(), operator, COMMENTED.getStatus());
|
||||
createExtTaskInst(extAxHiTaskInstService, processInstanceId,
|
||||
task.getId(), task.getTaskDefinitionKey(), operator, COMMENTED.getStatus());
|
||||
task.setTransientVariable(TASK_COMPLETE_OPERATION_TYPE + task.getId(), COMMENTED.getStatus());
|
||||
|
||||
// 保存临时节点
|
||||
taskService.saveTask(task);
|
||||
|
||||
// 设置快照信息
|
||||
task.setVariable(INTERNAL_TASK_RELATION_ASSIGNEE_INFO + task.getId(), operator.toJson());
|
||||
|
||||
// 完成临时节点
|
||||
taskService.complete(task.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -136,9 +140,9 @@ public class CustomCommentTaskCmd extends AbstractCommand<Void> implements Seria
|
||||
HistoricProcessInstance processInstance,
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration) {
|
||||
HistoricVariableService historicVariableService =
|
||||
processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService();
|
||||
processEngineConfiguration.getVariableServiceConfiguration().getHistoricVariableService();
|
||||
HistoricVariableInstanceEntity historicVariableInstance =
|
||||
historicVariableService.createHistoricVariableInstance();
|
||||
historicVariableService.createHistoricVariableInstance();
|
||||
historicVariableInstance.setTaskId(task.getId());
|
||||
historicVariableInstance.setExecutionId(task.getExecutionId());
|
||||
historicVariableInstance.setProcessInstanceId(processInstance.getId());
|
||||
|
||||
@ -344,7 +344,6 @@ public class CustomTaskHelper {
|
||||
task.setPriority(DEFAULT_PRIORITY);
|
||||
task.setCreateTime(new Date());
|
||||
|
||||
|
||||
if (Objects.nonNull(assigner)) {
|
||||
CommandContextUtil.getEntityCache().findInCache(TaskEntity.class).stream()
|
||||
.filter(i -> Objects.equals(i.getId(), task.getId())).findAny()
|
||||
@ -364,6 +363,9 @@ public class CustomTaskHelper {
|
||||
task.getTaskDefinitionKey(), assigner, extTaskInstStatus);
|
||||
task.setTransientVariable(TASK_COMPLETE_OPERATION_TYPE + task.getId(), extTaskInstStatus);
|
||||
|
||||
// 保存任务
|
||||
taskService.saveTask(task);
|
||||
|
||||
if (Objects.nonNull(assigner)) {
|
||||
// 设置快照信息
|
||||
task.setVariable(INTERNAL_TASK_RELATION_ASSIGNEE_INFO + task.getId(), assigner.toJson());
|
||||
|
||||
@ -3,7 +3,6 @@ package cn.axzo.workflow.core.engine.listener.entity.type;
|
||||
import cn.axzo.framework.jackson.utility.JSON;
|
||||
import cn.axzo.workflow.common.enums.BpmnFlowNodeMode;
|
||||
import cn.axzo.workflow.common.enums.BpmnFlowNodeType;
|
||||
import cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum;
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import cn.axzo.workflow.core.engine.listener.entity.EntityEventHandle;
|
||||
import cn.axzo.workflow.core.repository.entity.ExtAxProcessLog;
|
||||
@ -21,7 +20,9 @@ import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
||||
import org.flowable.engine.impl.util.CommandContextUtil;
|
||||
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -79,6 +80,7 @@ public class TaskEntityEventHandle implements EntityEventHandle<TaskEntity> {
|
||||
ExtAxProcessLog queryLog = new ExtAxProcessLog();
|
||||
queryLog.setProcessInstanceId(taskEntity.getProcessInstanceId());
|
||||
queryLog.setTaskId(taskEntity.getId());
|
||||
queryLog.setOperationDesc(PENDING.getDesc());
|
||||
ExtAxProcessLog update = new ExtAxProcessLog();
|
||||
|
||||
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
|
||||
@ -97,17 +99,26 @@ public class TaskEntityEventHandle implements EntityEventHandle<TaskEntity> {
|
||||
update.setStatus(APPROVED.getStatus());
|
||||
} else {
|
||||
String completionType = taskEntity.getVariable(TASK_COMPLETE_OPERATION_TYPE + taskEntity.getId(), String.class);
|
||||
log.info("TASK_COMPLETE_OPERATION_TYPE: {}", completionType);
|
||||
if (StringUtils.hasText(completionType)) {
|
||||
log.info("TASK_COMPLETE_OPERATION_TYPE: {}", completionType);
|
||||
update.setStatus(completionType);
|
||||
}
|
||||
Object advice = taskEntity.getTransientVariable(COMMENT_TYPE_ADVICE);
|
||||
log.info("COMMENT_TYPE_ADVICE: {}", advice);
|
||||
if (Objects.nonNull(advice) && StringUtils.hasText(advice.toString())) {
|
||||
log.info("COMMENT_TYPE_ADVICE: {}", advice);
|
||||
update.setAdvice(advice.toString());
|
||||
}
|
||||
Object operationDesc = taskEntity.getTransientVariable(COMMENT_TYPE_OPERATION_DESC);
|
||||
log.info("COMMENT_TYPE_OPERATION_DESC: {}", operationDesc);
|
||||
|
||||
update.setStatus(completionType);
|
||||
|
||||
queryLog.setOperationDesc(PENDING.getDesc());
|
||||
update.setOperationDesc(BpmnProcessInstanceResultEnum.valueOfStatus(completionType).getDesc());
|
||||
if (Objects.nonNull(operationDesc) && StringUtils.hasText(operationDesc.toString())) {
|
||||
log.info("COMMENT_TYPE_OPERATION_DESC: {}", operationDesc);
|
||||
update.setOperationDesc(Objects.nonNull(assignee) ? assignee.getAssignerName() + operationDesc : operationDesc.toString());
|
||||
} else {
|
||||
update.setOperationDesc(Objects.nonNull(assignee) ? assignee.getAssignerName() : "");
|
||||
// 评论节点会给 operationDesc 赋 COMMENTED 的值,所以注释
|
||||
// update.setOperationDesc(BpmnProcessInstanceResultEnum.valueOfStatus(completionType).getDesc());
|
||||
}
|
||||
}
|
||||
update.setEndTime(new Date());
|
||||
processLogService.update(queryLog, update);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user