bobol
7 months ago
26 changed files with 590 additions and 55 deletions
@ -0,0 +1,21 @@ |
|||||
|
package com.lzbi.common.utils; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.math.RoundingMode; |
||||
|
|
||||
|
public class NumberUtils { |
||||
|
|
||||
|
public static Double doubleScaleToDouble(Double number, int scale) { |
||||
|
if (null == number || scale < 0) { |
||||
|
return null; |
||||
|
} |
||||
|
return BigDecimal.valueOf(number).setScale(scale, RoundingMode.HALF_EVEN).doubleValue(); |
||||
|
} |
||||
|
|
||||
|
public static BigDecimal doubleScaleToBigDecimal(Double number, int scale) { |
||||
|
if (null == number || scale < 0) { |
||||
|
return null; |
||||
|
} |
||||
|
return BigDecimal.valueOf(number).setScale(scale, RoundingMode.HALF_EVEN); |
||||
|
} |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
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.web.bind.annotation.GetMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("/report/aj") |
||||
|
public class AjReportController { |
||||
|
|
||||
|
@Autowired |
||||
|
private AjReportService ajReportService; |
||||
|
|
||||
|
@GetMapping("/heatExchangeStation/data") |
||||
|
public List<Map<String, Object>> getReportDataList(ReportReq reportReq) { |
||||
|
return ajReportService.getReportDataList(reportReq); |
||||
|
} |
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
package com.lzbi.report.domain.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class ReportDTO { |
||||
|
|
||||
|
/** |
||||
|
* 统计单元编码 |
||||
|
*/ |
||||
|
private String assetCode; |
||||
|
/** |
||||
|
* 统计单元名称 |
||||
|
*/ |
||||
|
private String assetName; |
||||
|
/** |
||||
|
* 指标/参数编码 |
||||
|
*/ |
||||
|
private String targetModelCode; |
||||
|
/** |
||||
|
* 分区 |
||||
|
*/ |
||||
|
private String partition; |
||||
|
/** |
||||
|
* 和值 |
||||
|
*/ |
||||
|
private Double valSum; |
||||
|
/** |
||||
|
* 有效值数量 |
||||
|
*/ |
||||
|
private Integer valTotal; |
||||
|
/** |
||||
|
* 最新值 |
||||
|
*/ |
||||
|
private Double valLast; |
||||
|
} |
@ -0,0 +1,34 @@ |
|||||
|
package com.lzbi.report.domain.query; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Data |
||||
|
public class ReportQuery { |
||||
|
|
||||
|
/** |
||||
|
* 组织id |
||||
|
*/ |
||||
|
private Long orgId; |
||||
|
/** |
||||
|
* 查询日期 |
||||
|
*/ |
||||
|
private String countDate; |
||||
|
/** |
||||
|
* 统计单元类别 |
||||
|
*/ |
||||
|
private String assetType; |
||||
|
/** |
||||
|
* 统计单元级别 |
||||
|
*/ |
||||
|
private String assetLevel; |
||||
|
/** |
||||
|
* 指标/参数模板编码列表 |
||||
|
*/ |
||||
|
private List<String> targetModelCodeList; |
||||
|
/** |
||||
|
* T指标P参数 |
||||
|
*/ |
||||
|
private String columnType; |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
package com.lzbi.report.domain.req; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* 报表查询参数 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class ReportReq { |
||||
|
|
||||
|
/** |
||||
|
* 组织id |
||||
|
*/ |
||||
|
private Long orgId; |
||||
|
/** |
||||
|
* 查询日期 |
||||
|
*/ |
||||
|
private String countDate; |
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
package com.lzbi.report.domain.vo; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Data |
||||
|
public class ReportVO { |
||||
|
|
||||
|
/** |
||||
|
* 统计单元编码 |
||||
|
*/ |
||||
|
private String assetCode; |
||||
|
/** |
||||
|
* 统计单元名称 |
||||
|
*/ |
||||
|
private String assetName; |
||||
|
/** |
||||
|
* 分区 |
||||
|
*/ |
||||
|
private String partition; |
||||
|
/** |
||||
|
* 供热面积 |
||||
|
*/ |
||||
|
private Double supplyArea; |
||||
|
|
||||
|
private Map<String, Double> values; |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
package com.lzbi.report.mapper; |
||||
|
|
||||
|
import com.lzbi.report.domain.dto.ReportDTO; |
||||
|
import com.lzbi.report.domain.query.ReportQuery; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public interface AjReportMapper { |
||||
|
|
||||
|
/** |
||||
|
* 获取统计单元和分区组合字符串列表 |
||||
|
* @param reportQuery |
||||
|
* @return concat(assetCode, -, partition) |
||||
|
*/ |
||||
|
List<String> getAssetAndPartitionList(ReportQuery reportQuery); |
||||
|
|
||||
|
/** |
||||
|
* 获取报表数据列表 |
||||
|
* @param reportQuery |
||||
|
* @return |
||||
|
*/ |
||||
|
List<ReportDTO> getReportDataList(ReportQuery reportQuery); |
||||
|
} |
@ -0,0 +1,159 @@ |
|||||
|
package com.lzbi.report.service; |
||||
|
|
||||
|
import com.lzbi.common.constant.BizConstants; |
||||
|
import com.lzbi.common.constant.ParamsModelCodeConstants; |
||||
|
import com.lzbi.common.constant.PartitionConstants; |
||||
|
import com.lzbi.common.utils.NumberUtils; |
||||
|
import com.lzbi.external.service.ParamsService; |
||||
|
import com.lzbi.report.domain.dto.ReportDTO; |
||||
|
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.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.util.CollectionUtils; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
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.stream.Collectors; |
||||
|
|
||||
|
@Service |
||||
|
public class AjReportService { |
||||
|
|
||||
|
@Resource |
||||
|
private AjReportMapper ajReportMapper; |
||||
|
|
||||
|
@Autowired |
||||
|
private ParamsService paramsService; |
||||
|
|
||||
|
public List<Map<String, Object>> getReportDataList(ReportReq reportReq) { |
||||
|
List<Map<String, Object>> list = new ArrayList<>(); |
||||
|
if (StringUtils.isBlank(reportReq.getCountDate())) { |
||||
|
reportReq.setCountDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); |
||||
|
} |
||||
|
List<String> targetModelCodeList = new ArrayList<>(14); |
||||
|
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.电调阀开度给定); |
||||
|
targetModelCodeList.add(ParamsModelCodeConstants.电调阀开度反馈); |
||||
|
targetModelCodeList.add(ParamsModelCodeConstants.水箱水位计); |
||||
|
ReportQuery reportQuery = new ReportQuery(); |
||||
|
reportQuery.setOrgId(reportReq.getOrgId()); |
||||
|
reportQuery.setCountDate(reportReq.getCountDate()); |
||||
|
reportQuery.setAssetLevel(BizConstants.DcAssetLevel.HEAT_EXCHANGE_STATION); |
||||
|
reportQuery.setAssetType(BizConstants.DcAssetType.COMPUTE); |
||||
|
reportQuery.setColumnType(BizConstants.ColumnType.PARAM); |
||||
|
reportQuery.setTargetModelCodeList(targetModelCodeList); |
||||
|
List<String> assetAndPartitionList = ajReportMapper.getAssetAndPartitionList(reportQuery); |
||||
|
if (CollectionUtils.isEmpty(assetAndPartitionList)) { |
||||
|
throw new RuntimeException("未配置统计单元"); |
||||
|
} |
||||
|
List<ReportDTO> reportDataList = ajReportMapper.getReportDataList(reportQuery); |
||||
|
if (CollectionUtils.isEmpty(reportDataList)) { |
||||
|
throw new RuntimeException("无数据"); |
||||
|
} |
||||
|
Map<String, List<ReportDTO>> reportDataMap = reportDataList.stream().collect(Collectors.groupingBy(item -> StringUtils.join(item.getAssetCode(), "-", item.getPartition()))); |
||||
|
List<String> assetCodeList = reportDataList.stream().map(ReportDTO::getAssetCode).collect(Collectors.toList()); |
||||
|
// 获取供热面积
|
||||
|
Map<String, Double> multipleAssetSupplyArea = paramsService.getMultipleAssetSupplyArea(assetCodeList); |
||||
|
assetAndPartitionList.forEach(assetAndPartition -> { |
||||
|
if (reportDataMap.containsKey(assetAndPartition)) { |
||||
|
Map<String, Object> reportVO = new HashMap<>(); |
||||
|
List<ReportDTO> reportDTOList = reportDataMap.get(assetAndPartition); |
||||
|
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())); |
||||
|
if (!CollectionUtils.isEmpty(multipleAssetSupplyArea) && multipleAssetSupplyArea.containsKey(assetCode)) { |
||||
|
reportVO.put("supplyArea", multipleAssetSupplyArea.get(assetCode)); |
||||
|
} |
||||
|
Map<String, ReportDTO> targetDataMap = reportDTOList.stream().collect(Collectors.toMap(ReportDTO::getTargetModelCode, item -> item, (v1, v2) -> v2)); |
||||
|
targetModelCodeList.forEach(targetModelCode -> getValue(reportVO, targetDataMap.get(targetModelCode), targetModelCode)); |
||||
|
this.calculateExtraCellValue(reportVO); |
||||
|
list.add(reportVO); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
return list; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 计算其他单元格数值 |
||||
|
* @param reportVO |
||||
|
*/ |
||||
|
private void calculateExtraCellValue(Map<String, Object> reportVO) { |
||||
|
if (CollectionUtils.isEmpty(reportVO)) { |
||||
|
return; |
||||
|
} |
||||
|
Object b = reportVO.get("supplyArea"); |
||||
|
Object d = reportVO.get(ParamsModelCodeConstants.瞬时流量); |
||||
|
Object e = reportVO.get(ParamsModelCodeConstants.瞬时热量); |
||||
|
Object g = reportVO.get(ParamsModelCodeConstants.一次网供温); |
||||
|
Object h = reportVO.get(ParamsModelCodeConstants.一次网回温); |
||||
|
Object i = reportVO.get(ParamsModelCodeConstants.一次网供压); |
||||
|
Object j = reportVO.get(ParamsModelCodeConstants.一次网回压); |
||||
|
Object k = reportVO.get(ParamsModelCodeConstants.二次网供水温); |
||||
|
Object l = reportVO.get(ParamsModelCodeConstants.二次网回水温); |
||||
|
Object m = reportVO.get(ParamsModelCodeConstants.二次网供水压力); |
||||
|
Object n = reportVO.get(ParamsModelCodeConstants.二次网回水压力); |
||||
|
if (null != d && null != e && !e.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); |
||||
|
BigDecimal e1 = BigDecimal.valueOf((Double) e); |
||||
|
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)); |
||||
|
} |
||||
|
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)); |
||||
|
} |
||||
|
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)); |
||||
|
} |
||||
|
if (null != m && null != n) { |
||||
|
reportVO.put("c8", NumberUtils.doubleScaleToBigDecimal((Double) m - (Double) n, 2)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void getValue(Map<String, Object> reportVO, ReportDTO reportDTO, String targetModelCode) { |
||||
|
Double value = null; |
||||
|
if (null != reportDTO) { |
||||
|
switch (reportDTO.getTargetModelCode()) { |
||||
|
case ParamsModelCodeConstants.累计热量: |
||||
|
value = reportDTO.getValLast(); |
||||
|
break; |
||||
|
default: |
||||
|
if (null != reportDTO.getValSum() && null != reportDTO.getValTotal() && reportDTO.getValTotal() > 0) { |
||||
|
value = NumberUtils.doubleScaleToDouble(reportDTO.getValSum()/reportDTO.getValTotal(), 2); |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
reportVO.put(targetModelCode, value); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,60 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||
|
<!DOCTYPE mapper |
||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="com.lzbi.report.mapper.AjReportMapper"> |
||||
|
|
||||
|
<select id="getAssetAndPartitionList" |
||||
|
parameterType="com.lzbi.report.domain.query.ReportQuery" |
||||
|
resultType="java.lang.String"> |
||||
|
select |
||||
|
concat(t.asset_code, '-', t.goal_param_ext2) |
||||
|
from |
||||
|
( |
||||
|
select |
||||
|
distinct |
||||
|
t1.asset_code, |
||||
|
t2.goal_param_ext2 |
||||
|
from |
||||
|
dc_base_asset_info t1 |
||||
|
left join dc_busi_work_read_config t2 on t1.asset_code = t2.asset_code |
||||
|
where |
||||
|
t1.org_id = #{orgId} |
||||
|
and t1.asset_type = #{assetType} |
||||
|
and t1.asset_level = #{assetLevel} |
||||
|
order by |
||||
|
t1.asset_code asc, |
||||
|
t2.goal_param_ext2 asc |
||||
|
) t |
||||
|
</select> |
||||
|
|
||||
|
<select id="getReportDataList" |
||||
|
parameterType="com.lzbi.report.domain.query.ReportQuery" |
||||
|
resultType="com.lzbi.report.domain.dto.ReportDTO"> |
||||
|
select |
||||
|
t1.asset_code as "assetCode", |
||||
|
t1.asset_name as "assetName", |
||||
|
t2.target_model_code as "targetModelCode", |
||||
|
t3.goal_param_ext2 as "partition", |
||||
|
t4.val_sum as "valSum", |
||||
|
t4.val_total as "valTotal", |
||||
|
t4.val_last as "valLast" |
||||
|
from |
||||
|
dc_base_asset_info t1 |
||||
|
left join dc_base_asset_target t2 on t1.asset_code = t2.asset_code |
||||
|
and t2.target_model_code in |
||||
|
<foreach collection="targetModelCodeList" item="targetModelCode" open="(" separator="," close=")"> |
||||
|
#{targetModelCode} |
||||
|
</foreach> |
||||
|
and t2.column_type = #{columnType} |
||||
|
left join dc_busi_work_read_config t3 on t2.target_code = t3.asset_param_code |
||||
|
left join dc_busi_param_draft_day t4 on t2.target_code = t4.param_code and t4.count_date = #{countDate} |
||||
|
where |
||||
|
t1.org_id = #{orgId} |
||||
|
and t1.asset_type = #{assetType} |
||||
|
and t1.asset_level = #{assetLevel} |
||||
|
order by |
||||
|
t1.asset_code asc, |
||||
|
t3.goal_param_ext2 asc |
||||
|
</select> |
||||
|
</mapper> |
Loading…
Reference in new issue