From 8b2191df2f7d94aa299bd43dcbe97c94e5a61bbd Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 20 十一月 2019 14:53:34 +0800
Subject: [PATCH] RocketMQ的消息整改

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandGoodsCaheServiceImpl.java |  112 +++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 78 insertions(+), 34 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandGoodsCaheServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandGoodsCaheServiceImpl.java
index 0ab76b5..d6be2b0 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandGoodsCaheServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandGoodsCaheServiceImpl.java
@@ -68,15 +68,27 @@
 	 * @return
 	 */
 	private int addBrandGoodsTB(BrandInfo brandInfo) {
+		String shopKey = brandInfo.getShopKey();
+		if (StringUtil.isNullOrEmpty(shopKey))
+			shopKey = brandInfo.getName();
+		
+		String searchKey = brandInfo.getSearchKey();
+		if (StringUtil.isNullOrEmpty(searchKey))
+			searchKey = brandInfo.getName();
+		
 		Date date = new Date();
 		SearchFilter filter = new SearchFilter();
-		filter.setKey(brandInfo.getName());
+		filter.setKey(searchKey);
 		filter.setPage(1);
 		filter.setPageSize(100);
 		filter.setTmall(true);
 		filter.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
 		TaoBaoSearchResult searchResult = TaoKeApiUtil.searchWuLiao(filter);
 		
+		// 鍒犻櫎搴楅摵
+	    brandShopCaheService.removeByDateAndType(brandInfo.getId(), 11, date);
+	    
+	    // 缁勭粐鍟嗗搧 + 娣诲姞搴楅摵
 		int count = 0;
 		if (searchResult != null && searchResult.getTaoBaoGoodsBriefs() != null 
 				&& searchResult.getTaoBaoGoodsBriefs().size() > 0) {
@@ -86,8 +98,8 @@
 				// 娣诲姞搴楅摵
 				String shopTitle = goods.getShopTitle();
 				if (addShop && !StringUtil.isNullOrEmpty(shopTitle) && shopTitle.contains("鏃楄埌搴�") 
-						&& shopTitle.contains(brandInfo.getName())) {
-					addShop = brandShopCaheService.addBrandShopTB(brandInfo.getId(), goods.getAuctionId(),
+						&& shopTitle.toLowerCase().contains(shopKey.toLowerCase())) {
+					addShop = brandShopCaheService.addBrandShopTB(brandInfo, goods.getAuctionId(),
 							goods.getSellerId());
 				}
 				
@@ -106,9 +118,10 @@
 				}
 			}
 		}
+		
 		// 鍒犻櫎涔嬪墠鐨�
 	    brandGoodsCaheDao.removeByDate(brandInfo.getId(), 1 , date);
-		 
+	    
 		return count;
 	}
 	
