| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.HashMap; |
| | |
| | | if (handlers != null) { |
| | | for (DeviceLogicHandler handler : handlers) { |
| | | String deviceType = handler.getDeviceType(); |
| | | if (deviceType != null && !deviceType.isEmpty()) { |
| | | handlerMap.put(deviceType, handler); |
| | | if (StringUtils.hasText(deviceType)) { |
| | | String normalized = normalizeDeviceType(deviceType); |
| | | handlerMap.put(normalized, handler); |
| | | if (!normalized.equals(deviceType)) { |
| | | handlerMap.put(deviceType, handler); |
| | | } |
| | | log.info("注册设备逻辑处理器: {} -> {}", deviceType, handler.getClass().getSimpleName()); |
| | | } |
| | | } |
| | |
| | | * @return 设备逻辑处理器,如果未找到返回null |
| | | */ |
| | | public DeviceLogicHandler getHandler(String deviceType) { |
| | | if (deviceType == null || deviceType.isEmpty()) { |
| | | if (!StringUtils.hasText(deviceType)) { |
| | | return null; |
| | | } |
| | | return handlerMap.get(deviceType); |
| | | DeviceLogicHandler handler = handlerMap.get(deviceType); |
| | | if (handler != null) { |
| | | return handler; |
| | | } |
| | | String normalized = normalizeDeviceType(deviceType); |
| | | if (!normalized.equals(deviceType)) { |
| | | handler = handlerMap.get(normalized); |
| | | } |
| | | return handler; |
| | | } |
| | | |
| | | /** |
| | |
| | | public java.util.Set<String> getSupportedDeviceTypes() { |
| | | return handlerMap.keySet(); |
| | | } |
| | | |
| | | private String normalizeDeviceType(String deviceType) { |
| | | if (!StringUtils.hasText(deviceType)) { |
| | | return deviceType; |
| | | } |
| | | String trimmed = deviceType.trim(); |
| | | if (trimmed.endsWith("设备")) { |
| | | return trimmed.substring(0, trimmed.length() - 2); |
| | | } |
| | | return trimmed; |
| | | } |
| | | } |
| | | |