feat(新增-商品管理): 保存修改数据接口
Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
parent
580e1155db
commit
2b921ce7fd
|
@ -8,6 +8,7 @@ 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.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -50,4 +51,11 @@ public class ProductController {
|
|||
Product product = productService.getById(id);
|
||||
return Result.success(product);
|
||||
}
|
||||
|
||||
@Operation(summary = "保存修改数据接口", description = "保存修改数据接口")
|
||||
@PutMapping("updateById")
|
||||
public Result<Product> updateById(@Parameter(name = "product", description = "请求参数实体类", required = true) @RequestBody Product product) {
|
||||
productService.updateById(product);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -19,4 +19,11 @@ public interface ProductDetailsMapper {
|
|||
* @return ProductDetails
|
||||
*/
|
||||
ProductDetails selectByProductId(Long id);
|
||||
|
||||
/**
|
||||
* 修改商品的详情数据
|
||||
*
|
||||
* @param productDetails ProductDetails
|
||||
*/
|
||||
void updateById(ProductDetails productDetails);
|
||||
}
|
||||
|
|
|
@ -30,4 +30,11 @@ public interface ProductMapper {
|
|||
* @return 商品实体类
|
||||
*/
|
||||
Product selectById(Long id);
|
||||
|
||||
/**
|
||||
* 修改商品基本数据
|
||||
*
|
||||
* @param product 商品实体类
|
||||
*/
|
||||
void updateById(Product product);
|
||||
}
|
||||
|
|
|
@ -21,4 +21,11 @@ public interface ProductSkuMapper {
|
|||
* @return 商品实体类列表
|
||||
*/
|
||||
List<ProductSku> selectByProductId(Long id);
|
||||
|
||||
/**
|
||||
* 修改商品的sku数据
|
||||
*
|
||||
* @param productSku 商品实体类
|
||||
*/
|
||||
void updateById(ProductSku productSku);
|
||||
}
|
||||
|
|
|
@ -29,4 +29,11 @@ public interface ProductService {
|
|||
* @return 商品实体类
|
||||
*/
|
||||
Product getById(Long id);
|
||||
|
||||
/**
|
||||
* 保存修改数据接口
|
||||
*
|
||||
* @param product 商品实体类
|
||||
*/
|
||||
void updateById(Product product);
|
||||
}
|
||||
|
|
|
@ -96,8 +96,30 @@ public class ProductServiceImpl implements ProductService {
|
|||
// 根据商品的id查询商品详情数据
|
||||
ProductDetails productDetails = productDetailsMapper.selectByProductId(product.getId());
|
||||
product.setDetailsImageUrls(productDetails.getImageUrls());
|
||||
|
||||
|
||||
// 返回数据
|
||||
return product;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存修改数据接口
|
||||
*
|
||||
* @param product 商品实体类
|
||||
*/
|
||||
@Override
|
||||
public void updateById(Product product) {
|
||||
// 修改商品基本数据
|
||||
productMapper.updateById(product);
|
||||
|
||||
// 修改商品的sku数据
|
||||
List<ProductSku> productSkuList = product.getProductSkuList();
|
||||
productSkuList.forEach(productSku -> {
|
||||
productSkuMapper.updateById(productSku);
|
||||
});
|
||||
|
||||
// 修改商品的详情数据
|
||||
ProductDetails productDetails = productDetailsMapper.selectByProductId(product.getId());
|
||||
productDetails.setImageUrls(product.getDetailsImageUrls());
|
||||
productDetailsMapper.updateById(productDetails);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,19 @@
|
|||
values (#{id}, #{productId}, #{imageUrls}, now(), now(), 0)
|
||||
</insert>
|
||||
|
||||
<!-- 修改商品的详情数据 -->
|
||||
<update id="updateById">
|
||||
update product_details set
|
||||
<if test="productId != null and productId != ''">
|
||||
product_id = #{productId},
|
||||
</if>
|
||||
<if test="imageUrls != null and imageUrls != ''">
|
||||
image_urls = #{imageUrls},
|
||||
</if>
|
||||
update_time = now()
|
||||
where
|
||||
id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="selectByProductId" resultType="com.atguigu.spzx.model.entity.product.ProductDetails">
|
||||
select
|
||||
|
|
|
@ -14,6 +14,47 @@
|
|||
#{specValue}, #{status}, #{auditStatus}, #{auditMessage}, now(), now(), 0)
|
||||
</insert>
|
||||
|
||||
<!-- 修改商品基本数据 -->
|
||||
<update id="updateById">
|
||||
update product set
|
||||
<if test="name != null and name != ''">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="brandId != null and brandId != ''">
|
||||
brand_id = #{brandId},
|
||||
</if>
|
||||
<if test="category1Id != null and category1Id != ''">
|
||||
category1_id = #{category1Id},
|
||||
</if>
|
||||
<if test="category2Id != null and category2Id != ''">
|
||||
category2_id = #{category2Id},
|
||||
</if>
|
||||
<if test="category3Id != null and category3Id != ''">
|
||||
category3_id = #{category3Id},
|
||||
</if>
|
||||
<if test="unitName != null and unitName != ''">
|
||||
unit_name = #{unitName},
|
||||
</if>
|
||||
<if test="sliderUrls != null and sliderUrls != ''">
|
||||
slider_urls = #{sliderUrls},
|
||||
</if>
|
||||
<if test="specValue != null and specValue != ''">
|
||||
spec_value = #{specValue},
|
||||
</if>
|
||||
<if test="status != null and status != ''">
|
||||
status = #{status},
|
||||
</if>
|
||||
<if test="auditStatus != null and auditStatus != ''">
|
||||
audit_status = #{auditStatus},
|
||||
</if>
|
||||
<if test="auditMessage != null and auditMessage != ''">
|
||||
audit_message = #{auditMessage},
|
||||
</if>
|
||||
update_time = now()
|
||||
where
|
||||
id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 列表查询 -->
|
||||
<select id="findByPage" resultType="com.atguigu.spzx.model.entity.product.Product">
|
||||
select
|
||||
|
|
|
@ -15,6 +15,50 @@
|
|||
#{costPrice}, #{stockNum}, #{skuSpec}, #{weight}, #{volume}, #{status}, #{saleNum}, now(), now(), 0)
|
||||
</insert>
|
||||
|
||||
<!-- 修改商品的sku数据 -->
|
||||
<update id="updateById">
|
||||
update product_sku set
|
||||
<if test="skuCode != null and skuCode != ''">
|
||||
sku_code = #{skuCode},
|
||||
</if>
|
||||
<if test="skuName != null and skuName != ''">
|
||||
sku_name = #{skuName},
|
||||
</if>
|
||||
<if test="productId != null and productId != ''">
|
||||
product_id = #{productId},
|
||||
</if>
|
||||
<if test="thumbImg != null and thumbImg != ''">
|
||||
thumb_img = #{thumbImg},
|
||||
</if>
|
||||
<if test="salePrice != null and salePrice != ''">
|
||||
sale_price = #{salePrice},
|
||||
</if>
|
||||
<if test="marketPrice != null and marketPrice != ''">
|
||||
market_price = #{marketPrice},
|
||||
</if>
|
||||
<if test="costPrice != null and costPrice != ''">
|
||||
cost_price = #{costPrice},
|
||||
</if>
|
||||
<if test="stockNum != null and stockNum != ''">
|
||||
stock_num = #{stockNum},
|
||||
</if>
|
||||
<if test="skuSpec != null and skuSpec != ''">
|
||||
sku_spec = #{skuSpec},
|
||||
</if>
|
||||
<if test="weight != null and weight != ''">
|
||||
weight = #{weight},
|
||||
</if>
|
||||
<if test="volume != null and volume != ''">
|
||||
volume = #{volume},
|
||||
</if>
|
||||
<if test="status != null and status != ''">
|
||||
status = #{status},
|
||||
</if>
|
||||
update_time = now()
|
||||
where
|
||||
id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 根据商品的id查询sku数据 -->
|
||||
<select id="selectByProductId" resultType="com.atguigu.spzx.model.entity.product.ProductSku">
|
||||
select
|
||||
|
|
Loading…
Reference in New Issue