Bladeren bron

修改推荐数据列表接口

zhangchen 2 weken geleden
bovenliggende
commit
a46019aa40

+ 1 - 1
alien-entity/src/main/java/shop/alien/entity/store/vo/StoreInfoVo.java

@@ -216,7 +216,7 @@ public class StoreInfoVo extends StoreInfo {
     private Integer dynamicsNum;
 
     @ApiModelProperty(value = "推荐列表距离(米)")
-    private double distance3;
+    private String distance3;
 
     @ApiModelProperty(value = "店铺头图(多图列表)")
     private List<String> storeAlbumUrlList;

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

@@ -144,7 +144,7 @@ public interface StoreInfoMapper extends BaseMapper<StoreInfo> {
             " from store_evaluation eval " +
             " where eval.store_id = a.id and eval.delete_flag = 0 " +
             ") score, " +
-            "ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(a.store_position, ',', ' '), ')' ))) / 1000, 2) dist " +
+            "ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(a.store_position, ',', ' '), ')' ))), 0) distance3 " +
             "from store_info a " +
             "left join store_user b on a.id = b.store_id and a.delete_flag = 0 and b.delete_flag = 0 " +
             "left join store_img img on img.store_id = a.id and img.img_type = 1 and img.delete_flag = 0 " +
@@ -155,6 +155,6 @@ public interface StoreInfoMapper extends BaseMapper<StoreInfo> {
             "${ew.customSqlSegment} " +
             "and a.store_position is not null and a.store_position != '' " +
             "and ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(a.store_position, ',', ' '), ')' ))) / 1000, 2) <= 1 " +
-            "order by dist asc limit 20")
+            "order by distance3 asc limit 20")
     List<StoreInfoVo> getMoreRecommendedStores(@Param(Constants.WRAPPER) QueryWrapper<StoreInfoVo> queryWrapper, @Param("position") String position);
 }

+ 0 - 53
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -3028,59 +3028,6 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         return storeInfoVoList;
     }
 
-    /**
-     * 根据距离过滤并排序店铺列表
-     *
-     * @param storeInfoVoList 原始店铺列表
-     * @param lon             用户经度
-     * @param lat             用户纬度
-     * @return 距离范围内的店铺列表
-     */
-    private List<StoreInfoVo> filterStoresWithinDistance(List<StoreInfoVo> storeInfoVoList, double lon, double lat) {
-        List<StoreInfoVo> filteredList = storeInfoVoList.stream()
-                .filter(store -> isWithinDistance(store, lon, lat, StoreInfoServiceImpl.DEFAULT_DISTANCE_METER))
-                .sorted(Comparator.comparingDouble(StoreInfoVo::getDistance3))
-                .collect(Collectors.toList());
-
-        if (log.isInfoEnabled()) {
-            log.info("距离筛选完成,原始店铺数量={},筛选后店铺数量={},筛选距离={}米",
-                    storeInfoVoList.size(), filteredList.size(), StoreInfoServiceImpl.DEFAULT_DISTANCE_METER);
-        }
-        return filteredList;
-    }
-
-    /**
-     * 判断店铺是否在指定距离范围内
-     *
-     * @param store       店铺信息
-     * @param lon         用户经度
-     * @param lat         用户纬度
-     * @param maxDistance 最大距离(米)
-     * @return true 表示在范围内
-     */
-    private boolean isWithinDistance(StoreInfoVo store, double lon, double lat, int maxDistance) {
-        if (StringUtils.isEmpty(store.getStorePosition())) {
-            return false;
-        }
-
-        String[] positionArray = store.getStorePosition().split(",");
-        if (positionArray.length != 2) {
-            log.warn("店铺坐标格式异常,storeId={},storePosition={}", store.getId(), store.getStorePosition());
-            return false;
-        }
-
-        try {
-            double storeLon = Double.parseDouble(positionArray[0].trim());
-            double storeLat = Double.parseDouble(positionArray[1].trim());
-            double distanceMeters = DistanceUtil.haversineCalculateDistance(lon, lat, storeLon, storeLat) * 1000;
-            store.setDistance3(distanceMeters);
-            return distanceMeters <= maxDistance;
-        } catch (NumberFormatException ex) {
-            log.warn("店铺坐标解析失败,storeId={},storePosition={},error={}", store.getId(), store.getStorePosition(), ex.getMessage());
-            return false;
-        }
-    }
-
     @Override
     public Map<String, Object> getStoreOcrData(String storeId, String imageUrl) {
         Map<String, Object> map = new HashMap<>();