Browse Source

1、增加收益分析相关接口逻辑处理

dev
3067418132@qq.com 4 weeks ago
parent
commit
455bc79c5a
  1. 58
      mh-admin/src/main/java/com/mh/web/controller/energy/HowWaterRevenueEnergyController.java
  2. 28
      mh-admin/src/main/java/com/mh/web/controller/report/ReportHotWaterController.java
  3. 48
      mh-admin/src/test/java/com/mh/MHApplicationTest.java
  4. 14
      mh-common/src/main/java/com/mh/common/core/domain/dto/BFloorReportHotWaterDTO.java
  5. 2
      mh-common/src/main/java/com/mh/common/core/domain/dto/HotWaterNowDataDTO.java
  6. 77
      mh-common/src/main/java/com/mh/common/core/domain/dto/HotWaterRevenueSumDTO.java
  7. 18
      mh-common/src/main/java/com/mh/common/core/domain/dto/ThreeFloorReportHotWaterDTO.java
  8. 70
      mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyBaseSum.java
  9. 54
      mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyDaySum.java
  10. 54
      mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyMonthSum.java
  11. 54
      mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyYearSum.java
  12. 6
      mh-common/src/main/java/com/mh/common/core/domain/entity/ReportHotWaterParamHis.java
  13. 3
      mh-common/src/main/java/com/mh/common/core/domain/vo/DeviceMonitorVO.java
  14. 39
      mh-common/src/main/java/com/mh/common/utils/DateUtils.java
  15. 1
      mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java
  16. 4
      mh-system/src/main/java/com/mh/system/mapper/energy/EnergyDaySumMapper.java
  17. 2
      mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMonthSumMapper.java
  18. 2
      mh-system/src/main/java/com/mh/system/mapper/energy/EnergyYearSumMapper.java
  19. 14
      mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java
  20. 4
      mh-system/src/main/java/com/mh/system/service/energy/IEnergyQueryService.java
  21. 185
      mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyQueryServiceImpl.java
  22. 4
      mh-system/src/main/java/com/mh/system/service/report/impl/ReportHotWaterServiceImpl.java

58
mh-admin/src/main/java/com/mh/web/controller/energy/HowWaterRevenueEnergyController.java

@ -0,0 +1,58 @@
package com.mh.web.controller.energy;
import com.mh.common.core.controller.BaseController;
import com.mh.common.core.page.PageDomain;
import com.mh.common.core.page.TableDataInfo;
import com.mh.common.core.page.TableSupport;
import com.mh.system.service.energy.IEnergyQueryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author LJF
* @version 1.0
* @project EEMCS
* @description 中央热水收益分析
* @date 2026-05-13 08:37:12
*/
@RestController
@RequestMapping("/hot_water_revenue")
public class HowWaterRevenueEnergyController extends BaseController {
private final IEnergyQueryService energyQueryService;
public HowWaterRevenueEnergyController(IEnergyQueryService iEnergyQueryService) {
this.energyQueryService = iEnergyQueryService;
}
@GetMapping(value = "/energySum")
public TableDataInfo queryEnergySum(@RequestParam(value = "buildingId", required = false) String buildingId,
@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "type", required = true) Integer type) {
startPage();
List<?> result = energyQueryService.queryRevenueEnergyDataSumList(buildingId, startDate, endDate, type);
return getDataTable(result);
}
@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.queryRevenueEnergyDataList(buildingId, startDate, endDate, type);
TableDataInfo dataTable = getDataTable(result);
// 或者总条数数据
PageDomain pageDomain = TableSupport.buildPageRequest();
pageDomain.setPageNum(0);
List<?> result1 = energyQueryService.queryRevenueEnergyDataList(buildingId, startDate, endDate, type);
dataTable.setTotal(result1.size());
return dataTable;
}
}

28
mh-admin/src/main/java/com/mh/web/controller/report/ReportHotWaterController.java

