Quellcode durchsuchen

Merge remote-tracking branch 'origin/dev' into dev

panzhilin vor 1 Woche
Ursprung
Commit
fea3ebecf6

+ 5 - 3
alien-store/src/main/java/shop/alien/store/controller/StoreInfoController.java

@@ -821,6 +821,7 @@ public class StoreInfoController {
             @ApiImplicitParam(name = "distance", value = "距离范围(单位:公里)", dataType = "Double", paramType = "query"),
             @ApiImplicitParam(name = "sortType", value = "排序模式(1:智能排序,2:好评优先,3:距离优先)", dataType = "int", paramType = "query"),
             @ApiImplicitParam(name = "businessType", value = "店铺类型(KTV=3、洗浴汗蒸=4、按摩足浴=5,酒吧=11)", dataType = "int", paramType = "query"),
+            @ApiImplicitParam(name = "dictId", value = "字典表id,根据此id查询经营板块、经营种类、分类并匹配店铺", dataType = "Integer", paramType = "query"),
             @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "int", paramType = "query", required = true),
             @ApiImplicitParam(name = "pageSize", value = "页容", dataType = "int", paramType = "query", required = true)
     })
@@ -831,10 +832,11 @@ public class StoreInfoController {
             @RequestParam(value = "distance", required = false) Double distance,
             @RequestParam(value = "sortType", required = false, defaultValue = "1") Integer sortType,
             @RequestParam(value = "businessType", required = false) Integer businessType,
+            @RequestParam(value = "dictId", required = false) Integer dictId,
             @RequestParam(defaultValue = "1") int pageNum,
             @RequestParam(defaultValue = "10") int pageSize) {
-        log.info("StoreInfoController.getSpecialTypeStoresByDistance?lon={},lat={},distance={},sortType={},businessType={},pageNum={},pageSize={}",
-                lon, lat, distance, sortType, businessType, pageNum, pageSize);
+        log.info("StoreInfoController.getSpecialTypeStoresByDistance?lon={},lat={},distance={},sortType={},businessType={},dictId={},pageNum={},pageSize={}",
+                lon, lat, distance, sortType, businessType, dictId, pageNum, pageSize);
 
         try {
             // 参数校验:经度范围 [-180, 180],纬度范围 [-90, 90]
@@ -855,7 +857,7 @@ public class StoreInfoController {
             }
 
             // 调用服务层获取筛选结果
-            IPage<StoreInfoVo> result = storeInfoService.getSpecialTypeStoresByDistance(lon, lat, distance, sortType, businessType, pageNum, pageSize);
+            IPage<StoreInfoVo> result = storeInfoService.getSpecialTypeStoresByDistance(lon, lat, distance, sortType, businessType, dictId, pageNum, pageSize);
 
             // 记录响应日志
             log.info("四种类型店铺距离筛选响应 - 总记录数: {}, 当前页: {}, 页大小: {}",

+ 2 - 2
alien-store/src/main/java/shop/alien/store/service/StoreInfoService.java

@@ -308,12 +308,12 @@ public interface StoreInfoService extends IService<StoreInfo> {
      * @param distance    距离范围(单位:公里)
      * @param sortType    排序模式(1:智能排序,2:好评优先,3:距离优先)
      * @param businessType 店铺类型(KTV=3、洗浴汗蒸=4、按摩足浴=5,酒吧需要查询字典表),可选
-     * @param categoryId  分类ID(二级或三级分类的dictId,从getAllBusinessSection接口获取),可选
+     * @param dictId 字典表id,根据此id查询经营板块、经营种类、分类并匹配店铺,可选
      * @param pageNum     页码
      * @param pageSize    页容
      * @return IPage<StoreInfoVo> 分页的门店信息列表
      */
-    IPage<StoreInfoVo> getSpecialTypeStoresByDistance(Double lon, Double lat, Double distance, Integer sortType, Integer businessType, int pageNum, int pageSize);
+    IPage<StoreInfoVo> getSpecialTypeStoresByDistance(Double lon, Double lat, Double distance, Integer sortType, Integer businessType, Integer dictId, int pageNum, int pageSize);
 
     /**
      * web端查询门店明细

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

@@ -2445,7 +2445,7 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
     }
 
     @Override
-    public IPage<StoreInfoVo> getSpecialTypeStoresByDistance(Double lon, Double lat, Double distance, Integer sortType, Integer businessType, int pageNum, int pageSize) {
+    public IPage<StoreInfoVo> getSpecialTypeStoresByDistance(Double lon, Double lat, Double distance, Integer sortType, Integer businessType, Integer dictId, int pageNum, int pageSize) {
         // 参数校验
         if (lon == null || lat == null) {
             throw new IllegalArgumentException("经纬度参数不能为空");
@@ -2476,8 +2476,72 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         // 构建查询条件
         QueryWrapper<StoreInfoVo> queryWrapper = new QueryWrapper<>();
         
-        // 如果指定了businessType,则根据传入的数值进行筛选
-        if (businessType != null) {
+        // 如果传入了dictId,根据字典id查询经营板块、经营种类、分类并匹配店铺
+        if (dictId != null) {
+            // 根据dictId查询字典表记录
+            StoreDictionary dict = storeDictionaryMapper.selectById(dictId);
+            if (dict == null || dict.getDeleteFlag() == 1) {
+                throw new IllegalArgumentException("字典id不存在或已删除: " + dictId);
+            }
+            
+            String typeName = dict.getTypeName();
+            String dictIdStr =dict.getDictId();
+            
+            if ("business_section".equals(typeName)) {
+                // 如果是经营板块,直接匹配business_section
+                try {
+                    Integer sectionId = Integer.parseInt(dictIdStr);
+                    queryWrapper.eq("a.business_section", sectionId);
+                } catch (NumberFormatException e) {
+                    throw new IllegalArgumentException("经营板块dictId格式错误: " + dictIdStr);
+                }
+            } else if ("business_type".equals(typeName)) {
+                // 如果是经营种类,需要:
+                // 1. 向上查找父级(经营板块)
+                // 2. 匹配business_section和business_types
+                StoreDictionary parentDict = storeDictionaryMapper.selectById(dict.getParentId());
+                if (parentDict == null || !"business_section".equals(parentDict.getTypeName())) {
+                    throw new IllegalArgumentException("经营种类的父级不是经营板块,dictId: " + dictId);
+                }
+                
+                try {
+                    Integer sectionId = Integer.parseInt(parentDict.getDictId());
+                    queryWrapper.eq("a.business_section", sectionId);
+                    // 使用FIND_IN_SET匹配business_types字段(逗号分隔)
+                    queryWrapper.apply("FIND_IN_SET({0}, a.business_types) > 0", dictIdStr);
+                } catch (NumberFormatException e) {
+                    throw new IllegalArgumentException("经营板块或经营种类dictId格式错误");
+                }
+            } else if ("business_classify".equals(typeName)) {
+                // 如果是分类,需要:
+                // 1. 向上查找父级(经营种类)
+                // 2. 向上查找祖父级(经营板块)
+                // 3. 匹配business_section、business_types和business_classify
+                StoreDictionary parentDict = storeDictionaryMapper.selectById(dict.getParentId());
+                if (parentDict == null || !"business_type".equals(parentDict.getTypeName())) {
+                    throw new IllegalArgumentException("分类的父级不是经营种类,dictId: " + dictId);
+                }
+                
+                StoreDictionary grandParentDict = storeDictionaryMapper.selectById(parentDict.getParentId());
+                if (grandParentDict == null || !"business_section".equals(grandParentDict.getTypeName())) {
+                    throw new IllegalArgumentException("经营种类的父级不是经营板块,dictId: " + dictId);
+                }
+                
+                try {
+                    Integer sectionId = Integer.parseInt(grandParentDict.getDictId());
+                    queryWrapper.eq("a.business_section", sectionId);
+                    // 使用FIND_IN_SET匹配business_types字段
+                    queryWrapper.apply("FIND_IN_SET({0}, a.business_types) > 0", parentDict.getDictId());
+                    // 使用FIND_IN_SET匹配business_classify字段
+                    queryWrapper.apply("FIND_IN_SET({0}, a.business_classify) > 0", dictIdStr);
+                } catch (NumberFormatException e) {
+                    throw new IllegalArgumentException("经营板块、经营种类或分类dictId格式错误");
+                }
+            } else {
+                throw new IllegalArgumentException("不支持的字典类型: " + typeName + ", dictId: " + dictId);
+            }
+        } else if (businessType != null) {
+            // 如果指定了businessType,则根据传入的数值进行筛选
             // 直接使用传入的数值作为business_section进行筛选
             // KTV=3、洗浴汗蒸=4、按摩足浴=5,酒吧的数值未知(由调用方传入)
             queryWrapper.eq("a.business_section", businessType);
@@ -2493,11 +2557,11 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
             );
             
             List<Integer> businessSectionIds = storeDictionaries.stream()
-                    .filter(dict -> StringUtils.isNotEmpty(dict.getDictId()))
+                    .filter(d -> StringUtils.isNotEmpty(d.getDictId()))
                     .map(StoreDictionary::getDictId)
-                    .map(dictId -> {
+                    .map(dictIdStr -> {
                         try {
-                            return Integer.parseInt(dictId);
+                            return Integer.parseInt(dictIdStr);
                         } catch (NumberFormatException e) {
                             return null;
                         }