diff --git a/spzx-manager/src/main/java/cn/bunny/controller/CategoryController.java b/spzx-manager/src/main/java/cn/bunny/controller/CategoryController.java index fd306ed..2fecbce 100644 --- a/spzx-manager/src/main/java/cn/bunny/controller/CategoryController.java +++ b/spzx-manager/src/main/java/cn/bunny/controller/CategoryController.java @@ -5,6 +5,8 @@ import cn.bunny.common.spzx.model.entity.product.Category; import cn.bunny.common.spzx.model.vo.common.Result; import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum; import cn.bunny.service.CategoryService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -13,12 +15,14 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; +@Tag(name = "查询分类") @RestController @RequestMapping("/admin/product/category") public class CategoryController { @Autowired CategoryService categoryService; + @Operation(summary = "查询分类类别", description = "使用懒加载") @GetMapping("/findCategoryList/{id}") public Result findCategoryList(@PathVariable("id") Long id) { List categoryList = categoryService.findCategoryList(id); diff --git a/spzx-manager/src/main/java/cn/bunny/mapper/CategoryMapper.java b/spzx-manager/src/main/java/cn/bunny/mapper/CategoryMapper.java new file mode 100644 index 0000000..09204fe --- /dev/null +++ b/spzx-manager/src/main/java/cn/bunny/mapper/CategoryMapper.java @@ -0,0 +1,15 @@ +package cn.bunny.mapper; + +import cn.bunny.common.spzx.model.entity.product.Category; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface CategoryMapper { + // 查询分类类别 + List selectCategoryByParentId(Long id); + + // 查询是否有下级菜单 + int selectCountByParentId(Long parentId); +} diff --git a/spzx-manager/src/main/java/cn/bunny/service/impl/CategoryServiceImpl.java b/spzx-manager/src/main/java/cn/bunny/service/impl/CategoryServiceImpl.java index c941891..19e8fd0 100644 --- a/spzx-manager/src/main/java/cn/bunny/service/impl/CategoryServiceImpl.java +++ b/spzx-manager/src/main/java/cn/bunny/service/impl/CategoryServiceImpl.java @@ -1,15 +1,31 @@ package cn.bunny.service.impl; import cn.bunny.common.spzx.model.entity.product.Category; +import cn.bunny.mapper.CategoryMapper; import cn.bunny.service.CategoryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.util.List; +@Service public class CategoryServiceImpl implements CategoryService { + @Autowired + private CategoryMapper categoryMapper; // 根据id查询分类列表 @Override public List findCategoryList(Long id) { - return null; + List categoryList = categoryMapper.selectCategoryByParentId(id); + + if (!CollectionUtils.isEmpty(categoryList)) { + categoryList.forEach(category -> { + int count = categoryMapper.selectCountByParentId(category.getId()); + + category.setHasChildren(count > 0); + }); + } + return categoryList; } -} +} \ No newline at end of file diff --git a/spzx-manager/src/main/resources/mapper/category/CategoryMapper.xml b/spzx-manager/src/main/resources/mapper/category/CategoryMapper.xml new file mode 100644 index 0000000..ad73207 --- /dev/null +++ b/spzx-manager/src/main/resources/mapper/category/CategoryMapper.xml @@ -0,0 +1,25 @@ + + + + + + + + id,name,image_url,parent_id,status,order_num,create_time,update_time,is_deleted + + + + + + + +