From 0dfdc8148cc266fd3e877183c5b162fb986d5c65 Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期五, 12 十二月 2025 15:38:56 +0800
Subject: [PATCH] 修改导入工程json格式

---
 mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/DevicePlcOperationServiceImpl.java |   64 +++++++++++++++++++++----------
 1 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/DevicePlcOperationServiceImpl.java b/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/DevicePlcOperationServiceImpl.java
index c3c50d1..ebac164 100644
--- a/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/DevicePlcOperationServiceImpl.java
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/DevicePlcOperationServiceImpl.java
@@ -6,6 +6,7 @@
 import com.mes.device.service.DeviceConfigService;
 import com.mes.device.service.DeviceGroupRelationService;
 import com.mes.device.service.DevicePlcOperationService;
+import com.mes.device.util.ConfigJsonHelper;
 import com.mes.device.vo.DeviceGroupVO;
 import com.mes.device.vo.DevicePlcVO;
 import com.mes.service.PlcTestWriteService;
@@ -15,7 +16,6 @@
 import org.springframework.util.CollectionUtils;
 
 import java.time.LocalDateTime;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -39,6 +39,34 @@
     private final DeviceGroupRelationService deviceGroupRelationService;
     private final PlcTestWriteService plcTestWriteService;
     private final ObjectMapper objectMapper;
+
+    public static enum PlcOperationType {
+        /** PLC璇锋眰鎿嶄綔 */
+        REQUEST("PLC璇锋眰", "PLC 璇锋眰鍙戦�佹垚鍔�", "PLC 璇锋眰鍙戦�佸け璐�"),
+        /** PLC姹囨姤鎿嶄綔 */
+        REPORT("PLC姹囨姤", "PLC 姹囨姤妯℃嫙鎴愬姛", "PLC 姹囨姤妯℃嫙澶辫触"),
+        /** PLC閲嶇疆鎿嶄綔 */
+        RESET("PLC閲嶇疆", "PLC 鐘舵�佸凡閲嶇疆", "PLC 鐘舵�侀噸缃け璐�");
+
+        /** 鎿嶄綔鏄剧ず鍚嶇О */
+        private final String display;
+        /** 鎿嶄綔鎴愬姛鎻愮ず淇℃伅 */
+        private final String successMsg;
+        /** 鎿嶄綔澶辫触鎻愮ず淇℃伅 */
+        private final String failedMsg;
+
+        /**
+         * 鏋勯�犳柟娉�
+         * @param display 鎿嶄綔鏄剧ず鍚嶇О
+         * @param successMsg 鎴愬姛鎻愮ず淇℃伅
+         * @param failedMsg 澶辫触鎻愮ず淇℃伅
+         */
+        PlcOperationType(String display, String successMsg, String failedMsg) {
+            this.display = display;
+            this.successMsg = successMsg;
+            this.failedMsg = failedMsg;
+        }
+    }
 
     @Override
     public DevicePlcVO.OperationResult triggerRequest(Long deviceId) {
@@ -87,7 +115,7 @@
             return DevicePlcVO.StatusInfo.builder()
                     .deviceId(deviceId)
                     .deviceName("鏈煡璁惧")
-                    .data(Collections.emptyMap())
+                    .fieldValues(Collections.emptyMap())
                     .timestamp(LocalDateTime.now())
                     .build();
         }
@@ -99,7 +127,7 @@
                     .deviceName(device.getDeviceName())
                     .deviceCode(device.getDeviceCode())
                     .projectId(String.valueOf(device.getProjectId()))
-                    .data(data)
+                    .fieldValues(data)
                     .timestamp(LocalDateTime.now())
                     .build();
         } catch (Exception e) {
@@ -109,7 +137,7 @@
                     .deviceName(device.getDeviceName())
                     .deviceCode(device.getDeviceCode())
                     .projectId(null)
-                    .data(Collections.emptyMap())
+                    .fieldValues(Collections.emptyMap())
                     .timestamp(LocalDateTime.now())
                     .build();
         }
@@ -247,13 +275,21 @@
             throw new IllegalArgumentException("璁惧淇℃伅涓虹┖");
         }
 
+        // 浼樺厛浠巆onfigJson涓幏鍙�
+        Map<String, Object> configParams = ConfigJsonHelper.parseToMap(device.getConfigJson(), objectMapper);
+        Object plcProjectId = configParams.get(PLC_PROJECT_ID_KEY);
+        if (plcProjectId != null) {
+            return String.valueOf(plcProjectId);
+        }
+
+        // 鍏舵浠庢墿灞曞弬鏁颁腑鑾峰彇锛堝吋瀹规棫閰嶇疆锛�
         String extra = device.getExtraParams();
         if (extra != null && !extra.isEmpty()) {
             try {
                 Map<String, Object> extraParams = objectMapper.readValue(extra, new TypeReference<Map<String, Object>>() {});
-                Object plcProjectId = extraParams.get(PLC_PROJECT_ID_KEY);
-                if (plcProjectId != null) {
-                    return String.valueOf(plcProjectId);
+                Object plcProjectIdFromExtra = extraParams.get(PLC_PROJECT_ID_KEY);
+                if (plcProjectIdFromExtra != null) {
+                    return String.valueOf(plcProjectIdFromExtra);
                 }
             } catch (Exception e) {
                 log.warn("瑙f瀽璁惧鎵╁睍鍙傛暟澶辫触, deviceId={}", device.getId(), e);
@@ -271,20 +307,6 @@
         throw new IllegalStateException("鏃犳硶瑙f瀽璁惧鐨� PLC 椤圭洰鏍囪瘑, deviceId=" + device.getId());
     }
 
-    private enum PlcOperationType {
-        REQUEST("PLC璇锋眰", "PLC 璇锋眰鍙戦�佹垚鍔�", "PLC 璇锋眰鍙戦�佸け璐�"),
-        REPORT("PLC姹囨姤", "PLC 姹囨姤妯℃嫙鎴愬姛", "PLC 姹囨姤妯℃嫙澶辫触"),
-        RESET("PLC閲嶇疆", "PLC 鐘舵�佸凡閲嶇疆", "PLC 鐘舵�侀噸缃け璐�");
 
-        private final String display;
-        private final String successMsg;
-        private final String failedMsg;
-
-        PlcOperationType(String display, String successMsg, String failedMsg) {
-            this.display = display;
-            this.successMsg = successMsg;
-            this.failedMsg = failedMsg;
-        }
-    }
 }
 

--
Gitblit v1.8.0