商品SKU功能优化

This commit is contained in:
macro
2020-02-29 16:35:39 +08:00
parent 765affaa27
commit a308c69968
19 changed files with 2629 additions and 3584 deletions

View File

@@ -1,5 +1,6 @@
package com.macro.mall.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.dao.*;
import com.macro.mall.dto.PmsProductParam;
@@ -8,7 +9,6 @@ import com.macro.mall.dto.PmsProductResult;
import com.macro.mall.mapper.*;
import com.macro.mall.model.*;
import com.macro.mall.service.PmsProductService;
import io.swagger.annotations.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,6 +21,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* 商品管理Service实现类
@@ -71,7 +72,7 @@ public class PmsProductServiceImpl implements PmsProductService {
PmsProduct product = productParam;
product.setId(null);
productMapper.insertSelective(product);
//根据促销类型设置价格:、阶梯价格、满减价格
//根据促销类型设置价格:会员价格、阶梯价格、满减价格
Long productId = product.getId();
//会员价格
relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), productId);
@@ -139,11 +140,7 @@ public class PmsProductServiceImpl implements PmsProductService {
productFullReductionMapper.deleteByExample(fullReductionExample);
relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), id);
//修改sku库存信息
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
skuStockExample.createCriteria().andProductIdEqualTo(id);
skuStockMapper.deleteByExample(skuStockExample);
handleSkuStockCode(productParam.getSkuStockList(),id);
relateAndInsertList(skuStockDao, productParam.getSkuStockList(), id);
handleUpdateSkuStockList(id, productParam);
//修改商品参数,添加自定义商品规格
PmsProductAttributeValueExample productAttributeValueExample = new PmsProductAttributeValueExample();
productAttributeValueExample.createCriteria().andProductIdEqualTo(id);
@@ -163,6 +160,49 @@ public class PmsProductServiceImpl implements PmsProductService {
return count;
}
private void handleUpdateSkuStockList(Long id, PmsProductParam productParam) {
//当前的sku信息
List<PmsSkuStock> currSkuList = productParam.getSkuStockList();
//当前没有sku直接删除
if(CollUtil.isEmpty(currSkuList)){
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
skuStockExample.createCriteria().andProductIdEqualTo(id);
skuStockMapper.deleteByExample(skuStockExample);
return;
}
//获取初始sku信息
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
skuStockExample.createCriteria().andProductIdEqualTo(id);
List<PmsSkuStock> oriStuList = skuStockMapper.selectByExample(skuStockExample);
//获取新增sku信息
List<PmsSkuStock> insertSkuList = currSkuList.stream().filter(item->item.getId()==null).collect(Collectors.toList());
//获取需要更新的sku信息
List<PmsSkuStock> updateSkuList = currSkuList.stream().filter(item->item.getId()!=null).collect(Collectors.toList());
List<Long> updateSkuIds = updateSkuList.stream().map(PmsSkuStock::getId).collect(Collectors.toList());
//获取需要删除的sku信息
List<PmsSkuStock> removeSkuList = oriStuList.stream().filter(item-> !updateSkuIds.contains(item.getId())).collect(Collectors.toList());
handleSkuStockCode(insertSkuList,id);
handleSkuStockCode(updateSkuList,id);
//新增sku
if(CollUtil.isNotEmpty(insertSkuList)){
relateAndInsertList(skuStockDao, insertSkuList, id);
}
//删除sku
if(CollUtil.isNotEmpty(removeSkuList)){
List<Long> removeSkuIds = removeSkuList.stream().map(PmsSkuStock::getId).collect(Collectors.toList());
PmsSkuStockExample removeExample = new PmsSkuStockExample();
removeExample.createCriteria().andIdIn(removeSkuIds);
skuStockMapper.deleteByExample(removeExample);
}
//修改sku
if(CollUtil.isNotEmpty(updateSkuList)){
for (PmsSkuStock pmsSkuStock : updateSkuList) {
skuStockMapper.updateByPrimaryKeySelective(pmsSkuStock);
}
}
}
@Override
public List<PmsProduct> list(PmsProductQueryParam productQueryParam, Integer pageSize, Integer pageNum) {
PageHelper.startPage(pageNum, pageSize);
@@ -260,70 +300,6 @@ public class PmsProductServiceImpl implements PmsProductService {
return productMapper.selectByExample(productExample);
}
/**
* @deprecated 旧版创建
*/
public int createOld(PmsProductParam productParam) {
int count;
//创建商品
PmsProduct product = productParam;
product.setId(null);
productMapper.insertSelective(product);
//根据促销类型设置价格:、阶梯价格、满减价格
Long productId = product.getId();
//会员价格
List<PmsMemberPrice> memberPriceList = productParam.getMemberPriceList();
if (!CollectionUtils.isEmpty(memberPriceList)) {
for (PmsMemberPrice pmsMemberPrice : memberPriceList) {
pmsMemberPrice.setId(null);
pmsMemberPrice.setProductId(productId);
}
memberPriceDao.insertList(memberPriceList);
}
//阶梯价格
List<PmsProductLadder> productLadderList = productParam.getProductLadderList();
if (!CollectionUtils.isEmpty(productLadderList)) {
for (PmsProductLadder productLadder : productLadderList) {
productLadder.setId(null);
productLadder.setProductId(productId);
}
productLadderDao.insertList(productLadderList);
}
//满减价格
List<PmsProductFullReduction> productFullReductionList = productParam.getProductFullReductionList();
if (!CollectionUtils.isEmpty(productFullReductionList)) {
for (PmsProductFullReduction productFullReduction : productFullReductionList) {
productFullReduction.setId(null);
productFullReduction.setProductId(productId);
}
productFullReductionDao.insertList(productFullReductionList);
}
//添加sku库存信息
List<PmsSkuStock> skuStockList = productParam.getSkuStockList();
if (!CollectionUtils.isEmpty(skuStockList)) {
for (PmsSkuStock skuStock : skuStockList) {
skuStock.setId(null);
skuStock.setProductId(productId);
}
skuStockDao.insertList(skuStockList);
}
//添加商品参数,添加自定义商品规格
List<PmsProductAttributeValue> productAttributeValueList = productParam.getProductAttributeValueList();
if (!CollectionUtils.isEmpty(productAttributeValueList)) {
for (PmsProductAttributeValue productAttributeValue : productAttributeValueList) {
productAttributeValue.setId(null);
productAttributeValue.setProductId(productId);
}
productAttributeValueDao.insertList(productAttributeValueList);
}
//关联专题
relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), productId);
//关联优选
relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), productId);
count = 1;
return count;
}
/**
* 建立和插入关系表操作
*

View File

@@ -74,9 +74,6 @@
oi.product_price item_product_price,
oi.product_quantity item_product_quantity,
oi.product_attr item_product_attr,
oi.sp1 item_sp1,
oi.sp2 item_sp2,
oi.sp3 item_sp3,
oh.id history_id,
oh.operate_man history_operate_man,
oh.create_time history_create_time,

View File

@@ -24,7 +24,7 @@
l.id ladder_id,l.product_id ladder_product_id,l.discount ladder_discount,l.count ladder_count,l.price ladder_price,
pf.id full_id,pf.product_id full_product_id,pf.full_price full_full_price,pf.reduce_price full_reduce_price,
m.id member_id,m.product_id member_product_id,m.member_level_id member_member_level_id,m.member_price member_member_price,m.member_level_name member_member_level_name,
s.id sku_id,s.product_id sku_product_id,s.price sku_price,s.low_stock sku_low_stock,s.pic sku_pic,s.sale sku_sale,s.sku_code sku_sku_code,s.sp1 sku_sp1,s.sp2 sku_sp2,s.sp3 sku_sp3,s.stock sku_stock,
s.id sku_id,s.product_id sku_product_id,s.price sku_price,s.low_stock sku_low_stock,s.pic sku_pic,s.sale sku_sale,s.sku_code sku_sku_code,s.stock sku_stock,s.sp_data sku_sp_data,
a.id attribute_id,a.product_id attribute_product_id,a.product_attribute_id attribute_product_attribute_id,a.value attribute_value
FROM pms_product p
LEFT JOIN pms_product_category pc on pc.id = p.product_category_id

View File

@@ -2,22 +2,20 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.macro.mall.dao.PmsSkuStockDao">
<insert id="insertList">
INSERT INTO pms_sku_stock (product_id, sku_code, price, stock, low_stock, sp1, sp2, sp3, pic, sale) VALUES
INSERT INTO pms_sku_stock (product_id, sku_code, price, stock, low_stock, pic, sale, sp_data) VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.productId,jdbcType=BIGINT},
#{item.skuCode,jdbcType=VARCHAR},
#{item.price,jdbcType=DECIMAL},
#{item.stock,jdbcType=INTEGER},
#{item.lowStock,jdbcType=INTEGER},
#{item.sp1,jdbcType=VARCHAR},
#{item.sp2,jdbcType=VARCHAR},
#{item.sp3,jdbcType=VARCHAR},
#{item.pic,jdbcType=VARCHAR},
#{item.sale,jdbcType=INTEGER})
#{item.sale,jdbcType=INTEGER},
#{item.spData,jdbcType=VARCHAR})
</foreach>
</insert>
<insert id="replaceList">
REPLACE INTO pms_sku_stock (id,product_id, sku_code, price, stock, low_stock, sp1, sp2, sp3, pic, sale) VALUES
REPLACE INTO pms_sku_stock (id,product_id, sku_code, price, stock, low_stock,pic, sale, sp_data) VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.id,jdbcType=BIGINT},
#{item.productId,jdbcType=BIGINT},
@@ -25,11 +23,9 @@
#{item.price,jdbcType=DECIMAL},
#{item.stock,jdbcType=INTEGER},
#{item.lowStock,jdbcType=INTEGER},
#{item.sp1,jdbcType=VARCHAR},
#{item.sp2,jdbcType=VARCHAR},
#{item.sp3,jdbcType=VARCHAR},
#{item.pic,jdbcType=VARCHAR},
#{item.sale,jdbcType=INTEGER})
#{item.sale,jdbcType=INTEGER},
#{item.spData,jdbcType=VARCHAR})
</foreach>
</insert>
</mapper>