From 20d1a38a0f8049873f1fbbaef96c22e971ea9d77 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期三, 17 七月 2019 15:50:09 +0800
Subject: [PATCH] 搜索词

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonTemplateContentServiceImpl.java |  426 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 401 insertions(+), 25 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonTemplateContentServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonTemplateContentServiceImpl.java
index 897add2..f33299c 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonTemplateContentServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonTemplateContentServiceImpl.java
@@ -2,6 +2,7 @@
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import javax.annotation.Resource;
@@ -15,8 +16,11 @@
 import com.yeshi.fanli.dto.dataoke.DaTaoKeGoodsResult;
 import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
 import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.fanli.entity.taobao.TaobaoMeterial;
 import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
 import com.yeshi.fanli.service.inter.goods.CommonTemplateContentService;
+import com.yeshi.fanli.service.inter.lable.TaoKeGoodsService;
+import com.yeshi.fanli.service.inter.taobao.TaobaoMeterialService;
 import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
 import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil;
 import com.yeshi.fanli.util.taobao.DaTaoKeUtil;
@@ -27,6 +31,38 @@
 
 	@Resource
 	private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
+
+	@Resource
+	private TaobaoMeterialService taobaoMeterialService;
+
+	@Resource
+	private TaoKeGoodsService taoKeGoodsService;
+
+	private static List<CommonContentNav> getCommonNav() {
+		List<CommonContentNav> navList = new ArrayList<>();
+		navList.add(new CommonContentNav("1", "缁煎悎"));
+		navList.add(new CommonContentNav("2", "鏈�鏂�"));
+		navList.add(new CommonContentNav("3", "鐑崠"));
+		navList.add(new CommonContentNav("4", "閿�閲�"));
+		navList.add(new CommonContentNav("5", "杩斿埄姣�"));
+		return navList;
+	}
+
+	private static int getCommonSort(String cid) {
+		int sort = DaTaoKeApiUtil.SORT_DEFAULT;
+		if ("1".equalsIgnoreCase(cid))
+			sort = DaTaoKeApiUtil.SORT_DEFAULT;
+		else if ("2".equalsIgnoreCase(cid))
+			sort = DaTaoKeApiUtil.SORT_CREATETIME;
+		else if ("3".equalsIgnoreCase(cid))
+			sort = DaTaoKeApiUtil.SORT_COUPON_NUM;
+		else if ("4".equalsIgnoreCase(cid))
+			sort = DaTaoKeApiUtil.SORT_SALES;
+		else if ("5".equalsIgnoreCase(cid))
+			sort = DaTaoKeApiUtil.SORT_COMMISSION;
+
+		return sort;
+	}
 
 	@Override
 	public List<CommonContentNav> getNavList(CommonContentTypeEnum type) {
@@ -49,47 +85,75 @@
 			navList.add(new CommonContentNav("3", "30~50鍏冨埜"));
 			navList.add(new CommonContentNav("4", "50鍏冧互涓婂埜"));
 		} else if (type == CommonContentTypeEnum.juJia) {
-			navList.add(new CommonContentNav("1", "缁煎悎"));
-			navList.add(new CommonContentNav("2", "鏈�鏂�"));
-			navList.add(new CommonContentNav("3", "鐑崠"));
-			navList.add(new CommonContentNav("4", "閿�閲�"));
-			navList.add(new CommonContentNav("5", "杩斿埄姣�"));
+			navList = getCommonNav();
 		} else if (type == CommonContentTypeEnum.meiShi) {
-			navList.add(new CommonContentNav("1", "缁煎悎"));
-			navList.add(new CommonContentNav("2", "鏈�鏂�"));
-			navList.add(new CommonContentNav("3", "鐑崠"));
-			navList.add(new CommonContentNav("4", "閿�閲�"));
-			navList.add(new CommonContentNav("5", "杩斿埄姣�"));
+			navList = getCommonNav();
 		} else if (type == CommonContentTypeEnum.muYin) {
 			navList.add(new CommonContentNav("1", "绮鹃��"));
-			navList.add(new CommonContentNav("2", "澶囧瓡"));
-			navList.add(new CommonContentNav("3", "0~6鏈�"));
-			navList.add(new CommonContentNav("4", "7~12鏈�"));
-			navList.add(new CommonContentNav("5", "1~3宀�"));
-			navList.add(new CommonContentNav("6", "4~6宀�"));
-			navList.add(new CommonContentNav("7", "7~12宀�"));
+			navList.add(new CommonContentNav("澶囧瓡", "澶囧瓡"));
+			navList.add(new CommonContentNav("0鑷�6涓湀", "0~6鏈�"));
+			navList.add(new CommonContentNav("7鑷�12涓湀", "7~12鏈�"));
+			navList.add(new CommonContentNav("1鑷�3宀�", "1~3宀�"));
+			navList.add(new CommonContentNav("4鑷�6宀�", "4~6宀�"));
+			navList.add(new CommonContentNav("7鑷�12宀�", "7~12宀�"));
 		} else if (type == CommonContentTypeEnum.reMai) {
-			navList.add(new CommonContentNav("1", "缁煎悎"));
-			navList.add(new CommonContentNav("2", "鏈�鏂�"));
-			navList.add(new CommonContentNav("3", "鐑崠"));
-			navList.add(new CommonContentNav("4", "閿�閲�"));
-			navList.add(new CommonContentNav("5", "杩斿埄姣�"));
+			navList = getCommonNav();
+		} else if (type == CommonContentTypeEnum.chuanYiDaPei) {
+			navList = getCommonNav();
+		} else if (type == CommonContentTypeEnum.meiZhuangGehu) {
+			navList = getCommonNav();
+		} else if (type == CommonContentTypeEnum.jingPinXieBao) {
+			navList = getCommonNav();
+		} else if (type == CommonContentTypeEnum.chaoNanReMai) {
+			navList = getCommonNav();
+		} else if (type == CommonContentTypeEnum.shuMaShouJi) {
+			navList = getCommonNav();
+		} else if (type == CommonContentTypeEnum.yunDongKuXie) {
+			navList = getCommonNav();
+		} else if (type == CommonContentTypeEnum.qiCheHuWai) {
+			navList = getCommonNav();
+		} else if (type == CommonContentTypeEnum.chaoPinReMai) {
+			navList = getCommonNav();
 		}
