feat(新增): 分类品牌列表

Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
bunny 2024-03-26 10:55:37 +08:00
parent 8dddea3bf5
commit 6de6b4d232
7 changed files with 138 additions and 17 deletions

View File

@ -0,0 +1,27 @@
package com.atguigu.spzx.manger.controller;
import com.atguigu.spzx.manger.service.CategoryBrandService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.result.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/admin/product/categoryBrand")
public class CategoryBrandController {
@Autowired
private CategoryBrandService categoryBrandService;
@Operation(summary = "分类品牌列表", description = "分类品牌列表接口")
@GetMapping("{page}/{limit}")
public Result<PageInfo<CategoryBrand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit, CategoryBrandDto dto) {
PageInfo<CategoryBrand> pageInfo = categoryBrandService.findByPage(page, limit, dto);
return Result.success(pageInfo);
}
}

View File

@ -3,7 +3,6 @@ package com.atguigu.spzx.manger.controller;
import com.atguigu.spzx.manger.service.CategoryService;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.vo.result.Result;
import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
@ -21,21 +20,21 @@ public class CategoryController {
private CategoryService categoryService;
@Operation(summary = "根据parentId获取下级节点", description = "根据parentId获取下级节点")
@GetMapping(value = "findByParentId/{parentId}")
@GetMapping(value = "findCategoryList/{parentId}")
public Result<List<Category>> findByParentId(@PathVariable Long parentId) {
List<Category> list = categoryService.findByParentId(parentId);
return Result.success(list);
}
@Operation(summary = "导出数据",description = "导出数据")
@Operation(summary = "导出数据", description = "导出数据")
@GetMapping(value = "/exportData")
public void exportData(HttpServletResponse response) {
categoryService.exportData(response);
}
@Operation(summary = "导入功能",description = "导入功能")
@Operation(summary = "导入功能", description = "导入功能")
@PostMapping("importData")
public Result<String > importData(MultipartFile file) {
public Result<String> importData(MultipartFile file) {
categoryService.importData(file);
return Result.success();
}

View File

@ -0,0 +1,18 @@
package com.atguigu.spzx.manger.mapper;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface CategoryBrandMapper {
/**
* 分类品牌列表
*
* @param dto 搜索条件实体类
* @return PageInfo<CategoryBrand>
*/
List<CategoryBrand> findByPage(CategoryBrandDto dto);
}

View File

@ -0,0 +1,17 @@
package com.atguigu.spzx.manger.service;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.github.pagehelper.PageInfo;
public interface CategoryBrandService {
/**
* 分类品牌列表
*
* @param page 当前页
* @param limit 每页限制
* @param dto 搜索条件实体类
* @return PageInfo<CategoryBrand>
*/
PageInfo<CategoryBrand> findByPage(Integer page, Integer limit, CategoryBrandDto dto);
}

View File

@ -0,0 +1,33 @@
package com.atguigu.spzx.manger.service.impl;
import com.atguigu.spzx.manger.mapper.CategoryBrandMapper;
import com.atguigu.spzx.manger.service.CategoryBrandService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class CategoryBrandServiceImpl implements CategoryBrandService {
@Autowired
private CategoryBrandMapper categoryBrandMapper;
/**
* 分类品牌列表
*
* @param page 当前页
* @param limit 每页限制
* @param dto 搜索条件实体类
* @return PageInfo<CategoryBrand>
*/
@Override
public PageInfo<CategoryBrand> findByPage(Integer page, Integer limit, CategoryBrandDto dto) {
PageHelper.startPage(page, limit).close();
List<CategoryBrand> categoryBrandList = categoryBrandMapper.findByPage(dto);
return new PageInfo<>(categoryBrandList);
}
}

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.atguigu.spzx.manger.mapper.CategoryBrandMapper">
<!-- 用于select查询公用抽取的列 -->
<sql id="columns">
id,brand_id,category_id,create_time,update_time,is_deleted
</sql>
<!-- 分类品牌列表 -->
<select id="findByPage" resultType="com.atguigu.spzx.model.entity.product.CategoryBrand">
select
cb.id,cb.brand_id,cb.category_id,cb.create_time,cb.update_time,
c.name as categoryName,
b.name as brandName, b.logo
from category_brand cb
left join category c on c.id = cb.category_id
left join brand b on b.id = cb.brand_id
<where>
<if test="brandId != null and brandId != ''">
and cb.brand_id = #{brandId}
</if>
<if test="categoryId != null and categoryId != ''">
and cb.category_id = #{categoryId}
</if>
and cb.is_deleted = 0
</where>
order by cb.id desc
</select>
</mapper>

View File

@ -7,20 +7,18 @@ import lombok.Data;
@Data
@Schema(description = "分类品牌实体类")
public class CategoryBrand extends BaseEntity {
@Schema(description = "品牌id")
private Long brandId;
@Schema(description = "分类id")
private Long categoryId;
@Schema(description = "分类名称" , required = false)
@Schema(description = "分类名称", required = false)
private String categoryName;
@Schema(description = "品牌名称" , required = false)
@Schema(description = "品牌名称", required = false)
private String brandName;
@Schema(description = "品牌logo" , required = false)
@Schema(description = "品牌logo", required = false)
private String logo;
}