فهرست منبع

根据地址求经纬度方案

yq 3 سال پیش
والد
کامیت
338f1d2d8e

+ 6 - 0
mhfire-mapping/src/main/java/com/bizmatics/mhfire/persistence/mapper/FireStatisticsMapper.java

@@ -63,6 +63,12 @@ public interface FireStatisticsMapper {
                                   @Param("address")String address);
 
 
+    List<Map<String,String>> distanceList(@Param("longitude") Double longitude,
+                                          @Param("latitude")Double latitude,
+                                          @Param("startTime") Date startTime,
+                                          @Param("endTime")Date endTime);
+
+
     Map<String,String> getOne(@Param("id") String id);
 
 

+ 32 - 16
mhfire-mapping/src/main/resources/mapper/mysql/FireStatisticsMapper.xml

@@ -13,11 +13,9 @@
         select count(1)
         from `hzdc-hztjb`
         <where>
-            <if test="startTime != null">
-                and `起火时间_日期型` >= #{startTime}
-            </if>
-            <if test="endTime != null">
-                and `起火时间_日期型` &lt;= #{endTime}
+            <if test="startTime != null and endTime != null">
+                and  `起火时间_日期型` between STR_TO_DATE(#{startTime},'%Y-%m-%d %H:%i:%s')
+                and STR_TO_DATE(#{endTime},'%Y-%m-%d %H:%i:%s')
             </if>
             <if test="fireAddress != null and fireAddress != ''">
                 and `起火地点` LIKE CONCAT(CONCAT('%', #{fireAddress}), '%')
@@ -37,11 +35,9 @@
         select *
         from `hzdc-hztjb`
         <where>
-            <if test="startTime != null">
-                and `起火时间_日期型` >= #{startTime}
-            </if>
-            <if test="endTime !=null">
-                and `起火时间_日期型` &lt;= #{endTime}
+            <if test="startTime != null and endTime != null">
+                and  `起火时间_日期型` between STR_TO_DATE(#{startTime},'%Y-%m-%d %H:%i:%s')
+                and STR_TO_DATE(#{endTime},'%Y-%m-%d %H:%i:%s')
             </if>
             <if test="address !=null and address !=''">
                 and `起火地点` LIKE CONCAT(CONCAT('%', #{address}), '%')
@@ -104,20 +100,40 @@
         group by monthTime
     </select>
     <select id="list" resultType="java.util.Map">
-        select `火灾序号`,`死亡人数`,`受伤人数`,`longitude`,`latitude`,`起火地点`
+        select `火灾序号`,`直接财产损失`,`死亡人数`,`受伤人数`,`longitude`,`latitude`,`起火地点`
         from `hzdc-hztjb`
         <where>
-            <if test="startTime != null">
-                and `起火时间_日期型` >= #{startTime}
-            </if>
-            <if test="endTime !=null">
-                and `起火时间_日期型` &lt;= #{endTime}
+            <if test="startTime != null and endTime != null">
+                and  `起火时间_日期型` between STR_TO_DATE(#{startTime},'%Y-%m-%d %H:%i:%s')
+                and STR_TO_DATE(#{endTime},'%Y-%m-%d %H:%i:%s')
             </if>
             <if test="address !=null and address !=''">
                 and `起火地点` LIKE CONCAT(CONCAT('%', #{address}), '%')
             </if>
         </where>
     </select>
+    <select id="distanceList" resultType="java.util.Map">
+        SELECT
+	`起火地点`,`直接财产损失`,`死亡人数`,`受伤人数`,
+	ROUND(
+		6378.138 * 2 * ASIN(
+			SQRT(
+				POW( SIN( ( #{latitude} * PI() / 180 - latitude * PI() / 180 ) / 2 ), 2 ) + COS( #{latitude} * PI() / 180 ) * COS( latitude * PI() / 180 ) * POW( SIN( ( #{longitude} * PI() / 180 - longitude * PI() / 180 ) / 2 ), 2 )
+			)
+		) * 1000
+	) AS juli
+FROM
+	`hzdc-hztjb`
+        <where>
+            <if test="startTime != null and endTime != null">
+                and  `起火时间_日期型` between STR_TO_DATE(#{startTime},'%Y-%m-%d %H:%i:%s')
+                and STR_TO_DATE(#{endTime},'%Y-%m-%d %H:%i:%s')
+            </if>
+        </where>
+ORDER BY
+	juli ASC
+	limit 0,1
+    </select>
 
 
 </mapper>

+ 7 - 0
mhfire-service/src/main/java/com/bizmatics/mhfire/service/FireStatisticsService.java

@@ -40,6 +40,13 @@ public interface FireStatisticsService {
 
     List<FireStatisticsPO> list(Date startTime, Date endTime, String address);
 
+    /**
+     * 计算精度维度差
+     * @param longitude
+     * @param latitude
+     * @return
+     */
+    List<FireStatisticsPO> distanceList(Double longitude, Double latitude, Date startTime, Date endTime);
     /**
      * getOne
      * @param id

+ 17 - 27
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/AlertServiceImpl.java

@@ -17,7 +17,6 @@ import com.bizmatics.mhfire.persistence.mapper.vo.LocateInfo;
 import com.bizmatics.mhfire.service.AlertService;
 import com.bizmatics.mhfire.service.FireStatisticsService;
 import com.bizmatics.mhfire.service.util.Arith;
-import com.bizmatics.mhfire.service.util.CaculateDistance;
 import com.bizmatics.mhfire.service.util.GouldUtil;
 import com.bizmatics.mhfire.service.vo.AlertMapVO;
 import com.bizmatics.mhfire.service.vo.AlertStatisticsVO;
@@ -137,37 +136,28 @@ public class AlertServiceImpl extends AbstractCrudService<AlertMapper, Alert> im
     @Override
     public Alert getOne(String id) {
         Alert alert = this.getById(id);
-        Date startTime = DateUtils.addMonths(alert.getLasj(), -30);
-        Date endTime = DateUtils.addMonths(alert.getLasj(), 30);
-        String replace = alert.getAfdz().replace("(", " ");
-        String replace1 = replace.replace(")", " ");
-        String [] arr = replace1.split("\\s+");
-        for (String address:arr) {
-            if (!address.contains("闵行")){
-                List<FireStatisticsPO> list = fireStatisticsService.list(null, null, address);
-                System.out.println(list.size());
+        if (alert.getAjlx().equals(ALERT_TYPE[0])){
+            Date startTime = DateUtils.addMonths(alert.getLasj(), -30);
+            Date endTime = DateUtils.addMonths(alert.getLasj(), 30);
+            List<LocateInfo> lonLat = GouldUtil.getLonLat(alert.getAfdz());
+            LocateInfo locateInfo = lonLat.get(0);
+            List<FireStatisticsPO> list = fireStatisticsService.distanceList(locateInfo.getLongitude(), locateInfo.getLatitude(), startTime, endTime);
+            System.out.println(list);
+            if (CollectionUtils.isNotEmpty(list)){
+                FireStatisticsPO fireStatisticsPo = list.get(0);
+                alert.setPropertyLoss(fireStatisticsPo.getPropertyLoss());
+                alert.setDeathToll(fireStatisticsPo.getDeathToll());
+                alert.setNonFatal(fireStatisticsPo.getNonFatal());
             }
         }
-        List<FireStatisticsPO> list = fireStatisticsService.list(startTime, endTime, alert.getAfdz());
-        List<FireStatisticsPO> collect = list.stream()
-                .filter(fp -> {
-                    List<LocateInfo> lonLat = null;
-                    if (0.00 == fp.getLatitude()) {
-                        lonLat = GouldUtil.getLonLat(fp.getAddress());
-                    }
-                    if (CollectionUtils.isNotEmpty(lonLat)) {
-                        double distance = CaculateDistance.getDistance(Double.parseDouble(alert.getGisX()),
-                                Double.parseDouble(alert.getGisY()),
-                                lonLat.get(0).getLatitude(),
-                                lonLat.get(0).getLongitude());
-                        return distance > 100;
-                    }
-                    return false;
-                }).collect(Collectors.toList());
-        System.out.println(collect.size());
         return alert;
     }
 
+    public String checkAddress(String address){
+        String s = address.replaceAll(" ", "");
+        return s.substring(0,s.indexOf("("));
+    }
+
     @Override
     public List<AlertStatisticsVO> getAlertStatistics(Date startTime, Date endTime) {
 

+ 7 - 0
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/FireStatisticsServiceImpl.java

@@ -108,6 +108,13 @@ public class FireStatisticsServiceImpl implements FireStatisticsService {
                 .map(this::enhanceFireStatisticsPo).collect(Collectors.toList());
     }
 
+    @Override
+    public List<FireStatisticsPO> distanceList(Double longitude, Double latitude, Date startTime, Date endTime) {
+        return fireStatisticsMapper.distanceList(longitude, latitude, startTime, endTime)
+                .stream()
+                .map(this::enhanceFireStatisticsPo).collect(Collectors.toList());
+    }
+
     @Override
     public FireStatisticsPO getOne(String id) {
         return enhanceFireStatisticsPo(fireStatisticsMapper.getOne(id));

+ 0 - 29
mhfire-service/src/main/java/com/bizmatics/mhfire/service/util/CaculateDistance.java

@@ -1,29 +0,0 @@
-package com.bizmatics.mhfire.service.util;
-
-/**
- * @author yq
- * @date 2021/8/19 15:51
- */
-public class CaculateDistance {
-
-    private final static double EARTH_RADIUS = 6378.137;
-
-    private static double rad(double d) {
-        return d * Math.PI / 180.0;
-    }
-
-    /**
-     * 根据两点间经纬度坐标(double值),计算两点间距离,单位为米
-     */
-    public static double getDistance(double latOne, double lngOne, double latTwo, double lngTwo) {
-        double radLat1 = rad(latOne);
-        double radLat2 = rad(latTwo);
-        double a = radLat1 - radLat2;
-        double b = rad(lngOne) - rad(lngTwo);
-        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 = (s * 10000) / 10;
-        return s;
-    }
-}