From 4ad037f0028e2997822a714823ed14fdc22ee5a9 Mon Sep 17 00:00:00 2001 From: 25604 Date: Tue, 24 Jun 2025 17:37:16 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=94=9F=E6=B4=BB=E7=83=AD=E6=B0=B4?= =?UTF-8?q?=E4=BE=9B=E6=B0=B4=E7=B3=BB=E7=BB=9F=E6=A5=BC=E5=B1=82=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E3=80=81=E9=A1=B9=E7=9B=AE=E6=80=BB=E8=A7=88=E3=80=81?= =?UTF-8?q?=E8=83=BD=E6=BA=90=E5=88=86=E6=9E=90=E3=80=81=E7=94=A8=E8=83=BD?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E3=80=81=E6=95=B0=E6=8D=AE=E5=88=86=E6=9E=90?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../energy/HotWaterEnergyController.java | 109 ++++++++ .../space/BuildingInfoController.java | 18 ++ mh-admin/src/main/resources/logback.xml | 44 +-- .../com/mh/common/constant/EnergyType.java | 25 ++ .../common/core/domain/dto/DataResultDTO.java | 68 +++++ .../core/domain/entity/AnalysisMonth.java | 46 +++ .../core/domain/entity/AnalysisYear.java | 27 ++ .../core/domain/entity/DeviceState.java | 3 + .../common/core/domain/entity/EnergyDay.java | 89 ++++++ .../core/domain/entity/EnergyDaySum.java | 74 +++++ .../common/core/domain/entity/EnergyHour.java | 220 +++++++++++++++ .../core/domain/entity/EnergyMonth.java | 89 ++++++ .../core/domain/entity/EnergyMonthSum.java | 74 +++++ .../common/core/domain/entity/EnergyYear.java | 89 ++++++ .../core/domain/entity/EnergyYearSum.java | 74 +++++ .../common/core/domain/entity/WaterLevel.java | 117 ++++++++ .../common/core/domain/entity/WaterTemp.java | 117 ++++++++ .../java/com/mh/quartz/task/HotWaterTask.java | 224 +++++++++++++++ .../mapper/device/DeviceStateMapper.java | 2 +- .../system/mapper/energy/AnalysisMapper.java | 56 ++++ .../system/mapper/energy/EnergyDayMapper.java | 28 ++ .../mapper/energy/EnergyDaySumMapper.java | 22 ++ .../mapper/energy/EnergyHourMapper.java | 27 ++ .../mapper/energy/EnergyMonthMapper.java | 28 ++ .../mapper/energy/EnergyMonthSumMapper.java | 23 ++ .../mapper/energy/EnergyYearMapper.java | 27 ++ .../mapper/energy/EnergyYearSumMapper.java | 24 ++ .../mapper/energy/HotEnergyQueryMapper.java | 118 ++++++++ .../mapper/energy/WaterLevelMapper.java | 102 +++++++ .../system/mapper/energy/WaterTempMapper.java | 103 +++++++ .../service/energy/IEnergyQueryService.java | 32 +++ .../service/energy/IWaterLevelService.java | 14 + .../service/energy/IWaterTempService.java | 14 + .../energy/impl/EnergyQueryServiceImpl.java | 262 +++++++++++++++++- .../energy/impl/WaterLevelServiceImpl.java | 60 ++++ .../energy/impl/WaterTempServiceImpl.java | 60 ++++ 36 files changed, 2477 insertions(+), 32 deletions(-) create mode 100644 mh-admin/src/main/java/com/mh/web/controller/energy/HotWaterEnergyController.java create mode 100644 mh-common/src/main/java/com/mh/common/constant/EnergyType.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/dto/DataResultDTO.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/AnalysisMonth.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/AnalysisYear.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyDay.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyDaySum.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyHour.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyMonth.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyMonthSum.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyYear.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyYearSum.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/WaterLevel.java create mode 100644 mh-common/src/main/java/com/mh/common/core/domain/entity/WaterTemp.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/energy/AnalysisMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/energy/EnergyDayMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/energy/EnergyDaySumMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/energy/EnergyHourMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMonthMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMonthSumMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/energy/EnergyYearMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/energy/EnergyYearSumMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/energy/HotEnergyQueryMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/energy/WaterLevelMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/mapper/energy/WaterTempMapper.java create mode 100644 mh-system/src/main/java/com/mh/system/service/energy/IWaterLevelService.java create mode 100644 mh-system/src/main/java/com/mh/system/service/energy/IWaterTempService.java create mode 100644 mh-system/src/main/java/com/mh/system/service/energy/impl/WaterLevelServiceImpl.java create mode 100644 mh-system/src/main/java/com/mh/system/service/energy/impl/WaterTempServiceImpl.java diff --git a/mh-admin/src/main/java/com/mh/web/controller/energy/HotWaterEnergyController.java b/mh-admin/src/main/java/com/mh/web/controller/energy/HotWaterEnergyController.java new file mode 100644 index 0000000..26177d3 --- /dev/null +++ b/mh-admin/src/main/java/com/mh/web/controller/energy/HotWaterEnergyController.java @@ -0,0 +1,109 @@ +package com.mh.web.controller.energy; + +import com.mh.common.core.controller.BaseController; +import com.mh.common.core.domain.entity.WaterLevel; +import com.mh.common.core.domain.entity.WaterTemp; +import com.mh.common.core.page.TableDataInfo; +import com.mh.system.service.energy.IEnergyQueryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 生活热水能耗分析 + * @date 2025-06-18 17:49:49 + */ +@RestController +@RequestMapping("/hot_energy") +public class HotWaterEnergyController extends BaseController { + + private final IEnergyQueryService energyQueryService; + + public HotWaterEnergyController(IEnergyQueryService iEnergyQueryService) { + this.energyQueryService = iEnergyQueryService; + } + + @GetMapping("/query") + public TableDataInfo queryEnergy(@RequestParam(value = "buildingId", required = false) String buildingId, + @RequestParam(value = "startDate", required = false) String startDate, + @RequestParam(value = "endDate", required = false) String endDate, + @RequestParam(value = "type") int type) { + startPage(); + List result = energyQueryService.queryEnergyDataList(buildingId, startDate, endDate, type); + return getDataTable(result); + } + + //查询日月年用量汇总 + @GetMapping(value = "/energySum") + public TableDataInfo queryEnergySum(@RequestParam(value = "buildingId", required = false) String buildingId, + @RequestParam(value = "curDate", required = false) String curDate, + @RequestParam(value = "type", required = true) Integer type) { + startPage(); + List result = energyQueryService.queryEnergyDataSumList(buildingId, curDate, type); + return getDataTable(result); + } + + /** + * 温度变化表 + * + * @param buildingId + * @param curDate + * @return + */ + @GetMapping("/waterTemp") + public TableDataInfo queryWaterTemp(@RequestParam(value = "buildingId", required = false) String buildingId, + @RequestParam(value = "curDate", required = false) String curDate) { + startPage(); + List result = energyQueryService.queryWaterTemp(buildingId, curDate); + return getDataTable(result); + } + + /** + * 水位变化表 + * + * @param buildingId + * @param curDate + * @return + */ + @GetMapping("/waterLevel") + public TableDataInfo queryWaterLevel(@RequestParam(value = "buildingId", required = false) String buildingId, + @RequestParam(value = "curDate", required = false) String curDate) { + startPage(); + List result = energyQueryService.queryWaterLevel(buildingId, curDate); + return getDataTable(result); + } + + @GetMapping("/queryDeviceDatas") + public TableDataInfo queryDeviceDatas(@RequestParam(value = "buildingId", required = false) String buildingId, + @RequestParam(value = "startDate", required = false) String startDate, + @RequestParam(value = "endDate", required = false) String endDate, + @RequestParam(value = "deviceType", required = false) String deviceType) { + startPage(); + List result = energyQueryService.queryDeviceDatas(buildingId, startDate, endDate, deviceType); + return getDataTable(result); + } + + @GetMapping("/analysis/queryYear") //type=1(水),2(电),3(能耗),4(维保) + public TableDataInfo queryAnalysisYear(@RequestParam(value = "curDate",required = true) String curDate, + @RequestParam(value = "buildingId",required = true) String buildingId, + @RequestParam(value = "type",defaultValue = "3") int type) { + startPage(); + List result = energyQueryService.queryAnalysisYear(curDate, buildingId, type); + return getDataTable(result); + + } + + @GetMapping("/analysis/queryMonth") //type=1(水),2(电),3(能耗),4(维保),5(使用时间) + public TableDataInfo queryAnalysisMonth(@RequestParam(value = "curDate",required = true) String curDate, + @RequestParam(value = "buildingId",required = true) String buildingId, + @RequestParam(value = "type",defaultValue = "3") int type) { + startPage(); + List result = energyQueryService.queryAnalysisMonth(curDate, buildingId, type); + return getDataTable(result); + } + +} diff --git a/mh-admin/src/main/java/com/mh/web/controller/space/BuildingInfoController.java b/mh-admin/src/main/java/com/mh/web/controller/space/BuildingInfoController.java index 4709aa0..89d4ec8 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/space/BuildingInfoController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/space/BuildingInfoController.java @@ -6,6 +6,7 @@ import com.mh.common.core.domain.AjaxResult; import com.mh.common.core.domain.entity.BuildingInfo; import com.mh.common.core.page.TableDataInfo; import com.mh.common.enums.BusinessType; +import com.mh.system.service.energy.IEnergyQueryService; import com.mh.system.service.space.IBuildingInfoService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; @@ -13,6 +14,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.Map; /** * @author LJF @@ -28,6 +30,9 @@ public class BuildingInfoController extends BaseController { @Autowired private IBuildingInfoService buildingInfoService; + @Autowired + private IEnergyQueryService energyQueryService; + /** * 获取楼栋管理列表内容数据 */ @@ -85,4 +90,17 @@ public class BuildingInfoController extends BaseController { return toAjax(buildingInfoService.deleteBuildingInfoByIds(buildingIds)); } + /** + * 获取楼栋管理列表内容数据 + */ + @GetMapping("/hot_list") + public TableDataInfo hotWaterList() + { + List> list = energyQueryService.queryFloorInfo(); + // 在当前list首个坐标加个值 + list.addFirst(Map.of("id", "所有", "building_name", "所有")); + return getDataTable(list); + } + + } diff --git a/mh-admin/src/main/resources/logback.xml b/mh-admin/src/main/resources/logback.xml index 11c053f..29fd80d 100644 --- a/mh-admin/src/main/resources/logback.xml +++ b/mh-admin/src/main/resources/logback.xml @@ -13,27 +13,27 @@ - - ${log.path}/sys-info.log - - - - ${log.path}/sys-info.%d{yyyy-MM-dd}.log - - 1 - - - ${log.pattern} - - - - INFO - - ACCEPT - - DENY - - + + + + + + + + + + + + + + + + + + + + + ${log.path}/sys-error.log @@ -82,7 +82,7 @@ - + diff --git a/mh-common/src/main/java/com/mh/common/constant/EnergyType.java b/mh-common/src/main/java/com/mh/common/constant/EnergyType.java new file mode 100644 index 0000000..a369f4f --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/constant/EnergyType.java @@ -0,0 +1,25 @@ +package com.mh.common.constant; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description + * @date 2025-06-18 16:32:56 + */ +public enum EnergyType { + HOUR("hour"), + DAY("day"), + MONTH("month"), + YEAR("year"); + + private final String code; + + EnergyType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/dto/DataResultDTO.java b/mh-common/src/main/java/com/mh/common/core/domain/dto/DataResultDTO.java new file mode 100644 index 0000000..81b2ddf --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/dto/DataResultDTO.java @@ -0,0 +1,68 @@ +package com.mh.common.core.domain.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.math.BigDecimal; +import java.util.Date; + +@Data +public class DataResultDTO { + + private Long id; + + private String buildingId; + + private String buildingName; + + private String deviceNum; + + private String deviceName; + + private String deviceCode; + + private String deviceType; + + private BigDecimal lastValue; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date lastTime; + + private double curValue; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date curTime; + + private BigDecimal usedValue; + + private int ratio; + + private BigDecimal calcValue; + + private int grade; + + private String registerAddr; + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("id", id) + .append("buildingId", buildingId) + .append("buildingName", buildingName) + .append("deviceNum", deviceNum) + .append("deviceName", deviceName) + .append("deviceCode", deviceCode) + .append("deviceType", deviceType) + .append("lastValue", lastValue) + .append("lastTime", lastTime) + .append("curValue", curValue) + .append("curTime", curTime) + .append("usedValue", usedValue) + .append("ratio", ratio) + .append("calcValue", calcValue) + .append("grade", grade) + .append("registerAddr", registerAddr) + .toString(); + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/AnalysisMonth.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/AnalysisMonth.java new file mode 100644 index 0000000..5790655 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/AnalysisMonth.java @@ -0,0 +1,46 @@ +package com.mh.common.core.domain.entity; + +import lombok.Data; + +@Data +public class AnalysisMonth { + + private Long id; + private String curDate; + private String itemType; + private String day01; + private String day02; + private String day03; + private String day04; + private String day05; + private String day06; + private String day07; + private String day08; + private String day09; + private String day10; + private String day11; + private String day12; + private String day13; + private String day14; + private String day15; + private String day16; + private String day17; + private String day18; + private String day19; + private String day20; + private String day21; + private String day22; + private String day23; + private String day24; + private String day25; + private String day26; + private String day27; + private String day28; + private String day29; + private String day30; + private String day31; + private String day32; + private String totalValue; + private String buildingId; + private String buildingName; +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/AnalysisYear.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/AnalysisYear.java new file mode 100644 index 0000000..0b7c99f --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/AnalysisYear.java @@ -0,0 +1,27 @@ +package com.mh.common.core.domain.entity; + +import lombok.Data; + +@Data +public class AnalysisYear { + + private Long id; + private String curDate; + private String itemType; + private String month01; + private String month02; + private String month03; + private String month04; + private String month05; + private String month06; + private String month07; + private String month08; + private String month09; + private String month10; + private String month11; + private String month12; + private String totalValue; + private String buildingId; + private String buildingName; + +} 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 ef77558..61f8ab4 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,5 +1,7 @@ package com.mh.common.core.domain.entity; +import com.alibaba.fastjson2.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import java.util.Date; @@ -16,6 +18,7 @@ public class DeviceState { /** * 当前时间 */ + @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/EnergyDay.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyDay.java new file mode 100644 index 0000000..950bc18 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyDay.java @@ -0,0 +1,89 @@ +package com.mh.common.core.domain.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水时间能耗实体类 + * @date 2025-06-18 14:28:30 + */ +@Data +@TableName("energy_day") +public class EnergyDay { + + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + /** + * 时间 + */ + private String curDate; + + /** + * 建筑id + */ + private String buildingId; + + /** + * 产热量 + */ + private BigDecimal hotWaterValue; + + /** + * 使用用量 + */ + private BigDecimal useHotWater; + + /** + * 用电量 + */ + private BigDecimal electValue; + + /** + * 单耗 + */ + private BigDecimal electWater; + + /** + * 入住人数 + */ + private int checkInCount; + + /** + * 人均用电 + */ + private BigDecimal perElect; + + /** + * 人均用水 + */ + private BigDecimal perWater; + + /** + * 更新标志 + */ + private String updateFlag; + + /** + * 建筑名称 + */ + private String buildingName; + + /** + * 当前电表读数 + */ + private BigDecimal electCurValue; + + /** + * 当前水表读数 + */ + private BigDecimal wtCurValue; + +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyDaySum.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyDaySum.java new file mode 100644 index 0000000..4004568 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyDaySum.java @@ -0,0 +1,74 @@ +package com.mh.common.core.domain.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水时间能耗实体类 + * @date 2025-06-18 14:28:30 + */ +@Data +@TableName("energy_day_sum") +public class EnergyDaySum { + + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + /** + * 时间 + */ + private String curDate; + + /** + * 建筑id + */ + private String buildingId; + + /** + * 补水 + */ + private BigDecimal fillWater; + + /** + * 补水与昨日比 + */ + private String fillWaterP; + + /** + * 用水 + */ + private BigDecimal waterValue; + + /** + * 用水与昨日比 + */ + private String waterP; + + /** + * 用电量 + */ + private BigDecimal electValue; + + /** + * 用电与昨日比 + */ + private String electP; + + /** + * 单耗 + */ + private BigDecimal electWater; + + /** + * 单耗与昨日比 + */ + private String electWaterP; + +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyHour.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyHour.java new file mode 100644 index 0000000..deda123 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyHour.java @@ -0,0 +1,220 @@ +package com.mh.common.core.domain.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.math.BigDecimal; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水时间能耗实体类 + * @date 2025-06-18 14:28:30 + */ +@TableName("energy_hour") +public class EnergyHour { + + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + /** + * 时间 + */ + private String curDate; + + /** + * 建筑id + */ + private String buildingId; + + /** + * 产热量 + */ + private BigDecimal hotWaterValue; + + /** + * 使用用量 + */ + private BigDecimal useHotWater; + + /** + * 用电量 + */ + private BigDecimal electValue; + + /** + * 单耗 + */ + private BigDecimal electWater; + + /** + * 入住人数 + */ + private int checkInCount; + + /** + * 人均用电 + */ + private BigDecimal perElect; + + /** + * 人均用水 + */ + private BigDecimal perWater; + + /** + * 更新标志 + */ + private String updateFlag; + + /** + * 建筑名称 + */ + private String buildingName; + + /** + * 当前电表读数 + */ + private BigDecimal electCurValue; + + /** + * 当前水表读数 + */ + private BigDecimal wtCurValue; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getCurDate() { + return curDate; + } + + public void setCurDate(String curDate) { + this.curDate = curDate; + } + + public String getBuildingId() { + return buildingId; + } + + public void setBuildingId(String buildingId) { + this.buildingId = buildingId; + } + + public BigDecimal getHotWaterValue() { + return hotWaterValue; + } + + public void setHotWaterValue(BigDecimal hotWaterValue) { + this.hotWaterValue = hotWaterValue; + } + + public BigDecimal getUseHotWater() { + return useHotWater; + } + + public void setUseHotWater(BigDecimal useHotWater) { + this.useHotWater = useHotWater; + } + + public BigDecimal getElectValue() { + return electValue; + } + + public void setElectValue(BigDecimal electValue) { + this.electValue = electValue; + } + + public BigDecimal getElectWater() { + return electWater; + } + + public void setElectWater(BigDecimal electWater) { + this.electWater = electWater; + } + + public int getCheckInCount() { + return checkInCount; + } + + public void setCheckInCount(int checkInCount) { + this.checkInCount = checkInCount; + } + + public BigDecimal getPerElect() { + return perElect; + } + + public void setPerElect(BigDecimal perElect) { + this.perElect = perElect; + } + + public BigDecimal getPerWater() { + return perWater; + } + + public void setPerWater(BigDecimal perWater) { + this.perWater = perWater; + } + + public String getUpdateFlag() { + return updateFlag; + } + + public void setUpdateFlag(String updateFlag) { + this.updateFlag = updateFlag; + } + + public String getBuildingName() { + return buildingName; + } + + public void setBuildingName(String buildingName) { + this.buildingName = buildingName; + } + + public BigDecimal getElectCurValue() { + return electCurValue; + } + + public void setElectCurValue(BigDecimal electCurValue) { + this.electCurValue = electCurValue; + } + + public BigDecimal getWtCurValue() { + return wtCurValue; + } + + public void setWtCurValue(BigDecimal wtCurValue) { + this.wtCurValue = wtCurValue; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("id", id) + .append("curDate", curDate) + .append("buildingId", buildingId) + .append("hotWaterValue", hotWaterValue) + .append("useHotWater", useHotWater) + .append("electValue", electValue) + .append("electWater", electWater) + .append("checkInCount", checkInCount) + .append("perElect", perElect) + .append("perWater", perWater) + .append("updateFlag", updateFlag) + .append("buildingName", buildingName) + .append("electCurValue", electCurValue) + .append("wtCurValue", wtCurValue) + .toString(); + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyMonth.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyMonth.java new file mode 100644 index 0000000..372446f --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyMonth.java @@ -0,0 +1,89 @@ +package com.mh.common.core.domain.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水时间能耗实体类 + * @date 2025-06-18 14:28:30 + */ +@Data +@TableName("energy_month") +public class EnergyMonth { + + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + /** + * 时间 + */ + private String curDate; + + /** + * 建筑id + */ + private String buildingId; + + /** + * 产热量 + */ + private BigDecimal hotWaterValue; + + /** + * 使用用量 + */ + private BigDecimal useHotWater; + + /** + * 用电量 + */ + private BigDecimal electValue; + + /** + * 单耗 + */ + private BigDecimal electWater; + + /** + * 入住人数 + */ + private int checkInCount; + + /** + * 人均用电 + */ + private BigDecimal perElect; + + /** + * 人均用水 + */ + private BigDecimal perWater; + + /** + * 更新标志 + */ + private String updateFlag; + + /** + * 建筑名称 + */ + private String buildingName; + + /** + * 当前电表读数 + */ + private BigDecimal electCurValue; + + /** + * 当前水表读数 + */ + private BigDecimal wtCurValue; + +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyMonthSum.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyMonthSum.java new file mode 100644 index 0000000..5251ad0 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyMonthSum.java @@ -0,0 +1,74 @@ +package com.mh.common.core.domain.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水时间能耗实体类 + * @date 2025-06-18 14:28:30 + */ +@Data +@TableName("energy_month_sum") +public class EnergyMonthSum { + + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + /** + * 时间 + */ + private String curDate; + + /** + * 建筑id + */ + private String buildingId; + + /** + * 补水 + */ + private BigDecimal fillWater; + + /** + * 补水与昨日比 + */ + private String fillWaterP; + + /** + * 用水 + */ + private BigDecimal waterValue; + + /** + * 用水与昨日比 + */ + private String waterP; + + /** + * 用电量 + */ + private BigDecimal electValue; + + /** + * 用电与昨日比 + */ + private String electP; + + /** + * 单耗 + */ + private BigDecimal electWater; + + /** + * 单耗与昨日比 + */ + private String electWaterP; + +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyYear.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyYear.java new file mode 100644 index 0000000..cb8f42b --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyYear.java @@ -0,0 +1,89 @@ +package com.mh.common.core.domain.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水时间能耗实体类 + * @date 2025-06-18 14:28:30 + */ +@Data +@TableName("energy_year") +public class EnergyYear { + + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + /** + * 时间 + */ + private String curDate; + + /** + * 建筑id + */ + private String buildingId; + + /** + * 产热量 + */ + private BigDecimal hotWaterValue; + + /** + * 使用用量 + */ + private BigDecimal useHotWater; + + /** + * 用电量 + */ + private BigDecimal electValue; + + /** + * 单耗 + */ + private BigDecimal electWater; + + /** + * 入住人数 + */ + private int checkInCount; + + /** + * 人均用电 + */ + private BigDecimal perElect; + + /** + * 人均用水 + */ + private BigDecimal perWater; + + /** + * 更新标志 + */ + private String updateFlag; + + /** + * 建筑名称 + */ + private String buildingName; + + /** + * 当前电表读数 + */ + private BigDecimal electCurValue; + + /** + * 当前水表读数 + */ + private BigDecimal wtCurValue; + +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyYearSum.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyYearSum.java new file mode 100644 index 0000000..93a15b3 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyYearSum.java @@ -0,0 +1,74 @@ +package com.mh.common.core.domain.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水时间能耗实体类 + * @date 2025-06-18 14:28:30 + */ +@Data +@TableName("energy_month_sum") +public class EnergyYearSum { + + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + /** + * 时间 + */ + private String curDate; + + /** + * 建筑id + */ + private String buildingId; + + /** + * 补水 + */ + private BigDecimal fillWater; + + /** + * 补水与昨日比 + */ + private String fillWaterP; + + /** + * 用水 + */ + private BigDecimal waterValue; + + /** + * 用水与昨日比 + */ + private String waterP; + + /** + * 用电量 + */ + private BigDecimal electValue; + + /** + * 用电与昨日比 + */ + private String electP; + + /** + * 单耗 + */ + private BigDecimal electWater; + + /** + * 单耗与昨日比 + */ + private String electWaterP; + +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/WaterLevel.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/WaterLevel.java new file mode 100644 index 0000000..fd0d8de --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/WaterLevel.java @@ -0,0 +1,117 @@ +package com.mh.common.core.domain.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.util.Date; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水液位 + * @date 2025-06-19 16:18:12 + */ +@Data +@TableName("water_level") +public class WaterLevel { + + private String id; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date curDate; + + private String buildingId; + + private String buildingName; + + private String deviceNum; + + private String deviceName; + + private String temp00; + + private String temp01; + + private String temp02; + + private String temp03; + + private String temp04; + + private String temp05; + + private String temp06; + + private String temp07; + + private String temp08; + + private String temp09; + + private String temp10; + + private String temp11; + + private String temp12; + + private String temp13; + + private String temp14; + + private String temp15; + + private String temp16; + + private String temp17; + + private String temp18; + + private String temp19; + + private String temp20; + + private String temp21; + + private String temp22; + + private String temp23; + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("id", id) + .append("curDate", curDate) + .append("buildingId", buildingId) + .append("buildingName", buildingName) + .append("deviceNum", deviceNum) + .append("deviceName", deviceName) + .append("temp00", temp00) + .append("temp01", temp01) + .append("temp02", temp02) + .append("temp03", temp03) + .append("temp04", temp04) + .append("temp05", temp05) + .append("temp06", temp06) + .append("temp07", temp07) + .append("temp08", temp08) + .append("temp09", temp09) + .append("temp10", temp10) + .append("temp11", temp11) + .append("temp12", temp12) + .append("temp13", temp13) + .append("temp14", temp14) + .append("temp15", temp15) + .append("temp16", temp16) + .append("temp17", temp17) + .append("temp18", temp18) + .append("temp19", temp19) + .append("temp20", temp20) + .append("temp21", temp21) + .append("temp22", temp22) + .append("temp23", temp23) + .toString(); + } +} diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/WaterTemp.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/WaterTemp.java new file mode 100644 index 0000000..6d3969f --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/WaterTemp.java @@ -0,0 +1,117 @@ +package com.mh.common.core.domain.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.util.Date; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水温度 + * @date 2025-06-19 16:18:12 + */ +@Data +@TableName("water_temp") +public class WaterTemp { + + private String id; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date curDate; + + private String buildingId; + + private String buildingName; + + private String deviceNum; + + private String deviceName; + + private String temp00; + + private String temp01; + + private String temp02; + + private String temp03; + + private String temp04; + + private String temp05; + + private String temp06; + + private String temp07; + + private String temp08; + + private String temp09; + + private String temp10; + + private String temp11; + + private String temp12; + + private String temp13; + + private String temp14; + + private String temp15; + + private String temp16; + + private String temp17; + + private String temp18; + + private String temp19; + + private String temp20; + + private String temp21; + + private String temp22; + + private String temp23; + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("id", id) + .append("curDate", curDate) + .append("buildingId", buildingId) + .append("buildingName", buildingName) + .append("deviceNum", deviceNum) + .append("deviceName", deviceName) + .append("temp00", temp00) + .append("temp01", temp01) + .append("temp02", temp02) + .append("temp03", temp03) + .append("temp04", temp04) + .append("temp05", temp05) + .append("temp06", temp06) + .append("temp07", temp07) + .append("temp08", temp08) + .append("temp09", temp09) + .append("temp10", temp10) + .append("temp11", temp11) + .append("temp12", temp12) + .append("temp13", temp13) + .append("temp14", temp14) + .append("temp15", temp15) + .append("temp16", temp16) + .append("temp17", temp17) + .append("temp18", temp18) + .append("temp19", temp19) + .append("temp20", temp20) + .append("temp21", temp21) + .append("temp22", temp22) + .append("temp23", temp23) + .toString(); + } +} diff --git a/mh-quartz/src/main/java/com/mh/quartz/task/HotWaterTask.java b/mh-quartz/src/main/java/com/mh/quartz/task/HotWaterTask.java index 2882c24..480fb3c 100644 --- a/mh-quartz/src/main/java/com/mh/quartz/task/HotWaterTask.java +++ b/mh-quartz/src/main/java/com/mh/quartz/task/HotWaterTask.java @@ -1,10 +1,22 @@ package com.mh.quartz.task; +import com.mh.common.constant.EnergyType; +import com.mh.common.core.domain.entity.DataMonth; +import com.mh.common.utils.StringUtils; import com.mh.system.service.device.IDeviceLedgerService; +import com.mh.system.service.energy.IEnergyQueryService; +import com.mh.system.service.energy.IWaterLevelService; +import com.mh.system.service.energy.IWaterTempService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.stream.Collectors; + /** * @author LJF * @version 1.0 @@ -19,8 +31,47 @@ public class HotWaterTask { @Resource private IDeviceLedgerService deviceLedgerService; + @Resource + private IEnergyQueryService energyQueryService; + + @Resource + private IWaterTempService waterTempService; + + @Resource + private IWaterLevelService waterLevelService; + private boolean createOrUpdateDeviceState = false; + // 计算能耗表 + private boolean calcEnergyState = false; + + // 计算楼层能耗数据 + private boolean calcFloorEnergyState = false; + + // 计算热水温度状态 + private boolean calcWaterTempState = false; + + // 计算水箱水位 + private boolean calcWaterLevelState = false; + + /** + * 定时计算水箱水位,插入到存储表中 + */ + public void calcWaterLevel() { + try { + if (!calcWaterLevelState) { + calcWaterLevelState = true; + waterLevelService.calcWaterLevel(); + } + } catch (Exception e) { + log.error("计算水箱水位失败", e); + calcWaterLevelState = false; + } finally { + calcWaterLevelState = false; + } + + } + /** * 新增或者更新设备状态表 */ @@ -37,4 +88,177 @@ public class HotWaterTask { createOrUpdateDeviceState = false; } } + + /** + * 定时计算水温度,插入到存储表中 + */ + public void calcWaterTemp() { + try { + if (!calcWaterTempState) { + calcWaterTempState = true; + waterTempService.calcWaterTemp(); + } + } catch (Exception e) { + log.error("计算水温度失败", e); + calcWaterTempState = false; + } finally { + calcWaterTempState = false; + } + + } + + /** + * 定时计算楼层能耗数据 + * @param lastHourTime + */ + public void calcFloorEnergyData(String lastHourTime) { + try { + if (!calcFloorEnergyState) { + calcFloorEnergyState = true; + if (StringUtils.isEmpty(lastHourTime)) { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime lastHour = now.minusHours(1); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + lastHourTime = lastHour.format(formatter); + } + energyQueryService.calcFloorEnergyDataDetail(lastHourTime); + } + } catch (Exception e) { + log.error("计算楼层能耗数据失败", e); + calcFloorEnergyState = false; + } finally { + calcFloorEnergyState = false; + } + } + + /** + * 定时计算能耗数据任务 + * @param lastHourTime + */ + public void calcEnergyData(String lastHourTime) { + try { + if (!calcEnergyState) { + calcEnergyState = true; + calcEnergyDataDetail(lastHourTime); + } + } catch (Exception e) { + log.error("计算能耗表失败", e); + calcEnergyState = false; + } finally { + calcEnergyState = false; + } + } + /** + * 计算能耗表 + */ + public void calcEnergyDataDetail(String lastHourTime) { + //TODO 1、查询sql获取对应计算的楼层id、楼层名称用来当作楼栋id和楼栋名称 + List> floorInfos = energyQueryService.queryFloorInfo(); + // 开始遍历 + if (StringUtils.isEmpty(lastHourTime)) { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime lastHour = now.minusHours(1); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + lastHourTime = lastHour.format(formatter); + } + String tableName = "data_hour" + lastHourTime.substring(0, 4); + + List> hourList = new ArrayList<>(); + List> dayList = new ArrayList<>(); + List> monthList = new ArrayList<>(); + List> yearList = new ArrayList<>(); + + for (Map floorInfo : floorInfos) { + String buildingId = floorInfo.get("id").toString(); + String buildingName = floorInfo.get("building_name").toString(); + // 根据楼栋id查询对应楼层下的所有设备 + //TODO 2、计算每小时用电量、用水量、单耗(用电量/用水量) + Map hourMap = processEnergy(buildingId, buildingName, lastHourTime, tableName, "hour", EnergyType.HOUR); + if (null != hourMap) { + hourList.add(hourMap); + } + + //TODO 3、计算每日用用电量、用水量、单耗(用电量/用水量) + Map dayMap = processEnergy(buildingId, buildingName, lastHourTime, tableName, "day", EnergyType.DAY); + if (null != dayMap) { + dayList.add(dayMap); + } + + //TODO 4、计算月用电量、用水量、单耗(用电量/用水量) + Map monthMap = processEnergy(buildingId, buildingName, lastHourTime, tableName, "month", EnergyType.MONTH); + if (null != monthMap) { + monthList.add(monthMap); + } + + //TODO 5、计算年用电量、用水量、单耗(用电量/用水量) + Map yearMap = processEnergy(buildingId, buildingName, lastHourTime, tableName, "year", EnergyType.YEAR); + if (null != yearMap) { + yearList.add(yearMap); + } + + } + + // 更新插入所有楼栋的数据表 + processAndInsertEnergyData("hour", hourList, lastHourTime); + processAndInsertEnergyData("day", dayList, lastHourTime); + processAndInsertEnergyData("month", monthList, lastHourTime); + processAndInsertEnergyData("year", yearList, lastHourTime); + + } + + private void processAndInsertEnergyData(String timeUnit, List> dataList, String lastHourTime) { + if (dataList.isEmpty()) return; + + double electricity = 0.0; + double water = 0.0; + + for (Map map : dataList) { + electricity += map.getOrDefault("electricity", 0.0); + water += map.getOrDefault("water", 0.0); + } + + double specificConsumption = water > 0 ? electricity / water : 0.0; + energyQueryService.insertOrUpdateEnergyData(timeUnit, "所有", "所有", lastHourTime, electricity, water, specificConsumption); + } + + + private Map processEnergy(String buildingId, String buildingName, String curDate, String tableName, String dateType, EnergyType energyType) { + List datas = energyQueryService.queryEnergyDatas(tableName, buildingId, curDate, dateType); + Map result = new HashMap<>(); + double electricity = 0.0; + double water = 0.0; + double specificConsumption = 0.0; + if (datas == null || datas.isEmpty()) { + log.warn("未找到 {} 类型的能耗数据,buildingId={}, curDate={}", energyType, buildingId, curDate); + result.put("electricity", electricity); + result.put("water", water); + } else { + Map> grouped = datas.stream() + .collect(Collectors.groupingBy(DataMonth::getDeviceType)); + + electricity = grouped.getOrDefault("5", Collections.emptyList()).stream() + .mapToDouble(data -> Optional.ofNullable(data.getCalcValue()).map(BigDecimal::doubleValue).orElse(0.0)) + .sum(); + result.put("electricity", electricity); + + water = grouped.getOrDefault("23", Collections.emptyList()).stream() + .mapToDouble(data -> Optional.ofNullable(data.getCalcValue()).map(BigDecimal::doubleValue).orElse(0.0)) + .sum(); + result.put("water", water); + + + specificConsumption = water > 0 ? electricity / water : 0.0; + + log.info("楼栋: {}, {}电表总量: {}, 水表总量: {}, 单耗: {}", buildingName, energyType, electricity, water, specificConsumption); + } + energyQueryService.insertOrUpdateEnergyData( + energyType.getCode(), buildingId, buildingName, curDate, + electricity, + water, + specificConsumption + ); + + return result; + } + } diff --git a/mh-system/src/main/java/com/mh/system/mapper/device/DeviceStateMapper.java b/mh-system/src/main/java/com/mh/system/mapper/device/DeviceStateMapper.java index 1fe84fc..c6e651e 100644 --- a/mh-system/src/main/java/com/mh/system/mapper/device/DeviceStateMapper.java +++ b/mh-system/src/main/java/com/mh/system/mapper/device/DeviceStateMapper.java @@ -17,6 +17,6 @@ import java.util.List; @Mapper public interface DeviceStateMapper extends BaseMapper { - @Select("select * from device_state where system_type = #{systemType} and date(cur_date) = date(curdate()) limit 1") + @Select("select * from device_state where system_type = #{systemType} and date(cur_date) = date(now()) limit 1") List deviceState(String systemType); } diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/AnalysisMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/AnalysisMapper.java new file mode 100644 index 0000000..39b0f6f --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/AnalysisMapper.java @@ -0,0 +1,56 @@ +package com.mh.system.mapper.energy; + +import com.mh.common.core.domain.entity.AnalysisMonth; +import com.mh.common.core.domain.entity.AnalysisYear; +import org.apache.ibatis.annotations.*; + +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 用能分析 + * @date 2025-06-24 15:10:04 + */ +@Mapper +public interface AnalysisMapper { + + /** + * 分析查询 + * 根据日期、楼栋查询 + * @param curDate + * @param buildingId + * @return + */ + @Select("select * from analysis_elect_year where cur_date=#{curDate} and building_id=#{buildingId}") + List queryAnalysisElectYear(@Param("curDate") String curDate, @Param("buildingId") String buildingId); + + @Select("select * from analysis_Water_year where cur_date=#{curDate} and building_id=#{buildingId}") + List queryAnalysisWaterYear(@Param("curDate") String curDate, @Param("buildingId") String buildingId); + + @Select("select * from analysis_Energy_year where cur_date=#{curDate} and building_id=#{buildingId}") + List queryAnalysisEnergyYear(@Param("curDate") String curDate, @Param("buildingId") String buildingId); + + @Select("select * from analysis_Maintain_year where cur_date=#{curDate} and building_id=#{buildingId}") + List queryAnalysisMaintainYear(@Param("curDate") String curDate, @Param("buildingId") String buildingId); + + @Select("select * from analysis_runtime_year where cur_date=#{curDate} and building_id=#{buildingId}") + List queryAnalysisRuntimeYear(@Param("curDate") String curDate, @Param("buildingId") String buildingId); + + @Select("select * from analysis_elect_month where cur_date=#{curDate} and building_id=#{buildingId}") + List queryAnalysisElectMonth(@Param("curDate") String curDate, @Param("buildingId") String buildingId); + + @Select("select * from analysis_Water_month where cur_date=#{curDate} and building_id=#{buildingId}") + List queryAnalysisWaterMonth(@Param("curDate") String curDate, @Param("buildingId") String buildingId); + + @Select("select * from analysis_Energy_month where cur_date=#{curDate} and building_id=#{buildingId}") + List queryAnalysisEnergyMonth(@Param("curDate") String curDate, @Param("buildingId") String buildingId); + + @Select("select * from analysis_maintain_month where cur_date=#{curDate} and building_id=#{buildingId}") + List queryAnalysisMaintainMonth(@Param("curDate") String curDate, @Param("buildingId") String buildingId); + + @Select("select * from analysis_runtime_month where cur_date=#{curDate} and building_id=#{buildingId}") + List queryAnalysisRuntimeMonth(@Param("curDate") String curDate, @Param("buildingId") String buildingId); + +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyDayMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyDayMapper.java new file mode 100644 index 0000000..4abeb00 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyDayMapper.java @@ -0,0 +1,28 @@ +package com.mh.system.mapper.energy; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.common.core.domain.entity.EnergyDay; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.apache.poi.ss.formula.functions.T; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水小时 + * @date 2025-06-18 15:37:04 + */ +@Mapper +public interface EnergyDayMapper extends BaseMapper { + + @Update("update energy_day set elect_value = #{electricity}, use_hot_water = #{water}, elect_water = #{consumption} where building_id = #{buildingId} and cur_date = #{curDate}") + void updateByOther(String buildingId, String curDate, BigDecimal electricity, BigDecimal water, BigDecimal consumption); + + @Select("select * from energy_day where building_id = #{buildingId} and cur_date >= #{startDate} and cur_date <= #{endDate} order by cur_date desc ") + List queryEnergyDay(String buildingId, String startDate, String endDate); +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyDaySumMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyDaySumMapper.java new file mode 100644 index 0000000..12a8b92 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyDaySumMapper.java @@ -0,0 +1,22 @@ +package com.mh.system.mapper.energy; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.common.core.domain.entity.EnergyDaySum; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水小时 + * @date 2025-06-18 15:37:04 + */ +@Mapper +public interface EnergyDaySumMapper extends BaseMapper { + + @Select("select * from energy_day_sum where building_id = #{buildingId} and cur_date = #{startDate} ") + List queryEnergyDaySum(String buildingId, String startDate); +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyHourMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyHourMapper.java new file mode 100644 index 0000000..cbe24f0 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyHourMapper.java @@ -0,0 +1,27 @@ +package com.mh.system.mapper.energy; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.common.core.domain.entity.EnergyHour; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水小时 + * @date 2025-06-18 15:37:04 + */ +@Mapper +public interface EnergyHourMapper extends BaseMapper { + + @Update("update energy_hour set elect_value = #{electricity}, use_hot_water = #{water}, elect_water = #{consumption} where building_id = #{buildingId} and cur_date = #{curDate}") + void updateByOther(String buildingId, String curDate, BigDecimal electricity, BigDecimal water, BigDecimal consumption); + + @Select("select * from energy_hour where building_id = #{buildingId} and cur_date >= #{startDate} and cur_date <= #{endDate} order by cur_date desc ") + List queryEnergyHour(String buildingId, String startDate, String endDate); +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMonthMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMonthMapper.java new file mode 100644 index 0000000..ce15ece --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMonthMapper.java @@ -0,0 +1,28 @@ +package com.mh.system.mapper.energy; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.common.core.domain.entity.EnergyMonth; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.apache.poi.ss.formula.functions.T; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水小时 + * @date 2025-06-18 15:37:04 + */ +@Mapper +public interface EnergyMonthMapper extends BaseMapper { + + @Update("update energy_month set elect_value = #{electricity}, use_hot_water = #{water}, elect_water = #{consumption} where building_id = #{buildingId} and cur_date = #{curDate}") + void updateByOther(String buildingId, String curDate, BigDecimal electricity, BigDecimal water, BigDecimal consumption); + + @Select("select * from energy_month where building_id = #{buildingId} and cur_date >= #{startDate} and cur_date <= #{endDate} order by cur_date desc ") + List queryEnergyMonth(String buildingId, String startDate, String endDate); +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMonthSumMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMonthSumMapper.java new file mode 100644 index 0000000..8822b0a --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMonthSumMapper.java @@ -0,0 +1,23 @@ +package com.mh.system.mapper.energy; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.common.core.domain.entity.EnergyMonthSum; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水小时 + * @date 2025-06-18 15:37:04 + */ +@Mapper +public interface EnergyMonthSumMapper extends BaseMapper { + + @Select("select * from energy_month_sum where building_id = #{buildingId} and cur_date = #{startDate} ") + List queryEnergyMonthSum(String buildingId, String startDate); + +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyYearMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyYearMapper.java new file mode 100644 index 0000000..40a9bed --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyYearMapper.java @@ -0,0 +1,27 @@ +package com.mh.system.mapper.energy; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.common.core.domain.entity.EnergyYear; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水小时 + * @date 2025-06-18 15:37:04 + */ +@Mapper +public interface EnergyYearMapper extends BaseMapper { + + @Update("update energy_year set elect_value = #{electricity}, use_hot_water = #{water}, elect_water = #{consumption} where building_id = #{buildingId} and cur_date = #{curDate}") + void updateByOther(String buildingId, String curDate, BigDecimal electricity, BigDecimal water, BigDecimal consumption); + + @Select("select * from energy_year where building_id = #{buildingId} and cur_date >= #{startDate} and cur_date <= #{endDate} order by cur_date desc ") + List queryEnergyYear(String buildingId, String startDate, String endDate); +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyYearSumMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyYearSumMapper.java new file mode 100644 index 0000000..542251e --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/EnergyYearSumMapper.java @@ -0,0 +1,24 @@ +package com.mh.system.mapper.energy; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.common.core.domain.entity.EnergyMonthSum; +import com.mh.common.core.domain.entity.EnergyYearSum; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水小时 + * @date 2025-06-18 15:37:04 + */ +@Mapper +public interface EnergyYearSumMapper extends BaseMapper { + + @Select("select * from energy_year_sum where building_id = #{buildingId} and cur_date = #{startDate} ") + List queryEnergyYearSum(String buildingId, String startDate); + +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/HotEnergyQueryMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/HotEnergyQueryMapper.java new file mode 100644 index 0000000..012fbf9 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/HotEnergyQueryMapper.java @@ -0,0 +1,118 @@ +package com.mh.system.mapper.energy; + +import com.mh.common.core.domain.dto.DataResultDTO; +import com.mh.common.core.domain.entity.DataMonth; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; +import java.util.Map; + +/** + * @author LJF + * @version 1.0 + * @project NewZhujiang_Server + * @description 热水能耗查询 + * @date 2023-12-13 16:00:01 + */ +@Mapper +public interface HotEnergyQueryMapper { + + @Select("select " + + " t1.id, SUBSTRING(t1.floor_name FROM '(-?\\d+楼)') as building_name " + + "from " + + " ( " + + " select " + + " distinct fi.id,fi.floor_name " + + " from " + + " floor_info fi " + + " join " + + "building_info bi " + + "on " + + " fi.building_id = bi.id " + + " join area_info ai on " + + " bi.area_id = ai.id " + + " where " + + " ai.system_type = '1' " + + " ) t1 " + + "join cpm_space_relation csr on " + + " csr.floor_id = t1.id " + + "where " + + " csr.house_id = '' " + + "group by " + + " t1.id,t1.floor_name order by building_name") + List> queryFloorInfo(); + + @Select("") + List queryEnergyDatas(@Param("tableName") String tableName, + @Param("buildingId") String buildingId, + @Param("lastHour") String lastHourTime, + @Param("dateType") String dateType); + + @Select("select count(1) from ${tableName} where building_id = #{buildingId} and cur_date = #{curDate}") + int haveRecord(String tableName, String buildingId, String curDate); + + @Select("SELECT pro_energy_sum(#{lastHourTime}); ") + Map calcFloorEnergyDataDetail(@Param("lastHourTime") String lastHourTime); + + @Select("") + List queryDeviceDatas(@Param("buildingId") String buildingId, + @Param("startDate") String startDate, + @Param("endDate") String endDate, + @Param("deviceType") String deviceType, + @Param("tableName") String tableName); +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/WaterLevelMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/WaterLevelMapper.java new file mode 100644 index 0000000..44c256d --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/WaterLevelMapper.java @@ -0,0 +1,102 @@ +package com.mh.system.mapper.energy; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.common.core.domain.entity.WaterLevel; +import org.apache.ibatis.annotations.*; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水温度记录 + * @date 2025-06-19 16:24:31 + */ +@Mapper +public interface WaterLevelMapper extends BaseMapper { + + + @Select("select " + + " t1.*, " + + " csr.floor_id " + + "from " + + " ( " + + " select " + + " cpm.id, " + + " cpm.cur_value, " + + " cpm.cur_time, " + + " cpm.mt_num, " + + " dl.device_name " + + " from " + + " collection_params_manage cpm " + + " join device_ledger dl on " + + " cpm.device_ledger_id = dl.id " + + " where " + + " dl.system_type = '1' " + + " and device_type = '16' " + + " and cpm.param_type = '11' " + + " ) t1 " + + "join cpm_space_relation csr on " + + " t1.id = csr.cpm_id " + + "where " + + " csr.house_id = '' " + + "order by " + + " t1.device_name ") + List> getNowWaterLevel(); + + @Select("select count(1) from water_level where date(cur_date) = date(#{date}::timestamp) and building_id = #{buildingId} and device_num = #{pumpId}") + int isExits(@Param("date") String date, + @Param("buildingId") String buildingId, + @Param("pumpId") String pumpId); + + @Insert("insert into water_level(cur_date,building_id,device_num,device_name, ${tempTime}) values(#{date}::timestamp,#{buildingId},#{pumpId},#{pumpName},#{curValue})") + void insertWaterLevel(String date, String buildingId, String pumpId, String pumpName, BigDecimal curValue, String tempTime); + + @Update("update water_level set ${tempTime} = #{curValue} where date(cur_date) = date(#{date}::timestamp) and building_id = #{buildingId} and device_num = #{pumpId}") + void updateWaterLevel(String date, String buildingId, String pumpId, String pumpName, BigDecimal curValue, String tempTime); + + @Select("select " + + " wt.building_id, " + + " SUBSTRING(fi.floor_name FROM '(-?\\d+楼)') as building_name, " + + " ROUND(avg(temp00::numeric(24, 1)),1) as temp00, " + + " ROUND(avg(temp01::numeric(24, 1)),1) as temp01, " + + " ROUND(avg(temp02::numeric(24, 1)),1) as temp02, " + + " ROUND(avg(temp03::numeric(24, 1)),1) as temp03, " + + " ROUND(avg(temp04::numeric(24, 1)),1) as temp04, " + + " ROUND(avg(temp05::numeric(24, 1)),1) as temp05, " + + " ROUND(avg(temp06::numeric(24, 1)),1) as temp06, " + + " ROUND(avg(temp07::numeric(24, 1)),1) as temp07, " + + " ROUND(avg(temp08::numeric(24, 1)),1) as temp08, " + + " ROUND(avg(temp09::numeric(24, 1)),1) as temp09, " + + " ROUND(avg(temp10::numeric(24, 1)),1) as temp10, " + + " ROUND(avg(temp11::numeric(24, 1)),1) as temp11, " + + " ROUND(avg(temp12::numeric(24, 1)),1) as temp12, " + + " ROUND(avg(temp13::numeric(24, 1)),1) as temp13, " + + " ROUND(avg(temp14::numeric(24, 1)),1) as temp14, " + + " ROUND(avg(temp15::numeric(24, 1)),1) as temp15, " + + " ROUND(avg(temp16::numeric(24, 1)),1) as temp16, " + + " ROUND(avg(temp17::numeric(24, 1)),1) as temp17, " + + " ROUND(avg(temp18::numeric(24, 1)),1) as temp18, " + + " ROUND(avg(temp19::numeric(24, 1)),1) as temp19, " + + " ROUND(avg(temp20::numeric(24, 1)),1) as temp20, " + + " ROUND(avg(temp21::numeric(24, 1)),1) as temp21, " + + " ROUND(avg(temp22::numeric(24, 1)),1) as temp22, " + + " ROUND(avg(temp23::numeric(24, 1)),1) as temp23 " + + "from " + + " water_level wt " + + "join floor_info fi on wt.building_id = fi.id " + + "where " + + " date(wt.cur_date) = date(#{curDate}) " + + "group by " + + " wt.building_id, fi.floor_name " + + "order by SUBSTRING(fi.floor_name FROM '(-?\\d)') ") + List queryAvgWaterTemp(String curDate); + + @Select("select wt.*, SUBSTRING(fi.floor_name FROM '(-?\\d+楼)') as building_name from water_level wt " + + " join floor_info fi on wt.building_id = fi.id " + + " where wt.building_id = #{buildingId} and date(wt.cur_date) = date(#{curDate}) order by wt.device_name ") + List queryWaterTemp(String buildingId, String curDate); +} diff --git a/mh-system/src/main/java/com/mh/system/mapper/energy/WaterTempMapper.java b/mh-system/src/main/java/com/mh/system/mapper/energy/WaterTempMapper.java new file mode 100644 index 0000000..d653f20 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/energy/WaterTempMapper.java @@ -0,0 +1,103 @@ +package com.mh.system.mapper.energy; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.common.core.domain.entity.WaterTemp; +import org.apache.ibatis.annotations.*; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水温度记录 + * @date 2025-06-19 16:24:31 + */ +@Mapper +public interface WaterTempMapper extends BaseMapper { + + + @Select("select " + + " t1.*, " + + " csr.floor_id, " + + " csr.house_id " + + "from " + + " ( " + + " select " + + " cpm.id, " + + " cpm.cur_value, " + + " cpm.cur_time, " + + " cpm.mt_num, " + + " dl.device_name " + + " from " + + " collection_params_manage cpm " + + " join device_ledger dl on " + + " cpm.device_ledger_id = dl.id " + + " where " + + " dl.system_type = '1' " + + " and dl.device_type = '11' " + + " and cpm.param_type = '12' " + + " ) t1 " + + "join cpm_space_relation csr on " + + " t1.id = csr.cpm_id " + + "where " + + " csr.house_id = '' " + + "order by " + + " t1.device_name ") + List> getNowWaterTemp(); + + @Select("select count(1) from water_temp where date(cur_date) = date(#{date}::timestamp) and building_id = #{buildingId} and device_num = #{pumpId}") + int isExits(@Param("date") String date, + @Param("buildingId") String buildingId, + @Param("pumpId") String pumpId); + + @Insert("insert into water_temp(cur_date,building_id, device_num, device_name, ${tempTime}) values(#{date}::timestamp,#{buildingId},#{pumpId},#{pumpName},#{curValue})") + void insertWaterTemp(String date, String buildingId, String pumpId, String pumpName, BigDecimal curValue, String tempTime); + + @Update("update water_temp set ${tempTime} = #{curValue} where date(cur_date) = date(#{date}::timestamp) and building_id = #{buildingId} and device_num = #{pumpId}") + void updateWaterTemp(String date, String buildingId, String pumpId, String pumpName, BigDecimal curValue, String tempTime); + + @Select("select " + + " wt.building_id, " + + " SUBSTRING(fi.floor_name FROM '(-?\\d+楼)') as building_name, " + + " ROUND(avg(temp00::numeric(24, 1)),1) as temp00, " + + " ROUND(avg(temp01::numeric(24, 1)),1) as temp01, " + + " ROUND(avg(temp02::numeric(24, 1)),1) as temp02, " + + " ROUND(avg(temp03::numeric(24, 1)),1) as temp03, " + + " ROUND(avg(temp04::numeric(24, 1)),1) as temp04, " + + " ROUND(avg(temp05::numeric(24, 1)),1) as temp05, " + + " ROUND(avg(temp06::numeric(24, 1)),1) as temp06, " + + " ROUND(avg(temp07::numeric(24, 1)),1) as temp07, " + + " ROUND(avg(temp08::numeric(24, 1)),1) as temp08, " + + " ROUND(avg(temp09::numeric(24, 1)),1) as temp09, " + + " ROUND(avg(temp10::numeric(24, 1)),1) as temp10, " + + " ROUND(avg(temp11::numeric(24, 1)),1) as temp11, " + + " ROUND(avg(temp12::numeric(24, 1)),1) as temp12, " + + " ROUND(avg(temp13::numeric(24, 1)),1) as temp13, " + + " ROUND(avg(temp14::numeric(24, 1)),1) as temp14, " + + " ROUND(avg(temp15::numeric(24, 1)),1) as temp15, " + + " ROUND(avg(temp16::numeric(24, 1)),1) as temp16, " + + " ROUND(avg(temp17::numeric(24, 1)),1) as temp17, " + + " ROUND(avg(temp18::numeric(24, 1)),1) as temp18, " + + " ROUND(avg(temp19::numeric(24, 1)),1) as temp19, " + + " ROUND(avg(temp20::numeric(24, 1)),1) as temp20, " + + " ROUND(avg(temp21::numeric(24, 1)),1) as temp21, " + + " ROUND(avg(temp22::numeric(24, 1)),1) as temp22, " + + " ROUND(avg(temp23::numeric(24, 1)),1) as temp23 " + + "from " + + " water_temp wt " + + "join floor_info fi on wt.building_id = fi.id " + + "where " + + " date(wt.cur_date) = date(#{curDate}) " + + "group by " + + " wt.building_id, fi.floor_name " + + "order by SUBSTRING(fi.floor_name FROM '(-?\\d)') ") + List queryAvgWaterTemp(String curDate); + + @Select("select wt.*, SUBSTRING(fi.floor_name FROM '(-?\\d+楼)') as building_name from water_temp wt " + + " join floor_info fi on wt.building_id = fi.id " + + " where wt.building_id = #{buildingId} and date(wt.cur_date) = date(#{curDate}) order by wt.device_name ") + List queryWaterTemp(String buildingId, String curDate); +} diff --git a/mh-system/src/main/java/com/mh/system/service/energy/IEnergyQueryService.java b/mh-system/src/main/java/com/mh/system/service/energy/IEnergyQueryService.java index 31a8dbb..57d6880 100644 --- a/mh-system/src/main/java/com/mh/system/service/energy/IEnergyQueryService.java +++ b/mh-system/src/main/java/com/mh/system/service/energy/IEnergyQueryService.java @@ -1,7 +1,14 @@ package com.mh.system.service.energy; import com.mh.common.core.domain.AjaxResult; +import com.mh.common.core.domain.entity.DataMonth; +import com.mh.common.core.domain.entity.WaterLevel; +import com.mh.common.core.domain.entity.WaterTemp; import com.mh.common.core.domain.vo.EnergyQueryVO; +import org.apache.poi.ss.formula.functions.T; + +import java.util.List; +import java.util.Map; /** * @author LJF @@ -20,4 +27,29 @@ public interface IEnergyQueryService { AjaxResult sysQuery(EnergyQueryVO page); AjaxResult deviceTypeQuery(EnergyQueryVO page); + + List> queryFloorInfo(); + + List queryEnergyDatas(String tableName, String buildingId, String lastHourTime, String dateType); + + int haveRecord(String buildingId, String lastHourTime, String dateType); + + void insertOrUpdateEnergyData(String hour, String buildingId, String buildingName, String lastHourTime, double totalElectricity, double totalWater, double specificConsumption); + + List queryEnergyDataList(String buildingId, String startDate, String endDate, int type); + + List queryEnergyDataSumList(String buildingId, String curDate, Integer type); + + void calcFloorEnergyDataDetail(String lastHourTime); + + List queryWaterTemp(String buildingId, String curDate); + + List queryWaterLevel(String buildingId, String curDate); + + List queryDeviceDatas(String buildingId, String startDate, String endDate, String deviceType); + + List queryAnalysisYear(String curDate, String buildingId, int type); + + List queryAnalysisMonth(String curDate, String buildingId, int type); + } diff --git a/mh-system/src/main/java/com/mh/system/service/energy/IWaterLevelService.java b/mh-system/src/main/java/com/mh/system/service/energy/IWaterLevelService.java new file mode 100644 index 0000000..8a6d03f --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/energy/IWaterLevelService.java @@ -0,0 +1,14 @@ +package com.mh.system.service.energy; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水温度服务类 + * @date 2025-06-19 16:26:10 + */ +public interface IWaterLevelService { + + void calcWaterLevel(); + +} diff --git a/mh-system/src/main/java/com/mh/system/service/energy/IWaterTempService.java b/mh-system/src/main/java/com/mh/system/service/energy/IWaterTempService.java new file mode 100644 index 0000000..32836fa --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/energy/IWaterTempService.java @@ -0,0 +1,14 @@ +package com.mh.system.service.energy; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水温度服务类 + * @date 2025-06-19 16:26:10 + */ +public interface IWaterTempService { + + void calcWaterTemp(); + +} 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 e4e5a5e..0067bda 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 @@ -1,16 +1,21 @@ package com.mh.system.service.energy.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.mh.common.core.domain.AjaxResult; -import com.mh.common.core.domain.entity.ConsumptionAnalyze; +import com.mh.common.core.domain.entity.*; import com.mh.common.core.domain.vo.EnergyQueryVO; import com.mh.common.utils.DateUtils; +import com.mh.common.utils.StringUtils; import com.mh.system.mapper.device.CollectionParamsManageMapper; -import com.mh.system.mapper.energy.EnergyQueryMapper; +import com.mh.system.mapper.energy.*; import com.mh.system.service.energy.IEnergyQueryService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.formula.functions.T; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.math.BigDecimal; import java.util.*; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -29,9 +34,135 @@ public class EnergyQueryServiceImpl implements IEnergyQueryService { @Resource private EnergyQueryMapper energyQueryMapper; + @Resource + private HotEnergyQueryMapper hotEnergyQueryMapper; + @Resource private CollectionParamsManageMapper collectionParamsManageMapper; + @Resource + private EnergyHourMapper energyHourMapper; + + @Resource + private EnergyDayMapper energyDayMapper; + + @Resource + private EnergyMonthMapper energyMonthMapper; + + @Resource + private EnergyYearMapper energyYearMapper; + + @Resource + private EnergyDaySumMapper energyDaySumMapper; + + @Resource + private EnergyMonthSumMapper energyMonthSumMapper; + + @Resource + private EnergyYearSumMapper energyYearSumMapper; + + @Resource + private WaterTempMapper waterTempMapper; + + @Resource + private WaterLevelMapper waterLevelMapper; + + @Resource + AnalysisMapper analysisMapper; + + @Override + public List queryAnalysisYear(String curDate, String buildingId, int type) { + if (type==1){ + return analysisMapper.queryAnalysisWaterYear(curDate,buildingId); + }else if (type==2){ + return analysisMapper.queryAnalysisElectYear(curDate,buildingId); + }else if(type==3){ + return analysisMapper.queryAnalysisEnergyYear(curDate,buildingId); + }else if (type==4){ + return analysisMapper.queryAnalysisMaintainYear(curDate,buildingId); + } else { + return analysisMapper.queryAnalysisRuntimeYear(curDate,buildingId); + } + } + + @Override + public List queryAnalysisMonth(String curDate, String buildingId, int type) { + if (type==1){ + return analysisMapper.queryAnalysisWaterMonth(curDate,buildingId); + }else if (type==2){ + return analysisMapper.queryAnalysisElectMonth(curDate,buildingId); + }else if (type==3){ + return analysisMapper.queryAnalysisEnergyMonth(curDate,buildingId); + }else if (type==4){ + return analysisMapper.queryAnalysisMaintainMonth(curDate,buildingId); + } else { + return analysisMapper.queryAnalysisRuntimeMonth(curDate,buildingId); + } + } + + @Override + public List queryDeviceDatas(String buildingId, String startDate, String endDate, String deviceType) { + if (StringUtils.isEmpty(buildingId)) { + return List.of(); + } + String tableName = "data_min" + startDate.substring(0, 4); + return hotEnergyQueryMapper.queryDeviceDatas(buildingId, startDate, endDate, deviceType, tableName); + } + + @Override + public List queryWaterLevel(String buildingId, String curDate) { + if (StringUtils.isEmpty(buildingId) || buildingId.equals("所有")) { + // 返回所有楼栋的平均值 + return waterLevelMapper.queryAvgWaterTemp(curDate); + } + return waterLevelMapper.queryWaterTemp(buildingId, curDate); + } + + @Override + public List queryWaterTemp(String buildingId, String curDate) { + if (StringUtils.isEmpty(buildingId) || buildingId.equals("所有")) { + // 返回所有楼栋的平均值 + return waterTempMapper.queryAvgWaterTemp(curDate); + } + return waterTempMapper.queryWaterTemp(buildingId, curDate); + } + + @Override + public void calcFloorEnergyDataDetail(String lastHourTime) { + hotEnergyQueryMapper.calcFloorEnergyDataDetail(lastHourTime); + } + + @Override + public List queryEnergyDataSumList(String buildingId, String curDate, Integer type) { + if (StringUtils.isEmpty(buildingId)) { + return List.of(); + } + if (type==1){ + return energyDaySumMapper.queryEnergyDaySum(buildingId,curDate); //日 + }else if (type==2){ + return energyMonthSumMapper.queryEnergyMonthSum(buildingId,curDate); //月 + }else { + return energyYearSumMapper.queryEnergyYearSum(buildingId,curDate); //年 + } + } + + @Override + public List queryEnergyDataList(String buildingId, String startDate, String endDate, int type) { + if (StringUtils.isEmpty(buildingId)) { + return List.of(); + } + if (type == 0) { + return energyHourMapper.queryEnergyHour(buildingId,startDate,endDate); + } else if(type==1) { + return energyDayMapper.queryEnergyDay(buildingId,startDate,endDate); + } else if (type==2){ + return energyMonthMapper.queryEnergyMonth(buildingId,startDate,endDate); + } else if (type==3){ + return energyYearMapper.queryEnergyYear(buildingId,startDate,endDate); + } + return null; + } + @Override public AjaxResult sysQuery(EnergyQueryVO vo) { DateUtils.sysEnergyDateChange(vo); @@ -92,10 +223,10 @@ public class EnergyQueryServiceImpl implements IEnergyQueryService { try { double cold = Math.round(Double.parseDouble(coldArr[i]) * 100) / 100.0; double meter = Math.round(Double.parseDouble(meterArr[i]) * 100) / 100.0; - double cop = Math.round((meter==0 ? 0.00 : cold/ meter) * 100) / 100.0; + double cop = Math.round((meter == 0 ? 0.00 : cold / meter) * 100) / 100.0; copArr[i] = String.valueOf(cop); } catch (NumberFormatException e) { - log.error("处理累计能耗异常==>",e); + log.error("处理累计能耗异常==>", e); throw new RuntimeException(e); } } @@ -109,15 +240,15 @@ public class EnergyQueryServiceImpl implements IEnergyQueryService { map.put("copArr", copArr); map.put("timeStrArr", timeStrArr); } else { - int startIndex = (pageNum-1)*pageSize; + int startIndex = (pageNum - 1) * pageSize; int endIndex = Math.min(pageNum * pageSize, coldArr.length); if (startIndex > endIndex) { return AjaxResult.success(); } - map.put("coldArr", Arrays.copyOfRange(coldArr, startIndex , endIndex)); - map.put("meterArr", Arrays.copyOfRange(meterArr, startIndex , endIndex)); - map.put("copArr", Arrays.copyOfRange(copArr, startIndex , endIndex)); - map.put("timeStrArr", Arrays.copyOfRange(timeStrArr, startIndex , endIndex)); + map.put("coldArr", Arrays.copyOfRange(coldArr, startIndex, endIndex)); + map.put("meterArr", Arrays.copyOfRange(meterArr, startIndex, endIndex)); + map.put("copArr", Arrays.copyOfRange(copArr, startIndex, endIndex)); + map.put("timeStrArr", Arrays.copyOfRange(timeStrArr, startIndex, endIndex)); } // 组装赋值 @@ -159,4 +290,117 @@ public class EnergyQueryServiceImpl implements IEnergyQueryService { public AjaxResult deviceTypeQuery(EnergyQueryVO page) { return null; } + + @Override + public List> queryFloorInfo() { + return hotEnergyQueryMapper.queryFloorInfo(); + } + + @Override + public List queryEnergyDatas(String tableName, String buildingId, String lastHourTime, String dateType) { + return hotEnergyQueryMapper.queryEnergyDatas(tableName, buildingId, lastHourTime, dateType); + } + + @Override + public int haveRecord(String buildingId, String lastHourTime, String dateType) { + String tableName = "energy_hour"; + switch (dateType) { + case "hour": + tableName = "energy_hour"; + break; + case "day": + tableName = "energy_day"; + break; + case "month": + tableName = "energy_month"; + break; + case "year": + tableName = "energy_year"; + break; + default: + break; + } + return hotEnergyQueryMapper.haveRecord(tableName, buildingId, lastHourTime); + } + + @Override + public void insertOrUpdateEnergyData(String dateType, String buildingId, String buildingName, String curDate, + double totalElectricity, double totalWater, double specificConsumption) { + // 统一转换为 BigDecimal + BigDecimal electricity = BigDecimal.valueOf(totalElectricity); + BigDecimal water = BigDecimal.valueOf(totalWater); + BigDecimal consumption = BigDecimal.valueOf(specificConsumption); + + int count = 0; + switch (dateType) { + case "hour": + curDate = curDate.substring(0, 13); + count = haveRecord(buildingId, curDate, dateType); + if (count > 0) { + energyHourMapper.updateByOther(buildingId, curDate, electricity, water, consumption); + } else { + EnergyHour energyHour = new EnergyHour(); + energyHour.setCurDate(curDate); + energyHour.setBuildingId(buildingId); + energyHour.setBuildingName(buildingName); + energyHour.setUseHotWater(water); + energyHour.setElectValue(electricity); + energyHour.setElectWater(consumption); + energyHourMapper.insert(energyHour); + } + break; + case "day": + curDate = curDate.substring(0, 10); + count = haveRecord(buildingId, curDate, dateType); + if (count > 0) { + energyDayMapper.updateByOther(buildingId, curDate, electricity, water, consumption); + } else { + EnergyDay energyDay = new EnergyDay(); + energyDay.setCurDate(curDate); + energyDay.setBuildingId(buildingId); + energyDay.setBuildingName(buildingName); + energyDay.setUseHotWater(water); + energyDay.setElectValue(electricity); + energyDay.setElectWater(consumption); + energyDayMapper.insert(energyDay); + } + break; + case "month": + curDate = curDate.substring(0, 7); + count = haveRecord(buildingId, curDate, dateType); + if (count > 0) { + energyMonthMapper.updateByOther(buildingId, curDate, electricity, water, consumption); + } else { + EnergyMonth energyMonth = new EnergyMonth(); + energyMonth.setCurDate(curDate); + energyMonth.setBuildingId(buildingId); + energyMonth.setBuildingName(buildingName); + energyMonth.setUseHotWater(water); + energyMonth.setElectValue(electricity); + energyMonth.setElectWater(consumption); + energyMonthMapper.insert(energyMonth); + } + break; + case "year": + curDate = curDate.substring(0, 4); + count = haveRecord(buildingId, curDate, dateType); + if (count > 0) { + energyYearMapper.updateByOther(buildingId, curDate, electricity, water, consumption); + } else { + EnergyYear energyYear = new EnergyYear(); + energyYear.setCurDate(curDate); + energyYear.setBuildingId(buildingId); + energyYear.setBuildingName(buildingName); + energyYear.setUseHotWater(water); + energyYear.setElectValue(electricity); + energyYear.setElectWater(consumption); + energyYearMapper.insert(energyYear); + } + break; + default: + log.warn("未知的时间类型: {}", dateType); + } + } + + } diff --git a/mh-system/src/main/java/com/mh/system/service/energy/impl/WaterLevelServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/energy/impl/WaterLevelServiceImpl.java new file mode 100644 index 0000000..7d2cd7b --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/energy/impl/WaterLevelServiceImpl.java @@ -0,0 +1,60 @@ +package com.mh.system.service.energy.impl; + +import com.mh.system.mapper.energy.WaterLevelMapper; +import com.mh.system.mapper.energy.WaterTempMapper; +import com.mh.system.service.energy.IWaterLevelService; +import com.mh.system.service.energy.IWaterTempService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水温度服务类实现类 + * @date 2025-06-19 16:26:36 + */ +@Service +public class WaterLevelServiceImpl implements IWaterLevelService { + + @Resource + private WaterLevelMapper waterLevelMapper; + + @Override + public void calcWaterLevel() { + // todo 1、获取到多少个水箱,以及水位对应的实时水位 + // todo 2、根据对应的水箱id查询水箱对应的液位 + // todo 3、再根据绑定关系表查询到热泵对应的楼层id + List> list = waterLevelMapper.getNowWaterLevel(); + // 开始遍历数据 + for (Map map : list) { + // todo 5、拼接sql语句,插入到存储表中(id,楼栋id,水箱id,水箱名称,temp00至temp23) + String cpmId = map.get("id").toString(); + BigDecimal curValue = new BigDecimal(map.get("cur_value").toString()).setScale(1, BigDecimal.ROUND_HALF_UP); + String buildingId = map.get("floor_id").toString(); + String pumpId = map.get("mt_num").toString(); + String pumpName = map.get("device_name").toString(); + String curDate = map.get("cur_time").toString(); + + String tempTime = "temp" + curDate.substring(11, 13); + + // 格式化时间 + String date = curDate.substring(0,10) + " 00:00:00"; + // 判断是否存在值 + int count = waterLevelMapper.isExits(date, buildingId, pumpId); + + if (count == 0) { + // todo 6、插入数据 + waterLevelMapper.insertWaterLevel(date, buildingId, pumpId, pumpName, curValue, tempTime); + } else { + // todo 7、更新数据 + waterLevelMapper.updateWaterLevel(date, buildingId, pumpId, pumpName, curValue, tempTime); + } + } + } + +} diff --git a/mh-system/src/main/java/com/mh/system/service/energy/impl/WaterTempServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/energy/impl/WaterTempServiceImpl.java new file mode 100644 index 0000000..a7abbf7 --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/service/energy/impl/WaterTempServiceImpl.java @@ -0,0 +1,60 @@ +package com.mh.system.service.energy.impl; + +import com.mh.common.utils.DateUtils; +import com.mh.system.mapper.energy.WaterTempMapper; +import com.mh.system.service.energy.IWaterTempService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 热水温度服务类实现类 + * @date 2025-06-19 16:26:36 + */ +@Service +public class WaterTempServiceImpl implements IWaterTempService { + + @Resource + private WaterTempMapper waterTempMapper; + + @Override + public void calcWaterTemp() { + // todo 1、获取到多少个热泵,以及热泵对应的实时温度 + // todo 2、根据热泵id查询热泵对应的实时温度 + // todo 3、再根据绑定关系表查询到热泵对应的楼层id + List> list = waterTempMapper.getNowWaterTemp(); + // 开始遍历数据 + for (Map map : list) { + // todo 5、拼接sql语句,插入到存储表中(id,楼栋id,热泵采集id,热泵名称,temp00至temp23) + String cpmId = map.get("id").toString(); + BigDecimal curValue = new BigDecimal(map.get("cur_value").toString()).setScale(1, BigDecimal.ROUND_HALF_UP); + String buildingId = map.get("floor_id").toString(); + String pumpId = map.get("mt_num").toString(); + String pumpName = map.get("device_name").toString(); + String curDate = map.get("cur_time").toString(); + + String tempTime = "temp" + curDate.substring(11, 13); + + // 格式化时间 + String date = curDate.substring(0,10) + " 00:00:00"; + // 判断是否存在值 + int count = waterTempMapper.isExits(date, buildingId, pumpId); + + if (count == 0) { + // todo 6、插入数据 + waterTempMapper.insertWaterTemp(date, buildingId, pumpId, pumpName, curValue, tempTime); + } else { + // todo 7、更新数据 + waterTempMapper.updateWaterTemp(date, buildingId, pumpId, pumpName, curValue, tempTime); + } + } + } + +}