From a349a38dbdb92e8cb21f47fe62e4cf1c071f3336 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 05 七月 2023 11:13:20 +0800
Subject: [PATCH] 1

---
 src/main/java/com/yssh/service/ILocationService.java         |    2 +
 src/main/java/com/yssh/service/impl/SuYuanServiceImpl.java   |    7 +++
 src/main/java/com/yssh/dao/LocationMapper.java               |    2 +
 src/main/java/com/yssh/entity/Location.java                  |   28 ++++++-------
 src/main/java/com/yssh/utils/CalculateUtils.java             |    1 
 src/main/java/com/yssh/service/impl/LocationServiceImpl.java |   27 +++++++++++++
 src/main/resources/mapping/LocationMapper.xml                |   10 ++++-
 7 files changed, 59 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/yssh/dao/LocationMapper.java b/src/main/java/com/yssh/dao/LocationMapper.java
index ac9715f..35f1fd4 100644
--- a/src/main/java/com/yssh/dao/LocationMapper.java
+++ b/src/main/java/com/yssh/dao/LocationMapper.java
@@ -22,4 +22,6 @@
     int deleteLocation(String id);
 
     List<Location> selectByXY(@Param("x") double x, @Param("y") double y);
+
+    List<Location> selectVocAddrs();
 }
diff --git a/src/main/java/com/yssh/entity/Location.java b/src/main/java/com/yssh/entity/Location.java
index 741dbf3..ab5a31d 100644
--- a/src/main/java/com/yssh/entity/Location.java
+++ b/src/main/java/com/yssh/entity/Location.java
@@ -7,28 +7,26 @@
 import lombok.Data;
 
 /**
+ * 鍘傚尯鐑偣鐐逛綅
  * @author wMeng
- * @ClassName YsshLocation
- * @Description 鍘傚尯鐑偣鐐逛綅
  * @date 2022/10/30 13:16
- * @Version 1.0
+ * @version 1.0
  */
 @Data
 @ApiModel(value = "鍘傚尯鐑偣鐐逛綅",description = "鍘傚尯鐑偣鐐逛綅")
