Forráskód Böngészése

火灾数据分析

jichaobo 2 éve
szülő
commit
06620c2a27

+ 57 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/DemFireStatisticsAttachController.java

@@ -2,14 +2,19 @@ package com.usky.fire.controller.web;
 
 
 import com.usky.common.core.bean.ApiResult;
+import com.usky.common.core.bean.CommonPage;
 import com.usky.fire.service.DemFireStatisticsAttachService;
 import com.usky.fire.service.DemFireStatisticsService;
+import com.usky.fire.service.po.FireStatisticsPO;
+import com.usky.fire.service.vo.FireBubbleVO;
+import com.usky.fire.service.vo.FireLevelRatioVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -56,5 +61,57 @@ public class DemFireStatisticsAttachController {
                                                       @RequestParam(value = "fireType", required = false) String fireType) {
         return ApiResult.success(demFireStatisticsService.getFireCountByData(startTime, endTime, address, fireType));
     }
+
+
+    /**
+     * 火灾数据分析-火灾原因占比
+     *
+     * @param startTime 开始时间
+     * @param endTime   结束时间
+     * @param address   火灾地址
+     * @return
+     */
+    @GetMapping("fireCauseRatio")
+    public ApiResult<List<FireLevelRatioVO>> getGroupByLevel(@RequestParam(value = "startTime", required = false) String startTime,
+                                                             @RequestParam(value = "endTime", required = false) String endTime,
+                                                             @RequestParam(value = "address", required = false) String address) {
+        return ApiResult.success(demFireStatisticsService.getGroupByLevel(startTime, endTime, address));
+    }
+
+    /**
+     * 火灾数据分析-详细火灾情况
+     *
+     * @param startTime 开始时间
+     * @param endTime   结束时间
+     * @param address   地址
+     * @param current   当前页
+     * @param size      每页条数
+     * @return
+     */
+    @GetMapping("page")
+    public ApiResult<CommonPage<FireStatisticsPO>> page(@RequestParam(value = "startTime", required = false) String startTime,
+                                                        @RequestParam(value = "endTime", required = false) String endTime,
+                                                        @RequestParam(value = "address", required = false) String address,
+                                                        @RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
+                                                        @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
+        return ApiResult.success(demFireStatisticsService.page(current, size, startTime, endTime, address));
+    }
+
+    /**
+     * 火灾数据分析-火灾情况分析
+     *
+     * @param startTime 开始时间
+     * @param endTime   结束时间
+     * @param fireType  火灾类型
+     * @param unitId    单位代码
+     * @return
+     */
+    @GetMapping("fireBubble")
+    public ApiResult<List<FireBubbleVO>> getFireBubble(@RequestParam(value = "startTime", required = false) String startTime,
+                                                       @RequestParam(value = "endTime", required = false) String endTime,
+                                                       @RequestParam(value = "fireType", required = false) String fireType,
+                                                       @RequestParam(value = "unitId", required = false) String unitId) {
+        return ApiResult.success(demFireStatisticsService.getAvgAndSum(startTime, endTime, fireType, unitId));
+    }
 }
 

+ 6 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/domain/DemFireStatistics.java

@@ -289,6 +289,12 @@ public class DemFireStatistics implements Serializable {
      */
     private LocalDateTime updateTime;
 
+    private String longitude;
+    private String latitude;
+    private String district;
+    private String street;
+
+
     /**
      * 起火物(一级)
      */

+ 3 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/mapper/DemFireStatisticsMapper.java

@@ -2,6 +2,7 @@ package com.usky.fire.mapper;
 
 import com.usky.fire.domain.DemFireStatistics;
 import com.usky.common.mybatis.core.CrudMapper;
+import com.usky.fire.service.po.FireStatisticsPO;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
@@ -20,4 +21,6 @@ import java.util.Map;
 @Repository
 public interface DemFireStatisticsMapper extends CrudMapper<DemFireStatistics> {
 
+    int updateList(List<FireStatisticsPO> list);
+
 }

+ 10 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/DemFireStatisticsService.java

@@ -4,9 +4,13 @@ import com.usky.common.core.bean.CommonPage;
 import com.usky.common.mybatis.core.CrudService;
 import com.usky.fire.domain.DemFileLabel;
 import com.usky.fire.domain.DemFireStatistics;
+import com.usky.fire.service.po.FireStatisticsPO;
 import com.usky.fire.service.vo.DemFireStatisticsVo;
+import com.usky.fire.service.vo.FireBubbleVO;
+import com.usky.fire.service.vo.FireLevelRatioVO;
 import com.usky.fire.service.vo.ParameterVo;
 
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -92,4 +96,10 @@ public interface DemFireStatisticsService extends CrudService<DemFireStatistics>
     void updateFirePlace(DemFireStatistics demFireStatistics);
 
     List<Object> getFireCountByData(String startTime, String endTime, String address, String fireType);
+
+    List<FireLevelRatioVO> getGroupByLevel(String startTime, String endTime, String address);
+
+    CommonPage<FireStatisticsPO> page(Integer current, Integer size, String startTime, String endTime, String address);
+
+    List<FireBubbleVO> getAvgAndSum(String startTime, String endTime, String fireType, String unitId);
 }

