From c0f13add249efc60e02ea4a306ab0b464ed69353 Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期日, 28 四月 2019 11:52:47 +0800
Subject: [PATCH] 品牌商品优化

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java |  149 ++++++++++++++++++++-----------------------------
 1 files changed, 62 insertions(+), 87 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java
index cf022d3..1d1ff4d 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopServiceImpl.java
@@ -7,7 +7,6 @@
 
 import javax.annotation.Resource;
 
-import org.apache.commons.beanutils.PropertyUtils;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -61,16 +60,6 @@
 	private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
 	
 
-	@Override
-	public List<BrandClassShop> listEffective(long start, int count, Long cid) {
-		return brandClassShopMapper.listEffective(start, count, cid);
-	}
-
-	
-	@Override
-	public long countEffective(Long cid) {
-		return brandClassShopMapper.countEffective(cid);
-	}
 
 	@Override
 	public List<BrandClassShop> getExistByShopIds(List<Long> list){
@@ -183,7 +172,15 @@
 				long couponNum = commonGoodsService.countBySellerIdAndHasCoupon(shop.getId());
 				brandClassShop.setCouponNum(couponNum);
 				
-				shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
+				String shopLink = shop.getShopLink();
+				if (StringUtil.isNullOrEmpty(shopLink)) {
+					shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
+				}
+				
+				String shopNameCustom = shop.getShopNameCustom();
+				if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
+					shop.setShopName(shopNameCustom);
+				}
 				
 				String shopIconCustom = shop.getShopIconCustom();
 				if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
@@ -259,108 +256,86 @@
 	@Override
 	@Cacheable(value = "brandCache", key = "'listEffectiveCache-'+#page+'-'+#cid")
 	public JSONObject listEffectiveCache(int page, Long cid) {
-		long count = 0;
-		int pageSize = Constant.PAGE_SIZE;
-		List<BrandClassShop> list = brandClassShopMapper.listEffective((page - 1) * pageSize, pageSize, cid);
-		if (list == null) {
-			list = new ArrayList<BrandClassShop>();
-		} else if (list.size() > 0) {
-			count = brandClassShopMapper.countEffective(cid);
-		}
-
-		JSONObject data = new JSONObject();
-		if (page == 1 && cid != null && cid > 0 && count > pageSize) {
-			List<TaoBaoShop> listShop = new ArrayList<TaoBaoShop>();
-			List<BrandClassShop> listBrand = brandClassShopMapper.listEffective(0, Integer.MAX_VALUE, cid);
-			for (BrandClassShop brandClassShop : listBrand) {
-				TaoBaoShop shop = brandClassShop.getShop();
-				if (shop != null) {
-					String shopIconCustom = shop.getShopIconCustom();
-					if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
-						shop.setShopIcon(shopIconCustom);
-					}
-					listShop.add(shop);
-				}
+		long countShop = 0;
+		List<TaoBaoShop> listShop = new ArrayList<TaoBaoShop>();
+		// 绗竴椤� 鏌ヨ鍏ㄩ儴鍒嗙被涓嬪簵閾�
+		if (page == 1 &&  cid != null && cid > 0 ) {
+			List<BrandClassShop> list = brandClassShopMapper.listEffective(cid);
+			if (list == null) {
+				list = new ArrayList<BrandClassShop>();
+			} else if (list.size() > 0) {
+				countShop = brandClassShopMapper.countEffective(cid);
 			}
-			data.put("listShop", JsonUtil.getApiCommonGson().toJson(listShop));
-		} else if (page == 1 && cid != null && cid > 0) {
-			List<TaoBaoShop> listShop = new ArrayList<TaoBaoShop>();
+			
 			for (BrandClassShop brandClassShop : list) {
 				TaoBaoShop shop = brandClassShop.getShop();
 				if (shop != null) {
+					String shopLink = shop.getShopLink();
+					if (StringUtil.isNullOrEmpty(shopLink)) {
+						shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
+					}
+					
+					String shopNameCustom = shop.getShopNameCustom();
+					if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
+						shop.setShopName(shopNameCustom);
+					}
+					
 					String shopIconCustom = shop.getShopIconCustom();
 					if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
 						shop.setShopIcon(shopIconCustom);
 					}
+					
 					listShop.add(shop);
 				}
 			}
-			data.put("listShop", JsonUtil.getApiCommonGson().toJson(listShop));
 		}
