feat(新增-商品管理): 保存商品数据接口
Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
parent
1d8ff42dda
commit
ac36b13ee1
|
@ -0,0 +1,14 @@
|
||||||
|
package com.atguigu.spzx.manger.mapper;
|
||||||
|
|
||||||
|
import com.atguigu.spzx.model.entity.product.ProductDetails;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ProductDetailsMapper {
|
||||||
|
/**
|
||||||
|
* 保存数据
|
||||||
|
*
|
||||||
|
* @param productDetails 商品实体类
|
||||||
|
*/
|
||||||
|
void save(ProductDetails productDetails);
|
||||||
|
}
|
|
@ -15,4 +15,11 @@ public interface ProductMapper {
|
||||||
* @return 查询结果
|
* @return 查询结果
|
||||||
*/
|
*/
|
||||||
List<Product> findByPage(ProductDto dto);
|
List<Product> findByPage(ProductDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存商品数据
|
||||||
|
*
|
||||||
|
* @param product 商品实体类
|
||||||
|
*/
|
||||||
|
void save(Product product);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.atguigu.spzx.manger.mapper;
|
||||||
|
|
||||||
|
import com.atguigu.spzx.model.entity.product.ProductSku;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ProductSkuMapper {
|
||||||
|
/**
|
||||||
|
* 保存数据
|
||||||
|
*
|
||||||
|
* @param productSku 商品实体类
|
||||||
|
*/
|
||||||
|
void save(ProductSku productSku);
|
||||||
|
}
|
|
@ -15,5 +15,10 @@ public interface ProductService {
|
||||||
*/
|
*/
|
||||||
PageInfo<Product> findByPage(Integer page, Integer limit, ProductDto dto);
|
PageInfo<Product> findByPage(Integer page, Integer limit, ProductDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存商品数据接口
|
||||||
|
*
|
||||||
|
* @param product 商品实体类
|
||||||
|
*/
|
||||||
void save(Product product);
|
void save(Product product);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
package com.atguigu.spzx.manger.service.impl;
|
package com.atguigu.spzx.manger.service.impl;
|
||||||
|
|
||||||
|
import com.atguigu.spzx.manger.mapper.ProductDetailsMapper;
|
||||||
import com.atguigu.spzx.manger.mapper.ProductMapper;
|
import com.atguigu.spzx.manger.mapper.ProductMapper;
|
||||||
|
import com.atguigu.spzx.manger.mapper.ProductSkuMapper;
|
||||||
import com.atguigu.spzx.manger.service.ProductService;
|
import com.atguigu.spzx.manger.service.ProductService;
|
||||||
import com.atguigu.spzx.model.dto.product.ProductDto;
|
import com.atguigu.spzx.model.dto.product.ProductDto;
|
||||||
import com.atguigu.spzx.model.entity.product.Product;
|
import com.atguigu.spzx.model.entity.product.Product;
|
||||||
|
import com.atguigu.spzx.model.entity.product.ProductDetails;
|
||||||
|
import com.atguigu.spzx.model.entity.product.ProductSku;
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -16,13 +21,17 @@ import java.util.List;
|
||||||
public class ProductServiceImpl implements ProductService {
|
public class ProductServiceImpl implements ProductService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProductMapper productMapper;
|
private ProductMapper productMapper;
|
||||||
|
@Autowired
|
||||||
|
private ProductDetailsMapper productDetailsMapper;
|
||||||
|
@Autowired
|
||||||
|
private ProductSkuMapper productSkuMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表查询
|
* 列表查询
|
||||||
*
|
*
|
||||||
* @param page 当前也
|
* @param page 当前也
|
||||||
* @param limit 每页限制
|
* @param limit 每页限制
|
||||||
* @param dto
|
* @param dto 商品实体类
|
||||||
* @return 分页结果
|
* @return 分页结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,4 +42,40 @@ public class ProductServiceImpl implements ProductService {
|
||||||
startPage.close();
|
startPage.close();
|
||||||
return new PageInfo<>(productList);
|
return new PageInfo<>(productList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存商品数据接口
|
||||||
|
*
|
||||||
|
* @param product 商品实体类
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public void save(Product product) {
|
||||||
|
// 保存商品数据
|
||||||
|
product.setStatus(0); // 设置上架状态为0
|
||||||
|
product.setAuditStatus(0); // 设置审核状态为0
|
||||||
|
productMapper.save(product);
|
||||||
|
|
||||||
|
// 保存商品sku数据
|
||||||
|
List<ProductSku> productSkuList = product.getProductSkuList();
|
||||||
|
for (int i = 0, size = productSkuList.size(); i < size; i++) {
|
||||||
|
|
||||||
|
// 获取ProductSku对象
|
||||||
|
ProductSku productSku = productSkuList.get(i);
|
||||||
|
productSku.setSkuCode(product.getId() + "_" + i); // 构建skuCode
|
||||||
|
|
||||||
|
productSku.setProductId(product.getId()); // 设置商品id
|
||||||
|
productSku.setSkuName(product.getName() + productSku.getSkuSpec());
|
||||||
|
productSku.setSaleNum(0); // 设置销量
|
||||||
|
productSku.setStatus(0);
|
||||||
|
productSkuMapper.save(productSku); // 保存数据
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存商品详情数据
|
||||||
|
ProductDetails productDetails = new ProductDetails();
|
||||||
|
productDetails.setProductId(product.getId());
|
||||||
|
productDetails.setImageUrls(product.getDetailsImageUrls());
|
||||||
|
productDetailsMapper.save(productDetails);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?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">
|
||||||
|
|
||||||
|
<!-- 保存数据 -->
|
||||||
|
<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>
|
||||||
|
</mapper>
|
|
@ -6,6 +6,14 @@
|
||||||
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
|
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>
|
</sql>
|
||||||
|
|
||||||
|
<!-- 保存商品数据 -->
|
||||||
|
<insert id="save">
|
||||||
|
insert into product (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)
|
||||||
|
values (#{id}, #{name}, #{brandId}, #{category1Id}, #{category2Id}, #{category3Id}, #{unitName}, #{sliderUrls},
|
||||||
|
#{specValue}, #{status}, #{auditStatus}, #{auditMessage}, now(), now(), 0)
|
||||||
|
</insert>
|
||||||
|
|
||||||
<!-- 列表查询 -->
|
<!-- 列表查询 -->
|
||||||
<select id="findByPage" resultType="com.atguigu.spzx.model.entity.product.Product">
|
<select id="findByPage" resultType="com.atguigu.spzx.model.entity.product.Product">
|
||||||
select
|
select
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?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">
|
||||||
|
|
||||||
|
<!-- 保存数据 -->
|
||||||
|
<insert id="save" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into product_sku (id, sku_code, sku_name, product_id, thumb_img, sale_price, market_price, cost_price,
|
||||||
|
stock_num, sku_spec, weight, volume, status, sale_num, create_time, update_time,
|
||||||
|
is_deleted)
|
||||||
|
values (#{id}, #{skuCode}, #{skuName}, #{productId}, #{thumbImg}, #{salePrice}, #{marketPrice},
|
||||||
|
#{costPrice}, #{stockNum}, #{skuSpec}, #{weight}, #{volume}, #{status}, #{saleNum}, now(), now(), 0)
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
|
@ -3,63 +3,63 @@ package com.atguigu.spzx.model.entity.product;
|
||||||
import com.atguigu.spzx.model.entity.base.BaseEntity;
|
import com.atguigu.spzx.model.entity.base.BaseEntity;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
@Schema(description = "商品实体类")
|
@Schema(description = "商品实体类")
|
||||||
public class Product extends BaseEntity {
|
public class Product extends BaseEntity {
|
||||||
|
@Schema(description = "商品名称")
|
||||||
|
private String name; // 商品名称
|
||||||
|
|
||||||
@Schema(description = "商品名称")
|
@Schema(description = "品牌id")
|
||||||
private String name; // 商品名称
|
private Long brandId; // 品牌ID
|
||||||
|
|
||||||
@Schema(description = "品牌id")
|
@Schema(description = "一级分类id")
|
||||||
private Long brandId; // 品牌ID
|
private Long category1Id; // 一级分类id
|
||||||
|
|
||||||
@Schema(description = "一级分类id")
|
@Schema(description = "二级分类id")
|
||||||
private Long category1Id; // 一级分类id
|
private Long category2Id; // 二级分类id
|
||||||
|
|
||||||
@Schema(description = "二级分类id")
|
@Schema(description = "三级分类id")
|
||||||
private Long category2Id; // 二级分类id
|
private Long category3Id; // 三级分类id
|
||||||
|
|
||||||
@Schema(description = "三级分类id")
|
@Schema(description = "计量单位")
|
||||||
private Long category3Id; // 三级分类id
|
private String unitName; // 计量单位
|
||||||
|
|
||||||
@Schema(description = "计量单位")
|
@Schema(description = "轮播图url")
|
||||||
private String unitName; // 计量单位
|
private String sliderUrls; // 轮播图
|
||||||
|
|
||||||
@Schema(description = "轮播图url")
|
@Schema(description = "商品规格值json串")
|
||||||
private String sliderUrls; // 轮播图
|
private String specValue; // 商品规格值json串
|
||||||
|
|
||||||
@Schema(description = "商品规格值json串")
|
@Schema(description = "线上状态:0-初始值,1-上架,-1-自主下架")
|
||||||
private String specValue; // 商品规格值json串
|
private Integer status; // 线上状态:0-初始值,1-上架,-1-自主下架
|
||||||
|
|
||||||
@Schema(description = "线上状态:0-初始值,1-上架,-1-自主下架")
|
@Schema(description = "审核状态")
|
||||||
private Integer status; // 线上状态:0-初始值,1-上架,-1-自主下架
|
private Integer auditStatus; // 审核状态
|
||||||
|
|
||||||
@Schema(description = "审核状态")
|
@Schema(description = "审核信息")
|
||||||
private Integer auditStatus; // 审核状态
|
private String auditMessage; // 审核信息
|
||||||
|
|
||||||
@Schema(description = "审核信息")
|
// 扩展的属性,用来封装响应的数据
|
||||||
private String auditMessage; // 审核信息
|
@Schema(description = "品牌名称")
|
||||||
|
private String brandName; // 品牌
|
||||||
|
|
||||||
// 扩展的属性,用来封装响应的数据
|
@Schema(description = "一级分类名称")
|
||||||
@Schema(description = "品牌名称")
|
private String category1Name; // 一级分类
|
||||||
private String brandName; // 品牌
|
|
||||||
|
|
||||||
@Schema(description = "一级分类名称")
|
@Schema(description = "二级分类名称")
|
||||||
private String category1Name; // 一级分类
|
private String category2Name; // 二级分类
|
||||||
|
|
||||||
@Schema(description = "二级分类名称")
|
@Schema(description = "三级分类名称")
|
||||||
private String category2Name; // 二级分类
|
private String category3Name; // 三级分类
|
||||||
|
|
||||||
@Schema(description = "三级分类名称")
|
@Schema(description = "sku列表集合")
|
||||||
private String category3Name; // 三级分类
|
private List<ProductSku> productSkuList; // sku列表集合
|
||||||
|
|
||||||
@Schema(description = "sku列表集合")
|
|
||||||
private List<ProductSku> productSkuList; // sku列表集合
|
|
||||||
|
|
||||||
@Schema(description = "图片详情列表")
|
|
||||||
private String detailsImageUrls; // 图片详情列表
|
|
||||||
|
|
||||||
|
@Schema(description = "图片详情列表")
|
||||||
|
private String detailsImageUrls; // 图片详情列表
|
||||||
}
|
}
|
|
@ -5,49 +5,46 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Schema(description = "ProductSku")
|
@Schema(description = "ProductSku")
|
||||||
public class ProductSku extends BaseEntity {
|
public class ProductSku extends BaseEntity {
|
||||||
|
@Schema(description = "商品编号")
|
||||||
|
private String skuCode;
|
||||||
|
|
||||||
@Schema(description = "商品编号")
|
@Schema(description = "skuName")
|
||||||
private String skuCode;
|
private String skuName;
|
||||||
|
|
||||||
@Schema(description = "skuName")
|
@Schema(description = "商品ID")
|
||||||
private String skuName;
|
private Long productId;
|
||||||
|
|
||||||
@Schema(description = "商品ID")
|
@Schema(description = "缩略图路径")
|
||||||
private Long productId;
|
private String thumbImg;
|
||||||
|
|
||||||
@Schema(description = "缩略图路径")
|
@Schema(description = "售价")
|
||||||
private String thumbImg;
|
private BigDecimal salePrice;
|
||||||
|
|
||||||
@Schema(description = "售价")
|
@Schema(description = "市场价")
|
||||||
private BigDecimal salePrice;
|
private BigDecimal marketPrice;
|
||||||
|
|
||||||
@Schema(description = "市场价")
|
@Schema(description = "成本价")
|
||||||
private BigDecimal marketPrice;
|
private BigDecimal costPrice;
|
||||||
|
|
||||||
@Schema(description = "成本价")
|
@Schema(description = "库存数")
|
||||||
private BigDecimal costPrice;
|
private Integer stockNum;
|
||||||
|
|
||||||
@Schema(description = "库存数")
|
@Schema(description = "销量")
|
||||||
private Integer stockNum;
|
private Integer saleNum;
|
||||||
|
|
||||||
@Schema(description = "销量")
|
@Schema(description = "sku规格信息json")
|
||||||
private Integer saleNum;
|
private String skuSpec;
|
||||||
|
|
||||||
@Schema(description = "sku规格信息json")
|
@Schema(description = "重量")
|
||||||
private String skuSpec;
|
private String weight;
|
||||||
|
|
||||||
@Schema(description = "重量")
|
@Schema(description = "体积")
|
||||||
private String weight;
|
private String volume;
|
||||||
|
|
||||||
@Schema(description = "体积")
|
|
||||||
private String volume;
|
|
||||||
|
|
||||||
@Schema(description = "线上状态:0-初始值,1-上架,-1-自主下架")
|
|
||||||
private Integer status;
|
|
||||||
|
|
||||||
|
@Schema(description = "线上状态:0-初始值,1-上架,-1-自主下架")
|
||||||
|
private Integer status;
|
||||||
}
|
}
|
Loading…
Reference in New Issue