+
 		return navList;
 	}
 
-	
-	
 	@Cacheable(value = "commonContentCache", key = "#type+'-'+#cid+'-'+#page+'-'+#pageSize")
 	@Override
 	public CommonContentResult getContentList(CommonContentTypeEnum type, String cid, int page, int pageSize) {
-		if (type == CommonContentTypeEnum._9k9)
+		if (type == CommonContentTypeEnum._9k9) {
 			return get9K9Content(cid, page, pageSize);
-
+		} else if (type == CommonContentTypeEnum.juJia) {
+			return getJuJiaShengHuoContent(cid, page, pageSize);
+		} else if (type == CommonContentTypeEnum.muYin) {
+			return getMuYinJingXuanContent(cid, page, pageSize);
+		} else if (type == CommonContentTypeEnum.meiShi) {
+			return getYouXuanMeiShiContent(cid, page, pageSize);
+		} else if (type == CommonContentTypeEnum.chuanYiDaPei) {
+			return getChuanYiDaPeiContent(cid, page, pageSize);
+		} else if (type == CommonContentTypeEnum.meiZhuangGehu) {
+			return getMeiZhuangGeHuContent(cid, page, pageSize);
+		} else if (type == CommonContentTypeEnum.jingPinXieBao) {
+			return getJingPinXieBaoContent(cid, page, pageSize);
+		} else if (type == CommonContentTypeEnum.chaoNanReMai) {
+			return getChaoNanReMaiContent(cid, page, pageSize);
+		} else if (type == CommonContentTypeEnum.shuMaShouJi) {
+			return getShuMaShouJiContent(cid, page, pageSize);
+		} else if (type == CommonContentTypeEnum.yunDongKuXie) {
+			return getYunDongKuXieContent(cid, page, pageSize);
+		} else if (type == CommonContentTypeEnum.qiCheHuWai) {
+			return getQiCheHuWaiContent(cid, page, pageSize);
+		} else if (type == CommonContentTypeEnum.chaoPinReMai) {
+			return getChaoPinReMaiContent(cid, page, pageSize);
+		}
 		return null;
 	}
 
 	private CommonContentResult get9K9Content(String cid, int page, int pageSize) {
+		if (pageSize == 20)
+			pageSize = 50;
+
 		DaTaoKeGoodsResult result = null;
 		if ("-1".equalsIgnoreCase(cid)) {
 			result = DaTaoKeApiUtil.search("", null, null, new BigDecimal("10"), page, pageSize,
@@ -116,4 +180,316 @@
 		return new CommonContentResult(goodsList, count);
 	}
 
+	/**
+	 * 灞呭鐢熸椿
+	 * 
+	 * @param cid
+	 * @param page
+	 * @param pageSize
+	 * @return
+	 */
+	private CommonContentResult getJuJiaShengHuoContent(String cid, int page, int pageSize) {
+		DaTaoKeGoodsResult result = null;
+		List<Integer> cidList = new ArrayList<>();
+		cidList.add(4);// 灞呭鐢熸椿
+		int sort = getCommonSort(cid);
+		result = DaTaoKeApiUtil.search("", cidList, null, null, page, pageSize, sort);
+		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+		long count = 0;
+		if (result != null) {
+			count = result.getTotalCount();
+			if (result.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+		}
+		return new CommonContentResult(goodsList, count);
+	}
+
+	/**
+	 * 浼橀�夌編椋�
+	 * 
+	 * @param cid
+	 * @param page
+	 * @param pageSize
+	 * @return
+	 */
+	private CommonContentResult getYouXuanMeiShiContent(String cid, int page, int pageSize) {
+		DaTaoKeGoodsResult result = null;
+		List<Integer> cidList = new ArrayList<>();
+		cidList.add(6);// 缇庨
+		int sort = getCommonSort(cid);
+		result = DaTaoKeApiUtil.search("", cidList, null, null, page, pageSize, sort);
+		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+		long count = 0;
+		if (result != null) {
+			count = result.getTotalCount();
+			if (result.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+		}
+		return new CommonContentResult(goodsList, count);
+	}
+
+	/**
+	 * 娼搧鐑崠
+	 * 
+	 * @param cid
+	 * @param page
+	 * @param pageSize
+	 * @return
+	 */
+	private CommonContentResult getChaoPinReMaiContent(String cid, int page, int pageSize) {
+		DaTaoKeGoodsResult result = null;
+
+		int sort = getCommonSort(cid);
+		result = DaTaoKeApiUtil.search("娼�", null, null, null, page, pageSize, sort);
+		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+		long count = 0;
+		if (result != null) {
+			count = result.getTotalCount();
+			if (result.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+		}
+		return new CommonContentResult(goodsList, count);
+	}
+
+	/**
+	 * 鑾峰彇姣嶅┐绮鹃��
+	 * 
+	 * @param cid
+	 * @param page
+	 * @param pageSize
+	 * @return
+	 */
+	private CommonContentResult getMuYinJingXuanContent(String cid, int page, int pageSize) {
+		DaTaoKeGoodsResult result = null;
+		if ("1".equalsIgnoreCase(cid)) {// 澶ф窐瀹㈡暟鎹�
+			List<Integer> cidList = new ArrayList<>();
+			cidList.add(2);// 姣嶅┐
+			result = DaTaoKeApiUtil.search("", cidList, null, null, page, pageSize, DaTaoKeApiUtil.SORT_DEFAULT);
+			List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+			long count = 0;
+			if (result != null) {
+				count = result.getTotalCount();
+				if (result.getGoodsList() != null)
+					for (DaTaoKeDetailV2 detail : result.getGoodsList())
+						goodsList.add(TaoBaoUtil.convert(detail));
+			}
+			return new CommonContentResult(goodsList, count);
+
+		} else {//
+			List<TaobaoMeterial> taobaoMeterials = taobaoMeterialService.selectByClassNameAndSuperNameCache("姣嶅┐_" + cid,
+					"姣嶅┐涓婚");
+
+			if (taobaoMeterials == null || taobaoMeterials.size() == 0) {
+				return null;
+			}
+
+			TaobaoMeterial meterial = taobaoMeterials.get(0);
+			Integer materialId = meterial.getMaterialId();
+			if (materialId != null) {
+				List<TaoBaoGoodsBrief> listBrands = new ArrayList<>();
+				try {
+					listBrands = taoKeGoodsService.listByMaterial(materialId, page, pageSize);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+				return new CommonContentResult(listBrands, 1000);
+			}
+			return new CommonContentResult(new ArrayList<>(), 0);
+		}
+
+	}
+
+	/**
+	 * 绌胯。鎼厤
+	 * 
+	 * @param cid
+	 * @param page
+	 * @param pageSize
+	 * @return
+	 */
+	private CommonContentResult getChuanYiDaPeiContent(String cid, int page, int pageSize) {
+		DaTaoKeGoodsResult result = null;
+		List<Integer> cidList = new ArrayList<>();
+		cidList.add(1);// 濂宠
+		int sort = getCommonSort(cid);
+		result = DaTaoKeApiUtil.search("鍐呰。 濂�", cidList, null, null, page, pageSize, sort);
+		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+		long count = 0;
+		if (result != null) {
+			count = result.getTotalCount();
+			if (result.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+		}
+		return new CommonContentResult(goodsList, count);
+	}
+
+	/**
+	 * 缇庡涓姢
+	 * 
+	 * @param cid
+	 * @param page
+	 * @param pageSize
+	 * @return
+	 */
+	private CommonContentResult getMeiZhuangGeHuContent(String cid, int page, int pageSize) {
+		DaTaoKeGoodsResult result = null;
+		List<Integer> cidList = new ArrayList<>();
+		cidList.add(3);// 缇庡
+		int sort = getCommonSort(cid);
+		result = DaTaoKeApiUtil.search("娲楁姢", cidList, null, null, page, pageSize, sort);
+		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+		long count = 0;
+		if (result != null) {
+			count = result.getTotalCount();
+			if (result.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+		}
+		return new CommonContentResult(goodsList, count);
+	}
+
+	/**
+	 * 绮惧搧闉嬪寘
+	 * 
+	 * @param cid
+	 * @param page
+	 * @param pageSize
+	 * @return
+	 */
+
+	private CommonContentResult getJingPinXieBaoContent(String cid, int page, int pageSize) {
+		DaTaoKeGoodsResult result = null;
+		int sort = getCommonSort(cid);
+		result = DaTaoKeApiUtil.search("闉� 濂�", null, null, null, page, pageSize, sort);
+		DaTaoKeGoodsResult result1 = DaTaoKeApiUtil.search("鍖� 濂�", null, null, null, page, pageSize, sort);
+		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+		long count = 0;
+		if (result != null) {
+			count = result.getTotalCount() + result1.getTotalCount();
+			if (result.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+			if (result1.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result1.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+		}
+		Collections.shuffle(goodsList);
+		return new CommonContentResult(goodsList, count);
+	}
+
+	/**
+	 * 娼敺鐑崠
+	 * 
+	 * @param cid
+	 * @param page
+	 * @param pageSize
+	 * @return
+	 */
+	private CommonContentResult getChaoNanReMaiContent(String cid, int page, int pageSize) {
+		DaTaoKeGoodsResult result = null;
+		int sort = getCommonSort(cid);
+		result = DaTaoKeApiUtil.search("娼� 鐢�", null, null, null, page, pageSize, sort);
+		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+		long count = 0;
+		if (result != null) {
+			count = result.getTotalCount();
+			if (result.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+		}
+		Collections.shuffle(goodsList);
+		return new CommonContentResult(goodsList, count);
+	}
+
+	/**
+	 * 鏁扮爜鎵嬫満
+	 * 
+	 * @param cid
+	 * @param page
+	 * @param pageSize
+	 * @return
+	 */
+	private CommonContentResult getShuMaShouJiContent(String cid, int page, int pageSize) {
+		DaTaoKeGoodsResult result = null;
+		int sort = getCommonSort(cid);
+		result = DaTaoKeApiUtil.search("鐢�", null, null, null, page, pageSize, sort);
+		DaTaoKeGoodsResult result1 = DaTaoKeApiUtil.search("鎵嬫満", null, null, null, page, pageSize, sort);
+		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+		long count = 0;
+		if (result != null) {
+			count = result.getTotalCount() + result1.getTotalCount();
+			if (result.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+			if (result1.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result1.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+		}
+		Collections.shuffle(goodsList);
+		return new CommonContentResult(goodsList, count);
+	}
+
+	/**
+	 * 杩愬姩閰烽瀷
+	 * 
+	 * @param cid
+	 * @param page
+	 * @param pageSize
+	 * @return
+	 */
+	private CommonContentResult getYunDongKuXieContent(String cid, int page, int pageSize) {
+		DaTaoKeGoodsResult result = null;
+		int sort = getCommonSort(cid);
+		result = DaTaoKeApiUtil.search("闉� 鐢�", null, null, null, page, pageSize, sort);
+		DaTaoKeGoodsResult result1 = DaTaoKeApiUtil.search("杩愬姩 鐢�", null, null, null, page, pageSize, sort);
+		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+		long count = 0;
+		if (result != null) {
+			count = result.getTotalCount() + result1.getTotalCount();
+			if (result.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+			if (result1.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result1.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+		}
+		Collections.shuffle(goodsList);
+		return new CommonContentResult(goodsList, count);
+	}
+
+	/**
+	 * 姹借溅鎴峰
+	 * 
+	 * @param cid
+	 * @param page
+	 * @param pageSize
+	 * @return
+	 */
+	private CommonContentResult getQiCheHuWaiContent(String cid, int page, int pageSize) {
+		DaTaoKeGoodsResult result = null;
+		List<Integer> cidList = new ArrayList<>();
+		cidList.add(7);
+		cidList.add(13);
+		int sort = getCommonSort(cid);
+		result = DaTaoKeApiUtil.search("", cidList, null, null, page, pageSize, sort);
+		DaTaoKeGoodsResult result1 = DaTaoKeApiUtil.search("杩愬姩 鐢�", cidList, null, null, page, pageSize, sort);
+		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+		long count = 0;
+		if (result != null) {
+			count = result.getTotalCount() + result1.getTotalCount();
+			if (result.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+			if (result1.getGoodsList() != null)
+				for (DaTaoKeDetailV2 detail : result1.getGoodsList())
+					goodsList.add(TaoBaoUtil.convert(detail));
+		}
+		Collections.shuffle(goodsList);
+		return new CommonContentResult(goodsList, count);
+	}
+
 }

--
Gitblit v1.8.0