feat(REQ-2924) - 测试转交日志

This commit is contained in:
wangli 2024-09-06 00:36:47 +08:00
parent 465cbd2791
commit 53a17ed100
12 changed files with 398 additions and 164 deletions

View File

@ -2,6 +2,7 @@ package cn.axzo.workflow.core.engine.cmd;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import cn.axzo.workflow.core.engine.model.AddComment;
import cn.axzo.workflow.core.engine.operation.DeleteProcessInstanceOperation;
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
import com.alibaba.fastjson.JSON;
@ -20,7 +21,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import static cn.axzo.workflow.common.constant.BpmnConstants.COMMENT_TYPE_OPERATION_DESC;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_DELETE_PROCESS_FLAG;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_TENANT_ID;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_USER_ID;
@ -35,7 +35,7 @@ import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.CANCEL
import static cn.axzo.workflow.core.common.code.BpmnInstanceRespCode.PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS;
import static cn.axzo.workflow.core.common.code.BpmnInstanceRespCode.PROCESS_INSTANCE_CANT_ABORT;
import static cn.axzo.workflow.core.common.code.BpmnInstanceRespCode.PROCESS_INSTANCE_NOT_EXISTS;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.addComment;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.completeVirtualTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.createVirtualTask;
/**
@ -106,9 +106,10 @@ public class CustomAbortProcessInstanceCmd extends AbstractCommand<Void> impleme
// 添加自定义的节点,用于展示最后的操作
Task task = createVirtualTask(commandContext, extAxHiTaskInstService, processInstanceId,
"系统中止", NODE_ABORT.getType(), null, BpmnTaskDelegateAssigner.buildDummyAssigner("system",
TASK_ASSIGNEE_SKIP_FLAT, "系统"), ABORTED.getStatus());
addComment(commandContext, task, COMMENT_TYPE_OPERATION_DESC, reason);
TASK_ASSIGNEE_SKIP_FLAT, "系统"), ABORTED.getStatus(), new AddComment(reason));
runtimeService.setVariable(task.getProcessInstanceId(), TASK_COMPLETE_OPERATION_TYPE + task.getId(), ABORTED);
completeVirtualTask(commandContext, task);
return null;
}

View File

@ -2,6 +2,7 @@ package cn.axzo.workflow.core.engine.cmd;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import cn.axzo.workflow.core.engine.model.AddComment;
import cn.axzo.workflow.core.engine.operation.DeleteProcessInstanceOperation;
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
import com.alibaba.fastjson.JSON;
@ -18,7 +19,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import static cn.axzo.workflow.common.constant.BpmnConstants.COMMENT_TYPE_OPERATION_DESC;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_DELETE_PROCESS_FLAG;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_TENANT_ID;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_USER_ID;
@ -32,7 +32,7 @@ import static cn.axzo.workflow.core.common.code.BpmnInstanceRespCode.PROCESS_INS
import static cn.axzo.workflow.core.common.code.BpmnInstanceRespCode.PROCESS_INSTANCE_CANCEL_FAIL_NOT_SELF;
import static cn.axzo.workflow.core.common.code.BpmnInstanceRespCode.PROCESS_INSTANCE_CANT_CANCEL;
import static cn.axzo.workflow.core.common.code.BpmnInstanceRespCode.PROCESS_INSTANCE_NOT_EXISTS;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.addComment;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.completeVirtualTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.createVirtualTask;
/**
@ -108,8 +108,8 @@ public class CustomCancelProcessInstanceCmd extends AbstractCommand<Void> implem
// 添加自定义的节点,用于展示最后的操作
Task task = createVirtualTask(commandContext, extAxHiTaskInstService, processInstanceId,
"发起人撤回", NODE_CANCEL.getType(), reason, initiator, CANCELLED.getStatus());
addComment(commandContext, task, COMMENT_TYPE_OPERATION_DESC, "已撤回");
"发起人撤回", NODE_CANCEL.getType(), reason, initiator, CANCELLED.getStatus(), new AddComment(CANCELLED.getDesc()));
completeVirtualTask(commandContext, task);
return null;
}

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.engine.model.AddComment;
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
@ -23,12 +24,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.axzo.workflow.common.constant.BpmnConstants.COMMENT_TYPE_OPERATION_DESC;
import static cn.axzo.workflow.common.constant.BpmnConstants.COUNTERSIGN_ASSIGNER_SHOW_NUMBER;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_ACTIVITY_RELATION_ASSIGNEE_LIST_INFO_SNAPSHOT;
import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.COUNTERSIGN;
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.completeVirtualTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.createVirtualTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTaskAssignerCount;
@ -155,9 +155,9 @@ public class CustomCountersignUserTaskCmd extends AbstractCommand<Void> implemen
}
message.append("").append(targetTaskAssigneeList.size()).append("人进行审批");
Task virtualTask = createVirtualTask(commandContext, extAxHiTaskInstService, task.getProcessInstanceId(), task.getName(),
task.getTaskDefinitionKey(), advice, originTaskAssignee, COUNTERSIGN.getStatus());
addComment(commandContext, virtualTask, COMMENT_TYPE_OPERATION_DESC, message.toString());
task.getTaskDefinitionKey(), advice, originTaskAssignee, COUNTERSIGN.getStatus(), new AddComment(message.toString()));
batchAddAttachment(commandContext, task.getProcessInstanceId(), task.getId(), attachmentList, originTaskAssignee);
completeVirtualTask(commandContext, virtualTask);
}
}

View File

@ -4,6 +4,7 @@ import cn.axzo.workflow.common.enums.BpmnFlowNodeType;
import cn.axzo.workflow.common.model.request.bpmn.task.AttachmentDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskAuditDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import cn.axzo.workflow.core.engine.model.AddComment;
import cn.axzo.workflow.core.engine.operation.DeleteProcessInstanceOperation;
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
import com.alibaba.fastjson.JSON;
@ -23,7 +24,6 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import static cn.axzo.workflow.common.constant.BpmnConstants.COMMENT_TYPE_OPERATION_DESC;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_DELETE_PROCESS_FLAG;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_TENANT_ID;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_USER_ID;
@ -32,8 +32,8 @@ import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_PROCESS_DE
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_PROCESS_TYPE_REJECT;
import static cn.axzo.workflow.common.constant.BpmnConstants.TASK_COMPLETE_OPERATION_TYPE;
import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.REJECTED;
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.completeVirtualTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.createVirtualTask;
import static cn.axzo.workflow.core.engine.cmd.helper.CustomTaskHelper.validTask;
@ -103,11 +103,12 @@ public class CustomRejectionTaskCmd extends AbstractCommand<Void> implements Ser
((TaskEntity) task).setTransientVariable(TASK_COMPLETE_OPERATION_TYPE + task.getId(), REJECTED.getStatus());
Task virtualTask = createVirtualTask(commandContext, extAxHiTaskInstService, task.getProcessInstanceId(), task.getName(),
task.getTaskDefinitionKey(), advice, Objects.equals(operationDesc, "自动驳回") ? null : approver, REJECTED.getStatus());
addComment(commandContext, virtualTask, COMMENT_TYPE_OPERATION_DESC, operationDesc);
task.getTaskDefinitionKey(), advice,
Objects.equals(operationDesc, "自动驳回") ? null : approver, REJECTED.getStatus(),
new AddComment(operationDesc));
batchAddAttachment(commandContext, task.getProcessInstanceId(), virtualTask.getId(), attachmentList, approver);
completeVirtualTask(commandContext, virtualTask);
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
finishProcessInstance(commandContext, runtimeService, task, advice);

View File

@ -6,6 +6,7 @@ import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import cn.axzo.workflow.common.model.response.bpmn.task.BpmnHistoricTaskInstanceVO;
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
import cn.axzo.workflow.core.engine.model.AddComment;
import cn.axzo.workflow.core.repository.entity.ExtAxHiTaskInst;
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
import cn.axzo.workflow.core.service.converter.BpmnHistoricTaskInstanceConverter;
@ -246,8 +247,11 @@ public class CustomTaskHelper {
addComment(commandContext, task, type, message);
}
public static void addComment(CommandContext commandContext, Task task, AddComment addComment) {
addComment(commandContext, task, addComment.getCommentType(), addComment.getContent());
}
public static void addComment(CommandContext commandContext, Task task, String type, String message) {
if (!StringUtils.hasText(message)) {
if (!StringUtils.hasText(type) || !StringUtils.hasText(message)) {
return;
}
ProcessEngineConfigurationImpl processEngineConfiguration =
@ -317,7 +321,7 @@ public class CustomTaskHelper {
public static Task createVirtualTask(CommandContext commandContext, ExtAxHiTaskInstService extAxHiTaskInstService
, String processInstanceId, String nodeName, String taskDefinitionKey, String advice,
BpmnTaskDelegateAssigner assigner,
String extTaskInstStatus) {
String extTaskInstStatus, AddComment addComment) {
ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
HistoryService historyService = processEngineConfiguration.getHistoryService();
@ -352,6 +356,8 @@ public class CustomTaskHelper {
// 添加审批意见
addAdvice(commandContext, task, advice, Objects.nonNull(assigner) ? assigner.buildAssigneeId() : null);
// 添加操作描述
addComment(commandContext, task, addComment);
CustomTaskHelper.createExtTaskInst(extAxHiTaskInstService, task.getProcessInstanceId(), task.getId(),
task.getTaskDefinitionKey(), assigner, extTaskInstStatus);
@ -362,12 +368,20 @@ public class CustomTaskHelper {
task.setVariable(INTERNAL_TASK_RELATION_ASSIGNEE_INFO + task.getId(), assigner.toJson());
}
// 完成临时节点
taskService.complete(task.getId());
// 完成临时节点, 1.4.2虚拟节点创建方法不再默认完成需主动调用 completeVirtualTask 完成
// taskService.complete(task.getId());
return task;
}
public static Task completeVirtualTask(CommandContext commandContext, Task task) {
ProcessEngineConfigurationImpl processEngineConfiguration =
CommandContextUtil.getProcessEngineConfiguration(commandContext);
TaskService taskService = processEngineConfiguration.getTaskService();
taskService.complete(task.getId());
return task;
}
private static void addAdvice(CommandContext commandContext, Task task, String comment, String userId) {
if (StringUtils.hasLength(comment)) {
Authentication.setAuthenticatedUserId(userId);

View File

@ -0,0 +1,115 @@
package cn.axzo.workflow.core.engine.listener.entity;
import com.google.common.collect.ImmutableSet;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.event.AbstractFlowableEventListener;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_ACTIVATED;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_CREATED;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_DELETED;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_INITIALIZED;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_SUSPENDED;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_UPDATED;
/**
* TODO
*
* @author wangli
* @since 2024-09-02 15:34
*/
@Component
@Slf4j
@AllArgsConstructor
public class EngineEntityEventListener extends AbstractFlowableEventListener {
private final List<EntityEventHandle> handles;
public static final Set<FlowableEngineEventType> SUPPORTED =
ImmutableSet.<FlowableEngineEventType>builder()
.add(ENTITY_CREATED)
.add(ENTITY_INITIALIZED)
.add(ENTITY_UPDATED)
.add(ENTITY_DELETED)
.add(ENTITY_SUSPENDED)
.add(ENTITY_ACTIVATED)
.build();
@Override
public void onEvent(FlowableEvent event) {
if (event instanceof FlowableEntityEvent && SUPPORTED.contains(event.getType())) {
FlowableEntityEvent entityEvent = (FlowableEntityEvent) event;
// log.warn("entity event type: {}, class: {}",entityEvent.getType(), entityEvent.getEntity().getClass());
handles.forEach(handle -> {
Object entity = entityEvent.getEntity();
if (handle.support(entity)) {
Object convert = handle.convert(entity);
if (Objects.equals(event.getType(), ENTITY_CREATED)) {
handle.onCreate(convert);
} else if (Objects.equals(event.getType(), ENTITY_INITIALIZED)) {
handle.onInitialized(convert);
} else if (Objects.equals(event.getType(), ENTITY_UPDATED)) {
handle.onUpdated(convert);
} else if (Objects.equals(event.getType(), ENTITY_DELETED)) {
handle.onDeleted(convert);
} else if (Objects.equals(event.getType(), ENTITY_SUSPENDED)) {
handle.onSuspended(convert);
} else if (Objects.equals(event.getType(), ENTITY_ACTIVATED)) {
handle.onActivated(convert);
}
}
});
// if (entityEvent.getEntity() instanceof TaskEntity) {
// TaskEntity taskEntity = (TaskEntity) entityEvent.getEntity();
// log.error("event taskId :{}, taskDefKey: {}", taskEntity.getId(), taskEntity.getTaskDefinitionKey());
//
// if (Objects.equals(event.getType(), ENTITY_CREATED)) {
// onCreate(taskEntity);
// } else if (Objects.equals(event.getType(), ENTITY_INITIALIZED)) {
// onInitialized(taskEntity);
// } else if (Objects.equals(event.getType(), ENTITY_UPDATED)) {
// onUpdated(taskEntity);
// } else if (Objects.equals(event.getType(), ENTITY_DELETED)) {
// onDeleted(taskEntity);
// } else if (Objects.equals(event.getType(), ENTITY_SUSPENDED)) {
// onSuspended(taskEntity);
// } else if (Objects.equals(event.getType(), ENTITY_ACTIVATED)) {
// onActivated(taskEntity);
// }
// } else if(entityEvent.getEntity() instanceof CommentEntity) {
// CommentEntity commentEntity = (CommentEntity) entityEvent.getEntity();
// log.error("event taskId :{}", commentEntity.getId());
//
// if (Objects.equals(event.getType(), ENTITY_CREATED)) {
// onCreate(commentEntity);
// } else if (Objects.equals(event.getType(), ENTITY_INITIALIZED)) {
// onInitialized(commentEntity);
// } else if (Objects.equals(event.getType(), ENTITY_UPDATED)) {
// onUpdated(commentEntity);
// } else if (Objects.equals(event.getType(), ENTITY_DELETED)) {
// onDeleted(commentEntity);
// } else if (Objects.equals(event.getType(), ENTITY_SUSPENDED)) {
// onSuspended(commentEntity);
// } else if (Objects.equals(event.getType(), ENTITY_ACTIVATED)) {
// onActivated(commentEntity);
// }
// }
}
}
@Override
public boolean isFailOnException() {
return true;
}
}

