|
@@ -11,15 +11,20 @@ import com.bizmatics.common.mvc.base.AbstractCrudService;
|
|
|
import com.bizmatics.common.spring.util.GlobalUtils;
|
|
|
import com.bizmatics.common.spring.util.JsonUtils;
|
|
|
import com.bizmatics.model.*;
|
|
|
+import com.bizmatics.model.utils.TimeRangeParams;
|
|
|
+import com.bizmatics.model.utils.TimeRangeUtils;
|
|
|
import com.bizmatics.model.vo.*;
|
|
|
import com.bizmatics.persistence.mapper.*;
|
|
|
import com.bizmatics.service.*;
|
|
|
+import com.bizmatics.service.util.AnalogCache;
|
|
|
import com.bizmatics.service.util.FieldEscapeUtils;
|
|
|
import com.bizmatics.service.util.SecurityUtils;
|
|
|
+import com.bizmatics.service.util.SiteFeeCacheService;
|
|
|
import com.bizmatics.service.vo.*;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -76,6 +81,12 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
private SiteElectricityRecordMapper siteElectricityRecordMapper;
|
|
|
@Autowired
|
|
|
private ElectricityTimePriceMapper electricityTimePriceMapper;
|
|
|
+ @Autowired
|
|
|
+ private AnalogCache analogCache;
|
|
|
+ @Autowired
|
|
|
+ private SiteFeeCacheService siteFeeCacheService;
|
|
|
+
|
|
|
+ private static final BigDecimal ZERO = BigDecimal.ZERO;
|
|
|
|
|
|
@Override
|
|
|
public HadCountVO selectCount() {
|
|
@@ -1514,9 +1525,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
return new HtAnalogEnergyConsumptionVo();
|
|
|
}
|
|
|
|
|
|
- // LocalDate time = localDateTime.toLocalDate();
|
|
|
// 上个月的同一天
|
|
|
- // LocalDate sameDayLastMonth = time.minusMonths(1);
|
|
|
LocalDate today = time.toLocalDate();
|
|
|
LocalDate yesterday1 = today.minusDays(1);
|
|
|
LocalDate lastMonth = today.minusMonths(1);
|
|
@@ -1558,76 +1567,75 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
BigDecimal coefficient = new BigDecimal(siteDynamicProperties.getDemolitionStandardCoal1())
|
|
|
.divide(new BigDecimal(demolitionStandardCoal), 10, RoundingMode.DOWN);
|
|
|
|
|
|
+ // 时间范围
|
|
|
+ TimeRangeUtils.TimeRanges ranges = TimeRangeUtils.getAllTimeRanges(time);
|
|
|
+
|
|
|
switch (timeType) {
|
|
|
// 概览
|
|
|
case "overview":
|
|
|
if (!data183.isEmpty()) {
|
|
|
- dayList = getAnalogData(data183.get(0), time, 1);
|
|
|
- monthList = getAnalogData(data183.get(0), time, 2);
|
|
|
- yearList = getAnalogData(data183.get(0), time, 3);
|
|
|
-
|
|
|
- yesterday = getAnalogData(data183.get(0), time.minusDays(1), 1);
|
|
|
- // 上月同期
|
|
|
- sameDayLastMonthList = getAnalogData(data183.get(0), time, 22);
|
|
|
- // 上年同期
|
|
|
- sameDayLastYearList = getAnalogData(data183.get(0), time, 33);
|
|
|
-
|
|
|
+ String deviceCode183 = data183.get(0);
|
|
|
if (consume == 1) {
|
|
|
- // 昨日同期
|
|
|
- List<HtAnalogData> yesterdatSameTimeList = getAnalogData(data183.get(0), time, 11);
|
|
|
- List<HtAnalogData> sameDayLastMonth = getAnalogData(data183.get(0), time.minusMonths(1), 2);
|
|
|
- List<HtAnalogData> sameDayLastYear = getAnalogData(data183.get(0), time.minusYears(1), 3);
|
|
|
+ Map<String, BigDecimal> result = analogCache.get(deviceCode183, ranges);
|
|
|
+ BigDecimal today1 = result.get("today");
|
|
|
+ BigDecimal month1 = result.get("month");
|
|
|
+ BigDecimal year1 = result.get("year");
|
|
|
+ BigDecimal yesterday2 = result.get("yesterday");
|
|
|
+ BigDecimal lastMonth1 = result.get("last_month");
|
|
|
+ BigDecimal lastYear1 = result.get("last_year");
|
|
|
+ BigDecimal sameDay = result.get("same_day");
|
|
|
+ BigDecimal sameMonth = result.get("same_month");
|
|
|
+ BigDecimal sameYear = result.get("same_year");
|
|
|
+ BigDecimal lastYearSameDay = result.get("last_year_same_day");
|
|
|
+ BigDecimal lastYearSameMonth = result.get("last_year_same_month");
|
|
|
+
|
|
|
+ // 电
|
|
|
+ vo.setTodayElectricity(today1);
|
|
|
+ vo.setMonthElectricity(month1);
|
|
|
+ vo.setYearElectricity(year1);
|
|
|
+ vo.setYesterdayElectricity(yesterday2);
|
|
|
+ vo.setLastMonthElectricity(lastMonth1);
|
|
|
+ vo.setLastYearElectricity(lastYear1);
|
|
|
|
|
|
- vo.setTodayElectricity(getTotal(dayList));
|
|
|
- vo.setMonthElectricity(getTotal(monthList));
|
|
|
- vo.setYearElectricity(getTotal(yearList));
|
|
|
- vo.setYesterdayElectricity(getTotal(yesterday));
|
|
|
- vo.setLastMonthElectricity(getTotal(sameDayLastMonth));
|
|
|
- vo.setLastYearElectricity(getTotal(sameDayLastYear));
|
|
|
-
|
|
|
- vo.setTodayRingRatio(getRingRatio(dayList, yesterdatSameTimeList));
|
|
|
- vo.setMonthRingRatio(getRingRatio(monthList, sameDayLastMonthList));
|
|
|
- vo.setYearRingRatio(getRingRatio(yearList, sameDayLastYearList));
|
|
|
-
|
|
|
- vo.setToday(getTotal(dayList).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
- vo.setYesterday(getTotal(yesterday).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
- vo.setMonth(getTotal(monthList).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
- vo.setLastMonth(getTotal(sameDayLastMonth).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
- vo.setYear(getTotal(yearList).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
- vo.setLastYear(getTotal(sameDayLastYear).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
-
|
|
|
- // 调试输出
|
|
|
- System.out.println("昨日同期:" + getTotal(yesterdatSameTimeList));
|
|
|
- System.out.println("上月同期:" + getTotal(sameDayLastMonthList));
|
|
|
- System.out.println("去年同期:" + getTotal(sameDayLastYearList));
|
|
|
+ // 环比
|
|
|
+ vo.setTodayRingRatio(ringRatio(today1, sameDay));
|
|
|
+ vo.setMonthRingRatio(ringRatio(month1, sameMonth));
|
|
|
+ vo.setYearRingRatio(ringRatio(year1, sameYear));
|
|
|
|
|
|
+ // 能耗
|
|
|
+ vo.setToday(scale(today1, coefficient));
|
|
|
+ vo.setMonth(scale(month1, coefficient));
|
|
|
+ vo.setYear(scale(year1, coefficient));
|
|
|
+ vo.setYesterday(scale(yesterday2, coefficient));
|
|
|
+ vo.setLastMonth(scale(lastMonth1, coefficient));
|
|
|
+ vo.setLastYear(scale(lastYear1, coefficient));
|
|
|
} else if (consume == 2) {
|
|
|
// 1. 计算电量 & 基础费用
|
|
|
- ElectricityRateConfig cfg = getElectricityRateConfig(siteId);
|
|
|
+ // ElectricityRateConfig cfg = getElectricityRateConfig(siteId);
|
|
|
|
|
|
- BigDecimal dayElectricity = getTotal(dayList);
|
|
|
- BigDecimal monthElectricity = getTotal(monthList);
|
|
|
- BigDecimal yearElectricity = getTotal(yearList);
|
|
|
- BigDecimal sameDayElectricity = getTotal(yesterday);
|
|
|
- BigDecimal sameMonthElectricity = getTotal(sameDayLastMonthList);
|
|
|
- BigDecimal sameYearElectricity = getTotal(sameDayLastYearList);
|
|
|
+ // BigDecimal dayElectricity = getTotal(dayList);
|
|
|
+ // BigDecimal monthElectricity = getTotal(monthList);
|
|
|
+ // BigDecimal yearElectricity = getTotal(yearList);
|
|
|
+ // BigDecimal sameDayElectricity = getTotal(yesterday);
|
|
|
+ // BigDecimal sameMonthElectricity = getTotal(sameDayLastMonthList);
|
|
|
+ // BigDecimal sameYearElectricity = getTotal(sameDayLastYearList);
|
|
|
|
|
|
// 基本费用
|
|
|
- BigDecimal dayBasic = getBasicExpenses(dayList, cfg, siteId, dayElectricity);
|
|
|
- BigDecimal monthBasic = getBasicExpenses(monthList, cfg, siteId, monthElectricity);
|
|
|
- BigDecimal yearBasic = getBasicExpenses(yearList, cfg, siteId, yearElectricity);
|
|
|
- BigDecimal sameDayBasic = getBasicExpenses(yesterday, cfg, siteId, sameDayElectricity);
|
|
|
- BigDecimal sameMonthBasic = getBasicExpenses(sameDayLastMonthList, cfg, siteId, sameMonthElectricity);
|
|
|
- BigDecimal sameYearBasic = getBasicExpenses(sameDayLastYearList, cfg, siteId, sameYearElectricity);
|
|
|
+ // BigDecimal dayBasic = getBasicExpenses(dayList, cfg, siteId, dayElectricity);
|
|
|
+ // BigDecimal monthBasic = getBasicExpenses(monthList, cfg, siteId, monthElectricity);
|
|
|
+ // BigDecimal yearBasic = getBasicExpenses(yearList, cfg, siteId, yearElectricity);
|
|
|
+ // BigDecimal sameDayBasic = getBasicExpenses(yesterday, cfg, siteId, sameDayElectricity);
|
|
|
+ // BigDecimal sameMonthBasic = getBasicExpenses(sameDayLastMonthList, cfg, siteId, sameMonthElectricity);
|
|
|
+ // BigDecimal sameYearBasic = getBasicExpenses(sameDayLastYearList, cfg, siteId, sameYearElectricity);
|
|
|
|
|
|
// 3. 费用汇总
|
|
|
- BigDecimal dayCost = calculateTotalCost(calculateTimeFee(siteId, today, 1));//.add(dayBasic);
|
|
|
- BigDecimal monthCost = calculateTotalCost(calculateTimeFee(siteId, today, 2));
|
|
|
- BigDecimal yearCost = calculateTotalCost(calculateTimeFee(siteId, today, 3));
|
|
|
+ BigDecimal dayCost = siteFeeCacheService.getTotalCost(siteId, ranges.getToday(), 1);//.add(dayBasic);
|
|
|
+ BigDecimal monthCost = siteFeeCacheService.getTotalCost(siteId, ranges.getToday(), 2);
|
|
|
+ BigDecimal yearCost = siteFeeCacheService.getTotalCost(siteId, ranges.getToday(), 3);
|
|
|
|
|
|
- BigDecimal yesterdayCost = calculateTotalCost(calculateTimeFee(siteId, yesterday1, 1));//.add(sameDayBasic);
|
|
|
- BigDecimal sameMonthCost = calculateTotalCost(calculateTimeFee(siteId, lastMonth, 22));
|
|
|
- BigDecimal sameYearCost = calculateTotalCost(calculateTimeFee(siteId, lastYear, 33));
|
|
|
+ BigDecimal yesterdayCost = siteFeeCacheService.getTotalCost(siteId, ranges.getYesterdayRange()[0], 1);//.add(sameDayBasic);
|
|
|
+ BigDecimal sameMonthCost = siteFeeCacheService.getTotalCost(siteId, ranges.getSameMonthRange()[1].toLocalDate(), 22);
|
|
|
+ BigDecimal sameYearCost = siteFeeCacheService.getTotalCost(siteId, ranges.getSameYearRange()[1].toLocalDate(), 33);
|
|
|
|
|
|
// 4. 设置值
|
|
|
vo.setTodayCost(dayCost);
|
|
@@ -1638,20 +1646,11 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
vo.setLastYearCost(sameYearCost);
|
|
|
|
|
|
// 日环比
|
|
|
- vo.setDayCostRingRatio(yesterdayCost.compareTo(BigDecimal.ZERO) != 0
|
|
|
- ? dayCost.subtract(yesterdayCost)
|
|
|
- .divide(yesterdayCost, 2, RoundingMode.HALF_UP)
|
|
|
- : BigDecimal.ZERO);
|
|
|
+ vo.setDayCostRingRatio(ringRatio(dayCost, yesterdayCost));
|
|
|
// 月环比
|
|
|
- vo.setMonthCostRingRatio(sameMonthCost.compareTo(BigDecimal.ZERO) != 0
|
|
|
- ? monthCost.subtract(sameMonthCost)
|
|
|
- .divide(sameMonthCost, 2, RoundingMode.HALF_UP)
|
|
|
- : BigDecimal.ZERO);
|
|
|
+ vo.setMonthCostRingRatio(ringRatio(monthCost, sameMonthCost));
|
|
|
// 年环比
|
|
|
- vo.setYearCostRingRatio(sameYearCost.compareTo(BigDecimal.ZERO) != 0
|
|
|
- ? yearCost.subtract(sameYearCost)
|
|
|
- .divide(sameYearCost, 2, RoundingMode.HALF_UP)
|
|
|
- : BigDecimal.ZERO);
|
|
|
+ vo.setYearCostRingRatio(ringRatio(yearCost, sameYearCost));
|
|
|
}
|
|
|
} else if (!data173.isEmpty()) {
|
|
|
dayList173 = get173Data(data173, time, 1);
|
|
@@ -1701,24 +1700,20 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
// 电耗
|
|
|
vo.setTodayElectricity(getTotal(dayList));
|
|
|
// 昨日同期电耗
|
|
|
- vo.setYesterdayElectricity(getTotal(yesterday));
|
|
|
+ // vo.setYesterdayElectricity(getTotal(yesterday));
|
|
|
+ BigDecimal yesterdaySameTimeElectricity = getTotal(yesterday);
|
|
|
// 能耗
|
|
|
- vo.setToday(getTotal(dayList).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
- vo.setYesterday(getTotal(yesterday).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
+ vo.setToday(scale(vo.getTodayElectricity(), coefficient));
|
|
|
+ vo.setYesterday(scale(yesterdaySameTimeElectricity, coefficient));
|
|
|
// 日同期环比
|
|
|
- vo.setTodayRingRatio(getRingRatio(dayList, yesterday));
|
|
|
+ vo.setTodayRingRatio(ringRatio(vo.getTodayElectricity(), yesterdaySameTimeElectricity));
|
|
|
|
|
|
// 上一年同日能耗
|
|
|
List<HtAnalogData> analogData = getAnalogData(data183.get(0), time.minusYears(1), 1);
|
|
|
- BigDecimal sameDayLastYearEnergy = getTotal(analogData).multiply(coefficient).setScale(3, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal sameDayLastYearEnergy = scale(getTotal(analogData), coefficient);
|
|
|
vo.setYearOnYear(sameDayLastYearEnergy);
|
|
|
// 日能耗同比
|
|
|
- vo.setYearOnYearPercent(
|
|
|
- sameDayLastYearEnergy.compareTo(BigDecimal.ZERO) == 0
|
|
|
- ? BigDecimal.ZERO
|
|
|
- : getTotal(dayList).multiply(coefficient)
|
|
|
- .divide(sameDayLastYearEnergy, 3, RoundingMode.HALF_UP)
|
|
|
- );
|
|
|
+ vo.setYearOnYearPercent(ringRatio(vo.getToday(), sameDayLastYearEnergy));
|
|
|
} else if (!data173.isEmpty()) {
|
|
|
dayList173 = get173Data(data173, time, 1);
|
|
|
yesterday173 = get173Data(data173, time.minusDays(1), 1);
|
|
@@ -1745,7 +1740,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
vo.setTodayElectricity(getTotal(dayList));
|
|
|
|
|
|
dayList = getAnalogData(data183.get(0), time, 1);
|
|
|
- yesterday = getAnalogData(data183.get(0), time.minusDays(1), 1);
|
|
|
+ yesterday = getAnalogData(data183.get(0), ranges.getYesterdayTime(), 1);
|
|
|
|
|
|
BigDecimal dayElectricity = getTotal(dayList);
|
|
|
BigDecimal sameDayElectricity = getTotal(yesterday);
|
|
@@ -1755,20 +1750,15 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
BigDecimal yesterdayCost = calculateTotalCost(calculateTimeFee(siteId, yesterday1, 1)).add(sameDayBasic);
|
|
|
vo.setTodayCost(dayCost);
|
|
|
vo.setYesterdayCost(yesterdayCost);
|
|
|
- vo.setDayCostRingRatio(yesterdayCost.compareTo(BigDecimal.ZERO) != 0
|
|
|
- ? dayCost.subtract(yesterdayCost)
|
|
|
- .divide(yesterdayCost, 2, RoundingMode.HALF_UP)
|
|
|
- : BigDecimal.ZERO);
|
|
|
+ vo.setDayCostRingRatio(ringRatio(dayCost, yesterdayCost));
|
|
|
|
|
|
// 上一年同日能耗
|
|
|
- List<HtAnalogData> sameDayLastYear = getAnalogData(data183.get(0), time.minusYears(1), 1);
|
|
|
+ List<HtAnalogData> sameDayLastYear = getAnalogData(data183.get(0), ranges.getLastYearSameDay()[0], 1);
|
|
|
BigDecimal sameDayLastYearElectricity = getTotal(sameDayLastYear);
|
|
|
BigDecimal sameDayLastYearBasic = getBasicExpenses(sameDayLastYear, cfg, siteId, sameDayLastYearElectricity);
|
|
|
BigDecimal sameDayLastYearCost = calculateTotalCost(calculateTimeFee(siteId, lastYear, 1)).add(sameDayLastYearBasic);
|
|
|
vo.setYearOnYear(sameDayLastYearCost);
|
|
|
- vo.setYearOnYearPercent(sameDayLastYearCost.compareTo(BigDecimal.ZERO) != 0
|
|
|
- ? dayCost.subtract(sameDayLastYearCost)
|
|
|
- .divide(sameDayLastYearCost, 2, RoundingMode.HALF_UP) : BigDecimal.ZERO);
|
|
|
+ vo.setYearOnYearPercent(ringRatio(dayCost, sameDayLastYearCost));
|
|
|
|
|
|
} else if (!data173.isEmpty()) {
|
|
|
|
|
@@ -1778,53 +1768,53 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
// 月
|
|
|
case "month":
|
|
|
if (!data183.isEmpty()) {
|
|
|
- monthList = getAnalogData(data183.get(0), time, 2);
|
|
|
- sameDayLastMonthList = getAnalogData(data183.get(0), time.minusMonths(1), 22);
|
|
|
+ String deviceCode183 = data183.get(0);
|
|
|
+ Map<String, BigDecimal> result = analogCache.get(deviceCode183, ranges);
|
|
|
+ BigDecimal month1 = result.get("month");
|
|
|
+ // 电耗
|
|
|
+ vo.setMonthElectricity(month1);
|
|
|
+ // monthList = getAnalogData(deviceCode183, time, 2);
|
|
|
+ // sameDayLastMonthList = getAnalogData(deviceCode183, time.minusMonths(1), 22);
|
|
|
// 上一年同月能耗
|
|
|
- List<HtAnalogData> analogData = getAnalogData(data183.get(0), time.minusYears(1), 2);
|
|
|
+ // List<HtAnalogData> analogData = getAnalogData(deviceCode183, time.minusYears(1), 2);
|
|
|
if (consume == 1) {
|
|
|
- // 电耗
|
|
|
- vo.setMonthElectricity(getTotal(monthList));
|
|
|
- vo.setLastMonthElectricity(getTotal(sameDayLastMonthList));
|
|
|
+ BigDecimal sameMonth = result.get("same_month");
|
|
|
+ BigDecimal lastYearSameMonth = result.get("last_year_same_month");
|
|
|
+ // 上月同期电耗
|
|
|
+ vo.setLastMonthElectricity(sameMonth);
|
|
|
// 能耗
|
|
|
- vo.setMonth(getTotal(monthList).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
- vo.setLastMonth(getTotal(sameDayLastMonthList).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
+ vo.setMonth(scale(month1, coefficient));
|
|
|
+ vo.setLastMonth(scale(sameMonth, coefficient));
|
|
|
// 同期环比
|
|
|
- vo.setMonthRingRatio(getRingRatio(monthList, sameDayLastMonthList));
|
|
|
+ vo.setMonthRingRatio(ringRatio(month1, sameMonth));
|
|
|
|
|
|
- BigDecimal sameMonthLastYearEnergy = getTotal(analogData).multiply(coefficient).setScale(3, RoundingMode.HALF_UP);
|
|
|
- vo.setYearOnYear(sameMonthLastYearEnergy);
|
|
|
+ // BigDecimal sameMonthLastYearEnergy = getTotal(analogData).multiply(coefficient).setScale(3, RoundingMode.HALF_UP);
|
|
|
+ vo.setYearOnYear(lastYearSameMonth);
|
|
|
// 月能耗同比
|
|
|
- vo.setYearOnYearPercent(
|
|
|
- sameMonthLastYearEnergy.compareTo(BigDecimal.ZERO) == 0
|
|
|
- ? BigDecimal.ZERO
|
|
|
- : getTotal(monthList).multiply(coefficient)
|
|
|
- .divide(sameMonthLastYearEnergy, 3, RoundingMode.HALF_UP)
|
|
|
- );
|
|
|
+ vo.setYearOnYearPercent(ringRatio(month1, lastYearSameMonth));
|
|
|
} else if (consume == 2) {
|
|
|
- vo.setMonthElectricity(getTotal(monthList));
|
|
|
+ // vo.setMonthElectricity(getTotal(monthList));
|
|
|
|
|
|
- ElectricityRateConfig cfg = getElectricityRateConfig(siteId);
|
|
|
- BigDecimal monthBasic = getBasicExpenses(monthList, cfg, siteId, getTotal(monthList));
|
|
|
- BigDecimal sameMonthBasic = getBasicExpenses(sameDayLastMonthList, cfg, siteId, getTotal(sameDayLastMonthList));
|
|
|
- BigDecimal monthCost = calculateTotalCost(calculateTimeFee(siteId, today, 2)).add(monthBasic);
|
|
|
- BigDecimal sameMonthCost = calculateTotalCost(calculateTimeFee(siteId, lastMonth, 22)).add(sameMonthBasic);
|
|
|
+ BigDecimal monthCost = siteFeeCacheService.getTotalCost(siteId, ranges.getToday(), 2);
|
|
|
+ BigDecimal sameMonthCost = siteFeeCacheService.getTotalCost(siteId, ranges.getSameMonthRange()[0].toLocalDate(), 22);
|
|
|
+ BigDecimal sameMonthLastYearCost = siteFeeCacheService.getTotalCost(siteId, ranges.getLastYearSameMonth()[0].toLocalDate(), 4);
|
|
|
+
|
|
|
+ // ElectricityRateConfig cfg = getElectricityRateConfig(siteId);
|
|
|
+ // BigDecimal monthBasic = getBasicExpenses(monthList, cfg, siteId, getTotal(monthList));
|
|
|
+ // BigDecimal sameMonthBasic = getBasicExpenses(sameDayLastMonthList, cfg, siteId, getTotal(sameDayLastMonthList));
|
|
|
+ // BigDecimal monthCost = calculateTotalCost(calculateTimeFee(siteId, today, 2)).add(monthBasic);
|
|
|
+ // BigDecimal sameMonthCost = calculateTotalCost(calculateTimeFee(siteId, lastMonth, 22)).add(sameMonthBasic);
|
|
|
vo.setMonthCost(monthCost);
|
|
|
+ // 上月同期费用
|
|
|
vo.setLastMonthCost(sameMonthCost);
|
|
|
- vo.setMonthCostRingRatio(sameMonthCost.compareTo(BigDecimal.ZERO) != 0
|
|
|
- ? monthCost.subtract(sameMonthCost)
|
|
|
- .divide(sameMonthCost, 2, RoundingMode.HALF_UP)
|
|
|
- : BigDecimal.ZERO);
|
|
|
+ vo.setMonthCostRingRatio(ringRatio(monthCost, sameMonthCost));
|
|
|
// 上一年同月能耗
|
|
|
- List<HtAnalogData> sameMonthLastYear = getAnalogData(data183.get(0), time.minusYears(1), 2);
|
|
|
- BigDecimal sameMonthLastYearElectricity = getTotal(sameMonthLastYear);
|
|
|
- BigDecimal sameMonthLastYearBasic = getBasicExpenses(sameMonthLastYear, cfg, siteId, sameMonthLastYearElectricity);
|
|
|
- BigDecimal sameMonthLastYearCost = calculateTotalCost(calculateTimeFee(siteId, lastMonth, 2)).add(sameMonthLastYearBasic);
|
|
|
+ // List<HtAnalogData> sameMonthLastYear = getAnalogData(deviceCode183, time.minusYears(1), 2);
|
|
|
+ // BigDecimal sameMonthLastYearElectricity = getTotal(sameMonthLastYear);
|
|
|
+ // BigDecimal sameMonthLastYearBasic = getBasicExpenses(sameMonthLastYear, cfg, siteId, sameMonthLastYearElectricity);
|
|
|
+ // BigDecimal sameMonthLastYearCost = calculateTotalCost(calculateTimeFee(siteId, lastMonth, 2)).add(sameMonthLastYearBasic);
|
|
|
vo.setYearOnYear(sameMonthLastYearCost);
|
|
|
- vo.setYearOnYearPercent(sameMonthLastYearCost.compareTo(BigDecimal.ZERO) != 0
|
|
|
- ? monthCost.subtract(sameMonthLastYearCost)
|
|
|
- .divide(sameMonthLastYearCost, 2, RoundingMode.HALF_UP)
|
|
|
- : BigDecimal.ZERO);
|
|
|
+ vo.setYearOnYearPercent(ringRatio(monthCost, sameMonthLastYearCost));
|
|
|
}
|
|
|
|
|
|
} else if (!data173.isEmpty()) {
|
|
@@ -1851,39 +1841,44 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
// 年
|
|
|
case "year":
|
|
|
if (!data183.isEmpty()) {
|
|
|
- yearList = getAnalogData(data183.get(0), time, 3);
|
|
|
- sameDayLastYearList = getAnalogData(data183.get(0), time.minusYears(1), 33);
|
|
|
+ String deviceCode183 = data183.get(0);
|
|
|
+ Map<String, BigDecimal> result = analogCache.get(deviceCode183, ranges);
|
|
|
+ BigDecimal year1 = result.get("year");
|
|
|
+ // yearList = getAnalogData(deviceCode183, time, 3);
|
|
|
+ // sameDayLastYearList = getAnalogData(deviceCode183, time.minusYears(1), 33);
|
|
|
|
|
|
if (consume == 1) {
|
|
|
+ BigDecimal sameYear = result.get("same_year");
|
|
|
// 电耗
|
|
|
- vo.setYearElectricity(getTotal(yearList));
|
|
|
+ vo.setYearElectricity(year1);
|
|
|
// 去年同期电耗
|
|
|
- vo.setLastYearElectricity(getTotal(sameDayLastYearList));
|
|
|
+ vo.setLastYearElectricity(sameYear);
|
|
|
// 能耗
|
|
|
- vo.setYear(getTotal(yearList).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
- vo.setLastYear(getTotal(sameDayLastYearList).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
+ vo.setYear(scale(year1, coefficient));
|
|
|
+ vo.setLastYear(scale(sameYear, coefficient));
|
|
|
// 环比
|
|
|
- vo.setYearRingRatio(getRingRatio(yearList, sameDayLastYearList));
|
|
|
+ vo.setYearRingRatio(ringRatio(year1, sameYear));
|
|
|
// 同比
|
|
|
- vo.setYearOnYear(getTotal(sameDayLastYearList).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
- vo.setYearOnYearPercent(getRingRatio(yearList, sameDayLastYearList));
|
|
|
+ vo.setYearOnYear(vo.getYear());
|
|
|
+ vo.setYearOnYearPercent(vo.getYearCostRingRatio());
|
|
|
// 上一年能耗
|
|
|
- // List<HtAnalogData> analogData = getAnalogData(data183.get(0), time.minusYears(1), 3);
|
|
|
+ // List<HtAnalogData> analogData = getAnalogData(deviceCode183, time.minusYears(1), 3);
|
|
|
// vo.setYearOnYear(getTotal(analogData).multiply(coefficient).setScale(3, RoundingMode.HALF_UP));
|
|
|
} else if (consume == 2) {
|
|
|
- vo.setYearElectricity(getTotal(yearList));
|
|
|
+ // vo.setYearElectricity(getTotal(yearList));
|
|
|
+
|
|
|
+ BigDecimal yearCost = siteFeeCacheService.getTotalCost(siteId, ranges.getToday(), 3);
|
|
|
+
|
|
|
+ BigDecimal sameYearCost = siteFeeCacheService.getTotalCost(siteId, ranges.getSameYearRange()[1].toLocalDate(), 33);
|
|
|
|
|
|
- ElectricityRateConfig cfg = getElectricityRateConfig(siteId);
|
|
|
- BigDecimal yearBasic = getBasicExpenses(yearList, cfg, siteId, getTotal(yearList));
|
|
|
- BigDecimal sameYearBasic = getBasicExpenses(sameDayLastYearList, cfg, siteId, getTotal(sameDayLastYearList));
|
|
|
- BigDecimal yearCost = calculateTotalCost(calculateTimeFee(siteId, today, 3)).add(yearBasic);
|
|
|
- BigDecimal sameYearCost = calculateTotalCost(calculateTimeFee(siteId, lastYear, 33)).add(sameYearBasic);
|
|
|
+ // ElectricityRateConfig cfg = getElectricityRateConfig(siteId);
|
|
|
+ // BigDecimal yearBasic = getBasicExpenses(yearList, cfg, siteId, getTotal(yearList));
|
|
|
+ // BigDecimal sameYearBasic = getBasicExpenses(sameDayLastYearList, cfg, siteId, getTotal(sameDayLastYearList));
|
|
|
+ // BigDecimal yearCost = calculateTotalCost(calculateTimeFee(siteId, today, 3)).add(yearBasic);
|
|
|
+ // BigDecimal sameYearCost = calculateTotalCost(calculateTimeFee(siteId, lastYear, 33)).add(sameYearBasic);
|
|
|
vo.setYearCost(yearCost);
|
|
|
vo.setLastYearCost(sameYearCost);
|
|
|
- vo.setYearCostRingRatio(sameYearCost.compareTo(BigDecimal.ZERO) != 0
|
|
|
- ? yearCost.subtract(sameYearCost)
|
|
|
- .divide(sameYearCost, 2, RoundingMode.HALF_UP)
|
|
|
- : BigDecimal.ZERO);
|
|
|
+ vo.setYearCostRingRatio(ringRatio(yearCost, sameYearCost));
|
|
|
vo.setYearOnYear(sameYearCost);
|
|
|
vo.setYearOnYearPercent(vo.getYearCostRingRatio());
|
|
|
}
|
|
@@ -1912,9 +1907,18 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
+ // 环比计算
|
|
|
+ public static BigDecimal ringRatio(BigDecimal value, BigDecimal same) {
|
|
|
+ return same.compareTo(ZERO) == 0 ? ZERO : value.subtract(same).divide(same, 2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 能耗转换
|
|
|
+ public static BigDecimal scale(BigDecimal value, BigDecimal coefficient) {
|
|
|
+ return value == null ? ZERO : value.multiply(coefficient).setScale(3, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
// 获取173数据
|
|
|
public List<HtAnalog173Data> get173Data(List<String> deviceCodeList, LocalDateTime localDateTime, int timeType) {
|
|
|
-
|
|
|
LocalDate data = localDateTime.toLocalDate();
|
|
|
LocalDate monthFirstDay = data.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
LocalDate monthLastDay = data.with(TemporalAdjusters.lastDayOfMonth());
|
|
@@ -1968,7 +1972,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
*/
|
|
|
public BigDecimal get173Total(List<HtAnalog173Data> dataList) {
|
|
|
if (CollectionUtils.isEmpty(dataList)) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ return ZERO;
|
|
|
}
|
|
|
return dataList.stream()
|
|
|
.collect(Collectors.groupingBy(HtAnalog173Data::getDeviceName))
|
|
@@ -1978,8 +1982,8 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
.sorted(Comparator.comparing(HtAnalog173Data::getDataTime))
|
|
|
.map(HtAnalog173Data::getEpp)
|
|
|
.reduce((first, last) -> last.subtract(first))
|
|
|
- .orElse(BigDecimal.ZERO))
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ .orElse(ZERO))
|
|
|
+ .reduce(ZERO, BigDecimal::add);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1996,8 +2000,8 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
BigDecimal daySum = calcDeviceDiffSum(dayList173, localDateTime);
|
|
|
BigDecimal yearSum = calcDeviceDiffSum(yearList173, localDateTime);
|
|
|
|
|
|
- if (yearSum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ if (yearSum.compareTo(ZERO) == 0) {
|
|
|
+ return ZERO;
|
|
|
}
|
|
|
|
|
|
return daySum
|
|
@@ -2014,7 +2018,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
LocalDateTime localDateTime) {
|
|
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ return ZERO;
|
|
|
}
|
|
|
|
|
|
return list.stream()
|
|
@@ -2026,8 +2030,8 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
.sorted(Comparator.comparing(HtAnalog173Data::getDataTime))
|
|
|
.map(HtAnalog173Data::getEpp)
|
|
|
.reduce((first, last) -> last.subtract(first))
|
|
|
- .orElse(BigDecimal.ZERO))
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ .orElse(ZERO))
|
|
|
+ .reduce(ZERO, BigDecimal::add);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -2035,9 +2039,10 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
*/
|
|
|
public BigDecimal getTotal(List<HtAnalogData> dataList) {
|
|
|
if (dataList == null || dataList.isEmpty()) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ return ZERO;
|
|
|
}
|
|
|
|
|
|
+ // 获取最大最小时间,已按照时间顺序倒序
|
|
|
HtAnalogData max = dataList.get(0), min = dataList.get(dataList.size() - 1);
|
|
|
// for (int i = 1, size = dataList.size(); i < size; i++) {
|
|
|
// HtAnalogData d = dataList.get(i);
|
|
@@ -2048,6 +2053,10 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
// min = d;
|
|
|
// }
|
|
|
// }
|
|
|
+ if (max.getEpp() == null || min.getEpp() == null ||
|
|
|
+ max.getEpp().compareTo(min.getEpp()) == 0 || min.getEpp().compareTo(ZERO) == 0) {
|
|
|
+ return ZERO;
|
|
|
+ }
|
|
|
return max.getEpp().subtract(min.getEpp());
|
|
|
}
|
|
|
|
|
@@ -2071,14 +2080,6 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
*/
|
|
|
public List<HtAnalogData> getAnalogData(String deviceCode, LocalDateTime localDateTime, int timeType) {
|
|
|
LocalDate data = localDateTime.toLocalDate();
|
|
|
- LocalDate monthFirstDay = data.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
- LocalDateTime monthFirstTime = LocalDateTime.of(monthFirstDay, LocalTime.MIN);
|
|
|
- LocalDate monthMonthLastDay = data.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
- LocalDate yearFirstDay = data.with(TemporalAdjusters.firstDayOfYear());
|
|
|
- LocalDate yearLastDay = data.with(TemporalAdjusters.lastDayOfYear());
|
|
|
- LocalDateTime yearFirstTime = LocalDateTime.of(yearFirstDay, LocalTime.MIN);
|
|
|
- LocalDateTime dayFirstTime = LocalDateTime.of(data, LocalTime.MIN);
|
|
|
-
|
|
|
LambdaQueryWrapper<HtAnalogData> queryWrapper = Wrappers.lambdaQuery();
|
|
|
queryWrapper.select(HtAnalogData::getDeviceName,
|
|
|
HtAnalogData::getFreezingTime,
|
|
@@ -2092,23 +2093,30 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
break;
|
|
|
// 月
|
|
|
case 2:
|
|
|
+ LocalDate monthFirstDay = data.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ LocalDate monthMonthLastDay = data.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
queryWrapper.between(HtAnalogData::getFreezingTime, monthFirstDay, monthMonthLastDay);
|
|
|
break;
|
|
|
// 年
|
|
|
case 3:
|
|
|
+ LocalDate yearFirstDay = data.with(TemporalAdjusters.firstDayOfYear());
|
|
|
+ LocalDate yearLastDay = data.with(TemporalAdjusters.lastDayOfYear());
|
|
|
queryWrapper.between(HtAnalogData::getFreezingTime, yearFirstDay, yearLastDay);
|
|
|
break;
|
|
|
|
|
|
// 昨日同期
|
|
|
case 11:
|
|
|
+ LocalDateTime dayFirstTime = LocalDateTime.of(data, LocalTime.MIN);
|
|
|
queryWrapper.between(HtAnalogData::getDataTime, dayFirstTime.minusDays(1), localDateTime.minusDays(1));
|
|
|
break;
|
|
|
// 上月同期
|
|
|
case 22:
|
|
|
+ LocalDateTime monthFirstTime = localDateTime.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
queryWrapper.between(HtAnalogData::getDataTime, monthFirstTime.minusMonths(1), localDateTime.minusMonths(1));
|
|
|
break;
|
|
|
// 上年同期
|
|
|
case 33:
|
|
|
+ LocalDateTime yearFirstTime = localDateTime.with(TemporalAdjusters.firstDayOfYear());
|
|
|
queryWrapper.between(HtAnalogData::getDataTime, yearFirstTime.minusYears(1), localDateTime.minusYears(1));
|
|
|
break;
|
|
|
default:
|
|
@@ -2131,7 +2139,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
// List<String> timeList) {
|
|
|
//
|
|
|
// if (source == null || source.isEmpty() || timeList == null || timeList.isEmpty()) {
|
|
|
-// return Collections.nCopies(timeList == null ? 0 : timeList.size(), BigDecimal.ZERO);
|
|
|
+// return Collections.nCopies(timeList == null ? 0 : timeList.size(), ZERO);
|
|
|
// }
|
|
|
//
|
|
|
// // 提取时间“槽位”的映射函数
|
|
@@ -2160,7 +2168,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
// .collect(Collectors.groupingBy(slotExtractor));
|
|
|
//
|
|
|
// // 构造结果,顺序与 timeList 保持一致
|
|
|
-// List<BigDecimal> result = new ArrayList<>(Collections.nCopies(timeList.size(), BigDecimal.ZERO));
|
|
|
+// List<BigDecimal> result = new ArrayList<>(Collections.nCopies(timeList.size(), ZERO));
|
|
|
//
|
|
|
// grouped.forEach((slot, list) -> {
|
|
|
// if (slot >= 0 && slot < timeList.size() && list.size() >= 2) {
|
|
@@ -2183,7 +2191,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
public BigDecimal getRingRatio(List<HtAnalogData> curList,
|
|
|
List<HtAnalogData> preList) {
|
|
|
if (curList.isEmpty() || preList.isEmpty()) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ return ZERO;
|
|
|
}
|
|
|
|
|
|
// 已倒序:0 是最新,size-1 是最早
|
|
@@ -2192,8 +2200,8 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
BigDecimal preDiff = preList.get(0).getEpp()
|
|
|
.subtract(preList.get(preList.size() - 1).getEpp());
|
|
|
|
|
|
- if (preDiff.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ if (preDiff.compareTo(ZERO) == 0) {
|
|
|
+ return ZERO;
|
|
|
}
|
|
|
|
|
|
// 计算环比:(cur - pre) / pre
|
|
@@ -2308,9 +2316,9 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
List<String> devices183 = new ArrayList<>();
|
|
|
List<String> devices173 = new ArrayList<>();
|
|
|
|
|
|
- BigDecimal current = BigDecimal.ZERO;
|
|
|
- BigDecimal previous = BigDecimal.ZERO;
|
|
|
- BigDecimal ratio = BigDecimal.ZERO;
|
|
|
+ BigDecimal current = ZERO;
|
|
|
+ BigDecimal previous = ZERO;
|
|
|
+ BigDecimal ratio = ZERO;
|
|
|
|
|
|
List<Device> devices = getDevices(siteId);
|
|
|
if (devices.isEmpty()) {
|
|
@@ -2371,10 +2379,10 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
SiteDynamicProperties siteDynamicProperties = siteDynamicPropertiesService.selectOne(siteId);
|
|
|
if (siteDynamicProperties == null) {
|
|
|
log.warn("站点{}未配置能耗属性等数据", siteId);
|
|
|
- vo.setRatio(BigDecimal.ZERO);
|
|
|
+ vo.setRatio(ZERO);
|
|
|
vo.setUnit("energy".equals(queryType) ? "吨标准煤" : "electric".equals(queryType) ? "kwh" : "cost".equals(queryType) ? "元" : "kWh");
|
|
|
- vo.setCurrent(BigDecimal.ZERO);
|
|
|
- vo.setPrevious(BigDecimal.ZERO);
|
|
|
+ vo.setCurrent(ZERO);
|
|
|
+ vo.setPrevious(ZERO);
|
|
|
vo.setTimeKeys(timeKeys);
|
|
|
vo.setAmountList(zeroList(timeKeys.size()));
|
|
|
return vo;
|
|
@@ -2404,14 +2412,14 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
vo.setAmountList(dayCostList);
|
|
|
vo.setCurrent(dayCostList.stream()
|
|
|
.filter(Objects::nonNull)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ .reduce(ZERO, BigDecimal::add));
|
|
|
break;
|
|
|
case "month": {
|
|
|
List<SiteElectricityRecord> siteElectricityRecords = calculateTimeFee(siteId, localDate, 2);
|
|
|
vo.setCurrent(siteElectricityRecords.stream()
|
|
|
.filter(Objects::nonNull)
|
|
|
.map(SiteElectricityRecord::getTotalCost)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ .reduce(ZERO, BigDecimal::add));
|
|
|
|
|
|
List<SiteElectricityRecord> monthRecords = calculateTimeFee(siteId, localDate, 2);
|
|
|
vo.setAmountList(getMonthYearList(monthRecords, timeKeys, "month"));
|
|
@@ -2422,7 +2430,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
vo.setCurrent(siteElectricityRecords.stream()
|
|
|
.filter(Objects::nonNull)
|
|
|
.map(SiteElectricityRecord::getTotalCost)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ .reduce(ZERO, BigDecimal::add));
|
|
|
|
|
|
List<SiteElectricityRecord> monthRecords = calculateTimeFee(siteId, localDate, 3);
|
|
|
vo.setAmountList(getMonthYearList(monthRecords, timeKeys, "year"));
|
|
@@ -2454,7 +2462,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
Map<YearMonth, BigDecimal> monthMap = records.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
|
r -> YearMonth.from(r.getDate()),
|
|
|
- Collectors.reducing(BigDecimal.ZERO,
|
|
|
+ Collectors.reducing(ZERO,
|
|
|
SiteElectricityRecord::getTotalCost,
|
|
|
BigDecimal::add)));
|
|
|
|
|
@@ -2584,7 +2592,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
for (LocalDateTime hourStart : timeKeys) {
|
|
|
List<HtAnalogData> oneHour = groupByHour.get(hourStart);
|
|
|
if (oneHour == null || oneHour.isEmpty()) {
|
|
|
- result.add(BigDecimal.ZERO);
|
|
|
+ result.add(ZERO);
|
|
|
} else {
|
|
|
// 升序排序
|
|
|
oneHour.sort(Comparator.comparing(HtAnalogData::getDataTime));
|
|
@@ -2640,7 +2648,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
|
|
|
List<HtAnalogData> oneGroup = groupByPeriod.get(periodStart);
|
|
|
if (oneGroup == null || oneGroup.isEmpty()) {
|
|
|
- result.add(BigDecimal.ZERO);
|
|
|
+ result.add(ZERO);
|
|
|
} else {
|
|
|
oneGroup.sort(Comparator.comparing(HtAnalogData::getDataTime));
|
|
|
BigDecimal first = oneGroup.get(0).getEpp();
|
|
@@ -2661,7 +2669,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
List<LocalDateTime> timeKeys) {
|
|
|
if (periodPastOrPresent == 1) {
|
|
|
// 全部补 0
|
|
|
- return Collections.nCopies(size, BigDecimal.ZERO);
|
|
|
+ return Collections.nCopies(size, ZERO);
|
|
|
}
|
|
|
|
|
|
LocalDateTime nowPeriodStart = alignToPeriod(LocalDateTime.now(), period);
|
|
@@ -2670,7 +2678,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
if (periodStart.isAfter(nowPeriodStart)) {
|
|
|
list.add(null);
|
|
|
} else {
|
|
|
- list.add(BigDecimal.ZERO);
|
|
|
+ list.add(ZERO);
|
|
|
}
|
|
|
}
|
|
|
return list;
|
|
@@ -2694,7 +2702,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
for (LocalDateTime hourStart : timeKeys) {
|
|
|
List<HtAnalog173Data> oneHour = groupByHour.get(hourStart);
|
|
|
if (oneHour == null || oneHour.isEmpty()) {
|
|
|
- result.add(BigDecimal.ZERO);
|
|
|
+ result.add(ZERO);
|
|
|
} else {
|
|
|
oneHour.sort(Comparator.comparing(HtAnalog173Data::getDataTime));
|
|
|
BigDecimal first = oneHour.get(0).getEpp();
|
|
@@ -2734,7 +2742,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
for (LocalDateTime hourStart : timeKeys) {
|
|
|
List<HtAnalog173Data> oneHour = groupByHour.get(hourStart);
|
|
|
if (oneHour == null || oneHour.isEmpty()) {
|
|
|
- result.add(BigDecimal.ZERO);
|
|
|
+ result.add(ZERO);
|
|
|
} else {
|
|
|
oneHour.sort(Comparator.comparing(HtAnalog173Data::getDataTime));
|
|
|
BigDecimal first = oneHour.get(0).getEpp();
|
|
@@ -2762,7 +2770,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
/** 用“最后一条 - 第一条”计算周期总量 */
|
|
|
private BigDecimal calcTotal(List<HtAnalogData> list) {
|
|
|
if (list.size() < 2) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ return ZERO;
|
|
|
}
|
|
|
return list.get(0).getEpp()
|
|
|
.subtract(list.get(list.size() - 1).getEpp());
|
|
@@ -2783,7 +2791,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
|
|
|
/** 返回一个固定长度的 0 列表,避免空数组 */
|
|
|
private List<BigDecimal> zeroList(int size) {
|
|
|
- return new ArrayList<>(Collections.nCopies(size, BigDecimal.ZERO));
|
|
|
+ return new ArrayList<>(Collections.nCopies(size, ZERO));
|
|
|
}
|
|
|
|
|
|
/** 获取一个站点的费率配置-基本电价配置 */
|
|
@@ -2810,7 +2818,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
*/
|
|
|
public BigDecimal getBasicExpenses(List<HtAnalogData> list, ElectricityRateConfig config, Integer siteId, BigDecimal electricity) {
|
|
|
|
|
|
- BigDecimal basicExpenses = BigDecimal.ZERO;
|
|
|
+ BigDecimal basicExpenses = ZERO;
|
|
|
// 超过的百分比
|
|
|
BigDecimal excessPercentage = config.getExcessPercentage();
|
|
|
// 超过部分的计费倍数
|
|
@@ -2842,7 +2850,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
}
|
|
|
|
|
|
BigDecimal additionalElectricityPrice = additionalElectricityPrice(siteId, electricity);
|
|
|
- if (additionalElectricityPrice.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (additionalElectricityPrice.compareTo(ZERO) > 0) {
|
|
|
basicExpenses = basicExpenses.add(additionalElectricityPrice);
|
|
|
}
|
|
|
|
|
@@ -2858,7 +2866,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
return getSiteInformation(siteId).stream()
|
|
|
.map(SiteInformation::getAdditionalElectricityPrice)
|
|
|
.filter(Objects::nonNull)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .reduce(ZERO, BigDecimal::add)
|
|
|
.multiply(electricity)
|
|
|
.setScale(2, RoundingMode.HALF_UP);
|
|
|
}
|
|
@@ -2904,7 +2912,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
* @return 实际最大需量电费
|
|
|
*/
|
|
|
private BigDecimal calculateActualMaxDemand(List<HtAnalogData> dataList) {
|
|
|
- BigDecimal maxDemand = BigDecimal.ZERO;
|
|
|
+ BigDecimal maxDemand = ZERO;
|
|
|
|
|
|
for (int i = 0; i < dataList.size() - 1; i++) {
|
|
|
HtAnalogData start = dataList.get(i);
|
|
@@ -2937,7 +2945,7 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
// 允许n%浮动
|
|
|
BigDecimal overDemand = actualDemand.subtract(contractDemand.multiply(new BigDecimal(1).add(excessPercentage)));
|
|
|
|
|
|
- if (overDemand.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ if (overDemand.compareTo(ZERO) <= 0) {
|
|
|
// 未超105%,按合同计费
|
|
|
return contractDemand.multiply(demandPrice);
|
|
|
} else {
|
|
@@ -3012,12 +3020,12 @@ public class HtAnalogDataServiceImpl extends AbstractCrudService<HtAnalogDataMap
|
|
|
*/
|
|
|
private BigDecimal calculateTotalCost(List<SiteElectricityRecord> records) {
|
|
|
if (records == null || records.isEmpty()) {
|
|
|
- return BigDecimal.ZERO;
|
|
|
+ return ZERO;
|
|
|
}
|
|
|
|
|
|
return records.stream()
|
|
|
.map(SiteElectricityRecord::getTotalCost)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ .reduce(ZERO, BigDecimal::add);
|
|
|
}
|
|
|
|
|
|
|