Browse Source

城市消防体征

jichaobo 2 years ago
parent
commit
c888273a4f

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

@@ -0,0 +1,60 @@
+package com.usky.fire.controller.web;
+
+
+import com.usky.common.core.bean.ApiResult;
+import com.usky.fire.service.DemFireStatisticsAttachService;
+import com.usky.fire.service.DemFireStatisticsService;
+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.List;
+
+/**
+ * <p>
+ * 消防检查人员 前端控制器
+ * </p>
+ *
+ * @author JCB
+ * @since 2022-11-24
+ */
+@RestController
+@RequestMapping("/demFireStatisticsAttach")
+public class DemFireStatisticsAttachController {
+
+    @Autowired
+    private DemFireStatisticsAttachService demFireStatisticsAttachService;
+
+    @Autowired
+    private DemFireStatisticsService demFireStatisticsService;
+
+    /**
+     * 城市消防体征-火灾类型
+     *
+     * @return
+     */
+    @GetMapping("fireType")
+    public ApiResult<List<String>> fireType() {
+        return ApiResult.success(demFireStatisticsAttachService.getFireType());
+    }
+
+    /**
+     * 城市消防体征-火灾趋势图
+     *
+     * @param startTime 开始时间
+     * @param endTime   结束时间
+     * @param address   地址
+     * @param fireType  火灾类型
+     * @return
+     */
+    @GetMapping("fireCountByData")
+    public ApiResult<List<Object>> getFireCountByData(@RequestParam(value = "startTime") String startTime,
+                                                      @RequestParam(value = "endTime") String endTime,
+                                                      @RequestParam(value = "address", required = false) String address,
+                                                      @RequestParam(value = "fireType", required = false) String fireType) {
+        return ApiResult.success(demFireStatisticsService.getFireCountByData(startTime, endTime, address, fireType));
+    }
+}
+

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

@@ -2,6 +2,12 @@ package com.usky.fire.mapper;
 
 import com.usky.fire.domain.DemFireStatistics;
 import com.usky.common.mybatis.core.CrudMapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -11,6 +17,7 @@ import com.usky.common.mybatis.core.CrudMapper;
  * @author JCB
  * @since 2022-09-13
  */
+@Repository
 public interface DemFireStatisticsMapper extends CrudMapper<DemFireStatistics> {
 
 }

+ 2 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/DemFireStatisticsAttachService.java

@@ -26,4 +26,6 @@ public interface DemFireStatisticsAttachService extends CrudService<DemFireStati
     List<String> fireCauseType();
 
     Integer fireStatisticsAttachCount(String fireCauseType1);
+
+    List<String> getFireType();
 }

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

@@ -7,6 +7,7 @@ import com.usky.fire.domain.DemFireStatistics;
 import com.usky.fire.service.vo.DemFireStatisticsVo;
 import com.usky.fire.service.vo.ParameterVo;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -89,4 +90,6 @@ public interface DemFireStatisticsService extends CrudService<DemFireStatistics>
     CommonPage<Map<String, Object>> firePlaceList(String fireNumber, Integer id, Integer pageNum, Integer pageSize);
 
     void updateFirePlace(DemFireStatistics demFireStatistics);
+
+    List<Object> getFireCountByData(String startTime, String endTime, String address, String fireType);
 }

+ 0 - 1
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/DemPoliceInfoService.java

@@ -28,5 +28,4 @@ public interface DemPoliceInfoService extends CrudService<DemPoliceInfo> {
 
     List<Map<String, Object>> warningInstanceScatterer(String streetTown, Integer id);
 
-    List<String> getFireType();
 }

+ 20 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/DemFireStatisticsAttachServiceImpl.java

@@ -8,10 +8,13 @@ import com.usky.common.mybatis.core.AbstractCrudService;
 import com.usky.fire.domain.DemFireStatisticsAttach;
 import com.usky.fire.mapper.DemFireStatisticsAttachMapper;
 import com.usky.fire.service.DemFireStatisticsAttachService;
+import com.usky.fire.service.vo.FireLevelRatioVO;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -56,4 +59,21 @@ public class DemFireStatisticsAttachServiceImpl extends AbstractCrudService<DemF
         int count = this.count(queryWrapper);
         return count;
     }
+
+    @Override
+    public List<String> getFireType() {
+        List<FireLevelRatioVO> list = new ArrayList<>();
+        List<String> fireTypes = this.fireCauseType();
+        if (CollectionUtils.isNotEmpty(fireTypes)) {
+            for (String cause : fireTypes) {
+                FireLevelRatioVO fireLevelRatioVo = new FireLevelRatioVO();
+                fireLevelRatioVo.setFireType(cause);
+                Integer count = this.fireStatisticsAttachCount(cause);
+                fireLevelRatioVo.setRadio(count.doubleValue());
+                list.add(fireLevelRatioVo);
+            }
+        }
+        return list.stream().sorted(Comparator.comparing(FireLevelRatioVO::getRadio).reversed())
+                .map(FireLevelRatioVO::getFireType).collect(Collectors.toList());
+    }
 }

+ 79 - 4
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/DemFireStatisticsServiceImpl.java

@@ -1,6 +1,7 @@
 package com.usky.fire.service.impl;
 
 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.toolkit.CollectionUtils;
 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.usky.common.core.bean.CommonPage;
 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.security.utils.SecurityUtils;
 import com.usky.fire.domain.DemFileLabel;
@@ -27,10 +30,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 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>
@@ -486,4 +487,78 @@ public class DemFireStatisticsServiceImpl extends AbstractCrudService<DemFireSta
         demFireStatisticsAttach.setUpdateTime(LocalDateTime.now());
         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;
+    }
 }

+ 0 - 18
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/DemPoliceInfoServiceImpl.java

@@ -177,24 +177,6 @@ public class DemPoliceInfoServiceImpl extends AbstractCrudService<DemPoliceInfoM
         return list;
     }
 
-
-    @Override
-    public List<String> getFireType() {
-        List<FireLevelRatioVO> list = new ArrayList<>();
-        List<String> fireTypes = demFireStatisticsAttachService.fireCauseType();
-        if (CollectionUtils.isNotEmpty(fireTypes)) {
-            for (String cause : fireTypes) {
-                FireLevelRatioVO fireLevelRatioVo = new FireLevelRatioVO();
-                fireLevelRatioVo.setFireType(cause);
-                Integer count = demFireStatisticsAttachService.fireStatisticsAttachCount(cause);
-                fireLevelRatioVo.setRadio(count.doubleValue());
-                list.add(fireLevelRatioVo);
-            }
-        }
-        return list.stream().sorted(Comparator.comparing(FireLevelRatioVO::getRadio).reversed())
-                .map(FireLevelRatioVO::getFireType).collect(Collectors.toList());
-    }
-
     public void collectByThree(Map<String, List<AlertStatisticsVO>> map, Integer distanceOfTwoDate) {
         for (String type : map.keySet()) {
             List<AlertStatisticsVO> list = map.get(type);

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

@@ -31,6 +31,16 @@ import java.util.stream.Collectors;
 @Slf4j
 public class OnlineMethod {
 
+    public static Date transferString2Date(String s) {
+        Date date = new Date();
+        try {
+            date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(s);
+        } catch (ParseException e) {
+            //LOGGER.error("时间转换错误, string = {}", s, e);
+        }
+        return date;
+    }
+
     /**
      * 默认地球半径
      */