Selaa lähdekoodia

获取店铺分类信息(根据business_classify字段获取字典表数据实现UI图中的功能)

panzhilin 2 viikkoa sitten
vanhempi
commit
4961963276

+ 25 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreInfoController.java

@@ -93,6 +93,7 @@ public class StoreInfoController {
         return R.fail("失败");
     }
 
+
     @ApiOperation("新增门店草稿")
     @ApiOperationSupport(order = 3)
     @PostMapping("/saveStoreInfoDraft")
@@ -903,4 +904,28 @@ public class StoreInfoController {
             return R.fail("获取分类数据失败,请稍后重试");
         }
     }
+
+    /**
+     * 根据business_classify字段获取字典表数据实现UI图中的功能
+     * RESTful风格:GET /store/info/business-classifies
+     * 返回扁平化的分类列表,用于多选分类功能
+     *
+     * @param parentId 父分类ID(可选),如果提供则只返回该父分类下的子分类
+     * @return R<List<StoreDictionaryVo>> 分类列表(扁平化,仅子分类)
+     */
+    @ApiOperation("获取店铺分类信息)")
+    @ApiOperationSupport(order = 19)
+    @GetMapping("/business-classifies")
+    public R<List<StoreDictionaryVo>> getBusinessClassifyData(
+            @RequestParam(value = "parentId", required = false) Integer parentId) {
+        log.info("StoreInfoController.getBusinessClassifyData?parentId={}", parentId);
+        try {
+            List<StoreDictionaryVo> result = storeInfoService.getBusinessClassifyData(parentId);
+            return R.data(result);
+        } catch (Exception e) {
+            log.error("获取business_classify分类数据异常", e);
+            return R.fail("获取分类数据失败,请稍后重试");
+        }
+    }
+
 }

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

@@ -329,4 +329,13 @@ public interface StoreInfoService extends IService<StoreInfo> {
      * @return List<StoreDictionaryVo> 分类列表,包含主分类和子分类
      */
     List<StoreDictionaryVo> getLeisureEntertainmentCategories();
+
+    /**
+     * 根据business_classify字段获取字典表数据实现UI图中的功能
+     * 
+     * @param parentId 父分类ID(可选),如果提供则只返回该父分类下的子分类;如果为null则返回所有子分类
+     * @return List<StoreDictionaryVo> 分类列表
+     */
+    List<StoreDictionaryVo> getBusinessClassifyData(Integer parentId);
+
 }

+ 37 - 1
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -3424,4 +3424,40 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
 
         return result;
     }
-}
+
+    @Override
+    public List<StoreDictionaryVo> getBusinessClassifyData(Integer parentId) {
+        // 构建查询条件
+        LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<StoreDictionary>()
+                .eq(StoreDictionary::getTypeName, "business_classify")
+                .eq(StoreDictionary::getDeleteFlag, 0)
+                .orderByAsc(StoreDictionary::getDictId);
+
+        // 如果指定了parentId,则只查询该父分类下的子分类
+        if (parentId != null) {
+            queryWrapper.eq(StoreDictionary::getParentId, parentId);
+        } else {
+            // 如果没有指定parentId,则查询所有子分类(parentId不为0或null的分类)
+            queryWrapper.isNotNull(StoreDictionary::getParentId)
+                    .ne(StoreDictionary::getParentId, 0);
+        }
+
+        // 查询字典数据
+        List<StoreDictionary> allClassifies = storeDictionaryMapper.selectList(queryWrapper);
+
+        // 构建扁平化的结果列表(仅返回子分类,用于多选功能)
+        List<StoreDictionaryVo> result = new ArrayList<>();
+
+        for (StoreDictionary classify : allClassifies) {
+            StoreDictionaryVo vo = new StoreDictionaryVo();
+            BeanUtils.copyProperties(classify, vo);
+            // 不设置subDataList,返回扁平化列表
+            result.add(vo);
+        }
+
+        return result;
+    }
+
+
+    }
+