|
@@ -8,6 +8,7 @@ import com.usky.demo.RemoteTsdbProxyService;
|
|
|
import com.usky.demo.domain.EnergyItemSumQueryVO;
|
|
import com.usky.demo.domain.EnergyItemSumQueryVO;
|
|
|
import com.usky.demo.domain.EnergyItemSumResultVO;
|
|
import com.usky.demo.domain.EnergyItemSumResultVO;
|
|
|
import com.usky.ems.domain.*;
|
|
import com.usky.ems.domain.*;
|
|
|
|
|
+import com.usky.ems.enums.EnergyTypeEnum;
|
|
|
import com.usky.ems.mapper.DmpProductMapper;
|
|
import com.usky.ems.mapper.DmpProductMapper;
|
|
|
import com.usky.ems.mapper.EmsDeviceMapper;
|
|
import com.usky.ems.mapper.EmsDeviceMapper;
|
|
|
import com.usky.ems.mapper.EmsEnergyItemCodeMapper;
|
|
import com.usky.ems.mapper.EmsEnergyItemCodeMapper;
|
|
@@ -243,11 +244,11 @@ public class EmsOverviewServiceImpl implements EmsOverviewService {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- BigDecimal data = sumEnergyByProductCodes(productCodeList, identifier, startTime, endTime);
|
|
|
|
|
|
|
+ BigDecimal data = sumEnergyByProductCodes(productCodeList, identifier.toLowerCase(), startTime, endTime);
|
|
|
|
|
|
|
|
LocalDateTime pariPassuEndTime = endTime.minusYears(1);
|
|
LocalDateTime pariPassuEndTime = endTime.minusYears(1);
|
|
|
LocalDateTime pariPassuStartTime = getStartTime(dateType, pariPassuEndTime);
|
|
LocalDateTime pariPassuStartTime = getStartTime(dateType, pariPassuEndTime);
|
|
|
- BigDecimal pariPassuData = sumEnergyByProductCodes(productCodeList, identifier, pariPassuStartTime, pariPassuEndTime);
|
|
|
|
|
|
|
+ BigDecimal pariPassuData = sumEnergyByProductCodes(productCodeList, identifier.toLowerCase(), pariPassuStartTime, pariPassuEndTime);
|
|
|
|
|
|
|
|
LocalDateTime sequentialEndTime;
|
|
LocalDateTime sequentialEndTime;
|
|
|
if (dateType == 1) {
|
|
if (dateType == 1) {
|
|
@@ -258,7 +259,7 @@ public class EmsOverviewServiceImpl implements EmsOverviewService {
|
|
|
sequentialEndTime = endTime.minusYears(1);
|
|
sequentialEndTime = endTime.minusYears(1);
|
|
|
}
|
|
}
|
|
|
LocalDateTime sequentialStartTime = getStartTime(dateType, sequentialEndTime);
|
|
LocalDateTime sequentialStartTime = getStartTime(dateType, sequentialEndTime);
|
|
|
- BigDecimal sequentialData = sumEnergyByProductCodes(productCodeList, identifier, sequentialStartTime, sequentialEndTime);
|
|
|
|
|
|
|
+ BigDecimal sequentialData = sumEnergyByProductCodes(productCodeList, identifier.toLowerCase(), sequentialStartTime, sequentialEndTime);
|
|
|
|
|
|
|
|
return buildClassificationResult(data, sequentialData, pariPassuData, coalFactor, co2Factor);
|
|
return buildClassificationResult(data, sequentialData, pariPassuData, coalFactor, co2Factor);
|
|
|
}
|
|
}
|
|
@@ -582,7 +583,6 @@ public class EmsOverviewServiceImpl implements EmsOverviewService {
|
|
|
* 单位综合能耗、综合累计能耗、分类能耗占比(总览顶部)
|
|
* 单位综合能耗、综合累计能耗、分类能耗占比(总览顶部)
|
|
|
* - 能源类型来自 EmsModelService.getEnergyTypeList(电/水/气)
|
|
* - 能源类型来自 EmsModelService.getEnergyTypeList(电/水/气)
|
|
|
* - 折算系数来自 leo.ems_project_conversion_factor(优先取项目专属,其次 project_id=0 的公共配置)
|
|
* - 折算系数来自 leo.ems_project_conversion_factor(优先取项目专属,其次 project_id=0 的公共配置)
|
|
|
- * - 真实 TSDB 能耗数据暂不可用,当前按规则模拟各能源类型的能耗值。
|
|
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public Map<String, Object> queryOverviewTop(Integer dateType, Long projectId) {
|
|
public Map<String, Object> queryOverviewTop(Integer dateType, Long projectId) {
|
|
@@ -599,8 +599,8 @@ public class EmsOverviewServiceImpl implements EmsOverviewService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 项目信息(含面积、根空间 ID)
|
|
// 项目信息(含面积、根空间 ID)
|
|
|
- Integer resolvedProjectId = projectId != null ? projectId.intValue() : null;
|
|
|
|
|
- EmsProjectResponse project = getProject(resolvedProjectId);
|
|
|
|
|
|
|
+ Long resolvedProjectId = resolveProjectId(projectId);
|
|
|
|
|
+ EmsProjectResponse project = getProject(Math.toIntExact(resolvedProjectId));
|
|
|
if (project == null || project.getSpaceId() == null) {
|
|
if (project == null || project.getSpaceId() == null) {
|
|
|
return resultMap;
|
|
return resultMap;
|
|
|
}
|
|
}
|
|
@@ -620,102 +620,62 @@ public class EmsOverviewServiceImpl implements EmsOverviewService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 2. 查询折算系数(项目专属 + 公共)
|
|
// 2. 查询折算系数(项目专属 + 公共)
|
|
|
-// List<EmsProjectConversionFactor> factorList = emsProjectConversionFactorMapper.selectList(
|
|
|
|
|
-// new LambdaQueryWrapper<EmsProjectConversionFactor>()
|
|
|
|
|
-// .in(EmsProjectConversionFactor::getEnergyType, typeIds)
|
|
|
|
|
-// .in(EmsProjectConversionFactor::getProjectId, pid, 0L)
|
|
|
|
|
-// );
|
|
|
|
|
-// if (factorList == null || factorList.isEmpty()) {
|
|
|
|
|
-// return resultMap;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// // 优先使用项目专属配置;若没有则退回公共配置
|
|
|
|
|
-// Map<Integer, List<EmsProjectConversionFactor>> groupedByType = factorList.stream()
|
|
|
|
|
-// .collect(Collectors.groupingBy(EmsProjectConversionFactor::getEnergyType));
|
|
|
|
|
-
|
|
|
|
|
- // 3. 模拟各能源类型能耗值(真实实现应从 TSDB 或历史统计表获取)
|
|
|
|
|
- Map<Integer, BigDecimal> consumeMap = new HashMap<>();
|
|
|
|
|
- BigDecimal base = new BigDecimal("1000");
|
|
|
|
|
- BigDecimal step = new BigDecimal("200");
|
|
|
|
|
- BigDecimal factor;
|
|
|
|
|
- if (dateType == 1) {
|
|
|
|
|
- factor = BigDecimal.ONE;
|
|
|
|
|
- } else if (dateType == 2) {
|
|
|
|
|
- factor = new BigDecimal("1.5");
|
|
|
|
|
- } else if (dateType == 3) {
|
|
|
|
|
- factor = new BigDecimal("2.0");
|
|
|
|
|
- } else {
|
|
|
|
|
- factor = BigDecimal.ONE;
|
|
|
|
|
|
|
+ List<EmsProjectConversionFactor> factorList = emsProjectConversionFactorMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<EmsProjectConversionFactor>()
|
|
|
|
|
+ .in(EmsProjectConversionFactor::getEnergyType, typeIds)
|
|
|
|
|
+ .in(EmsProjectConversionFactor::getProjectId, resolvedProjectId, 0L)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (factorList == null || factorList.isEmpty()) {
|
|
|
|
|
+ return resultMap;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- int index = 0;
|
|
|
|
|
- for (Integer typeId : typeIds) {
|
|
|
|
|
- BigDecimal value = base.subtract(step.multiply(BigDecimal.valueOf(index))).multiply(factor);
|
|
|
|
|
- if (value.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
|
- value = BigDecimal.ZERO;
|
|
|
|
|
|
|
+ Map<Integer, BigDecimal> map = new HashMap();
|
|
|
|
|
+
|
|
|
|
|
+ for(Integer energyType : typeIds) {
|
|
|
|
|
+ if (energyType != 5) {
|
|
|
|
|
+ EnergyTypeEnum typeEnum = EnergyTypeEnum.get(energyType);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ List<String> productCodeList = dmpProductMapper.selectProductCodesByEnergyType(
|
|
|
|
|
+ SecurityUtils.getTenantId(), energyType);
|
|
|
|
|
+ if (productCodeList == null || productCodeList.isEmpty()) {
|
|
|
|
|
+ return resultMap;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal data = sumEnergyByProductCodes(productCodeList, typeEnum.getCode(), startTime, endTime);
|
|
|
|
|
+ map.put(energyType, data);
|
|
|
}
|
|
}
|
|
|
- consumeMap.put(typeId, value);
|
|
|
|
|
- index++;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- BigDecimal totalCon = consumeMap.values().stream()
|
|
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
-
|
|
|
|
|
- // 4. 计算各能源类型折算标煤与碳排放、占比
|
|
|
|
|
|
|
+ Map<Integer, List<EmsProjectConversionFactor>> listMap = (Map)factorList.stream().collect(Collectors.groupingBy(EmsProjectConversionFactor::getEnergyType));
|
|
|
BigDecimal coalTotal = BigDecimal.ZERO;
|
|
BigDecimal coalTotal = BigDecimal.ZERO;
|
|
|
BigDecimal co2Total = BigDecimal.ZERO;
|
|
BigDecimal co2Total = BigDecimal.ZERO;
|
|
|
- List<Map<String, Object>> ratioList = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
-// for (EmsEnergyTypeVO typeVO : energyTypes) {
|
|
|
|
|
-// if (typeVO.getId() == null) {
|
|
|
|
|
-// continue;
|
|
|
|
|
-// }
|
|
|
|
|
-// Integer typeId = typeVO.getId().intValue();
|
|
|
|
|
-// BigDecimal con = consumeMap.get(typeId);
|
|
|
|
|
-// if (con == null) {
|
|
|
|
|
-// continue;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// List<EmsProjectConversionFactor> conversionFactorList = groupedByType.get(typeId);
|
|
|
|
|
-// if (conversionFactorList == null || conversionFactorList.isEmpty()) {
|
|
|
|
|
-// continue;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// // 先筛出项目专属配置
|
|
|
|
|
-// List<EmsProjectConversionFactor> projectFactors = conversionFactorList.stream()
|
|
|
|
|
-// .filter(f -> pid.equals(f.getProjectId()))
|
|
|
|
|
-// .collect(Collectors.toList());
|
|
|
|
|
-// List<EmsProjectConversionFactor> effectiveFactors = projectFactors.isEmpty()
|
|
|
|
|
-// ? conversionFactorList
|
|
|
|
|
-// : projectFactors;
|
|
|
|
|
-//
|
|
|
|
|
-// Map<String, BigDecimal> factorMap = effectiveFactors.stream()
|
|
|
|
|
-// .filter(f -> f.getName() != null && f.getValue() != null)
|
|
|
|
|
-// .collect(Collectors.toMap(EmsProjectConversionFactor::getName, EmsProjectConversionFactor::getValue,
|
|
|
|
|
-// (oldVal, newVal) -> oldVal));
|
|
|
|
|
-//
|
|
|
|
|
-// BigDecimal coal = factorMap.get("coal");
|
|
|
|
|
-// if (coal == null) {
|
|
|
|
|
-// continue;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// BigDecimal coalAmount = coal.multiply(con).setScale(2, RoundingMode.UP);
|
|
|
|
|
-// BigDecimal co2Amount = coalAmount.multiply(new BigDecimal("2.4589")).setScale(2, RoundingMode.UP);
|
|
|
|
|
-// coalTotal = coalTotal.add(coalAmount);
|
|
|
|
|
-// co2Total = co2Total.add(co2Amount);
|
|
|
|
|
-//
|
|
|
|
|
-// Map<String, Object> ratioMap = new HashMap<>();
|
|
|
|
|
-// ratioMap.put("name", typeVO.getName());
|
|
|
|
|
-// ratioMap.put("consume", coalAmount);
|
|
|
|
|
-// ratioMap.put("totalConsume", totalCon.multiply(coal).setScale(2, RoundingMode.UP));
|
|
|
|
|
-// ratioList.add(ratioMap);
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ BigDecimal totalCon = (BigDecimal)map.values().stream().reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ List<Map<String, Object>> ratioList = new ArrayList();
|
|
|
|
|
+
|
|
|
|
|
+ for(Integer energyType : typeIds) {
|
|
|
|
|
+ if (energyType != 5) {
|
|
|
|
|
+ BigDecimal con = (BigDecimal)map.get(energyType);
|
|
|
|
|
+ List<EmsProjectConversionFactor> conversionFactorList = (List)listMap.get(energyType);
|
|
|
|
|
+ if (conversionFactorList != null && !conversionFactorList.isEmpty()) {
|
|
|
|
|
+ Map<String, BigDecimal> factorMap = (Map)conversionFactorList.stream().collect(Collectors.toMap(EmsProjectConversionFactor::getName, EmsProjectConversionFactor::getValue));
|
|
|
|
|
+ BigDecimal coal = (BigDecimal)factorMap.get("coal");
|
|
|
|
|
+ BigDecimal coalAmount = coal.multiply(con).setScale(2, RoundingMode.UP);
|
|
|
|
|
+ BigDecimal co2Amount = coalAmount.multiply(new BigDecimal("2.4589")).setScale(2, RoundingMode.UP);
|
|
|
|
|
+ coalTotal = coalTotal.add(coalAmount);
|
|
|
|
|
+ co2Total = co2Total.add(co2Amount);
|
|
|
|
|
+ EnergyTypeEnum typeEnum = EnergyTypeEnum.get(energyType);
|
|
|
|
|
+ Map<String, Object> ratioMap = new HashMap();
|
|
|
|
|
+ ratioMap.put("name", typeEnum.getName());
|
|
|
|
|
+ ratioMap.put("consume", con.multiply(coal).setScale(2, RoundingMode.UP));
|
|
|
|
|
+ ratioMap.put("totalConsume", totalCon.multiply(coal).setScale(2, RoundingMode.UP));
|
|
|
|
|
+ ratioList.add(ratioMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 5. 单位综合能耗(每平米标煤量)
|
|
|
|
|
BigDecimal unitCoal = BigDecimal.ZERO;
|
|
BigDecimal unitCoal = BigDecimal.ZERO;
|
|
|
- if (project.getArea() != null
|
|
|
|
|
- && project.getArea().compareTo(BigDecimal.ZERO) != 0
|
|
|
|
|
- && coalTotal.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
|
|
|
+ if (project.getArea() != null && project.getArea().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
unitCoal = coalTotal.divide(project.getArea(), 2, RoundingMode.UP);
|
|
unitCoal = coalTotal.divide(project.getArea(), 2, RoundingMode.UP);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -724,6 +684,8 @@ public class EmsOverviewServiceImpl implements EmsOverviewService {
|
|
|
resultMap.put("coalTotal", coalTotal);
|
|
resultMap.put("coalTotal", coalTotal);
|
|
|
resultMap.put("co2Total", co2Total);
|
|
resultMap.put("co2Total", co2Total);
|
|
|
return resultMap;
|
|
return resultMap;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|