diff --git a/spzx-common/common-service/src/main/java/com/atguigu/config/Knife4jConfig.java b/spzx-common/common-service/src/main/java/com/atguigu/config/Knife4jConfig.java index 1d9a131..049b317 100644 --- a/spzx-common/common-service/src/main/java/com/atguigu/config/Knife4jConfig.java +++ b/spzx-common/common-service/src/main/java/com/atguigu/config/Knife4jConfig.java @@ -21,4 +21,11 @@ public class Knife4jConfig { return new OpenAPI().info(new Info().title("尚品甑选API接口文档") .version("1.0").description("尚品甑选API接口文档").contact(new Contact().name("bunny"))); } + + @Bean + public GroupedOpenApi webApi() { // 创建了一个api接口的分组 + return GroupedOpenApi.builder() + .group("web-api") // 分组名称 + .pathsToMatch("/api/**").build(); // 接口请求路径规则 + } } \ No newline at end of file diff --git a/spzx-common/common-service/src/main/java/com/atguigu/utils/CategoryHelper.java b/spzx-common/common-service/src/main/java/com/atguigu/utils/CategoryHelper.java new file mode 100644 index 0000000..581e1dd --- /dev/null +++ b/spzx-common/common-service/src/main/java/com/atguigu/utils/CategoryHelper.java @@ -0,0 +1,41 @@ +package com.atguigu.utils; + +import com.atguigu.spzx.model.entity.product.Category; + +import java.util.ArrayList; +import java.util.List; + + +public class CategoryHelper { + /** + * 构建树型结构 + * + * @param categoryList 分类列表 + * @return 结构列表 + */ + public static List buildTree(List categoryList) { + ArrayList tree = new ArrayList<>(); + // 将菜单进行遍历 + categoryList.forEach(category -> { + if (category.getParentId() == 0) { + tree.add(getChildren(category, categoryList)); + } + }); + return tree; + } + + + public static Category getChildren(Category category, List categoryList) { + // 遍历所有菜单数据,判断id和parentID对应关系 + category.setChildren(new ArrayList<>()); + + categoryList.forEach(menu -> { + if (menu.getChildren() == null) menu.setChildren(new ArrayList<>()); + if (category.getId().equals(menu.getParentId())) { + category.getChildren().add(getChildren(menu, categoryList)); + } + }); + + return category; + } +} diff --git a/spzx-service/service-product/src/main/java/com/atguigu/product/controller/CategoryController.java b/spzx-service/service-product/src/main/java/com/atguigu/product/controller/CategoryController.java new file mode 100644 index 0000000..4cc031f --- /dev/null +++ b/spzx-service/service-product/src/main/java/com/atguigu/product/controller/CategoryController.java @@ -0,0 +1,33 @@ +package com.atguigu.product.controller; + +import com.atguigu.product.service.CategoryService; +import com.atguigu.spzx.model.entity.product.Category; +import com.atguigu.spzx.model.vo.result.Result; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Tag(name = "分类接口管理") +@RestController +@RequestMapping("/api/product/category/") +@Slf4j +@CrossOrigin +public class CategoryController { + @Autowired + private CategoryService categoryService; + + @Operation(summary = "获取分类树形数据", description = "获取分类树形数据") + @GetMapping("findCategoryTree") + public Result> findCategoryTree() { + log.info("===>获取分类树形数据"); + List list = categoryService.findCategoryTree(); + return Result.success(list); + } +} \ No newline at end of file diff --git a/spzx-service/service-product/src/main/java/com/atguigu/product/controller/IndexController.java b/spzx-service/service-product/src/main/java/com/atguigu/product/controller/IndexController.java index 893e982..6b1b135 100644 --- a/spzx-service/service-product/src/main/java/com/atguigu/product/controller/IndexController.java +++ b/spzx-service/service-product/src/main/java/com/atguigu/product/controller/IndexController.java @@ -8,6 +8,7 @@ import com.atguigu.spzx.model.vo.h5.IndexVo; import com.atguigu.spzx.model.vo.result.Result; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; @@ -19,6 +20,7 @@ import java.util.List; @Tag(name = "首页接口管理") @RestController @RequestMapping(value = "/api/product/index") +@Slf4j @CrossOrigin public class IndexController { @Autowired @@ -29,6 +31,7 @@ public class IndexController { @Operation(summary = "获取首页数据", description = "获取首页数据") @GetMapping public Result findData() { + log.info("===>获取首页数据"); // 查询以及分类 List categoryList = categoryService.selectOneCategory(); // 根据销量排序,获取前十条数据 diff --git a/spzx-service/service-product/src/main/java/com/atguigu/product/mapper/CategoryMapper.java b/spzx-service/service-product/src/main/java/com/atguigu/product/mapper/CategoryMapper.java index 0625e91..0fc927f 100644 --- a/spzx-service/service-product/src/main/java/com/atguigu/product/mapper/CategoryMapper.java +++ b/spzx-service/service-product/src/main/java/com/atguigu/product/mapper/CategoryMapper.java @@ -13,4 +13,11 @@ public interface CategoryMapper { * @return 分类列表 */ List findOneCategory(); + + /** + * 查询所以分类 + * + * @return 分类列表 + */ + List findAll(); } diff --git a/spzx-service/service-product/src/main/java/com/atguigu/product/service/CategoryService.java b/spzx-service/service-product/src/main/java/com/atguigu/product/service/CategoryService.java index 86f85d4..f2195bd 100644 --- a/spzx-service/service-product/src/main/java/com/atguigu/product/service/CategoryService.java +++ b/spzx-service/service-product/src/main/java/com/atguigu/product/service/CategoryService.java @@ -11,4 +11,11 @@ public interface CategoryService { * @return 分类实体类列表 */ List selectOneCategory(); + + /** + * 查询属性结构 + * + * @return 分类实体类列表 + */ + List findCategoryTree(); } diff --git a/spzx-service/service-product/src/main/java/com/atguigu/product/service/impl/CategoryServiceImpl.java b/spzx-service/service-product/src/main/java/com/atguigu/product/service/impl/CategoryServiceImpl.java index 7d49f22..33dad2f 100644 --- a/spzx-service/service-product/src/main/java/com/atguigu/product/service/impl/CategoryServiceImpl.java +++ b/spzx-service/service-product/src/main/java/com/atguigu/product/service/impl/CategoryServiceImpl.java @@ -3,6 +3,7 @@ package com.atguigu.product.service.impl; import com.atguigu.product.mapper.CategoryMapper; import com.atguigu.product.service.CategoryService; import com.atguigu.spzx.model.entity.product.Category; +import com.atguigu.utils.CategoryHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,4 +23,16 @@ public class CategoryServiceImpl implements CategoryService { public List selectOneCategory() { return categoryMapper.findOneCategory(); } + + /** + * 查询属性结构 + * + * @return 分类实体类列表 + */ + @Override + public List findCategoryTree() { + // 查询所以分类,返回list集合 + List categoryList = categoryMapper.findAll(); + return CategoryHelper.buildTree(categoryList); + } } diff --git a/spzx-service/service-product/src/main/resources/application-dev.yml b/spzx-service/service-product/src/main/resources/application-dev.yml index 93c5aa3..5af0355 100644 --- a/spzx-service/service-product/src/main/resources/application-dev.yml +++ b/spzx-service/service-product/src/main/resources/application-dev.yml @@ -6,5 +6,11 @@ bunny: username: root password: "02120212" + redis: + host: 106.15.251.123 + port: 6379 + database: 2 + nacos: - server-addr: z-bunny.cn:8848 \ No newline at end of file + server-addr: z-bunny.cn:8848 + diff --git a/spzx-service/service-product/src/main/resources/application.yml b/spzx-service/service-product/src/main/resources/application.yml index 439cc67..2949858 100644 --- a/spzx-service/service-product/src/main/resources/application.yml +++ b/spzx-service/service-product/src/main/resources/application.yml @@ -17,6 +17,12 @@ spring: username: ${bunny.datasource.username} password: "${bunny.datasource.password}" + data: + redis: + host: ${bunny.redis.host} + port: ${bunny.redis.port} + database: ${bunny.redis.database} + logging: level: com.atguigu.product.mapper: debug diff --git a/spzx-service/service-product/src/main/resources/banner.txt b/spzx-service/service-product/src/main/resources/banner.txt new file mode 100644 index 0000000..cc77fc2 --- /dev/null +++ b/spzx-service/service-product/src/main/resources/banner.txt @@ -0,0 +1,16 @@ +-----------------▄██-█▄--------- +-----------------███▄██▄-------- +-----------------███████-------- +-----------------▀███████------- +-------------------██████▄▄----- +-------------------█████████▄--- +-------------------██████▄████-- +-------▄███████████████████████- +-----▄███████████████████████▀-- +---▄██████████████████████------ +---███████████████████████------ +---███████████████████████------ +-▄▄██████████████████████▀------ +-█████████████████▀█████-------- +-▀██████████████▀▀-▀█████▄------ +-------▀▀▀▀▀▀▀▀▀------▀▀▀▀------ \ No newline at end of file diff --git a/spzx-service/service-product/src/main/resources/favicon.ico b/spzx-service/service-product/src/main/resources/favicon.ico new file mode 100644 index 0000000..1ba397c Binary files /dev/null and b/spzx-service/service-product/src/main/resources/favicon.ico differ diff --git a/spzx-service/service-product/src/main/resources/mapper/product/CategoryMapper.xml b/spzx-service/service-product/src/main/resources/mapper/product/CategoryMapper.xml index 4014a09..46cd238 100644 --- a/spzx-service/service-product/src/main/resources/mapper/product/CategoryMapper.xml +++ b/spzx-service/service-product/src/main/resources/mapper/product/CategoryMapper.xml @@ -16,4 +16,15 @@ and is_deleted = 0 order by order_num + + + diff --git a/spzx-service/service-product/src/main/resources/mybatis-config.xml b/spzx-service/service-product/src/main/resources/mybatis-config.xml new file mode 100644 index 0000000..89898c2 --- /dev/null +++ b/spzx-service/service-product/src/main/resources/mybatis-config.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + +