Ver código fonte

同步代码

yq 3 anos atrás
pai
commit
766c0f4429

+ 23 - 0
mhfire-controller/src/main/java/com/bizmatics/mhfire/controller/web/AlertControllerWeb.java

@@ -4,6 +4,7 @@ import com.bizmatics.common.core.bean.ApiResult;
 import com.bizmatics.common.core.bean.CommonPage;
 import com.bizmatics.mhfire.model.Alert;
 import com.bizmatics.mhfire.service.AlertService;
+import com.bizmatics.mhfire.service.vo.AlertMapVO;
 import com.bizmatics.mhfire.service.vo.AlertStatisticsVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -66,6 +67,23 @@ public class AlertControllerWeb {
         return ApiResult.success(alertService.page(current, size, startTime, endTime));
     }
 
+    /**
+     * 地图撒点
+     *
+     * @param current   页数
+     * @param size      条数
+     * @param startTime 开始时间
+     * @param endTime   结束时间
+     * @return
+     */
+    @GetMapping("/pageMap")
+    public ApiResult<CommonPage<AlertMapVO>> pageMap(@RequestParam(required = false) Integer current,
+                                                     @RequestParam(required = false) Integer size,
+                                                     @RequestParam(required = false) Date startTime,
+                                                     @RequestParam(required = false) Date endTime) {
+        return ApiResult.success(alertService.pageMap(current, size, startTime, endTime));
+    }
+
     /**
      * 查询不同警情(社会救助,警情,火灾)的占比
      *
@@ -79,6 +97,11 @@ public class AlertControllerWeb {
         return ApiResult.success(alertService.getAlertStatistics(startTime, endTime));
     }
 
+    @GetMapping("/one")
+    public ApiResult<Alert> getOne(@RequestParam String id) {
+        return ApiResult.success(alertService.getOne(id));
+    }
+
     @PostMapping("/add")
     public void add(@RequestBody List<Alert> alert){
         alertService.saveBatch(alert);

+ 4 - 0
mhfire-service/src/main/java/com/bizmatics/mhfire/service/AlertService.java

@@ -3,6 +3,7 @@ package com.bizmatics.mhfire.service;
 import com.bizmatics.common.core.bean.CommonPage;
 import com.bizmatics.common.mvc.base.CrudService;
 import com.bizmatics.mhfire.model.Alert;
+import com.bizmatics.mhfire.service.vo.AlertMapVO;
 import com.bizmatics.mhfire.service.vo.AlertStatisticsVO;
 
 import java.util.Date;
@@ -42,6 +43,7 @@ public interface AlertService  extends CrudService<Alert> {
      */
     CommonPage<Alert> page(Integer current, Integer size, Date startTime, Date endTime);
 
+    CommonPage<AlertMapVO> pageMap(Integer current, Integer size, Date startTime, Date endTime);
     /**
      * 查询不同警情(社会救助,警情,火灾)的占比
      * @param startTime
@@ -50,5 +52,7 @@ public interface AlertService  extends CrudService<Alert> {
      */
     List<AlertStatisticsVO> getAlertStatistics(Date startTime, Date endTime);
 
+    Alert getOne(String id);
+
 
 }

+ 10 - 9
mhfire-service/src/main/java/com/bizmatics/mhfire/service/api/AlertAndSiteApi.java

