Browse Source

1、热水系统监控界面显示内容接口更改;

2、启动内容添加;
dev
3067418132@qq.com 3 days ago
parent
commit
837e662c8d
  1. 33
      mh-admin/src/main/java/com/mh/MHRunner.java
  2. 10
      mh-common/src/main/java/com/mh/common/core/domain/dto/HotWaterNowDataDTO.java
  3. 4
      mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java
  4. 106
      mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java

33
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<GatewayManage> 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();
}
/**

10
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泵状态

4
mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java

@ -221,7 +221,7 @@ public interface CollectionParamsManageMapper extends BaseMapper<CollectionParam
@Select("<script>" +
"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<CollectionParam
@Select("select " +
" dl.id, " +
" dl.device_name, " +
" cpm.cur_value as collectValue, " +
" ROUND(cpm.cur_value, 1) as collectValue, " +
" cpm.cur_time as collectTime, " +
" cpm.param_type as paramType, " +
" cpm.other_name as collectName, " +

106
mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java

@ -731,16 +731,30 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag
result.forEach(dto -> dto.setFreq2(new BigDecimal(freq2.getCollectValue()).setScale(2, RoundingMode.HALF_UP).toString()));
}
// 处理水箱,水箱绑定了补水阀参数(deviceType=16)
List<DeviceMonitorVO> waterValves = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "16");
// 处理水箱:液位、温度
List<DeviceMonitorVO> 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<DeviceMonitorVO> 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<DeviceMonitorVO> 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()

Loading…
Cancel
Save