feat(新增-分类接口管理): 获取分类树形数据
Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
parent
52004cf2ba
commit
fee9dab785
|
@ -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(); // 接口请求路径规则
|
||||
}
|
||||
}
|
|
@ -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<Category> buildTree(List<Category> categoryList) {
|
||||
ArrayList<Category> tree = new ArrayList<>();
|
||||
// 将菜单进行遍历
|
||||
categoryList.forEach(category -> {
|
||||
if (category.getParentId() == 0) {
|
||||
tree.add(getChildren(category, categoryList));
|
||||
}
|
||||
});
|
||||
return tree;
|
||||
}
|
||||
|
||||
|
||||
public static Category getChildren(Category category, List<Category> 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;
|
||||
}
|
||||
}
|
|
@ -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<List<Category>> findCategoryTree() {
|
||||
log.info("===>获取分类树形数据");
|
||||
List<Category> list = categoryService.findCategoryTree();
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
|
@ -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<IndexVo> findData() {
|
||||
log.info("===>获取首页数据");
|
||||
// 查询以及分类
|
||||
List<Category> categoryList = categoryService.selectOneCategory();
|
||||
// 根据销量排序,获取前十条数据
|
||||
|
|
|
@ -13,4 +13,11 @@ public interface CategoryMapper {
|
|||
* @return 分类列表
|
||||
*/
|
||||
List<Category> findOneCategory();
|
||||
|
||||
/**
|
||||
* 查询所以分类
|
||||
*
|
||||
* @return 分类列表
|
||||
*/
|
||||
List<Category> findAll();
|
||||
}
|
||||
|
|
|
@ -11,4 +11,11 @@ public interface CategoryService {
|
|||
* @return 分类实体类列表
|
||||
*/
|
||||
List<Category> selectOneCategory();
|
||||
|
||||
/**
|
||||
* 查询属性结构
|
||||
*
|
||||
* @return 分类实体类列表
|
||||
*/
|
||||
List<Category> findCategoryTree();
|
||||
}
|
||||
|
|
|
@ -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<Category> selectOneCategory() {
|
||||
return categoryMapper.findOneCategory();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询属性结构
|
||||
*
|
||||
* @return 分类实体类列表
|
||||
*/
|
||||
@Override
|
||||
public List<Category> findCategoryTree() {
|
||||
// 查询所以分类,返回list集合
|
||||
List<Category> categoryList = categoryMapper.findAll();
|
||||
return CategoryHelper.buildTree(categoryList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
server-addr: z-bunny.cn:8848
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
-----------------▄██-█▄---------
|
||||
-----------------███▄██▄--------
|
||||
-----------------███████--------
|
||||
-----------------▀███████-------
|
||||
-------------------██████▄▄-----
|
||||
-------------------█████████▄---
|
||||
-------------------██████▄████--
|
||||
-------▄███████████████████████-
|
||||
-----▄███████████████████████▀--
|
||||
---▄██████████████████████------
|
||||
---███████████████████████------
|
||||
---███████████████████████------
|
||||
-▄▄██████████████████████▀------
|
||||
-█████████████████▀█████--------
|
||||
-▀██████████████▀▀-▀█████▄------
|
||||
-------▀▀▀▀▀▀▀▀▀------▀▀▀▀------
|
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
|
@ -16,4 +16,15 @@
|
|||
and is_deleted = 0
|
||||
order by order_num
|
||||
</select>
|
||||
|
||||
<!-- 查询所以分类 -->
|
||||
<select id="findAll" resultType="com.atguigu.spzx.model.entity.product.Category">
|
||||
select
|
||||
<include refid="columns"/>
|
||||
from category
|
||||
where
|
||||
status = 1
|
||||
and is_deleted = 0
|
||||
order by order_num
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE configuration PUBLIC
|
||||
"-//mybatis.org//DTD Config 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
<configuration>
|
||||
<settings>
|
||||
<!-- 设置驼峰标识 -->
|
||||
<setting name="mapUnderscoreToCamelCase" value="true"/>
|
||||
<!-- 打印SQL语句 -->
|
||||
<setting name="logImpl" value="STDOUT_LOGGING"/>
|
||||
</settings>
|
||||
<plugins>
|
||||
<!-- 分页插件 -->
|
||||
<plugin interceptor="com.github.pagehelper.PageInterceptor"/>
|
||||
</plugins>
|
||||
</configuration>
|
Loading…
Reference in New Issue