Ver código fonte

警情综合和撒点相关接口代码开发

jichaobo 2 anos atrás
pai
commit
f8c49e625b

+ 22 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/DemPoliceInfoController.java

@@ -6,6 +6,7 @@ import com.usky.common.core.bean.CommonPage;
 import com.usky.fire.domain.DemPoliceInfo;
 import com.usky.fire.service.DemMicroStationService;
 import com.usky.fire.service.DemPoliceInfoService;
+import com.usky.fire.service.DemWaterSourceService;
 import com.usky.fire.service.vo.AlertStatisticsVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -34,6 +35,9 @@ public class DemPoliceInfoController {
     @Autowired
     private DemPoliceInfoService demPoliceInfoService;
 
+    @Autowired
+    private DemWaterSourceService demWaterSourceService;
+
     /**
      * 综合警情-撒点
      *
@@ -117,5 +121,23 @@ public class DemPoliceInfoController {
     public ApiResult<List<Map<String, Object>>> warningInstanceScatterer(@RequestParam(value = "streetTown", required = false) String streetTown) {
         return ApiResult.success(demPoliceInfoService.warningInstanceScatterer(streetTown));
     }
+
+    /**
+     * 综合警情-周边资源
+     *
+     * @param longitude 实时警情经度
+     * @param latitude  实时警情纬度
+     * @param pageNum   当前页
+     * @param pageSize  每页条数
+     * @return
+     */
+    @GetMapping("/waterSourceList")
+    public ApiResult<CommonPage<Map<String, Object>>> waterSourceList(@RequestParam(value = "longitude") double longitude,
+                                                                      @RequestParam(value = "latitude") double latitude,
+                                                                      @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
+                                                                      @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
+        return ApiResult.success(demWaterSourceService.waterSourceList(longitude, latitude, pageNum, pageSize));
+    }
+
 }
 

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

@@ -43,4 +43,6 @@ public interface DemWaterSourceService extends CrudService<DemWaterSource> {
     void delWaterSource(Integer id);
 
     List<Object> waterSourceList(String streetTown);
+
+    CommonPage<Map<String, Object>> waterSourceList(double longitude, double latitude, Integer pageNum, Integer pageSize);
 }

+ 34 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/DemWaterSourceServiceImpl.java

@@ -11,6 +11,7 @@ import com.usky.common.mybatis.core.AbstractCrudService;
 import com.usky.fire.domain.DemWaterSource;
 import com.usky.fire.mapper.DemWaterSourceMapper;
 import com.usky.fire.service.DemWaterSourceService;
+import com.usky.fire.service.util.OnlineMethod;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -105,4 +106,37 @@ public class DemWaterSourceServiceImpl extends AbstractCrudService<DemWaterSourc
         return list;
     }
 
+    @Override
+    public CommonPage<Map<String, Object>> waterSourceList(double longitude, double latitude, Integer pageNum, Integer pageSize) {
+        List<Map<String, Object>> list = new ArrayList<>();
+        IPage<DemWaterSource> page = new Page<>(pageNum, pageSize);
+        LambdaQueryWrapper<DemWaterSource> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.select(DemWaterSource::getId, DemWaterSource::getWaterType, DemWaterSource::getWaterName,
+                DemWaterSource::getWaterAddress, DemWaterSource::getWaterCompany, DemWaterSource::getContactMode,
+                DemWaterSource::getGisX, DemWaterSource::getGisY)
+                .eq(DemWaterSource::getDeleteFlag, 0)
+                .orderByDesc(DemWaterSource::getId);
+        page = this.page(page, queryWrapper);
+        if (CollectionUtils.isNotEmpty(page.getRecords())) {
+            for (int i = 0; i < page.getRecords().size(); i++) {
+                Map<String, Object> map = new HashMap<>();
+                map.put("id", page.getRecords().get(i).getId());
+                map.put("waterType", page.getRecords().get(i).getWaterType());
+                map.put("waterName", page.getRecords().get(i).getWaterName());
+                map.put("waterAddress", page.getRecords().get(i).getWaterAddress());
+                map.put("waterCompany", page.getRecords().get(i).getWaterCompany());
+                map.put("contactMode", page.getRecords().get(i).getContactMode());
+                if (StringUtils.isNotBlank(page.getRecords().get(i).getGisX()) && StringUtils.isNotBlank(page.getRecords().get(i).getGisY())) {
+                    double gisX = Double.valueOf(page.getRecords().get(i).getGisX());
+                    double gisY = Double.valueOf(page.getRecords().get(i).getGisY());
+                    map.put("distance", OnlineMethod.GetDistance(longitude, latitude, gisX, gisY));
+                } else {
+                    map.put("distance", null);
+                }
+                list.add(map);
+            }
+        }
+        return new CommonPage<>(list, page.getTotal(), pageSize, pageNum);
+    }
+
 }

