parent
b4b6690a09
commit
99cd87b917
@ -0,0 +1,60 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.macro.mall.dao.PmsProductAttributeCategoryDao;
|
||||
import com.macro.mall.dto.PmsProductAttributeCategoryItem;
|
||||
import com.macro.mall.mapper.PmsProductAttributeCategoryMapper;
|
||||
import com.macro.mall.model.PmsProductAttributeCategory;
|
||||
import com.macro.mall.model.PmsProductAttributeCategoryExample;
|
||||
import com.macro.mall.service.PmsProductAttributeCategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* PmsProductAttributeCategoryServiceʵÏÖÀà
|
||||
*/
|
||||
@Service
|
||||
public class PmsProductAttributeCategoryServiceImpl implements PmsProductAttributeCategoryService {
|
||||
@Autowired
|
||||
private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
|
||||
@Autowired
|
||||
private PmsProductAttributeCategoryDao productAttributeCategoryDao;
|
||||
|
||||
@Override
|
||||
public int create(String name) {
|
||||
PmsProductAttributeCategory productAttributeCategory = new PmsProductAttributeCategory();
|
||||
productAttributeCategory.setName(name);
|
||||
return productAttributeCategoryMapper.insertSelective(productAttributeCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Long id, String name) {
|
||||
PmsProductAttributeCategory productAttributeCategory = new PmsProductAttributeCategory();
|
||||
productAttributeCategory.setName(name);
|
||||
productAttributeCategory.setId(id);
|
||||
return productAttributeCategoryMapper.updateByPrimaryKeySelective(productAttributeCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
return productAttributeCategoryMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PmsProductAttributeCategory getItem(Long id) {
|
||||
return productAttributeCategoryMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PmsProductAttributeCategory> getList(Integer pageSize, Integer pageNum) {
|
||||
PageHelper.startPage(pageNum,pageSize);
|
||||
return productAttributeCategoryMapper.selectByExample(new PmsProductAttributeCategoryExample());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PmsProductAttributeCategoryItem> getListWithAttr() {
|
||||
return productAttributeCategoryDao.getListWithAttr();
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.macro.mall.dao.PmsProductAttributeDao;
|
||||
import com.macro.mall.dto.PmsProductAttributeParam;
|
||||
import com.macro.mall.dto.ProductAttrInfo;
|
||||
import com.macro.mall.mapper.PmsProductAttributeCategoryMapper;
|
||||
import com.macro.mall.mapper.PmsProductAttributeMapper;
|
||||
import com.macro.mall.model.PmsProductAttribute;
|
||||
import com.macro.mall.model.PmsProductAttributeCategory;
|
||||
import com.macro.mall.model.PmsProductAttributeExample;
|
||||
import com.macro.mall.service.PmsProductAttributeService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品属性Service实现类
|
||||
*/
|
||||
@Service
|
||||
public class PmsProductAttributeServiceImpl implements PmsProductAttributeService {
|
||||
@Autowired
|
||||
private PmsProductAttributeMapper productAttributeMapper;
|
||||
@Autowired
|
||||
private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
|
||||
@Autowired
|
||||
private PmsProductAttributeDao productAttributeDao;
|
||||
|
||||
@Override
|
||||
public List<PmsProductAttribute> getList(Long cid, Integer type, Integer pageSize, Integer pageNum) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
PmsProductAttributeExample example = new PmsProductAttributeExample();
|
||||
example.setOrderByClause("sort desc");
|
||||
example.createCriteria().andProductAttributeCategoryIdEqualTo(cid).andTypeEqualTo(type);
|
||||
return productAttributeMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int create(PmsProductAttributeParam pmsProductAttributeParam) {
|
||||
PmsProductAttribute pmsProductAttribute = new PmsProductAttribute();
|
||||
BeanUtils.copyProperties(pmsProductAttributeParam, pmsProductAttribute);
|
||||
int count = productAttributeMapper.insertSelective(pmsProductAttribute);
|
||||
//新增商品属性以后需要更新商品属性分类数量
|
||||
PmsProductAttributeCategory pmsProductAttributeCategory = productAttributeCategoryMapper.selectByPrimaryKey(pmsProductAttribute.getProductAttributeCategoryId());
|
||||
if(pmsProductAttribute.getType()==0){
|
||||
pmsProductAttributeCategory.setAttributeCount(pmsProductAttributeCategory.getAttributeCount()+1);
|
||||
}else if(pmsProductAttribute.getType()==1){
|
||||
pmsProductAttributeCategory.setParamCount(pmsProductAttributeCategory.getParamCount()+1);
|
||||
}
|
||||
productAttributeCategoryMapper.updateByPrimaryKey(pmsProductAttributeCategory);
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Long id, PmsProductAttributeParam productAttributeParam) {
|
||||
PmsProductAttribute pmsProductAttribute = new PmsProductAttribute();
|
||||
pmsProductAttribute.setId(id);
|
||||
BeanUtils.copyProperties(productAttributeParam, pmsProductAttribute);
|
||||
return productAttributeMapper.updateByPrimaryKeySelective(pmsProductAttribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PmsProductAttribute getItem(Long id) {
|
||||
return productAttributeMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(List<Long> ids) {
|
||||
//获取分类
|
||||
PmsProductAttribute pmsProductAttribute = productAttributeMapper.selectByPrimaryKey(ids.get(0));
|
||||
Integer type = pmsProductAttribute.getType();
|
||||
PmsProductAttributeCategory pmsProductAttributeCategory = productAttributeCategoryMapper.selectByPrimaryKey(pmsProductAttribute.getProductAttributeCategoryId());
|
||||
PmsProductAttributeExample example = new PmsProductAttributeExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
int count = productAttributeMapper.deleteByExample(example);
|
||||
//删除完成后修改数量
|
||||
if(type==0){
|
||||
if(pmsProductAttributeCategory.getAttributeCount()>=count){
|
||||
pmsProductAttributeCategory.setAttributeCount(pmsProductAttributeCategory.getAttributeCount()-count);
|
||||
}else{
|
||||
pmsProductAttributeCategory.setAttributeCount(0);
|
||||
}
|
||||
}else if(type==1){
|
||||
if(pmsProductAttributeCategory.getParamCount()>=count){
|
||||
pmsProductAttributeCategory.setParamCount(pmsProductAttributeCategory.getParamCount()-count);
|
||||
}else{
|
||||
pmsProductAttributeCategory.setParamCount(0);
|
||||
}
|
||||
}
|
||||
productAttributeCategoryMapper.updateByPrimaryKey(pmsProductAttributeCategory);
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductAttrInfo> getProductAttrInfo(Long productCategoryId) {
|
||||
return productAttributeDao.getProductAttrInfo(productCategoryId);
|
||||
}
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.macro.mall.dao.PmsProductCategoryAttributeRelationDao;
|
||||
import com.macro.mall.dao.PmsProductCategoryDao;
|
||||
import com.macro.mall.dto.PmsProductCategoryParam;
|
||||
import com.macro.mall.dto.PmsProductCategoryWithChildrenItem;
|
||||
import com.macro.mall.mapper.PmsProductCategoryAttributeRelationMapper;
|
||||
import com.macro.mall.mapper.PmsProductCategoryMapper;
|
||||
import com.macro.mall.mapper.PmsProductMapper;
|
||||
import com.macro.mall.model.*;
|
||||
import com.macro.mall.service.PmsProductCategoryService;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* PmsProductCategoryService实现类
|
||||
*/
|
||||
@Service
|
||||
public class PmsProductCategoryServiceImpl implements PmsProductCategoryService {
|
||||
@Autowired
|
||||
private PmsProductCategoryMapper productCategoryMapper;
|
||||
@Autowired
|
||||
private PmsProductMapper productMapper;
|
||||
@Autowired
|
||||
private PmsProductCategoryAttributeRelationDao productCategoryAttributeRelationDao;
|
||||
@Autowired
|
||||
private PmsProductCategoryAttributeRelationMapper productCategoryAttributeRelationMapper;
|
||||
@Autowired
|
||||
private PmsProductCategoryDao productCategoryDao;
|
||||
@Override
|
||||
public int create(PmsProductCategoryParam pmsProductCategoryParam) {
|
||||
PmsProductCategory productCategory = new PmsProductCategory();
|
||||
productCategory.setProductCount(0);
|
||||
BeanUtils.copyProperties(pmsProductCategoryParam, productCategory);
|
||||
//没有父分类时为一级分类
|
||||
setCategoryLevel(productCategory);//设置分类等级
|
||||
int count = productCategoryMapper.insertSelective(productCategory);
|
||||
//创建筛选属性关联
|
||||
List<Long> productAttributeIdList = pmsProductCategoryParam.getProductAttributeIdList();
|
||||
if(!CollectionUtils.isEmpty(productAttributeIdList)){
|
||||
insertRelationList(productCategory.getId(), productAttributeIdList);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入商品分类与筛选属性关系表
|
||||
* @param productCategoryId 商品分类id
|
||||
* @param productAttributeIdList 相关商品筛选属性id集合
|
||||
*/
|
||||
private void insertRelationList(Long productCategoryId, List<Long> productAttributeIdList) {
|
||||
List<PmsProductCategoryAttributeRelation> relationList = new ArrayList<>();
|
||||
for (Long productAttrId : productAttributeIdList) {
|
||||
PmsProductCategoryAttributeRelation relation = new PmsProductCategoryAttributeRelation();
|
||||
relation.setProductAttributeId(productAttrId);
|
||||
relation.setProductCategoryId(productCategoryId);
|
||||
relationList.add(relation);
|
||||
}
|
||||
productCategoryAttributeRelationDao.insertList(relationList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Long id, PmsProductCategoryParam pmsProductCategoryParam) {
|
||||
PmsProductCategory productCategory = new PmsProductCategory();
|
||||
productCategory.setId(id);
|
||||
BeanUtils.copyProperties(pmsProductCategoryParam, productCategory);
|
||||
setCategoryLevel(productCategory);
|
||||
//更新商品分类时要更新商品中的名称
|
||||
PmsProduct product = new PmsProduct();
|
||||
product.setProductCategoryName(productCategory.getName());
|
||||
PmsProductExample example = new PmsProductExample();
|
||||
example.createCriteria().andProductCategoryIdEqualTo(id);
|
||||
productMapper.updateByExampleSelective(product,example);
|
||||
//同时更新筛选属性的信息
|
||||
if(!CollectionUtils.isEmpty(pmsProductCategoryParam.getProductAttributeIdList())){
|
||||
PmsProductCategoryAttributeRelationExample relationExample = new PmsProductCategoryAttributeRelationExample();
|
||||
relationExample.createCriteria().andProductCategoryIdEqualTo(id);
|
||||
productCategoryAttributeRelationMapper.deleteByExample(relationExample);
|
||||
insertRelationList(id,pmsProductCategoryParam.getProductAttributeIdList());
|
||||
}else{
|
||||
PmsProductCategoryAttributeRelationExample relationExample = new PmsProductCategoryAttributeRelationExample();
|
||||
relationExample.createCriteria().andProductCategoryIdEqualTo(id);
|
||||
productCategoryAttributeRelationMapper.deleteByExample(relationExample);
|
||||
}
|
||||
return productCategoryMapper.updateByPrimaryKeySelective(productCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PmsProductCategory> getList(Long parentId, Integer pageSize, Integer pageNum) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
PmsProductCategoryExample example = new PmsProductCategoryExample();
|
||||
example.setOrderByClause("sort desc");
|
||||
example.createCriteria().andParentIdEqualTo(parentId);
|
||||
return productCategoryMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
return productCategoryMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PmsProductCategory getItem(Long id) {
|
||||
return productCategoryMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateNavStatus(List<Long> ids, Integer navStatus) {
|
||||
PmsProductCategory productCategory = new PmsProductCategory();
|
||||
productCategory.setNavStatus(navStatus);
|
||||
PmsProductCategoryExample example = new PmsProductCategoryExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
return productCategoryMapper.updateByExampleSelective(productCategory, example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateShowStatus(List<Long> ids, Integer showStatus) {
|
||||
PmsProductCategory productCategory = new PmsProductCategory();
|
||||
productCategory.setShowStatus(showStatus);
|
||||
PmsProductCategoryExample example = new PmsProductCategoryExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
return productCategoryMapper.updateByExampleSelective(productCategory, example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PmsProductCategoryWithChildrenItem> listWithChildren() {
|
||||
return productCategoryDao.listWithChildren();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类的parentId设置分类的level
|
||||
*/
|
||||
private void setCategoryLevel(PmsProductCategory productCategory) {
|
||||
//没有父分类时为一级分类
|
||||
if (productCategory.getParentId() == 0) {
|
||||
productCategory.setLevel(0);
|
||||
} else {
|
||||
//有父分类时选择根据父分类level设置
|
||||
PmsProductCategory parentCategory = productCategoryMapper.selectByPrimaryKey(productCategory.getParentId());
|
||||
if (parentCategory != null) {
|
||||
productCategory.setLevel(parentCategory.getLevel() + 1);
|
||||
} else {
|
||||
productCategory.setLevel(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,350 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
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.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;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品管理Service实现类
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
|
||||
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(StringUtils.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库存信息
|
||||
PmsSkuStockExample skuStockExample = new PmsSkuStockExample();
|
||||
skuStockExample.createCriteria().andProductIdEqualTo(id);
|
||||
skuStockMapper.deleteByExample(skuStockExample);
|
||||
handleSkuStockCode(productParam.getSkuStockList(),id);
|
||||
relateAndInsertList(skuStockDao, productParam.getSkuStockList(), id);
|
||||
//修改商品参数,添加自定义商品规格
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PmsProduct> list(PmsProductQueryParam productQueryParam, Integer pageSize, Integer pageNum) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
PmsProductExample productExample = new PmsProductExample();
|
||||
PmsProductExample.Criteria criteria = productExample.createCriteria();
|
||||
criteria.andDeleteStatusEqualTo(0);
|
||||
if (productQueryParam.getPublishStatus() != null) {
|
||||
criteria.andPublishStatusEqualTo(productQueryParam.getPublishStatus());
|
||||
}
|
||||
if (productQueryParam.getVerifyStatus() != null) {
|
||||
criteria.andVerifyStatusEqualTo(productQueryParam.getVerifyStatus());
|
||||
}
|
||||
if (!StringUtils.isEmpty(productQueryParam.getKeyword())) {
|
||||
criteria.andNameLike("%" + productQueryParam.getKeyword() + "%");
|
||||
}
|
||||
if (!StringUtils.isEmpty(productQueryParam.getProductSn())) {
|
||||
criteria.andProductSnEqualTo(productQueryParam.getProductSn());
|
||||
}
|
||||
if (productQueryParam.getBrandId() != null) {
|
||||
criteria.andBrandIdEqualTo(productQueryParam.getBrandId());
|
||||
}
|
||||
if (productQueryParam.getProductCategoryId() != null) {
|
||||
criteria.andProductCategoryIdEqualTo(productQueryParam.getProductCategoryId());
|
||||
}
|
||||
return productMapper.selectByExample(productExample);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateVerifyStatus(List<Long> ids, Integer verifyStatus, String detail) {
|
||||
PmsProduct product = new PmsProduct();
|
||||
product.setVerifyStatus(verifyStatus);
|
||||
PmsProductExample example = new PmsProductExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
List<PmsProductVertifyRecord> list = new ArrayList<>();
|
||||
int count = productMapper.updateByExampleSelective(product, example);
|
||||
//修改完审核状态后插入审核记录
|
||||
for (Long id : ids) {
|
||||
PmsProductVertifyRecord record = new PmsProductVertifyRecord();
|
||||
record.setProductId(id);
|
||||
record.setCreateTime(new Date());
|
||||
record.setDetail(detail);
|
||||
record.setStatus(verifyStatus);
|
||||
record.setVertifyMan("test");
|
||||
list.add(record);
|
||||
}
|
||||
productVertifyRecordDao.insertList(list);
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updatePublishStatus(List<Long> ids, Integer publishStatus) {
|
||||
PmsProduct record = new PmsProduct();
|
||||
record.setPublishStatus(publishStatus);
|
||||
PmsProductExample example = new PmsProductExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
return productMapper.updateByExampleSelective(record, example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateRecommendStatus(List<Long> ids, Integer recommendStatus) {
|
||||
PmsProduct record = new PmsProduct();
|
||||
record.setRecommandStatus(recommendStatus);
|
||||
PmsProductExample example = new PmsProductExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
return productMapper.updateByExampleSelective(record, example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateNewStatus(List<Long> ids, Integer newStatus) {
|
||||
PmsProduct record = new PmsProduct();
|
||||
record.setNewStatus(newStatus);
|
||||
PmsProductExample example = new PmsProductExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
return productMapper.updateByExampleSelective(record, example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateDeleteStatus(List<Long> ids, Integer deleteStatus) {
|
||||
PmsProduct record = new PmsProduct();
|
||||
record.setDeleteStatus(deleteStatus);
|
||||
PmsProductExample example = new PmsProductExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
return productMapper.updateByExampleSelective(record, example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PmsProduct> list(String keyword) {
|
||||
PmsProductExample productExample = new PmsProductExample();
|
||||
PmsProductExample.Criteria criteria = productExample.createCriteria();
|
||||
criteria.andDeleteStatusEqualTo(0);
|
||||
if(!StringUtils.isEmpty(keyword)){
|
||||
criteria.andNameLike("%" + keyword + "%");
|
||||
productExample.or().andDeleteStatusEqualTo(0).andProductSnLike("%" + keyword + "%");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 建立和插入关系表操作
|
||||
*
|
||||
* @param dao 可以操作的dao
|
||||
* @param dataList 要插入的数据
|
||||
* @param productId 建立关系的id
|
||||
*/
|
||||
private void relateAndInsertList(Object dao, List dataList, Long productId) {
|
||||
try {
|
||||
if (CollectionUtils.isEmpty(dataList)) return;
|
||||
for (Object item : dataList) {
|
||||
Method setId = item.getClass().getMethod("setId", Long.class);
|
||||
setId.invoke(item, (Long) null);
|
||||
Method setProductId = item.getClass().getMethod("setProductId", Long.class);
|
||||
setProductId.invoke(item, productId);
|
||||
}
|
||||
Method insertList = dao.getClass().getMethod("insertList", List.class);
|
||||
insertList.invoke(dao, dataList);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("创建产品出错:{}", e.getMessage());
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue