From e76f0739e647fe8a7e0e2618914e2faff554b1b7 Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期一, 17 十一月 2025 17:33:23 +0800
Subject: [PATCH] 解决冲突

---
 mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/DeviceGroupController.java |  421 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 421 insertions(+), 0 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
new file mode 100644
index 0000000..88e657c
--- /dev/null
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/device/controller/DeviceGroupController.java
@@ -0,0 +1,421 @@
+package com.mes.device.controller;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.mes.device.entity.DeviceGroupConfig;
+import com.mes.device.request.DeviceGroupRequest;
+import com.mes.device.service.DeviceGroupConfigService;
+import com.mes.device.service.DeviceGroupRelationService;
+import com.mes.device.vo.DeviceGroupVO;
+import com.mes.device.vo.StatisticsVO;
+import com.mes.vo.Result;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.validation.Valid;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 璁惧缁勭鐞嗘帶鍒跺櫒
+ * 
+ * @author mes
+ * @since 2024-10-30
+ */
+@Slf4j
+@RestController
+@RequestMapping("device/group")
+@Tag(name = "璁惧缁勭鐞�", description = "璁惧缁勭鐞嗙浉鍏虫帴鍙�")
+public class DeviceGroupController {
+
+    @Resource
+    private DeviceGroupConfigService deviceGroupConfigService;
+
+    @Autowired
+    private DeviceGroupRelationService deviceGroupRelationService;
+
+    /**
+     * 鍒涘缓璁惧缁�
+     */
+    @PostMapping("/create")
+    @Operation(summary = "鍒涘缓璁惧缁�", description = "鍒涘缓璁惧缁勪俊鎭�")
+    public Result<DeviceGroupConfig> createGroup(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            DeviceGroupConfig groupConfig = (DeviceGroupConfig) request.getGroupConfig();
+            boolean success = deviceGroupConfigService.createDeviceGroup(groupConfig);
+            if (success) {
+                // 鍒涘缓鎴愬姛鍚庯紝閲嶆柊鑾峰彇璁惧缁勫璞�
+                DeviceGroupConfig created = deviceGroupConfigService.getDeviceGroupByCode(groupConfig.getGroupCode());
+                return Result.success(created);
+            } else {
+                return Result.error();
+            }
+        } catch (Exception e) {
+            log.error("鍒涘缓璁惧缁勫け璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鏇存柊璁惧缁勯厤缃�
+     */
+    @PostMapping("/update")
+    @Operation(summary = "鏇存柊璁惧缁勯厤缃�", description = "鏇存柊鎸囧畾ID鐨勮澶囩粍閰嶇疆")
+    public Result<DeviceGroupConfig> updateGroup(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            DeviceGroupConfig groupConfig = (DeviceGroupConfig) request.getGroupConfig();
+            groupConfig.setId(request.getGroupId());
+            boolean success = deviceGroupConfigService.updateDeviceGroup(groupConfig);
+            if (success) {
+                // 鏇存柊鎴愬姛鍚庯紝閲嶆柊鑾峰彇璁惧缁勫璞�
+                DeviceGroupConfig updated = deviceGroupConfigService.getDeviceGroupByCode(groupConfig.getGroupCode());
+                return Result.success(updated);
+            } else {
+                return Result.error();
+            }
+        } catch (Exception e) {
+            log.error("鏇存柊璁惧缁勯厤缃け璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鍒犻櫎璁惧缁勯厤缃�
+     */
+    @PostMapping("/delete")
+    @Operation(summary = "鍒犻櫎璁惧缁勯厤缃�", description = "鍒犻櫎鎸囧畾ID鐨勮澶囩粍閰嶇疆")
+    public Result<Void> deleteGroup(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            deviceGroupConfigService.deleteDeviceGroup(request.getGroupId());
+            return Result.success(null);
+        } catch (Exception e) {
+            log.error("鍒犻櫎璁惧缁勯厤缃け璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鏍规嵁ID鑾峰彇璁惧缁勯厤缃�
+     */
+    @PostMapping("/detail")
+    @Operation(summary = "鑾峰彇璁惧缁勯厤缃鎯�", description = "鏍规嵁ID鑾峰彇璁惧缁勯厤缃殑璇︾粏淇℃伅")
+    public Result<DeviceGroupConfig> getGroupById(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            DeviceGroupConfig group = deviceGroupConfigService.getDeviceGroupById(request.getGroupId());
+            return Result.success(group);
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧缁勯厤缃け璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鍒嗛〉鏌ヨ璁惧缁勫垪琛�
+     */
+    @PostMapping("/list")
+    @Operation(summary = "鍒嗛〉鏌ヨ璁惧缁勫垪琛�", description = "鍒嗛〉鏌ヨ璁惧缁勫垪琛�")
+    public Result<Page<DeviceGroupVO.GroupInfo>> getGroupList(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            @SuppressWarnings("unchecked")
+            Map<String, Object> configMap = (Map<String, Object>) (request.getGroupConfig() != null ? request.getGroupConfig() : new HashMap<>());
+            Page pageResult = deviceGroupConfigService.getDeviceGroupList(
+                (Long) configMap.get("projectId"),
+                (String) configMap.get("groupType"),
+                (String) configMap.get("groupStatus"),
+                (String) configMap.get("keyword"),
+                (Integer) configMap.get("page"),
+                (Integer) configMap.get("size")
+            );
+            return Result.success(pageResult);
+        } catch (Exception e) {
+            log.error("鏌ヨ璁惧缁勫垪琛ㄥけ璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鍚敤璁惧缁�
+     */
+    @PostMapping("/enable")
+    @Operation(summary = "鍚敤璁惧缁�", description = "鍚敤鎸囧畾璁惧缁�")
+    public Result<Void> enableGroup(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            deviceGroupConfigService.enableDeviceGroup(request.getGroupId());
+            return Result.success(null);
+        } catch (Exception e) {
+            log.error("鍚敤璁惧缁勫け璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 绂佺敤璁惧缁�
+     */
+    @PostMapping("/disable")
+    @Operation(summary = "绂佺敤璁惧缁�", description = "绂佺敤鎸囧畾璁惧缁�")
+    public Result<Void> disableGroup(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            deviceGroupConfigService.disableDeviceGroup(request.getGroupId());
+            return Result.success(null);
+        } catch (Exception e) {
+            log.error("绂佺敤璁惧缁勫け璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鎵归噺鍚敤璁惧缁�
+     */
+    @PostMapping("/batch-enable")
+    @Operation(summary = "鎵归噺鍚敤璁惧缁�", description = "鎵归噺鍚敤鎸囧畾ID鍒楄〃鐨勮澶囩粍")
+    public Result<Void> batchEnableGroups(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            deviceGroupConfigService.batchEnableDeviceGroups(request.getGroupIds());
+            return Result.success(null);
+        } catch (Exception e) {
+            log.error("鎵归噺鍚敤璁惧缁勫け璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鎵归噺绂佺敤璁惧缁�
+     */
+    @PostMapping("/batch-disable")
+    @Operation(summary = "鎵归噺绂佺敤璁惧缁�", description = "鎵归噺绂佺敤鎸囧畾ID鍒楄〃鐨勮澶囩粍")
+    public Result<Void> batchDisableGroups(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            deviceGroupConfigService.batchDisableDeviceGroups(request.getGroupIds());
+            return Result.success(null);
+        } catch (Exception e) {
+            log.error("鎵归噺绂佺敤璁惧缁勫け璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鑾峰彇璁惧缁勭粺璁′俊鎭�
+     */
+    @PostMapping("/statistics/groups")
+    @Operation(summary = "鑾峰彇璁惧缁勭粺璁′俊鎭�", description = "鑾峰彇璁惧缁勭浉鍏崇殑缁熻淇℃伅")
+    public Result<StatisticsVO.GroupStatistics> getGroupStatistics(
+            @RequestBody(required = false) Map<String, Object> request) {
+        try {
+            Long projectId = request != null ? (Long) request.get("projectId") : null;
+            StatisticsVO.GroupStatistics statistics = deviceGroupConfigService.getDeviceGroupStatistics(projectId);
+            return Result.success(statistics);
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧缁勭粺璁′俊鎭け璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 妫�鏌ヨ澶囩粍缂栫爜鏄惁宸插瓨鍦�
+     */
+    @PostMapping("/check-code")
+    @Operation(summary = "妫�鏌ヨ澶囩粍缂栫爜", description = "妫�鏌ヨ澶囩粍缂栫爜鏄惁宸插瓨鍦�")
+    public Result<Boolean> checkGroupCodeExists(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            @SuppressWarnings("unchecked")
+            Map<String, Object> configMap = (Map<String, Object>) (request.getGroupConfig() != null ? request.getGroupConfig() : new HashMap<>());
+            boolean exists = deviceGroupConfigService.isGroupCodeExists(
+                (String) configMap.get("groupCode"), 
+                request.getGroupId());
+            return Result.success(exists);
+        } catch (Exception e) {
+            log.error("妫�鏌ヨ澶囩粍缂栫爜澶辫触", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鑾峰彇璁惧缁勭被鍨嬪垪琛�
+     */
+    @PostMapping("/types")
+    @Operation(summary = "鑾峰彇璁惧缁勭被鍨嬪垪琛�", description = "鑾峰彇鎵�鏈夊彲鐢ㄧ殑璁惧缁勭被鍨�")
+    public Result<List<String>> getGroupTypes() {
+        try {
+            List<String> groupTypes = deviceGroupConfigService.getAllGroupTypes();
+            return Result.success(groupTypes);
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧缁勭被鍨嬪垪琛ㄥけ璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鑾峰彇璁惧缁勭姸鎬佸垪琛�
+     */
+    @PostMapping("/statuses")
+    @Operation(summary = "鑾峰彇璁惧缁勭姸鎬佸垪琛�", description = "鑾峰彇鎵�鏈夊彲鐢ㄧ殑璁惧缁勭姸鎬�")
+    public Result<List<String>> getGroupStatuses() {
+        try {
+            List<String> groupStatuses = deviceGroupConfigService.getAllGroupStatuses();
+            return Result.success(groupStatuses);
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧缁勭姸鎬佸垪琛ㄥけ璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 娣诲姞璁惧鍒拌澶囩粍
+     */
+    @PostMapping("/devices")
+    @Operation(summary = "娣诲姞璁惧鍒拌澶囩粍", description = "灏嗘寚瀹氳澶囨坊鍔犲埌璁惧缁勪腑")
+    public Result<Void> addDeviceToGroup(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            deviceGroupRelationService.addDeviceToGroup(request.getGroupId(), request.getDeviceId(), 
+                request.getDeviceRole() != null ? request.getDeviceRole() : "MEMBER");
+            return Result.success(null);
+        } catch (Exception e) {
+            log.error("娣诲姞璁惧鍒拌澶囩粍澶辫触", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 浠庤澶囩粍绉婚櫎璁惧
+     */
+    @PostMapping("/devices/remove")
+    @Operation(summary = "浠庤澶囩粍绉婚櫎璁惧", description = "浠庤澶囩粍涓Щ闄ゆ寚瀹氳澶�")
+    public Result<Void> removeDeviceFromGroup(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            deviceGroupRelationService.removeDeviceFromGroup(request.getGroupId(), request.getDeviceId());
+            return Result.success(null);
+        } catch (Exception e) {
+            log.error("浠庤澶囩粍绉婚櫎璁惧澶辫触", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鏇存柊璁惧瑙掕壊
+     */
+    @PostMapping("/devices/role")
+    @Operation(summary = "鏇存柊璁惧瑙掕壊", description = "鏇存柊璁惧鍦ㄨ澶囩粍涓殑瑙掕壊")
+    public Result<Void> updateDeviceRole(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            deviceGroupRelationService.updateDeviceRole(request.getGroupId(), request.getDeviceId(), 
+                request.getDeviceRole());
+            return Result.success(null);
+        } catch (Exception e) {
+            log.error("鏇存柊璁惧瑙掕壊澶辫触", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鑾峰彇璁惧缁勮澶囧垪琛�
+     */
+    @PostMapping("/devices/list")
+    @Operation(summary = "鑾峰彇璁惧缁勮澶囧垪琛�", description = "鑾峰彇鎸囧畾璁惧缁勪笅鐨勬墍鏈夎澶�")
+    public Result<List<DeviceGroupVO.DeviceInfo>> getGroupDevices(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            List<DeviceGroupVO.DeviceInfo> devices = deviceGroupRelationService.getGroupDevices(request.getGroupId());
+            return Result.success(devices);
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧缁勮澶囧垪琛ㄥけ璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鑾峰彇璁惧璁惧缁勫垪琛�
+     */
+    @PostMapping("/devices/groups")
+    @Operation(summary = "鑾峰彇璁惧璁惧缁勫垪琛�", description = "鑾峰彇鎸囧畾璁惧鎵�灞炵殑鎵�鏈夎澶囩粍")
+    public Result<List<DeviceGroupVO.GroupInfo>> getDeviceGroups(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            List<DeviceGroupVO.GroupInfo> groups = deviceGroupRelationService.getDeviceGroups(request.getDeviceId());
+            return Result.success(groups);
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧璁惧缁勫垪琛ㄥけ璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鎵归噺娣诲姞璁惧鍒拌澶囩粍
+     */
+    @PostMapping("/batch-add-devices")
+    @Operation(summary = "鎵归噺娣诲姞璁惧鍒拌澶囩粍", description = "鎵归噺灏嗘寚瀹氳澶囧垪琛ㄦ坊鍔犲埌璁惧缁勪腑")
+    public Result<Void> batchAddDevicesToGroup(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            deviceGroupRelationService.batchAddDevicesToGroup(request.getGroupId(), request.getDeviceIds());
+            return Result.success(null);
+        } catch (Exception e) {
+            log.error("鎵归噺娣诲姞璁惧鍒拌澶囩粍澶辫触", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鎵归噺浠庤澶囩粍绉婚櫎璁惧
+     */
+    @PostMapping("/devices/batch-remove")
+    @Operation(summary = "鎵归噺浠庤澶囩粍绉婚櫎璁惧", description = "鎵归噺浠庤澶囩粍涓Щ闄ゆ寚瀹氳澶囧垪琛�")
+    public Result<Void> batchRemoveDevicesFromGroup(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            deviceGroupRelationService.batchRemoveDevicesFromGroup(request.getGroupId(), request.getDeviceIds());
+            return Result.success(null);
+        } catch (Exception e) {
+            log.error("鎵归噺浠庤澶囩粍绉婚櫎璁惧澶辫触", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 璁惧缁勫仴搴锋鏌�
+     */
+    @PostMapping("/health-check")
+    @Operation(summary = "璁惧缁勫仴搴锋鏌�", description = "瀵规寚瀹氳澶囩粍杩涜鍋ュ悍妫�鏌�")
+    public Result<DeviceGroupVO.HealthCheckResult> performGroupHealthCheck(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            DeviceGroupVO.HealthCheckResult result = deviceGroupConfigService.performGroupHealthCheck(request.getGroupId());
+            return Result.success(result);
+        } catch (Exception e) {
+            log.error("璁惧缁勫仴搴锋鏌ュけ璐�", e);
+            return Result.error();
+        }
+    }
+
+    /**
+     * 鑾峰彇璁惧缁勬�ц兘缁熻
+     */
+    @PostMapping("/performance")
+    @Operation(summary = "鑾峰彇璁惧缁勬�ц兘缁熻", description = "鑾峰彇鎸囧畾璁惧缁勭殑鎬ц兘缁熻淇℃伅")
+    public Result<DeviceGroupVO.PerformanceStats> getGroupPerformance(
+            @Valid @RequestBody DeviceGroupRequest request) {
+        try {
+            DeviceGroupVO.PerformanceStats stats = deviceGroupConfigService.getGroupPerformance(request.getGroupId());
+            return Result.success(stats);
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧缁勬�ц兘缁熻澶辫触", e);
+            return Result.error();
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.8.0