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/service/impl/DeviceGroupConfigServiceImpl.java |  812 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 812 insertions(+), 0 deletions(-)

diff --git a/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/DeviceGroupConfigServiceImpl.java b/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/DeviceGroupConfigServiceImpl.java
new file mode 100644
index 0000000..2a229c2
--- /dev/null
+++ b/mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/DeviceGroupConfigServiceImpl.java
@@ -0,0 +1,812 @@
+package com.mes.device.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.mes.device.entity.DeviceGroupConfig;
+import com.mes.device.mapper.DeviceGroupConfigMapper;
+import com.mes.device.service.DeviceGroupConfigService;
+import com.mes.device.vo.DeviceGroupConfigVO;
+import com.mes.device.vo.DeviceGroupVO;
+import com.mes.device.vo.StatisticsVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 璁惧缁勯厤缃湇鍔″疄鐜扮被
+ */
+@Slf4j
+@Service
+public class DeviceGroupConfigServiceImpl extends ServiceImpl<DeviceGroupConfigMapper, DeviceGroupConfig> implements DeviceGroupConfigService {
+
+    private final ObjectMapper objectMapper = new ObjectMapper();
+
+    @Override
+    public boolean createDeviceGroup(DeviceGroupConfig groupConfig) {
+        try {
+            // 妫�鏌ヨ澶囩粍缂栧彿鏄惁宸插瓨鍦�
+            if (isGroupCodeExists(groupConfig.getGroupCode(), null)) {
+                log.warn("璁惧缁勭紪鍙峰凡瀛樺湪: {}", groupConfig.getGroupCode());
+                return false;
+            }
+            
+            // 鍒濆鍖栬澶囩粍鐘舵�佷负鍋滅敤
+            if (groupConfig.getStatus() == null) {
+                groupConfig.setStatus(DeviceGroupConfig.Status.DISABLED);
+            }
+            
+            // 璁剧疆榛樿閰嶇疆
+            if (groupConfig.getMaxConcurrentDevices() == null) {
+                groupConfig.setMaxConcurrentDevices(3);
+            }
+            
+            if (groupConfig.getHeartbeatInterval() == null) {
+                groupConfig.setHeartbeatInterval(30);
+            }
+            
+            if (groupConfig.getCommunicationTimeout() == null) {
+                groupConfig.setCommunicationTimeout(5000);
+            }
+            
+            boolean result = save(groupConfig);
+            if (result) {
+                log.info("鍒涘缓璁惧缁勯厤缃垚鍔�: {}", groupConfig.getGroupCode());
+            }
+            return result;
+        } catch (Exception e) {
+            log.error("鍒涘缓璁惧缁勯厤缃け璐�", e);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean updateDeviceGroup(DeviceGroupConfig groupConfig) {
+        try {
+            // 妫�鏌ヨ澶囩粍缂栧彿鏄惁宸插瓨鍦紙鎺掗櫎褰撳墠璁惧缁勶級
+            if (isGroupCodeExists(groupConfig.getGroupCode(), groupConfig.getId())) {
+                log.warn("璁惧缁勭紪鍙峰凡瀛樺湪: {}", groupConfig.getGroupCode());
+                return false;
+            }
+            
+            boolean result = updateById(groupConfig);
+            if (result) {
+                log.info("鏇存柊璁惧缁勯厤缃垚鍔�: {}", groupConfig.getGroupCode());
+            }
+            return result;
+        } catch (Exception e) {
+            log.error("鏇存柊璁惧缁勯厤缃け璐�", e);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean deleteDeviceGroup(Long id) {
+        try {
+            // 鍏堟鏌ヨ璁惧缁勪笅鏄惁鏈夎澶�
+            int deviceCount = getDeviceCountByGroupId(id);
+            if (deviceCount > 0) {
+                log.warn("璁惧缁勪笅杩樻湁璁惧锛屾棤娉曞垹闄�: {}", id);
+                return false;
+            }
+            
+            boolean result = removeById(id);
+            if (result) {
+                log.info("鍒犻櫎璁惧缁勯厤缃垚鍔�: {}", id);
+            }
+            return result;
+        } catch (Exception e) {
+            log.error("鍒犻櫎璁惧缁勯厤缃け璐�", e);
+            return false;
+        }
+    }
+
+    @Override
+    public DeviceGroupConfig getDeviceGroupById(Long id) {
+        return getById(id);
+    }
+
+    @Override
+    public DeviceGroupConfig getDeviceGroupByCode(String groupCode) {
+        LambdaQueryWrapper<DeviceGroupConfig> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(DeviceGroupConfig::getGroupCode, groupCode);
+        wrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+        return getOne(wrapper);
+    }
+
+    @Override
+    public List<DeviceGroupConfig> getDeviceGroupList(Long projectId, Integer groupType, Integer status) {
+        LambdaQueryWrapper<DeviceGroupConfig> wrapper = new LambdaQueryWrapper<>();
+        
+        // 杩囨护鏈垹闄ょ殑璁惧缁�
+        wrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+        
+        if (groupType != null) {
+            wrapper.eq(DeviceGroupConfig::getGroupType, groupType);
+        }
+        
+        if (status != null) {
+            wrapper.eq(DeviceGroupConfig::getStatus, status);
+        }
+        
+        wrapper.orderByAsc(DeviceGroupConfig::getId);
+        
+        return list(wrapper);
+    }
+
+    @Override
+    public Page<DeviceGroupVO.GroupInfo> getDeviceGroupList(Long projectId, String groupType, String groupStatus, String keyword, Integer page, Integer size) {
+        try {
+            // 鍒涘缓鍒嗛〉瀵硅薄
+            Page<DeviceGroupConfig> pageEntity = new Page<>(page, size);
+            
+            LambdaQueryWrapper<DeviceGroupConfig> wrapper = new LambdaQueryWrapper<>();
+            
+            // 杩囨护鏈垹闄ょ殑璁惧缁�
+            wrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+            
+            // 椤圭洰ID杩囨护
+            if (projectId != null) {
+                wrapper.eq(DeviceGroupConfig::getProjectId, projectId);
+            }
+            
+            // 璁惧缁勭被鍨嬭繃婊わ紙瀛楃涓茶浆鎹负鏋氫妇鍊硷級
+            if (groupType != null && !groupType.trim().isEmpty()) {
+                Integer typeEnum = convertGroupTypeFromString(groupType);
+                if (typeEnum != null) {
+                    wrapper.eq(DeviceGroupConfig::getGroupType, typeEnum);
+                }
+            }
+            
+            // 璁惧缁勭姸鎬佽繃婊わ紙瀛楃涓茶浆鎹负鏋氫妇鍊硷級
+            if (groupStatus != null && !groupStatus.trim().isEmpty()) {
+                Integer statusEnum = convertStatusFromString(groupStatus);
+                if (statusEnum != null) {
+                    wrapper.eq(DeviceGroupConfig::getStatus, statusEnum);
+                }
+            }
+            
+            // 鍏抽敭璇嶆悳绱�
+            if (keyword != null && !keyword.trim().isEmpty()) {
+                wrapper.and(w -> w
+                    .like(DeviceGroupConfig::getGroupName, keyword)
+                    .or().like(DeviceGroupConfig::getGroupCode, keyword)
+                    .or().like(DeviceGroupConfig::getDescription, keyword));
+            }
+            
+            wrapper.orderByDesc(DeviceGroupConfig::getUpdatedTime);
+            
+            // 鎵ц鍒嗛〉鏌ヨ
+            pageEntity = page(pageEntity, wrapper);
+            
+            // 杞崲涓篤O瀵硅薄
+            List<DeviceGroupVO.GroupInfo> voList = pageEntity.getRecords().stream().map(group -> {
+                DeviceGroupVO.GroupInfo vo = new DeviceGroupVO.GroupInfo();
+                vo.setId(group.getId());
+                vo.setGroupCode(group.getGroupCode());
+                vo.setGroupName(group.getGroupName());
+                vo.setGroupType(getGroupTypeName(group.getGroupType()));
+                vo.setStatus(getStatusName(group.getStatus()));
+                vo.setDeviceCount(getDeviceCountByGroupId(group.getId()));
+                vo.setCreateTime(group.getCreatedTime());
+                vo.setProjectId(group.getProjectId());
+                return vo;
+            }).collect(Collectors.toList());
+            
+            // 鍒涘缓鍒嗛〉缁撴灉
+            Page<DeviceGroupVO.GroupInfo> result = new Page<>(pageEntity.getCurrent(), pageEntity.getSize(), pageEntity.getTotal());
+            result.setRecords(voList);
+            
+            return result;
+        } catch (Exception e) {
+            log.error("鍒嗛〉鏌ヨ璁惧缁勯厤缃垪琛ㄥけ璐�", e);
+            throw new RuntimeException("鍒嗛〉鏌ヨ璁惧缁勯厤缃垪琛ㄥけ璐�: " + e.getMessage(), e);
+        }
+    }
+
+    @Override
+    public List<DeviceGroupConfigVO.GroupInfo> getDeviceGroupVOList(Long projectId, Integer groupType, Integer status) {
+        // TODO: 杩欓噷闇�瑕佸疄鐜癡O杞崲閫昏緫锛屽寘鎷澶囨暟閲忕粺璁�
+        List<DeviceGroupConfig> groupList = getDeviceGroupList(projectId, groupType, status);
+        
+        return groupList.stream().map(group -> {
+            DeviceGroupConfigVO.GroupInfo vo = new DeviceGroupConfigVO.GroupInfo();
+            vo.setId(group.getId());
+            vo.setGroupName(group.getGroupName());
+            vo.setGroupCode(group.getGroupCode());
+            vo.setGroupType(getGroupTypeName(group.getGroupType()));
+            vo.setDescription(group.getDescription());
+            vo.setStatus(getStatusName(group.getStatus()));
+            vo.setDeviceCount(getDeviceCountByGroupId(group.getId()));
+            vo.setIsEnabled(group.getStatus() != null && group.getStatus() == DeviceGroupConfig.Status.ENABLED);
+            vo.setLocation("榛樿浣嶇疆"); // TODO: 浠庢墿灞曢厤缃垨鍏宠仈琛ㄤ腑鑾峰彇
+            vo.setSupervisor("榛樿绠$悊鍛�"); // TODO: 浠庢墿灞曢厤缃垨鍏宠仈琛ㄤ腑鑾峰彇
+            vo.setCreatedTime(new Date());
+            vo.setUpdatedTime(new Date());
+            vo.setProjectId(group.getProjectId());
+            return vo;
+        }).collect(Collectors.toList());
+    }
+
+    /**
+     * 鑾峰彇璁惧缁勭被鍨嬪悕绉�
+     */
+    private String getGroupTypeName(Integer groupType) {
+        switch (groupType != null ? groupType : 0) {
+            case DeviceGroupConfig.GroupType.PRODUCTION_LINE:
+                return "鐢熶骇绾�";
+            case DeviceGroupConfig.GroupType.TEST_LINE:
+                return "娴嬭瘯绾�";
+            case DeviceGroupConfig.GroupType.AUXILIARY_GROUP:
+                return "杈呭姪璁惧缁�";
+            default:
+                return "鏈煡绫诲瀷";
+        }
+    }
+
+    /**
+     * 瀛楃涓茶浆鎹负璁惧缁勭被鍨嬫灇涓惧��
+     */
+    private Integer convertGroupTypeFromString(String groupType) {
+        if (groupType == null || groupType.trim().isEmpty()) {
+            return null;
+        }
+        
+        switch (groupType.trim()) {
+            case "鐢熶骇绾�":
+            case "production_line":
+            case "PRODUCTION_LINE":
+                return DeviceGroupConfig.GroupType.PRODUCTION_LINE;
+            case "娴嬭瘯绾�":
+            case "test_line":
+            case "TEST_LINE":
+                return DeviceGroupConfig.GroupType.TEST_LINE;
+            case "杈呭姪璁惧缁�":
+            case "auxiliary_group":
+            case "AUXILIARY_GROUP":
+                return DeviceGroupConfig.GroupType.AUXILIARY_GROUP;
+            default:
+                try {
+                    // 灏濊瘯鐩存帴瑙f瀽涓烘暣鏁�
+                    return Integer.parseInt(groupType.trim());
+                } catch (NumberFormatException e) {
+                    log.warn("鏃犳硶璇嗗埆鐨勮澶囩粍绫诲瀷: {}", groupType);
+                    return null;
+                }
+        }
+    }
+
+    /**
+     * 鑾峰彇璁惧缁勭姸鎬佸悕绉�
+     */
+    private String getStatusName(Integer status) {
+        switch (status != null ? status : 0) {
+            case DeviceGroupConfig.Status.ENABLED:
+                return "鍚敤";
+            case DeviceGroupConfig.Status.DISABLED:
+                return "鍋滅敤";
+            case DeviceGroupConfig.Status.MAINTENANCE:
+                return "缁存姢涓�";
+            default:
+                return "鏈煡鐘舵��";
+        }
+    }
+
+    /**
+     * 瀛楃涓茶浆鎹负璁惧缁勭姸鎬佹灇涓惧��
+     */
+    private Integer convertStatusFromString(String status) {
+        if (status == null || status.trim().isEmpty()) {
+            return null;
+        }
+        
+        switch (status.trim()) {
+            case "鍚敤":
+            case "enabled":
+            case "ENABLED":
+                return DeviceGroupConfig.Status.ENABLED;
+            case "鍋滅敤":
+            case "disabled":
+            case "DISABLED":
+                return DeviceGroupConfig.Status.DISABLED;
+            case "缁存姢涓�":
+            case "maintenance":
+            case "MAINTENANCE":
+                return DeviceGroupConfig.Status.MAINTENANCE;
+            default:
+                try {
+                    // 灏濊瘯鐩存帴瑙f瀽涓烘暣鏁�
+                    return Integer.parseInt(status.trim());
+                } catch (NumberFormatException e) {
+                    log.warn("鏃犳硶璇嗗埆鐨勮澶囩粍鐘舵��: {}", status);
+                    return null;
+                }
+        }
+    }
+
+    @Override
+    public boolean isGroupCodeExists(String groupCode, Long excludeId) {
+        LambdaQueryWrapper<DeviceGroupConfig> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(DeviceGroupConfig::getGroupCode, groupCode);
+        wrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+        
+        if (excludeId != null) {
+            wrapper.ne(DeviceGroupConfig::getId, excludeId);
+        }
+        
+        return count(wrapper) > 0;
+    }
+
+    @Override
+    public boolean updateDeviceGroupStatus(Long id, Integer status) {
+        try {
+            DeviceGroupConfig group = getById(id);
+            if (group == null) {
+                log.warn("璁惧缁勪笉瀛樺湪: {}", id);
+                return false;
+            }
+            
+            group.setStatus(status);
+            boolean result = updateById(group);
+            if (result) {
+                log.info("鏇存柊璁惧缁勭姸鎬佹垚鍔�: {} -> {}", id, status);
+            }
+            return result;
+        } catch (Exception e) {
+            log.error("鏇存柊璁惧缁勭姸鎬佸け璐�", e);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean batchUpdateDeviceGroupStatus(List<Long> ids, Integer status) {
+        try {
+            LambdaQueryWrapper<DeviceGroupConfig> wrapper = new LambdaQueryWrapper<>();
+            wrapper.in(DeviceGroupConfig::getId, ids);
+            
+            DeviceGroupConfig updateEntity = new DeviceGroupConfig();
+            updateEntity.setStatus(status);
+            
+            boolean result = update(updateEntity, wrapper);
+            if (result) {
+                log.info("鎵归噺鏇存柊璁惧缁勭姸鎬佹垚鍔�: {} 涓澶囩粍 -> {}", ids.size(), status);
+            }
+            return result;
+        } catch (Exception e) {
+            log.error("鎵归噺鏇存柊璁惧缁勭姸鎬佸け璐�", e);
+            return false;
+        }
+    }
+
+    @Override
+    public Map<String, Object> getExtraConfig(Long id) {
+        try {
+            DeviceGroupConfig group = getById(id);
+            if (group == null || group.getExtraConfig() == null) {
+                return new HashMap<>();
+            }
+            
+            return objectMapper.readValue(group.getExtraConfig(), 
+                new TypeReference<Map<String, Object>>() {});
+        } catch (IOException e) {
+            log.error("瑙f瀽璁惧缁勬墿灞曢厤缃け璐�", e);
+            return new HashMap<>();
+        }
+    }
+
+    @Override
+    public boolean updateExtraConfig(Long id, Map<String, Object> extraConfig) {
+        try {
+            DeviceGroupConfig group = getById(id);
+            if (group == null) {
+                log.warn("璁惧缁勪笉瀛樺湪: {}", id);
+                return false;
+            }
+            
+            String extraConfigJson = objectMapper.writeValueAsString(extraConfig);
+            group.setExtraConfig(extraConfigJson);
+            
+            boolean result = updateById(group);
+            if (result) {
+                log.info("鏇存柊璁惧缁勬墿灞曢厤缃垚鍔�: {}", id);
+            }
+            return result;
+        } catch (IOException e) {
+            log.error("搴忓垪鍖栬澶囩粍鎵╁睍閰嶇疆澶辫触", e);
+            return false;
+        }
+    }
+
+    @Override
+    public int getDeviceCountByGroupId(Long groupId) {
+        // 杩欓噷闇�瑕佹煡璇evice_group_relation琛ㄦ潵鑾峰彇璁惧鏁伴噺
+        // 绠�鍖栧疄鐜帮紝瀹為檯闇�瑕佹敞鍏eviceGroupRelationMapper
+        return 0; // TODO: 瀹炵幇鐪熷疄閫昏緫
+    }
+
+    /**
+     * 鑾峰彇璁惧缁勭被鍨嬬粺璁℃暟鎹�
+     */
+    private List<StatisticsVO.GroupTypeStatistics> getDeviceGroupTypeStatistics(Long projectId) {
+        try {
+            List<StatisticsVO.GroupTypeStatistics> groupTypeStats = new ArrayList<>();
+            
+            // 鑾峰彇鎵�鏈夎澶囩粍绫诲瀷鏋氫妇鍊�
+            // 娉ㄦ剰锛氶渶瑕佹墜鍔ㄥ垪鍑烘墍鏈夊彲鑳界殑璁惧缁勭被鍨嬶紝鍥犱负鏋氫妇绫荤粨鏋勪笌棰勬湡涓嶇
+            List<Integer> groupTypes = Arrays.asList(DeviceGroupConfig.GroupType.PRODUCTION_LINE, DeviceGroupConfig.GroupType.TEST_LINE, DeviceGroupConfig.GroupType.AUXILIARY_GROUP);
+            
+            for (Integer groupType : groupTypes) {
+                // 璁惧缁勬�绘暟
+                LambdaQueryWrapper<DeviceGroupConfig> totalWrapper = new LambdaQueryWrapper<>();
+                totalWrapper.eq(DeviceGroupConfig::getGroupType, groupType);
+                totalWrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+                long totalCount = count(totalWrapper);
+                
+                // 鍦ㄧ嚎鏁帮紙鍚敤鐨勮澶囩粍鏁帮級
+                LambdaQueryWrapper<DeviceGroupConfig> onlineWrapper = new LambdaQueryWrapper<>();
+                onlineWrapper.eq(DeviceGroupConfig::getGroupType, groupType);
+                onlineWrapper.eq(DeviceGroupConfig::getStatus, DeviceGroupConfig.Status.ENABLED);
+                onlineWrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+                long onlineCount = count(onlineWrapper);
+                
+                // 绂荤嚎鏁帮紙鍋滅敤鐨勮澶囩粍鏁帮級
+                LambdaQueryWrapper<DeviceGroupConfig> offlineWrapper = new LambdaQueryWrapper<>();
+                offlineWrapper.eq(DeviceGroupConfig::getGroupType, groupType);
+                offlineWrapper.eq(DeviceGroupConfig::getStatus, DeviceGroupConfig.Status.DISABLED);
+                offlineWrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+                long offlineCount = count(offlineWrapper);
+                
+                // 缁存姢涓殑璁惧缁勬暟
+                LambdaQueryWrapper<DeviceGroupConfig> maintenanceWrapper = new LambdaQueryWrapper<>();
+                maintenanceWrapper.eq(DeviceGroupConfig::getGroupType, groupType);
+                maintenanceWrapper.eq(DeviceGroupConfig::getStatus, DeviceGroupConfig.Status.MAINTENANCE);
+                maintenanceWrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+                long maintenanceCount = count(maintenanceWrapper);
+                
+                // 璁$畻鍙敤鎬�
+                double availability = totalCount > 0 ? (onlineCount * 100.0 / totalCount) : 0.0;
+                
+                // 鍒涘缓璁惧缁勭被鍨嬬粺璁″璞�
+                StatisticsVO.GroupTypeStatistics groupTypeStat = new StatisticsVO.GroupTypeStatistics();
+                groupTypeStat.setGroupType(getGroupTypeName(groupType));
+                groupTypeStat.setTotalCount((int) totalCount);
+                // 娉ㄦ剰锛歋tatisticsVO.GroupTypeStatistics鐨勫瓧娈典笌浠g爜鏈熸湜涓嶇锛岃繖閲屽仛閫傚綋璋冩暣
+                // activeCount琛ㄧず鍚敤鐨勮澶囩粍鏁�
+                groupTypeStat.setActiveCount((int) onlineCount);
+                
+                groupTypeStats.add(groupTypeStat);
+            }
+            
+            return groupTypeStats;
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧缁勭被鍨嬬粺璁℃暟鎹け璐�", e);
+            return new ArrayList<>();
+        }
+    }
+
+    @Override
+    public int getOnlineDeviceGroupCount(Long projectId) {
+        // 绠�鍖栧疄鐜帮紝瀹為檯椤圭洰涓彲鑳介渶瑕佹牴鎹」鐩甀D杩囨护
+        LambdaQueryWrapper<DeviceGroupConfig> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(DeviceGroupConfig::getStatus, DeviceGroupConfig.Status.ENABLED);
+        wrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+        
+        return (int) count(wrapper);
+    }
+
+    @Override
+    public StatisticsVO.GroupStatistics getDeviceGroupStatistics(Long projectId) {
+        try {
+            // 璁惧缁勬�绘暟
+            LambdaQueryWrapper<DeviceGroupConfig> totalWrapper = new LambdaQueryWrapper<>();
+            totalWrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+            if (projectId != null) {
+                totalWrapper.eq(DeviceGroupConfig::getProjectId, projectId);
+            }
+            long totalGroups = count(totalWrapper);
+            
+            // 鍚敤鐨勮澶囩粍鏁�
+            LambdaQueryWrapper<DeviceGroupConfig> enabledWrapper = new LambdaQueryWrapper<>();
+            enabledWrapper.eq(DeviceGroupConfig::getStatus, DeviceGroupConfig.Status.ENABLED);
+            enabledWrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+            if (projectId != null) {
+                enabledWrapper.eq(DeviceGroupConfig::getProjectId, projectId);
+            }
+            long enabledGroups = count(enabledWrapper);
+            
+            // 鍋滅敤鐨勮澶囩粍鏁�
+            LambdaQueryWrapper<DeviceGroupConfig> disabledWrapper = new LambdaQueryWrapper<>();
+            disabledWrapper.eq(DeviceGroupConfig::getStatus, DeviceGroupConfig.Status.DISABLED);
+            disabledWrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+            if (projectId != null) {
+                disabledWrapper.eq(DeviceGroupConfig::getProjectId, projectId);
+            }
+            long disabledGroups = count(disabledWrapper);
+            
+            // 缁存姢涓殑璁惧缁勬暟
+            LambdaQueryWrapper<DeviceGroupConfig> maintenanceWrapper = new LambdaQueryWrapper<>();
+            maintenanceWrapper.eq(DeviceGroupConfig::getStatus, DeviceGroupConfig.Status.MAINTENANCE);
+            maintenanceWrapper.eq(DeviceGroupConfig::getIsDeleted, 0);
+            if (projectId != null) {
+                maintenanceWrapper.eq(DeviceGroupConfig::getProjectId, projectId);
+            }
+            long maintenanceGroups = count(maintenanceWrapper);
+            
+            // 鍒涘缓璁惧缁勭粺璁″璞�
+            StatisticsVO.GroupStatistics groupStats = new StatisticsVO.GroupStatistics();
+            groupStats.setTotalGroups((int) totalGroups);
+            groupStats.setActiveGroups((int) enabledGroups);
+            groupStats.setInactiveGroups((int) disabledGroups);
+            // 娉ㄦ剰锛歋tatisticsVO.GroupStatistics娌℃湁鐩存帴鐨勭淮鎶や腑璁惧缁勫瓧娈碉紝杩欓噷蹇界暐鎴栬皟鏁�
+            
+            // 璁$畻璁惧缁勫彲鐢ㄦ�э紙鍚敤璁惧缁� / 鎬昏澶囩粍 * 100%锛�
+            double availability = totalGroups > 0 ? (enabledGroups * 100.0 / totalGroups) : 0.0;
+            groupStats.setGroupAvailability(availability);
+            
+            // 鑾峰彇鎸夎澶囩粍绫诲瀷鐨勭粺璁℃暟鎹�
+            List<StatisticsVO.GroupTypeStatistics> groupTypeStats = getDeviceGroupTypeStatistics(projectId);
+            groupStats.setGroupTypeStats(groupTypeStats);
+            
+            log.info("鑾峰彇璁惧缁勭粺璁′俊鎭垚鍔�: 鎬绘暟={}, 鍚敤={}, 鍋滅敤={}, 缁存姢涓�={}", 
+                totalGroups, enabledGroups, disabledGroups, maintenanceGroups);
+            
+            return groupStats;
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧缁勭粺璁′俊鎭け璐�", e);
+            // 杩斿洖榛樿缁熻瀵硅薄
+            return new StatisticsVO.GroupStatistics();
+        }
+    }
+
+    @Override
+    public DeviceGroupVO.PerformanceStats getGroupPerformance(Long groupId) {
+        try {
+            // 妫�鏌ヨ澶囩粍鏄惁瀛樺湪
+            DeviceGroupConfig group = getById(groupId);
+            if (group == null) {
+                log.warn("璁惧缁勪笉瀛樺湪: {}", groupId);
+                return new DeviceGroupVO.PerformanceStats();
+            }
+
+            // 鑾峰彇璁惧缁勪笅鐨勮澶囨暟閲�
+            int totalDevices = getDeviceCountByGroupId(groupId);
+            
+            // 鑾峰彇鍦ㄧ嚎璁惧鏁伴噺
+            int activeDevices = 0; // TODO: 闇�瑕佹牴鎹疄闄呬笟鍔¢�昏緫瀹炵幇
+            
+            // 璁$畻骞冲潎鎬ц兘鎸囨爣锛堟ā鎷熸暟鎹級
+            double averageCpuUsage = 45.5; // CPU浣跨敤鐜囩櫨鍒嗘瘮
+            double averageMemoryUsage = 65.2; // 鍐呭瓨浣跨敤鐜囩櫨鍒嗘瘮
+            int totalTasksCompleted = 1000; // 鎬诲畬鎴愪换鍔℃暟
+            double successRate = 99.2; // 浠诲姟鎴愬姛鐜囩櫨鍒嗘瘮
+            
+            // 鍒涘缓璁惧缁勬�ц兘缁熻瀵硅薄
+            DeviceGroupVO.PerformanceStats performanceStats = new DeviceGroupVO.PerformanceStats();
+            performanceStats.setTotalDevices(totalDevices);
+            performanceStats.setActiveDevices(activeDevices);
+            performanceStats.setAverageCpuUsage(averageCpuUsage);
+            performanceStats.setAverageMemoryUsage(averageMemoryUsage);
+            performanceStats.setTotalTasksCompleted(totalTasksCompleted);
+            performanceStats.setSuccessRate(successRate);
+            performanceStats.setStatsTime(new Date());
+            performanceStats.setDevicePerformances(new ArrayList<>());
+            
+            log.info("鑾峰彇璁惧缁勬�ц兘缁熻鎴愬姛: groupId={}, totalDevices={}", 
+                groupId, totalDevices);
+            
+            return performanceStats;
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧缁勬�ц兘缁熻澶辫触", e);
+            // 杩斿洖榛樿鎬ц兘缁熻瀵硅薄
+            return new DeviceGroupVO.PerformanceStats();
+        }
+    }
+
+    @Override
+    public DeviceGroupVO.HealthCheckResult performGroupHealthCheck(Long groupId) {
+        try {
+            // 妫�鏌ヨ澶囩粍鏄惁瀛樺湪
+            DeviceGroupConfig group = getById(groupId);
+            if (group == null) {
+                log.warn("璁惧缁勪笉瀛樺湪: {}", groupId);
+                DeviceGroupVO.HealthCheckResult errorResult = new DeviceGroupVO.HealthCheckResult();
+                errorResult.setIsHealthy(false);
+                errorResult.setTotalDevices(0);
+                errorResult.setOnlineDevices(0);
+                errorResult.setOfflineDevices(0);
+                errorResult.setFailedDevices(new ArrayList<>());
+                errorResult.setCheckTime(new Date());
+                errorResult.setCheckSummary("璁惧缁勪笉瀛樺湪");
+                return errorResult;
+            }
+
+            // 鑾峰彇璁惧缁勪笅鐨勮澶囦俊鎭�
+            int totalDevices = getDeviceCountByGroupId(groupId);
+            int onlineDevices = 0; // TODO: 闇�瑕佹牴鎹疄闄呬笟鍔¢�昏緫瀹炵幇
+            int offlineDevices = totalDevices - onlineDevices;
+            
+            // 璁$畻鍋ュ悍鐘舵��
+            boolean isHealthy = onlineDevices >= totalDevices * 0.9; // 90%浠ヤ笂鍦ㄧ嚎鍒欏仴搴�
+            
+            // 鍒涘缓鍋ュ悍妫�鏌ョ粨鏋�
+            DeviceGroupVO.HealthCheckResult healthResult = new DeviceGroupVO.HealthCheckResult();
+            healthResult.setIsHealthy(isHealthy);
+            healthResult.setTotalDevices(totalDevices);
+            healthResult.setOnlineDevices(onlineDevices);
+            healthResult.setOfflineDevices(offlineDevices);
+            healthResult.setFailedDevices(new ArrayList<>()); // 璁剧疆涓虹┖鍒楄〃
+            healthResult.setCheckTime(new Date());
+            healthResult.setCheckSummary(isHealthy ? "璁惧缁勫仴搴�" : "璁惧缁勫瓨鍦ㄩ棶棰�");
+            
+            log.info("璁惧缁勫仴搴锋鏌ュ畬鎴�: groupId={}, isHealthy={}, totalDevices={}, onlineDevices={}", 
+                groupId, isHealthy, totalDevices, onlineDevices);
+            
+            return healthResult;
+        } catch (Exception e) {
+            log.error("鎵ц璁惧缁勫仴搴锋鏌ュけ璐�", e);
+            // 杩斿洖閿欒鐘舵�佺殑缁撴灉
+            DeviceGroupVO.HealthCheckResult errorResult = new DeviceGroupVO.HealthCheckResult();
+            errorResult.setIsHealthy(false);
+            errorResult.setTotalDevices(0);
+            errorResult.setOnlineDevices(0);
+            errorResult.setOfflineDevices(0);
+            errorResult.setFailedDevices(new ArrayList<>());
+            errorResult.setCheckTime(new Date());
+            errorResult.setCheckSummary("鍋ュ悍妫�鏌ユ墽琛屽け璐�: " + e.getMessage());
+            return errorResult;
+        }
+    }
+
+    @Override
+    public boolean enableDeviceGroup(Long id) {
+        try {
+            // 妫�鏌ヨ澶囩粍鏄惁瀛樺湪
+            DeviceGroupConfig group = getById(id);
+            if (group == null) {
+                log.warn("璁惧缁勪笉瀛樺湪: {}", id);
+                return false;
+            }
+
+            // 鏇存柊璁惧缁勭姸鎬佷负鍚敤
+            group.setStatus(DeviceGroupConfig.Status.ENABLED);
+            boolean result = updateById(group);
+            
+            if (result) {
+                log.info("鍚敤璁惧缁勬垚鍔�: {}", id);
+            } else {
+                log.error("鍚敤璁惧缁勫け璐�: {}", id);
+            }
+            
+            return result;
+        } catch (Exception e) {
+            log.error("鍚敤璁惧缁勫紓甯�", e);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean disableDeviceGroup(Long id) {
+        try {
+            // 妫�鏌ヨ澶囩粍鏄惁瀛樺湪
+            DeviceGroupConfig group = getById(id);
+            if (group == null) {
+                log.warn("璁惧缁勪笉瀛樺湪: {}", id);
+                return false;
+            }
+
+            // 鏇存柊璁惧缁勭姸鎬佷负绂佺敤
+            group.setStatus(DeviceGroupConfig.Status.DISABLED);
+            boolean result = updateById(group);
+            
+            if (result) {
+                log.info("绂佺敤璁惧缁勬垚鍔�: {}", id);
+            } else {
+                log.error("绂佺敤璁惧缁勫け璐�: {}", id);
+            }
+            
+            return result;
+        } catch (Exception e) {
+            log.error("绂佺敤璁惧缁勫紓甯�", e);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean batchEnableDeviceGroups(java.util.List<Long> groupIds) {
+        try {
+            if (groupIds == null || groupIds.isEmpty()) {
+                log.warn("鎵归噺鍚敤璁惧缁�: 璁惧缁処D鍒楄〃涓虹┖");
+                return false;
+            }
+
+            // 鎵归噺鏇存柊璁惧缁勭姸鎬�
+            LambdaUpdateWrapper<DeviceGroupConfig> updateWrapper = new LambdaUpdateWrapper<>();
+            updateWrapper.in(DeviceGroupConfig::getId, groupIds)
+                        .set(DeviceGroupConfig::getStatus, DeviceGroupConfig.Status.ENABLED);
+            
+            boolean result = update(updateWrapper);
+            
+            if (result) {
+                log.info("鎵归噺鍚敤璁惧缁勬垚鍔�: {} 涓澶囩粍", groupIds.size());
+            } else {
+                log.error("鎵归噺鍚敤璁惧缁勫け璐�");
+            }
+            
+            return result;
+        } catch (Exception e) {
+            log.error("鎵归噺鍚敤璁惧缁勫紓甯�", e);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean batchDisableDeviceGroups(java.util.List<Long> groupIds) {
+        try {
+            if (groupIds == null || groupIds.isEmpty()) {
+                log.warn("鎵归噺绂佺敤璁惧缁�: 璁惧缁処D鍒楄〃涓虹┖");
+                return false;
+            }
+
+            // 鎵归噺鏇存柊璁惧缁勭姸鎬�
+            LambdaUpdateWrapper<DeviceGroupConfig> updateWrapper = new LambdaUpdateWrapper<>();
+            updateWrapper.in(DeviceGroupConfig::getId, groupIds)
+                        .set(DeviceGroupConfig::getStatus, DeviceGroupConfig.Status.DISABLED);
+            
+            boolean result = update(updateWrapper);
+            
+            if (result) {
+                log.info("鎵归噺绂佺敤璁惧缁勬垚鍔�: {} 涓澶囩粍", groupIds.size());
+            } else {
+                log.error("鎵归噺绂佺敤璁惧缁勫け璐�");
+            }
+            
+            return result;
+        } catch (Exception e) {
+            log.error("鎵归噺绂佺敤璁惧缁勫紓甯�", e);
+            return false;
+        }
+    }
+
+    @Override
+    public java.util.List<String> getAllGroupTypes() {
+        try {
+            // 杩斿洖棰勫畾涔夌殑璁惧缁勭被鍨嬪垪琛�
+            java.util.List<String> groupTypes = new java.util.ArrayList<>();
+            groupTypes.add("PRODUCTION");
+            groupTypes.add("QUALITY_CONTROL");
+            groupTypes.add("LOGISTICS");
+            groupTypes.add("MAINTENANCE");
+            groupTypes.add("MONITORING");
+            
+            log.debug("鑾峰彇璁惧缁勭被鍨嬪垪琛�: {} 涓被鍨�", groupTypes.size());
+            return groupTypes;
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧缁勭被鍨嬪垪琛ㄥけ璐�", e);
+            return new java.util.ArrayList<>();
+        }
+    }
+
+    @Override
+    public java.util.List<String> getAllGroupStatuses() {
+        try {
+            // 杩斿洖棰勫畾涔夌殑璁惧缁勭姸鎬佸垪琛�
+            java.util.List<String> groupStatuses = new java.util.ArrayList<>();
+            groupStatuses.add("ENABLED");
+            groupStatuses.add("DISABLED");
+            groupStatuses.add("MAINTENANCE");
+            groupStatuses.add("OFFLINE");
+            
+            log.debug("鑾峰彇璁惧缁勭姸鎬佸垪琛�: {} 涓姸鎬�", groupStatuses.size());
+            return groupStatuses;
+        } catch (Exception e) {
+            log.error("鑾峰彇璁惧缁勭姸鎬佸垪琛ㄥけ璐�", e);
+            return new java.util.ArrayList<>();
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.8.0