|
@@ -2,6 +2,8 @@ package com.caimei.module.product.service.impl;
|
|
|
|
|
|
import com.caimei.module.base.entity.bo.PageVo;
|
|
|
import com.caimei.module.base.entity.po.SeconHandProduct;
|
|
|
+import com.caimei.module.base.entity.po.Smalltype;
|
|
|
+import com.caimei.module.base.entity.po.Tinytype;
|
|
|
import com.caimei.module.base.entity.vo.*;
|
|
|
import com.caimei.module.product.dao.ProductModuleDao;
|
|
|
import com.caimei.module.product.service.ProductModuleService;
|
|
@@ -15,7 +17,9 @@ import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -58,6 +62,30 @@ public class ProductModuleServiceImpl implements ProductModuleService {
|
|
|
return bigTypeList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据一级分类ID获取二三级分类
|
|
|
+ * bigTypeID 一级分类ID
|
|
|
+ * source 请求来源:www,crm
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<SmalltypeVo> getBigTypeClassify(String domain, Integer bigTypeID, String source) {
|
|
|
+ List<SmalltypeVo> smallTypeList = productModuleDao.getSmallType(bigTypeID,source);
|
|
|
+ for (SmalltypeVo smallType : smallTypeList) {
|
|
|
+ String caiMeiImage = ProductUtils.getImageURL("caiMeiImage", null, 0, domain);
|
|
|
+ smallType.setWwwIcon(StringUtils.isEmpty(smallType.getWwwIcon())?caiMeiImage:smallType.getWwwIcon());
|
|
|
+ smallType.setCrmIcon(StringUtils.isEmpty(smallType.getCrmIcon())?caiMeiImage:smallType.getCrmIcon());
|
|
|
+ List<TinytypeVo> tinytypeList = productModuleDao.getTinytype(smallType.getSmallTypeID(), source);
|
|
|
+ if (!CollectionUtils.isEmpty(tinytypeList)) {
|
|
|
+ for (TinytypeVo tinyType : tinytypeList) {
|
|
|
+ tinyType.setWwwIcon(StringUtils.isEmpty(tinyType.getWwwIcon())?caiMeiImage:tinyType.getWwwIcon());
|
|
|
+ tinyType.setCrmIcon(StringUtils.isEmpty(tinyType.getCrmIcon())?caiMeiImage:tinyType.getCrmIcon());
|
|
|
+ }
|
|
|
+ smallType.setTinytypeList(tinytypeList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return smallTypeList;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据一级/二级/三级分类获取商品
|
|
|
*
|
|
@@ -67,13 +95,51 @@ public class ProductModuleServiceImpl implements ProductModuleService {
|
|
|
* @param pageSize
|
|
|
*/
|
|
|
@Override
|
|
|
- public PageVo<ProductVo> getProductsByTypeId(Integer bigTypeID, Integer smallTypeID, Integer tinyTypeID, Integer sortType, Integer pageNum, Integer pageSize) {
|
|
|
+ public PageVo<ProductVo> getProductsByTypeId(Integer bigTypeID, Integer smallTypeID, Integer tinyTypeID, Integer sortType, String source, Integer pageNum, Integer pageSize) {
|
|
|
// sortType (3:价格升序, 4:价格降序, 7:人气, 8:销量)
|
|
|
pageNum = null != pageNum ? pageNum : 1;
|
|
|
pageSize = null != pageSize ? pageSize : 10;
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
|
sortType = null != sortType ? sortType : 8;
|
|
|
- List<ProductVo> productList = productModuleDao.getProductsByTypeId(bigTypeID, smallTypeID, tinyTypeID, sortType);
|
|
|
+ List<Integer> bigTypeIDList = new ArrayList<>();
|
|
|
+ List<Integer> smallTypeIDList = new ArrayList<>();
|
|
|
+ List<Integer> tinyTypeIDList = new ArrayList<>();
|
|
|
+ if (bigTypeID != null) {
|
|
|
+ bigTypeIDList.add(bigTypeID);
|
|
|
+ }
|
|
|
+ if (smallTypeID != null) {
|
|
|
+ smallTypeIDList.add(smallTypeID);
|
|
|
+ }
|
|
|
+ if (tinyTypeID != null) {
|
|
|
+ tinyTypeIDList.add(tinyTypeID);
|
|
|
+ }
|
|
|
+ if (tinyTypeIDList.size() > 0) {
|
|
|
+ bigTypeIDList.clear();
|
|
|
+ smallTypeIDList.clear();
|
|
|
+ } else if (smallTypeIDList.size() > 0) {
|
|
|
+ bigTypeIDList.clear();
|
|
|
+ }
|
|
|
+ //当二级和三级分类id列表都为空时,根据一级分类id获取二级分类id列表
|
|
|
+ if (smallTypeIDList.size() == 0 && tinyTypeIDList.size() == 0) {
|
|
|
+ List<SmalltypeVo> smalltypeVoList = productModuleDao.getSmallType(bigTypeID, source);
|
|
|
+ if (smalltypeVoList.size() > 0) {
|
|
|
+ bigTypeIDList.clear();
|
|
|
+ smallTypeIDList.addAll(smalltypeVoList.stream().map(Smalltype::getSmallTypeID).collect(Collectors.toList())) ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //当二级分类id列表不为空且三级分类id列表为空时,获取三级分类id列表
|
|
|
+ if (smallTypeIDList.size()>0 && tinyTypeIDList.size() == 0) {
|
|
|
+ Iterator<Integer> iterator = smallTypeIDList.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ Integer smallId = iterator.next();
|
|
|
+ List<TinytypeVo> tinytypeVoList = productModuleDao.getTinytype(smallId, source);
|
|
|
+ if (tinytypeVoList.size() > 0) {
|
|
|
+ iterator.remove();
|
|
|
+ tinyTypeIDList.addAll(tinytypeVoList.stream().map(Tinytype::getTinyTypeID).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<ProductVo> productList = productModuleDao.getProductsByTypeId(bigTypeIDList, smallTypeIDList, tinyTypeIDList, sortType);
|
|
|
return new PageVo<>(productList);
|
|
|
}
|
|
|
|