|
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
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.google.common.collect.Lists;
|
|
|
|
+import com.ruoyi.common.core.utils.bean.BeanUtils;
|
|
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.Arith;
|
|
@@ -22,9 +24,10 @@ import com.usky.fire.service.DemFileLabelService;
|
|
import com.usky.fire.service.DemFireLabelAttributeService;
|
|
import com.usky.fire.service.DemFireLabelAttributeService;
|
|
import com.usky.fire.service.DemFireStatisticsAttachService;
|
|
import com.usky.fire.service.DemFireStatisticsAttachService;
|
|
import com.usky.fire.service.DemFireStatisticsService;
|
|
import com.usky.fire.service.DemFireStatisticsService;
|
|
|
|
+import com.usky.fire.service.po.FireStatisticsPO;
|
|
import com.usky.fire.service.util.OnlineMethod;
|
|
import com.usky.fire.service.util.OnlineMethod;
|
|
-import com.usky.fire.service.vo.DemFireStatisticsVo;
|
|
|
|
-import com.usky.fire.service.vo.ParameterVo;
|
|
|
|
|
|
+import com.usky.fire.service.vo.*;
|
|
|
|
+import io.lettuce.core.dynamic.support.ReflectionUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -32,6 +35,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -561,4 +566,189 @@ public class DemFireStatisticsServiceImpl extends AbstractCrudService<DemFireSta
|
|
}
|
|
}
|
|
return avgList;
|
|
return avgList;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<FireLevelRatioVO> getGroupByLevel(String startTime, String endTime, String address) {
|
|
|
|
+ List<FireLevelRatioVO> list = new ArrayList<>();
|
|
|
|
+ int fireCount = 0;
|
|
|
|
+ List<String> fireCauses = demFireStatisticsAttachService.getFireType();
|
|
|
|
+ for (String cause : fireCauses) {
|
|
|
|
+ if (StringUtils.isBlank(cause)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ FireLevelRatioVO fireLevelRatioVo = new FireLevelRatioVO();
|
|
|
|
+ fireLevelRatioVo.setFireType(cause);
|
|
|
|
+ List<String> fireNumberList = new ArrayList<>();
|
|
|
|
+ if (StringUtils.isNotBlank(cause)) {
|
|
|
|
+ LambdaQueryWrapper<DemFireStatisticsAttach> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
+ queryWrapper.select(DemFireStatisticsAttach::getFireNumber)
|
|
|
|
+ .eq(DemFireStatisticsAttach::getFireCauseType1, cause);
|
|
|
|
+ List<DemFireStatisticsAttach> list1 = demFireStatisticsAttachService.list(queryWrapper);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(list1)) {
|
|
|
|
+ for (int i = 0; i < list1.size(); i++) {
|
|
|
|
+ fireNumberList.add(list1.get(i).getFireNumber());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ LambdaQueryWrapper<DemFireStatistics> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
+ queryWrapper.like(StringUtils.isNotBlank(address), DemFireStatistics::getFireAddress, address)
|
|
|
|
+ .between(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime), DemFireStatistics::getFireTime, startTime, endTime);
|
|
|
|
+ Integer count = this.count(queryWrapper);
|
|
|
|
+ fireLevelRatioVo.setRadio(count.doubleValue());
|
|
|
|
+ list.add(fireLevelRatioVo);
|
|
|
|
+ fireCount += count;
|
|
|
|
+ }
|
|
|
|
+ //排序
|
|
|
|
+ List<FireLevelRatioVO> orderByList = list.stream().sorted(Comparator.comparing(FireLevelRatioVO::getRadio).reversed()).limit(10).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ //差集求和
|
|
|
|
+ double sum = list.stream().filter(item -> !orderByList.contains(item)).mapToDouble(FireLevelRatioVO::getRadio).sum();
|
|
|
|
+ orderByList.stream().filter(item -> "其他".equals(item.getFireType())).findAny()
|
|
|
|
+ .map(fireLevelRatio -> {
|
|
|
|
+ fireLevelRatio.setRadio(fireLevelRatio.getRadio() + sum);
|
|
|
|
+ return fireLevelRatio;
|
|
|
|
+ }
|
|
|
|
+ ).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)));
|
|
|
|
+ }
|
|
|
|
+ return orderByList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public CommonPage<FireStatisticsPO> page(Integer current, Integer size, String startTime, String endTime, String address) {
|
|
|
|
+ Page<DemFireStatistics> page = new Page<>(current, size);
|
|
|
|
+ LambdaQueryWrapper<DemFireStatistics> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
+ queryWrapper.between(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime), DemFireStatistics::getFireTime, startTime, endTime)
|
|
|
|
+ .like(StringUtils.isNotBlank(address), DemFireStatistics::getFireAddress, address)
|
|
|
|
+ .orderByDesc(DemFireStatistics::getDeathToll);
|
|
|
|
+ page = this.page(page, queryWrapper);
|
|
|
|
+ List<Map<String, String>> listmap = new ArrayList<>();
|
|
|
|
+ if (CollectionUtils.isNotEmpty(page.getRecords())) {
|
|
|
|
+ List<String> fireNumberList = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < page.getRecords().size(); i++) {
|
|
|
|
+ fireNumberList.add(page.getRecords().get(i).getFireNumber());
|
|
|
|
+ }
|
|
|
|
+ LambdaQueryWrapper<DemFireStatisticsAttach> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
|
+ queryWrapper1.in(DemFireStatisticsAttach::getFireNumber, fireNumberList);
|
|
|
|
+ List<DemFireStatisticsAttach> list = demFireStatisticsAttachService.list(queryWrapper1);
|
|
|
|
+ AtomicReference<Map<String, String>> stringStringMap = new AtomicReference<>();
|
|
|
|
+ listmap = page.getRecords().stream().map(m -> {
|
|
|
|
+ list.stream().filter(m2 -> Objects.equals(m.getFireNumber(), m2.getFireNumber())).forEach(m2 -> {
|
|
|
|
+ stringStringMap.set(convertObjectToMap(m));
|
|
|
|
+ Map<String, String> stringStringMap1 = convertObjectToMap(m2);
|
|
|
|
+ stringStringMap.get().putAll(stringStringMap1);
|
|
|
|
+ });
|
|
|
|
+ return stringStringMap.get();
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<FireStatisticsPO> list = listmap
|
|
|
|
+ .stream()
|
|
|
|
+ .map(this::enhanceFireStatisticsPo).collect(Collectors.toList());
|
|
|
|
+ //筛选出精度和维度是空的数据
|
|
|
|
+ List<FireStatisticsPO> isNullData = list.stream()
|
|
|
|
+ .filter(fireStatisticsPo -> 0.00 == fireStatisticsPo.getLatitude())
|
|
|
|
+ .filter(fireStatisticsPo -> StringUtils.isNotBlank(fireStatisticsPo.getAddress()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ List<List<FireStatisticsPO>> subSets = Lists.partition(isNullData, 10);
|
|
|
|
+ for (List<FireStatisticsPO> listLimit : subSets) {
|
|
|
|
+ String addressList = listLimit.stream().map(FireStatisticsPO::getAddress).collect(Collectors.joining("|"));
|
|
|
|
+ List<LocateInfo> lonLat = OnlineMethod.getLonLat(addressList);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(lonLat)) {
|
|
|
|
+ for (FireStatisticsPO fireStatisticsPo : listLimit) {
|
|
|
|
+ fireStatisticsPo.setLatitude(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getLatitude());
|
|
|
|
+ fireStatisticsPo.setLongitude(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getLongitude());
|
|
|
|
+ fireStatisticsPo.setDistrict(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getDistrict());
|
|
|
|
+ fireStatisticsPo.setStreet(lonLat.get(listLimit.indexOf(fireStatisticsPo)).getStreet());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ baseMapper.updateList(listLimit);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return new CommonPage<>(list, page.getTotal(), page.getSize(), page.getCurrent());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<FireBubbleVO> getAvgAndSum(String startTime, String endTime, String fireType, String unitId) {
|
|
|
|
+ List<FireBubbleVO> fireBubbleVOS = new ArrayList<>();
|
|
|
|
+ List<String> fireNumberList = new ArrayList<>();
|
|
|
|
+ if (StringUtils.isNotBlank(fireType)) {
|
|
|
|
+ LambdaQueryWrapper<DemFireStatisticsAttach> queryWrapper = Wrappers.lambdaQuery();
|
|
|
|
+ queryWrapper.select(DemFireStatisticsAttach::getFireNumber)
|
|
|
|
+ .eq(DemFireStatisticsAttach::getFireCauseType1, fireType);
|
|
|
|
+ List<DemFireStatisticsAttach> list = demFireStatisticsAttachService.list(queryWrapper);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ fireNumberList.add(list.get(i).getFireNumber());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ QueryWrapper<DemFireStatistics> query = Wrappers.query();
|
|
|
|
+ query.select("administrative_division as region", "IFNULL(sum(death_toll),0) as deathPerson", "IFNULL(avg(burned_area),0.00) as fireArea", "count(1) as fireCount")
|
|
|
|
+ .eq(StringUtils.isNotBlank(unitId), "company_code", unitId)
|
|
|
|
+ .between(StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime), "fire_time", startTime, endTime)
|
|
|
|
+ .in(CollectionUtils.isNotEmpty(fireNumberList), "fire_number", fireNumberList)
|
|
|
|
+ .groupBy("administrative_division");
|
|
|
|
+ List<Map<String, Object>> list = this.listMaps(query);
|
|
|
|
+// list = list.stream().filter(s -> s.get("region").toString().contains("派出所")).collect(Collectors.toList());
|
|
|
|
+ list.forEach(s -> {
|
|
|
|
+ FireBubbleVO fireBubbleVo = new FireBubbleVO();
|
|
|
|
+ if (s.get("region").toString().contains("派出所")){
|
|
|
|
+ fireBubbleVo.setRegion(s.get("region").toString().replace("派出所",""));
|
|
|
|
+ }else {
|
|
|
|
+ fireBubbleVo.setRegion(s.get("region").toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fireBubbleVo.setFireCount(Integer.valueOf(s.get("fireCount").toString()));
|
|
|
|
+ fireBubbleVo.setDeathToll(Double.valueOf(s.get("deathPerson").toString()));
|
|
|
|
+ fireBubbleVo.setFireArea(Double.valueOf(s.get("fireArea").toString()));
|
|
|
|
+ fireBubbleVOS.add(fireBubbleVo);
|
|
|
|
+ });
|
|
|
|
+ return fireBubbleVOS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public FireStatisticsPO enhanceFireStatisticsPo(Map<String, String> map) {
|
|
|
|
+ FireStatisticsPO fireStatisticsPo = new FireStatisticsPO();
|
|
|
|
+ fireStatisticsPo.setId(Optional.ofNullable(map.get("fireNumber")).filter(s -> !"null".equals(s)).orElse(""));
|
|
|
|
+ fireStatisticsPo.setAddress(Optional.ofNullable(map.get("fireAddress")).filter(s -> !"null".equals(s)).orElse(""));
|
|
|
|
+ fireStatisticsPo.setBurnedArea(Optional.ofNullable(map.get("burnedArea")).filter(s -> !"null".equals(s)).orElse(""));
|
|
|
|
+ fireStatisticsPo.setPropertyLoss(Optional.ofNullable(map.get("directPropertyLoss")).filter(s -> !"null".equals(s)).orElse(""));
|
|
|
|
+ fireStatisticsPo.setDeathToll(Optional.ofNullable(map.get("deathToll")).filter(s -> !"null".equals(s)).orElse(""));
|
|
|
|
+ fireStatisticsPo.setNonFatal(Optional.ofNullable(map.get("victimNumber")).filter(s -> !"null".equals(s)).orElse(""));
|
|
|
|
+ fireStatisticsPo.setDisasterHome(Optional.ofNullable(map.get("affectedHouse")).filter(s -> !"null".equals(s)).orElse(""));
|
|
|
|
+ fireStatisticsPo.setFireCause(Optional.ofNullable(map.get("fireCauseType1")).filter(s -> !"null".equals(s)).orElse(""));
|
|
|
|
+ fireStatisticsPo.setFireLevel(Optional.ofNullable(map.get("fireGrade")).filter(s -> !"null".equals(s)).orElse(""));
|
|
|
|
+ fireStatisticsPo.setLongitude(Double.valueOf(Optional.ofNullable(map.get("longitude")).filter(StringUtils::isNotBlank).orElse("0.00")));
|
|
|
|
+ fireStatisticsPo.setLatitude(Double.valueOf(Optional.ofNullable(map.get("latitude")).filter(StringUtils::isNotBlank).orElse("0.00")));
|
|
|
|
+ fireStatisticsPo.setDistrict(map.get("district"));
|
|
|
|
+ fireStatisticsPo.setStreet(map.get("street"));
|
|
|
|
+ fireStatisticsPo.setPlaceOne(map.get("initialFuelType1"));
|
|
|
|
+ fireStatisticsPo.setPlaceTwo(map.get("initialFuelType2"));
|
|
|
|
+ fireStatisticsPo.setFireGoodsOne(map.get("fireSiteType1"));
|
|
|
|
+ fireStatisticsPo.setFireGoodsTwo(map.get("fireSiteType2"));
|
|
|
|
+ fireStatisticsPo.setNature(map.get("useCharacterName"));
|
|
|
|
+ return fireStatisticsPo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private static Map<String, String> convertObjectToMap(Object obj) {
|
|
|
|
+ return Arrays.stream(BeanUtils.getPropertyDescriptors(obj.getClass()))
|
|
|
|
+ .filter(pd -> !"class".equals(pd.getName()))
|
|
|
|
+ .collect(HashMap::new,
|
|
|
|
+ (map, pd) -> {
|
|
|
|
+ if (ReflectionUtils.invokeMethod(pd.getReadMethod(), obj) != null) {
|
|
|
|
+ map.put(pd.getName(), String.valueOf(ReflectionUtils.invokeMethod(pd.getReadMethod(), obj)));
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ HashMap::putAll);
|
|
|
|
+ }
|
|
}
|
|
}
|