From a391fa4aa1d4f64b03ff6ccb17c438f85b1c7d80 Mon Sep 17 00:00:00 2001 From: bobol Date: Tue, 16 Apr 2024 14:03:58 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81aj-report=E6=8A=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lzbi/external/service/ParamsService.java | 12 +- .../report/controller/AjReportController.java | 11 +- .../lzbi/report/domain/query/ReportQuery.java | 4 + .../com/lzbi/report/domain/req/ReportReq.java | 7 + .../lzbi/report/service/AjReportService.java | 141 +++++++++++++++--- .../mapper/report/AjReportMapper.xml | 6 + 6 files changed, 153 insertions(+), 28 deletions(-) diff --git a/lzbi-module/src/main/java/com/lzbi/external/service/ParamsService.java b/lzbi-module/src/main/java/com/lzbi/external/service/ParamsService.java index c2efcc1..b53cb38 100644 --- a/lzbi-module/src/main/java/com/lzbi/external/service/ParamsService.java +++ b/lzbi-module/src/main/java/com/lzbi/external/service/ParamsService.java @@ -3,15 +3,15 @@ package com.lzbi.external.service; import com.lzbi.common.constant.ParamsModelCodeConstants; import com.lzbi.draft.domain.DcBusiParamDraftDay; import com.lzbi.draft.mapper.DcBusiParamDraftDayMapper; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; +@Slf4j @Service public class ParamsService { @@ -29,9 +29,9 @@ public class ParamsService { } List list = dcBusiParamDraftDayMapper.selectLastDataByAssetCodeListAndParamsModelCode(assetCodeList, ParamsModelCodeConstants.供暖面积); if (CollectionUtils.isEmpty(list)) { - throw new RuntimeException("暂无数据"); + log.warn("暂无数据"); + return new HashMap<>(); } - Map map = list.stream().collect(Collectors.toMap(DcBusiParamDraftDay::getAssetCode, DcBusiParamDraftDay::getValLast)); - return map; + return list.stream().collect(Collectors.toMap(DcBusiParamDraftDay::getAssetCode, DcBusiParamDraftDay::getValLast)); } } diff --git a/lzbi-module/src/main/java/com/lzbi/report/controller/AjReportController.java b/lzbi-module/src/main/java/com/lzbi/report/controller/AjReportController.java index 2a39476..668a506 100644 --- a/lzbi-module/src/main/java/com/lzbi/report/controller/AjReportController.java +++ b/lzbi-module/src/main/java/com/lzbi/report/controller/AjReportController.java @@ -1,9 +1,9 @@ package com.lzbi.report.controller; import com.lzbi.report.domain.req.ReportReq; -import com.lzbi.report.domain.vo.ReportVO; import com.lzbi.report.service.AjReportService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -18,8 +18,13 @@ public class AjReportController { @Autowired private AjReportService ajReportService; + @GetMapping("/datang/data") + public List> getDatangDataList(@Validated ReportReq reportReq) { + return ajReportService.getDatangDataList(reportReq); + } + @GetMapping("/heatExchangeStation/data") - public List> getReportDataList(ReportReq reportReq) { - return ajReportService.getReportDataList(reportReq); + public List> getHeatExchangeStationDataList(@Validated ReportReq reportReq) { + return ajReportService.getHeatExchangeStationDataList(reportReq); } } diff --git a/lzbi-module/src/main/java/com/lzbi/report/domain/query/ReportQuery.java b/lzbi-module/src/main/java/com/lzbi/report/domain/query/ReportQuery.java index dcfffeb..fb2b63e 100644 --- a/lzbi-module/src/main/java/com/lzbi/report/domain/query/ReportQuery.java +++ b/lzbi-module/src/main/java/com/lzbi/report/domain/query/ReportQuery.java @@ -11,6 +11,10 @@ public class ReportQuery { * 组织id */ private Long orgId; + /** + * 统计单元编码 + */ + private String assetCode; /** * 查询日期 */ diff --git a/lzbi-module/src/main/java/com/lzbi/report/domain/req/ReportReq.java b/lzbi-module/src/main/java/com/lzbi/report/domain/req/ReportReq.java index 33dfe36..c3eec77 100644 --- a/lzbi-module/src/main/java/com/lzbi/report/domain/req/ReportReq.java +++ b/lzbi-module/src/main/java/com/lzbi/report/domain/req/ReportReq.java @@ -2,6 +2,8 @@ package com.lzbi.report.domain.req; import lombok.Data; +import javax.validation.constraints.NotNull; + /** * 报表查询参数 */ @@ -11,7 +13,12 @@ public class ReportReq { /** * 组织id */ + @NotNull(message = "请输入热源ID") private Long orgId; + /** + * 统计单元编码 + */ + private String assetCode; /** * 查询日期 */ diff --git a/lzbi-module/src/main/java/com/lzbi/report/service/AjReportService.java b/lzbi-module/src/main/java/com/lzbi/report/service/AjReportService.java index 7fc734b..a0813e3 100644 --- a/lzbi-module/src/main/java/com/lzbi/report/service/AjReportService.java +++ b/lzbi-module/src/main/java/com/lzbi/report/service/AjReportService.java @@ -1,5 +1,7 @@ package com.lzbi.report.service; +import com.lzbi.asset.domain.DcBaseAssetInfo; +import com.lzbi.asset.mapper.DcBaseAssetInfoMapper; import com.lzbi.common.constant.BizConstants; import com.lzbi.common.constant.ParamsModelCodeConstants; import com.lzbi.common.constant.PartitionConstants; @@ -10,6 +12,7 @@ import com.lzbi.report.domain.query.ReportQuery; import com.lzbi.report.domain.req.ReportReq; import com.lzbi.report.mapper.AjReportMapper; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -19,10 +22,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @Service @@ -34,8 +34,107 @@ public class AjReportService { @Autowired private ParamsService paramsService; - public List> getReportDataList(ReportReq reportReq) { + @Resource + private DcBaseAssetInfoMapper dcBaseAssetInfoMapper; + + /** + * 获取大唐管井数据 + * @param reportReq + * @return + */ + public List> getDatangDataList(ReportReq reportReq) { + if (StringUtils.isBlank(reportReq.getCountDate())) { + reportReq.setCountDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + } + List targetModelCodeList = new ArrayList<>(13); + targetModelCodeList.add(ParamsModelCodeConstants.瞬时热量); + targetModelCodeList.add(ParamsModelCodeConstants.累计热量); + targetModelCodeList.add(ParamsModelCodeConstants.一次网供温); + targetModelCodeList.add(ParamsModelCodeConstants.一次网回温); + targetModelCodeList.add(ParamsModelCodeConstants.一次网供压); + targetModelCodeList.add(ParamsModelCodeConstants.一次网回压); + targetModelCodeList.add(ParamsModelCodeConstants.供水流量); + targetModelCodeList.add(ParamsModelCodeConstants.回水流量); + targetModelCodeList.add(ParamsModelCodeConstants.水表瞬时补水量); + targetModelCodeList.add(ParamsModelCodeConstants.水表累计补水量); + targetModelCodeList.add(ParamsModelCodeConstants.电调阀开度给定); + targetModelCodeList.add(ParamsModelCodeConstants.电调阀开度反馈); + ReportQuery reportQuery = new ReportQuery(); + BeanUtils.copyProperties(reportReq, reportQuery); + reportQuery.setAssetLevel(BizConstants.DcAssetLevel.HEAT_SOURCE); + reportQuery.setAssetType(BizConstants.DcAssetType.COMPUTE); + reportQuery.setColumnType(BizConstants.ColumnType.PARAM); + reportQuery.setTargetModelCodeList(targetModelCodeList); + List assetAndPartitionList = ajReportMapper.getAssetAndPartitionList(reportQuery); + if (CollectionUtils.isEmpty(assetAndPartitionList)) { + throw new RuntimeException("未配置统计单元"); + } + List reportDataList = ajReportMapper.getReportDataList(reportQuery); + if (CollectionUtils.isEmpty(reportDataList)) { + throw new RuntimeException("无数据"); + } List> list = new ArrayList<>(); + Map reportVO = new HashMap<>(); + String datangAssetAndPartition = assetAndPartitionList.get(0); + Map> reportDataMap = reportDataList.stream().collect(Collectors.groupingBy(item -> StringUtils.join(item.getAssetCode(), "-", item.getPartition()))); + List reportDTOList = reportDataMap.get(datangAssetAndPartition); + String assetCode = reportDTOList.get(0).getAssetCode(); + reportVO.put("assetCode", assetCode); + reportVO.put("assetName", reportDTOList.get(0).getAssetName()); + reportVO.put("partition", PartitionConstants.partition.get(reportDTOList.get(0).getPartition())); + Map targetDataMap = reportDTOList.stream().collect(Collectors.toMap(ReportDTO::getTargetModelCode, item -> item, (v1, v2) -> v2)); + targetModelCodeList.forEach(targetModelCode -> getValue(reportVO, targetDataMap.get(targetModelCode), targetModelCode)); + // 获取合力热源下的所有换热站的供暖面积 + DcBaseAssetInfo dcBaseAssetInfo = new DcBaseAssetInfo(); + dcBaseAssetInfo.setOrgId(reportReq.getOrgId()); + dcBaseAssetInfo.setAssetLevel(BizConstants.DcAssetLevel.HEAT_EXCHANGE_STATION); + dcBaseAssetInfo.setAssetType(BizConstants.DcAssetType.COMPUTE); + List dcBaseAssetInfos = dcBaseAssetInfoMapper.selectDcBaseAssetInfoList(dcBaseAssetInfo); + List assetCodeList = dcBaseAssetInfos.stream().map(DcBaseAssetInfo::getAssetCode).collect(Collectors.toList()); + Map multipleAssetSupplyArea = paramsService.getMultipleAssetSupplyArea(assetCodeList); + if (!CollectionUtils.isEmpty(multipleAssetSupplyArea)) { + Double supplyArea = 0D; + Set keys = multipleAssetSupplyArea.keySet(); + Iterator iterator = keys.iterator(); + while (iterator.hasNext()) { + supplyArea += multipleAssetSupplyArea.get(iterator.next()); + } + reportVO.put("supplyArea", NumberUtils.doubleScaleToDouble(supplyArea, 2)); + } + Object b = reportVO.get("supplyArea"); + Object c = reportVO.get(ParamsModelCodeConstants.瞬时热量); + Object e = reportVO.get(ParamsModelCodeConstants.一次网供温); + Object f = reportVO.get(ParamsModelCodeConstants.一次网回温); + Object g = reportVO.get(ParamsModelCodeConstants.一次网供压); + Object h = reportVO.get(ParamsModelCodeConstants.一次网回压); + Object i = reportVO.get(ParamsModelCodeConstants.供水流量); + if (null != i && null != b && !b.equals(0D)) { + BigDecimal i1 = BigDecimal.valueOf((Double) i * 1000D); + BigDecimal b1 = BigDecimal.valueOf((Double) b); + reportVO.put("c1", i1.divide(b1, 8, RoundingMode.HALF_EVEN)); + } + if (null != c && null != b && !b.equals(0D)) { + BigDecimal c1 = BigDecimal.valueOf((Double) c); + BigDecimal b1 = BigDecimal.valueOf((Double) b); + reportVO.put("c2", c1.divide(b1, 8, RoundingMode.HALF_EVEN).toPlainString()); + } + if (null != g && null != h) { + reportVO.put("c3", NumberUtils.doubleScaleToDouble((Double) g - (Double) h, 2)); + } + if (null != e && null != f) { + reportVO.put("c4", NumberUtils.doubleScaleToDouble((Double) e - (Double) f, 2)); + reportVO.put("c5", NumberUtils.doubleScaleToDouble(((Double) e + (Double) f) / 2, 2)); + } + list.add(reportVO); + return list; + } + + /** + * 获取换热站数据 + * @param reportReq + * @return + */ + public List> getHeatExchangeStationDataList(ReportReq reportReq) { if (StringUtils.isBlank(reportReq.getCountDate())) { reportReq.setCountDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); } @@ -55,12 +154,16 @@ public class AjReportService { targetModelCodeList.add(ParamsModelCodeConstants.电调阀开度反馈); targetModelCodeList.add(ParamsModelCodeConstants.水箱水位计); ReportQuery reportQuery = new ReportQuery(); - reportQuery.setOrgId(reportReq.getOrgId()); - reportQuery.setCountDate(reportReq.getCountDate()); + BeanUtils.copyProperties(reportReq, reportQuery); reportQuery.setAssetLevel(BizConstants.DcAssetLevel.HEAT_EXCHANGE_STATION); reportQuery.setAssetType(BizConstants.DcAssetType.COMPUTE); reportQuery.setColumnType(BizConstants.ColumnType.PARAM); reportQuery.setTargetModelCodeList(targetModelCodeList); + return this.getData(reportQuery); + } + + private List> getData(ReportQuery reportQuery) { + List> list = new ArrayList<>(); List assetAndPartitionList = ajReportMapper.getAssetAndPartitionList(reportQuery); if (CollectionUtils.isEmpty(assetAndPartitionList)) { throw new RuntimeException("未配置统计单元"); @@ -85,12 +188,12 @@ public class AjReportService { reportVO.put("supplyArea", multipleAssetSupplyArea.get(assetCode)); } Map targetDataMap = reportDTOList.stream().collect(Collectors.toMap(ReportDTO::getTargetModelCode, item -> item, (v1, v2) -> v2)); + List targetModelCodeList = reportQuery.getTargetModelCodeList(); targetModelCodeList.forEach(targetModelCode -> getValue(reportVO, targetDataMap.get(targetModelCode), targetModelCode)); this.calculateExtraCellValue(reportVO); list.add(reportVO); } }); - return list; } @@ -113,29 +216,29 @@ public class AjReportService { Object l = reportVO.get(ParamsModelCodeConstants.二次网回水温); Object m = reportVO.get(ParamsModelCodeConstants.二次网供水压力); Object n = reportVO.get(ParamsModelCodeConstants.二次网回水压力); - if (null != d && null != e && !e.equals(0D)) { + if (null != d && null != b && !b.equals(0D)) { BigDecimal d1 = BigDecimal.valueOf((Double) d * 1000D); - BigDecimal e1 = BigDecimal.valueOf((Double) e); - reportVO.put("c1", d1.divide(e1, 8, RoundingMode.HALF_EVEN)); - } - if (null != b && null != e && !e.equals(0D)) { BigDecimal b1 = BigDecimal.valueOf((Double) b); + reportVO.put("c1", d1.divide(b1, 8, RoundingMode.HALF_EVEN)); + } + if (null != e && null != b && !b.equals(0D)) { BigDecimal e1 = BigDecimal.valueOf((Double) e); + BigDecimal b1 = BigDecimal.valueOf((Double) b); reportVO.put("c2", e1.divide(b1, 8, RoundingMode.HALF_EVEN).toPlainString()); } if (null != i && null != j) { - reportVO.put("c3", NumberUtils.doubleScaleToBigDecimal((Double) i - (Double) j, 2)); + reportVO.put("c3", NumberUtils.doubleScaleToDouble((Double) i - (Double) j, 2)); } if (null != g && null != h) { - reportVO.put("c4", NumberUtils.doubleScaleToBigDecimal((Double) g - (Double) h, 2)); - reportVO.put("c5", NumberUtils.doubleScaleToBigDecimal(((Double) g + (Double) h) / 2, 2)); + reportVO.put("c4", NumberUtils.doubleScaleToDouble((Double) g - (Double) h, 2)); + reportVO.put("c5", NumberUtils.doubleScaleToDouble(((Double) g + (Double) h) / 2, 2)); } if (null != k && null != l) { - reportVO.put("c6", NumberUtils.doubleScaleToBigDecimal((Double) k - (Double) l, 2)); - reportVO.put("c7", NumberUtils.doubleScaleToBigDecimal(((Double) k + (Double) l) / 2, 2)); + reportVO.put("c6", NumberUtils.doubleScaleToDouble((Double) k - (Double) l, 2)); + reportVO.put("c7", NumberUtils.doubleScaleToDouble(((Double) k + (Double) l) / 2, 2)); } if (null != m && null != n) { - reportVO.put("c8", NumberUtils.doubleScaleToBigDecimal((Double) m - (Double) n, 2)); + reportVO.put("c8", NumberUtils.doubleScaleToDouble((Double) m - (Double) n, 2)); } } diff --git a/lzbi-module/src/main/resources/mapper/report/AjReportMapper.xml b/lzbi-module/src/main/resources/mapper/report/AjReportMapper.xml index 85e8a66..f4af5d9 100644 --- a/lzbi-module/src/main/resources/mapper/report/AjReportMapper.xml +++ b/lzbi-module/src/main/resources/mapper/report/AjReportMapper.xml @@ -22,6 +22,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" t1.org_id = #{orgId} and t1.asset_type = #{assetType} and t1.asset_level = #{assetLevel} + + and t1.asset_code = #{assetCode} + order by t1.asset_code asc, t2.goal_param_ext2 asc @@ -53,6 +56,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" t1.org_id = #{orgId} and t1.asset_type = #{assetType} and t1.asset_level = #{assetLevel} + + and t1.asset_code = #{assetCode} + order by t1.asset_code asc, t3.goal_param_ext2 asc