diff --git a/mh-admin/src/main/java/com/mh/web/controller/device/ChillersParamsController.java b/mh-admin/src/main/java/com/mh/web/controller/device/ChillersParamsController.java index cf14fe3..b4f0a95 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/device/ChillersParamsController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/device/ChillersParamsController.java @@ -4,10 +4,15 @@ import com.mh.common.core.controller.BaseController; import com.mh.common.core.domain.AjaxResult; import com.mh.common.core.domain.entity.CollectionParamsManage; import com.mh.common.core.domain.entity.CommunicationParams; +import com.mh.common.core.domain.entity.SysDictData; +import com.mh.common.core.domain.vo.CollectionParamsManageVO2; import com.mh.common.core.domain.vo.EnergyConsumptionVO; import com.mh.common.core.domain.vo.EnergyQueryVO; import com.mh.common.core.page.TableDataInfo; import com.mh.common.utils.DateUtils; +import com.mh.common.utils.DictUtils; +import com.mh.common.utils.StringUtils; +import com.mh.common.utils.bean.BeanUtils; import com.mh.system.service.device.ICollectionParamsManageService; import com.mh.system.service.device.ICommunicationParamsService; import com.mh.system.service.energy.IEnergyService; @@ -40,34 +45,84 @@ public class ChillersParamsController extends BaseController { /** * 获取注解全部参数内容数据 + * * @param collectionParamsManage * @return */ @GetMapping("/list") - public TableDataInfo list(CollectionParamsManage collectionParamsManage) - { + public TableDataInfo list(CollectionParamsManage collectionParamsManage) { List list = iCollectionParamsManageService.selectCollectionParamsManageList(collectionParamsManage); // list中的CollectionParamsManage中的other_name去掉“号主机”之前数据 list.forEach(item -> { String otherName = item.getOtherName(); // 使用正则表达式去掉“号主机”及之前的内容 String result = otherName != null ? otherName.replaceFirst(".*号主机", "") : otherName; + result = result != null ? result.replace("-", "") : result; item.setOtherName(result); }); + // list中的CollectionParamsManage对象赋值到CollectionParamsManageVO2形成List + List voList = list.stream() + .filter(item -> item.getIsUse() != 1) + .map(item -> { + CollectionParamsManageVO2 vo = new CollectionParamsManageVO2(); + BeanUtils.copyProperties(item, vo); + vo.setCurValue(item.getCurValue().setScale(2).toString()); + // 判断运行状态、启停、故障、本地远程 + switch (vo.getParamType()) { + case "1": // 运行状态 + if (!StringUtils.isEmpty(vo.getCurValue())) { + vo.setCurValue(vo.getCurValue().equals("1") ? "运行" : "停止"); + } + break; + case "2": // 启停 + if (!StringUtils.isEmpty(vo.getCurValue())) { + vo.setCurValue(vo.getCurValue().equals("1") ? "启动" : "停止"); + } + break; + case "5": // 故障 + if (!StringUtils.isEmpty(vo.getCurValue())) { + vo.setCurValue(vo.getCurValue().equals("1") ? "故障" : "正常"); + } + break; + case "6": // 手自动切换 + if (!StringUtils.isEmpty(vo.getCurValue())) { + vo.setCurValue(vo.getCurValue().equals("1") ? "手动" : "自动"); + } + break; + case "22": // 本地远程切换 + if (!StringUtils.isEmpty(vo.getCurValue())) { + vo.setCurValue(vo.getCurValue().equals("1") ? "远程" : "本地"); + } + break; + default: + break; + } + return vo; + }) + .collect(Collectors.toList()); + // 再根据mtType进行分组 - Map> collect = list.stream().collect(Collectors.groupingBy(CollectionParamsManage::getMtType)); + Map> collect = voList.stream().collect(Collectors.groupingBy(CollectionParamsManageVO2::getMtType)); // map转list + List sysMtTypeList = DictUtils.getDictCache("sys_mt_type"); List> result = collect.entrySet().stream().map(entry -> { Map map = new HashMap<>(); map.put("mtType", entry.getKey()); + map.put("mtTypeName", sysMtTypeList.stream().filter(item -> item.getDictValue().equals(entry.getKey())).findFirst().get().getDictLabel()); map.put("list", entry.getValue()); return map; }).collect(Collectors.toList()); + result.sort((map1, map2) -> { + Integer mtType1 = Integer.parseInt((String)map1.get("mtType")); + Integer mtType2 = Integer.parseInt((String)map2.get("mtType")); + return mtType1.compareTo(mtType2); // 升序 + }); return getDataTable(result); } /** * 获取折线图数据:冷冻水进出水温度和冷却水进出水温度 + * * @param vo * @return */ diff --git a/mh-admin/src/main/java/com/mh/web/controller/monitor/AirHandingUnitsMonitorController.java b/mh-admin/src/main/java/com/mh/web/controller/monitor/AirHandingUnitsMonitorController.java index f3a38ea..e426db8 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/monitor/AirHandingUnitsMonitorController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/monitor/AirHandingUnitsMonitorController.java @@ -1,15 +1,18 @@ package com.mh.web.controller.monitor; import com.mh.common.core.controller.BaseController; +import com.mh.common.core.domain.AjaxResult; import com.mh.common.core.domain.dto.DeviceMonitorDTO; +import com.mh.common.core.domain.entity.DeviceLedger; +import com.mh.common.core.domain.entity.PolicyManage; import com.mh.common.core.page.TableDataInfo; import com.mh.system.service.device.ICollectionParamsManageService; +import com.mh.system.service.policy.IPolicyManageService; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import java.util.Date; import java.util.List; /** @@ -25,8 +28,11 @@ public class AirHandingUnitsMonitorController extends BaseController { private final ICollectionParamsManageService iCollectionParamsManageService; - public AirHandingUnitsMonitorController(ICollectionParamsManageService iCollectionParamsManageService) { + private final IPolicyManageService policyManageService; + + public AirHandingUnitsMonitorController(ICollectionParamsManageService iCollectionParamsManageService, IPolicyManageService policyManageService) { this.iCollectionParamsManageService = iCollectionParamsManageService; + this.policyManageService = policyManageService; } /** @@ -39,4 +45,25 @@ public class AirHandingUnitsMonitorController extends BaseController { return getDataTable(list); } + /** + * 风柜获取定时开关机参数 + */ + @GetMapping("/monitor/timeList") + public TableDataInfo timeList(@RequestParam(name = "systemType") String systemType, + @RequestParam(name = "funPolicyType") String funPolicyType, + @RequestParam(name = "houseId") String houseId) + { + List list = policyManageService.selectDDCTimeList(systemType, funPolicyType, houseId); + return getDataTable(list); + } + + /** + * 修改定时任务时间参数值 + */ + @PutMapping("/monitor/time") + public AjaxResult edit(@RequestParam(name = "policyId") String policyId, @RequestParam(name = "timeValue") String timeValue) + { + return toAjax(policyManageService.updateTimeValue(policyId, timeValue)); + } + } diff --git a/mh-admin/src/main/java/com/mh/web/controller/monitor/HotWaterMonitorController.java b/mh-admin/src/main/java/com/mh/web/controller/monitor/HotWaterMonitorController.java index ec5aab1..23f55a9 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/monitor/HotWaterMonitorController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/monitor/HotWaterMonitorController.java @@ -48,7 +48,7 @@ public class HotWaterMonitorController extends BaseController { } /** - * 获取生活热水监控公共信息列表 + * 获取生活热水监控热泵信息 * @param systemType * @param floorId * @return diff --git a/mh-admin/src/main/resources/application-dev.yml b/mh-admin/src/main/resources/application-dev.yml index cdd9257..63c74ba 100644 --- a/mh-admin/src/main/resources/application-dev.yml +++ b/mh-admin/src/main/resources/application-dev.yml @@ -195,6 +195,11 @@ mqttSpring: port: 2883 username: mh password: mhtech@803 +# protocol: MQTT +# host: mqtt.mhito.net +# port: 1883 +# username: sa +# password: sa123 client-id: mqtt_mz_producer_dev # If the protocol is ws/wss, this value is required. path: 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 0d05b63..bdded5a 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 @@ -28,7 +28,13 @@ public class HotWaterNowDataDTO { private String tankName; //水箱名称 private String envTemp; //环境温度 - private String upWaterState; // 供水状态 + private String upWaterState1; // 供水1泵状态 + + private String freq1; // 供水频率1 + + private String upWaterState2; // 供水2泵状态 + + private String freq2; // 供水频率2 private String useWaterState; // 补水状态 diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/PolicyManage.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/PolicyManage.java index c12ca39..4b07118 100644 --- a/mh-common/src/main/java/com/mh/common/core/domain/entity/PolicyManage.java +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/PolicyManage.java @@ -89,6 +89,11 @@ public class PolicyManage { */ private int digits; + /** + * 房间id + */ + private String houseId; + @Override public String toString() { return new ToStringBuilder(this) diff --git a/mh-common/src/main/java/com/mh/common/core/domain/vo/CollectionParamsManageVO.java b/mh-common/src/main/java/com/mh/common/core/domain/vo/CollectionParamsManageVO.java index d861870..8c218cb 100644 --- a/mh-common/src/main/java/com/mh/common/core/domain/vo/CollectionParamsManageVO.java +++ b/mh-common/src/main/java/com/mh/common/core/domain/vo/CollectionParamsManageVO.java @@ -44,6 +44,8 @@ public class CollectionParamsManageVO { */ private int cpmOrderNum; + private int mtRatio; + public BigDecimal getCurValue() { return curValue; } diff --git a/mh-common/src/main/java/com/mh/common/core/domain/vo/CollectionParamsManageVO2.java b/mh-common/src/main/java/com/mh/common/core/domain/vo/CollectionParamsManageVO2.java new file mode 100644 index 0000000..39f5c74 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/vo/CollectionParamsManageVO2.java @@ -0,0 +1,223 @@ +package com.mh.common.core.domain.vo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.mh.common.core.domain.BaseEntity; +import lombok.Getter; +import lombok.Setter; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.Map; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 数据采集参数配置管理 + * @date 2025-01-13 15:23:40 + */ +@Setter +@Getter +public class CollectionParamsManageVO2 extends BaseEntity { + + /** + * id + */ + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + /** + * 设备台账id + */ + private String deviceLedgerId; + + /** + * 仪表类型id + */ + private String mtType; + + /** + * 仪表编号 + */ + private String mtNum; + + /** + * 仪表代码 + */ + private String mtCode; + + /** + * 寄存器地址 + */ + private String registerAddr; + + /** + * 功能码 + */ + private String funcCode; + + /** + * 仪表标识码 + */ + private String identifyCode; + + /** + * 仪表标定脉冲 + */ + private String mtCaliberPulse; + + /** + * 仪表范围 + */ + private BigDecimal mtRange; + + /** + * 仪表比率 + */ + private Integer mtRatio; + + /** + * 初始值 + */ + private BigDecimal mtInitValue; + + /** + * 小数位数 + */ + private Integer digits; + + /** + * 数据类型 + */ + private Integer dataType; + + /** + * 当前值 + */ + private String curValue; + + /** + * 当前时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date curTime; + + /** + * 是否是总表累计值 + */ + private Integer mtIsSum; + + /** + * 单位 + */ + private String unit; + + /** + * 排序 + */ + private Integer orderNum; + + /** + * 网关id + */ + private String gatewayId; + + /** + * 通信参数id + */ + private String communicationParamId; + + /** + * 通讯协议类型 + */ + private String protocolType; + + /** + * 通讯类型 + */ + private String communicationType; + + /** + * 读取响应的寄存器大小(创建指令的时候需要) + */ + private Integer registerSize; + + /** + * 是否使用 + */ + private Integer isUse; + + /** + * 别名 + * @return + */ + private String otherName; + + /** + * 累计/瞬时 状态标识 + */ + private Integer grade; + + /** + * 参数类型:0:运行状态,1:启停状态,2:频率调节,3:频率反馈 + */ + private String paramType; + + /** + * 系统类型 + */ + private String systemType; + + /** + * 采集类别:0:遥测(连续变化参数),1:遥信(离散开关状态) + */ + private String collectionType; + + /** + * 终端设备类型实际上就是设备类型 + */ + private String terminalDeviceType; + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("id", id) + .append("deviceLedgerId", deviceLedgerId) + .append("mtType", mtType) + .append("mtNum", mtNum) + .append("mtCode", mtCode) + .append("registerAddr", registerAddr) + .append("funcCode", funcCode) + .append("identifyCode", identifyCode) + .append("mtCaliberPulse", mtCaliberPulse) + .append("mtRange", mtRange) + .append("mtRatio", mtRatio) + .append("mtInitValue", mtInitValue) + .append("digits", digits) + .append("dataType", dataType) + .append("curValue", curValue) + .append("curTime", curTime) + .append("mtIsSum", mtIsSum) + .append("unit", unit) + .append("orderNum", orderNum) + .append("gatewayId", gatewayId) + .append("communicationParamId", communicationParamId) + .append("protocolType", protocolType) + .append("communicationType", communicationType) + .append("registerSize", registerSize) + .append("isUse", isUse) + .append("otherName", otherName) + .append("grade", grade) + .append("paramType", paramType) + .append("systemType", systemType) + .append("collectionType", collectionType) + .append("terminalDeviceType", terminalDeviceType) + .toString(); + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/vo/HotWaterControlListVO.java b/mh-common/src/main/java/com/mh/common/core/domain/vo/HotWaterControlListVO.java index 08d8286..9cfa961 100644 --- a/mh-common/src/main/java/com/mh/common/core/domain/vo/HotWaterControlListVO.java +++ b/mh-common/src/main/java/com/mh/common/core/domain/vo/HotWaterControlListVO.java @@ -42,6 +42,18 @@ public class HotWaterControlListVO { private int cpmOrderNum; + public BigDecimal getCurValue() { + return curValue; + } + + public void setCurValue(BigDecimal curValue) { + if (curValue!= null) { + // 保留两位小数 + curValue = curValue.setScale(2, BigDecimal.ROUND_HALF_UP); + } + this.curValue = curValue; + } + @Override public String toString() { return new ToStringBuilder(this) diff --git a/mh-common/src/main/java/com/mh/common/core/domain/vo/HotWaterControlVO.java b/mh-common/src/main/java/com/mh/common/core/domain/vo/HotWaterControlVO.java index 88cb80d..37ee3c9 100644 --- a/mh-common/src/main/java/com/mh/common/core/domain/vo/HotWaterControlVO.java +++ b/mh-common/src/main/java/com/mh/common/core/domain/vo/HotWaterControlVO.java @@ -121,6 +121,13 @@ public class HotWaterControlVO { private int orderNum; + public void setCounterSet(BigDecimal counterSet) { + if (counterSet != null) { + counterSet = counterSet.setScale(0, BigDecimal.ROUND_HALF_UP); + } + this.counterSet = counterSet; + } + @Override public String toString() { return new ToStringBuilder(this) 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 4766be8..0824475 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 @@ -12,7 +12,6 @@ import java.math.BigDecimal; import java.util.Date; import java.util.List; import java.util.Map; -import java.util.Objects; /** * @author LJF @@ -205,7 +204,8 @@ public interface CollectionParamsManageMapper extends BaseMapper selectHotWaterBySystemTypeAndBuildingId(@Param("systemType") String systemType, @Param("floorId") String floorId); @@ -326,7 +326,7 @@ public interface CollectionParamsManageMapper extends BaseMapper { @Select("select pm.* from policy_manage pm where pm.cpm_id = #{cpmId} limit 1") PolicyManage selectOntByCpmId(@Param("cpmId") String cpmId); + + @Select("select pm.*,cpm.cur_value from policy_manage pm " + + " left join collection_params_manage cpm on pm.cpm_id = cpm.id " + + " where pm.system_type = #{systemType} " + + " and pm.fun_policy_type = #{funPolicyType} " + + " and house_id = #{houseId} " + + " order by pm.policy_type, pm.order_num ") + List selectPolicyListByParams(@Param("systemType") String systemType, + @Param("funPolicyType") String funPolicyType, + @Param("houseId") String houseId); + + @Select("select cpm_id from policy_manage where id = #{policyId} limit 1") + String selectCpmId(String policyId); } diff --git a/mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java index a119205..3120892 100644 --- a/mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java @@ -243,13 +243,16 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag deviceMonitorVO.setId(param.getId()); deviceMonitorVO.setDeviceLedgerId(param.getDeviceLedgerId()); deviceMonitorVO.setDeviceName(param.getDeviceName()); + if (StringUtils.isEmpty(param.getMtType())) { + deviceMonitorVO.setDeviceType(""); + } deviceMonitorVO.setDeviceType(param.getMtType()); deviceMonitorVO.setCollectName(param.getOtherName()); deviceMonitorVO.setCollectTime(param.getCurTime()); // 判断如果是压力,放大1000倍,并保留一位小数 if (param.getParamType().equals("13")) { BigDecimal bigDecimal = param.getCurValue(); -// bigDecimal = bigDecimal.multiply(new BigDecimal(1000)); + bigDecimal = bigDecimal.multiply(new BigDecimal(param.getMtRatio())); param.setCurValue(bigDecimal.setScale(1, RoundingMode.HALF_UP)); } deviceMonitorVO.setCollectValue(String.valueOf(param.getCurValue().setScale(1, RoundingMode.HALF_UP))); @@ -258,6 +261,7 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag } return deviceMonitorVO; }) + .filter(vo -> vo.getDeviceType() != null) .collect(Collectors.groupingBy(DeviceMonitorVO::getDeviceType)); // 根据deviceType进行分组,赋值给List得出结果集 @@ -332,6 +336,10 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag List> mapList = collectionParamsManageMapper.selectBySystemTypeAndBuildingId(systemType, floorId); // stream流判断mapList中的数据curTime是否为今天日期,假如不是今天日期,则重新赋值value为"采集失败",然后响应赋值给List return mapList.stream() + .filter(map -> { + String name = map.get("name").toString(); + return !name.contains("热泵"); + }) .map(map -> { // 1. 获取当前记录的 curTime 和 value Object curTimeObj = map.get("curTime"); @@ -358,12 +366,12 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag map.put("value", "采集失败"); } else { // 4.1 如果是今天,设置 value 为采集到的值 - map.put("value", new BigDecimal(String.valueOf(map.get("value"))).setScale(0, RoundingMode.HALF_UP).toString()); + map.put("value", new BigDecimal(String.valueOf(map.get("value"))).setScale(2, RoundingMode.HALF_UP).toString()); } // 4. 转换为 ColumnFilter 对象(假设构造函数为 ColumnFilter(name, value)) return new ColumnFilter( - (String) map.get("name"), + map.get("name").toString().replace("回水阀", ""), (String) map.get("value") ); }) @@ -405,19 +413,69 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag return dto; }).collect(Collectors.toList()); - // 处理供水泵(deviceType=10) + // 处理供水泵状态(deviceType=10) List waterPumps = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "10"); // 判断是否存在collectValue>0的记录 - boolean hasValidCollectValue = waterPumps.stream() + boolean hasValidCollectValue1 = waterPumps.stream() + .anyMatch(vo -> "1".equals(vo.getParamType()) + && vo.getCollectValue() != null + && new BigDecimal(vo.getCollectValue()).intValue() > 0 + && vo.getCollectName().contains("供水泵1")); + // 根据判断结果设置状态值 + result.forEach(dto -> dto.setUpWaterState1(hasValidCollectValue1 ? "1" : "0")); + // 判断是否存在collectValue>0的记录 + boolean hasValidCollectValue2 = waterPumps.stream() .anyMatch(vo -> "1".equals(vo.getParamType()) + && vo.getCollectValue() != null + && new BigDecimal(vo.getCollectValue()).intValue() > 0 + && vo.getCollectName().contains("供水泵2")); + // 根据判断结果设置状态值 + result.forEach(dto -> dto.setUpWaterState2(hasValidCollectValue2 ? "1" : "0")); + // 频率反馈1 + DeviceMonitorVO freq1 = waterPumps.stream() + .filter(vo -> "4".equals(vo.getParamType()) + && vo.getCollectValue() != null + && vo.getCollectName().contains("供水泵1")) + .collect(Collectors.toList()).getFirst(); + // 根据判断结果设置状态值 + if (StringUtils.isEmpty(freq1.getCollectValue())) { + freq1.setCollectValue("0"); + } + result.forEach(dto -> dto.setFreq1(new BigDecimal(freq1.getCollectValue()).setScale(2, RoundingMode.HALF_UP).toString())); + // 频率反馈2 + DeviceMonitorVO freq2 = waterPumps.stream() + .filter(vo -> "4".equals(vo.getParamType()) + && vo.getCollectValue() != null + && vo.getCollectName().contains("供水泵2")) + .collect(Collectors.toList()).getFirst(); + if (StringUtils.isEmpty(freq2.getCollectValue())) { + freq2.setCollectValue("0"); + } + // 根据判断结果设置状态值 + result.forEach(dto -> dto.setFreq2(new BigDecimal(freq2.getCollectValue()).setScale(2, RoundingMode.HALF_UP).toString())); + + // 处理水箱,水箱绑定了补水阀参数(deviceType=16) + List waterValves = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "16"); + // 判断是否存在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")); + // 处理回水阀(deviceType=22) + List waterBackValves = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "22"); + // 判断是否存在collectValue>0的记录 + boolean backWaterState = waterBackValves.stream() + .anyMatch(vo -> "2".equals(vo.getParamType()) + && vo.getCollectValue() != null + && new BigDecimal(vo.getCollectValue()).intValue() > 0); // 根据判断结果设置状态值 - result.forEach(dto -> dto.setUpWaterState(hasValidCollectValue ? "1" : "0")); + result.forEach(dto -> dto.setBackWaterState(backWaterState ? "1" : "0")); - // 处理水箱液位(deviceType=12) - List waterLevels = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "12"); + // 处理水箱液位(deviceType=16) + List waterLevels = collectionParamsManageMapper.selectHotWaterBySystemTypeAndBuildingIdAndDeviceType(systemType, floorId, "16"); // 计算levelSet平均值(paramType=10) Double levelSetAvg = waterLevels.stream() diff --git a/mh-system/src/main/java/com/mh/system/service/policy/IPolicyManageService.java b/mh-system/src/main/java/com/mh/system/service/policy/IPolicyManageService.java index 03de176..6b8bcaa 100644 --- a/mh-system/src/main/java/com/mh/system/service/policy/IPolicyManageService.java +++ b/mh-system/src/main/java/com/mh/system/service/policy/IPolicyManageService.java @@ -11,4 +11,8 @@ import java.util.List; */ public interface IPolicyManageService { List selectPolicyList(String systemType, String funPolicyType); + + List selectDDCTimeList(String systemType, String funPolicyType, String houseId); + + int updateTimeValue(String policyId, String timeValue); } diff --git a/mh-system/src/main/java/com/mh/system/service/policy/impl/PolicyManageServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/policy/impl/PolicyManageServiceImpl.java index 94a399e..74bec20 100644 --- a/mh-system/src/main/java/com/mh/system/service/policy/impl/PolicyManageServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/policy/impl/PolicyManageServiceImpl.java @@ -3,16 +3,14 @@ package com.mh.system.service.policy.impl; import com.mh.common.core.domain.dto.DeviceMonitorDTO; import com.mh.common.core.domain.entity.CollectionParamsManage; import com.mh.common.core.domain.entity.PolicyManage; +import com.mh.common.utils.StringUtils; import com.mh.system.mapper.device.CollectionParamsManageMapper; import com.mh.system.mapper.policy.PolicyManageMapper; import com.mh.system.service.policy.IPolicyManageService; import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -34,6 +32,44 @@ public class PolicyManageServiceImpl implements IPolicyManageService { this.collectionParamsManageMapper = collectionParamsManageMapper; } + @Override + public int updateTimeValue(String policyId, String timeValue) { + String cpmId = policyManageMapper.selectCpmId(policyId); + if (StringUtils.isEmpty(cpmId)) { + throw new RuntimeException("未找到该时间策略值"); + } + return collectionParamsManageMapper.updateCurValueById(cpmId, new BigDecimal(timeValue), new Date()); + } + + @Override + public List selectDDCTimeList(String systemType, String funPolicyType, String houseId) { + List policyManages = policyManageMapper.selectPolicyListByParams(systemType, funPolicyType, houseId); + Map> listMap = policyManages.stream() + // 先排序(例如按 policyType) + .sorted(Comparator.comparing(PolicyManage::getPolicyType)) + // 处理每个PolicyManage对象的curValue字段 + .peek(policy -> { + policy.setCurValue(BigDecimal.valueOf(policy.getCurValue().intValue())); // 除以1000并保留整数 + }) + // 分组时使用 LinkedHashMap 来保持插入顺序 + .collect(Collectors.groupingBy( + PolicyManage::getPolicyName, // 分组键 + LinkedHashMap::new, // 使用 LinkedHashMap 保持顺序 ✅ + Collectors.toList() // 下游收集器 + )); + + // 转换为 DeviceMonitorDTO 列表 + List result = new ArrayList<>(); + listMap.forEach((name, values) -> { + DeviceMonitorDTO dto = new DeviceMonitorDTO(); + dto.setName(name); + dto.setValues(values); + result.add(dto); + }); + + return result; + } + @Override public List selectPolicyList(String systemType, String funPolicyType) { // QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -49,8 +85,8 @@ public class PolicyManageServiceImpl implements IPolicyManageService { .peek(policy -> { // 自动开关机时间,反馈是ms,页面是s,所以除以1000 // if (funPolicyType.equals("2")) { - policy.setCurValue(BigDecimal.valueOf((policy.getCurValue()==null?new BigDecimal("0"):policy.getCurValue()) - .divide(new BigDecimal( (int) Math.pow(10, policy.getDigits()))).intValue())); // 除以1000并保留整数 + policy.setCurValue(BigDecimal.valueOf((policy.getCurValue() == null ? new BigDecimal("0") : policy.getCurValue()) + .divide(new BigDecimal((int) Math.pow(10, policy.getDigits()))).intValue())); // 除以1000并保留整数 // } // 判断系统启动模式值是多少,如果是1:一键启动,如果是2:定时启动 if (policy.getPolicyType().equals("5") && policy.getFunPolicyType().equals("1")) { @@ -69,8 +105,12 @@ public class PolicyManageServiceImpl implements IPolicyManageService { } } }) - // 再按PolicyName分组 - .collect(Collectors.groupingBy(PolicyManage::getPolicyName, Collectors.toList())); + // 分组时使用 LinkedHashMap 来保持插入顺序 + .collect(Collectors.groupingBy( + PolicyManage::getPolicyName, // 分组键 + LinkedHashMap::new, // 使用 LinkedHashMap 保持顺序 ✅ + Collectors.toList() // 下游收集器 + )); // 在遍历赋值给DeviceMonitorDTO,key给name,value给list List list = new ArrayList<>(); listMap.keySet().forEach(k -> {