-
-		List<TaoBaoShopVO> listVO = new ArrayList<TaoBaoShopVO>();
-		for (BrandClassShop brandClassShop : list) {
-			TaoBaoShop shop = brandClassShop.getShop();
-			if (shop == null) {
-				continue;
+		
+		JSONObject data = new JSONObject();
+		data.put("countShop", countShop);
+		data.put("listShop", JsonUtil.getApiCommonGson().toJson(listShop));
+		
+		long count = 0;
+		List<TaoBaoShopVO> listInfo = taoBaoShopService.listBrandShopinfo((page-1)*Constant.PAGE_SIZE, Constant.PAGE_SIZE, cid);
+		if (listInfo == null) {
+			listInfo = new ArrayList<TaoBaoShopVO>();
+		} else if (listInfo.size() > 0) {
+			count = taoBaoShopService.countBrandShopinfo(cid);
+		}
+		
+		BigDecimal proportion = manageService.getFanLiRate();
+		for (TaoBaoShopVO taoBaoShopVO : listInfo) {
+			
+			String shopLink = taoBaoShopVO.getShopLink();
+			if (StringUtil.isNullOrEmpty(shopLink)) {
+				taoBaoShopVO.setShopLink(TaoBaoUtil.getShopLink(taoBaoShopVO.getId()));
 			}
 			
-			String shopIconCustom = shop.getShopIconCustom();
+			String shopNameCustom = taoBaoShopVO.getShopNameCustom();
+			if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
+				taoBaoShopVO.setShopName(shopNameCustom);
+			}
+			
+			String shopIconCustom = taoBaoShopVO.getShopIconCustom();
 			if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
-				shop.setShopIcon(shopIconCustom);
+				taoBaoShopVO.setShopIcon(shopIconCustom);
 			}
-
 			
-			List<Long> listgid = new ArrayList<Long>();
-			listgid.add(543572782962L);
-			listgid.add(578504974101L);
-			listgid.add(530275132249L);
 			
-			BigDecimal proportion = manageService.getFanLiRate();
 			List<TaoBaoGoodsBriefExtra> listGoods = new ArrayList<TaoBaoGoodsBriefExtra>();
-			List<TaoBaoGoodsBrief> listgd = taoBaoGoodsBriefService.listQueryByAuctionId(listgid);
-			for (TaoBaoGoodsBrief taoBaoGoodsBrief : listgd) {
+			List<TaoBaoGoodsBrief> listGoodsBrief = taoBaoShopVO.getListGoodsBrief();
+			for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoodsBrief) {
 				listGoods.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null));
 			}
-			
-			
-//			List<QualityFactory> listFactory = qualityGoodsService.listByShopId(0, 3, shop.getId());
-//			if (listFactory == null || listFactory.size() < 3) {
-//				count --;
-//				continue;
-//			}
-//			
-//			List<TaoBaoGoodsBriefExtra> listGoods = new ArrayList<TaoBaoGoodsBriefExtra>();
-//			BigDecimal proportion = manageService.getFanLiRate();
-//			for (QualityFactory selectionGoods : listFactory) {
-//				TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief();
-//				if (taoBaoGoodsBrief == null) {
-//					break;
-//				}
-//				listGoods.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null));
-//			}
-//			
-//			if (listGoods == null || listGoods.size() < 3) {
-//				count --;
-//				continue;
-//			}
-//			
-			
-			TaoBaoShopVO vo = new TaoBaoShopVO();
-			try {
-				PropertyUtils.copyProperties(vo, shop);
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-			vo.setListGoods(listGoods);
-			listVO.add(vo);
+			taoBaoShopVO.setListGoods(listGoods);
 		}
 		data.put("count", count);
-		data.put("list", JsonUtil.getApiCommonGson().toJson(listVO));
+		data.put("list", JsonUtil.getApiCommonGson().toJson(listInfo));
 		
 		return data;
 	}
 	
+	
+	
 	@Override
 	public void addClick(Long shopId) {
 		BrandClassShop brandClassShop = brandClassShopMapper.getByShopId(shopId);

--
Gitblit v1.8.0