From d268edfce2ea611c45c977bd16a509db0e17be08 Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 2 Jun 2025 13:28:15 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E9=A3=8E=E6=9F=9C=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9A=E6=97=B6=E5=BC=80=E5=85=B3=E6=9C=BA?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E5=A4=84=E7=90=86=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/OperationController.java | 2 +- .../java/com/mh/common/utils/DateUtils.java | 39 +++ .../java/com/mh/quartz/domain/PIDParams.java | 52 ++++ .../main/java/com/mh/quartz/task/AHUTask.java | 258 ++++++++++++++++++ .../com/mh/quartz/util/AHUPIDControlUtil.java | 56 ++++ .../device/CollectionParamsManageMapper.java | 3 +- .../mapper/space/CpmSpaceRelationMapper.java | 8 + .../ICollectionParamsManageService.java | 3 + .../CollectionParamsManageServiceImpl.java | 29 ++ .../service/policy/IPolicyManageService.java | 5 + .../policy/impl/PolicyManageServiceImpl.java | 19 ++ .../space/ICpmSpaceRelationService.java | 2 + .../impl/CpmSpaceRelationServiceImpl.java | 15 + 13 files changed, 489 insertions(+), 2 deletions(-) create mode 100644 mh-quartz/src/main/java/com/mh/quartz/domain/PIDParams.java create mode 100644 mh-quartz/src/main/java/com/mh/quartz/task/AHUTask.java create mode 100644 mh-quartz/src/main/java/com/mh/quartz/util/AHUPIDControlUtil.java diff --git a/mh-admin/src/main/java/com/mh/web/controller/device/OperationController.java b/mh-admin/src/main/java/com/mh/web/controller/device/OperationController.java index a902d1a..90e962d 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/device/OperationController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/device/OperationController.java @@ -99,7 +99,7 @@ public class OperationController extends BaseController { String name = mhConfig.getName(); // 获取mqtt操作队列(后期通过mqtt队列配置发送主题) log.info("发送主题:{},消息:{}", name + "/"+ controlTopic, sendOrder); - iMqttGatewayService.publish(name + "/"+ controlTopic, sendOrder, 1); +// iMqttGatewayService.publish(name + "/"+ controlTopic, sendOrder, 1); } catch (Exception e) { log.error("设备操作失败", e); return AjaxResult.error(); diff --git a/mh-common/src/main/java/com/mh/common/utils/DateUtils.java b/mh-common/src/main/java/com/mh/common/utils/DateUtils.java index 8b5875e..c7eeb6b 100644 --- a/mh-common/src/main/java/com/mh/common/utils/DateUtils.java +++ b/mh-common/src/main/java/com/mh/common/utils/DateUtils.java @@ -37,6 +37,35 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"}; + public static String dayOfWeekValue() { + int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); + String result = ""; + switch (dayOfWeek) { + case Calendar.MONDAY: + result = "星期一"; + break; + case Calendar.TUESDAY: + result = "星期二"; + break; + case Calendar.WEDNESDAY: + result = "星期三"; + break; + case Calendar.THURSDAY: + result = "星期四"; + break; + case Calendar.FRIDAY: + result = "星期五"; + break; + case Calendar.SATURDAY: + result = "星期六"; + break; + case Calendar.SUNDAY: + result = "星期日"; + break; + } + return result; + } + /** * 将 Date 类型的 curTime 转换为 LocalTime * @@ -437,4 +466,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils // 格式化日期 return zonedDateTime.format(formatter); } + + public static boolean isBetween(LocalTime nowTime, LocalTime startTime, LocalTime endTime) { + if (startTime.isBefore(endTime)) { + return !nowTime.isBefore(startTime) && !nowTime.isAfter(endTime); + } else { + // 跨天情况,比如 22:00 - 6:00 + return !nowTime.isBefore(startTime) || !nowTime.isAfter(endTime); + } + } + } diff --git a/mh-quartz/src/main/java/com/mh/quartz/domain/PIDParams.java b/mh-quartz/src/main/java/com/mh/quartz/domain/PIDParams.java new file mode 100644 index 0000000..d7cae3b --- /dev/null +++ b/mh-quartz/src/main/java/com/mh/quartz/domain/PIDParams.java @@ -0,0 +1,52 @@ +package com.mh.quartz.domain; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description PID参数 + * @date 2025-05-30 13:51:22 + */ +public class PIDParams { + + private volatile double kp; // 比例系数 + private volatile double ki; // 积分系数 + private volatile double kd; // 微分系数 + + public PIDParams(double kp, double ki, double kd) { + this.kp = kp; + this.ki = ki; + this.kd = kd; + } + + // 动态更新PID参数 + public void updateParams(double kp, double ki, double kd) { + this.kp = kp; + this.ki = ki; + this.kd = kd; + } + + public double getKp() { + return kp; + } + + public void setKp(double kp) { + this.kp = kp; + } + + public double getKi() { + return ki; + } + + public void setKi(double ki) { + this.ki = ki; + } + + public double getKd() { + return kd; + } + + public void setKd(double kd) { + this.kd = kd; + } +} diff --git a/mh-quartz/src/main/java/com/mh/quartz/task/AHUTask.java b/mh-quartz/src/main/java/com/mh/quartz/task/AHUTask.java new file mode 100644 index 0000000..80b4499 --- /dev/null +++ b/mh-quartz/src/main/java/com/mh/quartz/task/AHUTask.java @@ -0,0 +1,258 @@ +package com.mh.quartz.task; + +import com.mh.common.config.MHConfig; +import com.mh.common.core.domain.AjaxResult; +import com.mh.common.core.domain.dto.DeviceMonitorDTO; +import com.mh.common.core.domain.entity.CollectionParamsManage; +import com.mh.common.core.domain.entity.CpmSpaceRelation; +import com.mh.common.core.domain.entity.OrderEntity; +import com.mh.common.core.domain.entity.PolicyManage; +import com.mh.common.utils.DateUtils; +import com.mh.framework.mqtt.service.IMqttGatewayService; +import com.mh.quartz.domain.PIDParams; +import com.mh.quartz.util.AHUPIDControlUtil; +import com.mh.system.service.device.ICollectionParamsManageService; +import com.mh.system.service.operation.IOperationDeviceService; +import com.mh.system.service.policy.IPolicyManageService; +import com.mh.system.service.space.ICpmSpaceRelationService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.time.LocalTime; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 风柜系统任务 + * @date 2025-05-30 08:36:43 + */ +@Slf4j +@Component("ahuTask") +public class AHUTask { + + @Value("${control.topic}") + String controlTopic; + + @Autowired + private MHConfig mhConfig; + + private final ICollectionParamsManageService collectionParamsManageService; + + private final IPolicyManageService policyManageService; + + private final ICpmSpaceRelationService cpmSpaceRelationService; + + private final IOperationDeviceService iOperationService; + + private final IMqttGatewayService iMqttGatewayService; + + + @Autowired + public AHUTask(ICollectionParamsManageService collectionParamsManageService, IPolicyManageService policyManageService, ICpmSpaceRelationService cpmSpaceRelationService, IOperationDeviceService iOperationService, IMqttGatewayService iMqttGatewayService) { + this.collectionParamsManageService = collectionParamsManageService; + this.policyManageService = policyManageService; + this.cpmSpaceRelationService = cpmSpaceRelationService; + this.iOperationService = iOperationService; + this.iMqttGatewayService = iMqttGatewayService; + } + + + public void sendOrderToMqtt(List changeValues) { + try { + String sendOrder = iOperationService.operationDevice(changeValues); + String name = mhConfig.getName(); + // 获取mqtt操作队列(后期通过mqtt队列配置发送主题) + log.info("发送主题:{},消息:{}", name + "/" + controlTopic, sendOrder); + iMqttGatewayService.publish(name + "/" + controlTopic, sendOrder, 1); + } catch (Exception e) { + log.error("设备操作失败", e); + } + } + + public void adjustWaterValve(String kp, String ki, String kd) { + // 西餐走廊2、宴会走廊需要调整PID参数,其他的ddc自己已经处理好 + String[] deviceLedgerIds = new String[]{"ddc0083b3a898d85f3a1205a2d82071e100", "ddc0133b3a898d85f3a1205a2d82071e100"}; + for (String deviceLedgerId : deviceLedgerIds) { + // 获取西餐走廊2的启停控制 + HashMap queryMap = new HashMap<>(); + queryMap.put("systemType", "2"); + queryMap.put("deviceLedgerId", deviceLedgerId); + queryMap.put("isUse", 0); + // 得出 systemType =2 的数据 + List collectionParamsManages = collectionParamsManageService.selectListByParams(queryMap); + + // 过滤得出启停状态 + Optional first = collectionParamsManages.stream().filter(item -> item.getCurValue().intValue() == 1 && item.getParamType().equals("2")).findFirst(); + if (first.isEmpty()) { + continue; + } + + // 初始化PID参数(可动态调整) +// PIDParams params = new PIDParams(2.5, 0.1, 0.5); + PIDParams params = new PIDParams(new BigDecimal(kp).doubleValue(), new BigDecimal(ki).doubleValue(), new BigDecimal(kd).doubleValue()); // Kp, Ki, Kd + + // 过滤获取回风温度设置值 + Optional second = collectionParamsManages + .stream() + .filter(item -> item.getOtherName().contains("回风温度") + && item.getParamType().equals("14")).findFirst(); + if (second.isEmpty()) { + continue; + } + // 得出回风温度设置值 + double backTemp = second.get().getCurValue().doubleValue(); + + // 设定目标温度(夏季制冷24℃) + AHUPIDControlUtil pid = new AHUPIDControlUtil(params, backTemp); + + // 过滤获取当前回风温度 + Optional third = collectionParamsManages + .stream() + .filter(item -> item.getOtherName().contains("回风温度") + && item.getParamType().equals("12")).findFirst(); + if (third.isEmpty()) { + continue; + } + // 得出当前回风温度 + double temp = third.get().getCurValue().doubleValue(); + + // 2. 计算水阀开度(时间间隔1秒) + double valveOpening1 = pid.calculate(temp, 1.0); + int valveOpening = new BigDecimal(valveOpening1).intValue(); + + // 过滤获取水阀调节参数 + Optional fourth = collectionParamsManages + .stream() + .filter(item -> item.getOtherName().contains("水阀调节") + && item.getParamType().equals("3")).findFirst(); + if (fourth.isEmpty()) { + continue; + } + // 得出水阀调节参数 + CollectionParamsManage collectionParamsManage = fourth.get(); + // 发送控制指令 + if (valveOpening > 0 && valveOpening <= 100) { + // 开启 + List changeValues = new ArrayList<>(); + changeValues.add(new OrderEntity(collectionParamsManage.getId(), String.valueOf(valveOpening), Integer.parseInt(collectionParamsManage.getParamType()), collectionParamsManage.getOtherName())); + sendOrderToMqtt(changeValues); + // 3. 应用水阀开度(实际应用发送给执行机构) + log.info("回风温度: {} ℃ | 水阀开度: {} % | P:{}, I:{} D:{} ", + temp, valveOpening, params.getKp(), params.getKi(), params.getKd()); + } + + } + } + + public void startOrStopAHU() { + // 扫描启动了定时开关机的风机,根据当前时间判断是否需要启动或停止 + // systemType 2: 风柜系统 + HashMap queryMap = new HashMap<>(); + queryMap.put("systemType", "2"); + // 得出 systemType =2 的数据 + List collectionParamsManages = collectionParamsManageService.selectListByParams(queryMap); + // 判断当前时间是星期几 + String dayOfWeekValue = DateUtils.dayOfWeekValue(); + // 过滤otherName包含dayOfWeekValue,paramType=29, curValue=1的数据,代表已经启用定时开关机的功能 + List needStartOrStopDataList = collectionParamsManages + .stream() + .filter(item -> item.getOtherName().contains(dayOfWeekValue) + && item.getParamType().equals("29") + && item.getCurValue().intValue() == 1) + .toList(); + // 查询得出对应的houseId + List policyManageList = policyManageService.selectListByCpmIds(needStartOrStopDataList); + + // 开始:根据houseId查询出对应的风机启停id + List cpmSpaceRelationList = cpmSpaceRelationService.selectListByHouseId(policyManageList); + // collectionParamsManages过滤出能够开启风机的点位,paramType=2,isUse=0 + List startDeviceList = collectionParamsManages + .stream() + .filter(item -> item.getParamType().equals("2") + && item.getIsUse() == 0) + .toList(); + // 结束:根据houseId查询出对应的风机启停id + + // 在拼接出启用定时开关机的启动时间、关闭时间 + Map> groupedByHouseId = policyManageList.stream() + .collect(Collectors.groupingBy( + PolicyManage::getHouseId, + Collectors.toList() + )); + // groupedByHouseId for 循环遍历 + for (Map.Entry> entry : groupedByHouseId.entrySet()) { + // 得出houseId + String houseId = entry.getKey(); + // 得出policyManageList + List timeList = entry.getValue(); + int startHour = 0; + int startMinute = 0; + int endHour = 0; + int endMinute = 0; + for (PolicyManage policyManage : timeList) { + if (policyManage.getPointName().equals("开_时")) { + startHour = collectionParamsManageService.selectCollectionParamsManageById(policyManage.getCpmId()).getCurValue().intValue(); + } + if (policyManage.getPointName().equals("开_分")) { + startMinute = collectionParamsManageService.selectCollectionParamsManageById(policyManage.getCpmId()).getCurValue().intValue(); + } + if (policyManage.getPointName().equals("关_时")) { + endHour = collectionParamsManageService.selectCollectionParamsManageById(policyManage.getCpmId()).getCurValue().intValue(); + } + if (policyManage.getPointName().equals("关_分")) { + endMinute = collectionParamsManageService.selectCollectionParamsManageById(policyManage.getCpmId()).getCurValue().intValue(); + } + } + LocalTime nowTime = LocalTime.now(); + LocalTime startTime = LocalTime.of(startHour, startMinute); + LocalTime endTime = LocalTime.of(endHour, endMinute); + // collectionParamsManages过滤出能够开启风机的点位,paramType=2,isUse=0 + Set validCpmIds = cpmSpaceRelationList.stream() + .filter(item -> item.getHouseId().equals(houseId)) + .map(CpmSpaceRelation::getCpmId) + .collect(Collectors.toSet()); + List startDataList = startDeviceList + .stream() + .filter(item -> validCpmIds.contains(item.getId())) + .toList(); + // 判断当前风机是否在开启状态了 + if (null == startDataList || startDataList.size() == 0) { + return; + } + CollectionParamsManage first = startDataList.getFirst(); + // 判断当前时间是否在开启时间范围内 + if (DateUtils.isBetween(nowTime, startTime, endTime)) { + // 判断当前风机是否在开启状态了 + if (first.getCurValue().intValue() == 1) { + // 当前风机在开启状态,不需要启动 + log.info("当前风机在开启状态,不需要启动"); + } else { + // 当前风机不在开启状态,需要启动 + log.info("当前风机不在开启状态,需要启动"); + List changeValues = new ArrayList<>(); + changeValues.add(new OrderEntity(first.getId(), "1", Integer.parseInt(first.getParamType()), first.getOtherName())); + sendOrderToMqtt(changeValues); + } + ; + } else { + // 判断当前风机是否在关闭状态了 + if (first.getCurValue().intValue() == 0) { + // 当前风机在关闭状态,不需要停止 + log.info("当前风机在关闭状态,不需要停止"); + } else { + // 当前风机不在关闭状态,需要停止 + log.info("当前风机不在关闭状态,需要停止"); + List changeValues = new ArrayList<>(); + changeValues.add(new OrderEntity(first.getId(), "0", Integer.parseInt(first.getParamType()), first.getOtherName())); + sendOrderToMqtt(changeValues); + } + } + } + } +} diff --git a/mh-quartz/src/main/java/com/mh/quartz/util/AHUPIDControlUtil.java b/mh-quartz/src/main/java/com/mh/quartz/util/AHUPIDControlUtil.java new file mode 100644 index 0000000..227fa65 --- /dev/null +++ b/mh-quartz/src/main/java/com/mh/quartz/util/AHUPIDControlUtil.java @@ -0,0 +1,56 @@ +package com.mh.quartz.util; + +import com.mh.quartz.domain.PIDParams; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 风柜系统PID调节工具类 + * @date 2025-05-30 13:47:40 + */ +public class AHUPIDControlUtil { + + // PID控制器核心实现 + private PIDParams params; + private double setPoint; // 目标温度 + private double prevError; // 上次误差 + private double integral; // 积分累积值 + private double minOutput = 0; // 输出下限(0%) + private double maxOutput = 100; // 输出上限(100%) + + public AHUPIDControlUtil(PIDParams params, double setPoint) { + this.params = params; + this.setPoint = setPoint; + } + + // 计算水阀开度百分比 (0-100%) + public double calculate(double currentTemp, double deltaTime) { + // 1. 计算当前误差 + double error = setPoint - currentTemp; + + // 2. 比例项计算 + double proportional = params.getKp() * error; + + // 3. 积分项计算(带抗饱和) + integral += params.getKi() * error * deltaTime; + // 积分限幅防止超调 + integral = Math.max(minOutput, Math.min(maxOutput, integral)); + + // 4. 微分项计算(带低通滤波) + double derivative = params.getKd() * (error - prevError) / deltaTime; + prevError = error; // 更新误差记录 + + // 5. 综合输出(0-100%) + double output = proportional + integral + derivative; + + // 6. 输出限幅 + return Math.max(minOutput, Math.min(maxOutput, output)); + } + + // 更新设定温度 + public void setSetPoint(double setPoint) { + this.setPoint = setPoint; + } + +} 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 0824475..0ae6e50 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 @@ -320,7 +320,8 @@ public interface CollectionParamsManageMapper extends BaseMapper selectBySystemTypeAndHouseId(@Param("systemType") String systemType, @Param("houseId") String houseId); diff --git a/mh-system/src/main/java/com/mh/system/mapper/space/CpmSpaceRelationMapper.java b/mh-system/src/main/java/com/mh/system/mapper/space/CpmSpaceRelationMapper.java index cdbc39e..5a727bc 100644 --- a/mh-system/src/main/java/com/mh/system/mapper/space/CpmSpaceRelationMapper.java +++ b/mh-system/src/main/java/com/mh/system/mapper/space/CpmSpaceRelationMapper.java @@ -3,6 +3,10 @@ package com.mh.system.mapper.space; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.mh.common.core.domain.entity.CpmSpaceRelation; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; /** * @author LJF @@ -13,4 +17,8 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface CpmSpaceRelationMapper extends BaseMapper { + + @Select("select * from cpm_space_relation where house_id = #{houseId} ") + List selectListByHouseId(@Param("houseId") String houseId); + } diff --git a/mh-system/src/main/java/com/mh/system/service/device/ICollectionParamsManageService.java b/mh-system/src/main/java/com/mh/system/service/device/ICollectionParamsManageService.java index 4b46366..6141d2f 100644 --- a/mh-system/src/main/java/com/mh/system/service/device/ICollectionParamsManageService.java +++ b/mh-system/src/main/java/com/mh/system/service/device/ICollectionParamsManageService.java @@ -10,6 +10,7 @@ import com.mh.common.core.domain.entity.CollectionParamsManage; import com.mh.common.core.domain.vo.DeviceOperateMonitorVO; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; /** @@ -76,4 +77,6 @@ public interface ICollectionParamsManageService { * @return */ List selectMonitorListBySystemTypeAndHouseId(String systemType, String houseId); + + List selectListByParams(HashMap queryMap); } 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 3120892..8c8b59a 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 @@ -52,6 +52,35 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag @Resource private DataProcessMapper dataProcessMapper; + @Override + public List selectListByParams(HashMap queryMap) { + if (queryMap == null || queryMap.isEmpty()) { + return List.of(); + } + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (queryMap.containsKey("systemType")) { + String systemType = (String) queryMap.get("systemType"); + queryWrapper.eq("system_type", systemType); + } + if (queryMap.containsKey("paramType")) { + String paramType = (String) queryMap.get("paramType"); + queryWrapper.eq("param_type", paramType); + } + if (queryMap.containsKey("curValue")) { + BigDecimal curValue = (BigDecimal) queryMap.get("curValue"); + queryWrapper.eq("cur_value", curValue); + } + if (queryMap.containsKey("isUse")) { + int isUse = (int) queryMap.get("isUse"); + queryWrapper.eq("is_use", isUse); + } + if (queryMap.containsKey("deviceLedgerId")) { + String deviceLedgerId = (String) queryMap.get("deviceLedgerId"); + queryWrapper.eq("device_ledger_id", deviceLedgerId); + } + return collectionParamsManageMapper.selectList(queryWrapper); + } + @Override public List selectCollectionParamsManageList(CollectionParamsManage communicationParams) { if (communicationParams == null) { 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 6b8bcaa..3eb71eb 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 @@ -1,5 +1,8 @@ package com.mh.system.service.policy; +import com.mh.common.core.domain.entity.CollectionParamsManage; +import com.mh.common.core.domain.entity.PolicyManage; + import java.util.List; /** @@ -15,4 +18,6 @@ public interface IPolicyManageService { List selectDDCTimeList(String systemType, String funPolicyType, String houseId); int updateTimeValue(String policyId, String timeValue); + + List selectListByCpmIds(List collectionParamsManages); } 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 74bec20..a40ba59 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 @@ -32,6 +32,25 @@ public class PolicyManageServiceImpl implements IPolicyManageService { this.collectionParamsManageMapper = collectionParamsManageMapper; } + @Override + public List selectListByCpmIds(List collectionParamsManages) { + if (collectionParamsManages.isEmpty()) { + return List.of(); + } + List resultList = new ArrayList<>(); + for (CollectionParamsManage collectionParamsManage : collectionParamsManages) { + if (StringUtils.isEmpty(collectionParamsManage.getId())) { + throw new RuntimeException("未找到该时间策略值"); + } + PolicyManage policyManage = policyManageMapper.selectOntByCpmId(collectionParamsManage.getId()); + if (null == policyManage) { + throw new RuntimeException("未找到该时间策略值"); + } + resultList.add(policyManage); + } + return resultList; + } + @Override public int updateTimeValue(String policyId, String timeValue) { String cpmId = policyManageMapper.selectCpmId(policyId); diff --git a/mh-system/src/main/java/com/mh/system/service/space/ICpmSpaceRelationService.java b/mh-system/src/main/java/com/mh/system/service/space/ICpmSpaceRelationService.java index 532274f..fc19eef 100644 --- a/mh-system/src/main/java/com/mh/system/service/space/ICpmSpaceRelationService.java +++ b/mh-system/src/main/java/com/mh/system/service/space/ICpmSpaceRelationService.java @@ -3,6 +3,7 @@ package com.mh.system.service.space; import com.mh.common.core.domain.SpaceTreeSelect; import com.mh.common.core.domain.entity.CollectionParamsManage; import com.mh.common.core.domain.entity.CpmSpaceRelation; +import com.mh.common.core.domain.entity.PolicyManage; import java.util.List; @@ -25,4 +26,5 @@ public interface ICpmSpaceRelationService { int deleteCpmSpaceRelationByIds(String[] buildingIds); + List selectListByHouseId(List policyManageList); } diff --git a/mh-system/src/main/java/com/mh/system/service/space/impl/CpmSpaceRelationServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/space/impl/CpmSpaceRelationServiceImpl.java index fc25f6d..df28f70 100644 --- a/mh-system/src/main/java/com/mh/system/service/space/impl/CpmSpaceRelationServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/space/impl/CpmSpaceRelationServiceImpl.java @@ -2,6 +2,7 @@ package com.mh.system.service.space.impl; import com.mh.common.core.domain.entity.CollectionParamsManage; import com.mh.common.core.domain.entity.CpmSpaceRelation; +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.space.CpmSpaceRelationMapper; @@ -9,6 +10,7 @@ import com.mh.system.service.space.ICpmSpaceRelationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; /** @@ -31,6 +33,19 @@ public class CpmSpaceRelationServiceImpl implements ICpmSpaceRelationService { this.collectionParamsManageMapper = collectionParamsManageMapper; } + @Override + public List selectListByHouseId(List policyManageList) { + if (policyManageList.isEmpty()) { + return List.of(); + } + List result = new ArrayList<>(); + for (PolicyManage policyManage : policyManageList) { + List cpmSpaceRelationList = cpmSpaceRelationMapper.selectListByHouseId(policyManage.getHouseId()); + result.addAll(cpmSpaceRelationList); + } + return result; + } + @Override public List selectCpmSpaceRelationList(CpmSpaceRelation cpmSpaceRelation) { // 判断房间号id是否为空