From 366ba040d2447bacd3455299425e3166f1f992bb Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期四, 20 十一月 2025 14:38:32 +0800
Subject: [PATCH] 添加大车、大理片笼以及多设备串行/并行执行写入基础逻辑
---
mes-processes/mes-plcSend/src/main/java/com/mes/device/service/impl/DeviceGroupConfigServiceImpl.java | 107 +++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 98 insertions(+), 9 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
index 2a229c2..05c19fa 100644
--- 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
@@ -7,7 +7,9 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mes.device.entity.DeviceGroupConfig;
+import com.mes.device.entity.DeviceGroupRelation;
import com.mes.device.mapper.DeviceGroupConfigMapper;
+import com.mes.device.mapper.DeviceGroupRelationMapper;
import com.mes.device.service.DeviceGroupConfigService;
import com.mes.device.vo.DeviceGroupConfigVO;
import com.mes.device.vo.DeviceGroupVO;
@@ -27,6 +29,12 @@
public class DeviceGroupConfigServiceImpl extends ServiceImpl<DeviceGroupConfigMapper, DeviceGroupConfig> implements DeviceGroupConfigService {
private final ObjectMapper objectMapper = new ObjectMapper();
+ private final DeviceGroupRelationMapper deviceGroupRelationMapper;
+ private static final TypeReference<Map<String, Object>> MAP_TYPE = new TypeReference<Map<String, Object>>() {};
+
+ public DeviceGroupConfigServiceImpl(DeviceGroupRelationMapper deviceGroupRelationMapper) {
+ this.deviceGroupRelationMapper = deviceGroupRelationMapper;
+ }
@Override
public boolean createDeviceGroup(DeviceGroupConfig groupConfig) {
@@ -194,6 +202,7 @@
vo.setGroupType(getGroupTypeName(group.getGroupType()));
vo.setStatus(getStatusName(group.getStatus()));
vo.setDeviceCount(getDeviceCountByGroupId(group.getId()));
+ vo.setOnlineDeviceCount(getOnlineDeviceCountByGroupId(group.getId()));
vo.setCreateTime(group.getCreatedTime());
vo.setProjectId(group.getProjectId());
return vo;
@@ -212,7 +221,6 @@
@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 -> {
@@ -225,8 +233,8 @@
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.setLocation(extractLocationFromExtraConfig(group));
+ vo.setSupervisor(extractSupervisorFromExtraConfig(group));
vo.setCreatedTime(new Date());
vo.setUpdatedTime(new Date());
vo.setProjectId(group.getProjectId());
@@ -425,9 +433,37 @@
@Override
public int getDeviceCountByGroupId(Long groupId) {
- // 杩欓噷闇�瑕佹煡璇evice_group_relation琛ㄦ潵鑾峰彇璁惧鏁伴噺
- // 绠�鍖栧疄鐜帮紝瀹為檯闇�瑕佹敞鍏eviceGroupRelationMapper
- return 0; // TODO: 瀹炵幇鐪熷疄閫昏緫
+ if (groupId == null) {
+ return 0;
+ }
+ try {
+ LambdaQueryWrapper<DeviceGroupRelation> wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(DeviceGroupRelation::getGroupId, groupId)
+ .eq(DeviceGroupRelation::getIsDeleted, 0);
+ return (int) deviceGroupRelationMapper.selectCount(wrapper);
+ } catch (Exception e) {
+ log.error("鑾峰彇璁惧缁勮澶囨暟閲忓け璐�, groupId={}", groupId, e);
+ return 0;
+ }
+ }
+
+ /**
+ * 鑾峰彇璁惧缁勪笅鐨勫湪绾胯澶囨暟閲�
+ *
+ * @param groupId 璁惧缁処D
+ * @return 鍦ㄧ嚎璁惧鏁伴噺
+ */
+ private int getOnlineDeviceCountByGroupId(Long groupId) {
+ if (groupId == null) {
+ return 0;
+ }
+ try {
+ Integer count = deviceGroupRelationMapper.getOnlineDeviceCountByGroupId(groupId);
+ return count != null ? count : 0;
+ } catch (Exception e) {
+ log.error("鑾峰彇璁惧缁勫湪绾胯澶囨暟閲忓け璐�, groupId={}", groupId, e);
+ return 0;
+ }
}
/**
@@ -577,8 +613,8 @@
// 鑾峰彇璁惧缁勪笅鐨勮澶囨暟閲�
int totalDevices = getDeviceCountByGroupId(groupId);
- // 鑾峰彇鍦ㄧ嚎璁惧鏁伴噺
- int activeDevices = 0; // TODO: 闇�瑕佹牴鎹疄闄呬笟鍔¢�昏緫瀹炵幇
+ // 鑾峰彇鍦ㄧ嚎璁惧鏁伴噺锛堢姸鎬佷负姝e父鐨勮澶囨暟锛�
+ int activeDevices = getActiveDeviceCountByGroupId(groupId);
// 璁$畻骞冲潎鎬ц兘鎸囨爣锛堟ā鎷熸暟鎹級
double averageCpuUsage = 45.5; // CPU浣跨敤鐜囩櫨鍒嗘瘮
@@ -628,7 +664,7 @@
// 鑾峰彇璁惧缁勪笅鐨勮澶囦俊鎭�
int totalDevices = getDeviceCountByGroupId(groupId);
- int onlineDevices = 0; // TODO: 闇�瑕佹牴鎹疄闄呬笟鍔¢�昏緫瀹炵幇
+ int onlineDevices = getActiveDeviceCountByGroupId(groupId);
int offlineDevices = totalDevices - onlineDevices;
// 璁$畻鍋ュ悍鐘舵��
@@ -792,6 +828,59 @@
}
}
+ /**
+ * 浠庢墿灞曢厤缃腑鎻愬彇浣嶇疆淇℃伅
+ */
+ private String extractLocationFromExtraConfig(DeviceGroupConfig group) {
+ if (group == null || group.getExtraConfig() == null) {
+ return "榛樿浣嶇疆";
+ }
+ try {
+ Map<String, Object> extraConfig = objectMapper.readValue(group.getExtraConfig(), MAP_TYPE);
+ Object location = extraConfig.get("location");
+ return location != null ? String.valueOf(location) : "榛樿浣嶇疆";
+ } catch (Exception e) {
+ log.warn("瑙f瀽璁惧缁勪綅缃俊鎭け璐�, groupId={}", group.getId(), e);
+ return "榛樿浣嶇疆";
+ }
+ }
+
+ /**
+ * 浠庢墿灞曢厤缃腑鎻愬彇绠$悊鍛樹俊鎭�
+ */
+ private String extractSupervisorFromExtraConfig(DeviceGroupConfig group) {
+ if (group == null || group.getExtraConfig() == null) {
+ return "榛樿绠$悊鍛�";
+ }
+ try {
+ Map<String, Object> extraConfig = objectMapper.readValue(group.getExtraConfig(), MAP_TYPE);
+ Object supervisor = extraConfig.get("supervisor");
+ return supervisor != null ? String.valueOf(supervisor) : "榛樿绠$悊鍛�";
+ } catch (Exception e) {
+ log.warn("瑙f瀽璁惧缁勭鐞嗗憳淇℃伅澶辫触, groupId={}", group.getId(), e);
+ return "榛樿绠$悊鍛�";
+ }
+ }
+
+ /**
+ * 鑾峰彇璁惧缁勪腑娲昏穬璁惧鏁伴噺锛堢姸鎬佷负姝e父鐨勮澶囷級
+ */
+ private int getActiveDeviceCountByGroupId(Long groupId) {
+ if (groupId == null) {
+ return 0;
+ }
+ try {
+ LambdaQueryWrapper<DeviceGroupRelation> wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(DeviceGroupRelation::getGroupId, groupId)
+ .eq(DeviceGroupRelation::getStatus, DeviceGroupRelation.Status.NORMAL)
+ .eq(DeviceGroupRelation::getIsDeleted, 0);
+ return (int) deviceGroupRelationMapper.selectCount(wrapper);
+ } catch (Exception e) {
+ log.error("鑾峰彇璁惧缁勬椿璺冭澶囨暟閲忓け璐�, groupId={}", groupId, e);
+ return 0;
+ }
+ }
+
@Override
public java.util.List<String> getAllGroupStatuses() {
try {
--
Gitblit v1.8.0