diff --git a/waynboot-common/src/main/java/com/wayn/common/core/domain/vo/VanTreeSelectVo.java b/waynboot-common/src/main/java/com/wayn/common/core/domain/vo/VanTreeSelectVo.java new file mode 100644 index 0000000..8b322fe --- /dev/null +++ b/waynboot-common/src/main/java/com/wayn/common/core/domain/vo/VanTreeSelectVo.java @@ -0,0 +1,22 @@ +package com.wayn.common.core.domain.vo; + +import lombok.Data; + +/** + * 路由显示信息 + */ +@Data +public class VanTreeSelectVo { + private Long id; + private String text; + private String icon; + + public VanTreeSelectVo() { + } + + public VanTreeSelectVo(Long id, String text, String icon) { + this.id = id; + this.text = text; + this.icon = icon; + } +} diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/ICategoryService.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/ICategoryService.java index 3f4cf73..532d7b8 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/ICategoryService.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/ICategoryService.java @@ -2,6 +2,7 @@ package com.wayn.common.core.service.shop; import com.baomidou.mybatisplus.extension.service.IService; import com.wayn.common.core.domain.shop.Category; +import com.wayn.common.core.domain.vo.VanTreeSelectVo; import java.util.List; @@ -21,4 +22,8 @@ public interface ICategoryService extends IService { * @return 分类列表 */ List list(Category category); + + List selectL1Category(); + + List selectCategoryByPid(Long id); } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/CategoryServiceImpl.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/CategoryServiceImpl.java index 1e7eeab..a44346f 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/CategoryServiceImpl.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/CategoryServiceImpl.java @@ -1,12 +1,15 @@ package com.wayn.common.core.service.shop.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.wayn.common.core.domain.shop.Category; +import com.wayn.common.core.domain.vo.VanTreeSelectVo; import com.wayn.common.core.mapper.shop.CategoryMapper; import com.wayn.common.core.service.shop.ICategoryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; /** @@ -28,4 +31,31 @@ public class CategoryServiceImpl extends ServiceImpl i public List list(Category category) { return categoryMapper.selectCategoryList(category); } + + @Override + public List selectL1Category() { + List categoryList = list(new QueryWrapper().eq("level", "L1").orderByAsc("sort_order")); + List vanTreeSelectVos = new ArrayList<>(); + categoryList.forEach(category -> { + VanTreeSelectVo vanTreeSelectVo = new VanTreeSelectVo(); + vanTreeSelectVo.setId(category.getId()); + vanTreeSelectVo.setText(category.getName()); + vanTreeSelectVos.add(vanTreeSelectVo); + }); + return vanTreeSelectVos; + } + + @Override + public List selectCategoryByPid(Long id) { + List categoryList = list(new QueryWrapper().eq("pid", id).orderByAsc("sort_order")); + List vanTreeSelectVos = new ArrayList<>(); + categoryList.forEach(category -> { + VanTreeSelectVo vanTreeSelectVo = new VanTreeSelectVo(); + vanTreeSelectVo.setId(category.getId()); + vanTreeSelectVo.setIcon(category.getIconUrl()); + vanTreeSelectVo.setText(category.getName()); + vanTreeSelectVos.add(vanTreeSelectVo); + }); + return vanTreeSelectVos; + } } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CategoryController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CategoryController.java new file mode 100644 index 0000000..7ff7d45 --- /dev/null +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CategoryController.java @@ -0,0 +1,41 @@ +package com.wayn.mobile.api.controller; + +import com.wayn.common.core.domain.shop.Category; +import com.wayn.common.core.domain.vo.VanTreeSelectVo; +import com.wayn.common.core.service.shop.ICategoryService; +import com.wayn.common.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Objects; + +@RestController +@RequestMapping("category") +public class CategoryController { + + @Autowired + private ICategoryService iCategoryService; + + @GetMapping("index") + public R index(@RequestParam(required = false) Long id) { + R success = R.success(); + List categoryList = iCategoryService.selectL1Category(); + Category currentCategory; + List subCategoryList; + if (Objects.isNull(id) && categoryList.size() > 0) { + currentCategory = iCategoryService.getById(categoryList.get(0).getId()); + subCategoryList = iCategoryService.selectCategoryByPid(currentCategory.getId()); + } else { + currentCategory = iCategoryService.getById(id); + subCategoryList = iCategoryService.selectCategoryByPid(id); + } + success.add("categoryList", categoryList); + success.add("currentCategory", currentCategory); + success.add("subCategoryList", subCategoryList); + return success; + } +} diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/HomeController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/HomeController.java index 2168303..2b8f16f 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/HomeController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/HomeController.java @@ -19,7 +19,7 @@ public class HomeController extends BaseController { private HomeService homeService; @PostMapping("index") - public R getHomeIndex() { + public R index() { return homeService.getHomeIndexData(); } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/TestController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/TestController.java deleted file mode 100644 index d003768..0000000 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/TestController.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.wayn.mobile.api.controller; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class TestController { - - @GetMapping("test") - public String test() { - return "hello world!"; - } -}