Bläddra i källkod

完善数据补充

yq 3 år sedan
förälder
incheckning
0f726d015a

+ 2 - 0
mhfire-controller/src/main/java/com/bizmatics/mhfire/controller/MhfireControllerApplication.java

@@ -4,10 +4,12 @@ import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 @ComponentScan("com.bizmatics")
 @SpringBootApplication
 @MapperScan("com.bizmatics.mhfire.persistence")
+@EnableScheduling
 public class MhfireControllerApplication {
 
     public static void main(String[] args) {

+ 9 - 6
mhfire-controller/src/main/java/com/bizmatics/mhfire/controller/web/AlertControllerWeb.java

@@ -6,13 +6,11 @@ import com.bizmatics.mhfire.model.Alert;
 import com.bizmatics.mhfire.service.AlertService;
 import com.bizmatics.mhfire.service.vo.AlertStatisticsVO;
 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 org.springframework.web.bind.annotation.*;
 
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 警情模块
@@ -33,7 +31,7 @@ public class AlertControllerWeb {
      * @return
      */
     @GetMapping("/alertStatisticsByHouse")
-    public ApiResult<List<AlertStatisticsVO>> getAlertStatisticsByHouse() {
+    public ApiResult<Map<String, List<AlertStatisticsVO>>> getAlertStatisticsByHouse() {
         return ApiResult.success(alertService.getAlertStatisticsByHouse());
     }
 
@@ -44,7 +42,7 @@ public class AlertControllerWeb {
      * @return
      */
     @GetMapping("/alertStatisticsByMonth")
-    public ApiResult<List<AlertStatisticsVO>> getAlertStatisticsByMonth() {
+    public ApiResult<Map<String, List<AlertStatisticsVO>>> getAlertStatisticsByMonth() {
         return ApiResult.success(alertService.getAlertStatisticsByMonth());
     }
 
@@ -78,4 +76,9 @@ public class AlertControllerWeb {
                                                                  @RequestParam(required = false) Date endTime) {
         return ApiResult.success(alertService.getAlertStatistics(startTime, endTime));
     }
+
+    @PostMapping("/add")
+    public void add(@RequestBody List<Alert> alert){
+        alertService.saveBatch(alert);
+    }
 }

+ 2 - 2
mhfire-controller/src/main/resources/application-dev.properties

@@ -16,7 +16,7 @@ mybatis.refresh.sleep-seconds=20
 # datasource
 spring.autoconfigure.exclude=com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
 spring.datasource.dynamic.primary=mhfire
-spring.datasource.dynamic.datasource.mhfire.url=jdbc:mysql://120.55.70.156:3306/mhfire?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&characterEncoding=utf8&allowMultiQueries=true
+spring.datasource.dynamic.datasource.mhfire.url=jdbc:mysql://120.55.70.156:3306/mhfire?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8&allowMultiQueries=true
 spring.datasource.dynamic.datasource.mhfire.username=root
 spring.datasource.dynamic.datasource.mhfire.password=123456
 #À¶Ð¡°ï
@@ -56,7 +56,7 @@ spring.datasource.druid.filter.slf4j.result-set-open-after-log-enabled=false
 spring.datasource.druid.filter.slf4j.result-set-close-after-log-enabled=false
 # jackson
 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
-spring.jackson.time-zone=GMT+0
+spring.jackson.time-zone=GMT+8
 spring.jackson.default-property-inclusion=always
 #spring.jackson.serialization.indent_output=true
 spring.jackson.serialization.fail-on-empty-beans=false

+ 2 - 2
mhfire-controller/src/main/resources/application-prod.properties

@@ -16,7 +16,7 @@ mybatis.refresh.sleep-seconds=20
 # datasource
 spring.autoconfigure.exclude=com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
 spring.datasource.dynamic.primary=mhfire
-spring.datasource.dynamic.datasource.mhfire.url=jdbc:mysql://32.0.15.104:3306/mhxf?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&characterEncoding=utf8&allowMultiQueries=true
+spring.datasource.dynamic.datasource.mhfire.url=jdbc:mysql://32.0.15.104:3306/mhxf?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&characterEncoding=utf8&allowMultiQueries=true
 spring.datasource.dynamic.datasource.mhfire.username=root
 spring.datasource.dynamic.datasource.mhfire.password=xfzdadmin#2021
 spring.datasource.dynamic.druid.initial-size=5                                                                       
@@ -52,7 +52,7 @@ spring.datasource.druid.filter.slf4j.result-set-open-after-log-enabled=false
 spring.datasource.druid.filter.slf4j.result-set-close-after-log-enabled=false
 # jackson
 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
-spring.jackson.time-zone=GMT+0
+spring.jackson.time-zone=GMT+8
 spring.jackson.default-property-inclusion=always
 #spring.jackson.serialization.indent_output=true
 spring.jackson.serialization.fail-on-empty-beans=false

+ 2 - 2
mhfire-mapping/src/main/resources/mapper/mysql/AlertMapper.xml

@@ -26,7 +26,7 @@
         <result column="qrqk" property="qrqk" />
         <result column="qx" property="qx" />
         <result column="qy" property="qy" />
-        <result column="sJC" property="sJC" />
+        <result column="sJC" property="sjc" />
         <result column="tzdcsj" property="tzdcsj" />
         <result column="tzfdsj" property="tzfdsj" />
         <result column="tzsj" property="tzsj" />
@@ -46,7 +46,7 @@
     </select>
     <select id="getCountByMonth" resultType="java.util.Map">
         SELECT
-    DATE_FORMAT(dcsj, '%Y-%m-%d') monthTime,
+    month(dcsj) monthTime,
     COUNT(id) as aCount,
     ajlx as aType
     FROM

+ 3 - 2
mhfire-model/src/main/java/com/bizmatics/mhfire/model/Alert.java

@@ -1,5 +1,6 @@
 package com.bizmatics.mhfire.model;
 
+import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fasterxml.jackson.annotation.JsonAlias;
@@ -61,7 +62,7 @@ public class Alert implements Serializable {
     @TableField("gIS_Y")
     private String gisY;
 
-    @TableId(value = "id")
+    @TableId(value = "id",type = IdType.INPUT)
     private String id;
 
     private String larq;
@@ -76,7 +77,7 @@ public class Alert implements Serializable {
 
     @JsonAlias("sJC")
     @TableField("sJC")
-    private Date sJC;
+    private Date sjc;
 
     private String tzdcsj;
 

+ 3 - 2
mhfire-service/src/main/java/com/bizmatics/mhfire/service/AlertService.java

@@ -7,6 +7,7 @@ import com.bizmatics.mhfire.service.vo.AlertStatisticsVO;
 
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author yq
@@ -20,7 +21,7 @@ public interface AlertService  extends CrudService<Alert> {
      * 查询当天24小时警情
      * @return
      */
-    List<AlertStatisticsVO> getAlertStatisticsByHouse();
+    Map<String, List<AlertStatisticsVO>> getAlertStatisticsByHouse();
 
 
 
@@ -28,7 +29,7 @@ public interface AlertService  extends CrudService<Alert> {
      * 查询每年12个月警情
      * @return
      */
-    List<AlertStatisticsVO> getAlertStatisticsByMonth();
+    Map<String, List<AlertStatisticsVO>> getAlertStatisticsByMonth();
 
 
     /**

+ 43 - 14
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/AlertServiceImpl.java

@@ -15,10 +15,8 @@ import com.bizmatics.mhfire.service.util.Arith;
 import com.bizmatics.mhfire.service.vo.AlertStatisticsVO;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author yq
@@ -27,15 +25,42 @@ import java.util.Map;
 @Service
 public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> implements AlertService {
 
+    private static final String[] ALERT_TYPE = {"火灾","社会救助","抢险救援"};
 
     @Override
-    public List<AlertStatisticsVO> getAlertStatisticsByHouse() {
+    public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByHouse() {
         Date date = new Date();
         Date startTime = DateUtils.getDayStartTime(date);
-        return enhanceList(baseMapper.getCountByHorse(startTime, date));
+        Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(baseMapper.getCountByHorse(startTime, date));
+        perfect(typeMap,24);
+        return typeMap;
     }
 
-    public List<AlertStatisticsVO> enhanceList(List<Map<String,Object>> mapList){
+    public void perfect(Map<String, List<AlertStatisticsVO>> typeMap,Integer times){
+        for (String type:ALERT_TYPE) {
+            if (!typeMap.containsKey(type)){
+                typeMap.put(type,new ArrayList<>());
+            }
+            perfectDate(typeMap.get(type), times);
+        }
+    }
+
+    public void perfectDate(List<AlertStatisticsVO> list,Integer times){
+        for (int i = 1; i < times; i++) {
+            int finalI = i;
+            if (list.stream().noneMatch(asv->Integer.parseInt(asv.getMonth()) == finalI)){
+                AlertStatisticsVO asv = new AlertStatisticsVO();
+                asv.setMonth(Integer.toString(i));
+                asv.setNumber(0);
+                list.add(asv);
+            }
+        }
+        list.sort(Comparator.comparingInt(x -> Integer.parseInt(x.getMonth())));
+    }
+
+
+
+    public Map<String, List<AlertStatisticsVO>> enhanceList(List<Map<String,Object>> mapList){
         List<AlertStatisticsVO> list = new ArrayList<>();
         for (Map<String, Object> map:mapList) {
             AlertStatisticsVO alertStatisticsVo = new AlertStatisticsVO();
@@ -45,22 +70,26 @@ public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> im
             alertStatisticsVo.setType(map.get("aType").toString());
             list.add(alertStatisticsVo);
         }
-        return list;
+        return list.stream().collect(Collectors.groupingBy(AlertStatisticsVO::getType));
     }
 
 
     @Override
-    public List<AlertStatisticsVO> getAlertStatisticsByMonth() {
+    public Map<String, List<AlertStatisticsVO>> getAlertStatisticsByMonth() {
         Date date = new Date();
         Date startTime = DateUtils.getDayStartTime(date);
-        return enhanceList(baseMapper.getCountByMonth(startTime, date));
+        Map<String, List<AlertStatisticsVO>> typeMap = enhanceList(baseMapper.getCountByMonth(startTime, date));
+        perfect(typeMap,12);
+        return typeMap;
     }
 
     @Override
     public CommonPage<Alert> page(Integer current, Integer size, Date startTime, Date endTime) {
         IPage<Alert> page = new Page<>(current, size);
         LambdaQueryWrapper<Alert> queryWrapper = Wrappers.lambdaQuery();
-        queryWrapper.between(Alert::getDcsj,startTime,endTime);
+        if (null != startTime && null != endTime){
+            queryWrapper.between(Alert::getDcsj,startTime,endTime);
+        }
         page = this.page(page, queryWrapper);
         return  this.ToCommonPage(page);
     }
@@ -68,9 +97,9 @@ public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> im
     @Override
     public List<AlertStatisticsVO> getAlertStatistics(Date startTime, Date endTime) {
         List<AlertStatisticsVO> list = new ArrayList<>();
-        list.add(getAsV(startTime, endTime, "火灾"));
-        list.add(getAsV(startTime, endTime, "社会救援"));
-        list.add(getAsV(startTime, endTime, "抢险救援"));
+        list.add(getAsV(startTime, endTime, ALERT_TYPE[0]));
+        list.add(getAsV(startTime, endTime, ALERT_TYPE[1]));
+        list.add(getAsV(startTime, endTime, ALERT_TYPE[2]));
         int sum = list.stream().mapToInt(AlertStatisticsVO::getNumber).sum();
         list.forEach(alertStatisticsVO -> {
             if (0 == sum){

+ 3 - 0
mhfire-service/src/main/java/com/bizmatics/mhfire/service/job/AlertJob.java

@@ -25,6 +25,8 @@ public class AlertJob{
     @Autowired
     private AlertService alertService;
 
+
+//    @Scheduled(cron = "0 0 0 */1 * ?")
     public void execute(){
         try {
             String token = AlertAndSiteApi.login(AlertAndSiteApi.USER_NAME, AlertAndSiteApi.USER_PASSWORD);
@@ -36,6 +38,7 @@ public class AlertJob{
         }
     }
 
+
     public void executeToday(){
         try {
             String token = AlertAndSiteApi.login(AlertAndSiteApi.USER_NAME, AlertAndSiteApi.USER_PASSWORD);

+ 1 - 1
mhfire-service/src/main/java/com/bizmatics/mhfire/service/job/FireSiteJob.java

@@ -23,7 +23,7 @@ public class FireSiteJob {
 
     @Autowired
     private FireSiteService fireSiteService;
-
+//    @Scheduled(cron = "0 0 0 */1 * ?")
     public void execute(){
         try {
             String token = AlertAndSiteApi.login(AlertAndSiteApi.USER_NAME, AlertAndSiteApi.USER_PASSWORD);