+ 192 - 2
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/DemFireStatisticsServiceImpl.java

@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 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.exception.BusinessException;
 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.DemFireStatisticsAttachService;
 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.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.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -32,6 +35,8 @@ import org.springframework.transaction.annotation.Transactional;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -561,4 +566,189 @@ public class DemFireStatisticsServiceImpl extends AbstractCrudService<DemFireSta
         }
         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);
+    }
 }

+ 85 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/po/FireStatisticsPO.java

@@ -0,0 +1,85 @@
+package com.usky.fire.service.po;
+
+import com.usky.fire.service.vo.LocateInfo;
+import lombok.Data;
+
+/**
+ * @author yq
+ * @date 2021/5/28 9:49
+ * 火灾统计
+ */
+@Data
+public class FireStatisticsPO extends LocateInfo {
+
+    /**
+     * id
+     */
+    private String id;
+
+
+    /**
+     * 火灾地址
+     */
+    private String address;
+
+    /**
+     * 过火面积
+     */
+    private String burnedArea;
+
+    /**
+     * 财产损失
+     */
+    private String propertyLoss;
+
+
+    /**
+     * 死亡人数
+     */
+    private String deathToll;
+
+    /**
+     * 受伤人数
+     */
+    private String nonFatal;
+
+    /**
+     * 受灾户数
+     */
+    private String disasterHome;
+
+    /**
+     * 受灾原因
+     */
+    private String fireCause;
+
+    /**
+     * 火灾登记
+     */
+    private String fireLevel;
+
+    /**
+     * 场所一级
+     */
+    private String placeOne;
+    /**
+     * 场所二级
+     */
+    private String placeTwo;
+
+    /**
+     * 起火物一级
+     */
+    private String fireGoodsOne;
+
+    /**
+     * 起火物二级
+     */
+    private String fireGoodsTwo;
+
+    /**
+     * 性质
+     */
+    private String nature;
+
+}

+ 32 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/vo/FireBubbleVO.java

@@ -0,0 +1,32 @@
+package com.usky.fire.service.vo;
+
+import lombok.Data;
+
+/**
+ * @author yq
+ * @date 2021/6/24 13:22
+ * 火灾气泡图
+ */
+@Data
+public class FireBubbleVO {
+
+    /**
+     * 街道
+     */
+    private String region;
+
+    /**
+     * 死亡人数
+     */
+    private Double deathToll;
+
+    /**
+     * 火灾面积
+     */
+    private Double fireArea;
+
+    /**
+     * 火灾数
+     */
+    private Integer fireCount;
+}

+ 12 - 0
service-fire/service-fire-biz/src/main/resources/mapper/fire/DemFireStatisticsMapper.xml

@@ -57,6 +57,18 @@
         <result column="create_time" property="createTime" />
         <result column="update_person" property="updatePerson" />
         <result column="update_time" property="updateTime" />
+        <result column="longitude" property="longitude" />
+        <result column="latitude" property="latitude" />
+        <result column="district" property="district" />
+        <result column="street" property="street" />
     </resultMap>
 
+    <update id="updateList" parameterType="java.util.List">
+        <foreach collection="list" item="item" index="index" separator=";">
+            UPDATE dem_fire_statistics
+            SET longitude = #{item.longitude},latitude = #{item.latitude},district = #{item.district},street = #{item.street}
+            WHERE fire_number = #{item.id}
+        </foreach>
+    </update>
+
 </mapper>