package com.macro.mall.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.macro.mall.dao.*;
import com.macro.mall.dto.PmsProductParam;
import com.macro.mall.dto.PmsProductQueryParam;
import com.macro.mall.dto.PmsProductResult;
import com.macro.mall.dto.newdo.TruePmsProductParam;
import com.macro.mall.mapper.*;
import com.macro.mall.mapper.newdo.PmsProductMapper;
import com.macro.mall.model.*;
import com.macro.mall.model.newdo.TruePmsProduct;
import com.macro.mall.service.PmsProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* 商品管理Service实现类
* Created by macro on 2018/4/26.
*/
@Service
public class PmsProductServiceImpl implements PmsProductService {
private static final Logger LOGGER = LoggerFactory.getLogger(PmsProductServiceImpl.class);
@Autowired
private PmsProductMapper productMapper;
@Autowired
private PmsMemberPriceDao memberPriceDao;
@Autowired
private PmsMemberPriceMapper memberPriceMapper;
@Autowired
private PmsProductLadderDao productLadderDao;
@Autowired
private PmsProductLadderMapper productLadderMapper;
@Autowired
private PmsProductFullReductionDao productFullReductionDao;
@Autowired
private PmsProductFullReductionMapper productFullReductionMapper;
@Autowired
private PmsSkuStockDao skuStockDao;
@Autowired
private PmsSkuStockMapper skuStockMapper;
@Autowired
private PmsProductAttributeValueDao productAttributeValueDao;
@Autowired
private PmsProductAttributeValueMapper productAttributeValueMapper;
@Autowired
private CmsSubjectProductRelationDao subjectProductRelationDao;
@Autowired
private CmsSubjectProductRelationMapper subjectProductRelationMapper;
@Autowired
private CmsPrefrenceAreaProductRelationDao prefrenceAreaProductRelationDao;
@Autowired
private CmsPrefrenceAreaProductRelationMapper prefrenceAreaProductRelationMapper;
@Autowired
private PmsProductDao productDao;
@Autowired
private PmsProductVertifyRecordDao productVertifyRecordDao;
@Override
public int create(PmsProductParam productParam) {
int count;
//创建商品
PmsProduct product = productParam;
product.setId(null);
productMapper.insertSelective(product);
//根据促销类型设置价格:会员价格、阶梯价格、满减价格
Long productId = product.getId();
//会员价格
relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), productId);
//阶梯价格
relateAndInsertList(productLadderDao, productParam.getProductLadderList(), productId);
//满减价格
relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), productId);
//处理sku的编码
handleSkuStockCode(productParam.getSkuStockList(),productId);
//添加sku库存信息
relateAndInsertList(skuStockDao, productParam.getSkuStockList(), productId);
//添加商品参数,添加自定义商品规格
relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), productId);
//关联专题
relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), productId);
//关联优选
relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), productId);
count = 1;
return count;
}
@Override
public int truecreate(TruePmsProductParam productParam) {
int count;
//创建商品
TruePmsProduct product = productParam;
product.setId(null);
productMapper.trueInsertSelective(product);
return 1;
}
private void handleSkuStockCode(List<PmsSkuStock> skuStockList, Long productId) {
if(CollectionUtils.isEmpty(skuStockList))return;
for(int i=0;i<skuStockList.size();i++){
PmsSkuStock skuStock = skuStockList.get(i);
if(StrUtil.isEmpty(skuStock.getSkuCode())){
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
StringBuilder sb = new StringBuilder();
//日期
sb.append(sdf.format(new Date()));
//四位商品id
sb.append(String.format("%04d", productId));
//三位索引id
sb.append(String.format("%03d", i+1));
skuStock.setSkuCode(sb.toString());
}
}
}
@Override
public PmsProductResult getUpdateInfo(Long id) {
return productDao.getUpdateInfo(id);
}
@Override
public int update(Long id, PmsProductParam productParam) {
int count;
//更新商品信息
PmsProduct product = productParam;
product.setId(id);
productMapper.updateByPrimaryKeySelective(product);
//会员价格
PmsMemberPriceExample pmsMemberPriceExample = new PmsMemberPriceExample();
pmsMemberPriceExample.createCriteria().andProductIdEqualTo(id);
memberPriceMapper.deleteByExample(pmsMemberPriceExample);
relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), id);
//阶梯价格
PmsProductLadderExample ladderExample = new PmsProductLadderExample();
ladderExample.createCriteria().andProductIdEqualTo(id);
productLadderMapper.deleteByExample(ladderExample);
relateAndInsertList(productLadderDao, productParam.getProductLadderList(), id);
//满减价格
PmsProductFullReductionExample fullReductionExample = new PmsProductFullReductionExample();
fullReductionExample.createCriteria().andProductIdEqualTo(id);
productFullReductionMapper.deleteByExample(fullReductionExample);
relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), id);
//修改sku库存信息
handleUpdateSkuStockList(id, productParam);
//修改商品参数,添加自定义商品规格
PmsProductAttributeValueExample productAttributeValueExample = new PmsProductAttributeValueExample();
productAttributeValueExample.createCriteria().andProductIdEqualTo(id);
productAttributeValueMapper.deleteByExample(productAttributeValueExample);
relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), id);
//关联专题
CmsSubjectProductRelationExample subjectProductRelationExample = new CmsSubjectProductRelationExample();
subjectProductRelationExample.createCriteria().andProductIdEqualTo(id);
subjectProductRelationMapper.deleteByExample(subjectProductRelationExample);
relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), id);
//关联优选
CmsPrefrenceAreaProductRelationExample prefrenceAreaExample = new CmsPrefrenceAreaProductRelationExample();
prefrenceAreaExample.createCriteria().andProductIdEqualTo(id);
prefrenceAreaProductRelationMapper.deleteByExample(prefrenceAreaExample);
relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), id);
count = 1;
return count;
}
private void handleUpdateSkuStockList(Long id, PmsProductParam productParam) {
//当前的sku信息
List<PmsSkuStock> currSkuList = productParam.getSkuStockList();
//当前没有sku直接删除
if(CollUtil.isEmpty
四两面
- 粉丝: 52
- 资源: 3
最新资源
- C#ASP.NET幼儿园管理系统源码数据库 SQL2008源码类型 WebForm
- 【重磅,更新!】空间杜宾模型和检验代码+结果解释(2024版)
- unity类似于QQ截图功能
- 虚拟机中安装MAC黑苹果系统需要的解锁软件
- 2草药信息增加(头歌)(1).cpp
- 基于matlab实现LQR+PID车辆横纵向控制算法实现(自动驾驶控制算法)+项目源码+模型+文档说明+代码注释
- 【老生谈算法】matlab实现机器视觉硬币检测与计数系统研究
- winform - GDI 绘制三万个方块并实时刷新.zip,某个点位是否焊接完毕,焊接完了就由红变蓝色实时刷新
- C#星辰物料采购仓储系统源码数据库 SQL2008源码类型 WebForm
- 基于MATLAB车牌识别系统实现系统【GUI带界面】.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