From eabb757720375b74900027e23e50303b7e02ca36 Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期二, 09 十二月 2025 17:04:23 +0800
Subject: [PATCH] 添加nacos配置中心,可动态更新mes导入工程接口;修改Excel表数据转json格式

---
 mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/DeviceGroupController.java |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/DeviceGroupController.java b/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/DeviceGroupController.java
index 37ea229..fc0bc8e 100644
--- a/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/DeviceGroupController.java
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/DeviceGroupController.java
@@ -1,6 +1,7 @@
 package com.mes.device.controller;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.mes.device.entity.DeviceGroupConfig;
 import com.mes.device.request.DeviceGroupRequest;
 import com.mes.device.service.DeviceGroupConfigService;
@@ -37,6 +38,9 @@
 
     @Autowired
     private DeviceGroupRelationService deviceGroupRelationService;
+    
+    @Resource
+    private ObjectMapper objectMapper;
 
     /**
      * 鍒涘缓璁惧缁�
@@ -46,18 +50,21 @@
     public Result<DeviceGroupConfig> createGroup(
             @Valid @RequestBody DeviceGroupRequest request) {
         try {
-            DeviceGroupConfig groupConfig = (DeviceGroupConfig) request.getGroupConfig();
+            DeviceGroupConfig groupConfig = convertToDeviceGroupConfig(request.getGroupConfig());
+            if (groupConfig == null) {
+                return Result.error("璁惧缁勯厤缃俊鎭笉鑳戒负绌�");
+            }
             boolean success = deviceGroupConfigService.createDeviceGroup(groupConfig);
             if (success) {
                 // 鍒涘缓鎴愬姛鍚庯紝閲嶆柊鑾峰彇璁惧缁勫璞�
                 DeviceGroupConfig created = deviceGroupConfigService.getDeviceGroupByCode(groupConfig.getGroupCode());
                 return Result.success(created);
             } else {
-                return Result.error();
+                return Result.error("鍒涘缓璁惧缁勫け璐�");
             }
         } catch (Exception e) {
             log.error("鍒涘缓璁惧缁勫け璐�", e);
-            return Result.error();
+            return Result.error("鍒涘缓璁惧缁勫け璐�: " + e.getMessage());
         }
     }
 
@@ -69,7 +76,13 @@
     public Result<DeviceGroupConfig> updateGroup(
             @Valid @RequestBody DeviceGroupRequest request) {
         try {
-            DeviceGroupConfig groupConfig = (DeviceGroupConfig) request.getGroupConfig();
+            if (request.getGroupId() == null) {
+                return Result.error("璁惧缁処D涓嶈兘涓虹┖");
+            }
+            DeviceGroupConfig groupConfig = convertToDeviceGroupConfig(request.getGroupConfig());
+            if (groupConfig == null) {
+                return Result.error("璁惧缁勯厤缃俊鎭笉鑳戒负绌�");
+            }
             groupConfig.setId(request.getGroupId());
             boolean success = deviceGroupConfigService.updateDeviceGroup(groupConfig);
             if (success) {
@@ -77,11 +90,11 @@
                 DeviceGroupConfig updated = deviceGroupConfigService.getDeviceGroupByCode(groupConfig.getGroupCode());
                 return Result.success(updated);
             } else {
-                return Result.error();
+                return Result.error("鏇存柊璁惧缁勯厤缃け璐�");
             }
         } catch (Exception e) {
             log.error("鏇存柊璁惧缁勯厤缃け璐�", e);
-            return Result.error();
+            return Result.error("鏇存柊璁惧缁勯厤缃け璐�: " + e.getMessage());
         }
     }
 
@@ -418,4 +431,39 @@
             return Result.error();
         }
     }
+    
+    /**
+     * 灏哋bject杞崲涓篋eviceGroupConfig
+     * 
+     * @param obj 寰呰浆鎹㈢殑瀵硅薄
+     * @return DeviceGroupConfig瀵硅薄锛屽鏋滆浆鎹㈠け璐ヨ繑鍥瀗ull
+     */
+    private DeviceGroupConfig convertToDeviceGroupConfig(Object obj) {
+        if (obj == null) {
+            return null;
+        }
+        
+        // 濡傛灉宸茬粡鏄疍eviceGroupConfig绫诲瀷锛岀洿鎺ヨ繑鍥�
+        if (obj instanceof DeviceGroupConfig) {
+            return (DeviceGroupConfig) obj;
+        }
+        
+        // 濡傛灉鏄疢ap绫诲瀷锛屼娇鐢∣bjectMapper杞崲
+        if (obj instanceof Map) {
+            try {
+                return objectMapper.convertValue(obj, DeviceGroupConfig.class);
+            } catch (Exception e) {
+                log.error("杞崲Map鍒癉eviceGroupConfig澶辫触", e);
+                return null;
+            }
+        }
+        
+        // 鍏朵粬绫诲瀷锛屽皾璇曚娇鐢∣bjectMapper杞崲
+        try {
+            return objectMapper.convertValue(obj, DeviceGroupConfig.class);
+        } catch (Exception e) {
+            log.error("杞崲Object鍒癉eviceGroupConfig澶辫触: obj={}", obj, e);
+            return null;
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.8.0