From 4732280dc514ef1c0c5069e239864b4cf6ca28f7 Mon Sep 17 00:00:00 2001 From: "3067418132@qq.com" Date: Wed, 10 Jun 2026 13:37:36 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=9D=E5=88=A9=E8=83=BD=E7=AE=A1?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=A1=B9=E7=9B=AE=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=AF=B9=E5=BA=94=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mh-admin/src/main/java/com/mh/MHRunner.java | 4 +- .../device/OperationController.java | 32 +- .../controller/monitor/HomeController.java | 76 +++ .../controller/mqtt/MqttSubsController.java | 2 + .../controller/mqtt/MqttTopicController.java | 2 + .../src/main/resources/application-dev.yml | 12 +- .../src/main/resources/application-prod.yml | 2 + .../src/main/resources/application-test.yml | 2 + mh-admin/src/main/resources/application.yml | 2 +- .../com/mh/common/constant/DateConstant.java | 15 + .../core/domain/entity/DeviceState.java | 6 +- .../core/domain/entity/HistoryEntity.java | 15 + .../core/domain/entity/chart/AxisLine.java | 30 ++ .../domain/entity/chart/BaseChartEntity.java | 45 ++ .../core/domain/entity/chart/ChartEntity.java | 54 +++ .../core/domain/entity/chart/ChartParams.java | 17 + .../core/domain/entity/chart/Feature.java | 31 ++ .../domain/entity/chart/GetChartParams.java | 35 ++ .../core/domain/entity/chart/Legend.java | 30 ++ .../core/domain/entity/chart/LineStyle.java | 21 + .../core/domain/entity/chart/Series.java | 38 ++ .../core/domain/entity/chart/SplitLine.java | 21 + .../core/domain/entity/chart/Title.java | 25 + .../core/domain/entity/chart/ToolTip.java | 16 + .../common/core/domain/entity/chart/Unit.java | 37 ++ .../core/domain/entity/chart/XAxis.java | 21 + .../core/domain/entity/chart/YAxis.java | 31 ++ .../mh/common/core/page/TableDataInfo.java | 31 ++ .../common/utils/AnalysisReceiveOrder485.java | 27 +- .../com/mh/common/utils/BigDecimalUtils.java | 7 + .../com/mh/common/utils/SendOrderUtils.java | 5 +- .../java/com/mh/common/utils/TableUtils.java | 79 ++++ .../mh/framework/mqtt/config/MqttConfig.java | 2 + .../mqtt/config/MqttInboundConfig.java | 2 + .../mqtt/config/MqttMessageChannel.java | 2 + .../mqtt/config/MqttOutboundConfig.java | 2 + .../mqtt/handler/InboundMessageRouter.java | 2 + .../mqtt/service/impl/EventsServiceImpl.java | 2 + .../service/impl/MqttGatewayServiceImpl.java | 2 + .../impl/MqttMsgSenderServiceImpl.java | 2 + .../service/impl/MqttTopicServiceImpl.java | 2 + .../mh/framework/netty/EchoServerHandler.java | 7 +- .../main/java/com/mh/quartz/task/AHUTask.java | 2 + .../java/com/mh/quartz/task/ChillersTask.java | 2 + .../mh/quartz/task/GetOtherSysDataJob.java | 392 +++++++++++++++ .../mh/system/mapper/energy/EnergyMapper.java | 6 +- .../mapper/energy/EnergyQueryMapper.java | 6 + .../mh/system/mapper/overview/HomeMapper.java | 278 +++++++++++ .../system/mapper/overview/ReportMapper.java | 147 ++++++ .../energy/impl/EnergyAnalyzeServiceImpl.java | 11 + .../energy/impl/EnergyQueryServiceImpl.java | 40 +- .../system/service/overview/HomeService.java | 55 +++ .../overview/impl/HomeServiceImpl.java | 446 ++++++++++++++++++ .../overview/impl/ProOverviewServiceImpl.java | 6 +- .../resources/mapper/system/EnergyMapper.xml | 63 ++- 55 files changed, 2185 insertions(+), 65 deletions(-) create mode 100644 mh-admin/src/main/java/com/mh/web/controller/monitor/HomeController.java create mode 100644 mh-common/src/main/java/com/mh/common/constant/DateConstant.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/HistoryEntity.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/AxisLine.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/BaseChartEntity.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ChartEntity.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ChartParams.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Feature.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/GetChartParams.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Legend.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/LineStyle.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Series.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/SplitLine.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Title.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ToolTip.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Unit.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/XAxis.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/chart/YAxis.java create mode 100644 mh-common/src/main/java/com/mh/common/utils/TableUtils.java create mode 100644 mh-quartz/src/main/java/com/mh/quartz/task/GetOtherSysDataJob.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/overview/HomeMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/overview/ReportMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/service/overview/HomeService.java create mode 100644 mh-system/src/main/java/com/mh/system/service/overview/impl/HomeServiceImpl.java diff --git a/mh-admin/src/main/java/com/mh/MHRunner.java b/mh-admin/src/main/java/com/mh/MHRunner.java index 7e42007..c2d19a1 100644 --- a/mh-admin/src/main/java/com/mh/MHRunner.java +++ b/mh-admin/src/main/java/com/mh/MHRunner.java @@ -10,6 +10,7 @@ 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.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import java.util.List; @@ -23,6 +24,7 @@ import java.util.stream.Collectors; * @date 2025-02-14 16:35:50 */ @Component +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class MHRunner implements ApplicationRunner { private final IMqttSubscriptionService iMqttSubscriptionService; @@ -43,7 +45,7 @@ public class MHRunner implements ApplicationRunner { @Override public void run(ApplicationArguments args) throws Exception { // 初始化mqtt订阅记录 - initializeMqttSubscription(); +// initializeMqttSubscription(); // 生成DTU采集参数 // createDtuCollectionParams(); // 启动netty服务端 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 abe9b5a..7d32d8a 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 @@ -40,23 +40,17 @@ public class OperationController extends BaseController { @Autowired private MHConfig mhConfig; - private final ICollectionParamsManageService iCollectionParamsManageService; - - private final IOperationDeviceService iOperationService; + @Autowired + private ICollectionParamsManageService iCollectionParamsManageService; - private final IMqttGatewayService iMqttGatewayService; + @Autowired + private IOperationDeviceService iOperationService; - private final INettyService nettyService; + @Autowired(required = false) + private IMqttGatewayService iMqttGatewayService; @Autowired - public OperationController(ICollectionParamsManageService iCollectionParamsManageService, - IOperationDeviceService iOperationService, - IMqttGatewayService iMqttGatewayService, INettyService nettyService) { - this.iCollectionParamsManageService = iCollectionParamsManageService; - this.iOperationService = iOperationService; - this.iMqttGatewayService = iMqttGatewayService; - this.nettyService = nettyService; - } + private INettyService nettyService; /** * 获取监控列表内容数据 @@ -105,14 +99,22 @@ public class OperationController extends BaseController { String name = mhConfig.getName(); // 获取mqtt操作队列(后期通过mqtt队列配置发送主题) log.info("发送主题:{},消息:{}", name + "/" + controlTopic, sendOrder); - iMqttGatewayService.publish(name + "/" + controlTopic, sendOrder, 1); + if (iMqttGatewayService != null) { + iMqttGatewayService.publish(name + "/" + controlTopic, sendOrder, 1); + } else { + log.warn("MQTT未启用,无法发送控制指令"); + } } else if (!iOperationService.isAdvanTech(changeValues)) { // 判断id是否是DTU设备类型 String sendOrder = iOperationService.operationDevice(changeValues); String name = mhConfig.getName(); // 获取mqtt操作队列(后期通过mqtt队列配置发送主题) log.info("发送主题:{},消息:{}", name + "/" + controlTopic, sendOrder); - iMqttGatewayService.publish(name + "/" + controlTopic, sendOrder, 1); + if (iMqttGatewayService != null) { + iMqttGatewayService.publish(name + "/" + controlTopic, sendOrder, 1); + } else { + log.warn("MQTT未启用,无法发送控制指令"); + } } else { // 目前只有DTU设备需要发送4G指令 if (nettyService.sendOrder(changeValues)) { diff --git a/mh-admin/src/main/java/com/mh/web/controller/monitor/HomeController.java b/mh-admin/src/main/java/com/mh/web/controller/monitor/HomeController.java new file mode 100644 index 0000000..8334bef --- /dev/null +++ b/mh-admin/src/main/java/com/mh/web/controller/monitor/HomeController.java @@ -0,0 +1,76 @@ +package com.mh.web.controller.monitor; + +import com.mh.common.core.controller.BaseController; +import com.mh.common.core.page.TableDataInfo; +import com.mh.system.service.overview.HomeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 新增首页监控 + * @date 2026-06-05 10:14:39 + */ +@RestController +@RequestMapping("/home") +public class HomeController extends BaseController { + + @Autowired + HomeService homeService; + + /** + * 主界面图表 + * @return + */ + @GetMapping("/charts") + public TableDataInfo getHomeCharts(){ + return homeService.getHomeCharts(); + } + + /** + * 查询日供冷量、月供冷量、年供冷量 + * 日、月、年、累计EER + * 累计供冷量 + * @return + */ + @GetMapping("/statical") + public TableDataInfo getStatisticalData(){ + return homeService.getStatisticalData(); + } + + /** + * 查询能耗系数 + * @return + */ + @GetMapping("/getCoe") + public TableDataInfo getCoe(){ + return homeService.getCoe(); + } + + /** + * 查询系统运行时长 + * @return + */ + @GetMapping("/getRunTime") + public TableDataInfo getRunTime(){ + return homeService.getRunTime(); + } + + /** + * 获取实时功率 + * @return + */ + @GetMapping("/getCurrentRate") + public TableDataInfo getCurrentRate(){ + return homeService.getCurrentRate(); + } + + @GetMapping("/getWeatherData") + public TableDataInfo getWeatherData() { + return homeService.getWeatherData(); + } +} \ No newline at end of file diff --git a/mh-admin/src/main/java/com/mh/web/controller/mqtt/MqttSubsController.java b/mh-admin/src/main/java/com/mh/web/controller/mqtt/MqttSubsController.java index 5df8ee3..b7a769d 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/mqtt/MqttSubsController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/mqtt/MqttSubsController.java @@ -10,6 +10,7 @@ import com.mh.common.utils.StringUtils; import com.mh.framework.mqtt.service.IMqttTopicService; import com.mh.system.service.mqtt.IMqttSubscriptionService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -28,6 +29,7 @@ import java.util.Objects; */ @RestController @RequestMapping("/mqtt/subs") +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class MqttSubsController extends BaseController { @Autowired diff --git a/mh-admin/src/main/java/com/mh/web/controller/mqtt/MqttTopicController.java b/mh-admin/src/main/java/com/mh/web/controller/mqtt/MqttTopicController.java index 564f011..410bc1e 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/mqtt/MqttTopicController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/mqtt/MqttTopicController.java @@ -3,6 +3,7 @@ package com.mh.web.controller.mqtt; import com.mh.framework.mqtt.service.IMqttMsgSenderService; import com.mh.framework.mqtt.service.IMqttTopicService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -18,6 +19,7 @@ import java.util.Arrays; */ @RestController @RequestMapping("/topic") +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class MqttTopicController { @Autowired diff --git a/mh-admin/src/main/resources/application-dev.yml b/mh-admin/src/main/resources/application-dev.yml index 37b8b6b..89fb5a2 100644 --- a/mh-admin/src/main/resources/application-dev.yml +++ b/mh-admin/src/main/resources/application-dev.yml @@ -1,7 +1,7 @@ # 项目相关配置 mh: # 名称 - name: gh_ers_dev + name: bl_dev # 版本 version: 1.0.0 # 版权年份 @@ -63,7 +63,7 @@ spring: # 端口,默认为6379 port: 6379 # 数据库索引 - database: 1 + database: 3 # 密码 password: # 连接超时时间 @@ -84,7 +84,7 @@ spring: port: 5672 username: eemcs password: mh@803 - virtual-host: /eemcs_gh_ers + virtual-host: /eemcs_bl_dev listener: direct: prefetch: 2 @@ -98,7 +98,7 @@ spring: # 主库数据源 master: #添加allowMultiQueries=true 在批量更新时才不会出错 - url: jdbc:postgresql://127.0.0.1:5432/eemcs_gh_ers_dev + url: jdbc:postgresql://127.0.0.1:5432/eemcs_bl_dev # url: jdbc:postgresql://106.55.173.225:5505/eemcs username: postgres password: mh@803 @@ -188,6 +188,8 @@ xss: urlPatterns: /system/*,/monitor/*,/tool/* mqttSpring: + # 是否启用MQTT,默认false + enabled: false # BASIC parameters are required. BASIC: protocol: MQTT @@ -200,7 +202,7 @@ mqttSpring: # port: 1883 # username: sa # password: sa123 - client-id: mqtt_gh_ers_producer_dev + client-id: mqtt_bl_producer_dev # If the protocol is ws/wss, this value is required. path: # Topics that need to be subscribed when initially connecting to mqtt, multiple topics are divided by ",". diff --git a/mh-admin/src/main/resources/application-prod.yml b/mh-admin/src/main/resources/application-prod.yml index 5763df8..f026e67 100644 --- a/mh-admin/src/main/resources/application-prod.yml +++ b/mh-admin/src/main/resources/application-prod.yml @@ -188,6 +188,8 @@ xss: urlPatterns: /system/*,/monitor/*,/tool/* mqttSpring: + # 是否启用MQTT,默认false + enabled: false # BASIC parameters are required. BASIC: protocol: MQTT diff --git a/mh-admin/src/main/resources/application-test.yml b/mh-admin/src/main/resources/application-test.yml index 404efc4..ce594c0 100644 --- a/mh-admin/src/main/resources/application-test.yml +++ b/mh-admin/src/main/resources/application-test.yml @@ -187,6 +187,8 @@ xss: urlPatterns: /system/*,/monitor/*,/tool/* mqttSpring: + # 是否启用MQTT,默认false + enabled: false # BASIC parameters are required. BASIC: protocol: MQTT diff --git a/mh-admin/src/main/resources/application.yml b/mh-admin/src/main/resources/application.yml index 44f7920..c3ae7c3 100644 --- a/mh-admin/src/main/resources/application.yml +++ b/mh-admin/src/main/resources/application.yml @@ -1,6 +1,6 @@ spring: profiles: - active: prod + active: dev # 用户配置 user: diff --git a/mh-common/src/main/java/com/mh/common/constant/DateConstant.java b/mh-common/src/main/java/com/mh/common/constant/DateConstant.java new file mode 100644 index 0000000..1196623 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/constant/DateConstant.java @@ -0,0 +1,15 @@ +package com.mh.common.constant; + +import java.text.SimpleDateFormat; + +/** + * @Author : Rainbow + * @date : 2023/7/10 + */ +public class DateConstant { + public final static SimpleDateFormat DAY_SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + public final static SimpleDateFormat MONTH = new SimpleDateFormat("yyyy-MM"); + public final static SimpleDateFormat DAY = new SimpleDateFormat("yyyy-MM-dd"); + public final static SimpleDateFormat MONTH_SDF = new SimpleDateFormat("yyyy-MM-dd"); + public final static SimpleDateFormat YEAR_SDF = new SimpleDateFormat("yyyy"); +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/DeviceState.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/DeviceState.java index 61f8ab4..35c002f 100644 --- a/mh-common/src/main/java/com/mh/common/core/domain/entity/DeviceState.java +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/DeviceState.java @@ -1,6 +1,8 @@ package com.mh.common.core.domain.entity; -import com.alibaba.fastjson2.annotation.JSONField; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; @@ -13,11 +15,13 @@ import java.util.Date; * @description 设备统计状态表 */ @Data +@TableName("device_state") public class DeviceState { /** * 当前时间 */ + @TableId(type = IdType.INPUT) @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date curDate; diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/HistoryEntity.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/HistoryEntity.java new file mode 100644 index 0000000..ee84cea --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/HistoryEntity.java @@ -0,0 +1,15 @@ +package com.mh.common.core.domain.entity; + +import lombok.Data; + +/** + * @Author : Rainbow + * @date : 2023/7/11 + */ +@Data +public class HistoryEntity { + private int id; + private String name; + private String date; + private double value; +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/AxisLine.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/AxisLine.java new file mode 100644 index 0000000..2b80b9f --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/AxisLine.java @@ -0,0 +1,30 @@ +package com.mh.common.core.domain.entity.chart; + +import lombok.Getter; +import lombok.Setter; + +/** + * @author LJF + * @title : + * @description : + * @updateTime 2020-07-10 + * @throws : + */ +@Setter +@Getter +public class AxisLine { + private boolean show; + private LineStyle lineStyle; + private String color = ""; + + public AxisLine(boolean show, LineStyle lineStyle) { + this.show = show; + this.lineStyle = lineStyle; + } + + public AxisLine(boolean show, LineStyle lineStyle, String color) { + this.show = show; + this.lineStyle = lineStyle; + this.color = color; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/BaseChartEntity.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/BaseChartEntity.java new file mode 100644 index 0000000..d797efd --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/BaseChartEntity.java @@ -0,0 +1,45 @@ +package com.mh.common.core.domain.entity.chart; + +import lombok.Getter; +import lombok.Setter; + +/** + * @author LJF + * @title : 基础数据获取实体类 + * @description : + * @updateTime 2020-07-13 + * @throws : + */ +@Setter +@Getter +public class BaseChartEntity { + + private String chartTime; + private String indexName; + private String indexType; + private String displayType; + private int indexId; + private int width; + private String chartName; + private String timeName; + private int chartId; + private String unit; + private double data; + + @Override + public String toString() { + return "BaseChartEntity{" + + "chartTime='" + chartTime + '\'' + + ", indexName='" + indexName + '\'' + + ", indexType='" + indexType + '\'' + + ", displayType='" + displayType + '\'' + + ", indexId=" + indexId + + ", width=" + width + + ", chartName='" + chartName + '\'' + + ", timeName='" + timeName + '\'' + + ", chartId=" + chartId + + ", unit='" + unit + '\'' + + ", data=" + data + + '}'; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ChartEntity.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ChartEntity.java new file mode 100644 index 0000000..fb0e36a --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ChartEntity.java @@ -0,0 +1,54 @@ +package com.mh.common.core.domain.entity.chart; + +import com.alibaba.fastjson2.annotation.JSONType; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +/** + * @author LJF + * @title :图表实体类 + * @description : + * @updateTime 2020-07-10 + * @throws : + */ +@Setter +@Getter +@JSONType(orders = {"title","feature","legend","xAxis","yAxis","series","timeName"}) +public class ChartEntity { + + private Title title; + private Feature feature; + private Legend legend; + private ToolTip toolTip; + private XAxis xAxis; + private List yAxis; + private List series; + + public ChartEntity() { + } + + public ChartEntity(Title title, Feature feature, Legend legend, XAxis xAxis, List yAxis, List series) { + this.title = title; + this.feature = feature; + this.legend = legend; + this.xAxis = xAxis; + this.yAxis = yAxis; + this.series = series; + } + + @Override + public String toString() { + return "ChartEntity{" + + "title=" + title + + ", feature=" + feature + + ", legend=" + legend + + ", xAxis=" + xAxis + + ", yAxis=" + yAxis + + ", series=" + series + + '}'; + } +} + + diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ChartParams.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ChartParams.java new file mode 100644 index 0000000..20631c6 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ChartParams.java @@ -0,0 +1,17 @@ +package com.mh.common.core.domain.entity.chart; + +import lombok.Data; + +/** + * @author 铭汉科技——LJF + * @date 2023-03-23 15:25 + * @Description + */ +@Data +public class ChartParams { + private String beginTime; + private String endTime; + private String dayType; + private String charType; + private String chooseId; +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Feature.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Feature.java new file mode 100644 index 0000000..4b51d2c --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Feature.java @@ -0,0 +1,31 @@ +package com.mh.common.core.domain.entity.chart; + +import com.alibaba.fastjson2.annotation.JSONType; +import lombok.Getter; +import lombok.Setter; + +/** + * @author LJF + * @title : + * @description : + * @updateTime 2020-07-10 + * @throws : + */ +@Getter +@Setter +@JSONType(orders = {"state","tile","icon","name"}) +public class Feature { + private boolean[] state; + private String[] title; + private String[] icon; + private String[] name; + private String[] yAxisName; + + public Feature(boolean[] state, String[] title, String[] icon, String[] name, String[] yAxisName) { + this.state = state; + this.title = title; + this.icon = icon; + this.name = name; + this.yAxisName = yAxisName; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/GetChartParams.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/GetChartParams.java new file mode 100644 index 0000000..a5d52ec --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/GetChartParams.java @@ -0,0 +1,35 @@ +package com.mh.common.core.domain.entity.chart; + +import lombok.Getter; +import lombok.Setter; + +import java.util.Arrays; + +/** + * @author LJF + * @title : + * @description : + * @updateTime 2020-07-17 + * @throws : + */ +@Setter +@Getter +public class GetChartParams { + + private int chartId; + private int[] chooseIndexId; + private String beginTime; + private String endTime; + private String type; // 'today' 'yesterday' 'twentyFourHour' 'thisWeek' 'fourWeek' 'twelveMonth' 'fourYear' + + @Override + public String toString() { + return "GetChartParams{" + + "chartId=" + chartId + + ", chooseIndexId=" + Arrays.toString(chooseIndexId) + + ", beginTime='" + beginTime + '\'' + + ", endTime='" + endTime + '\'' + + ", type='" + type + '\'' + + '}'; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Legend.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Legend.java new file mode 100644 index 0000000..20de93b --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Legend.java @@ -0,0 +1,30 @@ +package com.mh.common.core.domain.entity.chart; + +import com.alibaba.fastjson2.annotation.JSONType; +import lombok.Getter; +import lombok.Setter; + +/** + * @author LJF + * @title : + * @description : + * @updateTime 2020-07-10 + * @throws : + */ +@Setter +@Getter +@JSONType(orders = {"data","width","indexId"}) +public class Legend { + private String[] data; + private int width; + private int[] indexId; + + public Legend() { + } + + public Legend(String[] data, int width, int[] indexId) { + this.data = data; + this.width = width; + this.indexId = indexId; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/LineStyle.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/LineStyle.java new file mode 100644 index 0000000..8b62b81 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/LineStyle.java @@ -0,0 +1,21 @@ +package com.mh.common.core.domain.entity.chart; + +import lombok.Getter; +import lombok.Setter; + +/** + * @author LJF + * @title : + * @description : + * @updateTime 2020-07-10 + * @throws : + */ +@Setter +@Getter +public class LineStyle { + private String color; + + public LineStyle(String color) { + this.color = color; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Series.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Series.java new file mode 100644 index 0000000..c4f5075 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Series.java @@ -0,0 +1,38 @@ +package com.mh.common.core.domain.entity.chart; + +import com.alibaba.fastjson2.annotation.JSONType; +import lombok.Getter; +import lombok.Setter; + +/** + * @author LJF + * @title : + * @description : + * @updateTime 2020-07-10 + * @throws : + */ +@Setter +@Getter +@JSONType(orders = {"name","type","yAxisIndex","data","sampling"}) +public class Series { + private String name; + private String type; + private int yAxisIndex = 0; + private Double[] data; + private String sampling = "average"; + + public Series(String name, String type, int yAxisIndex, Double[] data) { + this.name = name; + this.type = type; + this.yAxisIndex = yAxisIndex; + this.data = data; + } + + public Series(String name, String type, int yAxisIndex, Double[] data, String sampling) { + this.name = name; + this.type = type; + this.yAxisIndex = yAxisIndex; + this.data = data; + this.sampling = sampling; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/SplitLine.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/SplitLine.java new file mode 100644 index 0000000..4a1d5ab --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/SplitLine.java @@ -0,0 +1,21 @@ +package com.mh.common.core.domain.entity.chart; + +import lombok.Getter; +import lombok.Setter; + +/** + * @author LJF + * @title : + * @description : + * @updateTime 2020-07-10 + * @throws : + */ +@Setter +@Getter +public class SplitLine { + private boolean show; + + public SplitLine(boolean show) { + this.show = show; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Title.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Title.java new file mode 100644 index 0000000..eb4295a --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Title.java @@ -0,0 +1,25 @@ +package com.mh.common.core.domain.entity.chart; + +import com.alibaba.fastjson2.annotation.JSONType; +import lombok.Getter; +import lombok.Setter; + +/** + * @author LJF + * @title : + * @description : + * @updateTime 2020-07-10 + * @throws : + */ +@Setter +@Getter +@JSONType(orders = {"state","name"}) +public class Title { + private boolean state; + private String name; + + public Title(boolean state, String name) { + this.state = state; + this.name = name; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ToolTip.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ToolTip.java new file mode 100644 index 0000000..8779e54 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/ToolTip.java @@ -0,0 +1,16 @@ +package com.mh.common.core.domain.entity.chart; + +import lombok.Data; + +/** + * @Author : Rainbow + * @date : 2023/7/11 + */ +@Data +public class ToolTip { + private String trigger; + + public ToolTip(String trigger) { + this.trigger = trigger; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Unit.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Unit.java new file mode 100644 index 0000000..e106429 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/Unit.java @@ -0,0 +1,37 @@ +package com.mh.common.core.domain.entity.chart; + +import lombok.Getter; +import lombok.Setter; + +/** + * @author LJF + * @title : + * @description :单位实体类 + * @updateTime 2020-07-13 + * @throws : + */ +@Setter +@Getter +public class Unit { + + private int id; + private String unitName; + private String unit; + private String icon; + private String grade; + private String indexName; + private String otherName; + + @Override + public String toString() { + return "Unit{" + + "id=" + id + + ", unitName='" + unitName + '\'' + + ", unit='" + unit + '\'' + + ", icon='" + icon + '\'' + + ", grade='" + grade + '\'' + + ", indexName='" + indexName + '\'' + + ", otherName='" + otherName + '\'' + + '}'; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/XAxis.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/XAxis.java new file mode 100644 index 0000000..315fb03 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/XAxis.java @@ -0,0 +1,21 @@ +package com.mh.common.core.domain.entity.chart; + +import lombok.Getter; +import lombok.Setter; + +/** + * @author LJF + * @title : + * @description : + * @updateTime 2020-07-10 + * @throws : + */ +@Setter +@Getter +public class XAxis { + private String[] data; + + public XAxis(String[] data) { + this.data = data; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/YAxis.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/YAxis.java new file mode 100644 index 0000000..4ca1cf5 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/chart/YAxis.java @@ -0,0 +1,31 @@ +package com.mh.common.core.domain.entity.chart; + +import com.alibaba.fastjson2.annotation.JSONType; +import lombok.Getter; +import lombok.Setter; + +/** + * @author LJF + * @title : + * @description : + * @updateTime 2020-07-10 + * @throws : + */ +@Setter +@Getter +@JSONType(orders = {"type","name","splitLine","axisLine","show"}) +public class YAxis { + private String type; + private String name; + private SplitLine splitLine; + private AxisLine axisLine; + private boolean show; + + public YAxis(String type, String name, SplitLine splitLine, AxisLine axisLine, boolean show) { + this.type = type; + this.name = name; + this.splitLine = splitLine; + this.axisLine = axisLine; + this.show = show; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/page/TableDataInfo.java b/mh-common/src/main/java/com/mh/common/core/page/TableDataInfo.java index e95da32..22db6fc 100644 --- a/mh-common/src/main/java/com/mh/common/core/page/TableDataInfo.java +++ b/mh-common/src/main/java/com/mh/common/core/page/TableDataInfo.java @@ -1,6 +1,9 @@ package com.mh.common.core.page; +import com.mh.common.constant.HttpStatus; + import java.io.Serializable; +import java.util.Collections; import java.util.List; /** @@ -43,6 +46,34 @@ public class TableDataInfo implements Serializable this.total = total; } + /** + * 返回成功数据(无分页) + * + * @param data 数据对象 + * @return TableDataInfo + */ + public static TableDataInfo ok(Object data) + { + TableDataInfo rspData = new TableDataInfo(); + rspData.setCode(HttpStatus.SUCCESS); + rspData.setMsg("查询成功"); + rspData.setRows(Collections.singletonList(data)); + return rspData; + } + + /** + * 返回成功(无数据) + * + * @return TableDataInfo + */ + public static TableDataInfo ok() + { + TableDataInfo rspData = new TableDataInfo(); + rspData.setCode(HttpStatus.SUCCESS); + rspData.setMsg("查询成功"); + return rspData; + } + public long getTotal() { return total; diff --git a/mh-common/src/main/java/com/mh/common/utils/AnalysisReceiveOrder485.java b/mh-common/src/main/java/com/mh/common/utils/AnalysisReceiveOrder485.java index 2e30c0b..8675bda 100644 --- a/mh-common/src/main/java/com/mh/common/utils/AnalysisReceiveOrder485.java +++ b/mh-common/src/main/java/com/mh/common/utils/AnalysisReceiveOrder485.java @@ -25,7 +25,7 @@ public class AnalysisReceiveOrder485 { // private final DecimalFormat df = new DecimalFormat("#.##"); //解析冷量表 - public void analysisCloudOrder485(final String dataStr1, final CollectionParamsManage deviceCodeParam) { + public String analysisCloudOrder485(final String dataStr1, final CollectionParamsManage deviceCodeParam) { // 去掉空格 String dataStr = dataStr1.replace(" ", "").toUpperCase(); // 检验报文 @@ -36,9 +36,6 @@ public class AnalysisReceiveOrder485 { checkWord = checkWord.substring(2, 4) + checkWord.substring(0, 2); if (checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) { - //创建SimpleDateFormat对象,指定样式 2019-05-13 22:39:30 -// Date date = new Date(); -// String dateStr = sdf1.format(date); //保留两位小数处理 DecimalFormat decimalFormat = new DecimalFormat("0.00"); // 表号 @@ -51,25 +48,35 @@ public class AnalysisReceiveOrder485 { + dataStr.substring(dataStr.length() - 10, dataStr.length() - 8); String registerAddr = deviceCodeParam.getRegisterAddr(); -// if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) { -// dateStr = dateStr.substring(0, 17) + "00"; -// } else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) { -// dateStr = dateStr.substring(0, 17) + "30"; -// } try { - if (registerAddr.equals("32") || registerAddr.equals("33") || registerAddr.equals("35") || registerAddr.equals("36")) { + if (registerAddr.equals("32") + || registerAddr.equals("33") + || registerAddr.equals("35") + || registerAddr.equals("36") + || registerAddr.equals("0001") // 慧创冷量计 + || registerAddr.equals("0003") // 慧创冷量计 + || registerAddr.equals("0033") // 慧创冷量计 + || registerAddr.equals("0035") // 慧创冷量计 + || registerAddr.equals("0121") // 慧创冷量计 + ) { data = decimalFormat.format(Math.abs(ExchangeStringUtil.hexToSingle(data)));//十六进制字符串转IEEE754浮点型 log.info("冷量计==>{},寄存器地址==>{},读数==>{}", cloudId, registerAddr, data); } else if (registerAddr.equals("31") || registerAddr.equals("34")) { long lData = Long.parseLong(ExchangeStringUtil.hexToDec(data)); log.info("冷量计==>{},寄存器地址==>{},累计读数==>{}", cloudId, registerAddr, lData); } + // 判断data大于99999999,就返回空 + if (new BigDecimal(data).intValue() > 99999999) { + return ""; + } + return data; } catch (Exception e) { log.error("保存冷量计数据失败!", e); } } else { log.info("冷量计校验失败===>{}", dataStr); } + return ""; } /** diff --git a/mh-common/src/main/java/com/mh/common/utils/BigDecimalUtils.java b/mh-common/src/main/java/com/mh/common/utils/BigDecimalUtils.java index 6c6c6f3..7f1c427 100644 --- a/mh-common/src/main/java/com/mh/common/utils/BigDecimalUtils.java +++ b/mh-common/src/main/java/com/mh/common/utils/BigDecimalUtils.java @@ -52,5 +52,12 @@ public class BigDecimalUtils { System.out.println(compare("<=", a, b)); System.out.println(compare("==", a, b)); System.out.println(compare("!=", a, b)); + + String dataStr = "01030406513F9E3B32"; + String data = dataStr.substring(dataStr.length() - 8, dataStr.length() - 6) + + dataStr.substring(dataStr.length() - 6, dataStr.length() - 4) + + dataStr.substring(dataStr.length() - 12, dataStr.length() - 10) + + dataStr.substring(dataStr.length() - 10, dataStr.length() - 8); + System.out.println(data); } } diff --git a/mh-common/src/main/java/com/mh/common/utils/SendOrderUtils.java b/mh-common/src/main/java/com/mh/common/utils/SendOrderUtils.java index dd695a9..cb0585d 100644 --- a/mh-common/src/main/java/com/mh/common/utils/SendOrderUtils.java +++ b/mh-common/src/main/java/com/mh/common/utils/SendOrderUtils.java @@ -19,6 +19,9 @@ public class SendOrderUtils { public static void sendAllOrder(CollectionParamsManage paramsManage, ChannelHandlerContext ctx, int num, int size) { // 开始创建指令 String mtCode = paramsManage.getMtCode(); // 采集编号 + if (paramsManage.getParamType().equals("17")) { + mtCode = paramsManage.getMtNum(); + } String funCode = paramsManage.getFuncCode(); // 功能码 String registerAddr = paramsManage.getRegisterAddr(); // 寄存器地址 String registerNum = String.valueOf(paramsManage.getRegisterSize()); // 寄存器数量 @@ -35,7 +38,7 @@ public class SendOrderUtils { ByteBuf buffer = getByteBuf(ctx, sendOrderStr); // 发送数据 ctx.channel().writeAndFlush(buffer); - log.info("sends :" + sendOrderStr + ",num:" + num + ",records:" + size); + log.info("sends :{},num:{},records:{}", sendOrderStr, num, size); try { Thread.sleep(500); } catch (InterruptedException e) { diff --git a/mh-common/src/main/java/com/mh/common/utils/TableUtils.java b/mh-common/src/main/java/com/mh/common/utils/TableUtils.java new file mode 100644 index 0000000..c8fb6be --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/utils/TableUtils.java @@ -0,0 +1,79 @@ +package com.mh.common.utils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Author : Rainbow + * @date : 2023/7/10 + */ +public class TableUtils { + /** + * 主机 + */ + public final static String CHILLER = "chiller"; + /** + * 电表等参数 + */ + public final static String DEVICE = "device"; + + /** + * 返回表明列表 + * + * @param dateType 分钟、小时、日月年 + * @param dataType 主机参数、电表等参数 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 表名集合 + */ + public static List getTableName(String dateType, String dataType, String startTime, String endTime) { + int start = Integer.parseInt(startTime.substring(0, 4)); + int end = Integer.parseInt(endTime.substring(0, 4)); + if (end < start) { + throw new RuntimeException("时间不正确"); + } + List tabNames = new ArrayList<>(); + StringBuilder tableName = new StringBuilder(); + for (int i = start; i <= end; i++) { + //清空 + tableName.setLength(0); + switch (dataType){ + case CHILLER: + tableName.append("chillers_data_").append(dateType).append(i); + break; + case DEVICE: + tableName.append("data_").append(dateType).append(i); + break; + default: + break; + } + tabNames.add(tableName.toString()); + } + return tabNames; + } + + /** + * 返回表名字 + * + * @param dateType 分钟、小时、日月年 + * @param dataType 主机参数、电表等参数 + * @param date 时间 + * @return 一个表名 + */ + public static String getTableName(String dateType, String dataType, String date) { + StringBuilder tableName = new StringBuilder(); + switch (dataType) { + case CHILLER: + tableName.append("chillers_data_"); + break; + case DEVICE: + tableName.append("data_"); + break; + default: + break; + } + + tableName.append(dateType).append(date.substring(0, 4)); + return tableName.toString(); + } +} diff --git a/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttConfig.java b/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttConfig.java index 3488b5c..d6292fc 100644 --- a/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttConfig.java +++ b/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttConfig.java @@ -5,6 +5,7 @@ import com.mh.common.enums.MqttProtocolEnum; import com.mh.common.enums.MqttUseEnum; import lombok.Data; import org.eclipse.paho.client.mqttv3.MqttConnectOptions; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -24,6 +25,7 @@ import java.util.Map; @Configuration @Data @ConfigurationProperties +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class MqttConfig { private static Map mqttSpring; 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 5dbf207..6e0a507 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 @@ -5,6 +5,7 @@ import com.mh.common.enums.MqttClientOptions; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.annotation.IntegrationComponentScan; @@ -27,6 +28,7 @@ import org.springframework.messaging.MessageHandler; @Slf4j @Configuration @IntegrationComponentScan +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class MqttInboundConfig { @Autowired diff --git a/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttMessageChannel.java b/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttMessageChannel.java index e8ba111..0fb483f 100644 --- a/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttMessageChannel.java +++ b/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttMessageChannel.java @@ -2,6 +2,7 @@ package com.mh.framework.mqtt.config; import com.mh.common.constant.ChannelName; import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.channel.DirectChannel; @@ -17,6 +18,7 @@ import org.springframework.messaging.MessageChannel; */ @Slf4j @Configuration +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class MqttMessageChannel { @Bean(name = ChannelName.OUTBOUND) diff --git a/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttOutboundConfig.java b/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttOutboundConfig.java index 2c73e2f..8b4460e 100644 --- a/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttOutboundConfig.java +++ b/mh-framework/src/main/java/com/mh/framework/mqtt/config/MqttOutboundConfig.java @@ -3,6 +3,7 @@ package com.mh.framework.mqtt.config; import com.mh.common.constant.ChannelName; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.annotation.IntegrationComponentScan; @@ -22,6 +23,7 @@ import org.springframework.messaging.MessageHandler; @Slf4j @Configuration @IntegrationComponentScan +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class MqttOutboundConfig { @Autowired diff --git a/mh-framework/src/main/java/com/mh/framework/mqtt/handler/InboundMessageRouter.java b/mh-framework/src/main/java/com/mh/framework/mqtt/handler/InboundMessageRouter.java index 015746f..7f293ef 100644 --- a/mh-framework/src/main/java/com/mh/framework/mqtt/handler/InboundMessageRouter.java +++ b/mh-framework/src/main/java/com/mh/framework/mqtt/handler/InboundMessageRouter.java @@ -6,6 +6,7 @@ import com.mh.common.constant.TopicEnum; import com.mh.common.utils.spring.SpringUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.integration.annotation.Router; import org.springframework.integration.mqtt.support.MqttHeaders; import org.springframework.integration.router.AbstractMessageRouter; @@ -27,6 +28,7 @@ import java.util.Objects; */ @Slf4j @Component +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class InboundMessageRouter extends AbstractMessageRouter { /** 系统基础配置 */ diff --git a/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/EventsServiceImpl.java b/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/EventsServiceImpl.java index 499e9a9..6e76361 100644 --- a/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/EventsServiceImpl.java +++ b/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/EventsServiceImpl.java @@ -12,6 +12,7 @@ import com.mh.framework.rabbitmq.producer.SendMsgByTopic; import io.netty.util.CharsetUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.messaging.MessageHeaders; import org.springframework.stereotype.Service; @@ -28,6 +29,7 @@ import java.util.Objects; */ @Slf4j @Service +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class EventsServiceImpl implements IEventsService { @Autowired diff --git a/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttGatewayServiceImpl.java b/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttGatewayServiceImpl.java index fa8961e..f66eabb 100644 --- a/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttGatewayServiceImpl.java +++ b/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttGatewayServiceImpl.java @@ -2,6 +2,7 @@ package com.mh.framework.mqtt.service.impl; import com.mh.framework.mqtt.service.IMqttGatewayService; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.integration.mqtt.support.MqttHeaders; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.MessageChannel; @@ -15,6 +16,7 @@ import org.springframework.stereotype.Service; * @date 2025-02-07 08:44:55 */ @Service +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class MqttGatewayServiceImpl implements IMqttGatewayService { private final MessageChannel outboundChannel; diff --git a/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttMsgSenderServiceImpl.java b/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttMsgSenderServiceImpl.java index 855be91..8c68e32 100644 --- a/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttMsgSenderServiceImpl.java +++ b/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttMsgSenderServiceImpl.java @@ -11,6 +11,7 @@ import com.mh.framework.mqtt.service.IMqttMsgSenderService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -26,6 +27,7 @@ import java.util.UUID; */ @Slf4j @Service +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class MqttMsgSenderServiceImpl implements IMqttMsgSenderService { @Autowired diff --git a/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttTopicServiceImpl.java b/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttTopicServiceImpl.java index 6911a17..831f696 100644 --- a/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttTopicServiceImpl.java +++ b/mh-framework/src/main/java/com/mh/framework/mqtt/service/impl/MqttTopicServiceImpl.java @@ -3,6 +3,7 @@ package com.mh.framework.mqtt.service.impl; import com.mh.framework.mqtt.service.IMqttTopicService; import jakarta.annotation.Resource; import org.eclipse.paho.client.mqttv3.MqttAsyncClient; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.integration.mqtt.core.MqttPahoClientFactory; import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter; import org.springframework.stereotype.Service; @@ -15,6 +16,7 @@ import org.springframework.stereotype.Service; * @date 2024-10-29 17:36:31 */ @Service +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class MqttTopicServiceImpl implements IMqttTopicService { @Resource diff --git a/mh-framework/src/main/java/com/mh/framework/netty/EchoServerHandler.java b/mh-framework/src/main/java/com/mh/framework/netty/EchoServerHandler.java index e5f4428..78b220a 100644 --- a/mh-framework/src/main/java/com/mh/framework/netty/EchoServerHandler.java +++ b/mh-framework/src/main/java/com/mh/framework/netty/EchoServerHandler.java @@ -161,9 +161,9 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter { log.info("gateway not find deviceCodeParam!"); } } else if (receiveStr.length() == 18) { - // 水电表返回数据解析 + // 水电表、冷量计返回数据解析 idleCount = 1; - log.info("水电表、热泵设置接收==>{},长度:{}", receiveStr, receiveStr.length()); + log.info("水电表、冷量计、热泵设置接收==>{},长度:{}", receiveStr, receiveStr.length()); nextSendOrder(ctx); } else if (receiveStr.length() == 12 || receiveStr.length() == 14) { // 热泵返回数据解析 @@ -344,6 +344,9 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter { AnalysisReceiveOrder485 analysisReceiveOrder485 = new AnalysisReceiveOrder485(); String analysisData = ""; switch (deviceCodeParamEntity.getParamType()) { + case "17" -> + // 冷量计 + analysisData = analysisReceiveOrder485.analysisCloudOrder485(receiveStr, deviceCodeParamEntity); case "16" -> // 电表 analysisData = analysisReceiveOrder485.analysisMeterOrder485(receiveStr, deviceCodeParamEntity); 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 index af026df..2259746 100644 --- a/mh-quartz/src/main/java/com/mh/quartz/task/AHUTask.java +++ b/mh-quartz/src/main/java/com/mh/quartz/task/AHUTask.java @@ -16,6 +16,7 @@ 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.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import java.math.BigDecimal; @@ -32,6 +33,7 @@ import java.util.stream.Collectors; */ @Slf4j @Component("ahuTask") +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class AHUTask { @Value("${control.topic}") diff --git a/mh-quartz/src/main/java/com/mh/quartz/task/ChillersTask.java b/mh-quartz/src/main/java/com/mh/quartz/task/ChillersTask.java index 10e0c6b..ae6dd9a 100644 --- a/mh-quartz/src/main/java/com/mh/quartz/task/ChillersTask.java +++ b/mh-quartz/src/main/java/com/mh/quartz/task/ChillersTask.java @@ -16,6 +16,7 @@ import com.mh.system.service.report.IReportSysService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import java.math.BigDecimal; @@ -32,6 +33,7 @@ import java.util.stream.Collectors; */ @Slf4j @Component("chillersTask") +@ConditionalOnProperty(prefix = "mqttSpring", name = "enabled", havingValue = "true", matchIfMissing = true) public class ChillersTask { @Value("${control.topic}") diff --git a/mh-quartz/src/main/java/com/mh/quartz/task/GetOtherSysDataJob.java b/mh-quartz/src/main/java/com/mh/quartz/task/GetOtherSysDataJob.java new file mode 100644 index 0000000..7a74d29 --- /dev/null +++ b/mh-quartz/src/main/java/com/mh/quartz/task/GetOtherSysDataJob.java @@ -0,0 +1,392 @@ +package com.mh.quartz.task; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.mh.common.constant.Constants; +import com.mh.common.core.domain.entity.CollectionParamsManage; +import com.mh.common.model.request.AdvantechDatas; +import com.mh.common.model.request.AdvantechReceiver; +import com.mh.common.utils.DateUtils; +import com.mh.common.utils.http.HttpUtils; +import com.mh.framework.rabbitmq.producer.SendMsgByTopic; +import com.mh.system.service.device.ICollectionParamsManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 获取第三方数据定时任务 + * @date 2026-06-05 10:57:49 + */ +@Slf4j +@Component("getOtherSysDataJob") +public class GetOtherSysDataJob { + + @Autowired + private ICollectionParamsManageService collectionParamsManageService; + + @Autowired + private ObjectMapper mapper; + + @Autowired + private SendMsgByTopic sendMsgByTopic; + + // 创建线程池用于并发请求 + private static final ExecutorService executor = Executors.newFixedThreadPool(2, r -> { + Thread thread = new Thread(r); + thread.setName("BSD-Data-Fetcher"); + thread.setDaemon(true); + return thread; + }); + + //TODO 机房总电表 + private final String[] totalMeters = new String[]{ + "Power", // 机房实时功率 + "PowerTotal" // 机房累计读数 + }; + + //TODO 主机总电表 + private final String[] powerMeters = new String[]{ + "ChPower", // 主机实时功率 + "PowerTotal_CH" // 主机累计读数 + }; + + //TODO 冷冻泵总电表 + private final String[] freezePumpMeters = new String[]{ + "PriChWPPower", // 冷冻泵实时功率 + "PowerTotal_ChWPump" // 冷冻泵累计读数 + }; + + //TODO 冷却泵总电表 + private final String[] coolPumpMeters = new String[]{ + "CWPPower", // 冷却泵实时功率 + "PowerTotal_CWPump" // 冷却泵累计读数 + }; + + //TODO 冷却塔总电表 + private final String[] towerMeters = new String[]{ + "CTPower", // 冷却塔实时功率 + "PowerTotal_CT" // 冷却塔累计读数 + }; + + public void getBSDData(String realUrl, String realValuesUrl) { + log.info("获取BSD数据"); + try { + // 获取实时读数\累计读数的所有点位 + HashMap params = new HashMap<>(); + params.put("systemType", "0"); + params.put("paramType", "16"); + List collectionParamsManages = collectionParamsManageService.selectListByParams(params); + + // 分离grade=40(累计读数)和grade=140(实时功率)的点位 + List cumulativeMtCodes = new ArrayList<>(); // grade=40 + List powerMtCodes = new ArrayList<>(); // grade=140 + HashMap mtCodeToOtherNameMap = new HashMap<>(); // mtCode到otherName的映射 + + for (CollectionParamsManage param : collectionParamsManages) { + if (param.getGrade() != null && param.getMtCode() != null) { + // 建立mtCode到otherName的映射关系 + if (param.getOtherName() != null && !param.getOtherName().isEmpty()) { + mtCodeToOtherNameMap.put(param.getMtCode(), param.getOtherName()); + } + // 判断如果等于totalMeters、powerMeters、freezePumpMeters、coolPumpMeters、towerMeters的点位,就下一个循环 + if (totalMeters[0].equals(param.getMtCode()) || totalMeters[1].equals(param.getMtCode()) || + powerMeters[0].equals(param.getMtCode()) || powerMeters[1].equals(param.getMtCode()) || + freezePumpMeters[0].equals(param.getMtCode()) || freezePumpMeters[1].equals(param.getMtCode()) || + coolPumpMeters[0].equals(param.getMtCode()) || coolPumpMeters[1].equals(param.getMtCode()) || + towerMeters[0].equals(param.getMtCode()) || towerMeters[1].equals(param.getMtCode())) { + continue; + } + + if (param.getGrade() == 40) { + cumulativeMtCodes.add(param.getMtCode()); + } else if (param.getGrade() == 140) { + powerMtCodes.add(param.getMtCode()); + } + } + } + + List allAdvantechDatas = new ArrayList<>(); + + // 使用CompletableFuture并发请求累计读数和功率读数 + CompletableFuture> cumulativeFuture = null; + CompletableFuture> powerFuture = null; + + // 并发请求累计读数 (grade=40) + if (!cumulativeMtCodes.isEmpty()) { + final List finalCumulativeMtCodes = new ArrayList<>(cumulativeMtCodes); + final HashMap finalMtCodeToOtherNameMap = new HashMap<>(mtCodeToOtherNameMap); + cumulativeFuture = CompletableFuture.supplyAsync(() -> { + log.info("[线程-{}] 请求累计读数,点位数量: {}", Thread.currentThread().getName(), finalCumulativeMtCodes.size()); + // http://192.168.1.80:5002/data/get_real + return fetchCumulativeData(finalCumulativeMtCodes, finalMtCodeToOtherNameMap, realUrl); + }, executor); + } + + // 并发请求功率读数 (grade=140) + if (!powerMtCodes.isEmpty()) { + final List finalPowerMtCodes = new ArrayList<>(powerMtCodes); + final HashMap finalMtCodeToOtherNameMap = new HashMap<>(mtCodeToOtherNameMap); + powerFuture = CompletableFuture.supplyAsync(() -> { + log.info("[线程-{}] 请求功率读数,点位数量: {}", Thread.currentThread().getName(), finalPowerMtCodes.size()); + // http://192.168.1.80:5002/data/get_real_values + return fetchPowerData(finalPowerMtCodes, finalMtCodeToOtherNameMap, realValuesUrl); + }, executor); + } + + // 等待两个任务完成并合并结果 + try { + if (cumulativeFuture != null) { + List cumulativeDatas = cumulativeFuture.get(30, TimeUnit.SECONDS); + // 累计读数 + // cumulativeDatas.遍历计算得出机房总累计读数、主机总累计读数、冷冻泵总累计读数、冷却泵总累计读数、冷却塔总累计读数 + // 新建一个主机总电表的AdvantechDatas对象,tag为mtCodeToOtherNameMap,key值为"PowerTotal_CH"的value值,quality为0,value为cumulativeDatas中tag包含"主机*累计读数"的value和值 + // 新建一个冷冻泵总电表的AdvantechDatas对象,tag为mtCodeToOtherNameMap,key值为"PowerTotal_ChWPump"的value值,quality为0,value为cumulativeDatas中tag包含"冷冻泵*累计读数"的value和值 + // 新建一个冷却泵总电表的AdvantechDatas对象,tag为mtCodeToOtherNameMap,key值为"PowerTotal_CWPump"的value值,quality为0,value为cumulativeDatas中tag包含"冷却泵*累计读数"的value和值 + // 新建一个冷却塔总电表的AdvantechDatas对象,tag为mtCodeToOtherNameMap,key值为"PowerTotal_CT"的value值,quality为0,value为cumulativeDatas中tag包含"冷却塔*累计读数"的value和值 + // 新建一个机房总电表的AdvantechDatas对象,tag为mtCodeToOtherNameMap,key值为"PowerTotal"的value值,quality为0,value为cumulativeDatas中tag包含"累计读数"的value和值 + // 瞬时功率 + // cumulativeDatas.遍历计算得出机房总瞬时功率、主机总瞬时功率、冷冻泵总瞬时功率、冷却泵总瞬时功率、冷却塔总瞬时功率 + // 新建一个主机总电表的AdvantechDatas对象,tag为mtCodeToOtherNameMap,key值为"ChPower"的value值,quality为0,value为cumulativeDatas中tag包含"主机*瞬时功率"的value和值 + // 新建一个冷冻泵总电表的AdvantechDatas对象,tag为mtCodeToOtherNameMap,key值为"PriChWPPower"的value值,quality为0,value为cumulativeDatas中tag包含"冷冻泵*瞬时功率"的value和值 + // 新建一个冷却泵总电表的AdvantechDatas对象,tag为mtCodeToOtherNameMap,key值为"CWPPower"的value值,quality为0,value为cumulativeDatas中tag包含"冷却泵*瞬时功率"的value和值 + // 新建一个冷却塔总电表的AdvantechDatas对象,tag为mtCodeToOtherNameMap,key值为"CTPower"的value值,quality为0,value为cumulativeDatas中tag包含"冷却塔*瞬时功率"的value和值 + // 新建一个机房总电表的AdvantechDatas对象,tag为mtCodeToOtherNameMap,key值为"Power"的value值,quality为0,value为cumulativeDatas中tag包含"瞬时功率"的value和值 + // 再插入到cumulativeDatas中 + + try { + // 计算汇总数据并添加到cumulativeDatas + calculateAndAddSummaryData(cumulativeDatas, mtCodeToOtherNameMap); + } catch (Exception e) { + log.error("累计读数汇总计算异常,但不影响后续流程", e); + } + + allAdvantechDatas.addAll(cumulativeDatas); + log.info("累计读数获取完成,数据点数: {}", cumulativeDatas.size()); + } + + if (powerFuture != null) { + List powerDatas = powerFuture.get(30, TimeUnit.SECONDS); + allAdvantechDatas.addAll(powerDatas); + // 实时功率 + log.info("功率读数获取完成,数据点数: {}", powerDatas.size()); + } + } catch (Exception e) { + log.error("等待异步任务完成时异常", e); + } + + // 封装成研华网关格式并发送到消息队列 + if (!allAdvantechDatas.isEmpty()) { + AdvantechReceiver advantechReceiver = new AdvantechReceiver(); + advantechReceiver.setTs(DateUtils.dateToString(new Date(), Constants.DATE_FORMAT)); + advantechReceiver.setD(allAdvantechDatas); + + String message = JSONObject.toJSONString(advantechReceiver); + log.info("发送BSD数据到消息队列,数据点数: {}", allAdvantechDatas.size()); + sendMsgByTopic.sendToDeviceMQ(message); + log.info("BSD数据发送成功"); + } else { + log.warn("没有获取到任何BSD数据"); + } + + } catch (Exception e) { + log.error("获取BSD数据异常", e); + } + } + + /** + * 计算并添加汇总数据到cumulativeDatas + * @param cumulativeDatas 累计读数数据列表 + * @param mtCodeToOtherNameMap mtCode到otherName的映射关系 + */ + private void calculateAndAddSummaryData(List cumulativeDatas, HashMap mtCodeToOtherNameMap) { + // 定义汇总类型枚举 + enum SummaryType { + CH_CUMULATIVE("主机", "累计读数", "PowerTotal_CH", "主机总累计读数"), + CHWP_CUMULATIVE("冷冻泵", "累计读数", "PowerTotal_ChWPump", "冷冻泵总累计读数"), + CWP_CUMULATIVE("冷却泵", "累计读数", "PowerTotal_CWPump", "冷却泵总累计读数"), + CT_CUMULATIVE("冷却塔", "累计读数", "PowerTotal_CT", "冷却塔总累计读数"), + ALL_CUMULATIVE(null, "累计读数", "PowerTotal", "机房总累计读数"), + CH_POWER("主机", "瞬时功率", "ChPower", "主机总瞬时功率"), + CHWP_POWER("冷冻泵", "瞬时功率", "PriChWPPower", "冷冻泵总瞬时功率"), + CWP_POWER("冷却泵", "瞬时功率", "CWPPower", "冷却泵总瞬时功率"), + CT_POWER("冷却塔", "瞬时功率", "CTPower", "冷却塔总瞬时功率"), + ALL_POWER(null, "瞬时功率", "Power", "机房总瞬时功率"); + + private final String deviceKeyword; + private final String dataKeyword; + private final String mtCode; + private final String description; + + SummaryType(String deviceKeyword, String dataKeyword, String mtCode, String description) { + this.deviceKeyword = deviceKeyword; + this.dataKeyword = dataKeyword; + this.mtCode = mtCode; + this.description = description; + } + } + + // 一次性遍历cumulativeDatas,分类累加各类型数据 + Map summaryMap = new HashMap<>(); + // 初始化所有汇总类型 + for (SummaryType type : SummaryType.values()) { + summaryMap.put(type, BigDecimal.ZERO); + } + + for (AdvantechDatas data : cumulativeDatas) { + if (data.getTag() == null || data.getValue() == null) { + continue; + } + String tag = data.getTag(); + BigDecimal value = new BigDecimal(data.getValue().toString()); + + // 遍历所有汇总类型进行匹配 + for (SummaryType type : SummaryType.values()) { + boolean matchesDataKeyword = tag.contains(type.dataKeyword); + boolean matchesDeviceKeyword = type.deviceKeyword == null || tag.contains(type.deviceKeyword); + + if (matchesDataKeyword && matchesDeviceKeyword) { + summaryMap.merge(type, value, BigDecimal::add); + } + } + } + + // 创建并添加汇总数据点 + int successCount = 0; + for (SummaryType type : SummaryType.values()) { + try { + String targetTag = mtCodeToOtherNameMap.get(type.mtCode); + if (targetTag != null && !targetTag.isEmpty()) { + AdvantechDatas summaryData = new AdvantechDatas(); + summaryData.setTag(targetTag); + summaryData.setValue(summaryMap.get(type)); + summaryData.setQuality(0); + cumulativeDatas.add(summaryData); + log.debug("添加{}: {} = {}", type.description, targetTag, summaryMap.get(type)); + successCount++; + } + } catch (Exception e) { + log.error("添加{}失败", type.description, e); + } + } + + log.info("累计读数汇总完成,成功添加{}/{}个汇总数据点", successCount, SummaryType.values().length); + } + + /** + * 获取累计读数数据 + * @param mtCodes 点位编码列表 + * @param mtCodeToOtherNameMap mtCode到otherName的映射关系 + * @param realUrl 请求URL + * @return 解析后的数据列表 + */ + private List fetchCumulativeData(List mtCodes, HashMap mtCodeToOtherNameMap, String realUrl) { + List dataList = new ArrayList<>(); + try { + JSONObject cumulativeRequest = new JSONObject(); + cumulativeRequest.put("names", mtCodes); + JSONArray pointProperty = new JSONArray(); + pointProperty.add("point_value"); + cumulativeRequest.put("point_property", pointProperty); + cumulativeRequest.put("proj_id", "1"); + + String cumulativeResponse = HttpUtils.sendPost(realUrl, cumulativeRequest.toJSONString()); + log.info("[线程-{}] 累计读数响应长度: {}", Thread.currentThread().getName(), + cumulativeResponse != null ? cumulativeResponse.length() : 0); + + if (cumulativeResponse != null && !cumulativeResponse.isEmpty()) { + JSONObject cumulativeJson = JSON.parseObject(cumulativeResponse); + if (cumulativeJson.getBooleanValue("success") && cumulativeJson.containsKey("data")) { + JSONObject dataObj = cumulativeJson.getJSONObject("data"); + for (String mtCode : mtCodes) { + if (dataObj.containsKey(mtCode)) { + JSONArray valueArray = dataObj.getJSONArray(mtCode); + if (valueArray != null && !valueArray.isEmpty()) { + String valueStr = valueArray.getString(0); + try { + BigDecimal value = new BigDecimal(valueStr); + AdvantechDatas datas = new AdvantechDatas(); + // 使用otherName作为tag,如果不存在则使用mtCode + String tag = mtCodeToOtherNameMap.getOrDefault(mtCode, mtCode); + datas.setTag(tag); + datas.setValue(value); + datas.setQuality(0); + dataList.add(datas); + } catch (NumberFormatException e) { + log.error("解析累计读数失败,mtCode: {}, value: {}", mtCode, valueStr, e); + } + } + } + } + } + } + } catch (Exception e) { + log.error("获取累计读数异常", e); + } + return dataList; + } + + /** + * 获取功率读数数据 + * + * @param mtCodes 点位编码列表 + * @param mtCodeToOtherNameMap mtCode到otherName的映射关系 + * @param realValuesUrl 请求URL + * @return 解析后的数据列表 + */ + private List fetchPowerData(List mtCodes, HashMap mtCodeToOtherNameMap, String realValuesUrl) { + List dataList = new ArrayList<>(); + try { + JSONObject powerRequest = new JSONObject(); + powerRequest.put("expresss", mtCodes); + powerRequest.put("proj_id", "1"); + + String powerResponse = HttpUtils.sendPost(realValuesUrl, powerRequest.toJSONString()); + log.info("[线程-{}] 功率读数响应长度: {}", Thread.currentThread().getName(), + powerResponse != null ? powerResponse.length() : 0); + + if (powerResponse != null && !powerResponse.isEmpty()) { + JSONObject powerJson = JSON.parseObject(powerResponse); + if (powerJson.getBooleanValue("success") && powerJson.containsKey("data")) { + JSONObject dataObj = powerJson.getJSONObject("data"); + for (String mtCode : mtCodes) { + if (dataObj.containsKey(mtCode)) { + String valueStr = dataObj.getString(mtCode); + try { + BigDecimal value = new BigDecimal(valueStr); + AdvantechDatas datas = new AdvantechDatas(); + // 使用otherName作为tag,如果不存在则使用mtCode + String tag = mtCodeToOtherNameMap.getOrDefault(mtCode, mtCode); + datas.setTag(tag); + datas.setValue(value); + datas.setQuality(0); + dataList.add(datas); + } catch (NumberFormatException e) { + log.error("解析功率读数失败,mtCode: {}, value: {}", mtCode, valueStr, e); + } + } + } + } + } + } catch (Exception e) { + log.error("获取功率读数异常", e); + } + return dataList; + } +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMapper.java index 42d8ea0..0ce735d 100644 --- a/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMapper.java +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMapper.java @@ -59,7 +59,7 @@ public interface EnergyMapper { "on " + " cpm.device_ledger_id = dl.id " + " and dl.device_type in ('5', '6') and cpm.grade = 40 " + -// " and cpm.terminal_device_type = '15' " + + " and cpm.terminal_device_type = '15' " + "" + " and cpm.system_type = #{systemType} " + "" + @@ -111,7 +111,7 @@ public interface EnergyMapper { "on " + " cpm.device_ledger_id = dl.id " + " and dl.device_type in ('5', '6') and cpm.grade = 40 " + -// " and cpm.terminal_device_type = '15' " + + " and cpm.terminal_device_type = '15' " + "" + " and cpm.system_type = #{systemType} " + "" + @@ -181,7 +181,7 @@ public interface EnergyMapper { "on " + " cpm.device_ledger_id = dl.id " + " and dl.device_type in ('5', '6') and cpm.grade = 40 " + -// " and cpm.terminal_device_type = '15' " + + " and cpm.terminal_device_type = '15' " + "" + " and cpm.system_type = #{systemType} " + "" + diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyQueryMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyQueryMapper.java index 130fad4..b1a6c9b 100644 --- a/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyQueryMapper.java +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyQueryMapper.java @@ -57,6 +57,8 @@ public interface EnergyQueryMapper { "on " + " cpm.device_ledger_id = dl.id " + " and dl.device_type in ('5', '6') " + + " and cpm.terminal_device_type = '15' " + + " and cpm.grade = 40 " + " " + " and cpm.system_type = #{systemType} " + "" + @@ -108,6 +110,8 @@ public interface EnergyQueryMapper { "on " + " cpm.device_ledger_id = dl.id " + " and dl.device_type in ('5', '6') " + + " and cpm.terminal_device_type = '15' " + + " and cpm.grade = 40 " + " " + " and cpm.system_type = #{systemType} " + "" + @@ -178,6 +182,8 @@ public interface EnergyQueryMapper { "on " + " cpm.device_ledger_id = dl.id " + " and dl.device_type in ('5', '6') " + + " and cpm.terminal_device_type = '15' " + + " and cpm.grade = 40 " + " " + " and cpm.system_type = #{systemType} " + "" + diff --git a/mh-system/src/main/java/com/mh/system/mapper/overview/HomeMapper.java b/mh-system/src/main/java/com/mh/system/mapper/overview/HomeMapper.java new file mode 100644 index 0000000..dcb2483 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/overview/HomeMapper.java @@ -0,0 +1,278 @@ +package com.mh.system.mapper.overview; + +import com.mh.common.core.domain.ColumnFilter; +import com.mh.common.core.domain.entity.HistoryEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +/** + * 首页数据 Mapper + *

+ * 基于 collection_params_manage.mt_num = data_min.device_code 的关联查询。 + *

+ * grade 仅有两个值:40=累计值,140=瞬时值; + * 设备类型通过 other_name 前缀或 mt_num 前缀区分。 + * + * @Author : Rainbow + * @date : 2023/7/11 + */ +@Mapper +public interface HomeMapper { + + // ==================== 基础元数据查询 ==================== + + /** + * 获取天气温湿度 + */ + @Select("select wd.temperature, wd.humidity from weather_data wd where wd.report_time between #{startTime}::timestamp and #{endTime}::timestamp order by wd.report_time desc limit 1") + Map selectWeatherData(@Param("startTime") String startTime, @Param("endTime") String endTime); + + /** + * 查询系统运行时长(从2024-03-05起算) + */ + @Select("SELECT EXTRACT(DAY FROM (CURRENT_DATE - DATE '2024-03-05'))::bigint") + long selectRunTime(); + + /** + * 根据 grade 查询 mt_num 列表(所有在用设备) + * + * @param grade 40=累计值, 140=瞬时值 + * @return mt_num 列表 + */ + @Select("SELECT mt_num FROM collection_params_manage WHERE grade = #{grade} AND is_use = 0") + List queryMtNumsByGrade(@Param("grade") Integer grade); + + /** + * 根据 grade 和 other_name 前缀查询 mt_num 列表 + *

+ * 用于按设备分类查询,如: + * PowerTotal → 累计用电量设备 + * ChPower → 主机瞬时功率 + * + * @param grade 40=累计值, 140=瞬时值 + * @param otherNamePrefix other_name 前缀 + * @return mt_num 列表 + */ + @Select("SELECT mt_code FROM collection_params_manage WHERE grade = #{grade} AND mt_num LIKE CONCAT(#{otherNamePrefix}, '%') AND is_use = 0") + List queryMtNumsByGradeAndOtherNamePrefix(@Param("grade") Integer grade, + @Param("otherNamePrefix") String otherNamePrefix); + + /** + * 根据 grade 和 mt_num 前缀查询 mt_num 列表(用于冷量表) + * + * @param grade 40=累计值, 140=瞬时值 + * @param mtNumPrefix mt_num 前缀(如 3900) + * @return mt_num 列表 + */ + @Select("SELECT mt_num FROM collection_params_manage WHERE grade = #{grade} AND mt_num LIKE CONCAT(#{mtNumPrefix}, '%') AND is_use = 0") + List queryMtNumsByGradeAndMtNumPrefix(@Param("grade") Integer grade, + @Param("mtNumPrefix") String mtNumPrefix); + + /** + * 根据 grade、排除指定 mt_num 前缀查询 mt_num 列表 + *

+ * 用于获取"非冷量表"的电力设备,如 grade=40 且 mt_num 不以 3900 开头 + * + * @param grade grade 值 + * @param excludePrefix 需要排除的 mt_num 前缀 + * @return mt_num 列表 + */ + @Select("SELECT mt_num FROM collection_params_manage WHERE grade = #{grade} AND mt_num NOT LIKE CONCAT(#{excludePrefix}, '%') AND is_use = 0") + List queryMtNumsByGradeExcludeMtNumPrefix(@Param("grade") Integer grade, + @Param("excludePrefix") String excludePrefix); + + /** + * 根据 grade 和 param_type 查询 mt_code 列表 + * + * @param grade 40=累计值 + * @param paramType 参数类型(如 "2"=产冷量) + * @return mt_num 列表 + */ + @Select("SELECT mt_code FROM collection_params_manage WHERE grade = #{grade} AND param_type = #{paramType} AND is_use = 0") + List queryMtNumsByGradeAndParamType(@Param("grade") Integer grade, + @Param("paramType") String paramType); + + // ==================== 图表曲线数据查询 ==================== + + /** + * 多个 mt_num 汇总后的当日曲线(SUM calc_value,用于总用电量、瞬时功率等累加指标) + * + * @param tableName 动态表名 + * @param mtNums mt_num 列表 + * @return 时间-汇总值列表 + */ + @Select("") + @Results({ + @Result(column = "date", property = "date"), + @Result(column = "value", property = "value") + }) + List querySumHistoryByMtNums(@Param("tableName") String tableName, + @Param("mtNums") List mtNums); + + /** + * 单个 device_code 的当日曲线(cur_value 字段,用于温度等直接读取类参数) + * + * @param tableName 动态表名 + * @param deviceCode 设备编码(= mt_num) + * @return 时间-值列表 + */ + @Select("SELECT to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS date, cur_value AS value " + + "FROM ${tableName} WHERE device_code = #{deviceCode} AND cur_time::date = CURRENT_DATE ORDER BY cur_time") + @Results({ + @Result(column = "date", property = "date"), + @Result(column = "value", property = "value") + }) + List queryCurValueByDeviceCode(@Param("tableName") String tableName, + @Param("deviceCode") String deviceCode); + + /** + * 单个 device_code 的当日曲线(calc_value 字段,用于功率/冷量等累计差值参数) + * + * @param tableName 动态表名 + * @param deviceCode 设备编码(= mt_num) + * @return 时间-值列表 + */ + @Select("SELECT to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS date, calc_value AS value " + + "FROM ${tableName} WHERE device_code = #{deviceCode} AND cur_time::date = CURRENT_DATE ORDER BY cur_time") + @Results({ + @Result(column = "date", property = "date"), + @Result(column = "value", property = "value") + }) + List queryCalcValueByDeviceCode(@Param("tableName") String tableName, + @Param("deviceCode") String deviceCode); + + // ==================== 能耗系数查询 ==================== + + /** + * 查询当日所有瞬时用电量设备的最新 calc_value 与 other_name + *

+ * 用于 getCoe() 中按 other_name 前缀分类累加各子系统瞬时功率 + * + * @param tableName 动态表名 + * @param grade 140=瞬时值 + * @return other_name 和 calc_value 列表 + */ + @Select("") + List> selectInstantEleWithOtherName(@Param("tableName") String tableName, + @Param("grade") Integer grade); + + // ==================== 数据统计查询 ==================== + + /** + * 产冷量统计(日、月、年累计 calc_value 求和) + * + * @param tableName 动态表名 + * @param mtNums mt_num 列表 + * @return dayCap, monthCap, yearCap + */ + @Select("") + Map selectAllTypeCap(@Param("tableName") String tableName, + @Param("mtNums") List mtNums); + + /** + * 用电量统计(日、月、年累计 calc_value 求和) + * + * @param tableName 动态表名 + * @param mtNums mt_num 列表 + * @return dayEle, monthEle, yearEle + */ + @Select("") + Map selectAllTypeEle(@Param("tableName") String tableName, + @Param("mtNums") List mtNums); + + /** + * 累计总用电量(全部历史 calc_value 求和) + * + * @param tableName 动态表名 + * @param mtNums mt_num 列表 + * @return 累计用电量 + */ + @Select("") + BigDecimal selectTotalEle(@Param("tableName") String tableName, + @Param("mtNums") List mtNums); + + /** + * 累计总产冷量(最新 cur_value - 初始值 mt_init_value) + * + * @param tableName 动态表名 + * @param deviceCode 设备编码(总冷量计读数 mt_num) + * @return 累计产冷量 + */ + @Select("") + BigDecimal selectTotalCap(@Param("tableName") String tableName, + @Param("deviceCode") String deviceCode); + + // ==================== 实时数据查询 ==================== + + /** + * 最新总瞬时功率(各 device_code 最新 calc_value 之和) + * + * @param tableName 动态表名 + * @param mtNums mt_num 列表 + * @return 瞬时功率总和 + */ + @Select("") + double selectLastEle(@Param("tableName") String tableName, + @Param("mtNums") List mtNums); + + /** + * 最新瞬时产冷量 / 功率值(按 mt_num 查最新一条 calc_value) + * + * @param tableName 动态表名 + * @param deviceCode 设备编码 + * @return 最新 calc_value + */ + @Select("SELECT calc_value FROM ${tableName} WHERE device_code = #{deviceCode} ORDER BY cur_time DESC LIMIT 1") + BigDecimal selectLastCalcValueByMtNum(@Param("tableName") String tableName, + @Param("deviceCode") String deviceCode); +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/overview/ReportMapper.java b/mh-system/src/main/java/com/mh/system/mapper/overview/ReportMapper.java new file mode 100644 index 0000000..848a042 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/overview/ReportMapper.java @@ -0,0 +1,147 @@ +package com.mh.system.mapper.overview; + +import com.mh.common.core.domain.entity.HistoryEntity; +import org.apache.ibatis.annotations.*; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +/** + * @author LJF + * @title :查询报表功能 + * @description : + * @updateTime 2020-07-03 + * @throws : + */ +@Mapper +@Component +public interface ReportMapper { + + /** + * 单表查询当日记录 + * + * @param tableName + * @param id + * @return + */ + @Select("select cur_time,cur_value from ${tableName} where register_id = #{id} AND DateDiff(dd,cur_time,getdate())=0 order by cur_time asc ") + @Results({@Result(column = "cur_time", property = "date"), + @Result(column = "cur_value", property = "value")}) + List queryHistoryByTable(@Param("tableName") String tableName, @Param("id") int id); + + /** + * 查询当日用电量图表 + * @param tableName + * @return + */ + @Select("SELECT T1.cur_time,(T1.calc_value + t2.calc_value) 'value' from \n" + + "(SELECT cur_time,calc_value from ${tableName} where device_num = #{deviceNum1})T1\n" + + "FULL JOIN\n" + + "(SELECT cur_time,calc_value from ${tableName} where device_num = #{deviceNum2})T2\n" + + "ON T1.cur_time = T2.cur_time where DATEDIFF(dd,T1.cur_time,getdate()) = 0 order by T1.cur_time asc") + @Results({@Result(column = "cur_time", property = "date"), + @Result(column = "value", property = "value")}) + List queryCurDateEleUsed(@Param("tableName") String tableName, @Param("deviceNum1") String deviceNum1, @Param("deviceNum2") String deviceNum2); + + /** + * 查询当日用电量图表 + * @param tableName + * @return + */ + @Select("SELECT cur_time,calc_value from ${tableName} where device_num = #{deviceNum1} and DATEDIFF(dd,cur_time,getdate()) = 0 order by cur_time asc") + @Results({@Result(column = "cur_time", property = "date"), + @Result(column = "calc_value", property = "value")}) + List queryCurDateEleUsedOne(@Param("tableName") String tableName, @Param("deviceNum1") String deviceNum1); + + /** + * 查询COP历史纪录 + * + * @return + */ + @Select("select cur_time,cur_value from data_min_cop where " + + " DateDiff(dd,cur_time,getdate())=0 order by cur_time asc") + @Results({@Result(column = "cur_time", property = "date"), + @Result(column = "cur_value", property = "value")}) + List selectCopHistory(); + + /** + * 查询冷冻水日平均温度 + * @param type + * @param curDate + * @param tableName + * @return + */ + @Select("select avg(cur_value) from ${tableName} where id in(51,70) and DATEDIFF(dd,cur_time,#{curDate}) = 0") + BigDecimal selectAvgTempDD(@Param("type") String type,@Param("curDate") String curDate,@Param("tableName") String tableName); + + /** + * 查询月平均温度 + * @param type + * @param curDate + * @param tableName + * @return + */ + BigDecimal selectAvgTempMM(@Param("type") String type,@Param("curDate") String curDate,@Param("tableName") String tableName); + + /** + * 查询瞬时功率 + * @param tableName + * @return + */ + @Select("select cur_time,calc_value from ${tableName} where device_num = '3077' AND DateDiff(dd,cur_time,getdate())=0 order by cur_time asc ") + @Results({@Result(column = "cur_time", property = "date"), + @Result(column = "calc_value", property = "value")}) + List queryRateCold(String tableName); + + @Select("") + @ResultType(Map.class) + Map selectTemp(@Param("type") String type, @Param("curDate") String curDate, @Param("tableName") String tableName, @Param("len") int len); + + @Select("") + String selectRuntimes(@Param("type") String type, + @Param("curDate") String curDate, + @Param("tableName") String dataTable, + @Param("registerAddr") String registerAddr); +} diff --git a/mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyAnalyzeServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyAnalyzeServiceImpl.java index d8392a7..fbae147 100644 --- a/mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyAnalyzeServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyAnalyzeServiceImpl.java @@ -36,6 +36,15 @@ public class EnergyAnalyzeServiceImpl implements EnergyAnalyzeService { @Resource private CollectionParamsManageMapper collectionParamsManageMapper; + // 总表的device_num + private static final List totalMeter = Arrays.asList( + "PowerTotal_CH", + "PowerTotal_ChWPump", + "PowerTotal_CWPump", + "PowerTotal_CT", + "PowerTotal" + ); + @Override public JSONObject sysAnalyze(EnergyQueryVO vo) { DateUtils.sysEnergyDateChange(vo); @@ -291,6 +300,8 @@ public class EnergyAnalyzeServiceImpl implements EnergyAnalyzeService { private static List createDeviceTypeData(List deviceTypeEnergyEntities, int x, int x1) { return deviceTypeEnergyEntities.stream() .filter(val -> Integer.parseInt(val.getDeviceType()) == x) + // 并过滤掉总合计的,其中过滤掉totalMeter这个数组的值 + .filter(val -> !totalMeter.contains(val.getDeviceNum())) .collect(Collectors.groupingBy(DeviceTypeEnergy::getDeviceNum, Collectors.summarizingDouble(DeviceTypeEnergy::getDoubleCalcValue))) .entrySet().stream() .map(entry -> { diff --git a/mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyQueryServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyQueryServiceImpl.java index 72f5d5a..72af35f 100644 --- a/mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyQueryServiceImpl.java +++ b/mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyQueryServiceImpl.java @@ -20,6 +20,7 @@ import java.math.BigDecimal; import java.util.*; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * @author LJF @@ -239,7 +240,7 @@ public class EnergyQueryServiceImpl implements IEnergyQueryService { .toArray(String[]::new); String[] coldArr = getArr(coldData, timeStrArr); // 计算COP=制冷量/耗电量 - for (int i = 0; i < meterData.size(); i++) { + IntStream.range(0, meterData.size()).forEach(i -> { try { double cold = Math.round(Double.parseDouble(coldArr[i]) * 100) / 100.0; double meter = Math.round(Double.parseDouble(meterArr[i]) * 100) / 100.0; @@ -249,7 +250,34 @@ public class EnergyQueryServiceImpl implements IEnergyQueryService { log.error("处理累计能耗异常==>", e); throw new RuntimeException(e); } - } + }); + + // 计算合计值(在分页之前)- 使用Stream API + double totalCold = Arrays.stream(coldArr) + .mapToDouble(s -> { + try { + return Double.parseDouble(s); + } catch (NumberFormatException e) { + log.error("解析冷量数据异常==>", e); + return 0.0; + } + }) + .sum(); + + double totalMeter = Arrays.stream(meterArr) + .mapToDouble(s -> { + try { + return Double.parseDouble(s); + } catch (NumberFormatException e) { + log.error("解析电量数据异常==>", e); + return 0.0; + } + }) + .sum(); + + totalCold = Math.round(totalCold * 100) / 100.0; + totalMeter = Math.round(totalMeter * 100) / 100.0; + double totalCop = Math.round((totalMeter == 0 ? 0.00 : totalCold / totalMeter) * 100) / 100.0; // 表格数据 Map map = new HashMap<>(); int pageNum = vo.getPageNum(); @@ -292,6 +320,14 @@ public class EnergyQueryServiceImpl implements IEnergyQueryService { Map total = new HashMap<>(); total.put("total", timeStrArr.length); listData.add(total); + + // 添加合计数据 + Map summary = new HashMap<>(); + summary.put("totalCold", String.valueOf(totalCold)); + summary.put("totalMeter", String.valueOf(totalMeter)); + summary.put("totalCop", String.valueOf(totalCop)); + listData.add(summary); + return AjaxResult.success(listData); } diff --git a/mh-system/src/main/java/com/mh/system/service/overview/HomeService.java b/mh-system/src/main/java/com/mh/system/service/overview/HomeService.java new file mode 100644 index 0000000..900d2d2 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/overview/HomeService.java @@ -0,0 +1,55 @@ +package com.mh.system.service.overview; + + +import com.mh.common.core.page.TableDataInfo; + +/** + * 首页数据服务接口 + * + * @Author : Rainbow + * @date : 2023/7/11 + */ +public interface HomeService { + + /** + * 主界面charts图表数据 + * + * @return 图表数据 + */ + TableDataInfo getHomeCharts(); + + /** + * 查询统计数据(日/月/年产冷量、用电量、EER) + * + * @return 统计数据 + */ + TableDataInfo getStatisticalData(); + + /** + * 查询能耗系数(系统能效系数、主机能效、冷冻泵/冷却泵/冷却塔输送系数) + * + * @return 能耗系数 + */ + TableDataInfo getCoe(); + + /** + * 查询系统运行时长 + * + * @return 运行天数 + */ + TableDataInfo getRunTime(); + + /** + * 查询实时功率与产冷量 + * + * @return 实时功率数据 + */ + TableDataInfo getCurrentRate(); + + /** + * 获取天气数据(温度、湿度) + * + * @return 天气数据 + */ + TableDataInfo getWeatherData(); +} diff --git a/mh-system/src/main/java/com/mh/system/service/overview/impl/HomeServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/overview/impl/HomeServiceImpl.java new file mode 100644 index 0000000..c6a1b35 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/overview/impl/HomeServiceImpl.java @@ -0,0 +1,446 @@ +package com.mh.system.service.overview.impl; + +import com.mh.common.constant.DateConstant; +import com.mh.common.core.domain.entity.HistoryEntity; +import com.mh.common.core.domain.entity.chart.*; +import com.mh.common.core.page.TableDataInfo; +import com.mh.common.utils.DateUtils; +import com.mh.common.utils.TableUtils; +import com.mh.system.mapper.overview.HomeMapper; +import com.mh.system.service.overview.HomeService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; +import java.util.function.Supplier; + +/** + * 首页数据服务实现 + *

+ * 基于 data_min(动态年表)和 collection_params_manage 的关联查询, + * 其中 collection_params_manage.mt_num = data_min.device_code。 + *

+ * grade 仅有两个值:40=累计值,140=瞬时值; + * 设备类型通过 other_name 前缀区分,冷量表通过 mt_num 前缀(3900)识别。 + * + * @Author : Rainbow + * @date : 2023/7/11 + */ +@Service +@Slf4j +public class HomeServiceImpl implements HomeService { + + @Autowired + private HomeMapper homeMapper; + + // ==================== grade 常量 ==================== + + /** 累计值 */ + private static final int GRADE_CUMULATIVE = 40; + /** 瞬时值 */ + private static final int GRADE_INSTANT = 140; + + // ==================== 冷量表 mt_num 常量 ==================== + + /** 总冷量计读数(累计) */ + private static final String MT_COLD_READING = "39001700"; + /** 总冷量计供水温度 */ + private static final String MT_COLD_SUPPLY_TEMP = "39001620"; + /** 总冷量计回水温度 */ + private static final String MT_COLD_RETURN_TEMP = "39001660"; + /** 系统总冷量计瞬时冷量 */ + private static final String MT_SYS_COLD_INSTANT = "39001580"; + /** 冷量表 mt_num 前缀 */ + private static final String MT_COLD_PREFIX = "3900"; + + // ==================== 电力设备 other_name 前缀常量 ==================== + + /** 累计用电量总表(格数:PowerTotal_xxx) */ + private static final String ON_POWER_CUMULATIVE_PREFIX = "PowerTotal"; + /** 机房总瞬时功率 */ + private static final String ON_SYSTEM_POWER = "Power"; + /** 主机瞬时功率(格数:ChPower, ChPower01~04) */ + private static final String ON_CHILLER_POWER_PREFIX = "ChPower"; + /** 冷冻泵瞬时功率(格数:PriChWPPower, PriChWPPower01~05) */ + private static final String ON_CHILL_PUMP_POWER_PREFIX = "PriChWPPower"; + /** 冷却泵瞬时功率(格数:CWPPower, CWPPower01~05) */ + private static final String ON_COOL_PUMP_POWER_PREFIX = "CWPPower"; + /** 冷却塔瞬时功率(格数:CTPower, CTPower01~07) */ + private static final String ON_TOWER_POWER_PREFIX = "CTPower"; + + /** 产冷量参数类型 */ + private static final String PARAM_TYPE_COLD = "17"; + + // 总表的device_num + private static final List totalMeter = Arrays.asList( + "PowerTotal_CH", + "PowerTotal_ChWPump", + "PowerTotal_CWPump", + "PowerTotal_CT", + "PowerTotal" + ); + + @Override + public TableDataInfo getHomeCharts() { + String date = DateConstant.DAY_SDF.format(new Date()); + String tableName = TableUtils.getTableName("min", TableUtils.DEVICE, date); + Map resultMap = new LinkedHashMap<>(8); + + try { + // 1)设备总用电量:累计值(grade=40)所有非冷量表的电力设备 + List eleMtNums = safeList( + homeMapper.queryMtNumsByGradeAndOtherNamePrefix(GRADE_CUMULATIVE, ON_POWER_CUMULATIVE_PREFIX)); + // 过滤掉数组totalMeter的值 + eleMtNums.removeAll(totalMeter); + List eleHistory = queryOrEmpty(() -> + homeMapper.querySumHistoryByMtNums(tableName, eleMtNums)); + resultMap.put("eleChart", buildSingleChart("设备总用电量", eleHistory)); + + // 2)冷冻水供/回水温度走势图(只展示总管) + List coldOutHistory = queryOrEmpty(() -> + homeMapper.queryCurValueByDeviceCode(tableName, MT_COLD_SUPPLY_TEMP)); + List coldInHistory = queryOrEmpty(() -> + homeMapper.queryCurValueByDeviceCode(tableName, MT_COLD_RETURN_TEMP)); + + List> tempHistoryList = new ArrayList<>(); + tempHistoryList.add(wrapSeriesData("冷冻供水温度", coldOutHistory)); + tempHistoryList.add(wrapSeriesData("冷冻回水温度", coldInHistory)); + resultMap.put("tempChart", buildChart(tempHistoryList)); + + // 3)设备瞬时功率:瞬时值(grade=140)所有非冷量表的电力设备汇总 + List powerMtNums = safeList( + homeMapper.queryMtNumsByGradeExcludeMtNumPrefix(GRADE_INSTANT, MT_COLD_PREFIX)); + List powerHistory = queryOrEmpty(() -> + homeMapper.querySumHistoryByMtNums(tableName, powerMtNums)); + resultMap.put("eleRateChart", buildSingleChart("设备瞬时功率", powerHistory)); + + // 4)冷量表瞬时冷量 + List rateColdHis = queryOrEmpty(() -> + homeMapper.queryCalcValueByDeviceCode(tableName, MT_SYS_COLD_INSTANT)); + resultMap.put("cloudChart", buildSingleChart("冷量表瞬时冷量", rateColdHis)); + + // 5)瞬时 EER = 冷量瞬时值 / 功率瞬时值(时间对齐) + List dividedResultList = calcInstantEER(powerHistory, rateColdHis); + resultMap.put("copChart", buildSingleChart("系统EER", dividedResultList)); + } catch (Exception e) { + log.error("getHomeCharts 查询异常", e); + } + + return TableDataInfo.ok(resultMap); + } + + @Override + public TableDataInfo getStatisticalData() { + String date = DateConstant.DAY_SDF.format(new Date()); + String year = date.substring(0, 4); + String dayTable = "data_min" + year; + Map resultMap = new LinkedHashMap<>(16); + + try { + // 产冷量 mt_num:累计值(grade=40)中 param_type=2 的冷量表 + List coldMtNums = safeList( + homeMapper.queryMtNumsByGradeAndParamType(GRADE_CUMULATIVE, PARAM_TYPE_COLD)); + // 用电量 mt_num:累计值(grade=40)中所有电力设备(other_name 以 PowerTotal 开头) + List eleMtNums = safeList( + homeMapper.queryMtNumsByGradeAndOtherNamePrefix(GRADE_CUMULATIVE, ON_POWER_CUMULATIVE_PREFIX)); + // 过滤掉数组totalMeter的值 + eleMtNums.removeAll(totalMeter); + + Map allCap = homeMapper.selectAllTypeCap(dayTable, coldMtNums); + Map allEle = homeMapper.selectAllTypeEle(dayTable, eleMtNums); + BigDecimal totalCap = homeMapper.selectTotalCap(dayTable, MT_COLD_READING); + BigDecimal totalEle = homeMapper.selectTotalEle(dayTable, eleMtNums); + + BigDecimal dayColdCap = getOrDefault(allCap, "daycap"); + BigDecimal monthColdCap = getOrDefault(allCap, "monthcap"); + BigDecimal yearColdCap = getOrDefault(allCap, "yearcap"); + + BigDecimal dayEle = getOrDefault(allEle, "dayele"); + BigDecimal monthEle = getOrDefault(allEle, "monthele"); + BigDecimal yearEle = getOrDefault(allEle, "yearele"); + + resultMap.put("dayColdCap", String.valueOf(dayColdCap)); + resultMap.put("monthColdCap", String.valueOf(monthColdCap)); + resultMap.put("yearColdCap", String.valueOf(yearColdCap)); + resultMap.put("totalColdCap", String.valueOf(totalCap != null ? totalCap : BigDecimal.ZERO)); + + resultMap.put("dayEER", calcEER(dayColdCap, dayEle).toString()); + resultMap.put("monthEER", calcEER(monthColdCap, monthEle).toString()); + resultMap.put("yearEER", calcEER(yearColdCap, yearEle).toString()); + resultMap.put("totalEER", calcEER(totalCap, totalEle).toString()); + } catch (Exception e) { + log.error("getStatisticalData 计算出现异常", e); + } + + return TableDataInfo.ok(resultMap); + } + + @Override + public TableDataInfo getCoe() { + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); + String tableName = "data_min" + year; + + // 系统能效系数、主机能效、冷冻泵输送系数、冷却泵输送系数、冷却塔输送系数 + // 瞬时冷量:mt_num = 39001580(系统总冷量计瞬时冷量) + BigDecimal cap = homeMapper.selectLastCalcValueByMtNum(tableName, MT_SYS_COLD_INSTANT); + // 瞬时用电量:grade=140 所有电力设备,带 other_name 用于分类 + List> eleList = homeMapper.selectInstantEleWithOtherName(tableName, GRADE_INSTANT); + + // 按 other_name 前缀归类 + BigDecimal sysEle = BigDecimal.ZERO; + BigDecimal chillerEle = BigDecimal.ZERO; + BigDecimal chillPumpEle = BigDecimal.ZERO; + BigDecimal coolPumpEle = BigDecimal.ZERO; + BigDecimal towerEle = BigDecimal.ZERO; + + for (Map ele : eleList) { + String otherName = (String) ele.get("mt_num"); + BigDecimal value = (BigDecimal) ele.get("calc_value"); + if (otherName == null || value == null) { + continue; + } + if (otherName.equals(ON_SYSTEM_POWER)) { + sysEle = sysEle.add(value); + } else if (otherName.startsWith(ON_CHILLER_POWER_PREFIX)) { + chillerEle = chillerEle.add(value); + } else if (otherName.startsWith(ON_CHILL_PUMP_POWER_PREFIX)) { + chillPumpEle = chillPumpEle.add(value); + } else if (otherName.startsWith(ON_COOL_PUMP_POWER_PREFIX)) { + coolPumpEle = coolPumpEle.add(value); + } else if (otherName.startsWith(ON_TOWER_POWER_PREFIX)) { + towerEle = towerEle.add(value); + } + } + + Map resultMap = new LinkedHashMap<>(8); + if (cap == null) { + resultMap.put("sysCoe", null); + resultMap.put("chillerCoe", null); + resultMap.put("chillPumpCoe", null); + resultMap.put("coolPumpCoe", null); + resultMap.put("towerCoe", null); + return TableDataInfo.ok(resultMap); + } + + resultMap.put("sysCoe", safeDivide(cap, sysEle)); + resultMap.put("chillerCoe", safeDivide(cap, chillerEle)); + resultMap.put("chillPumpCoe", safeDivide(cap, chillPumpEle)); + resultMap.put("coolPumpCoe", safeDivide(cap, coolPumpEle)); + resultMap.put("towerCoe", safeDivide(cap, towerEle)); + + return TableDataInfo.ok(resultMap); + } + + @Override + public TableDataInfo getRunTime() { + // 从运行时长的表中读取系统运行时长的数据 + long runTime = homeMapper.selectRunTime(); + return TableDataInfo.ok(runTime); + } + + @Override + public TableDataInfo getCurrentRate() { + Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); + String tableName = "data_min" + year; + + // 实时总用电量:瞬时值(grade=140)所有电力设备最新 calc_value 之和 + List powerMtNums = safeList( + homeMapper.queryMtNumsByGradeExcludeMtNumPrefix(GRADE_INSTANT, MT_COLD_PREFIX)); + double eleUsed = homeMapper.selectLastEle(tableName, powerMtNums); + BigDecimal power = BigDecimal.valueOf(eleUsed).setScale(2, RoundingMode.HALF_UP); + + // 实时产冷量:瞬时冷量表最新值 + BigDecimal capPower = homeMapper.selectLastCalcValueByMtNum(tableName, MT_SYS_COLD_INSTANT); + + Map resultMap = new LinkedHashMap<>(4); + resultMap.put("totalEle", power.toString()); + resultMap.put("totalCap", capPower != null + ? capPower.setScale(2, RoundingMode.HALF_UP).toString() : "0"); + + return TableDataInfo.ok(resultMap); + } + + @Override + public TableDataInfo getWeatherData() { + // 获取今天的日期,格式为 yyyy-MM-dd + String date = DateUtils.getDate(); + Map values = homeMapper.selectWeatherData(date + " 00:00:00", date + " 23:59:59"); + if (values == null) { + return TableDataInfo.ok(); + } + Map result = new LinkedHashMap<>(2); + result.putIfAbsent("temperature", + String.valueOf(values.get("temperature"))); + result.putIfAbsent("humidity", + String.valueOf(values.get("humidity"))); + return TableDataInfo.ok(result); + } + + // ==================== 私有辅助方法 ==================== + + /** + * null → 空列表 + */ + private List safeList(List list) { + return list != null ? list : Collections.emptyList(); + } + + /** + * 从 Map 安全取值 + */ + private BigDecimal getOrDefault(Map map, String key) { + if (map == null) { + return BigDecimal.ZERO; + } + BigDecimal val = map.get(key); + return val != null ? val : BigDecimal.ZERO; + } + + /** + * 安全查询,异常时返回空列表 + */ + private List queryOrEmpty(Supplier> query) { + try { + List result = query.get(); + return result != null ? result : Collections.emptyList(); + } catch (Exception e) { + log.warn("数据查询返回空", e); + return Collections.emptyList(); + } + } + + /** + * 构建单系列图表 + */ + private ChartEntity buildSingleChart(String name, List historyList) { + if (CollectionUtils.isEmpty(historyList)) { + return null; + } + List> dataList = new ArrayList<>(); + dataList.add(wrapSeriesData(name, historyList)); + return buildChart(dataList); + } + + /** + * 封装单系列数据 + */ + private Map wrapSeriesData(String name, List historyList) { + Map map = new HashMap<>(4); + map.put("name", name); + map.put("value", historyList != null ? historyList : Collections.emptyList()); + return map; + } + + /** + * 计算瞬时 EER = 冷量 / 功率(时间对齐) + */ + private List calcInstantEER(List powerHistory, List coldHistory) { + if (CollectionUtils.isEmpty(powerHistory) || CollectionUtils.isEmpty(coldHistory)) { + return Collections.emptyList(); + } + + List result = new ArrayList<>(); + List powerSorted = new ArrayList<>(powerHistory); + List coldSorted = new ArrayList<>(coldHistory); + + powerSorted.sort(Comparator.comparing(HistoryEntity::getDate)); + coldSorted.sort(Comparator.comparing(HistoryEntity::getDate)); + + Iterator powerIt = powerSorted.iterator(); + Iterator coldIt = coldSorted.iterator(); + + HistoryEntity powerItem = powerIt.hasNext() ? powerIt.next() : null; + HistoryEntity coldItem = coldIt.hasNext() ? coldIt.next() : null; + + while (powerItem != null && coldItem != null) { + int timeCompare = powerItem.getDate().compareTo(coldItem.getDate()); + if (timeCompare == 0) { + double divideValue = 0; + if (powerItem.getValue() > 0 && coldItem.getValue() >= 0) { + divideValue = coldItem.getValue() / powerItem.getValue(); + } + divideValue = BigDecimal.valueOf(divideValue) + .setScale(2, RoundingMode.HALF_UP).doubleValue(); + + HistoryEntity entity = new HistoryEntity(); + entity.setDate(powerItem.getDate()); + entity.setValue(divideValue); + result.add(entity); + + powerItem = powerIt.hasNext() ? powerIt.next() : null; + coldItem = coldIt.hasNext() ? coldIt.next() : null; + } else if (timeCompare < 0) { + powerItem = powerIt.hasNext() ? powerIt.next() : null; + } else { + coldItem = coldIt.hasNext() ? coldIt.next() : null; + } + } + return result; + } + + /** + * 计算 EER 系数 + */ + private BigDecimal calcEER(BigDecimal cap, BigDecimal ele) { + if (cap == null || ele == null + || cap.compareTo(BigDecimal.ZERO) == 0 + || ele.compareTo(BigDecimal.ZERO) == 0) { + return BigDecimal.ZERO; + } + return cap.divide(ele, 2, RoundingMode.HALF_UP); + } + + /** + * 安全除法,分子或除数为0/null时返回null + */ + private BigDecimal safeDivide(BigDecimal numerator, BigDecimal denominator) { + if (numerator == null || denominator == null + || denominator.compareTo(BigDecimal.ZERO) == 0) { + return null; + } + return numerator.divide(denominator, 2, RoundingMode.HALF_UP); + } + + /** + * 构建 chart 图表数据 + * + * @param dealDatas 图表数据列表,每个元素包含 name 和 value + * @return ChartEntity 图表实体 + */ + private ChartEntity buildChart(List> dealDatas) { + if (CollectionUtils.isEmpty(dealDatas)) { + return null; + } + + ChartEntity chartEntity = new ChartEntity(); + chartEntity.setToolTip(new ToolTip("axis")); + chartEntity.setLegend(new Legend()); + List seriesList = new ArrayList<>(); + + for (Map dealData : dealDatas) { + if (CollectionUtils.isEmpty(dealData)) { + continue; + } + String name = (String) dealData.get("name"); + @SuppressWarnings("unchecked") + List data = (List) dealData.get("value"); + if (CollectionUtils.isEmpty(data)) { + continue; + } + Double[] values = data.stream() + .map(HistoryEntity::getValue).toArray(Double[]::new); + Series series = new Series(name, "line", 0, values, "average"); + chartEntity.setXAxis(new XAxis(data.stream() + .map(HistoryEntity::getDate).toArray(String[]::new))); + seriesList.add(series); + } + chartEntity.setSeries(seriesList); + return chartEntity; + } +} 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 8d9d74b..ec04916 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 @@ -728,7 +728,7 @@ public class ProOverviewServiceImpl implements IProOverviewService { .map(sysDictData -> CompletableFuture.supplyAsync(() -> { String sysType = sysDictData.getDictValue(); // 查询采集参数 - List collectionParamsManages = queryCollectionParams(paramType, sysType, 40, null, false); + List collectionParamsManages = queryCollectionParams(paramType, sysType, 40, "15", false); // 合并数据 if (collectionParamsManages != null && !collectionParamsManages.isEmpty()) { return overviewMapper.energyAnalysis(collectionParamsManages); @@ -818,9 +818,9 @@ public class ProOverviewServiceImpl implements IProOverviewService { private String getEnergyUnit(String paramType) { switch (paramType) { case "16": - return "kw/h"; + return "kwh"; case "17": - return "kw"; + return "kwh"; case "18": return "t"; case "19": diff --git a/mh-system/src/main/resources/mapper/system/EnergyMapper.xml b/mh-system/src/main/resources/mapper/system/EnergyMapper.xml index 8788c6d..9377ffb 100644 --- a/mh-system/src/main/resources/mapper/system/EnergyMapper.xml +++ b/mh-system/src/main/resources/mapper/system/EnergyMapper.xml @@ -105,7 +105,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time) @@ -143,7 +143,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time) @@ -180,7 +180,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time) @@ -217,7 +217,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time) @@ -261,7 +261,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) GROUP BY device_type, @@ -292,7 +292,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) GROUP BY device_type, @@ -324,7 +324,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) GROUP BY device_type, @@ -355,7 +355,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) GROUP BY device_type, @@ -408,7 +408,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) GROUP BY TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time) @@ -448,7 +448,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) GROUP BY EXTRACT(YEAR FROM cur_time) @@ -511,7 +511,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) group by @@ -553,7 +553,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) group by @@ -606,7 +606,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) group by substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}), @@ -637,7 +637,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) group by substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}), @@ -669,7 +669,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) group by extract(year from cur_time) @@ -698,7 +698,7 @@ and cpm.system_type = #{systemType} and cpm.grade = 40 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) group by extract(year from cur_time) @@ -726,13 +726,13 @@ 'YYYY-MM-DD HH24' 'YYYY-MM-DD HH24:MI' 'YYYY-MM-DD HH24:MI:SS' - + = #{startTime}::timestamp - and dm.cur_time <= #{endTime}::timestamp + and dm.cur_time <= #{endTime}::timestamp and dm.device_num in( select cpm.mt_num @@ -747,12 +747,19 @@ and cpm.terminal_device_type = #{deviceType} and cpm.is_use = '0' and cpm.grade = 40 + and cpm.mt_code not in( + 'PowerTotal_CH', + 'PowerTotal_ChWPump', + 'PowerTotal_CWPump', + 'PowerTotal_CT', + 'PowerTotal' + ) group by cpm.mt_num ) group by TO_CHAR(dm.cur_time, - + ]]> 'YYYY' 'YYYY-MM' 'YYYY-MM-DD' @@ -853,6 +860,13 @@ and cpm.is_use = '0' and cpm.grade = 40 + and cpm.mt_code not in ( + 'PowerTotal_CH', + 'PowerTotal_ChWPump', + 'PowerTotal_CWPump', + 'PowerTotal_CT', + 'PowerTotal' + ) group by cpm.mt_num ) @@ -903,6 +917,13 @@ and cpm.is_use = '0' and cpm.grade = 40 + and cpm.mt_code not in ( + 'PowerTotal_CH', + 'PowerTotal_ChWPump', + 'PowerTotal_CWPump', + 'PowerTotal_CT', + 'PowerTotal' + ) group by cpm.mt_num ) @@ -1052,7 +1073,7 @@ cpm.device_ledger_id = dl.id and dl.device_type = '5' and cpm.grade = 140 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) group by device_type, @@ -1079,7 +1100,7 @@ cpm.device_ledger_id = dl.id and dl.device_type = '6' and cpm.grade = 140 --- and cpm.terminal_device_type = '15' + and cpm.terminal_device_type = '15' ) group by device_type,