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