View File

@ -0,0 +1,27 @@
package cn.axzo.workflow.core.engine.listener.entity;
/**
* TODO
*
* @author wangli
* @since 2024-09-06 00:03
*/
public interface EntityEventHandle<T> {
boolean support(Object entity);
T convert(Object entity);
void onCreate(T entity);
void onInitialized(T entity);
void onUpdated(T entity);
void onDeleted(T entity);
void onSuspended(T entity);
void onActivated(T entity);
}

View File

@ -0,0 +1,82 @@
package cn.axzo.workflow.core.engine.listener.entity.type;
import cn.axzo.workflow.core.engine.listener.entity.EntityEventHandle;
import cn.axzo.workflow.core.repository.entity.ExtAxProcessLog;
import cn.axzo.workflow.core.service.ExtAxProcessLogService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.impl.persistence.entity.CommentEntity;
import org.springframework.stereotype.Component;
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_OPERATION_DESC;
/**
* TODO
*
* @author wangli
* @since 2024-09-06 00:14
*/
@Slf4j
@Component
@AllArgsConstructor
public class CommentEntityEventHandle implements EntityEventHandle<CommentEntity> {
private final ExtAxProcessLogService processLogService;
@Override
public boolean support(Object entity) {
return entity instanceof CommentEntity;
}
@Override
public CommentEntity convert(Object entity) {
return (CommentEntity) entity;
}
@Override
public void onCreate(CommentEntity entity) {
log.info("comment event onCreate: {}", entity.getId());
ExtAxProcessLog queryLog = new ExtAxProcessLog();
queryLog.setProcessInstanceId(entity.getProcessInstanceId());
queryLog.setTaskId(entity.getId());
ExtAxProcessLog update = new ExtAxProcessLog();
if (Objects.equals(COMMENT_TYPE_ADVICE, entity.getType())) {
update.setAdvice(entity.getFullMessage());
} else if (Objects.equals(COMMENT_TYPE_OPERATION_DESC, entity.getType())) {
update.setOperationDesc(entity.getFullMessage());
}
processLogService.update(queryLog, update);
}
@Override
public void onInitialized(CommentEntity entity) {
log.info("comment event onInitialized: {}", entity.getId());
}
@Override
public void onUpdated(CommentEntity entity) {
log.info("comment event onUpdated: {}", entity.getId());
}
@Override
public void onDeleted(CommentEntity entity) {
log.info("comment event onDeleted: {}", entity.getId());
}
@Override
public void onSuspended(CommentEntity entity) {
log.info("comment event onSuspended: {}", entity.getId());
}
@Override
public void onActivated(CommentEntity entity) {
log.info("comment event onSuspended: {}", entity.getId());
}
}

