分时段按量金额计算修改

This commit is contained in:
墨大叔 2024-09-04 17:55:58 +08:00
parent 5426294462
commit 40aa07d1dd

View File

@ -1082,18 +1082,35 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 计算分时段计量金额
private BigDecimal calcTimingCountAmount(TransactionBillVO order, LocalDateTime endTime, BigDecimal totalEle) {
// 计算平均用电量
Duration between = Duration.between(order.getSuitStartTime(), endTime);
long hours = between.toHours();
BigDecimal total = BigDecimal.ZERO;
endTime = endTime.plusHours(10);
// 计算每小时平均用电量
Duration betweenAvg = Duration.between(order.getSuitStartTime(), endTime);
long hours = betweenAvg.toHours();
if (hours == 0) {
hours = 1;
}
BigDecimal startEle = order.getSuitStartEle() == null ? BigDecimal.ZERO : order.getSuitStartEle();
BigDecimal usedEle = totalEle == null ? BigDecimal.ZERO : totalEle.subtract(startEle);
BigDecimal avgEle = usedEle.divide(BigDecimal.valueOf(hours), 2, RoundingMode.HALF_UP);
BigDecimal avgEle = usedEle.divide(BigDecimal.valueOf(hours), 2, RoundingMode.HALF_UP); // 平均每小时的用电量
// 计算金额
return this.calcTimingTimeAmount(order, endTime).multiply(avgEle);
// 初始时间
LocalDateTime startTime = order.getSuitStartTime();
List<BigDecimal> suitGearAmount = order.getSuitGearAmount();
List<Integer> suitGearTime = order.getSuitGearTime();
int hour = startTime.getHour() ;
// 计算每个小时的金额
for (int i = 0; i < hours; i++) {
BigDecimal hourAmount = suitGearAmount.get(suitGearTime.get(hour)).multiply(avgEle);
total = total.add(hourAmount);
hour = (hour + 1) % 24;
}
return total;
}
// 计算分时段计时金额