From 99cd87b9177f7766119161d1588565a8e71aa061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=9A=93=E9=9B=AF?= <18868469283@qq.com> Date: Sun, 13 Jan 2019 14:56:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E6=9C=8D=E5=8A=A1=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...msProductAttributeCategoryServiceImpl.java | 60 +++ .../impl/PmsProductAttributeServiceImpl.java | 100 +++++ .../impl/PmsProductCategoryServiceImpl.java | 153 ++++++++ .../service/impl/PmsProductServiceImpl.java | 350 ++++++++++++++++++ 4 files changed, 663 insertions(+) create mode 100644 代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductAttributeCategoryServiceImpl.java create mode 100644 代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductAttributeServiceImpl.java create mode 100644 代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductCategoryServiceImpl.java create mode 100644 代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductServiceImpl.java diff --git a/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductAttributeCategoryServiceImpl.java b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductAttributeCategoryServiceImpl.java new file mode 100644 index 0000000..138a869 --- /dev/null +++ b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductAttributeCategoryServiceImpl.java @@ -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 getList(Integer pageSize, Integer pageNum) { + PageHelper.startPage(pageNum,pageSize); + return productAttributeCategoryMapper.selectByExample(new PmsProductAttributeCategoryExample()); + } + + @Override + public List getListWithAttr() { + return productAttributeCategoryDao.getListWithAttr(); + } +} \ No newline at end of file diff --git a/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductAttributeServiceImpl.java b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductAttributeServiceImpl.java new file mode 100644 index 0000000..cb95d16 --- /dev/null +++ b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductAttributeServiceImpl.java @@ -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 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 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 getProductAttrInfo(Long productCategoryId) { + return productAttributeDao.getProductAttrInfo(productCategoryId); + } +} diff --git a/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductCategoryServiceImpl.java b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductCategoryServiceImpl.java new file mode 100644 index 0000000..dc231ef --- /dev/null +++ b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductCategoryServiceImpl.java @@ -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 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 productAttributeIdList) { + List 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 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 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 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 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); + } + } + } +} \ No newline at end of file diff --git a/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductServiceImpl.java b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductServiceImpl.java new file mode 100644 index 0000000..2488301 --- /dev/null +++ b/代码库/mall-admin/src/main/java/com/sock/mall/service/impl/PmsProductServiceImpl.java @@ -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 skuStockList, Long productId) { + if(CollectionUtils.isEmpty(skuStockList))return; + for(int i=0;i 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 ids, Integer verifyStatus, String detail) { + PmsProduct product = new PmsProduct(); + product.setVerifyStatus(verifyStatus); + PmsProductExample example = new PmsProductExample(); + example.createCriteria().andIdIn(ids); + List 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 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 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 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 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 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 memberPriceList = productParam.getMemberPriceList(); + if (!CollectionUtils.isEmpty(memberPriceList)) { + for (PmsMemberPrice pmsMemberPrice : memberPriceList) { + pmsMemberPrice.setId(null); + pmsMemberPrice.setProductId(productId); + } + memberPriceDao.insertList(memberPriceList); + } + //ݼ۸ + List productLadderList = productParam.getProductLadderList(); + if (!CollectionUtils.isEmpty(productLadderList)) { + for (PmsProductLadder productLadder : productLadderList) { + productLadder.setId(null); + productLadder.setProductId(productId); + } + productLadderDao.insertList(productLadderList); + } + //۸ + List productFullReductionList = productParam.getProductFullReductionList(); + if (!CollectionUtils.isEmpty(productFullReductionList)) { + for (PmsProductFullReduction productFullReduction : productFullReductionList) { + productFullReduction.setId(null); + productFullReduction.setProductId(productId); + } + productFullReductionDao.insertList(productFullReductionList); + } + //skuϢ + List skuStockList = productParam.getSkuStockList(); + if (!CollectionUtils.isEmpty(skuStockList)) { + for (PmsSkuStock skuStock : skuStockList) { + skuStock.setId(null); + skuStock.setProductId(productId); + } + skuStockDao.insertList(skuStockList); + } + //Ʒ,ԶƷ + List 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()); + } + } + +}