mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-10 00:40:30 +08:00
fix(v0.11): 走查项——事件模块空安全、条件类名、设备筛选与占位接口
- EventConfiguration 标注 @Configuration,Bean 方法改为 cloudwalkEventInitializing - CloudwalkEventManager 对 handler/custom 映射链式 get 做空映射兜底 - EventHandlerMapping / CloudwalkEventInitializing 中 EventType 原型判空 - Rest 层 @ConditionalOnMissingClass 指向正确的本地实现类全名 - RestDeviceServiceImpl:deviceType 与设备类型树数据的 NPE 防护 - PersonRuleServiceImpl:未实现方法返回 CloudwalkResult.fail 替代 null Made-with: Cursor
This commit is contained in:
+2
-1
@@ -175,7 +175,8 @@ public class CloudwalkEventInitializing implements CommandLineRunner {
|
||||
|
||||
private EventType getEventType(Class<? extends BaseEvent> eventClass) {
|
||||
for (EventType eventType : EventType.values()) {
|
||||
if (eventType.getEventClass().getClass().equals(eventClass)) {
|
||||
BaseEvent prototype = eventType.getEventClass();
|
||||
if (prototype != null && prototype.getClass().equals(eventClass)) {
|
||||
return eventType;
|
||||
}
|
||||
}
|
||||
|
||||
+17
-5
@@ -10,7 +10,9 @@ import cn.cloudwalk.event.handler.EventHandlerWorker;
|
||||
import cn.cloudwalk.event.listener.GroupEventListener;
|
||||
import cn.cloudwalk.event.listener.GroupListnerClassMapping;
|
||||
import cn.cloudwalk.event.task.EventHandleTask;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -29,14 +31,24 @@ public class CloudwalkEventManager {
|
||||
public void handle(Class<? extends GroupEventListener> eventListnerClass, BaseEvent baseEvent) {
|
||||
String groupId = this.groupListnerClassMapping.getGroupId(eventListnerClass);
|
||||
if (baseEvent instanceof CustomEvent) {
|
||||
List<CustomEventHandler> customEventHandlers = (List<CustomEventHandler>)this.eventHandlerMapping
|
||||
.getServiceCodeCustomHandlerListMap(groupId, ((CustomEvent)baseEvent).getTopic())
|
||||
.get(baseEvent.getServiceCode());
|
||||
Map<String, List<CustomEventHandler>> customByServiceCode =
|
||||
this.eventHandlerMapping.getServiceCodeCustomHandlerListMap(groupId,
|
||||
((CustomEvent)baseEvent).getTopic());
|
||||
if (customByServiceCode == null) {
|
||||
customByServiceCode = Collections.emptyMap();
|
||||
}
|
||||
List<CustomEventHandler> customEventHandlers =
|
||||
(List<CustomEventHandler>)customByServiceCode.get(baseEvent.getServiceCode());
|
||||
eventHandle(baseEvent, customEventHandlers);
|
||||
return;
|
||||
}
|
||||
List<EventHandler> handlerList = (List<EventHandler>)this.eventHandlerMapping
|
||||
.getServiceCodeHandlerListMap(groupId, baseEvent.getClass()).get(baseEvent.getServiceCode());
|
||||
Map<String, List<EventHandler>> handlerByServiceCode =
|
||||
this.eventHandlerMapping.getServiceCodeHandlerListMap(groupId, baseEvent.getClass());
|
||||
if (handlerByServiceCode == null) {
|
||||
handlerByServiceCode = Collections.emptyMap();
|
||||
}
|
||||
List<EventHandler> handlerList =
|
||||
(List<EventHandler>)handlerByServiceCode.get(baseEvent.getServiceCode());
|
||||
eventHandle(baseEvent, handlerList);
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -4,10 +4,12 @@ import cn.cloudwalk.event.CloudwalkEventInitializing;
|
||||
import cn.cloudwalk.event.CloudwalkEventManager;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 事件模块 Spring 配置:注册 {@link cn.cloudwalk.event.CloudwalkEventManager} 与初始化组件。
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({EventProperties.class})
|
||||
public class EventConfiguration {
|
||||
@Bean
|
||||
@@ -16,7 +18,7 @@ public class EventConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CloudwalkEventInitializing CloudwalkEventInitializing(EventProperties eventProperties) {
|
||||
public CloudwalkEventInitializing cloudwalkEventInitializing(EventProperties eventProperties) {
|
||||
return new CloudwalkEventInitializing(eventProperties);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -26,7 +26,8 @@ public class EventHandlerMapping {
|
||||
public Map<String, List<EventHandler>> getServiceCodeHandlerListMap(String groupId,
|
||||
Class<? extends BaseEvent> eventClass) {
|
||||
for (EventType eventType : EventType.values()) {
|
||||
if (eventType.getEventClass().getClass().equals(eventClass)) {
|
||||
BaseEvent prototype = eventType.getEventClass();
|
||||
if (prototype != null && prototype.getClass().equals(eventClass)) {
|
||||
return getServiceCodeHandlerListMap(groupId, eventType);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user