From 16f4bb3c28fc85cffcc511718c903ada9fdab134 Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期五, 26 十二月 2025 16:59:45 +0800
Subject: [PATCH] 调用mes导入工程参数修改,Excel表数据流程卡号一致;增加读取层号/工程号方法; 工程号一致覆盖更新

---
 mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/DeviceGroupController.java |   68 +++++++++++++++++++++++++++++-----
 1 files changed, 58 insertions(+), 10 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..fb68306 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());
         }
     }
 
@@ -281,7 +294,7 @@
     public Result<Void> addDeviceToGroup(
             @Valid @RequestBody DeviceGroupRequest request) {
         try {
-            deviceGroupRelationService.addDeviceToGroup(request.getGroupId(), request.getDeviceId(), 
+            deviceGroupRelationService.addDeviceToGroup(request.getGroupId(), request.getId(), 
                 request.getDeviceRole() != null ? request.getDeviceRole() : "MEMBER");
             return Result.success(null);
         } catch (Exception e) {
@@ -298,7 +311,7 @@
     public Result<Void> removeDeviceFromGroup(
             @Valid @RequestBody DeviceGroupRequest request) {
         try {
-            deviceGroupRelationService.removeDeviceFromGroup(request.getGroupId(), request.getDeviceId());
+            deviceGroupRelationService.removeDeviceFromGroup(request.getGroupId(), request.getId());
             return Result.success(null);
         } catch (Exception e) {
             log.error("浠庤澶囩粍绉婚櫎璁惧澶辫触", e);
@@ -314,7 +327,7 @@
     public Result<Void> updateDeviceRole(
             @Valid @RequestBody DeviceGroupRequest request) {
         try {
-            deviceGroupRelationService.updateDeviceRole(request.getGroupId(), request.getDeviceId(), 
+            deviceGroupRelationService.updateDeviceRole(request.getGroupId(), request.getId(), 
                 request.getDeviceRole());
             return Result.success(null);
         } catch (Exception e) {
@@ -347,7 +360,7 @@
     public Result<List<DeviceGroupVO.GroupInfo>> getDeviceGroups(
             @Valid @RequestBody DeviceGroupRequest request) {
         try {
-            List<DeviceGroupVO.GroupInfo> groups = deviceGroupRelationService.getDeviceGroups(request.getDeviceId());
+            List<DeviceGroupVO.GroupInfo> groups = deviceGroupRelationService.getDeviceGroups(request.getId());
             return Result.success(groups);
         } catch (Exception e) {
             log.error("鑾峰彇璁惧璁惧缁勫垪琛ㄥけ璐�", e);
@@ -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