diff --git a/mh-admin/src/main/java/com/mh/web/controller/monitor/CoolingSystemMonitorController.java b/mh-admin/src/main/java/com/mh/web/controller/monitor/CoolingSystemMonitorController.java index c0ff26b..3ba4024 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/monitor/CoolingSystemMonitorController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/monitor/CoolingSystemMonitorController.java @@ -89,5 +89,9 @@ public class CoolingSystemMonitorController extends BaseController { return AjaxResult.success(iCoolingSystemMonitorService.getSysPerformance()); } + @GetMapping("/oneKeyButton") + public AjaxResult getOneKeyButton(@RequestParam(name = "systemType") String systemType, @RequestParam(name = "paramType") String paramType) { + return AjaxResult.success(iCoolingSystemMonitorService.getOneKeyButton(systemType, paramType)); + } } diff --git a/mh-admin/src/main/java/com/mh/web/controller/policy/PolicyManageController.java b/mh-admin/src/main/java/com/mh/web/controller/policy/PolicyManageController.java new file mode 100644 index 0000000..7278878 --- /dev/null +++ b/mh-admin/src/main/java/com/mh/web/controller/policy/PolicyManageController.java @@ -0,0 +1,32 @@ +package com.mh.web.controller.policy; + +import com.mh.common.core.controller.BaseController; +import com.mh.common.core.page.TableDataInfo; +import com.mh.system.service.policy.IPolicyManageService; +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; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 策略管理 + * @date 2025-04-01 14:51:48 + */ +@RestController +@RequestMapping("/policy") +public class PolicyManageController extends BaseController { + + private final IPolicyManageService policyManageService; + + public PolicyManageController(IPolicyManageService policyManageService) { + this.policyManageService = policyManageService; + } + + @GetMapping("/list") + public TableDataInfo getPolicyList(@RequestParam(required = false) String systemType, @RequestParam(required = false) String funPolicyType){ + return getDataTable(policyManageService.selectPolicyList(systemType,funPolicyType)); + } +} diff --git a/mh-admin/src/main/resources/application-dev.yml b/mh-admin/src/main/resources/application-dev.yml index 4e99947..8f2836a 100644 --- a/mh-admin/src/main/resources/application-dev.yml +++ b/mh-admin/src/main/resources/application-dev.yml @@ -99,6 +99,7 @@ spring: master: #添加allowMultiQueries=true 在批量更新时才不会出错 url: jdbc:postgresql://127.0.0.1:5432/eemcs_hw +# url: jdbc:postgresql://127.0.0.1:5432/eemcs username: postgres password: mh@803 # 从库数据源 diff --git a/mh-admin/src/main/resources/application-druid.yml b/mh-admin/src/main/resources/application-druid.yml index ed7a72c..8f7d78a 100644 --- a/mh-admin/src/main/resources/application-druid.yml +++ b/mh-admin/src/main/resources/application-druid.yml @@ -8,6 +8,7 @@ spring: master: #添加allowMultiQueries=true 在批量更新时才不会出错 url: jdbc:postgresql://127.0.0.1:5432/eemcs_hw +# url: jdbc:postgresql://127.0.0.1:5432/eemcs username: postgres password: mh@803 # 从库数据源 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 new file mode 100644 index 0000000..c2952e3 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/PolicyManage.java @@ -0,0 +1,92 @@ +package com.mh.common.core.domain.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Getter; +import lombok.Setter; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.math.BigDecimal; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 策略管理 + * @date 2025-04-01 14:26:31 + */ +@Setter +@Getter +@TableName("policy_manage") +public class PolicyManage { + + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + /** + * 策略类型 + */ + private String policyType; + + /** + * 策略名称 + */ + private String policyName; + + /** + * 点位名称 + */ + private String pointName; + + /** + * 输入类型 + */ + private String inputType; + + /** + * 输入值 + */ + private BigDecimal curValue; + + /** + * 单位 + */ + private String unit; + + /** + * 采集点位名称 + */ + private String cpmId; + + /** + * 系统类型 + */ + private String systemType; + + /** + * 功能策略类型 + */ + private String funPolicyType; + + /** + * 排序 + */ + private int orderNum; + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("id", id) + .append("policyType", policyType) + .append("policyName", policyName) + .append("pointName", pointName) + .append("inputType", inputType) + .append("unit", unit) + .append("cpmId", cpmId) + .append("systemType", systemType) + .append("funPolicyType", funPolicyType) + .toString(); + } + +} diff --git a/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttInboundConfig.java b/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttInboundConfig.java index d3e4c71..5dbf207 100644 --- a/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttInboundConfig.java +++ b/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttInboundConfig.java @@ -51,7 +51,7 @@ public class MqttInboundConfig { clientId, mqttClientFactory, options.getInboundTopic().split(",")); - System.out.println("每一次都会入站适配器吗?"+clientId); + // System.out.println("每一次都会入站适配器吗?"+clientId); DefaultPahoMessageConverter converter = new DefaultPahoMessageConverter(); // 统一是字节处理 converter.setPayloadAsBytes(true); diff --git a/mh-quartz/src/main/java/com/mh/quartz/task/GetWeatherDataTask.java b/mh-quartz/src/main/java/com/mh/quartz/task/GetWeatherDataTask.java index 0b956ba..906e3d3 100644 --- a/mh-quartz/src/main/java/com/mh/quartz/task/GetWeatherDataTask.java +++ b/mh-quartz/src/main/java/com/mh/quartz/task/GetWeatherDataTask.java @@ -47,7 +47,7 @@ public class GetWeatherDataTask { String returnResult = restTemplate.getForObject(url, String.class); if (!StringUtils.isBlank(returnResult)) { JSONObject jsonObject = JSON.parseObject(returnResult); - System.out.println(jsonObject); + //System.out.println(jsonObject); if ("1".equals(jsonObject.get("status"))) { try { WeatherData weatherData = new WeatherData(); diff --git a/mh-system/src/main/java/com/mh/system/mapper/policy/PolicyManageMapper.java b/mh-system/src/main/java/com/mh/system/mapper/policy/PolicyManageMapper.java new file mode 100644 index 0000000..21720bb --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/policy/PolicyManageMapper.java @@ -0,0 +1,26 @@ +package com.mh.system.mapper.policy; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.common.core.domain.entity.PolicyManage; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 策略管理 + * @date 2025-04-01 15:11:28 + */ +@Mapper +public interface PolicyManageMapper extends BaseMapper { + + @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} order by pm.policy_type, pm.order_num ") + List selectPolicyList(@Param("systemType") String systemType, + @Param("funPolicyType") String funPolicyType); +} diff --git a/mh-system/src/main/java/com/mh/system/service/device/ICoolingSystemMonitorService.java b/mh-system/src/main/java/com/mh/system/service/device/ICoolingSystemMonitorService.java index d2bee1e..0dd009a 100644 --- a/mh-system/src/main/java/com/mh/system/service/device/ICoolingSystemMonitorService.java +++ b/mh-system/src/main/java/com/mh/system/service/device/ICoolingSystemMonitorService.java @@ -1,6 +1,7 @@ package com.mh.system.service.device; import com.mh.common.core.domain.dto.SysPerformanceDTO; +import com.mh.common.core.domain.entity.CollectionParamsManage; import java.util.Map; @@ -30,4 +31,6 @@ public interface ICoolingSystemMonitorService { * @return */ SysPerformanceDTO getSysPerformance(); + + CollectionParamsManage getOneKeyButton(String systemType, String paramType); } 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 1afd39d..3bcd40c 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 @@ -222,6 +222,7 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag // 如果paramType="4",则是频率反馈,则赋值给frequency // 使用Stream API处理数据 Map> groupedByDeviceType = collectionParamsManages.stream() + .filter(p -> p.getDeviceLedgerId() != null && StringUtils.isNotEmpty(p.getDeviceLedgerId())) .collect(Collectors.groupingBy(CollectionParamsManageVO::getId)) .values() .stream() @@ -266,6 +267,7 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag // 按设备台账ID分组 Map> groupedByDevice = collectionParamsManages.stream() .sorted(Comparator.comparing(CollectionParamsManageVO::getDlOrderNum)) + .filter(p -> p.getDeviceLedgerId() != null && StringUtils.isNotEmpty(p.getDeviceLedgerId())) .collect(Collectors.groupingBy(CollectionParamsManageVO::getDeviceLedgerId)); // 转换分组结果为监控VO列表 diff --git a/mh-system/src/main/java/com/mh/system/service/device/impl/CoolingSystemMonitorServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/device/impl/CoolingSystemMonitorServiceImpl.java index 61ebe8b..ce87044 100644 --- a/mh-system/src/main/java/com/mh/system/service/device/impl/CoolingSystemMonitorServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/device/impl/CoolingSystemMonitorServiceImpl.java @@ -5,6 +5,7 @@ import com.mh.common.core.domain.dto.SysPerformanceDTO; import com.mh.common.core.domain.entity.CollectionParamsManage; import com.mh.common.core.domain.entity.SysParams; import com.mh.common.core.domain.entity.WeatherData; +import com.mh.common.core.domain.vo.DeviceOperateMonitorVO; import com.mh.common.utils.DateUtils; import com.mh.common.utils.WeatherUtil; import com.mh.system.mapper.SysParamsMapper; @@ -42,6 +43,11 @@ public class CoolingSystemMonitorServiceImpl implements ICoolingSystemMonitorSer this.collectionParamsManageMapper = collectionParamsManageMapper; } + @Override + public CollectionParamsManage getOneKeyButton(String systemType, String paramType) { + return collectionParamsManageMapper.selectOne(new QueryWrapper().eq("system_type", systemType).eq("param_type", paramType)); + } + @Override public SysPerformanceDTO getSysPerformance() { SysPerformanceDTO sysPerformanceDTO = new SysPerformanceDTO(); diff --git a/mh-system/src/main/java/com/mh/system/service/overview/impl/ProOverviewServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/overview/impl/ProOverviewServiceImpl.java index 34999c2..63e4c8b 100644 --- a/mh-system/src/main/java/com/mh/system/service/overview/impl/ProOverviewServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/overview/impl/ProOverviewServiceImpl.java @@ -92,25 +92,28 @@ public class ProOverviewServiceImpl implements IProOverviewService { // 热泵生活热水系统 // 查询供回水温度 List realInAndOutTempParams = queryCollectionParams("12", "1", 140); - // 查询供水温度的平均值 - BigDecimal avgOutTemp = realInAndOutTempParams.stream() - .filter(param -> param != null - && param.getOtherName() != null - && param.getOtherName().contains("供水")) - .map(CollectionParamsManage::getCurValue) - .filter(Objects::nonNull) - .reduce(BigDecimal.ZERO, BigDecimal::add) - .divide(new BigDecimal(realInAndOutTempParams.size()), 2, BigDecimal.ROUND_HALF_UP); - // 查询回水温度的平均值 - BigDecimal avgInTemp = realInAndOutTempParams.stream() - .filter(param -> param != null - && param.getOtherName() != null - && param.getOtherName().contains("回水")) - .map(CollectionParamsManage::getCurValue) - .filter(Objects::nonNull) - .reduce(BigDecimal.ZERO, BigDecimal::add) - .divide(new BigDecimal(realInAndOutTempParams.size()), 2, BigDecimal.ROUND_HALF_UP); - + BigDecimal avgInTemp = new BigDecimal("0.00"); + BigDecimal avgOutTemp = new BigDecimal("0.00"); + if (null != realInAndOutTempParams && !realInAndOutTempParams.isEmpty()) { + // 查询供水温度的平均值 + avgOutTemp = realInAndOutTempParams.stream() + .filter(param -> param != null + && param.getOtherName() != null + && param.getOtherName().contains("供水")) + .map(CollectionParamsManage::getCurValue) + .filter(Objects::nonNull) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(new BigDecimal(realInAndOutTempParams.size()), 2, BigDecimal.ROUND_HALF_UP); + // 查询回水温度的平均值 + avgInTemp = realInAndOutTempParams.stream() + .filter(param -> param != null + && param.getOtherName() != null + && param.getOtherName().contains("回水")) + .map(CollectionParamsManage::getCurValue) + .filter(Objects::nonNull) + .reduce(BigDecimal.ZERO, BigDecimal::add) + .divide(new BigDecimal(realInAndOutTempParams.size()), 2, BigDecimal.ROUND_HALF_UP); + } ColumnFilter inTempColumn = new ColumnFilter("回水平均温度", avgInTemp.toString()); ColumnFilter outTempColumn = new ColumnFilter("供水平均温度", avgOutTemp.toString()); DeviceMonitorDTO deviceMonitorDTO2 = new DeviceMonitorDTO(); 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 new file mode 100644 index 0000000..03de176 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/policy/IPolicyManageService.java @@ -0,0 +1,14 @@ +package com.mh.system.service.policy; + +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 策略管理 + * @date 2025-04-01 15:04:53 + */ +public interface IPolicyManageService { + List selectPolicyList(String systemType, String funPolicyType); +} 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 new file mode 100644 index 0000000..d6fe0b3 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/policy/impl/PolicyManageServiceImpl.java @@ -0,0 +1,55 @@ +package com.mh.system.service.policy.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.mh.common.core.domain.dto.DeviceMonitorDTO; +import com.mh.common.core.domain.entity.PolicyManage; +import com.mh.system.mapper.policy.PolicyManageMapper; +import com.mh.system.service.policy.IPolicyManageService; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 策略管理服务实现类 + * @date 2025-04-01 15:05:43 + */ +@Service +public class PolicyManageServiceImpl implements IPolicyManageService { + + private final PolicyManageMapper policyManageMapper; + + public PolicyManageServiceImpl(PolicyManageMapper policyManageMapper) { + this.policyManageMapper = policyManageMapper; + } + + @Override + public List selectPolicyList(String systemType, String funPolicyType) { +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// queryWrapper.eq("system_type", systemType); +// queryWrapper.eq("fun_policy_type", funPolicyType); +// queryWrapper.orderByAsc("order_num"); + List policyManages = policyManageMapper.selectPolicyList(systemType, funPolicyType); + // policyManages使用stream流,根据policyType进行数据分组, + Map> listMap = policyManages.stream() + // 先按PolicyType排序 + .sorted(Comparator.comparing(PolicyManage::getPolicyType)) + // 再按PolicyName分组 + .collect(Collectors.groupingBy(PolicyManage::getPolicyName, Collectors.toList())); + // 在遍历赋值给DeviceMonitorDTO,key给name,value给list + List list = new ArrayList<>(); + listMap.keySet().forEach(k -> { + DeviceMonitorDTO deviceMonitorDTO = new DeviceMonitorDTO(); + deviceMonitorDTO.setName(k); + deviceMonitorDTO.setValues(listMap.get(k)); + list.add(deviceMonitorDTO); + }); + return list; + } +} diff --git a/sql/表结构设计.sql b/sql/表结构设计.sql index 8cac8bf..64c23dc 100644 --- a/sql/表结构设计.sql +++ b/sql/表结构设计.sql @@ -658,4 +658,32 @@ COMMENT ON COLUMN weather_data.humidity IS '相对湿度,百分比(0-100)'; COMMENT ON COLUMN weather_data.wind_direction IS '风向描述'; COMMENT ON COLUMN weather_data.wind_power IS '风力等级描述'; COMMENT ON COLUMN weather_data.report_time IS '天气数据报告时间,数据来源的原始时间'; -COMMENT ON COLUMN weather_data.created_time IS '记录创建时间,系统自动记录'; \ No newline at end of file +COMMENT ON COLUMN weather_data.created_time IS '记录创建时间,系统自动记录'; + + +-- 建表语句 +CREATE TABLE policy_manage ( + id VARCHAR(36) PRIMARY KEY not NULL, + policy_type VARCHAR(50) NOT NULL, + policy_name VARCHAR(50) NOT NULL, + point_name VARCHAR(100) NOT NULL, + input_type VARCHAR(50) NOT NULL, + unit VARCHAR(20), + cpm_id VARCHAR(36) NOT NULL, + system_type VARCHAR(10) NOT NULL, + fun_policy_type varchar(10) not null, + FOREIGN KEY (cpm_id) REFERENCES collection_params_manage(id) +) WITH (OIDS = FALSE); + +-- 添加注释 +COMMENT ON TABLE policy_manage IS '策略管理核心表'; +COMMENT ON COLUMN policy_manage.policy_type IS '策略类型(枚举值)'; +COMMENT ON COLUMN policy_manage.policy_name IS '策略名称'; +COMMENT ON COLUMN policy_manage.input_type IS '输入类型:select,text等'; +COMMENT ON COLUMN policy_manage.unit IS '单位符号,允许为空表示无单位'; +COMMENT ON COLUMN policy_manage.cpm_id IS '采集点位参数id'; +COMMENT ON COLUMN policy_manage.system_type IS '项目类型'; +COMMENT ON COLUMN policy_manage.fun_policy_type IS '功能策略类型:0 设备策略,1 定时策略'; + +-- 创建索引 +CREATE INDEX idx_binding_param ON policy_manage(cpm_id); \ No newline at end of file