Browse Source

1、生活热水监视界面

dev
mh 2 months ago
parent
commit
de9b657e69
  1. 2
      mh-admin/src/main/java/com/mh/web/controller/device/OperationController.java
  2. 15
      mh-admin/src/main/java/com/mh/web/controller/monitor/HotWaterMonitorController.java
  3. 8
      mh-common/src/main/java/com/mh/common/core/domain/ColumnFilter.java
  4. 39
      mh-common/src/main/java/com/mh/common/core/domain/dto/HotWaterNowDataDTO.java
  5. 2
      mh-common/src/main/java/com/mh/common/core/domain/entity/HouseInfo.java
  6. 3
      mh-common/src/main/java/com/mh/common/core/domain/vo/DeviceMonitorVO.java
  7. 50
      mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java
  8. 18
      mh-system/src/main/java/com/mh/system/service/device/ICollectionParamsManageService.java
  9. 142
      mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java
  10. 13
      sql/初始化采集参数.sql

2
mh-admin/src/main/java/com/mh/web/controller/device/OperationController.java

@ -59,7 +59,7 @@ public class OperationController extends BaseController {
* @param systemType
* @return
*/
@PreAuthorize("@ss.hasPermi('device:cpm:operation')")
@PreAuthorize("@ss.hasPermi('device:cpm:operationList')")
@GetMapping("/operation/list")
public TableDataInfo operationDeviceList(@RequestParam(name = "systemType") String systemType) {
try {

15
mh-admin/src/main/java/com/mh/web/controller/monitor/HotWaterMonitorController.java

@ -1,6 +1,9 @@
package com.mh.web.controller.monitor;
import com.mh.common.core.controller.BaseController;
import com.mh.common.core.domain.ColumnData;
import com.mh.common.core.domain.ColumnFilter;
import com.mh.common.core.domain.dto.HotWaterNowDataDTO;
import com.mh.common.core.domain.dto.PumpInfoDTO;
import com.mh.common.core.domain.entity.ChillersEntity;
import com.mh.common.core.page.TableDataInfo;
@ -31,6 +34,18 @@ public class HotWaterMonitorController extends BaseController {
this.iCollectionParamsManageService = iCollectionParamsManageService;
}
@GetMapping("/monitorPublic")
public TableDataInfo monitorPublic(@RequestParam("systemType") String systemType, @RequestParam("floorId") String floorId) {
List<ColumnFilter> list = iCollectionParamsManageService.monitorPublic(systemType, floorId);
return getDataTable(list);
}
@GetMapping("/monitorList")
public TableDataInfo monitorList(@RequestParam("systemType") String systemType, @RequestParam("floorId") String floorId) {
List<HotWaterNowDataDTO> list = iCollectionParamsManageService.monitorList(systemType, floorId);
return getDataTable(list);
}
@GetMapping("/pumpListInfo")
public TableDataInfo list(@RequestParam("registerAddr") String registerAddr,
@RequestParam("mtType") String mtType) {

8
mh-common/src/main/java/com/mh/common/core/domain/ColumnFilter.java

@ -16,6 +16,14 @@ public class ColumnFilter {
*/
private String value;
public ColumnFilter(String name, String value) {
this.name = name;
this.value = value;
}
public ColumnFilter() {
}
public String getName() {
return name;
}

39
mh-common/src/main/java/com/mh/common/core/domain/dto/HotWaterNowDataDTO.java

@ -0,0 +1,39 @@
package com.mh.common.core.domain.dto;
import lombok.Data;
/**
* @author LJF
* @version 1.0
* @project EEMCS
* @description 热水实时监控列表数据
* @date 2025-03-10 15:43:36
*/
@Data
public class HotWaterNowDataDTO {
private String id;
private String curDate; //日期
private String buildingId; //楼栋编号
private String buildingName; //楼栋名称
private String pumpId; //热泵编号
private String pumpName; //热泵名称
private String tempSet; //水温设定
private String waterTemp; //水箱水温
private String runState; //运行状态
private String isFault; //是否故障
private String levelSet; //水位设置
private String waterLevel; //实际水位
private String tankId; //水箱编号
private String tankName; //水箱名称
private String envTemp; //环境温度
private String upWaterState; // 供水状态
private String useWaterState; // 补水状态
private String backWaterState; // 回水状态
private int orderNum;
}

2
mh-common/src/main/java/com/mh/common/core/domain/entity/HouseInfo.java

@ -90,6 +90,8 @@ public class HouseInfo extends BaseEntity {
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, Object> params;
private int orderNum;
@Override
public String toString() {
return new ToStringBuilder(this)

3
mh-common/src/main/java/com/mh/common/core/domain/vo/DeviceMonitorVO.java

@ -60,6 +60,8 @@ public class DeviceMonitorVO {
*/
private String paramType;
private int orderNum;
@Override
public String toString() {
return new ToStringBuilder(this)
@ -71,6 +73,7 @@ public class DeviceMonitorVO {
.append("collectTime", collectTime)
.append("collectValue", collectValue)
.append("paramType", paramType)
.append("orderNum", orderNum)
.toString();
}
}

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

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mh.common.core.domain.dto.TempHumidityDTO;
import com.mh.common.core.domain.entity.CollectionParamsManage;
import com.mh.common.core.domain.vo.CollectionParamsManageVO;
import com.mh.common.core.domain.vo.DeviceMonitorVO;
import org.apache.ibatis.annotations.*;
import java.util.List;
@ -164,4 +165,53 @@ public interface CollectionParamsManageMapper extends BaseMapper<CollectionParam
" and cpm.param_type != '0' " +
" order by dl.device_type, cpm.param_type ")
List<CollectionParamsManageVO> selectBySystemType(@Param("systemType") String systemType);
@Select("select " +
" hi.house_name || right(cpm.other_name, " +
" 4) as name, " +
" cpm.cur_value as value, " +
" cpm.cur_time as curTime " +
"from " +
" collection_params_manage cpm " +
"left join device_ledger dl on " +
" cpm.device_ledger_id = dl.id " +
"left join cpm_space_relation csr on " +
" cpm.id = csr.cpm_id " +
"left join house_info hi on " +
" csr.house_id = hi.id " +
"where " +
" (cpm.param_type = '12' " +
" or cpm.param_type = '13') " +
" and (dl.device_type = '13' " +
" or dl.device_type = '14') " +
" and csr.floor_id = #{floorId} " +
" and cpm.system_type = #{systemType}" +
" order by hi.house_name, cpm.param_type ")
List<Map<String, Object>> selectBySystemTypeAndBuildingId(@Param("systemType") String systemType,
@Param("floorId") String floor_id);
@Select("select " +
" dl.id, " +
" dl.device_name, " +
" cpm.cur_value as collectValue, " +
" cpm.cur_time as collectTime, " +
" cpm.param_type as paramType, " +
" cpm.other_name as collectName, " +
" dl.order_num as orderNum " +
"from " +
" collection_params_manage cpm " +
"left join device_ledger dl on " +
" cpm.device_ledger_id = dl.id " +
"left join cpm_space_relation csr on " +
" cpm.id = csr.cpm_id " +
"left join house_info hi on " +
" csr.house_id = hi.id " +
"where " +
" (dl.device_type = #{deviceType}) " +
" and csr.floor_id = #{floorId} " +
" and cpm.system_type = #{systemType} " +
" order by cpm.param_type,dl.order_num ")
List<DeviceMonitorVO> selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(@Param("systemType") String systemType,
@Param("floorId") String floorId,
@Param("deviceType") String deviceType);
}

18
mh-system/src/main/java/com/mh/system/service/device/ICollectionParamsManageService.java

@ -1,6 +1,8 @@
package com.mh.system.service.device;
import com.mh.common.core.domain.ColumnFilter;
import com.mh.common.core.domain.dto.DeviceMonitorDTO;
import com.mh.common.core.domain.dto.HotWaterNowDataDTO;
import com.mh.common.core.domain.dto.PumpInfoDTO;
import com.mh.common.core.domain.entity.ChillersEntity;
import com.mh.common.core.domain.entity.CollectionParamsManage;
@ -41,4 +43,20 @@ public interface ICollectionParamsManageService {
List<DeviceMonitorDTO> selectMonitorListBySystemType(String systemType);
List<DeviceOperateMonitorVO> operationDeviceList(String systemType);
/**
* 查询生活热水系统设备监视公共信息内容
* @param systemType
* @param buildingId
* @return
*/
List<ColumnFilter> monitorPublic(String systemType, String buildingId);
/**
* 查询生活热水系统设备监视列表
* @param systemType
* @param floorId
* @return
*/
List<HotWaterNowDataDTO> monitorList(String systemType, String floorId);
}

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

@ -1,7 +1,9 @@
package com.mh.system.service.device.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mh.common.core.domain.ColumnFilter;
import com.mh.common.core.domain.dto.DeviceMonitorDTO;
import com.mh.common.core.domain.dto.HotWaterNowDataDTO;
import com.mh.common.core.domain.dto.PumpInfoDTO;
import com.mh.common.core.domain.entity.ChillersEntity;
import com.mh.common.core.domain.entity.CollectionParamsManage;
@ -17,13 +19,15 @@ import com.mh.system.mapper.device.DeviceLedgerMapper;
import com.mh.system.mapper.device.GatewayManageMapper;
import com.mh.system.service.device.ICollectionParamsManageService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -33,6 +37,7 @@ import java.util.stream.Collectors;
* @description 设备采集参数配置
* @date 2025-01-13 16:33:47
*/
@Slf4j
@Service
public class CollectionParamsManageServiceImpl implements ICollectionParamsManageService {
@ -298,4 +303,135 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag
});
return monitorData;
}
@Override
public List<ColumnFilter> monitorPublic(String systemType, String floorId) {
List<Map<String, Object>> mapList = collectionParamsManageMapper.selectBySystemTypeAndBuildingId(systemType, floorId);
// stream流判断mapList中的数据curTime是否为今天日期,假如不是今天日期,则重新赋值value为"采集失败",然后响应赋值给List<ColumnFilter>
return mapList.stream()
.map(map -> {
// 1. 获取当前记录的 curTime 和 value
Object curTimeObj = map.get("curTime");
// 2. 判断 curTime 是否为今天
boolean isToday = false;
try {
if (curTimeObj != null) {
// 假设 curTime 是 Date 类型(根据实际数据库类型调整)
Date curTime = (Date) curTimeObj;
LocalDate recordDate = curTime.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
LocalDate today = LocalDate.now();
isToday = recordDate.isEqual(today);
}
} catch (Exception e) {
// 处理日期解析异常(如类型不匹配)
log.error("日期解析失败: {}", curTimeObj, e);
}
// 3. 如果非今天或 curTime 为空,设置 value 为采集失败
if (!isToday || curTimeObj == null) {
map.put("value", "采集失败");
} else {
// 4.1 如果是今天,设置 value 为采集到的值
map.put("value", new BigDecimal(String.valueOf(map.get("value"))).setScale(0, RoundingMode.HALF_UP).toString());
}
// 4. 转换为 ColumnFilter 对象(假设构造函数为 ColumnFilter(name, value))
return new ColumnFilter(
(String) map.get("name"),
(String) map.get("value")
);
})
.collect(Collectors.toList());
}
@Override
public List<HotWaterNowDataDTO> monitorList(String systemType, String floorId) {
// 处理热泵设备(deviceType=11)
List<DeviceMonitorVO> hotPumps = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "11");
Map<String, List<DeviceMonitorVO>> hotPumpGroups = hotPumps.stream()
.collect(Collectors.groupingBy(DeviceMonitorVO::getId));
List<HotWaterNowDataDTO> result = hotPumpGroups.values().stream().map(group -> {
HotWaterNowDataDTO dto = new HotWaterNowDataDTO();
group.forEach(vo -> {
dto.setId(vo.getId());
dto.setPumpId(vo.getId());
dto.setPumpName(vo.getDeviceName());
dto.setCurDate(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", vo.getCollectTime()));
dto.setCurDate(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", vo.getCollectTime()));
dto.setOrderNum(vo.getOrderNum());
switch(vo.getParamType()) {
case "2": // 运行状态
dto.setRunState(vo.getCollectValue());
break;
case "5": // 故障状态
dto.setIsFault(vo.getCollectValue());
break;
case "14": // 温度设置
dto.setTempSet(vo.getCollectValue());
break;
case "12": // 水温
dto.setWaterTemp(vo.getCollectValue());
break;
}
});
return dto;
}).collect(Collectors.toList());
// 处理供水泵(deviceType=10)
List<DeviceMonitorVO> waterPumps = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "10");
// 判断是否存在collectValue>0的记录
boolean hasValidCollectValue = waterPumps.stream()
.anyMatch(vo -> "1".equals(vo.getParamType())
&& vo.getCollectValue() != null
&& new BigDecimal(vo.getCollectValue()).intValue() > 0);
// 根据判断结果设置状态值
result.forEach(dto -> dto.setUpWaterState(hasValidCollectValue ? "1" : "0"));
// 处理水箱液位(deviceType=12)
List<DeviceMonitorVO> waterLevels = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "12");
// 计算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()
.sorted(Comparator.comparingInt(HotWaterNowDataDTO::getOrderNum))
.collect(Collectors.toList());
}
}

13
sql/初始化采集参数.sql

@ -78,3 +78,16 @@ INSERT INTO "public"."collection_params_manage" ("id", "device_ledger_id", "mt_t
INSERT INTO "public"."collection_params_manage" ("id", "device_ledger_id", "mt_type", "mt_num", "mt_code", "register_addr", "func_code", "identify_code", "mt_caliber_pulse", "mt_range", "mt_ratio", "mt_init_value", "digits", "data_type", "cur_value", "cur_time", "mt_is_sum", "unit", "sort", "gateway_id", "communication_param_id", "protocol_type", "communication_type", "remark", "register_size", "is_use", "create_time", "update_time", "create_by", "update_by", "other_name", "grade", "param_type", "system_type", "collection_type", "terminal_device_type") VALUES ('233034ed16a1b3179a27332526b2d81d', '5485aaa03ee8b8badfafec0cb03a70b1', '0', '3', '3', '0002', '03', '', '', NULL, 1, '0.000', 0, 0, NULL, NULL, 0, '', 0, '1', '2', '1', '0', '', 2, 0, '2025-03-07 17:05:51.48', NULL, 'mhtech', NULL, '5号冷却泵故障报警', 140, '5', '0', '1', '0');
INSERT INTO "public"."collection_params_manage" ("id", "device_ledger_id", "mt_type", "mt_num", "mt_code", "register_addr", "func_code", "identify_code", "mt_caliber_pulse", "mt_range", "mt_ratio", "mt_init_value", "digits", "data_type", "cur_value", "cur_time", "mt_is_sum", "unit", "sort", "gateway_id", "communication_param_id", "protocol_type", "communication_type", "remark", "register_size", "is_use", "create_time", "update_time", "create_by", "update_by", "other_name", "grade", "param_type", "system_type", "collection_type", "terminal_device_type") VALUES ('2d30344d2639b3a79186332286b2h811', '5485aaa03ee8b8badfafec0cb03a70b1', '0', '3', '3', '0003', '03', '', '', NULL, 1, '0.000', 0, 0, NULL, NULL, 0, '', 0, '1', '2', '1', '0', '', 2, 0, '2025-03-07 17:05:51.48', NULL, 'mhtech', NULL, '5号冷却泵手自动状态', 140, '6', '0', '1', '0');
INSERT INTO "public"."collection_params_manage" ("id", "device_ledger_id", "mt_type", "mt_num", "mt_code", "register_addr", "func_code", "identify_code", "mt_caliber_pulse", "mt_range", "mt_ratio", "mt_init_value", "digits", "data_type", "cur_value", "cur_time", "mt_is_sum", "unit", "sort", "gateway_id", "communication_param_id", "protocol_type", "communication_type", "remark", "register_size", "is_use", "create_time", "update_time", "create_by", "update_by", "other_name", "grade", "param_type", "system_type", "collection_type", "terminal_device_type") VALUES ('2830347dw6a9bha71a86337296b24h12', '5485aaa03ee8b8badfafec0cb03a70b1', '0', '3', '3', '0004', '03', '', '', NULL, 1, '0.000', 0, 0, NULL, NULL, 0, '', 0, '1', '2', '1', '0', '', 2, 0, '2025-03-07 17:05:51.48', NULL, 'mhtech', NULL, '5号冷却泵启停控制', 140, '2', '0', '1', '0');
insert into cpm_space_relation(id,cpm_id,area_id,building_id,floor_id,house_id,create_by,create_time)
select
cpm.id,
cpm.id,
'6e0328147a051b79c81a215c1ffda9e3',
'73138702b71e16d200b458185bb07e59',
'e3dc9e3d0aa7c07d3b6db9ce8c119f3d',
'059018cd0679ec7ad73df96a3c44f9f3',
'mhtech',
current_timestamp
from collection_params_manage cpm where cpm.system_type = '1' and (cpm.other_name like '4号%水温度%' )

Loading…
Cancel
Save