feat(新增-商品管理): 列表查询

Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
bunny 2024-03-26 14:50:41 +08:00
parent 27105b3220
commit 3d69821e67
5 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package com.atguigu.spzx.manger.controller;
import com.atguigu.spzx.manger.service.ProductService;
import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.entity.product.Product;
import com.atguigu.spzx.model.vo.result.Result;
import com.github.pagehelper.PageInfo;
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;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Tag(name = "商品管理")
@RestController
@RequestMapping(value = "/admin/product/product")
public class ProductController {
@Autowired
private ProductService productService;
@Operation(summary = "列表查询", description = "列表查询")
@GetMapping("{page}/{limit}")
public Result<PageInfo<Product>> findByPage(@PathVariable Integer page, @PathVariable Integer limit, ProductDto dto) {
PageInfo<Product> pageInfo = productService.findByPage(page, limit, dto);
return Result.success(pageInfo);
}
}

View File

@ -0,0 +1,18 @@
package com.atguigu.spzx.manger.mapper;
import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.entity.product.Product;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ProductMapper {
/**
* 列表查询
*
* @return 查询结果
*/
List<Product> findByPage(ProductDto dto);
}

View File

@ -0,0 +1,17 @@
package com.atguigu.spzx.manger.service;
import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.entity.product.Product;
import com.github.pagehelper.PageInfo;
public interface ProductService {
/**
* 列表查询
*
* @param page 当前也
* @param limit 每页限制
* @return 分页结果
*/
PageInfo<Product> findByPage(Integer page, Integer limit, ProductDto dto);
}

View File

@ -0,0 +1,36 @@
package com.atguigu.spzx.manger.service.impl;
import com.atguigu.spzx.manger.mapper.ProductMapper;
import com.atguigu.spzx.manger.service.ProductService;
import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.entity.product.Product;
import com.github.pagehelper.Page;
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 ProductServiceImpl implements ProductService {
@Autowired
private ProductMapper productMapper;
/**
* 列表查询
*
* @param page 当前也
* @param limit 每页限制
* @param dto
* @return 分页结果
*/
@Override
public PageInfo<Product> findByPage(Integer page, Integer limit, ProductDto dto) {
Page<Object> startPage = PageHelper.startPage(page, limit);
List<Product> productList = productMapper.findByPage(dto);
startPage.close();
return new PageInfo<>(productList);
}
}

View File

@ -0,0 +1,38 @@
<?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.ProductMapper">
<!-- 用于select查询公用抽取的列 -->
<sql id="columns">
id,name,brand_id,category1_id,category2_id,category3_id,unit_name,slider_urls,spec_value,status,audit_status,audit_message,create_time,update_time,is_deleted
</sql>
<!-- 列表查询 -->
<select id="findByPage" resultType="com.atguigu.spzx.model.entity.product.Product">
select
p.id, p.name , p.brand_id , p.category1_id , p.category2_id , p.category3_id, p.unit_name,
p.slider_urls , p.spec_value , p.status , p.audit_status , p.audit_message , p.create_time , p.update_time ,
p.is_deleted ,
b.name brandName , c1.name category1Name , c2.name category2Name , c3.name category3Name
from product p
LEFT JOIN brand b on b.id = p.brand_id
LEFT JOIN category c1 on c1.id = p.category1_id
LEFT JOIN category c2 on c2.id = p.category2_id
LEFT JOIN category c3 on c3.id = p.category3_id
<where>
<if test="brandId != null and brandId != ''">
and p.brand_id = #{brandId}
</if>
<if test="category1Id != null and category1Id != ''">
and p.category1_id = #{category1Id}
</if>
<if test="category2Id != null and category2Id != ''">
and p.category2_id = #{category2Id}
</if>
<if test="category3Id != null and category3Id != ''">
and p.category3_id = #{category3Id}
</if>
and p.is_deleted = 0
</where>
order by id desc
</select>
</mapper>