View File

@ -1,23 +1,19 @@
package cn.axzo.workflow.core.engine.listener;
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;
import cn.axzo.workflow.core.service.ExtAxProcessLogService;
import com.google.common.collect.ImmutableSet;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.UserTask;
import org.flowable.common.engine.api.delegate.event.AbstractFlowableEventListener;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior;
@ -31,15 +27,12 @@ import org.springframework.stereotype.Component;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import static cn.axzo.workflow.common.constant.BpmnConstants.AND_SIGN_EXPRESSION;
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;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_INITIATOR;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_TASK_RELATION_ASSIGNEE_INFO;
import static cn.axzo.workflow.common.constant.BpmnConstants.OLD_INTERNAL_INITIATOR;
import static cn.axzo.workflow.common.constant.BpmnConstants.TASK_COMPLETE_OPERATION_TYPE;
import static cn.axzo.workflow.common.enums.ApprovalMethodEnum.nobody;
import static cn.axzo.workflow.common.enums.BpmnFlowNodeMode.AND;
@ -51,79 +44,60 @@ import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.PROCES
import static cn.axzo.workflow.core.common.enums.BpmnProcessTaskResultEnum.PENDING;
import static cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper.getApprovalMethod;
import static cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper.getNodeType;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_ACTIVATED;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_CREATED;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_DELETED;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_INITIALIZED;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_SUSPENDED;
import static org.flowable.common.engine.api.delegate.event.FlowableEngineEventType.ENTITY_UPDATED;
/**
* TODO
*
* @author wangli
* @since 2024-09-02 15:34
* @since 2024-09-06 00:02
*/
@Component
@Slf4j
@Component
@AllArgsConstructor
public class EngineEntityEventListener extends AbstractFlowableEventListener {
public class TaskEntityEventHandle implements EntityEventHandle<TaskEntity> {
private final ExtAxProcessLogService processLogService;
public static final Set<FlowableEngineEventType> SUPPORTED =
ImmutableSet.<FlowableEngineEventType>builder()
.add(ENTITY_CREATED)
.add(ENTITY_INITIALIZED)
.add(ENTITY_UPDATED)
.add(ENTITY_DELETED)
.add(ENTITY_SUSPENDED)
.add(ENTITY_ACTIVATED)
.build();
@Override
public void onEvent(FlowableEvent event) {
if (event instanceof FlowableEntityEvent) {
FlowableEntityEvent entityEvent = (FlowableEntityEvent) event;
// log.warn("entity event type: {}, class: {}",entityEvent.getType(), entityEvent.getEntity().getClass());
if (entityEvent.getEntity() instanceof TaskEntity) {
TaskEntity taskEntity = (TaskEntity) entityEvent.getEntity();
log.error("event taskId :{}, taskDefKey: {}", taskEntity.getId(), taskEntity.getTaskDefinitionKey());
if (Objects.equals(event.getType(), ENTITY_CREATED)) {
onCreate(taskEntity);
} else if (Objects.equals(event.getType(), ENTITY_INITIALIZED)) {
onInitialized(taskEntity);
} else if (Objects.equals(event.getType(), ENTITY_UPDATED)) {
onUpdated(taskEntity);
} else if (Objects.equals(event.getType(), ENTITY_DELETED)) {
onDeleted(taskEntity);
} else if (Objects.equals(event.getType(), ENTITY_SUSPENDED)) {
onSuspended(taskEntity);
} else if (Objects.equals(event.getType(), ENTITY_ACTIVATED)) {
onActivated(taskEntity);
}
}
}
public boolean support(Object entity) {
return entity instanceof TaskEntity;
}
private void onActivated(TaskEntity taskEntity) {
@Override
public TaskEntity convert(Object entity) {
return (TaskEntity) entity;
}
@Override
public void onActivated(TaskEntity taskEntity) {
log.error("onActivated");
}
private void onSuspended(TaskEntity taskEntity) {
public void onSuspended(TaskEntity taskEntity) {
log.error("onSuspended");
}
private void onDeleted(TaskEntity taskEntity) {
public void onDeleted(TaskEntity taskEntity) {
log.error("onDeleted");
ExtAxProcessLog queryLog = new ExtAxProcessLog();
queryLog.setProcessInstanceId(taskEntity.getProcessInstanceId());
queryLog.setTaskId(taskEntity.getId());
ExtAxProcessLog update = new ExtAxProcessLog();
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
// BpmnTaskDelegateAssigner assignee = BpmnTaskDelegateAssigner.toObjectCompatible(runtimeService.getVariable(taskEntity.getProcessInstanceId(), INTERNAL_TASK_RELATION_ASSIGNEE_INFO + taskEntity.getId()));
BpmnTaskDelegateAssigner assignee = BpmnTaskDelegateAssigner.toObjectCompatible(taskEntity.getVariable(INTERNAL_TASK_RELATION_ASSIGNEE_INFO + taskEntity.getId()));
if (Objects.nonNull(assignee)) {
update.setAssigneeFull(assignee);
update.setAssigneeId(Long.valueOf(assignee.getPersonId()));
update.setAssigneeTenantId(assignee.getTenantId());
update.setAssigneeName(assignee.getAssignerName());
update.setAssigneeOuId(assignee.getOuId());
}
if (Objects.equals(taskEntity.getTaskDefinitionKey(), NODE_STARTER.getType())) {
update.setStatus(APPROVED.getStatus());
} else {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
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()));
@ -137,7 +111,7 @@ public class EngineEntityEventListener extends AbstractFlowableEventListener {
processLogService.update(queryLog, update);
}
private void onUpdated(TaskEntity taskEntity) {
public void onUpdated(TaskEntity taskEntity) {
log.error("onUpdated");
if (Objects.equals(HIDDEN_ASSIGNEE_ID, taskEntity.getAssignee())) {
ExtAxProcessLog queryLog = new ExtAxProcessLog();
@ -160,28 +134,28 @@ public class EngineEntityEventListener extends AbstractFlowableEventListener {
}
}
private void onInitialized(TaskEntity taskEntity) {
public void onInitialized(TaskEntity taskEntity) {
log.error("onInitialized");
}
private void onCreate(TaskEntity taskEntity) {
public void onCreate(TaskEntity taskEntity) {
log.error("onCreate");
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
BpmnTaskDelegateAssigner assignee;
// 记录发起人
// RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
// BpmnTaskDelegateAssigner assignee;
//
// // 记录发起人
boolean isNodeStarter = Objects.equals(taskEntity.getTaskDefinitionKey(), NODE_STARTER.getType());
if (isNodeStarter) {
assignee = BpmnTaskDelegateAssigner.toObjectCompatible(runtimeService.getVariable(taskEntity.getProcessInstanceId(),
INTERNAL_INITIATOR));
if (Objects.isNull(assignee)) {
// 兼容历史数据
assignee = BpmnTaskDelegateAssigner.toObjectCompatible(runtimeService.getVariable(taskEntity.getProcessInstanceId(), OLD_INTERNAL_INITIATOR));
}
} else {
assignee = BpmnTaskDelegateAssigner.toObjectCompatible(runtimeService.getVariable(taskEntity.getProcessInstanceId(), INTERNAL_TASK_RELATION_ASSIGNEE_INFO + taskEntity.getId()));
}
// if (isNodeStarter) {
// assignee = BpmnTaskDelegateAssigner.toObjectCompatible(runtimeService.getVariable(taskEntity.getProcessInstanceId(),
// INTERNAL_INITIATOR));
// if (Objects.isNull(assignee)) {
// // 兼容历史数据
// assignee = BpmnTaskDelegateAssigner.toObjectCompatible(runtimeService.getVariable(taskEntity.getProcessInstanceId(), OLD_INTERNAL_INITIATOR));
// }
// } else {
// assignee = BpmnTaskDelegateAssigner.toObjectCompatible(runtimeService.getVariable(taskEntity.getProcessInstanceId(), INTERNAL_TASK_RELATION_ASSIGNEE_INFO + taskEntity.getId()));
// }
RepositoryService repositoryService = processEngineConfiguration.getRepositoryService();
BpmnModel bpmnModel = repositoryService.getBpmnModel(taskEntity.getProcessDefinitionId());
@ -197,13 +171,13 @@ public class EngineEntityEventListener extends AbstractFlowableEventListener {
log.setNodeMode((isNodeStarter ? BpmnFlowNodeMode.GENERAL : getNodeMode(flowElement)).getType());
log.setTaskId(taskEntity.getId());
log.setOperationDesc(PENDING.getDesc());
if (Objects.nonNull(assignee)) {
log.setAssigneeFull(assignee);
log.setAssigneeId(Long.valueOf(assignee.getPersonId()));
log.setAssigneeTenantId(assignee.getTenantId());
log.setAssigneeName(assignee.getAssignerName());
log.setAssigneeOuId(assignee.getOuId());
}
// if (Objects.nonNull(assignee)) {
// log.setAssigneeFull(assignee);
// log.setAssigneeId(Long.valueOf(assignee.getPersonId()));
// log.setAssigneeTenantId(assignee.getTenantId());
// log.setAssigneeName(assignee.getAssignerName());
// log.setAssigneeOuId(assignee.getOuId());
// }
log.setStartTime(taskEntity.getCreateTime());
log.setStatus(PROCESSING.getStatus());
@ -222,10 +196,4 @@ public class EngineEntityEventListener extends AbstractFlowableEventListener {
}
return node;
}
@Override
public boolean isFailOnException() {
return true;
}
}

View File

@ -0,0 +1,40 @@
package cn.axzo.workflow.core.engine.model;
import static cn.axzo.workflow.common.constant.BpmnConstants.COMMENT_TYPE_OPERATION_DESC;
/**
* 评论模型
*
* @author wangli
* @since 2024-09-05 23:18
*/
public class AddComment {
private String commentType;
private String content;
public AddComment(String commentType, String content) {
this.commentType = commentType;
this.content = content;
}
public AddComment(String content) {
this.commentType = COMMENT_TYPE_OPERATION_DESC;
this.content = content;
}
public String getCommentType() {
return commentType;
}
public void setCommentType(String commentType) {
this.commentType = commentType;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}

View File

@ -30,12 +30,12 @@ import static org.mapstruct.NullValueCheckStrategy.ALWAYS;
* @since 2024/1/25 16:31
*/
@Mapper(
componentModel = "spring",
nullValueCheckStrategy = ALWAYS,
imports = Arrays.class
componentModel = "spring",
nullValueCheckStrategy = ALWAYS,
imports = Arrays.class
)
public interface BpmnProcessInstanceAdminPageItemConverter extends EntityConverter<BpmnProcessInstanceAdminPageItemVO,
HistoricProcessInstance> {
HistoricProcessInstance> {
@Mapping(target = "processInstanceId", source = "id")
@Mapping(target = "processInstanceName", source = "name")
@ -58,8 +58,8 @@ public interface BpmnProcessInstanceAdminPageItemConverter extends EntityConvert
if (Objects.equals(PROCESSING.getStatus(), i.getBusinessStatus())) {
List<FlowElement> flowElements = instanceFlowElementMap.get(i.getId()).stream()
.filter(j -> j instanceof UserTask || j instanceof ReceiveTask || j instanceof ServiceTask)
.collect(Collectors.toList());
.filter(j -> j instanceof UserTask || j instanceof ReceiveTask || j instanceof ServiceTask)
.collect(Collectors.toList());
vo.setTotalNodeCount(flowElements.size());
// 进行中的节点
@ -85,7 +85,7 @@ public interface BpmnProcessInstanceAdminPageItemConverter extends EntityConvert
vo.setCategoryDesc(category.getLabel());
vo.setWorkspaceTypeCode(category.getWorkspaceTypeCode());
vo.setBusinessStatusDesc(BpmnProcessInstanceResultEnum.valueOfStatus(vo.getBusinessStatus()).getDesc());
vo.setWorkspaceType(WorkspaceType.getType(Integer.valueOf(vo.getWorkspaceTypeCode())));
vo.setWorkspaceType(WorkspaceType.getType(Integer.valueOf(Objects.nonNull(vo.getWorkspaceTypeCode()) ? vo.getWorkspaceTypeCode() : "0")));
result.add(vo);
});
return result;

View File

@ -1,77 +1,63 @@
package cn.axzo.workflow.starter.api;
import cn.axzo.workflow.starter.feign.ext.WorkflowEngineStarterFeignConfiguration;
import cn.axzo.workflow.common.util.ThreadUtil;
import static cn.axzo.workflow.common.enums.RpcInvokeModeEnum.ASYNC;
import static cn.axzo.workflow.common.enums.RpcInvokeModeEnum.SYNC;
import cn.axzo.workflow.client.config.CommonFeignConfiguration;
import cn.axzo.workflow.common.annotation.InvokeMode;
import cn.axzo.workflow.common.annotation.Manageable;
import cn.axzo.workflow.common.model.request.bpmn.BpmnButtonMetaInfo;
import cn.azxo.framework.common.model.CommonResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
import cn.axzo.workflow.common.model.request.bpmn.RestBpmnProcessVariable;
import cn.axzo.workflow.common.model.request.bpmn.definition.BpmnProcessDefinitionUpdateDTO;
import cn.axzo.workflow.common.model.request.bpmn.model.BpmnModelCreateDTO;
import cn.axzo.workflow.common.model.request.bpmn.model.BpmnModelSearchDTO;
import cn.axzo.workflow.common.model.request.bpmn.model.BpmnModelUpdateDTO;
import cn.axzo.workflow.common.model.response.BpmPageResult;
import cn.axzo.workflow.common.model.response.bpmn.model.BpmnModelDetailVO;
import cn.axzo.workflow.common.model.response.bpmn.model.BpmnModelExtVO;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnActivitySetAssigneeDTO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceAbortDTO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessDefinitionPageDTO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceAdminPageReqVO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceCancelDTO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceCarbonCopyDTO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceCheckApproverDTO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceCreateDTO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceCreateWithFormDTO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceMyPageReqVO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceQueryDTO;
import cn.axzo.workflow.common.model.response.bpmn.BatchOperationResultVO;
import cn.axzo.workflow.common.model.response.bpmn.process.BpmnProcessInstanceAdminPageItemVO;
import cn.axzo.workflow.common.model.response.bpmn.process.BpmnProcessInstancePageItemVO;
import cn.axzo.workflow.common.model.response.bpmn.process.BpmnProcessInstanceVO;
import cn.axzo.workflow.common.model.response.bpmn.process.ProcessNodeDetailVO;
import com.fasterxml.jackson.databind.node.ObjectNode;
import javax.annotation.Nullable;
import java.util.Map;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskAttachmentDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskPageSearchDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskRemindDTO;
import cn.axzo.workflow.common.model.request.category.CategoryConfigCreateDTO;
import cn.axzo.workflow.common.model.request.category.CategoryConfigSearchDTO;
import cn.axzo.workflow.common.model.request.category.CategoryCreateDTO;
import cn.axzo.workflow.common.model.request.category.CategorySearchDTO;
import cn.axzo.workflow.common.model.request.category.CategoryUpdateDTO;
import cn.axzo.workflow.common.model.response.category.CategoryConfigItemVO;
import cn.axzo.workflow.common.model.response.category.CategoryItemVO;
import org.springframework.web.bind.annotation.PathVariable;
import cn.axzo.workflow.common.model.request.bpmn.RestBpmnProcessVariable;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnRobotTaskCompleteDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnRobotTaskCreateDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskAttachmentDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskAuditDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskCommentDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskCountersignDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskPageSearchDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskRemindDTO;
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskTransferDTO;
import cn.axzo.workflow.common.model.response.BpmPageResult;
import cn.axzo.workflow.common.model.response.bpmn.model.BpmnModelDetailVO;
import cn.axzo.workflow.common.model.response.bpmn.model.BpmnModelExtVO;
import cn.axzo.workflow.common.model.response.bpmn.process.BpmnProcessDefinitionVO;
import cn.axzo.workflow.common.model.response.bpmn.process.BpmnProcessInstanceAdminPageItemVO;
import cn.axzo.workflow.common.model.response.bpmn.process.BpmnProcessInstancePageItemVO;
import cn.axzo.workflow.common.model.response.bpmn.process.ProcessNodeDetailVO;
import cn.axzo.workflow.common.model.response.bpmn.task.BpmnHistoricTaskInstanceGroupVO;
import cn.axzo.workflow.common.model.response.bpmn.task.BpmnHistoricTaskInstanceVO;
import cn.axzo.workflow.common.model.response.bpmn.task.BpmnTaskDonePageItemVO;
import cn.axzo.workflow.common.model.response.bpmn.task.BpmnTaskInstanceVO;
import cn.axzo.workflow.common.model.response.bpmn.task.BpmnTaskTodoPageItemVO;
import cn.axzo.workflow.common.model.response.category.CategoryConfigItemVO;
import cn.axzo.workflow.common.model.response.category.CategoryItemVO;
import cn.axzo.workflow.common.util.ThreadUtil;
import cn.axzo.workflow.starter.feign.ext.WorkflowEngineStarterFeignConfiguration;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Nullable;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import cn.axzo.workflow.common.model.request.bpmn.definition.BpmnProcessDefinitionUpdateDTO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessDefinitionPageDTO;
import cn.axzo.workflow.common.model.response.bpmn.process.BpmnProcessDefinitionVO;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
import static cn.axzo.workflow.common.enums.RpcInvokeModeEnum.ASYNC;
import static cn.axzo.workflow.common.enums.RpcInvokeModeEnum.SYNC;
/**
* Workflow Engine Starter Management Service<br/>该类是根据 API 动态生成不同版本可能会开放新的接口或回收一些旧接口