huang
2 天以前 ab389a5a6b329b15a655340ba7b87bce7fd7871d
mes-processes/mes-plcSend/src/main/java/com/mes/interaction/DeviceLogicHandlerFactory.java
@@ -3,11 +3,13 @@
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;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
 * 设备逻辑处理器工厂类
@@ -33,8 +35,12 @@
        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());
                }
            }
@@ -49,10 +55,18 @@
     * @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;
    }
    /**
@@ -70,8 +84,19 @@
     * 
     * @return 设备类型集合
     */
    public java.util.Set<String> getSupportedDeviceTypes() {
    public 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;
    }
}