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:
反编译工作区
2026-04-24 23:45:30 +08:00
parent b30ea1f70c
commit b6e8442479
8 changed files with 48 additions and 20 deletions
@@ -175,7 +175,8 @@ public class CloudwalkEventInitializing implements CommandLineRunner {
private EventType getEventType(Class<? extends BaseEvent> eventClass) { private EventType getEventType(Class<? extends BaseEvent> eventClass) {
for (EventType eventType : EventType.values()) { for (EventType eventType : EventType.values()) {
if (eventType.getEventClass().getClass().equals(eventClass)) { BaseEvent prototype = eventType.getEventClass();
if (prototype != null && prototype.getClass().equals(eventClass)) {
return eventType; return eventType;
} }
} }
@@ -10,7 +10,9 @@ import cn.cloudwalk.event.handler.EventHandlerWorker;
import cn.cloudwalk.event.listener.GroupEventListener; import cn.cloudwalk.event.listener.GroupEventListener;
import cn.cloudwalk.event.listener.GroupListnerClassMapping; import cn.cloudwalk.event.listener.GroupListnerClassMapping;
import cn.cloudwalk.event.task.EventHandleTask; import cn.cloudwalk.event.task.EventHandleTask;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@@ -29,14 +31,24 @@ public class CloudwalkEventManager {
public void handle(Class<? extends GroupEventListener> eventListnerClass, BaseEvent baseEvent) { public void handle(Class<? extends GroupEventListener> eventListnerClass, BaseEvent baseEvent) {
String groupId = this.groupListnerClassMapping.getGroupId(eventListnerClass); String groupId = this.groupListnerClassMapping.getGroupId(eventListnerClass);
if (baseEvent instanceof CustomEvent) { if (baseEvent instanceof CustomEvent) {
List<CustomEventHandler> customEventHandlers = (List<CustomEventHandler>)this.eventHandlerMapping Map<String, List<CustomEventHandler>> customByServiceCode =
.getServiceCodeCustomHandlerListMap(groupId, ((CustomEvent)baseEvent).getTopic()) this.eventHandlerMapping.getServiceCodeCustomHandlerListMap(groupId,
.get(baseEvent.getServiceCode()); ((CustomEvent)baseEvent).getTopic());
if (customByServiceCode == null) {
customByServiceCode = Collections.emptyMap();
}
List<CustomEventHandler> customEventHandlers =
(List<CustomEventHandler>)customByServiceCode.get(baseEvent.getServiceCode());
eventHandle(baseEvent, customEventHandlers); eventHandle(baseEvent, customEventHandlers);
return; return;
} }
List<EventHandler> handlerList = (List<EventHandler>)this.eventHandlerMapping Map<String, List<EventHandler>> handlerByServiceCode =
.getServiceCodeHandlerListMap(groupId, baseEvent.getClass()).get(baseEvent.getServiceCode()); this.eventHandlerMapping.getServiceCodeHandlerListMap(groupId, baseEvent.getClass());
if (handlerByServiceCode == null) {
handlerByServiceCode = Collections.emptyMap();
}
List<EventHandler> handlerList =
(List<EventHandler>)handlerByServiceCode.get(baseEvent.getServiceCode());
eventHandle(baseEvent, handlerList); eventHandle(baseEvent, handlerList);
} }
@@ -4,10 +4,12 @@ import cn.cloudwalk.event.CloudwalkEventInitializing;
import cn.cloudwalk.event.CloudwalkEventManager; import cn.cloudwalk.event.CloudwalkEventManager;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/** /**
* 事件模块 Spring 配置:注册 {@link cn.cloudwalk.event.CloudwalkEventManager} 与初始化组件。 * 事件模块 Spring 配置:注册 {@link cn.cloudwalk.event.CloudwalkEventManager} 与初始化组件。
*/ */
@Configuration
@EnableConfigurationProperties({EventProperties.class}) @EnableConfigurationProperties({EventProperties.class})
public class EventConfiguration { public class EventConfiguration {
@Bean @Bean
@@ -16,7 +18,7 @@ public class EventConfiguration {
} }
@Bean @Bean
public CloudwalkEventInitializing CloudwalkEventInitializing(EventProperties eventProperties) { public CloudwalkEventInitializing cloudwalkEventInitializing(EventProperties eventProperties) {
return new CloudwalkEventInitializing(eventProperties); return new CloudwalkEventInitializing(eventProperties);
} }
} }
@@ -26,7 +26,8 @@ public class EventHandlerMapping {
public Map<String, List<EventHandler>> getServiceCodeHandlerListMap(String groupId, public Map<String, List<EventHandler>> getServiceCodeHandlerListMap(String groupId,
Class<? extends BaseEvent> eventClass) { Class<? extends BaseEvent> eventClass) {
for (EventType eventType : EventType.values()) { 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); return getServiceCodeHandlerListMap(groupId, eventType);
} }
} }
@@ -298,7 +298,7 @@ public class PersonRuleServiceImpl extends AbstractAcsPassService implements Per
public CloudwalkResult<Boolean> edit(AcsPersonEditParam param, CloudwalkCallContext context) public CloudwalkResult<Boolean> edit(AcsPersonEditParam param, CloudwalkCallContext context)
throws ServiceException { throws ServiceException {
return null; return CloudwalkResult.fail("76260998", "人员规则编辑接口未实现");
} }
public CloudwalkResult<Boolean> delete(AcsPersonDeleteParam param, CloudwalkCallContext context) public CloudwalkResult<Boolean> delete(AcsPersonDeleteParam param, CloudwalkCallContext context)
@@ -447,12 +447,12 @@ public class PersonRuleServiceImpl extends AbstractAcsPassService implements Per
public CloudwalkResult<AcsPersonTimeDetailResult> timeDetail(AcsPersonTimeDetailParam param, public CloudwalkResult<AcsPersonTimeDetailResult> timeDetail(AcsPersonTimeDetailParam param,
CloudwalkCallContext context) throws ServiceException { CloudwalkCallContext context) throws ServiceException {
return null; return CloudwalkResult.fail("76260998", "人员时段详情接口未实现");
} }
public CloudwalkResult<CloudwalkPageAble<AcsPersonResult>> pageByApp(AcsPersonQueryByAppParam param, public CloudwalkResult<CloudwalkPageAble<AcsPersonResult>> pageByApp(AcsPersonQueryByAppParam param,
CloudwalkPageInfo pageInfo, CloudwalkCallContext context) throws ServiceException { CloudwalkPageInfo pageInfo, CloudwalkCallContext context) throws ServiceException {
return null; return CloudwalkResult.fail("76260998", "应用端人员分页接口未实现");
} }
public CloudwalkResult<CloudwalkPageAble<ImageStorePersonResult>> personDetail(PersonDetailQueryParam param, public CloudwalkResult<CloudwalkPageAble<ImageStorePersonResult>> personDetail(PersonDetailQueryParam param,
@@ -13,9 +13,10 @@ import cn.cloudwalk.cloud.result.CloudwalkResult;
import cn.cloudwalk.rest.cwoscomponent.intelligent.device.config.DeviceCategoryProperties; import cn.cloudwalk.rest.cwoscomponent.intelligent.device.config.DeviceCategoryProperties;
import cn.cloudwalk.rest.cwoscomponent.intelligent.device.feign.DeviceFeignClient; import cn.cloudwalk.rest.cwoscomponent.intelligent.device.feign.DeviceFeignClient;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -40,7 +41,8 @@ public class RestDeviceServiceImpl implements DeviceService {
public CloudwalkResult<List<DeviceResult>> filterList(Integer deviceType, DeviceQueryParam param, public CloudwalkResult<List<DeviceResult>> filterList(Integer deviceType, DeviceQueryParam param,
CloudwalkCallContext context) throws ServiceException { CloudwalkCallContext context) throws ServiceException {
if (StringUtils.isEmpty(param.getDeviceTypeCode()) && CollectionUtils.isEmpty(param.getDeviceTypeCodes())) { if (deviceType != null && StringUtils.isEmpty(param.getDeviceTypeCode())
&& CollectionUtils.isEmpty(param.getDeviceTypeCodes())) {
if (deviceType.intValue() == 1) { if (deviceType.intValue() == 1) {
List<String> deviceCategoryIds = this.deviceCategoryProperties.getDeviceCategoryArray(); List<String> deviceCategoryIds = this.deviceCategoryProperties.getDeviceCategoryArray();
if (!CollectionUtils.isEmpty(deviceCategoryIds)) { if (!CollectionUtils.isEmpty(deviceCategoryIds)) {
@@ -58,15 +60,25 @@ public class RestDeviceServiceImpl implements DeviceService {
public List<String> getDeviceTypeCodes(List<String> deviceCategoryIds) throws ServiceException { public List<String> getDeviceTypeCodes(List<String> deviceCategoryIds) throws ServiceException {
CloudwalkResult<List<DeviceTypeResult>> deviceTypeResultList = this.deviceTypeService.getCacheAble(); CloudwalkResult<List<DeviceTypeResult>> deviceTypeResultList = this.deviceTypeService.getCacheAble();
Map<String, DeviceTypeResult> deviceTypeResultMap = if (deviceTypeResultList == null || deviceTypeResultList.getData() == null) {
(Map<String, DeviceTypeResult>)((List)deviceTypeResultList.getData()).stream() return Collections.emptyList();
.collect(Collectors.toMap(DeviceTypeResult::getId, d -> d)); }
List<DeviceTypeResult> dataList = deviceTypeResultList.getData();
Map<String, DeviceTypeResult> deviceTypeResultMap = dataList.stream().filter(Objects::nonNull)
.collect(Collectors.toMap(DeviceTypeResult::getId, d -> d, (a, b) -> a));
List<String> deviceTypeCodes = new ArrayList<>(); List<String> deviceTypeCodes = new ArrayList<>();
for (String deviceCategoryId : deviceCategoryIds) { for (String deviceCategoryId : deviceCategoryIds) {
DeviceTypeResult deviceTypeResult = deviceTypeResultMap.get(deviceCategoryId); DeviceTypeResult deviceTypeResult = deviceTypeResultMap.get(deviceCategoryId);
if (deviceTypeResult == null) {
continue;
}
List<DeviceTypeResult.DeviceTypeDetailResult> children = deviceTypeResult.getChildren(); List<DeviceTypeResult.DeviceTypeDetailResult> children = deviceTypeResult.getChildren();
deviceTypeCodes.addAll((Collection<? extends String>)children.stream() if (CollectionUtils.isEmpty(children)) {
.map(DeviceTypeResult.DeviceTypeDetailResult::getDeviceTypeCode).collect(Collectors.toList())); continue;
}
deviceTypeCodes.addAll(children.stream().filter(Objects::nonNull)
.map(DeviceTypeResult.DeviceTypeDetailResult::getDeviceTypeCode).filter(Objects::nonNull)
.collect(Collectors.toList()));
} }
return deviceTypeCodes; return deviceTypeCodes;
} }
@@ -12,7 +12,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClas
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@ConditionalOnMissingClass({"cn.cloudwalk.service.cwoscomponent.intelligent.record.service.AcsRecordServiceImpl"}) @ConditionalOnMissingClass({"cn.cloudwalk.service.cwoscomponent.intelligent.record.service.AcsRecordThreeSendServiceImpl"})
public class AcsRecordThreeSendServiceImpl implements AcsRecordThreeSendService { public class AcsRecordThreeSendServiceImpl implements AcsRecordThreeSendService {
@Autowired @Autowired
private AcsRecordThreeSendFeignClient acsRecordThreeSendFeignClient; private AcsRecordThreeSendFeignClient acsRecordThreeSendFeignClient;
@@ -12,7 +12,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClas
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
@ConditionalOnMissingClass({"cn.cloudwalk.service.cwoscomponent.intelligent.resource.service.SysettingAreaServiceImpl"}) @ConditionalOnMissingClass({"cn.cloudwalk.service.cwoscomponent.intelligent.sysetting.service.SysettingAreaServiceImpl"})
public class RestSysettingAreaServiceImpl implements SysettingAreaService { public class RestSysettingAreaServiceImpl implements SysettingAreaService {
@Autowired @Autowired
private SysettingAreaFeignClient sysettingAreaFeignClient; private SysettingAreaFeignClient sysettingAreaFeignClient;