|
@@ -77,6 +77,8 @@ import java.util.stream.Collectors;
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo> implements StoreInfoService {
|
|
public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo> implements StoreInfoService {
|
|
|
|
|
|
|
|
|
|
+ private static final int DEFAULT_DISTANCE_METER = 1000;
|
|
|
|
|
+
|
|
|
private final String DEFAULT_PASSWORD = "123456";
|
|
private final String DEFAULT_PASSWORD = "123456";
|
|
|
|
|
|
|
|
private final StoreInfoMapper storeInfoMapper;
|
|
private final StoreInfoMapper storeInfoMapper;
|
|
@@ -2494,10 +2496,10 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
// 加上 30 天
|
|
// 加上 30 天
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, 30);
|
|
calendar.add(Calendar.DAY_OF_MONTH, 30);
|
|
|
|
|
|
|
|
- // 距离选择(一千米)
|
|
|
|
|
- int distance = 5000;
|
|
|
|
|
-
|
|
|
|
|
List<StoreInfoVo> storeInfoVoList = storeInfoMapper.getMoreRecommendedStores(queryWrapper);
|
|
List<StoreInfoVo> storeInfoVoList = storeInfoMapper.getMoreRecommendedStores(queryWrapper);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(storeInfoVoList)) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
if (!storeInfoVoList.isEmpty()) {
|
|
if (!storeInfoVoList.isEmpty()) {
|
|
|
// 提前查询所有需要的字典数据
|
|
// 提前查询所有需要的字典数据
|
|
|
List<StoreInfoVo> collect = storeInfoVoList.stream().filter(record -> StringUtils.isNotEmpty(record.getStoreType())).collect(Collectors.toList());
|
|
List<StoreInfoVo> collect = storeInfoVoList.stream().filter(record -> StringUtils.isNotEmpty(record.getStoreType())).collect(Collectors.toList());
|
|
@@ -2569,49 +2571,68 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- List<StoreInfoVo> filteredList = new ArrayList<>();
|
|
|
|
|
- // 根据距离筛选店铺列表
|
|
|
|
|
- if (lon != null && lat != null) {
|
|
|
|
|
- filteredList = storeInfoVoList.stream()
|
|
|
|
|
- .filter(store -> {
|
|
|
|
|
- // 检查店铺坐标是否存在
|
|
|
|
|
- if (StringUtils.isEmpty(store.getStorePosition())) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- // 解析店铺坐标(格式:经度,纬度)
|
|
|
|
|
- String[] positionArray = store.getStorePosition().split(",");
|
|
|
|
|
- if (positionArray.length != 2) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- double storeLon = Double.parseDouble(positionArray[0].trim());
|
|
|
|
|
- double storeLat = Double.parseDouble(positionArray[1].trim());
|
|
|
|
|
-
|
|
|
|
|
- // 计算距离(单位:千米)
|
|
|
|
|
- double calculatedDistance = DistanceUtil.haversineCalculateDistance(lon, lat, storeLon, storeLat);
|
|
|
|
|
-
|
|
|
|
|
- // 将距离转换为米进行比较(distance 单位是米)
|
|
|
|
|
- double distanceInMeters = calculatedDistance * 1000;
|
|
|
|
|
- store.setDistance3(distanceInMeters);
|
|
|
|
|
- // 筛选距离范围内的店铺
|
|
|
|
|
- return distanceInMeters <= distance;
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- // 计算距离失败时,记录日志并过滤掉该店铺
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- // 记录距离筛选结果
|
|
|
|
|
- if (log.isInfoEnabled()) {
|
|
|
|
|
- log.info("距离筛选完成,原始店铺数量:" + storeInfoVoList.size() + ",筛选后店铺数量:" + filteredList.size() + ",筛选距离:" + distance + "米");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (lon == null || lat == null) {
|
|
|
|
|
+ log.warn("获取更多推荐店铺失败,经纬度为空");
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return filterStoresWithinDistance(storeInfoVoList, lon, lat, DEFAULT_DISTANCE_METER);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据距离过滤并排序店铺列表
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param storeInfoVoList 原始店铺列表
|
|
|
|
|
+ * @param lon 用户经度
|
|
|
|
|
+ * @param lat 用户纬度
|
|
|
|
|
+ * @param maxDistance 最大距离(米)
|
|
|
|
|
+ * @return 距离范围内的店铺列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<StoreInfoVo> filterStoresWithinDistance(List<StoreInfoVo> storeInfoVoList, double lon, double lat, int maxDistance) {
|
|
|
|
|
+ List<StoreInfoVo> filteredList = storeInfoVoList.stream()
|
|
|
|
|
+ .filter(store -> isWithinDistance(store, lon, lat, maxDistance))
|
|
|
|
|
+ .sorted(Comparator.comparingDouble(StoreInfoVo::getDistance3))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ if (log.isInfoEnabled()) {
|
|
|
|
|
+ log.info("距离筛选完成,原始店铺数量={},筛选后店铺数量={},筛选距离={}米",
|
|
|
|
|
+ storeInfoVoList.size(), filteredList.size(), maxDistance);
|
|
|
}
|
|
}
|
|
|
return filteredList;
|
|
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
|
|
@Override
|
|
|
public Map<String, Object> getStoreOcrData(String storeId, String imageUrl) {
|
|
public Map<String, Object> getStoreOcrData(String storeId, String imageUrl) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|