|
@@ -1,6 +1,7 @@
|
|
package com.usky.fire.service.impl;
|
|
package com.usky.fire.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
@@ -8,6 +9,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.usky.common.core.bean.CommonPage;
|
|
import com.usky.common.core.bean.CommonPage;
|
|
import com.usky.common.core.exception.BusinessException;
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
|
+import com.usky.common.core.util.Arith;
|
|
|
|
+import com.usky.common.core.util.DateUtils;
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
import com.usky.fire.domain.DemFileLabel;
|
|
import com.usky.fire.domain.DemFileLabel;
|
|
@@ -27,10 +30,8 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -486,4 +487,78 @@ public class DemFireStatisticsServiceImpl extends AbstractCrudService<DemFireSta
|
|
demFireStatisticsAttach.setUpdateTime(LocalDateTime.now());
|
|
demFireStatisticsAttach.setUpdateTime(LocalDateTime.now());
|
|
demFireStatisticsAttachService.updateById(demFireStatisticsAttach);
|
|
demFireStatisticsAttachService.updateById(demFireStatisticsAttach);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<Object> getFireCountByData(String startTime, String endTime, String address, String fireType) {
|
|
|
|
+ Date startTime1 = null;
|
|
|
|
+ Date endTime1 = null;
|
|
|
|
+ if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
|
|
|
|
+ startTime1 = OnlineMethod.transferString2Date(startTime);
|
|
|
|
+ endTime1 = OnlineMethod.transferString2Date(endTime);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ Date beginDayOfYear = DateUtils.getBeginDayOfYear(date);
|
|
|
|
+ //获取传入时间的最大时间和最小时间
|
|
|
|
+ int distanceOfTwoDate = Integer.parseInt(DateUtils.getYear(endTime1)) - Integer.parseInt(DateUtils.getYear(startTime1)) + 1;
|
|
|
|
+ //获取数据库全部项目的最小时间和最大时间
|
|
|
|
+ QueryWrapper<DemFireStatistics> query = Wrappers.query();
|
|
|
|
+ query.select("max(fire_time) as fireTime");
|
|
|
|
+ DemFireStatistics one = this.getOne(query);
|
|
|
|
+ QueryWrapper<DemFireStatistics> query1 = Wrappers.query();
|
|
|
|
+ query1.select("min(fire_time) as fireTime");
|
|
|
|
+ DemFireStatistics one1 = this.getOne(query1);
|
|
|
|
+ Date maxDate = null;
|
|
|
|
+ Date minDate = null;
|
|
|
|
+ if (one.getFireTime() != null) {
|
|
|
|
+ maxDate = Date.from(one.getFireTime().atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
+ }
|
|
|
|
+ if (one1.getFireTime() != null) {
|
|
|
|
+ minDate = Date.from(one1.getFireTime().atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
+ }
|
|
|
|
+ int distanceOfTwoDateYear = Integer.parseInt(DateUtils.getYear(maxDate)) - Integer.parseInt(DateUtils.getYear(minDate)) + 1;
|
|
|
|
+ list.add(perfect(beginDayOfYear, date, address, fireType, 1));
|
|
|
|
+ list.add(perfect(startTime1, endTime1, address, fireType, distanceOfTwoDate));
|
|
|
|
+ list.add(perfect(null, null, address, fireType, distanceOfTwoDateYear));
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<Object> perfect(Date startTime, Date endTime, String address, String fireType, Integer subTime) {
|
|
|
|
+ List<String> fireNumberList = new ArrayList<>();
|
|
|
|
+ if (StringUtils.isNotBlank(fireType)) {
|
|
|
|
+ LambdaQueryWrapper<DemFireStatisticsAttach> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
+ queryWrapper.select(DemFireStatisticsAttach::getFireNumber)
|
|
|
|
+ .eq(DemFireStatisticsAttach::getFireCauseType1, fireType);
|
|
|
|
+ List<DemFireStatisticsAttach> list1 = demFireStatisticsAttachService.list(queryWrapper);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(list1)) {
|
|
|
|
+ for (int i = 0; i < list1.size(); i++) {
|
|
|
|
+ fireNumberList.add(list1.get(i).getFireNumber());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ QueryWrapper<DemFireStatistics> query = Wrappers.query();
|
|
|
|
+ query.select("MONTH (fire_time) monthTime", "COUNT(1) AS aCount")
|
|
|
|
+ .like(StringUtils.isNotBlank(address), "fire_address", address)
|
|
|
|
+ .in(CollectionUtils.isNotEmpty(fireNumberList), "fire_number", fireNumberList)
|
|
|
|
+ .between(startTime != null && endTime != null, "fire_time", startTime, endTime)
|
|
|
|
+ .groupBy("monthTime");
|
|
|
|
+ List<Map<String, Object>> list = this.listMaps(query);
|
|
|
|
+ List<Object> avgList = new ArrayList<>();
|
|
|
|
+ for (int i = 1; i <= 12; i++) {
|
|
|
|
+ int finalI = i;
|
|
|
|
+ list.stream()
|
|
|
|
+ .filter(map -> Integer.parseInt(map.get("monthTime").toString()) == finalI)
|
|
|
|
+ .findFirst()
|
|
|
|
+ .map(map -> {
|
|
|
|
+ avgList.add(Arith.div(Double.parseDouble(map.get("aCount").toString()), subTime, 2));
|
|
|
|
+ return Optional.empty();
|
|
|
|
+ })
|
|
|
|
+ .orElseGet(() -> {
|
|
|
|
+ avgList.add(0.00);
|
|
|
|
+ return Optional.empty();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ return avgList;
|
|
|
|
+ }
|
|
}
|
|
}
|