From 837e662c8ded3ded45f9d067aa84fdede1e4b7e0 Mon Sep 17 00:00:00 2001 From: "3067418132@qq.com" Date: Thu, 2 Apr 2026 13:40:40 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=83=AD=E6=B0=B4=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E7=9B=91=E6=8E=A7=E7=95=8C=E9=9D=A2=E6=98=BE=E7=A4=BA=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E6=8E=A5=E5=8F=A3=E6=9B=B4=E6=94=B9=EF=BC=9B=202?= =?UTF-8?q?=E3=80=81=E5=90=AF=E5=8A=A8=E5=86=85=E5=AE=B9=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mh-admin/src/main/java/com/mh/MHRunner.java | 33 +++++- .../core/domain/dto/HotWaterNowDataDTO.java | 10 +- .../device/CollectionParamsManageMapper.java | 4 +- .../CollectionParamsManageServiceImpl.java | 106 ++++++++++-------- 4 files changed, 102 insertions(+), 51 deletions(-) diff --git a/mh-admin/src/main/java/com/mh/MHRunner.java b/mh-admin/src/main/java/com/mh/MHRunner.java index 9338c21..59c922c 100644 --- a/mh-admin/src/main/java/com/mh/MHRunner.java +++ b/mh-admin/src/main/java/com/mh/MHRunner.java @@ -1,14 +1,19 @@ package com.mh; +import com.mh.common.core.domain.entity.GatewayManage; import com.mh.common.core.domain.entity.MqttSubscription; import com.mh.common.utils.StringUtils; import com.mh.framework.mqtt.service.IMqttTopicService; +import com.mh.framework.netty.EchoServer; +import com.mh.system.service.device.ICollectionParamsManageService; +import com.mh.system.service.device.IGatewayManageService; import com.mh.system.service.mqtt.IMqttSubscriptionService; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; import java.util.List; +import java.util.stream.Collectors; /** * @author LJF @@ -24,15 +29,41 @@ public class MHRunner implements ApplicationRunner { private final IMqttTopicService iMqttTopicService; - public MHRunner(IMqttSubscriptionService iMqttSubscriptionService, IMqttTopicService iMqttTopicService) { + private final ICollectionParamsManageService collectionParamsManageService; + + private final IGatewayManageService gatewayManageService; + + public MHRunner(IMqttSubscriptionService iMqttSubscriptionService, IMqttTopicService iMqttTopicService, ICollectionParamsManageService collectionParamsManageService, IGatewayManageService gatewayManageService) { this.iMqttSubscriptionService = iMqttSubscriptionService; this.iMqttTopicService = iMqttTopicService; + this.collectionParamsManageService = collectionParamsManageService; + this.gatewayManageService = gatewayManageService; } @Override public void run(ApplicationArguments args) throws Exception { // 初始化mqtt订阅记录 initializeMqttSubscription(); + // 生成DTU采集参数 + createDtuCollectionParams(); + // 启动netty服务端 + startNettyServer(); + } + + private void startNettyServer() { + List gatewayManages = gatewayManageService.selectGwManageList(new GatewayManage()); + if (gatewayManages != null && !gatewayManages.isEmpty()) { + // 根据端口号分组 + gatewayManages.stream().collect(Collectors.groupingBy(GatewayManage::getPort)).forEach((k, v) -> { + // 启动网关 + GatewayManage gatewayManage = v.getFirst(); + new Thread(() -> new EchoServer(gatewayManage.getPort()).start()).start(); + }); + } + } + + private void createDtuCollectionParams() { + collectionParamsManageService.createDtuCollectionParams(); } /** diff --git a/mh-common/src/main/java/com/mh/common/core/domain/dto/HotWaterNowDataDTO.java b/mh-common/src/main/java/com/mh/common/core/domain/dto/HotWaterNowDataDTO.java index bdded5a..49e3f99 100644 --- a/mh-common/src/main/java/com/mh/common/core/domain/dto/HotWaterNowDataDTO.java +++ b/mh-common/src/main/java/com/mh/common/core/domain/dto/HotWaterNowDataDTO.java @@ -22,10 +22,16 @@ public class HotWaterNowDataDTO { private String waterTemp; //水箱水温 private String runState; //运行状态 private String isFault; //是否故障 - private String levelSet; //水位设置 - private String waterLevel; //实际水位 + private String levelSet; //水位1设置 + private String levelSet2; //水位2设置 + private String waterLevel1; //实际1水位 + private String waterLevel2; //实际2水位 private String tankId; //水箱编号 private String tankName; //水箱名称 + private String tankWaterTemp; // 水箱1温度 + private String tankWaterTemp2; // 水箱2温度 + private String tankId2; //水箱2编号 + private String tankName2; //水箱2名称 private String envTemp; //环境温度 private String upWaterState1; // 供水1泵状态 diff --git a/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java b/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java index 4d14af4..686e64f 100644 --- a/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java +++ b/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java @@ -221,7 +221,7 @@ public interface CollectionParamsManageMapper extends BaseMapper" + "select " + - " hi.house_name || right(cpm.other_name, 4) as name, " + + " hi.house_name || right(cpm.other_name, 3) as name, " + " cpm.cur_value as value, " + " cpm.cur_time as \"curTime\" " + "from " + @@ -250,7 +250,7 @@ public interface CollectionParamsManageMapper extends BaseMapper dto.setFreq2(new BigDecimal(freq2.getCollectValue()).setScale(2, RoundingMode.HALF_UP).toString())); } - // 处理水箱,水箱绑定了补水阀参数(deviceType=16) - List waterValves = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "16"); + // 处理水箱:液位、温度 + List waterValves = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "17"); if (!waterValves.isEmpty()) { - // 判断是否存在collectValue>0的记录 - boolean useWaterState = waterValves.stream() - .anyMatch(vo -> "2".equals(vo.getParamType()) - && vo.getCollectValue() != null - && new BigDecimal(vo.getCollectValue()).intValue() > 0); - // 根据判断结果设置状态值 - result.forEach(dto -> dto.setUseWaterState(useWaterState ? "1" : "0")); + // 遍历液位 + waterValves.stream() + .filter(vo -> "11".equals(vo.getParamType()) && vo.getCollectValue() != null) + .forEach(vo -> { + if (vo.getOrderNum()==1) { + result.forEach(dto -> dto.setWaterLevel1(vo.getCollectValue())); + } else if (vo.getOrderNum()==2) { + result.forEach(dto -> dto.setWaterLevel2(vo.getCollectValue())); + } + }); + // 遍历温度 + waterValves.stream() + .filter(vo -> "12".equals(vo.getParamType()) && vo.getCollectValue() != null) + .forEach(vo -> { + if (vo.getOrderNum()==1) { + result.forEach(dto -> dto.setTankWaterTemp(vo.getCollectValue())); + } else if (vo.getOrderNum()==2) { + result.forEach(dto -> dto.setTankWaterTemp2(vo.getCollectValue())); + } + }); + } // 处理回水阀(deviceType=22) @@ -756,43 +770,43 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag } - // 处理水箱液位(deviceType=16) - List waterLevels = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "16"); - if (!waterLevels.isEmpty()) { - // 计算levelSet平均值(paramType=10) - Double levelSetAvg = waterLevels.stream() - .filter(vo -> vo.getParamType().equals("10")) - .mapToDouble(vo -> { - try { - return Double.parseDouble(vo.getCollectValue()); - } catch (NumberFormatException e) { - log.error("数值转换失败:设备ID={} 值={}", vo.getId(), vo.getCollectValue()); - return 0.0; // 返回默认值 - } - }) - .average() - .orElse(0.0); - - // 计算waterLevel平均值(paramType=11) - Double waterLevelAvg = waterLevels.stream() - .filter(vo -> vo.getParamType().equals("11")) - .mapToDouble(vo -> { - try { - return Double.parseDouble(vo.getCollectValue()); - } catch (NumberFormatException e) { - log.error("数值转换失败:设备ID={} 值={}", vo.getId(), vo.getCollectValue()); - return 0.0; // 返回默认值 - } - }) - .average() - .orElse(0.0); - - // 设置平均值到所有DTO(根据业务需求调整) - result.forEach(dto -> { - dto.setLevelSet(String.format("%.2f", levelSetAvg)); - dto.setWaterLevel(String.format("%.2f", waterLevelAvg)); - }); - } +// // 处理水箱液位(deviceType=16) +// List waterLevels = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "16"); +// if (!waterLevels.isEmpty()) { +// // 计算levelSet平均值(paramType=10) +// Double levelSetAvg = waterLevels.stream() +// .filter(vo -> vo.getParamType().equals("10")) +// .mapToDouble(vo -> { +// try { +// return Double.parseDouble(vo.getCollectValue()); +// } catch (NumberFormatException e) { +// log.error("数值转换失败:设备ID={} 值={}", vo.getId(), vo.getCollectValue()); +// return 0.0; // 返回默认值 +// } +// }) +// .average() +// .orElse(0.0); +// +// // 计算waterLevel平均值(paramType=11) +// Double waterLevelAvg = waterLevels.stream() +// .filter(vo -> vo.getParamType().equals("11")) +// .mapToDouble(vo -> { +// try { +// return Double.parseDouble(vo.getCollectValue()); +// } catch (NumberFormatException e) { +// log.error("数值转换失败:设备ID={} 值={}", vo.getId(), vo.getCollectValue()); +// return 0.0; // 返回默认值 +// } +// }) +// .average() +// .orElse(0.0); +// +// // 设置平均值到所有DTO(根据业务需求调整) +// result.forEach(dto -> { +// dto.setLevelSet(String.format("%.2f", levelSetAvg)); +// dto.setWaterLevel(String.format("%.2f", waterLevelAvg)); +// }); +// } // result再根据orderNum排序 return result.stream()