@ -6,6 +6,7 @@ import com.mh.common.core.controller.BaseController;
import com.mh.common.core.domain.AjaxResult;
import com.mh.common.core.domain.dto.BFloorReportHotWaterDTO;
import com.mh.common.core.domain.dto.ThreeFloorReportHotWaterDTO;
import com.mh.common.core.domain.entity.FloorInfo;
import com.mh.common.core.domain.entity.ReportHotWaterParamHis;
import com.mh.common.core.domain.entity.ReportSysRunParamHis;
import com.mh.common.core.page.TableDataInfo;
@ -14,6 +15,7 @@ import com.mh.common.utils.file.handle.ExcelFillCellMergeHandler;
import com.mh.common.utils.file.handle.ReportSysParamHandler;
import com.mh.common.utils.file.handle.RowHeightStyleHandler;
import com.mh.system.service.report.IReportHotWaterService;
import com.mh.system.service.space.IFloorInfoService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
@ -38,8 +40,11 @@ public class ReportHotWaterController extends BaseController {
private final IReportHotWaterService reportHotWaterService;
private ReportHotWaterController(IReportHotWaterService reportHotWaterService) {
private final IFloorInfoService floorInfoService;
private ReportHotWaterController(IReportHotWaterService reportHotWaterService, IFloorInfoService floorInfoService) {
this.reportHotWaterService = reportHotWaterService;
this.floorInfoService = floorInfoService;
}
@PostMapping("/list")
@ -48,6 +53,12 @@ public class ReportHotWaterController extends BaseController {
if (reportHotWaterParamHis.getPageNum() != 0) {
PageHelper.startPage(reportHotWaterParamHis.getPageNum(), reportHotWaterParamHis.getPageSize());
}
FloorInfo floorInfo = floorInfoService.selectFloorInfoById(reportHotWaterParamHis.getFloorId());
if (floorInfo == null) {
throw new IllegalArgumentException("Floor not found");
} else {
reportHotWaterParamHis.setFloorId(reportHotWaterParamHis.getFloorId() + "_" + floorInfo.getFloorName());
}
List<ReportHotWaterParamHis> list = reportHotWaterService.selectList(reportHotWaterParamHis);
return getDataTable(list);
}
@ -55,6 +66,12 @@ public class ReportHotWaterController extends BaseController {
@PutMapping("/edit")
public AjaxResult edit(@RequestBody ReportHotWaterParamHis reportHotWaterParamHis)
{
// FloorInfo floorInfo = floorInfoService.selectFloorInfoById(reportHotWaterParamHis.getFloorId());
// if (floorInfo == null) {
// throw new IllegalArgumentException("Floor not found");
// } else {
// reportHotWaterParamHis.setFloorId(reportHotWaterParamHis.getFloorId() + "_" + floorInfo.getFloorName());
// }
return toAjax(reportHotWaterService.updateRunParams(reportHotWaterParamHis));
}
@ -64,6 +81,13 @@ public class ReportHotWaterController extends BaseController {
try {
String fileName = "热水热泵运行记录表.xlsx";
String floorId = reportHotWaterParamHis.getFloorId();
FloorInfo floorInfo = floorInfoService.selectFloorInfoById(floorId);
if (floorInfo == null) {
throw new IllegalArgumentException("Floor not found");
} else {
floorId = floorId + "_" + floorInfo.getFloorName();
reportHotWaterParamHis.setFloorId(floorId);
}
String headTitle = "热水热泵运行记录表";
if (!StringUtils.isBlank(floorId)) {
if (floorId.contains("主楼")) {
@ -123,6 +147,8 @@ public class ReportHotWaterController extends BaseController {
deviceInfoDTO.setStatusSwitchHotPumpOneStr(info.getStatusSwitchHotPumpOne() == 1 ? "开机" : "关机");
deviceInfoDTO.setStatusRunHotPumpTwoStr(info.getStatusRunHotPumpTwo() == 1 ? "运行" : "不运行");
deviceInfoDTO.setStatusSwitchHotPumpTwoStr(info.getStatusSwitchHotPumpTwo() == 1 ? "开机" : "关机");
deviceInfoDTO.setStatusRunCyclePumpOneStr(info.getStatusRunCyclePumpOne() == 1 ? "运行" : "不运行");
deviceInfoDTO.setStatusRunCyclePumpTwoStr(info.getStatusRunCyclePumpTwo() == 1 ? "运行" : "不运行");
// deviceInfoDTO.setStatusRunHotPumpThreeStr(info.getStatusRunHotPumpThree() == 1 ? "运行" : "不运行");
// deviceInfoDTO.setStatusSwitchHotPumpThreeStr(info.getStatusSwitchHotPumpThree() == 1 ? "开机" : "关机");
// deviceInfoDTO.setStatusRunHotPumpFourStr(info.getStatusRunHotPumpFour() == 1 ? "运行" : "不运行");

48
mh-admin/src/test/java/com/mh/MHApplicationTest.java

@ -11,6 +11,7 @@ import com.mh.common.utils.StringUtils;
import com.mh.quartz.task.DealDataTask;
import com.mh.quartz.task.GGDataTask;
import com.mh.quartz.task.GetWeatherDataTask;
import com.mh.quartz.task.HotWaterTask;
import com.mh.system.mapper.device.DataProcessMapper;
import com.mh.system.service.ISysParamsService;
import com.mh.system.service.ISysUserService;
@ -42,6 +43,53 @@ public class MHApplicationTest {
@Autowired
private ISysUserService sysUserService;
@Autowired
private HotWaterTask hotWaterTask;
@Test
public void hotWaterTask() {
hotWaterTask.calcEnergyData("2026-04-10 11:00:00");
}
@Test
public void hotWaterTaskWithTimeRange() {
// 定义起始时间和结束时间
String startTimeStr = "2026-05-12 00:00:00";
String endTimeStr = "2026-05-12 23:00:00";
try {
java.time.LocalDateTime startTime = java.time.LocalDateTime.parse(startTimeStr,
java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
java.time.LocalDateTime endTime = java.time.LocalDateTime.parse(endTimeStr,
java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
java.time.LocalDateTime currentTime = startTime;
int count = 0;
while (!currentTime.isAfter(endTime)) {
String timeStr = currentTime.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
System.out.println("正在处理时间: " + timeStr);
try {
hotWaterTask.calcFloorEnergyData(timeStr);
count++;
} catch (Exception e) {
System.err.println("处理时间 " + timeStr + " 时发生错误: " + e.getMessage());
e.printStackTrace();
}
// 增加一小时
currentTime = currentTime.plusHours(1);
}
System.out.println("完成!共处理了 " + count + " 个时间点的数据");
} catch (Exception e) {
System.err.println("时间范围处理过程中发生错误: " + e.getMessage());
e.printStackTrace();
}
}
@Test
public void test() throws Exception {
SysUser sysUser = sysUserService.selectUserById(1L);

14
mh-common/src/main/java/com/mh/common/core/domain/dto/BFloorReportHotWaterDTO.java

@ -315,23 +315,23 @@ public class BFloorReportHotWaterDTO {
// @ColumnWidth(10)
// private String statusRunSupplyPumpFourStr;
// 楼液位1(米)
@ExcelProperty(value = {"${deviceType}", "水箱液位", "水箱1液位%"}, index = 33)
// 贵宾楼液位1(米)
@ExcelProperty(value = {"${deviceType}", "水箱液位", "水箱1液位(米)"}, index = 33)
@ColumnWidth(10)
private BigDecimal levelWaterTankOne;
// 主楼液位2(米)
@ExcelProperty(value = {"${deviceType}", "水箱液位", "水箱2液位%"}, index = 34)
@ColumnWidth(10)
private BigDecimal levelWaterTankTwo;
// @ExcelProperty(value = {"${deviceType}", "水箱液位", "水箱2液位(米)"}, index = 34)
// @ColumnWidth(10)
// private BigDecimal levelWaterTankTwo;
// 巡查记录人
@ExcelProperty(value = {"${deviceType}", "巡查记录人", "巡查记录人"}, index = 35)
@ExcelProperty(value = {"${deviceType}", "巡查记录人", "巡查记录人"}, index = 34)
@ColumnWidth(20)
private String recorder;
// 备注信息
@ExcelProperty(value = {"${deviceType}", "备注", "备注"}, index = 36)
@ExcelProperty(value = {"${deviceType}", "备注", "备注"}, index = 35)
@ColumnWidth(20)
private String remark;

2
mh-common/src/main/java/com/mh/common/core/domain/dto/HotWaterNowDataDTO.java

@ -51,6 +51,8 @@ public class HotWaterNowDataDTO {
private String loopPumpState2; // 2循环泵状态:0:关机 1:运行 2:故障
private String gatewayStatus; // 网关状态 0:离线,1:在线
private int orderNum;
}

77
mh-common/src/main/java/com/mh/common/core/domain/dto/HotWaterRevenueSumDTO.java

@ -0,0 +1,77 @@
package com.mh.common.core.domain.dto;
import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;
import java.util.StringJoiner;
/**
* @author LJF
* @version 1.0
* @project EEMCS
* @description 热水收益总的收益情况
* @date 2026-05-13 09:33:27
*/
@Setter
@Getter
public class HotWaterRevenueSumDTO {
/**
* 时间
*/
private String curDate;
/**
* 建筑id
*/
private String buildingId;
// 电表用量
private BigDecimal totalUseEleAmount;
// 电量单价
private BigDecimal electPrice;
// 用电金额
private BigDecimal totalUseEle;
// 水表用量
private BigDecimal totalUseWaterAmount;
// 水价
private BigDecimal waterPrice;
// 用水金额
private BigDecimal totalUseWater;
// 平均电表用量
private BigDecimal avgUseEle;
// 平均水表用量
private BigDecimal avgUseWater;
// 单耗
private BigDecimal unitConsumption;
// 收益总额
private BigDecimal totalIncome;
@Override
public String toString() {
return new StringJoiner(", ", HotWaterRevenueSumDTO.class.getSimpleName() + "[", "]")
.add("curDate='" + curDate + "'")
.add("buildingId='" + buildingId + "'")
.add("totalUseEleAmount=" + totalUseEleAmount)
.add("electPrice=" + electPrice)
.add("totalUseEle=" + totalUseEle)
.add("totalUseWaterAmount=" + totalUseWaterAmount)
.add("waterPrice=" + waterPrice)
.add("totalUseWater=" + totalUseWater)
.add("avgUseEle=" + avgUseEle)
.add("avgUseWater=" + avgUseWater)
.add("unitConsumption=" + unitConsumption)
.add("totalIncome=" + totalIncome)
.toString();
}
}

18
mh-common/src/main/java/com/mh/common/core/domain/dto/ThreeFloorReportHotWaterDTO.java

@ -187,23 +187,33 @@ public class ThreeFloorReportHotWaterDTO {
// @ColumnWidth(10)
// private String statusRunSupplyPumpFourStr;
// 主楼与贵宾楼1号循环泵运行状态
@ExcelProperty(value = {"${deviceType}", "主楼与贵宾楼循环泵", "1号循环泵运行状态"}, index = 9)
@ColumnWidth(10)
private String statusRunCyclePumpOneStr;
// 主楼与贵宾楼2号循环泵运行状态
@ExcelProperty(value = {"${deviceType}", "主楼与贵宾楼循环泵", "2号循环泵运行状态"}, index = 10)
@ColumnWidth(10)
private String statusRunCyclePumpTwoStr;
// 主楼水箱1
@ExcelProperty(value = {"${deviceType}", "水箱液位", "水箱1液位%"}, index = 9)
@ExcelProperty(value = {"${deviceType}", "水箱液位", "水箱1液位(米)"}, index = 11)
@ColumnWidth(10)
private BigDecimal levelWaterTankOne;
// 主楼水箱2
@ExcelProperty(value = {"${deviceType}", "水箱液位", "水箱2液位%"}, index = 10)
@ExcelProperty(value = {"${deviceType}", "水箱液位", "水箱2液位(米)"}, index = 12)
@ColumnWidth(10)
private BigDecimal levelWaterTankTwo;
// 巡查记录人
@ExcelProperty(value = {"${deviceType}", "巡查记录人", "巡查记录人"}, index = 11)
@ExcelProperty(value = {"${deviceType}", "巡查记录人", "巡查记录人"}, index = 13)
@ColumnWidth(20)
private String recorder;
// 备注信息
@ExcelProperty(value = {"${deviceType}", "备注", "备注"}, index = 12)
@ExcelProperty(value = {"${deviceType}", "备注", "备注"}, index = 14)
@ColumnWidth(20)
private String remark;

70
mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyBaseSum.java

@ -0,0 +1,70 @@
package com.mh.common.core.domain.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author LJF
* @version 1.0
* @project EEMCS
* @description 热水Sum基础类
* @date 2026-05-13 09:50:45
*/
@Data
public class EnergyBaseSum {
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;
}

54
mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyDaySum.java

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
@ -14,61 +15,12 @@ import java.math.BigDecimal;
* @description 热水时间能耗实体类
* @date 2025-06-18 14:28:30
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("energy_day_sum")
public class EnergyDaySum {
public class EnergyDaySum extends EnergyBaseSum {
@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;
}

54
mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyMonthSum.java

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
@ -14,61 +15,12 @@ import java.math.BigDecimal;
* @description 热水时间能耗实体类
* @date 2025-06-18 14:28:30
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("energy_month_sum")
public class EnergyMonthSum {
public class EnergyMonthSum extends EnergyBaseSum {
@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;
}

54
mh-common/src/main/java/com/mh/common/core/domain/entity/EnergyYearSum.java

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
@ -14,61 +15,12 @@ import java.math.BigDecimal;
* @description 热水时间能耗实体类
* @date 2025-06-18 14:28:30
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("energy_month_sum")
public class EnergyYearSum {
public class EnergyYearSum extends EnergyBaseSum {
@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;
}

6
mh-common/src/main/java/com/mh/common/core/domain/entity/ReportHotWaterParamHis.java

@ -177,6 +177,12 @@ public class ReportHotWaterParamHis extends BaseEntity implements Serializable {
// 中区/中厨液位(米)
private BigDecimal levelWaterTankTwo;
// 主楼与贵宾楼循环泵1
private Integer statusRunCyclePumpOne;
// 主楼与贵宾楼循环泵2
private Integer statusRunCyclePumpTwo;
// 巡查记录人
private String recorder;

3
mh-common/src/main/java/com/mh/common/core/domain/vo/DeviceMonitorVO.java

@ -62,6 +62,8 @@ public class DeviceMonitorVO {
private int orderNum;
private String gatewayId;
@Override
public String toString() {
return new ToStringBuilder(this)
@ -74,6 +76,7 @@ public class DeviceMonitorVO {
.append("collectValue", collectValue)
.append("paramType", paramType)
.append("orderNum", orderNum)
.append("gatewayId", gatewayId)
.toString();
}
}

39
mh-common/src/main/java/com/mh/common/utils/DateUtils.java

@ -506,4 +506,43 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
}
return null;
}
public static int dayDiff(String startDate, String endDate) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date start = sdf.parse(startDate);
Date end = sdf.parse(endDate);
long diff = (end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000);
return Math.abs((int) diff) + 1;
} catch (ParseException e) {
return 0;
}
}
public static int monthDiff(String startDate, String endDate) {
try {
if (startDate == null || endDate == null || startDate.isEmpty() || endDate.isEmpty()) {
return 0;
}
LocalDate start = LocalDate.parse(startDate + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
LocalDate end = LocalDate.parse(endDate + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
Period period = Period.between(start, end);
int months = period.getYears() * 12 + period.getMonths();
return Math.abs(months)+1;
} catch (Exception e) {
return 0;
}
}
public static int yearDiff(String startDate, String endDate) {
try {
// startDate和endDate传入的值是“yyyy”
return Math.abs(Integer.parseInt(endDate) - Integer.parseInt(startDate))+1;
} catch (Exception e) {
return 0;
}
}
}

1
mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java

@ -254,6 +254,7 @@ public interface CollectionParamsManageMapper extends BaseMapper<CollectionParam
" cpm.cur_time as collectTime, " +
" cpm.param_type as paramType, " +
" cpm.other_name as collectName, " +
" cpm.gateway_id as gatewayId, " +
" dl.order_num as orderNum " +
"from " +
" collection_params_manage cpm " +

4
mh-system/src/main/java/com/mh/system/mapper/energy/EnergyDaySumMapper.java

@ -19,4 +19,8 @@ public interface EnergyDaySumMapper extends BaseMapper<EnergyDaySum> {
@Select("select * from energy_day_sum where building_id = #{buildingId} and cur_date = #{startDate} ")
List<EnergyDaySum> queryEnergyDaySum(String buildingId, String startDate);
@Select("select * from energy_day_sum where building_id = #{buildingId} and cur_date between #{startDate} and #{endDate} ")
List<EnergyDaySum> queryRevenueEnergyDaySum(String buildingId, String startDate, String endDate);
}

2
mh-system/src/main/java/com/mh/system/mapper/energy/EnergyMonthSumMapper.java

@ -20,4 +20,6 @@ public interface EnergyMonthSumMapper extends BaseMapper<EnergyMonthSum> {
@Select("select * from energy_month_sum where building_id = #{buildingId} and cur_date = #{startDate} ")
List<EnergyMonthSum> queryEnergyMonthSum(String buildingId, String startDate);
@Select("select * from energy_month_sum where building_id = #{buildingId} and cur_date between #{startDate} and #{endDate}")
List<EnergyMonthSum> queryRevenueEnergyMonthSum(String buildingId, String startDate, String endDate);
}

2
mh-system/src/main/java/com/mh/system/mapper/energy/EnergyYearSumMapper.java

@ -21,4 +21,6 @@ public interface EnergyYearSumMapper extends BaseMapper<EnergyYearSum> {
@Select("select * from energy_year_sum where building_id = #{buildingId} and cur_date = #{startDate} ")
List<EnergyYearSum> queryEnergyYearSum(String buildingId, String startDate);
@Select("select * from energy_year_sum where building_id = #{buildingId} and cur_date between #{startDate} and #{endDate} ")
List<EnergyYearSum> queryRevenueEnergyYearSum(String buildingId, String startDate, String endDate);
}

14
mh-system/src/main/java/com/mh/system/service/device/impl/CollectionParamsManageServiceImpl.java

@ -218,6 +218,7 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag
/**
* 处理otherName字段"-"分割并取最后一部分
*
* @param collectionParamsManages 待处理的集合
* @return 处理后的集合
*/
@ -861,6 +862,19 @@ public class CollectionParamsManageServiceImpl implements ICollectionParamsManag
// });
// }
// 处理网关在线状态
String gatewayId = hotPumps.getFirst().getGatewayId();
GatewayManage gatewayManage = gatewayManageMapper.selectById(gatewayId);
// 判断connectTime是否在30分钟内
if (gatewayManage != null) {
Date connectTime = gatewayManage.getConnectTime();
if (connectTime != null && new Date().getTime() - connectTime.getTime() <= 30 * 60 * 1000) {
result.forEach(dto -> dto.setGatewayStatus("1"));
} else {
result.forEach(dto -> dto.setGatewayStatus("0"));
}
}
// result再根据orderNum排序
return result.stream()
.sorted(Comparator.comparingInt(HotWaterNowDataDTO::getOrderNum))

4
mh-system/src/main/java/com/mh/system/service/energy/IEnergyQueryService.java

@ -53,4 +53,8 @@ public interface IEnergyQueryService {
List<?> queryAnalysisMonth(String curDate, String buildingId, int type);
void calcAnalysisData(String lastHourTime);
List<?> queryRevenueEnergyDataSumList(String buildingId, String startDate, String endDate, Integer type);
List<?> queryRevenueEnergyDataList(String buildingId, String startDate, String endDate, int type);
}

185
mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyQueryServiceImpl.java

@ -1,6 +1,7 @@
package com.mh.system.service.energy.impl;
import com.mh.common.core.domain.AjaxResult;
import com.mh.common.core.domain.dto.HotWaterRevenueSumDTO;
import com.mh.common.core.domain.entity.*;
import com.mh.common.core.domain.vo.EnergyQueryVO;
import com.mh.common.utils.DateUtils;
@ -67,6 +68,190 @@ public class EnergyQueryServiceImpl implements IEnergyQueryService {
@Resource
AnalysisMapper analysisMapper;
// 定义电价和水价
private static final BigDecimal ELECTRIC_PRICE = new BigDecimal("0.7100");
private static final BigDecimal WATER_PRICE = new BigDecimal("19.0000");
@Override
public List<?> queryRevenueEnergyDataSumList(String buildingId, String startDate, String endDate, Integer type) {
if (StringUtils.isEmpty(buildingId)) {
return List.of();
}
if (type==1){
List<EnergyDaySum> energyDaySums = energyDaySumMapper.queryRevenueEnergyDaySum(buildingId, startDate, endDate);
// 查看startDate和endDate相差多少天
int days = DateUtils.dayDiff(startDate, endDate);
return List.of(calculateRevenueSum(energyDaySums, days));
}else if (type==2){
List<EnergyMonthSum> energyMonthSums = energyMonthSumMapper.queryRevenueEnergyMonthSum(buildingId,startDate,endDate);
// 查看startDate和endDate相差多少月
int months = DateUtils.monthDiff(startDate, endDate);
return List.of(calculateRevenueSum(energyMonthSums, months));
}else {
List<EnergyYearSum> energyYearSums = energyYearSumMapper.queryRevenueEnergyYearSum(buildingId,startDate,endDate);
// 查看startDate和endDate相差多少年
int years = DateUtils.yearDiff(startDate, endDate);
return List.of(calculateRevenueSum(energyYearSums, years));
}
}
private HotWaterRevenueSumDTO calculateRevenueSum(List<? extends EnergyBaseSum> energySums, int diffTime) {
HotWaterRevenueSumDTO revenueSumDTO = new HotWaterRevenueSumDTO();
if (energySums == null || energySums.isEmpty()) {
revenueSumDTO.setTotalUseEle(BigDecimal.ZERO);
revenueSumDTO.setTotalUseWater(BigDecimal.ZERO);
revenueSumDTO.setAvgUseEle(BigDecimal.ZERO);
revenueSumDTO.setAvgUseWater(BigDecimal.ZERO);
revenueSumDTO.setUnitConsumption(BigDecimal.ZERO);
revenueSumDTO.setTotalIncome(BigDecimal.ZERO);
return revenueSumDTO;
}
BigDecimal totalWaterValue = energySums.stream()
.map(EnergyBaseSum::getWaterValue)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal totalElectValue = energySums.stream()
.map(EnergyBaseSum::getElectValue)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// int count = energySums.size();
// // count如果type=1,就是日,需要看startDate和endDate的天数差
// // count如果type=2,就是月,需要看startDate和endDate的月数差
// // count如果type=3,就是年,需要看startDate和endDate的年数差
// if (type == 1) {
// count = DateUtils.dayDiff(energySums.get(0).getCurDate(), energySums.get(energySums.size() - 1).getCurDate());
// } else if (type == 2) {
// count = DateUtils.monthDiff(energySums.get(0).getCurDate(), energySums.get(energySums.size() - 1).getCurDate());
// } else if (type == 3) {
// count = DateUtils.yearDiff(energySums.get(0).getCurDate(), energySums.get(energySums.size() - 1).getCurDate());
// }
BigDecimal unitConsumption = BigDecimal.ZERO;
if (totalWaterValue.compareTo(BigDecimal.ZERO) != 0) {
unitConsumption = totalElectValue.divide(totalWaterValue, 4, BigDecimal.ROUND_HALF_UP);
}
BigDecimal waterRevenue = totalWaterValue.multiply(WATER_PRICE);
BigDecimal electCost = totalElectValue.multiply(ELECTRIC_PRICE);
BigDecimal totalIncome = waterRevenue.subtract(electCost).divide(new BigDecimal("1.06"), 4, BigDecimal.ROUND_HALF_UP);
BigDecimal avgWaterValue = waterRevenue.divide(BigDecimal.valueOf(diffTime), 4, BigDecimal.ROUND_HALF_UP);
BigDecimal avgElectValue = electCost.divide(BigDecimal.valueOf(diffTime), 4, BigDecimal.ROUND_HALF_UP);
revenueSumDTO.setTotalUseEle(electCost);
revenueSumDTO.setTotalUseWater(waterRevenue);
revenueSumDTO.setAvgUseEle(avgElectValue);
revenueSumDTO.setAvgUseWater(avgWaterValue);
revenueSumDTO.setUnitConsumption(unitConsumption);
revenueSumDTO.setTotalIncome(totalIncome);
return revenueSumDTO;
}
@Override
public List<?> queryRevenueEnergyDataList(String buildingId, String startDate, String endDate, int type) {
if (StringUtils.isEmpty(buildingId)) {
return List.of();
}
if (type == 0) {
List<EnergyHour> energyHours = energyHourMapper.queryEnergyHour(buildingId, startDate + " 00", endDate + " 23");
// 遍历energyHours,然后计算用水金额,用电金额,总收入((水*19-电*0.71)/1.06),单耗,然后赋值给HotWaterRevenueSumDTO,并根据时间降序排序
return energyHours.stream()
.map(energyHour -> {
HotWaterRevenueSumDTO revenueSumDTO = new HotWaterRevenueSumDTO();
revenueSumDTO.setCurDate(energyHour.getCurDate());
revenueSumDTO.setTotalUseEleAmount(energyHour.getElectValue().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setElectPrice(ELECTRIC_PRICE);
revenueSumDTO.setTotalUseEle(energyHour.getElectValue().multiply(ELECTRIC_PRICE).setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setTotalUseWaterAmount(energyHour.getUseHotWater().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setWaterPrice(WATER_PRICE);
revenueSumDTO.setTotalUseWater(energyHour.getUseHotWater().multiply(WATER_PRICE).setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setAvgUseEle(BigDecimal.ZERO);
revenueSumDTO.setAvgUseWater(BigDecimal.ZERO);
revenueSumDTO.setUnitConsumption(energyHour.getElectWater().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setTotalIncome(energyHour.getUseHotWater().multiply(WATER_PRICE).subtract(energyHour.getElectValue().multiply(ELECTRIC_PRICE)).divide(new BigDecimal("1.06"), 4, BigDecimal.ROUND_HALF_UP));
return revenueSumDTO;
})
.sorted(Comparator.comparing(HotWaterRevenueSumDTO::getCurDate).reversed())
.collect(Collectors.toList());
} else if(type==1) {
List<EnergyDay> energyDays = energyDayMapper.queryEnergyDay(buildingId, startDate, endDate);
return energyDays.stream()
.map(energyDay -> {
HotWaterRevenueSumDTO revenueSumDTO = new HotWaterRevenueSumDTO();
revenueSumDTO.setCurDate(energyDay.getCurDate());
revenueSumDTO.setTotalUseEleAmount(energyDay.getElectValue().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setElectPrice(ELECTRIC_PRICE);
revenueSumDTO.setTotalUseEle(energyDay.getElectValue().multiply(ELECTRIC_PRICE).setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setTotalUseWaterAmount(energyDay.getUseHotWater().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setWaterPrice(WATER_PRICE);
revenueSumDTO.setTotalUseWater(energyDay.getUseHotWater().multiply(WATER_PRICE).setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setAvgUseEle(BigDecimal.ZERO);
revenueSumDTO.setAvgUseWater(BigDecimal.ZERO);
revenueSumDTO.setUnitConsumption(energyDay.getElectWater().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setTotalIncome(energyDay.getUseHotWater().multiply(WATER_PRICE).subtract(energyDay.getElectValue().multiply(ELECTRIC_PRICE)).divide(new BigDecimal("1.06"), 4, BigDecimal.ROUND_HALF_UP));
return revenueSumDTO;
})
.sorted(Comparator.comparing(HotWaterRevenueSumDTO::getCurDate).reversed())
.collect(Collectors.toList());
} else if (type==2){
List<EnergyMonth> energyMonths = energyMonthMapper.queryEnergyMonth(buildingId, startDate, endDate);
return energyMonths.stream()
.map(energyMonth -> {
HotWaterRevenueSumDTO revenueSumDTO = new HotWaterRevenueSumDTO();
revenueSumDTO.setCurDate(energyMonth.getCurDate());
revenueSumDTO.setTotalUseEleAmount(energyMonth.getElectValue().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setElectPrice(ELECTRIC_PRICE);
revenueSumDTO.setTotalUseEle(energyMonth.getElectValue().multiply(ELECTRIC_PRICE).setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setTotalUseWaterAmount(energyMonth.getUseHotWater().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setWaterPrice(WATER_PRICE);
revenueSumDTO.setTotalUseWater(energyMonth.getUseHotWater().multiply(WATER_PRICE).setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setAvgUseEle(BigDecimal.ZERO);
revenueSumDTO.setAvgUseWater(BigDecimal.ZERO);
revenueSumDTO.setUnitConsumption(energyMonth.getElectWater().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setTotalIncome(energyMonth.getUseHotWater().multiply(WATER_PRICE).subtract(energyMonth.getElectValue().multiply(ELECTRIC_PRICE)).divide(new BigDecimal("1.06"), 4, BigDecimal.ROUND_HALF_UP));
return revenueSumDTO;
})
.sorted(Comparator.comparing(HotWaterRevenueSumDTO::getCurDate).reversed())
.collect(Collectors.toList());
} else if (type==3){
List<EnergyYear> energyYears = energyYearMapper.queryEnergyYear(buildingId, startDate, endDate);
return energyYears.stream()
.map(energyYear -> {
HotWaterRevenueSumDTO revenueSumDTO = new HotWaterRevenueSumDTO();
revenueSumDTO.setCurDate(energyYear.getCurDate());
revenueSumDTO.setTotalUseEleAmount(energyYear.getElectValue().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setElectPrice(ELECTRIC_PRICE);
revenueSumDTO.setTotalUseEle(energyYear.getElectValue().multiply(ELECTRIC_PRICE).setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setTotalUseWaterAmount(energyYear.getUseHotWater().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setWaterPrice(WATER_PRICE);
revenueSumDTO.setTotalUseWater(energyYear.getUseHotWater().multiply(WATER_PRICE).setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setAvgUseEle(BigDecimal.ZERO);
revenueSumDTO.setAvgUseWater(BigDecimal.ZERO);
revenueSumDTO.setUnitConsumption(energyYear.getElectWater().setScale(4, BigDecimal.ROUND_HALF_UP));
revenueSumDTO.setTotalIncome(energyYear.getUseHotWater().multiply(WATER_PRICE).subtract(energyYear.getElectValue().multiply(ELECTRIC_PRICE)).divide(new BigDecimal("1.06"), 4, BigDecimal.ROUND_HALF_UP));
return revenueSumDTO;
})
.sorted(Comparator.comparing(HotWaterRevenueSumDTO::getCurDate).reversed())
.collect(Collectors.toList());
}
return null;
}
@Override
public void calcAnalysisData(String lastHourTime) {
try {

4
mh-system/src/main/java/com/mh/system/service/report/impl/ReportHotWaterServiceImpl.java

@ -55,7 +55,7 @@ public class ReportHotWaterServiceImpl implements IReportHotWaterService {
// 提交任务
Future<?> future1 = executorService.submit(() -> {
reportHotWaterParamHisMapper.execProHotWaterRunParam(
"73138702b71e16d200b458185bb07e59_主楼",
"e3dc9e3d0aa7c07d3b6db9ce8c119f3d_主楼",
"e3dc9e3d0aa7c07d3b6db9ce8c119f3d",
"",
timeParam
@ -65,7 +65,7 @@ public class ReportHotWaterServiceImpl implements IReportHotWaterService {
Future<?> future2 = executorService.submit(() -> {
reportHotWaterParamHisMapper.execProHotWaterRunParam(
"73138702b71e16d200b458185bb07e59_贵宾楼",
"24c7538214b5f6e707e27095b37aee46_贵宾楼",
"24c7538214b5f6e707e27095b37aee46",
"",
timeParam

Loading…
Cancel
Save