From ab389a5a6b329b15a655340ba7b87bce7fd7871d Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期三, 24 十二月 2025 17:16:19 +0800
Subject: [PATCH] 添加新增设备自动生成编码

---
 mes-processes/mes-plcSend/src/main/java/com/mes/interaction/DeviceLogicHandlerFactory.java |   35 ++++++++++++++++++++++++++++++-----
 1 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/interaction/DeviceLogicHandlerFactory.java b/mes-processes/mes-plcSend/src/main/java/com/mes/interaction/DeviceLogicHandlerFactory.java
index f5eb175..855a640 100644
--- a/mes-processes/mes-plcSend/src/main/java/com/mes/interaction/DeviceLogicHandlerFactory.java
+++ b/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 璁惧閫昏緫澶勭悊鍣紝濡傛灉鏈壘鍒拌繑鍥瀗ull
      */
     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;
+    }
 }
 

--
Gitblit v1.8.0