Browse Source

调整距离计算的sql语句

liwh 1 year ago
parent
commit
5e14f42c9b

+ 6 - 5
tile-web/src/main/java/cn/com/taiji/web/service/impl/EnterpriseServiceImpl.java

@@ -105,8 +105,8 @@ public class EnterpriseServiceImpl implements IEnterpriseService {
         return result.substring(0,result.lastIndexOf(","));
     }
 
-
-    public Result deviceQuery2(DeviceVo deviceVo) {
+    @Override
+    public Result deviceQuery(DeviceVo deviceVo) {
 
         //构建mysql数据库连接数据源--DataSource
         Map<String, Object> mapParams = new HashMap<String, Object>();
@@ -121,7 +121,8 @@ public class EnterpriseServiceImpl implements IEnterpriseService {
         mapParams.put(JDBCDataStoreFactory.DATABASE.key, enterpriseConfig.getDsBaseName());
 
 
-        String sql = "SELECT *,(st_distance(point(longitude, latitude), point("+deviceVo.getLon()+","+deviceVo.getLat()+"))*111195) AS distance FROM "+enterpriseConfig.getDevice()+" having distance < "+deviceVo.getRadius()*1000+" order by distance asc";
+//        String sql = "SELECT *,(st_distance(point(longitude, latitude), point("+deviceVo.getLon()+","+deviceVo.getLat()+"))*111195) AS distance FROM "+enterpriseConfig.getDevice()+" having distance < "+deviceVo.getRadius()*1000+" order by distance asc";
+          String sql = "SELECT *,(6371 * acos (cos ( radians("+deviceVo.getLat()+") )* cos( radians(latitude) )* cos( radians(longitude) - radians("+deviceVo.getLon()+") )+ sin ( radians("+deviceVo.getLat()+"))* sin( radians(latitude) ))) AS distance FROM "+enterpriseConfig.getDevice()+" having distance <"+deviceVo.getRadius()+" order by distance asc";
 
         PageResult pageResult = sqlService.sqlQuery4Mysql(mapParams,sql,null);
 
@@ -150,8 +151,8 @@ public class EnterpriseServiceImpl implements IEnterpriseService {
 
     }
 
-    @Override
-    public Result deviceQuery(DeviceVo deviceVo) {
+
+    public Result deviceQuery2(DeviceVo deviceVo) {
 
         //数据源
         Map<String, Object> entDsParams = new HashMap<String, Object>();