|
@@ -35,19 +35,65 @@ public class FireStatisticsServiceImpl implements FireStatisticsService {
|
|
|
@Autowired
|
|
|
private UnitService unitService;
|
|
|
@Override
|
|
|
- public List<Integer> getFireCountByData(Integer year, String address,String fireType) {
|
|
|
- List<Integer> list = new ArrayList<>();
|
|
|
+ public List<Object> getFireCountByData(Date startTime,Date endTime,String address,String fireType) {
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
|
+ List<Integer> thisYearList = new ArrayList<>();
|
|
|
+ List<Double> monthList = new ArrayList<>();
|
|
|
+ List<Double> yearList = new ArrayList<>();
|
|
|
Date date = new Date();
|
|
|
+ //获取传入时间的最大时间和最小时间
|
|
|
+ int distanceOfTwoDate =Integer.parseInt(DateUtils.getYear(endTime)) - Integer.parseInt(DateUtils.getYear(startTime)) + 1;
|
|
|
+ Date startMax = DateUtils.getFirstDayOfMonth(DateUtils.setMonths(startTime, 0));
|
|
|
+ Date endMax = DateUtils.getLastDayOfMonth(DateUtils.setMonths(endTime, 11));
|
|
|
+ //获取数据库全部项目的最小时间和最大时间
|
|
|
+ Date maxDate = fireStatisticsMapper.selectMaxDate();
|
|
|
+ Date minDate = fireStatisticsMapper.selectMinDate();
|
|
|
+ int distanceOfTwoDateYear =Integer.parseInt(DateUtils.getYear(maxDate)) - Integer.parseInt(DateUtils.getYear(minDate)) + 1;
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
- date.setDate(1);
|
|
|
+ //获取今年的12个月份数据
|
|
|
+ date = DateUtils.setDays(date,1);
|
|
|
Date setMonths = DateUtils.setMonths(date, i);
|
|
|
Date firstDayOfMonth = DateUtils.getFirstDayOfMonth(setMonths);
|
|
|
Date lastDayOfMonth = DateUtils.getLastDayOfMonth(setMonths);
|
|
|
- list.add(fireStatisticsMapper.selectCount(firstDayOfMonth, lastDayOfMonth, address,fireType,null));
|
|
|
+ thisYearList.add(fireStatisticsMapper.selectCount(firstDayOfMonth, lastDayOfMonth, address,fireType,null));
|
|
|
+ //月平均值
|
|
|
+ Integer monthCount = fireStatisticsMapper.selectCountByRangeDate(startMax, endMax, address, fireType,i+1);
|
|
|
+ monthList.add(Arith.div(monthCount, distanceOfTwoDate));
|
|
|
+ Integer yearCount = fireStatisticsMapper.selectCountByRangeDate(null, null,address, fireType,i+1);
|
|
|
+ yearList.add(Arith.div(yearCount, distanceOfTwoDate));
|
|
|
}
|
|
|
+ list.add(thisYearList);
|
|
|
+ list.add(monthList);
|
|
|
+ list.add(yearList);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 月平均值/年平均值
|
|
|
+ * @param endTime
|
|
|
+ * @param distanceOfTwoDate
|
|
|
+ * @param address
|
|
|
+ * @param fireType
|
|
|
+ * @param month
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Double getFireCountByDate(Date endTime,Integer distanceOfTwoDate,String address,String fireType,Integer month){
|
|
|
+ int count = 0;
|
|
|
+ for (int j = 0; j < distanceOfTwoDate; j++) {
|
|
|
+ Date monthDate = endTime;
|
|
|
+ if (0 != j){
|
|
|
+ monthDate = DateUtils.addYears(endTime, -j);
|
|
|
+ }
|
|
|
+ monthDate = DateUtils.setMonths(monthDate, month);
|
|
|
+ Date monthDateStartTime = DateUtils.getFirstDayOfMonth(monthDate);
|
|
|
+ Date monthDateEndTime = DateUtils.getLastDayOfMonth(monthDate);
|
|
|
+ System.out.println(DateUtils.format(monthDateStartTime,"yyyy-MM-dd HH:mm:ss"));
|
|
|
+ System.out.println(DateUtils.format(monthDateEndTime,"yyyy-MM-dd HH:mm:ss"));
|
|
|
+ count+=fireStatisticsMapper.selectCount(monthDateStartTime, monthDateEndTime, address, fireType, null);
|
|
|
+ }
|
|
|
+ return (double) (count/distanceOfTwoDate);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public CommonPage<FireStatisticsPO> page(Integer current, Integer size, Date startTime, Date endTime, String address) {
|
|
@@ -100,17 +146,17 @@ public class FireStatisticsServiceImpl implements FireStatisticsService {
|
|
|
|
|
|
//差集求和
|
|
|
double sum = list.stream().filter(item -> !orderByList.contains(item)).mapToDouble(FireLevelRatioVO::getRadio).sum();
|
|
|
- FireLevelRatioVO fireLevelRatioVO = orderByList.stream().filter(item -> "其他".equals(item.getFireType())).findAny()
|
|
|
+ orderByList.stream().filter(item -> "其他".equals(item.getFireType())).findAny()
|
|
|
.map(fireLevelRatio -> {
|
|
|
fireLevelRatio.setRadio(fireLevelRatio.getRadio() + sum);
|
|
|
return fireLevelRatio;
|
|
|
}
|
|
|
- ).orElse(new FireLevelRatioVO());
|
|
|
- if (null == fireLevelRatioVO.getFireType()){
|
|
|
- fireLevelRatioVO.setFireType("其他");
|
|
|
- fireLevelRatioVO.setRadio(sum);
|
|
|
- orderByList.add(fireLevelRatioVO);
|
|
|
- }
|
|
|
+ ).orElseGet(() -> {FireLevelRatioVO fireLevelRatioVo = new FireLevelRatioVO();
|
|
|
+ fireLevelRatioVo.setFireType("其他");
|
|
|
+ fireLevelRatioVo.setRadio(sum);
|
|
|
+ orderByList.add(fireLevelRatioVo);
|
|
|
+ return fireLevelRatioVo;
|
|
|
+ });
|
|
|
int finalFireCount = fireCount;
|
|
|
if (0 != finalFireCount){
|
|
|
orderByList.forEach(fireLevelRatio -> fireLevelRatio.setRadio(Arith.div(fireLevelRatio.getRadio(),finalFireCount)));
|