@@ -120,14 +133,28 @@
 	 * @return
 	 */
 	private int addBrandGoodsJD(BrandInfo brandInfo) {
+		String shopKey = brandInfo.getShopKey();
+		if (StringUtil.isNullOrEmpty(shopKey))
+			shopKey = brandInfo.getName();
+		
+		String searchKey = brandInfo.getSearchKey();
+		if (StringUtil.isNullOrEmpty(searchKey))
+			searchKey = brandInfo.getName();
+		
 		int count = 0;
 		JDSearchResult result = null;
 		String way = configService.get("jd_api_search_key");
 		Date date = new Date();
+		
+		// 鍒犻櫎搴楅摵
+	    brandShopCaheService.removeByDateAndType(brandInfo.getId(), 20, date);
+	    
+	    boolean addShop = true;
+	    
 		for (int i=0; i < 2;i ++) {
 			if ("1".equals(way)) {
 				JDFilter filterAPI = new JDFilter();
-				filterAPI.setKeyword(SearchFilterUtil.filterSearchContent(brandInfo.getName()));
+				filterAPI.setKeyword(SearchFilterUtil.filterSearchContent(searchKey));
 				filterAPI.setPageIndex(1);
 				filterAPI.setPageSize(30);
 				filterAPI.setSort(JDFilter.SORT_DESC);
@@ -136,7 +163,7 @@
 			} else {
 				// 缃戦〉鐖彇
 				JDSearchFilter jdfilter = new JDSearchFilter();
-				jdfilter.setKey(SearchFilterUtil.filterSearchContent(brandInfo.getName()));
+				jdfilter.setKey(SearchFilterUtil.filterSearchContent(searchKey));
 				jdfilter.setPageNo(1);
 				jdfilter.setPageSize(30);
 				jdfilter.setSort(JDSearchFilter.SORT_DESC);
@@ -144,29 +171,30 @@
 				result = JDUtil.searchByKey(jdfilter);
 			}
 			
-			if (result != null) {
+			if (result != null && result.getGoodsList() != null && result.getGoodsList().size() > 0) {
 				List<JDGoods> goodsList = result.getGoodsList();
-				if (goodsList != null && goodsList.size() > 0) {
-					for (JDGoods goods : goodsList) {
-						BrandGoodsCahe brandGoods = new BrandGoodsCahe();
-						brandGoods.setBrandId(brandInfo.getId());
-						brandGoods.setWeight((int) (Math.random() * 1000));
-						brandGoods.setGoodsJD(goods);
-						brandGoods.setGoodsType(2);
-						brandGoods.setCreateTime(date);
-						brandGoodsCaheDao.insert(brandGoods);
-						
-						if (count == 0) {
-							JDShopInfo shopInfo = goods.getShopInfo();
-							if(shopInfo != null) {
-								brandShopCaheService.addBrandShopJD(brandInfo, shopInfo);
-							}
+				for (JDGoods goods : goodsList) {
+					BrandGoodsCahe brandGoods = new BrandGoodsCahe();
+					brandGoods.setBrandId(brandInfo.getId());
+					brandGoods.setWeight((int) (Math.random() * 1000));
+					brandGoods.setGoodsJD(goods);
+					brandGoods.setGoodsType(2);
+					brandGoods.setCreateTime(date);
+					brandGoodsCaheDao.insert(brandGoods);
+					
+					JDShopInfo shopInfo = goods.getShopInfo();
+					if (addShop && shopInfo != null) {
+						// 鍖呭惈璇ュ搧鐗屽悕绉�
+						String shopName = shopInfo.getShopName();
+						if (!StringUtil.isNullOrEmpty(shopName) && shopName.toLowerCase().contains(shopKey.toLowerCase())) {
+							addShop = false;
+							brandShopCaheService.addBrandShopJD(brandInfo, shopInfo);
 						}
-						
-						count ++;
-						if (count >= 50) {
-							break;
-						}
+					}
+					
+					count ++;
+					if (count >= 50) {
+						break;
 					}
 				}
 			}
@@ -185,14 +213,20 @@
 	 * @return
 	 */
 	private int addBrandGoodsPDD(BrandInfo brandInfo) {
+		String searchKey = brandInfo.getSearchKey();
+		if (StringUtil.isNullOrEmpty(searchKey))
+			searchKey = brandInfo.getName();
+		
 		PDDSearchFilter pddfilter = new PDDSearchFilter();
-		pddfilter.setKw(brandInfo.getName());
+		pddfilter.setKw(searchKey);
 		pddfilter.setPage(1);
 		pddfilter.setPageSize(100);
 		pddfilter.setSortType(6);
-		Date date = new Date();
-		int count = 0;
 		PDDGoodsResult result = PinDuoDuoApiUtil.searchGoods(pddfilter);
+		
+		int count = 0;
+		Date date = new Date();
+		
 		if (result != null) {
 			List<PDDGoodsDetail> goodsList = result.getGoodsList();
 			if (goodsList != null && goodsList.size() > 0) {
@@ -211,14 +245,14 @@
 				}
 			}
 		}
+		// 鍒犻櫎涔嬪墠
+		brandGoodsCaheDao.removeByDate(brandInfo.getId(), 3, date);
+		// 鍒犻櫎涔嬪墠搴楅摵
+		brandShopCaheService.removeByDateAndType(brandInfo.getId(), 30, date);
 		// 娣诲姞搴楅摵
 		brandShopCaheService.addBrandShopPDD(brandInfo);
 		
-		// 鍒犻櫎涔嬪墠
-		brandGoodsCaheDao.removeByDate(brandInfo.getId(), 3, date);
-		
 		return count;
-		
 	}
 	
 	
@@ -231,4 +265,14 @@
 	public long countByBrandId(Long brandId){
 		return brandGoodsCaheDao.countByBrandId(brandId);
 	}
+	
+	@Override
+	public void removeAgoByDate(Date createTime) {
+		brandGoodsCaheDao.removeAgoByDate(createTime);
+	}
+	
+	@Override
+	public void removeByBrandId(Long brandId) {
+		brandGoodsCaheDao.removeByBrandId(brandId);
+	}
 }

--
Gitblit v1.8.0