dev-v2 #3

Merged
bunny merged 122 commits from dev-v2 into master-v2 2024-03-30 23:40:58 +08:00
13 changed files with 226 additions and 8 deletions
Showing only changes of commit e491620e6f - Show all commits

View File

@ -6,7 +6,6 @@ import lombok.Data;
@Data
@Schema(description = "商品列表搜索条件实体类")
public class ProductSkuDto {
@Schema(description = "关键字")
private String keyword;
@ -24,5 +23,4 @@ public class ProductSkuDto {
@Schema(description = "排序(综合排序:1 价格升序:2 价格降序:3")
private Integer order = 1;
}

View File

@ -1,13 +1,21 @@
package com.atguigu.product;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@ComponentScan("com.atguigu")
@EnableCaching// 开启缓存注解
@MapperScan("com.atguigu.*.mapper")
@EnableTransactionManagement // 开启注解方式的事务管理
@EnableScheduling
@Slf4j
public class ProductApplication {
public static void main(String[] args) {
SpringApplication.run(ProductApplication.class, args);

View File

@ -0,0 +1,28 @@
package com.atguigu.product.controller;
import com.atguigu.product.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.vo.result.Result;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Tag(name = "品牌管理")
@RestController
@RequestMapping(value = "/api/product/brand")
public class BrandController {
@Autowired
private BrandService brandService;
@Operation(summary = "获取全部品牌")
@GetMapping("findAll")
public Result<List<Brand>> findAll() {
List<Brand> list = brandService.findAll();
return Result.success(list);
}
}

View File

@ -0,0 +1,32 @@
package com.atguigu.product.controller;
import com.atguigu.product.service.ProductService;
import com.atguigu.spzx.model.dto.h5.ProductSkuDto;
import com.atguigu.spzx.model.entity.product.ProductSku;
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.Parameter;
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 = "/api/product")
public class ProductController {
@Autowired
private ProductService productService;
@Operation(summary = "分页查询")
@GetMapping(value = "{page}/{limit}")
public Result<PageInfo<ProductSku>> findByPage(@Parameter(name = "page", description = "当前页码", required = true) @PathVariable Integer page,
@Parameter(name = "limit", description = "每页记录数", required = true) @PathVariable Integer limit,
@Parameter(name = "productSkuDto", description = "搜索条件对象", required = false) ProductSkuDto productSkuDto) {
PageInfo<ProductSku> pageInfo = productService.findByPage(page, limit, productSkuDto);
return Result.success(pageInfo);
}
}

View File

@ -0,0 +1,16 @@
package com.atguigu.product.mapper;
import com.atguigu.spzx.model.entity.product.Brand;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface BrandMapper {
/**
* 获取全部品牌
*
* @return 查询返回全部品牌
*/
List<Brand> findAll();
}

View File

@ -1,5 +1,6 @@
package com.atguigu.product.mapper;
import com.atguigu.spzx.model.dto.h5.ProductSkuDto;
import com.atguigu.spzx.model.entity.product.ProductSku;
import org.apache.ibatis.annotations.Mapper;
@ -13,4 +14,12 @@ public interface ProductSkuMapper {
* @return ProductSku列表
*/
List<ProductSku> selectProductSkuBySale();
/**
* 分页查询
*
* @param productSkuDto 商品列表搜索条件实体类
* @return PageInfo<ProductSku>
*/
List<ProductSku> findByPage(ProductSkuDto productSkuDto);
}

View File

@ -0,0 +1,14 @@
package com.atguigu.product.service;
import com.atguigu.spzx.model.entity.product.Brand;
import java.util.List;
public interface BrandService {
/**
* 获取全部品牌
*
* @return 查询返回全部品牌
*/
List<Brand> findAll();
}

View File

@ -1,6 +1,8 @@
package com.atguigu.product.service;
import com.atguigu.spzx.model.dto.h5.ProductSkuDto;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.github.pagehelper.PageInfo;
import java.util.List;
@ -11,4 +13,14 @@ public interface ProductService {
* @return ProductSku 列表
*/
List<ProductSku> selectProductSkuBySale();
/**
* 分页查询
*
* @param page 当前页
* @param limit 分页每页多少
* @param productSkuDto 商品列表搜索条件实体类
* @return PageInfo<ProductSku>
*/
PageInfo<ProductSku> findByPage(Integer page, Integer limit, ProductSkuDto productSkuDto);
}

View File

@ -0,0 +1,25 @@
package com.atguigu.product.service.impl;
import com.atguigu.product.mapper.BrandMapper;
import com.atguigu.product.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class BrandServiceImpl implements BrandService {
@Autowired
private BrandMapper brandMapper;
/**
* 获取全部品牌
*
* @return 查询返回全部品牌
*/
@Override
public List<Brand> findAll() {
return brandMapper.findAll();
}
}

View File

@ -2,7 +2,11 @@ package com.atguigu.product.service.impl;
import com.atguigu.product.mapper.ProductSkuMapper;
import com.atguigu.product.service.ProductService;
import com.atguigu.spzx.model.dto.h5.ProductSkuDto;
import com.atguigu.spzx.model.entity.product.ProductSku;
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;
@ -22,4 +26,20 @@ public class ProductServiceImpl implements ProductService {
public List<ProductSku> selectProductSkuBySale() {
return productSkuMapper.selectProductSkuBySale();
}
/**
* 分页查询
*
* @param page 当前页
* @param limit 分页每页多少
* @param productSkuDto 商品列表搜索条件实体类
* @return PageInfo<ProductSku>
*/
@Override
public PageInfo<ProductSku> findByPage(Integer page, Integer limit, ProductSkuDto productSkuDto) {
Page<Object> startPage = PageHelper.startPage(page, limit);
List<ProductSku> productSkuList = productSkuMapper.findByPage(productSkuDto);
startPage.close();
return new PageInfo<>(productSkuList);
}
}

View File

@ -3,9 +3,10 @@ server:
spring:
profiles:
active: dev
main:
allow-bean-definition-overriding: true
application:
name: service-product
cloud:
nacos:
discovery:
@ -27,14 +28,14 @@ spring:
logging:
level:
com.atguigu.product.mapper: debug
com.atguigu.product.controller: info
com.atguigu.product.service: info
com.alibaba.nacos: info
com.atguigu.spzx.manger.mapper: debug
com.atguigu.spzx.manger.controller: info
com.atguigu.spzx.manger.service: info
pattern:
dateformat: HH:mm:ss:SSS
file:
path: logs/${spring.application.name}
path: "logs/${spring.application.name}"
mybatis:
type-aliases-package: com.atguigu.spzx.model

View File

@ -0,0 +1,17 @@
<?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.product.mapper.BrandMapper">
<!-- 用于select查询公用抽取的列 -->
<sql id="columns">
id,name,logo,create_time,update_time,is_deleted
</sql>
<!-- 获取全部品牌 -->
<select id="findAll" resultType="com.atguigu.spzx.model.entity.product.Brand">
select
<include refid="columns"/>
from brand
where is_deleted = 0
order by id desc
</select>
</mapper>

View File

@ -13,4 +13,42 @@
ORDER BY psku.sale_num DESC
LIMIT 10
</select>
<!-- 分页查询 -->
<select id="findByPage" resultType="com.atguigu.spzx.model.entity.product.ProductSku">
select
sku.id,sku.sku_code,sku.sku_name,sku.product_id,sku.thumb_img,sku.sale_price,sku.market_price,sku.cost_price,sku.stock_num,sku.sale_num,sku.sku_spec,sku.weight,sku.volume,sku.status,sku.create_time,sku.update_time,sku.is_deleted
from product_sku sku
left join product p on p.id = sku.product_id
<where>
<if test="keyword != null and keyword != ''">
and sku.sku_name like CONCAT('%',#{keyword},'%')
</if>
<if test="brandId != null">
and p.brand_id = #{brandId}
</if>
<if test="category1Id != null">
and p.category1_id = #{category1Id}
</if>
<if test="category2Id != null">
and p.category2_id = #{category2Id}
</if>
<if test="category3Id != null">
and p.category3_id = #{category3Id}
</if>
and p.status = 1
and p.audit_status = 1
and sku.is_deleted = 0
and p.is_deleted = 0
</where>
<if test="order == 1">
order by sku.sale_num desc
</if>
<if test="order == 2">
order by sku.sale_price asc
</if>
<if test="order == 3">
order by sku.sale_price desc
</if>
</select>
</mapper>