@@ -29,19 +29,19 @@ public class AlertAndSiteApi {
     /**
      * 密码
      */
-    public static final String USER_PASSWORD = "4VshDAQwHJEQSikJKE3oIiwxDcjfUEbi5nTWsNX6Y8ZFX2rk6c6ez7uDZdRjsQfzwSEGVVqdIfPeq1JPLYqw==";
+    public static final String USER_PASSWORD = "NOXBwA24Ojt+kp/wUxkLz0h2viJ7lQkyyBexlLkfKvU7/BW1RZjfUNUkW9Ot0pS/Bv17I1JKCjSSvZVAqp/Xug==";
     /**
      * 登录url
      */
-    private static final String LOGIN_URL = "http://172.200.50.4:7100/bsUser/user/login";
+    private static final String LOGIN_URL = "http://172.200.50.4/mhxfzd/mhapi/bsUser/user/login";
     /**
      * 警情url
      */
-    private static final String ALERT_URL = "http://172.200.50.4:7100/xf/case/queryCase";
+    private static final String ALERT_URL = "http://172.200.50.4/mhxfzd/mhapi/xf/case/queryCase";
     /**
      * 消防站点url
      */
-    private static final String FIRE_SITE_URL = "http://172.200.50.4:7100/xf/fire/queryNature";
+    private static final String FIRE_SITE_URL = "http://172.200.50.4/mhxfzd/mhapi/xf/fire/queryNature";
 
     private static final ObjectMapper MAPPER = new ObjectMapper();
 
@@ -55,7 +55,7 @@ public class AlertAndSiteApi {
         params.put("userPassword",userPassword);
         String token = "";
         try {
-            String result = HttpUtils.postJson(LOGIN_URL, JsonUtils.toJson(params), null);
+            String result = HttpUtils.postJson(LOGIN_URL, params, null);
             JsonNode arrNode = new ObjectMapper().readTree(result);
             if ("200".equals(arrNode.get("code").asText())){
                 token = arrNode.get("data").asText();
@@ -86,13 +86,14 @@ public class AlertAndSiteApi {
         Map<String,String> header = new HashMap<>();
         header.put("Authorization",token);
         try {
-            String result = HttpUtils.postJson(ALERT_URL, JsonUtils.toJson(params), header);
+            String result = HttpUtils.postJson(ALERT_URL, params, header);
             JsonNode arrNode = MAPPER.readTree(result);
             if ("200".equals(arrNode.get("code").asText())){
                 JsonNode data = arrNode.get("data");
                 JsonNode iterms = data.get("items");
                 if (iterms.isArray() && iterms.size() > 0){
-                    alerts = MAPPER.readValue(iterms.traverse(), new TypeReference<List<Alert>>() {});
+                    alerts = JsonUtils.fromJson(MAPPER.writeValueAsString(iterms), new TypeReference<List<Alert>>() {
+                    });
                 }
             }else {
                 throw new BusinessException("警情api失败"+ arrNode.get("msg"));
@@ -124,13 +125,13 @@ public class AlertAndSiteApi {
         Map<String,String> header = new HashMap<>();
         header.put("Authorization",token);
         try {
-            String result = HttpUtils.postJson(FIRE_SITE_URL, JsonUtils.toJson(params), header);
+            String result = HttpUtils.postJson(FIRE_SITE_URL, params, header);
             JsonNode arrNode = MAPPER.readTree(result);
             if ("200".equals(arrNode.get("code").asText())){
                 JsonNode data = arrNode.get("data");
                 JsonNode iterms = data.get("items");
                 if (iterms.isArray() && iterms.size() > 0){
-                    list = MAPPER.readValue(iterms.traverse(), new TypeReference<List<FireSite>>() {});
+                    list = MAPPER.readValue(MAPPER.writeValueAsString(iterms), new TypeReference<List<FireSite>>() {});
                 }
             }else {
                 throw new BusinessException("站点api失败"+arrNode.get("msg"));

+ 45 - 4
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/AlertServiceImpl.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.bizmatics.common.core.bean.CommonPage;
+import com.bizmatics.common.core.util.BeanMapperUtils;
 import com.bizmatics.common.core.util.DateUtils;
 import com.bizmatics.common.core.util.StringUtils;
 import com.bizmatics.common.mvc.base.AbstractCrudService;
@@ -12,6 +13,7 @@ import com.bizmatics.mhfire.model.Alert;
 import com.bizmatics.mhfire.persistence.mapper.AlertMapper;
 import com.bizmatics.mhfire.service.AlertService;
 import com.bizmatics.mhfire.service.util.Arith;
+import com.bizmatics.mhfire.service.vo.AlertMapVO;
 import com.bizmatics.mhfire.service.vo.AlertStatisticsVO;
 import org.springframework.stereotype.Service;
 
@@ -101,18 +103,57 @@ public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> im
         return  this.ToCommonPage(page);
     }
 
+    @Override
+    public CommonPage<AlertMapVO> pageMap(Integer current, Integer size, Date startTime, Date endTime) {
+
+        LambdaQueryWrapper<Alert> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.select(Alert::getId,Alert::getGisX,Alert::getGisY);
+        if (null != startTime && null != endTime){
+            queryWrapper.between(Alert::getDcsj,startTime,endTime);
+        }
+        CommonPage<AlertMapVO> commonPage;
+        if (null != current && size != null){
+            IPage<Alert> page = new Page<>(current,size);
+            page = this.page(page,queryWrapper);
+            commonPage = new CommonPage<AlertMapVO>(BeanMapperUtils.mapList(page.getRecords(),Alert.class,AlertMapVO.class),page.getTotal(),page.getSize(),page.getCurrent());
+        }else {
+            List<Alert> list = this.list(queryWrapper);
+            commonPage = new CommonPage<AlertMapVO>(BeanMapperUtils.mapList(list,Alert.class,AlertMapVO.class),list.size(),list.size(),1);
+        }
+        return commonPage;
+    }
+
+
+    @Override
+    public Alert getOne(String id) {
+        return this.getById(id);
+    }
+
     @Override
     public List<AlertStatisticsVO> getAlertStatistics(Date startTime, Date endTime) {
+
+        //获取同比
+        Date upStartTime = DateUtils.addYears(startTime, -1);
+        Date upEndTime = DateUtils.addYears(endTime, -1);
         List<AlertStatisticsVO> list = new ArrayList<>();
         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){
+            AlertStatisticsVO upAsv = getAsV(upStartTime, upEndTime, alertStatisticsVO.getType());
+            Integer number = alertStatisticsVO.getNumber();
+            Integer upNumber = upAsv.getNumber();
+            if (number.equals(upNumber)) {
+                alertStatisticsVO.setSameStatus(0);
+            } else if (number > upNumber) {
+                alertStatisticsVO.setSameStatus(1);
+            } else {
+                alertStatisticsVO.setSameStatus(2);
+            }
+            if (0 != upNumber) {
+                alertStatisticsVO.setRadio(Arith.div(number, upNumber));
+            } else {
                 alertStatisticsVO.setRadio(0.00);
-            }else {
-                alertStatisticsVO.setRadio(Arith.div(alertStatisticsVO.getNumber(), sum));
             }
         });
         return list;

+ 10 - 5
mhfire-service/src/main/java/com/bizmatics/mhfire/service/job/AlertJob.java

@@ -26,24 +26,24 @@ public class AlertJob{
     private AlertService alertService;
 
 
-//    @Scheduled(cron = "0 0 0 */1 * ?")
+    //    @Scheduled(cron = "0 0 23 * * ?")
     public void execute(){
         try {
             String token = AlertAndSiteApi.login(AlertAndSiteApi.USER_NAME, AlertAndSiteApi.USER_PASSWORD);
             int page = 1;
-            int size = 200;
+            int size = 100;
             executeCore(page,size,null,null,token);
         }catch (Exception e){
             log.info("alertJob--all--异常"+e.getMessage());
         }
     }
 
-
+    //    @Scheduled(cron = "*/30 * * * * ?")
     public void executeToday(){
         try {
             String token = AlertAndSiteApi.login(AlertAndSiteApi.USER_NAME, AlertAndSiteApi.USER_PASSWORD);
             int page = 1;
-            int size = 200;
+            int size = 100;
             Date date = new Date();
             Date dayStartTime = DateUtils.getDayStartTime(date);
             Date dayEndTime = DateUtils.getDayEndTime(date);
@@ -58,17 +58,22 @@ public class AlertJob{
         int count = 0;
         while (StringUtils.isNotBlank(token) && nextFlag){
             try {
+                long l = System.currentTimeMillis();
                 List<Alert> alerts = AlertAndSiteApi.alertPage(null, null, page, size, token);
+                long ea = System.currentTimeMillis();
+                log.info("alertJob----调用api需要时间"+(ea-l)+"毫秒");
                 if (null != startTime && null != endTime){
                     alerts = alerts.stream().filter(alert -> DateUtils.isEffectiveDate(alert.getDcsj(), startTime, endTime)).collect(Collectors.toList());
                 }
                 count+=alerts.size();
                 if (CollectionUtils.isNotEmpty(alerts)){
-                    alerts.forEach(alert -> alertService.saveOrUpdate(alert));
+                    alertService.saveOrUpdateBatch(alerts);
                     page++;
                 }else {
                     nextFlag = false;
                 }
+                long e = System.currentTimeMillis();
+                log.info("alertJob----处理100条数需要的时间"+(e-l)+"毫秒");
             }catch (Exception e){
                 log.info("alertJob----异常"+e.getMessage());
             }

+ 2 - 9
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 * ?")
+    //    @Scheduled(cron = "0 0 23 * * ?")
     public void execute(){
         try {
             String token = AlertAndSiteApi.login(AlertAndSiteApi.USER_NAME, AlertAndSiteApi.USER_PASSWORD);
@@ -31,14 +31,7 @@ public class FireSiteJob {
             if (StringUtils.isNotBlank(token)){
                 list = AlertAndSiteApi.fireSiteList(null, null, null, null, token);
                 if (CollectionUtils.isNotEmpty(list)){
-                    for (FireSite fireSite:list) {
-                        try {
-                            fireSiteService.saveOrUpdate(fireSite);
-                        }catch (Exception e){
-                            log.info("fireSiteJob----异常"+e.getMessage());
-                        }
-
-                    }
+                    fireSiteService.saveOrUpdateBatch(list);
                 }
             }
             log.info("fireSiteJob----完成,获取警情记录:"+ list.size());

+ 14 - 0
mhfire-service/src/main/java/com/bizmatics/mhfire/service/vo/AlertMapVO.java

@@ -0,0 +1,14 @@
+package com.bizmatics.mhfire.service.vo;
+
+import lombok.Data;
+
+@Data
+public class AlertMapVO {
+
+
+    private String gisX;
+
+    private String gisY;
+
+        private String id;
+}

+ 5 - 0
mhfire-service/src/main/java/com/bizmatics/mhfire/service/vo/AlertStatisticsVO.java

@@ -30,6 +30,11 @@ public class AlertStatisticsVO {
      */
     private Double radio;
 
+    /**
+     * 同比上升還是下降
+     */
+    private Integer sameStatus;
+
     /**
      * 平均值
      */