-public class Location implements Serializable{
-	
+public class Location implements Serializable {
 	private static final long serialVersionUID = -2728687771987124891L;
-	
+
 	@ApiModelProperty(value = "涓婚敭")
-    private int id;
+	private int id;
 	@ApiModelProperty(value = "鐐逛綅鍚嶇О")
-    private String name;
+	private String name;
 	@ApiModelProperty(value = "鐐逛綅绫诲瀷")
-    private String type;
+	private String type;
 	@ApiModelProperty(value = "鐐逛綅缁忓害")
-    private float lon;
+	private double lon;
 	@ApiModelProperty(value = "鐐逛綅绾害")
-    private float lat;
+	private double lat;
 
 	public int getId() {
 		return id;
@@ -54,19 +52,19 @@
 		this.type = type;
 	}
 
-	public float getLon() {
+	public double getLon() {
 		return lon;
 	}
 
-	public void setLon(float lon) {
+	public void setLon(double lon) {
 		this.lon = lon;
 	}
 
-	public float getLat() {
+	public double getLat() {
 		return lat;
 	}
 
-	public void setLat(float lat) {
+	public void setLat(double lat) {
 		this.lat = lat;
 	}
 }
diff --git a/src/main/java/com/yssh/service/ILocationService.java b/src/main/java/com/yssh/service/ILocationService.java
index 78a2b18..7c6baf4 100644
--- a/src/main/java/com/yssh/service/ILocationService.java
+++ b/src/main/java/com/yssh/service/ILocationService.java
@@ -17,4 +17,6 @@
     int insertLocation(Location ysshLocation);
 
     int deleteLocation(String id);
+
+    List<Location> selectVocAddrs(double x, double y);
 }
diff --git a/src/main/java/com/yssh/service/impl/LocationServiceImpl.java b/src/main/java/com/yssh/service/impl/LocationServiceImpl.java
index 7060dc2..d8eec96 100644
--- a/src/main/java/com/yssh/service/impl/LocationServiceImpl.java
+++ b/src/main/java/com/yssh/service/impl/LocationServiceImpl.java
@@ -3,9 +3,11 @@
 import com.yssh.dao.LocationMapper;
 import com.yssh.entity.Location;
 import com.yssh.service.ILocationService;
+import com.yssh.utils.CalculateUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -17,6 +19,8 @@
 public class LocationServiceImpl implements ILocationService {
     @Resource
     private LocationMapper mapper;
+
+    private static List<Location> vocAddrs = null;
 
     @Override
     public List<Location> query(String name, String type) {
@@ -37,4 +41,27 @@
     public int deleteLocation(String id) {
         return mapper.deleteLocation(id);
     }
+
+    @Override
+    public List<Location> selectVocAddrs(double x, double y) {
+        if (null == vocAddrs) {
+            vocAddrs = mapper.selectVocAddrs();
+
+            for (Location loc : vocAddrs) {
+                double X = CalculateUtils.getLon((int) loc.getLon(), (int) loc.getLat());
+                double Y = CalculateUtils.getLat((int) loc.getLon(), (int) loc.getLat());
+                loc.setLon(X);
+                loc.setLat(Y);
+            }
+        }
+
+        List<Location> list = new ArrayList<>();
+        for (Location loc : vocAddrs) {
+            if (Math.abs(loc.getLon() - x) <= 0.00009 && Math.abs(loc.getLat() - y) <= 0.00009) {
+                list.add(loc);
+            }
+        }
+
+        return list;
+    }
 }
diff --git a/src/main/java/com/yssh/service/impl/SuYuanServiceImpl.java b/src/main/java/com/yssh/service/impl/SuYuanServiceImpl.java
index 8e07d94..3f14383 100644
--- a/src/main/java/com/yssh/service/impl/SuYuanServiceImpl.java
+++ b/src/main/java/com/yssh/service/impl/SuYuanServiceImpl.java
@@ -44,6 +44,9 @@
 	@Resource
 	private LocationMapper locationMapper;
 
+	@Resource
+	private LocationServiceImpl locService;
+
 	//@Transactional
 	//@Override
 	@Async("threadPoolTaskExecutor")
@@ -309,6 +312,10 @@
 			return locations.get(0).getName();
 		}
 
+		locations = locService.selectVocAddrs(x, y);
+		if (null != locations && locations.size() > 0) {
+			return locations.get(0).getName();
+		}
 
 		return null;
 	}
diff --git a/src/main/java/com/yssh/utils/CalculateUtils.java b/src/main/java/com/yssh/utils/CalculateUtils.java
index 30c0abd..73871a4 100644
--- a/src/main/java/com/yssh/utils/CalculateUtils.java
+++ b/src/main/java/com/yssh/utils/CalculateUtils.java
@@ -1,7 +1,6 @@
 package com.yssh.utils;
 
 import java.awt.geom.Point2D;
-import java.text.SimpleDateFormat;
 import java.util.*;
 
 import com.yssh.entity.Coordinate;
diff --git a/src/main/resources/mapping/LocationMapper.xml b/src/main/resources/mapping/LocationMapper.xml
index b99aa66..e6665d9 100644
--- a/src/main/resources/mapping/LocationMapper.xml
+++ b/src/main/resources/mapping/LocationMapper.xml
@@ -16,11 +16,17 @@
     <select id="selectByXY" resultMap="locationResult">
         <include refid="locationSql"></include>
         <where>
-            lon between (#{x} - 0.000027) and (#{x} + 0.000027)
+            lon between (#{x} - 0.000045) and (#{x} + 0.000045)
             and
-            lat between (#{y} - 0.000027) and (#{y} + 0.000027)
+            lat between (#{y} - 0.000045) and (#{y} + 0.000045)
         </where>
     </select>
+
+    <select id="selectVocAddrs" resultMap="locationResult">
+        select id, x "lon", y "lat", addr "name"
+        from voc_addr
+        where length(addr) > 0;
+    </select>
     
     <select id="query" resultMap="locationResult">
     	<include refid="locationSql"></include>

--
Gitblit v1.9.3