Преглед изворни кода

分类列表,产品/仪器模块商品1

Aslee пре 4 година
родитељ
комит
eaee1d15d9

+ 1 - 1
product/src/main/java/com/caimei/module/product/dao/ProductModuleDao.java

@@ -17,7 +17,7 @@ import java.util.List;
  */
 @Mapper
 public interface ProductModuleDao {
-    List<ProductVo> getProductsByTypeId(@Param("bigTypeID") Integer bigTypeID, @Param("smallTypeID") Integer smallTypeID, @Param("tinyTypeID") Integer tinyTypeID, @Param("sortType") Integer sortType);
+    List<ProductVo> getProductsByTypeId(@Param("bigTypeIDList") List<Integer> bigTypeIDList, @Param("smallTypeIDList") List<Integer> smallTypeIDList, @Param("tinyTypeIDList") List<Integer> tinyTypeIDList, @Param("sortType") Integer sortType);
 
     List<SearchHistoryVo> getSearchHistoryList(Integer userId);
 

+ 6 - 1
product/src/main/java/com/caimei/module/product/service/ProductModuleService.java

@@ -18,10 +18,15 @@ public interface ProductModuleService {
      */
     List<BigtypeVo> getClassify(String domain, String typeSort, String source);
 
+    /**
+     * 根据一级分类ID获取二三级分类
+     */
+    List<SmalltypeVo> getBigTypeClassify(String domain, Integer bigTypeID, String source);
+
     /**
      * 根据一级/二级/三级分类获取商品
      */
-    PageVo<ProductVo> getProductsByTypeId(Integer bigTypeID, Integer smallTypeID, Integer tinyTypeID, Integer sortType, Integer pageNum, Integer pageSize);
+    PageVo<ProductVo> getProductsByTypeId(Integer bigTypeID, Integer smallTypeID, Integer tinyTypeID, Integer sortType, String source, Integer pageNum, Integer pageSize);
 
     /**
      * 根据关键词获取商品

+ 68 - 2
product/src/main/java/com/caimei/module/product/service/impl/ProductModuleServiceImpl.java

@@ -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);
     }
 

+ 30 - 15
product/src/main/resources/com-caimei-module-product/ProductModuleMapper.xml

@@ -99,29 +99,44 @@
         select
         <include refid="Product_Column_List" />
         from product
-        where validFlag = 2
+        <trim prefix="WHERE (" suffix=")" prefixOverrides="AND |OR ">
+            <if test="bigTypeIDList != null and bigTypeIDList.size() > 0">
+                OR bigTypeID in
+                <foreach collection="bigTypeIDList" open="(" separator="," close=")" item="bigTypeID">
+                    #{bigTypeID}
+                </foreach>
+            </if>
+            <if test="smallTypeIDList != null and smallTypeIDList.size() > 0">
+                OR smallTypeID in
+                <foreach collection="smallTypeIDList" open="(" separator="," close=")" item="smallTypeID">
+                    #{smallTypeID}
+                </foreach>
+            </if>
+            <if test="tinyTypeIDList != null and tinyTypeIDList.size() > 0">
+                OR tinyTypeID in
+                <foreach collection="tinyTypeIDList" open="(" separator="," close=")" item="tinyTypeID">
+                    #{tinyTypeID}
+                </foreach>
+            </if>
+        </trim>
+        and validFlag = 2
         <choose>
-            <when test="tinyTypeID != null and tinyTypeID != ''">
-                and tinyTypeID = #{tinyTypeID,jdbcType=INTEGER}
-            </when>
-            <when test="smallTypeID != null and smallTypeID != ''">
-                and smallTypeID = #{smallTypeID,jdbcType=INTEGER}
+            <when test="sortType == 1">
+                order by price1 asc
             </when>
-            <when test="bigTypeID != null and bigTypeID != ''">
-                and bigTypeID = #{bigTypeID,jdbcType=INTEGER}
+            <when test="sortType == 2">
+                order by price1 desc
             </when>
-        </choose>
-        <choose>
             <when test="sortType == 3">
-                order by price1 asc
+                order by favoriteTimes asc
             </when>
             <when test="sortType == 4">
-                order by price1 desc
-            </when>
-            <when test="sortType == 7">
                 order by favoriteTimes desc
             </when>
-            <when test="sortType == 8">
+            <when test="sortType == 5">
+                order by sellNumber asc
+            </when>
+            <when test="sortType == 6">
                 order by sellNumber desc
             </when>
             <otherwise>