feat(新增-商品管理): 查询商品详情
Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
parent
ac36b13ee1
commit
580e1155db
|
@ -43,4 +43,11 @@ public class ProductController {
|
|||
productService.save(product);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "查询商品详情", description = "查询商品详情")
|
||||
@GetMapping("getById/{id}")
|
||||
public Result<Product> getById(@PathVariable Long id) {
|
||||
Product product = productService.getById(id);
|
||||
return Result.success(product);
|
||||
}
|
||||
}
|
|
@ -11,4 +11,12 @@ public interface ProductDetailsMapper {
|
|||
* @param productDetails 商品实体类
|
||||
*/
|
||||
void save(ProductDetails productDetails);
|
||||
|
||||
/**
|
||||
* 根据商品的id查询商品详情数据
|
||||
*
|
||||
* @param id 查询的ID
|
||||
* @return ProductDetails
|
||||
*/
|
||||
ProductDetails selectByProductId(Long id);
|
||||
}
|
||||
|
|
|
@ -22,4 +22,12 @@ public interface ProductMapper {
|
|||
* @param product 商品实体类
|
||||
*/
|
||||
void save(Product product);
|
||||
|
||||
/**
|
||||
* 根据id查询商品数据
|
||||
*
|
||||
* @param id 查询的ID
|
||||
* @return 商品实体类
|
||||
*/
|
||||
Product selectById(Long id);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.atguigu.spzx.manger.mapper;
|
|||
import com.atguigu.spzx.model.entity.product.ProductSku;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductSkuMapper {
|
||||
/**
|
||||
|
@ -11,4 +13,12 @@ public interface ProductSkuMapper {
|
|||
* @param productSku 商品实体类
|
||||
*/
|
||||
void save(ProductSku productSku);
|
||||
|
||||
/**
|
||||
* 根据商品的id查询sku数据
|
||||
*
|
||||
* @param id 查询的ID
|
||||
* @return 商品实体类列表
|
||||
*/
|
||||
List<ProductSku> selectByProductId(Long id);
|
||||
}
|
||||
|
|
|
@ -21,4 +21,12 @@ public interface ProductService {
|
|||
* @param product 商品实体类
|
||||
*/
|
||||
void save(Product product);
|
||||
|
||||
/**
|
||||
* 查询商品详情
|
||||
*
|
||||
* @param id 查询ID
|
||||
* @return 商品实体类
|
||||
*/
|
||||
Product getById(Long id);
|
||||
}
|
||||
|
|
|
@ -78,4 +78,26 @@ public class ProductServiceImpl implements ProductService {
|
|||
productDetails.setImageUrls(product.getDetailsImageUrls());
|
||||
productDetailsMapper.save(productDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品详情
|
||||
*
|
||||
* @param id 查询ID
|
||||
* @return 商品实体类
|
||||
*/
|
||||
@Override
|
||||
public Product getById(Long id) {
|
||||
// 根据id查询商品数据
|
||||
Product product = productMapper.selectById(id);
|
||||
// 根据商品的id查询sku数据
|
||||
List<ProductSku> productSkuList = productSkuMapper.selectByProductId(id);
|
||||
product.setProductSkuList(productSkuList);
|
||||
|
||||
// 根据商品的id查询商品详情数据
|
||||
ProductDetails productDetails = productDetailsMapper.selectByProductId(product.getId());
|
||||
product.setDetailsImageUrls(productDetails.getImageUrls());
|
||||
|
||||
// 返回数据
|
||||
return product;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,23 @@
|
|||
<?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.ProductDetailsMapper">
|
||||
<!-- 用于select查询公用抽取的列 -->
|
||||
<sql id="columns">
|
||||
id,product_id,image_urls,create_time,update_time,is_deleted
|
||||
</sql>
|
||||
|
||||
<!-- 保存数据 -->
|
||||
<insert id="save" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into product_details (id, product_id, image_urls, create_time, update_time, is_deleted)
|
||||
values (#{id}, #{productId}, #{imageUrls}, now(), now(), 0) </insert>
|
||||
values (#{id}, #{productId}, #{imageUrls}, now(), now(), 0)
|
||||
</insert>
|
||||
|
||||
|
||||
<select id="selectByProductId" resultType="com.atguigu.spzx.model.entity.product.ProductDetails">
|
||||
select
|
||||
<include refid="columns"/>
|
||||
from product_details
|
||||
where
|
||||
product_id = #{productId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -43,4 +43,33 @@
|
|||
</where>
|
||||
order by id desc
|
||||
</select>
|
||||
|
||||
<!-- 根据id查询商品数据 -->
|
||||
<select id="selectById" 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,
|
||||
c2.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 p.id = #{id}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
<?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.ProductSkuMapper">
|
||||
<!-- 用于select查询公用抽取的列 -->
|
||||
<sql id="columns">
|
||||
id,sku_code,sku_name,product_id,thumb_img,sale_price,market_price,cost_price,stock_num,sku_spec,weight,volume,status,create_time,update_time,is_deleted
|
||||
</sql>
|
||||
|
||||
<!-- 保存数据 -->
|
||||
<insert id="save" useGeneratedKeys="true" keyProperty="id">
|
||||
|
@ -10,4 +14,14 @@
|
|||
values (#{id}, #{skuCode}, #{skuName}, #{productId}, #{thumbImg}, #{salePrice}, #{marketPrice},
|
||||
#{costPrice}, #{stockNum}, #{skuSpec}, #{weight}, #{volume}, #{status}, #{saleNum}, now(), now(), 0)
|
||||
</insert>
|
||||
|
||||
<!-- 根据商品的id查询sku数据 -->
|
||||
<select id="selectByProductId" resultType="com.atguigu.spzx.model.entity.product.ProductSku">
|
||||
select
|
||||
<include refid="columns"/>
|
||||
from product_sku
|
||||
where product_id = #{productId}
|
||||
and is_deleted = 0
|
||||
order by id desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue