diff --git a/workflow-engine-common/src/main/java/cn/axzo/workflow/common/constant/BpmnConstants.java b/workflow-engine-common/src/main/java/cn/axzo/workflow/common/constant/BpmnConstants.java index b42d74f64..6a769e539 100644 --- a/workflow-engine-common/src/main/java/cn/axzo/workflow/common/constant/BpmnConstants.java +++ b/workflow-engine-common/src/main/java/cn/axzo/workflow/common/constant/BpmnConstants.java @@ -24,6 +24,8 @@ public interface BpmnConstants { String INTERNAL_PROCESS_TYPE_REJECT = "[_INTERNAL_PROCESS_TYPE_REJECT_]"; String INTERNAL_PROCESS_TYPE_ABORT = "[_INTERNAL_PROCESS_TYPE_ABORT_]"; String INTERNAL_SPECIFY_NEXT_APPROVER = "[_INTERNAL_SPECIFY_NEXT_APPROVER_]"; + // 取消/驳回/终止时,记录原因 + String INTERNAL_PROCESS_DELETE_REASON = "[_INTERNAL_PROCESS_DELETE_REASON_]"; String BIZ_ORG_RELATION = "[_BIZ_ORG_RELATION_]"; String PENDING_TEMPLATE_VARIABLE = "[_PENDING_VARIABLES]"; String INTERNAL_PROCESS_AGENT = "[_INTERNAL_PROCESS_AGENT]"; diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomAbortProcessInstanceCmd.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomAbortProcessInstanceCmd.java index fd10803d1..ab2bbf5f6 100644 --- a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomAbortProcessInstanceCmd.java +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomAbortProcessInstanceCmd.java @@ -25,6 +25,7 @@ import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_DELETE_PRO import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_TENANT_ID; import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_USER_ID; import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_USER_NAME; +import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_PROCESS_DELETE_REASON; import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_PROCESS_TYPE_ABORT; import static cn.axzo.workflow.common.constant.BpmnConstants.TASK_ASSIGNEE_SKIP_FLAT; import static cn.axzo.workflow.common.constant.BpmnConstants.TASK_COMPLETE_OPERATION_TYPE; @@ -86,11 +87,12 @@ public class CustomAbortProcessInstanceCmd implements Command, Serializabl variables.put(INTERNAL_END_USER_ID, "system"); variables.put(INTERNAL_END_USER_NAME, "系统"); variables.put(INTERNAL_DELETE_PROCESS_FLAG, INTERNAL_PROCESS_TYPE_ABORT); + variables.put(INTERNAL_PROCESS_DELETE_REASON, reason); RuntimeService runtimeService = processEngineConfiguration.getRuntimeService(); runtimeService.setVariables(instance.getId(), variables); CommandContextUtil.getAgenda(commandContext).planOperation(new DeleteProcessInstanceOperation(commandContext, - processInstanceId, extAxHiTaskInstService, reason)); + processInstanceId, extAxHiTaskInstService)); // 添加自定义的节点,用于展示最后的操作 Task task = createVirtualTask(commandContext, extAxHiTaskInstService, processInstanceId, diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCancelProcessInstanceCmd.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCancelProcessInstanceCmd.java index a046375e8..3d1803ea2 100644 --- a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCancelProcessInstanceCmd.java +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomCancelProcessInstanceCmd.java @@ -22,6 +22,7 @@ import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_DELETE_PRO import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_TENANT_ID; import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_USER_ID; import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_USER_NAME; +import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_PROCESS_DELETE_REASON; import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_PROCESS_TYPE_CANCEL; import static cn.axzo.workflow.common.enums.BpmnFlowNodeType.NODE_CANCEL; import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.ABORTED; @@ -86,11 +87,12 @@ public class CustomCancelProcessInstanceCmd implements Command, Serializab variables.put(INTERNAL_END_USER_ID, initiator.buildAssigneeId()); variables.put(INTERNAL_END_USER_NAME, initiator.getAssignerName()); variables.put(INTERNAL_DELETE_PROCESS_FLAG, INTERNAL_PROCESS_TYPE_CANCEL); + variables.put(INTERNAL_PROCESS_DELETE_REASON, reason); RuntimeService runtimeService = processEngineConfiguration.getRuntimeService(); runtimeService.setVariables(instance.getId(), variables); CommandContextUtil.getAgenda(commandContext).planOperation(new DeleteProcessInstanceOperation(commandContext, - processInstanceId, extAxHiTaskInstService, reason)); + processInstanceId, extAxHiTaskInstService)); // 添加自定义的节点,用于展示最后的操作 Task task = createVirtualTask(commandContext, extAxHiTaskInstService, processInstanceId, diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomRejectionTaskCmd.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomRejectionTaskCmd.java index 0875138ac..5c41e6a83 100644 --- a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomRejectionTaskCmd.java +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/cmd/CustomRejectionTaskCmd.java @@ -25,6 +25,7 @@ import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_DELETE_PRO import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_TENANT_ID; import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_USER_ID; import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_END_USER_NAME; +import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_PROCESS_DELETE_REASON; 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; @@ -89,9 +90,10 @@ public class CustomRejectionTaskCmd implements Command, Serializable { variables.put(INTERNAL_END_USER_NAME, approver.getAssignerName()); variables.put(INTERNAL_END_USER_ID, approver.buildAssigneeId()); variables.put(INTERNAL_DELETE_PROCESS_FLAG, INTERNAL_PROCESS_TYPE_REJECT); + variables.put(INTERNAL_PROCESS_DELETE_REASON, reason); runtimeService.setVariables(task.getProcessInstanceId(), variables); CommandContextUtil.getAgenda(commandContext) .planOperation(new DeleteProcessInstanceOperation(commandContext, task.getProcessInstanceId(), - extAxHiTaskInstService, reason)); + extAxHiTaskInstService)); } } diff --git a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/operation/DeleteProcessInstanceOperation.java b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/operation/DeleteProcessInstanceOperation.java index 7520eb490..5f33c07c7 100644 --- a/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/operation/DeleteProcessInstanceOperation.java +++ b/workflow-engine-core/src/main/java/cn/axzo/workflow/core/engine/operation/DeleteProcessInstanceOperation.java @@ -25,14 +25,12 @@ import static cn.axzo.workflow.common.constant.BpmnConstants.HIDDEN_ASSIGNEE_ID; public class DeleteProcessInstanceOperation extends AbstractOperation { private final String processInstanceId; private final ExtAxHiTaskInstService extAxHiTaskInstService; - private final String reason; public DeleteProcessInstanceOperation(CommandContext commandContext, String processInstanceId, - ExtAxHiTaskInstService extAxHiTaskInstService, String reason) { + ExtAxHiTaskInstService extAxHiTaskInstService) { super(commandContext, null); this.processInstanceId = processInstanceId; this.extAxHiTaskInstService = extAxHiTaskInstService; - this.reason = reason; } @Override @@ -56,8 +54,8 @@ public class DeleteProcessInstanceOperation extends AbstractOperation { } RuntimeService runtimeService = processEngineConfiguration.getRuntimeService(); - // runtimeService.deleteProcessInstance(processInstanceId, HIDDEN_ASSIGNEE_ID); + runtimeService.deleteProcessInstance(processInstanceId, HIDDEN_ASSIGNEE_ID); // 将结束流程实例的原因记录下来 - runtimeService.deleteProcessInstance(processInstanceId, reason); +// runtimeService.deleteProcessInstance(processInstanceId, reason); } } diff --git a/workflow-engine-server/src/main/java/cn/axzo/workflow/server/controller/listener/process/RocketMqBpmnProcessEventListener.java b/workflow-engine-server/src/main/java/cn/axzo/workflow/server/controller/listener/process/RocketMqBpmnProcessEventListener.java index cd4d622d1..0826055f3 100644 --- a/workflow-engine-server/src/main/java/cn/axzo/workflow/server/controller/listener/process/RocketMqBpmnProcessEventListener.java +++ b/workflow-engine-server/src/main/java/cn/axzo/workflow/server/controller/listener/process/RocketMqBpmnProcessEventListener.java @@ -26,6 +26,7 @@ import java.util.Objects; import static cn.axzo.workflow.common.constant.BpmnConstants.FLOW_SERVER_VERSION_121; import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_INITIATOR; +import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_PROCESS_DELETE_REASON; import static cn.axzo.workflow.common.constant.BpmnConstants.WORKFLOW_ENGINE_VERSION; import static cn.axzo.workflow.common.enums.ProcessInstanceEventEnum.PROCESS_INSTANCE_ABORTED; import static cn.axzo.workflow.common.enums.ProcessInstanceEventEnum.PROCESS_INSTANCE_CANCELLED; @@ -149,14 +150,10 @@ public class RocketMqBpmnProcessEventListener implements BpmnProcessEventListene .setStartTime(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getStartTime()) .setTenantId(((FlowableProcessCancelledEventImpl) event).getExecution().getTenantId()) .setBusinessKey(((FlowableProcessCancelledEventImpl) event).getExecution().getProcessInstanceBusinessKey()) - .setBusinessProcessInstanceName(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getName()) - .setReason(String.valueOf(event.getCause())); + .setBusinessProcessInstanceName(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getName()); BpmnMetaParserHelper.getNoticeConfig(mainProcess).ifPresent(dto::setNoticeConf); - String version = (String) runtimeService.getVariable(event.getProcessInstanceId(), WORKFLOW_ENGINE_VERSION); - if (Objects.isNull(version)) { - version = FLOW_SERVER_VERSION_121; - } - dto.setWorkflowEngineVersion(version); + setProcessDeleteReason(event, dto); + setWorkflowEngineVersion(event, dto); sendMessageQueue(dto, PROCESS_INSTANCE_CANCELLED); if (log.isDebugEnabled()) { log.debug("MessagePushProcessEventListener#onCancelled...end: {}", event.getProcessInstanceId()); @@ -190,14 +187,10 @@ public class RocketMqBpmnProcessEventListener implements BpmnProcessEventListene .setStartTime(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getStartTime()) .setTenantId(((FlowableProcessCancelledEventImpl) event).getExecution().getTenantId()) .setBusinessKey(((FlowableProcessCancelledEventImpl) event).getExecution().getProcessInstanceBusinessKey()) - .setBusinessProcessInstanceName(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getName()) - .setReason(String.valueOf(event.getCause())); + .setBusinessProcessInstanceName(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getName()); BpmnMetaParserHelper.getNoticeConfig(mainProcess).ifPresent(dto::setNoticeConf); - String version = (String) runtimeService.getVariable(event.getProcessInstanceId(), WORKFLOW_ENGINE_VERSION); - if (Objects.isNull(version)) { - version = FLOW_SERVER_VERSION_121; - } - dto.setWorkflowEngineVersion(version); + setProcessDeleteReason(event, dto); + setWorkflowEngineVersion(event, dto); sendMessageQueue(dto, PROCESS_INSTANCE_REJECTED); if (log.isDebugEnabled()) { log.debug("MessagePushProcessEventListener#onRejected...end: {}", event.getProcessInstanceId()); @@ -226,18 +219,27 @@ public class RocketMqBpmnProcessEventListener implements BpmnProcessEventListene .setStartTime(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getStartTime()) .setTenantId(((FlowableProcessCancelledEventImpl) event).getExecution().getTenantId()) .setBusinessKey(((FlowableProcessCancelledEventImpl) event).getExecution().getProcessInstanceBusinessKey()) - .setBusinessProcessInstanceName(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getName()) - .setReason(String.valueOf(event.getCause())); + .setBusinessProcessInstanceName(((ExecutionEntityImpl) ((FlowableProcessCancelledEventImpl) event).getExecution()).getName()); BpmnMetaParserHelper.getNoticeConfig(mainProcess).ifPresent(dto::setNoticeConf); + setProcessDeleteReason(event, dto); + setWorkflowEngineVersion(event, dto); + sendMessageQueue(dto, PROCESS_INSTANCE_ABORTED); + if (log.isDebugEnabled()) { + log.debug("MessagePushProcessEventListener#onAborted...end: {}", event.getProcessInstanceId()); + } + } + + private void setProcessDeleteReason(FlowableCancelledEvent event, ProcessInstanceDTO dto) { + String processDeleteReason = (String) runtimeService.getVariable(event.getProcessInstanceId(), INTERNAL_PROCESS_DELETE_REASON); + dto.setReason(processDeleteReason); + } + + private void setWorkflowEngineVersion(FlowableCancelledEvent event, ProcessInstanceDTO dto) { String version = (String) runtimeService.getVariable(event.getProcessInstanceId(), WORKFLOW_ENGINE_VERSION); if (Objects.isNull(version)) { version = FLOW_SERVER_VERSION_121; } dto.setWorkflowEngineVersion(version); - sendMessageQueue(dto, PROCESS_INSTANCE_ABORTED); - if (log.isDebugEnabled()) { - log.debug("MessagePushProcessEventListener#onAborted...end: {}", event.getProcessInstanceId()); - } } @Override