ソースを参照

店铺详情接口距离用sql计算

jyc 4 週間 前
コミット
f320e006eb

+ 7 - 0
alien-entity/src/main/java/shop/alien/mapper/StoreInfoMapper.java

@@ -123,4 +123,11 @@ public interface StoreInfoMapper extends BaseMapper<StoreInfo> {
     @Select("SELECT a.* FROM store_info a " +
             "left join store_user b on a.id =b.store_id  where b.phone = #{phoneIdNew} limit 1")
     StoreMainInfoVo getStoreNameByPhone(String phoneIdNew);
+
+    @Select(
+            "select " +
+            "            ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(store_position, ',', ' '), ')' ))) / 1000, 2) dist " +
+            "from store_info where id = #{storeId}"
+            )
+    Double getStoreDistance(@Param("position") String position,@Param("storeId") Integer storeId);
 }

+ 6 - 3
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -1081,10 +1081,13 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         result.setStorePositionLatitude(result.getStorePosition().split(",")[1]);
         // 设置距离
         if ((jingdu != null && !jingdu.isEmpty()) && (weidu != null && !weidu.isEmpty())) {
-            double storeJing = Double.parseDouble(result.getStorePosition().split(",")[0]);
+            /*double storeJing = Double.parseDouble(result.getStorePosition().split(",")[0]);
             double storeWei = Double.parseDouble(result.getStorePosition().split(",")[1]);
-            double storeDistance = DistanceUtil.haversineCalculateDistance(Double.parseDouble(jingdu), Double.parseDouble(weidu), storeJing, storeWei);
-            result.setDistance(storeDistance);
+            double storeDistance = DistanceUtil.haversineCalculateDistance(Double.parseDouble(jingdu), Double.parseDouble(weidu), storeJing, storeWei);*/
+
+            Double distance = storeInfoMapper.getStoreDistance(jingdu + "," + weidu,result.getId());
+
+            result.setDistance(distance);
         }
         // 计算店铺到最近地铁站的距离
         JSONObject nearbySubway = gaoDeMapUtil.getNearbySubway(result.getStorePosition().split(",")[0], result.getStorePosition().split(",")[1]);