反序列化问题。

This commit is contained in:
dengqichen 2024-12-16 18:03:11 +08:00
parent 9c582f7e5b
commit e59b14c90c
4 changed files with 101 additions and 53 deletions

View File

@ -21,7 +21,7 @@ public class FlowableEventDispatcher implements FlowableEventListener {
@Override
public void onEvent(FlowableEvent event) {
String eventType = event.getType().name();
log.info("Dispatching Flowable event: {}, event class: {}", eventType, event.getClass().getName());
// log.info("Dispatching Flowable event: {}, event class: {}", eventType, event.getClass().getName());
for (IFlowableEventHandler handler : eventHandlers) {
if (handler.canHandle(eventType)) {

View File

@ -33,24 +33,24 @@ public class ProcessEventHandler implements IFlowableEventHandler {
@Override
public void handle(FlowableEvent event) {
String eventType = event.getType().name();
// log.info("Processing event: {}", eventType);
log.info("Processing event: {}", eventType);
FlowableProcessEngineEvent processEvent = (FlowableProcessEngineEvent) event;
WorkflowInstanceStatusEnums status = convertToWorkflowStatus(eventType);
if (status != null) {
// HistoricProcessInstance historicProcessInstance = processEngine.getHistoryService()
// .createHistoricProcessInstanceQuery()
// .processInstanceId(processEvent.getProcessInstanceId())
// .singleResult();
//
// publisher.publishEvent(WorkflowInstanceStatusChangeEvent.builder()
// .processInstanceId(processEvent.getProcessInstanceId())
// .status(status)
// .endTime(historicProcessInstance != null && historicProcessInstance.getEndTime() != null ?
// DateUtil.toLocalDateTime(historicProcessInstance.getEndTime()) : null)
// .build()
// );
HistoricProcessInstance historicProcessInstance = processEngine.getHistoryService()
.createHistoricProcessInstanceQuery()
.processInstanceId(processEvent.getProcessInstanceId())
.singleResult();
publisher.publishEvent(WorkflowInstanceStatusChangeEvent.builder()
.processInstanceId(processEvent.getProcessInstanceId())
.status(status)
.endTime(historicProcessInstance != null && historicProcessInstance.getEndTime() != null ?
DateUtil.toLocalDateTime(historicProcessInstance.getEndTime()) : null)
.build()
);
}
}
@ -63,6 +63,7 @@ public class ProcessEventHandler implements IFlowableEventHandler {
case "PROCESS_CANCELLED" -> WorkflowInstanceStatusEnums.TERMINATED;
case "PROCESS_SUSPENDED" -> WorkflowInstanceStatusEnums.SUSPENDED;
case "PROCESS_RESUMED" -> WorkflowInstanceStatusEnums.RUNNING;
case "PROCESS_COMPLETED_WITH_TERMINATE_END_EVENT" -> WorkflowInstanceStatusEnums.TERMINATED;
default -> null;
};
}

View File

@ -149,9 +149,37 @@ public class BpmnConverter {
serviceTask.setExtensionElements(extensionElements);
// 添加错误边界事件
addErrorBoundaryEventHandler(process, serviceTask);
}
}
/**
* 为服务任务添加错误边界事件和错误结束事件
* 当服务任务执行失败时会触发错误边界事件并流转到错误结束事件
*
* @param process BPMN流程定义
* @param serviceTask 需要添加错误处理的服务任务
*/
private void addErrorBoundaryEventHandler(Process process, ServiceTask serviceTask) {
BoundaryEvent boundaryEvent = createErrorBoundaryEvent(serviceTask);
EndEvent errorEndEvent = createErrorEndEvent(serviceTask);
SequenceFlow errorFlow = createErrorSequenceFlow(boundaryEvent, errorEndEvent);
// 将错误处理相关的元素添加到流程中
process.addFlowElement(boundaryEvent);
process.addFlowElement(errorEndEvent);
process.addFlowElement(errorFlow);
}
/**
* 创建错误边界事件
*
* @param serviceTask 关联的服务任务
* @return 配置好的错误边界事件
*/
private BoundaryEvent createErrorBoundaryEvent(ServiceTask serviceTask) {
BoundaryEvent boundaryEvent = new BoundaryEvent();
boundaryEvent.setId(WorkFlowConstants.BOUNDARY_EVENT_ERROR_PREFIX + serviceTask.getId());
// boundaryEvent.setName("错误边界事件");
boundaryEvent.setAttachedToRef(serviceTask);
boundaryEvent.setAttachedToRefId(serviceTask.getId());
boundaryEvent.setCancelActivity(true); // 确保取消原有活动
@ -161,26 +189,43 @@ public class BpmnConverter {
errorEventDefinition.setErrorCode(WorkFlowConstants.WORKFLOW_EXEC_ERROR);
boundaryEvent.addEventDefinition(errorEventDefinition);
// 添加错误结束事件
return boundaryEvent;
}
/**
* 创建错误结束事件
*
* @param serviceTask 关联的服务任务
* @return 配置好的错误结束事件
*/
private EndEvent createErrorEndEvent(ServiceTask serviceTask) {
EndEvent errorEndEvent = new EndEvent();
errorEndEvent.setId(WorkFlowConstants.END_EVENT_ERROR_PREFIX + serviceTask.getId());
// errorEndEvent.setName("错误结束事件");
// 添加终止定义
TerminateEventDefinition terminateEventDefinition = new TerminateEventDefinition();
errorEndEvent.addEventDefinition(terminateEventDefinition);
// TerminateEventDefinition terminateEventDefinition = new TerminateEventDefinition();
// errorEndEvent.addEventDefinition(terminateEventDefinition);
// 添加从边界事件到结束事件的连线
ErrorEventDefinition errorEventDefinition = new ErrorEventDefinition();
errorEventDefinition.setErrorCode(WorkFlowConstants.WORKFLOW_EXEC_ERROR);
errorEndEvent.addEventDefinition(errorEventDefinition);
return errorEndEvent;
}
/**
* 创建错误处理流程的连线
*
* @param boundaryEvent 错误边界事件
* @param errorEndEvent 错误结束事件
* @return 配置好的连线
*/
private SequenceFlow createErrorSequenceFlow(BoundaryEvent boundaryEvent, EndEvent errorEndEvent) {
SequenceFlow errorFlow = new SequenceFlow();
errorFlow.setId(WorkFlowConstants.SEQUENCE_FLOW_ERROR_PREFIX + serviceTask.getId());
// errorFlow.setName("错误处理流程");
errorFlow.setId(WorkFlowConstants.SEQUENCE_FLOW_ERROR_PREFIX + boundaryEvent.getAttachedToRefId());
errorFlow.setSourceRef(boundaryEvent.getId());
errorFlow.setTargetRef(errorEndEvent.getId());
// 将错误处理相关的元素添加到流程中
process.addFlowElement(boundaryEvent);
process.addFlowElement(errorEndEvent);
process.addFlowElement(errorFlow);
}
return errorFlow;
}
}

View File

@ -30,6 +30,15 @@ spring:
always-use-message-format: false
use-code-as-default-message: true
cache-duration: 3600
flyway:
enabled: true
baseline-on-migrate: true
locations: classpath:db/migration
table: flyway_schema_history
baseline-version: 0
validate-on-migrate: true
placeholderPrefix: "#{"
placeholderSuffix: "}"
flowable:
database-schema-update: true
# id-generator: org.flowable.common.engine.impl.db.DbIdGenerator
@ -62,10 +71,3 @@ jwt:
jackson:
time-zone: Asia/Shanghai
flyway:
enabled: true
baseline-on-migrate: true
locations: classpath:db/migration
table: flyway_schema_history
baseline-version: 0
validate-on-migrate: true