+ 59 - 12
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/util/OnlineMethod.java

@@ -5,7 +5,6 @@ package com.usky.fire.service.util;
 import com.alibaba.nacos.common.utils.StringUtils;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.usky.common.core.exception.BusinessException;
 import com.usky.common.core.util.HttpUtils;
 import com.usky.fire.service.vo.LocateInfo;
 import com.usky.fire.service.vo.PatrolInspectionAreaVo;
@@ -32,20 +31,68 @@ import java.util.stream.Collectors;
 @Slf4j
 public class OnlineMethod {
 
-    public static String getAlarmType(String value,Integer deviceType) {
+    /**
+     * 默认地球半径
+     */
+    private static double EARTH_RADIUS = 6371000;//赤道半径(单位m)
+
+    /**
+     * 转化为弧度(rad)
+     * */
+    private static double rad(double d)
+    {
+        return d * Math.PI / 180.0;
+    }
+    /**
+     * @param lon1 第一点的精度
+     * @param lat1 第一点的纬度
+     * @param lon2 第二点的精度
+     * @param lat2 第二点的纬度
+     * @return 返回的距离,单位m
+     * */
+    public static double GetDistance(double lon1,double lat1,double lon2, double lat2) {
+        double radLat1 = rad(lat1);
+        double radLat2 = rad(lat2);
+        double a = radLat1 - radLat2;
+        double b = rad(lon1) - rad(lon2);
+        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
+        s = s * EARTH_RADIUS;
+        s = Math.round(s * 10000) / 10000;
+        return s;
+    }
+
+    /**
+     * 计算中心经纬度与目标经纬度的距离(米)
+     *
+     * @param centerLon 中心精度
+     * @param centerLat 中心纬度
+     * @param targetLon 需要计算的精度
+     * @param targetLat 需要计算的纬度
+     * @return 米
+     */
+    public static double distance(double centerLon, double centerLat, double targetLon, double targetLat) {
+        double jl_jd = 102834.74258026089786013677476285;// 每经度单位米;
+        double jl_wd = 111712.69150641055729984301412873;// 每纬度单位米;
+        double b = Math.abs((centerLat - targetLat) * jl_jd);
+        double a = Math.abs((centerLon - targetLon) * jl_wd);
+        return Math.sqrt((a * a + b * b));
+    }
+
+
+    public static String getAlarmType(String value, Integer deviceType) {
         String alarmType = null;
         switch (value) {
             case "火警":
                 alarmType = "2";
                 break;
             case "故障":
-                if (deviceType==1){
+                if (deviceType == 1) {
                     alarmType = "4";
-                }else if (deviceType==2){
+                } else if (deviceType == 2) {
                     alarmType = "WP3";
-                }else if (deviceType==5){
+                } else if (deviceType == 5) {
                     alarmType = "LL3";
-                }else if (deviceType==7){
+                } else if (deviceType == 7) {
                     alarmType = "y05";
                 }
                 break;
@@ -80,23 +127,23 @@ public class OnlineMethod {
                 alarmType = "EF8";
                 break;
             case "离线":
-                if (deviceType==2){
+                if (deviceType == 2) {
                     alarmType = "WP4";
-                }else if (deviceType==7){
+                } else if (deviceType == 7) {
                     alarmType = "EF9";
                 }
                 break;
             case "正常":
-                if (deviceType==2){
+                if (deviceType == 2) {
                     alarmType = "WP0";
-                }else if (deviceType==5){
+                } else if (deviceType == 5) {
                     alarmType = "LL0";
                 }
                 break;
             case "低压":
-                if (deviceType==2){
+                if (deviceType == 2) {
                     alarmType = "WP1";
-                }else if (deviceType==3){
+                } else if (deviceType == 3) {
                     alarmType = "y04";
                 }
                 break;