|
|
@@ -13,6 +13,7 @@ import com.zksy.infrared.mapper.InfraredReadingMeterMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.*;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -31,7 +32,7 @@ public class InfraredReadingMeterServiceImpl extends ServiceImpl<InfraredReading
|
|
|
// 工具方法:生成默认日数据列表
|
|
|
private static final List<BigDecimal> DEFAULT_DAY_LIST = Collections.nCopies(31, BigDecimal.ZERO);
|
|
|
// 工具方法:生成默认季数据列表
|
|
|
- private static final List<BigDecimal> DEFAULT_QUARTER_LIST = Collections.nCopies(3, BigDecimal.ZERO);
|
|
|
+ private static final List<BigDecimal> DEFAULT_QUARTER_LIST = Collections.nCopies(3, new BigDecimal("0.00"));
|
|
|
|
|
|
@Override
|
|
|
public MeterYearDataVo selectByYear(Integer year, String meterNumber) {
|
|
|
@@ -187,9 +188,9 @@ public class InfraredReadingMeterServiceImpl extends ServiceImpl<InfraredReading
|
|
|
|
|
|
return new MeterDayDataVo(lastValue.subtract(firstValue));
|
|
|
}
|
|
|
- //TODO 按照年统计电表
|
|
|
@Override
|
|
|
public MeterYearDataVo selectByCurrentYearData() {
|
|
|
+ log.warn("按照年统计电表");
|
|
|
//首先获取当前年份
|
|
|
int currentYear = LocalDate.now().getYear();
|
|
|
|
|
|
@@ -230,18 +231,21 @@ public class InfraredReadingMeterServiceImpl extends ServiceImpl<InfraredReading
|
|
|
monthTotal=monthTotal.add(end.subtract(start));
|
|
|
}
|
|
|
}
|
|
|
+ monthTotal = monthTotal.setScale(2, RoundingMode.HALF_UP); //精度
|
|
|
monthDataList.set(month-1,monthTotal);
|
|
|
}
|
|
|
//计算年用电量
|
|
|
BigDecimal totalElectricity = monthDataList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-
|
|
|
+ //年总量处理
|
|
|
+ totalElectricity = totalElectricity.setScale(2, RoundingMode.HALF_UP);
|
|
|
return new MeterYearDataVo(totalElectricity,monthDataList);
|
|
|
|
|
|
}
|
|
|
|
|
|
- //TODO 根据当前年月统计电表数据
|
|
|
@Override
|
|
|
public MeterMonthDataVo selectByCurrentYearselectByCurrentYearAndCurrentMonthWithDayData() {
|
|
|
+ final List<BigDecimal> defaultDayList = Collections.nCopies(31, new BigDecimal("0.00"));
|
|
|
+ log.warn("根据当前年月统计电表数据");
|
|
|
//首先获取当前的日期
|
|
|
LocalDate now = LocalDate.now();
|
|
|
int year = now.getYear();
|
|
|
@@ -261,7 +265,7 @@ public class InfraredReadingMeterServiceImpl extends ServiceImpl<InfraredReading
|
|
|
List<InfraredReadingMeter> list = this.list(wrapper);
|
|
|
|
|
|
if(list==null||list.size()<2){
|
|
|
- return new MeterMonthDataVo(BigDecimal.ZERO,DEFAULT_DAY_LIST);
|
|
|
+ return new MeterMonthDataVo(new BigDecimal("0.00"),defaultDayList);
|
|
|
}
|
|
|
//对查询结果按照日期和电表编号分组
|
|
|
Map<Integer,Map<String,List<InfraredReadingMeter>>> groupedByDayAndMeter=list.stream()
|
|
|
@@ -286,6 +290,7 @@ public class InfraredReadingMeterServiceImpl extends ServiceImpl<InfraredReading
|
|
|
dayTotal=dayTotal.add(end.subtract(start));
|
|
|
}
|
|
|
}
|
|
|
+ dayTotal = dayTotal.setScale(2, RoundingMode.HALF_UP); // 添加这行
|
|
|
dayDataList.set(day-1,dayTotal);
|
|
|
}
|
|
|
// 按电表分组,计算每个电表当月最后一天最后一条数据减去当月第一天第一条数据,再累加
|
|
|
@@ -313,12 +318,14 @@ public class InfraredReadingMeterServiceImpl extends ServiceImpl<InfraredReading
|
|
|
totalElectricity = totalElectricity.add(endEnergy.subtract(startEnergy));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ // 月总量处理
|
|
|
+ totalElectricity = totalElectricity.setScale(2, RoundingMode.HALF_UP);
|
|
|
return new MeterMonthDataVo(totalElectricity,dayDataList);
|
|
|
}
|
|
|
- //TODO 根据当前季度统计电表数据
|
|
|
+
|
|
|
@Override
|
|
|
public MeterQuarterDataVo selectByCurrentQuarterData() {
|
|
|
+ log.warn("根据当前季度统计电表数据");
|
|
|
//首先获取当前的日期
|
|
|
LocalDate now = LocalDate.now();
|
|
|
int year = now.getYear();
|
|
|
@@ -342,7 +349,7 @@ public class InfraredReadingMeterServiceImpl extends ServiceImpl<InfraredReading
|
|
|
List<InfraredReadingMeter> list = this.list(wrapper);
|
|
|
|
|
|
if(list==null||list.size()<2){
|
|
|
- return new MeterQuarterDataVo(BigDecimal.ZERO,DEFAULT_QUARTER_LIST);
|
|
|
+ return new MeterQuarterDataVo(new BigDecimal("0.00"),DEFAULT_QUARTER_LIST);
|
|
|
}
|
|
|
//将结果集根据年份和电表编号进行分组
|
|
|
Map<Integer, Map<String, List<InfraredReadingMeter>>> groupedByMonthAndMeter =
|
|
|
@@ -353,7 +360,7 @@ public class InfraredReadingMeterServiceImpl extends ServiceImpl<InfraredReading
|
|
|
.getMonthValue(),
|
|
|
Collectors.groupingBy(InfraredReadingMeter::getElectricNumber)
|
|
|
));
|
|
|
- List<BigDecimal> monthDataList=new ArrayList<>(Collections.nCopies(3, BigDecimal.ZERO));
|
|
|
+ List<BigDecimal> monthDataList=new ArrayList<>(Collections.nCopies(3, new BigDecimal("0.00")));
|
|
|
BigDecimal totalQuarterElectricity = BigDecimal.ZERO;
|
|
|
for(int m=startMonth;m<=endMonth;m++){
|
|
|
Map<String, List<InfraredReadingMeter>> meterData = groupedByMonthAndMeter.getOrDefault(m, Collections.emptyMap());
|
|
|
@@ -365,10 +372,13 @@ public class InfraredReadingMeterServiceImpl extends ServiceImpl<InfraredReading
|
|
|
monthTotal=monthTotal.add(end.subtract(start));
|
|
|
}
|
|
|
}
|
|
|
+ monthTotal = monthTotal.setScale(2, RoundingMode.HALF_UP);
|
|
|
monthDataList.set(m-startMonth,monthTotal);
|
|
|
totalQuarterElectricity = totalQuarterElectricity.add(monthTotal);
|
|
|
}
|
|
|
|
|
|
+ totalQuarterElectricity = totalQuarterElectricity.setScale(2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
return new MeterQuarterDataVo(totalQuarterElectricity,monthDataList);
|
|
|
}
|
|
|
}
|