|
|
@@ -82,7 +82,7 @@ public class LifeUserStoreService {
|
|
|
// 过滤掉永久关门的店铺
|
|
|
wrapper.ne("a.business_status", 99);
|
|
|
// 根据构建的条件查询门店信息
|
|
|
- List<StoreInfoVo> storeInfoVoList = storeInfoMapper.getStoreInfoVoListNew(wrapper,weidu + "," + jingdu);
|
|
|
+ List<StoreInfoVo> storeInfoVoList = storeInfoMapper.getStoreInfoVoListNew(wrapper,jingdu + "," + weidu);
|
|
|
// 如果查询结果为空,则直接返回空列表
|
|
|
if (storeInfoVoList.isEmpty()) {
|
|
|
return returnMaps;
|
|
|
@@ -209,16 +209,37 @@ public class LifeUserStoreService {
|
|
|
// 如果用户提供了距离阈值,则根据距离过滤结果,并按距离升序排序
|
|
|
if (distance != null) {
|
|
|
double maxDistance = distance;
|
|
|
- returnMaps = returnMaps.stream()
|
|
|
- .filter(storeMap -> {
|
|
|
- Object distanceObj = storeMap.get("distance");
|
|
|
- if (distanceObj instanceof String) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- double distanceValue = (double) distanceObj;
|
|
|
- return distanceValue < maxDistance;
|
|
|
+ returnMaps = returnMaps.stream().filter(storeMap -> {
|
|
|
+ Object distanceObj = storeMap.get("distance");
|
|
|
+ if (distanceObj == null) {
|
|
|
+ return false; // 排除 null
|
|
|
+ }
|
|
|
+ double distanceValue;
|
|
|
+ try {
|
|
|
+ // 先尝试直接转换为数值类型(如果本身是 Double/Integer 等)
|
|
|
+ if (distanceObj instanceof Number) {
|
|
|
+ distanceValue = ((Number) distanceObj).doubleValue();
|
|
|
+ }
|
|
|
+ // 再处理字符串类型(如 "100.5")
|
|
|
+ else if (distanceObj instanceof String) {
|
|
|
+ // 将字符串解析为 double(注意处理非数字格式的字符串)
|
|
|
+ distanceValue = Double.parseDouble((String) distanceObj);
|
|
|
+ }
|
|
|
+ // 其他类型视为无效
|
|
|
+ else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ // 字符串无法解析为数字(如 "abc"),视为无效
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return distanceValue < maxDistance;
|
|
|
+ })
|
|
|
+ .sorted((map1, map2) -> {
|
|
|
+ double d1 = getDistanceValue(map1.get("distance"));
|
|
|
+ double d2 = getDistanceValue(map2.get("distance"));
|
|
|
+ return Double.compare(d1, d2);
|
|
|
})
|
|
|
- .sorted(Comparator.comparingDouble(storeMap -> (double) storeMap.get("distance")))
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
@@ -232,6 +253,19 @@ public class LifeUserStoreService {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
+ // 提取一个工具方法,统一处理距离值的转换
|
|
|
+ private double getDistanceValue(Object distanceObj) {
|
|
|
+ if (distanceObj instanceof Number) {
|
|
|
+ return ((Number) distanceObj).doubleValue();
|
|
|
+ } else if (distanceObj instanceof String) {
|
|
|
+ try {
|
|
|
+ return Double.parseDouble((String) distanceObj);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return Double.MAX_VALUE; // 无效值排序时放最后
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Double.MAX_VALUE;
|
|
|
+ }
|
|
|
|
|
|
public Map<String, Object> getStoreDetailById(String storeId, String userId, String jingdu, String weidu) {
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|