From cd637932a970e7935b17d41568fe89c92775bccc Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 06 十二月 2019 17:18:27 +0800
Subject: [PATCH] 双12活动添加,邀请码发布修改,爬单新规则添加

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonTemplateContentServiceImpl.java |   92 +++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 90 insertions(+), 2 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 cb5910b..5666f37 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
@@ -3,7 +3,9 @@
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.annotation.Resource;
 
@@ -19,23 +21,30 @@
 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.exception.taobao.TaoKeApiException;
+import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
 import com.yeshi.fanli.service.inter.goods.CommonTemplateContentService;
-import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
 import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
 import com.yeshi.fanli.service.inter.lable.TaoKeGoodsService;
+import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
 import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
 import com.yeshi.fanli.service.inter.taobao.TaobaoMeterialService;
 import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
+import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailV2Service;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil;
 import com.yeshi.fanli.util.taobao.DaTaoKeUtil;
 import com.yeshi.fanli.util.taobao.TaoBaoUtil;
+import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
 
 @Service
 public class CommonTemplateContentServiceImpl implements CommonTemplateContentService {
 
 	@Resource
 	private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
+
+	@Resource
+	private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service;
 
 	@Resource
 	private TaobaoMeterialService taobaoMeterialService;
@@ -130,6 +139,8 @@
 			navList = getCommonNav();
 		} else if (type == CommonContentTypeEnum.chaoPinReMai) {
 			navList = getCommonNav();
+		} else if (type == CommonContentTypeEnum.mianDan) {
+			navList = new ArrayList<>();
 		}
 
 		return navList;
@@ -167,7 +178,10 @@
 			result = getCaoShengContent(cid, page, pageSize);
 		} else if (type == CommonContentTypeEnum.haoQuan) {
 			result = getHaoQuanContent(cid, page, pageSize);
+		} else if (type == CommonContentTypeEnum.mianDan) {
+			result = getMianDanContent(page, pageSize);
 		}
+
 		if (result != null) {// 鍟嗗搧淇℃伅杩囨护
 			List<TaoBaoGoodsBrief> goodsList = taoBaoGoodsUpdateService
 					.filterImportantTaoBaoGoods(result.getGoodsList());
@@ -193,15 +207,36 @@
 		if ("-1".equalsIgnoreCase(cid)) {
 			result = DaTaoKeApiUtil.search("", null, null, new BigDecimal("10"), page, pageSize,
 					DaTaoKeApiUtil.SORT_DEFAULT);
+			if (result == null || result.getGoodsList() == null || result.getGoodsList().size() == 0) {
+				result = new DaTaoKeGoodsResult();
+				result.setGoodsList(daTaoKeGoodsDetailV2Service.listByMaxPrice(null,
+						new BigDecimal("10"),null, page, pageSize));
+				result.setTotalCount(
+						daTaoKeGoodsDetailV2Service.countByMaxPrice(null, new BigDecimal("10")));
+			}
 
 		} else if ("0".equalsIgnoreCase(cid)) {
 			result = DaTaoKeApiUtil.search("", null, null, new BigDecimal("10"), page, pageSize,
 					DaTaoKeApiUtil.SORT_CREATETIME);
+			if (result == null || result.getGoodsList() == null || result.getGoodsList().size() == 0) {
+				result = new DaTaoKeGoodsResult();
+				result.setGoodsList(daTaoKeGoodsDetailV2Service.listByMaxPrice(null,
+						new BigDecimal("10"),"createTime", page, pageSize));
+				result.setTotalCount(
+						daTaoKeGoodsDetailV2Service.countByMaxPrice(null, new BigDecimal("10")));
+			}
 		} else {
 			List<Integer> cidList = new ArrayList<>();
 			cidList.add(Integer.parseInt(cid));
 			result = DaTaoKeApiUtil.search("", cidList, null, new BigDecimal("10"), page, pageSize,
 					DaTaoKeApiUtil.SORT_DEFAULT);
+			if (result == null || result.getGoodsList() == null || result.getGoodsList().size() == 0) {
+				result = new DaTaoKeGoodsResult();
+				result.setGoodsList(daTaoKeGoodsDetailV2Service.listByMaxPrice(Integer.parseInt(cid),
+						new BigDecimal("10"),null, page, pageSize));
+				result.setTotalCount(
+						daTaoKeGoodsDetailV2Service.countByMaxPrice(Integer.parseInt(cid), new BigDecimal("10")));
+			}
 		}
 
 		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
@@ -477,7 +512,7 @@
 		List<Integer> cidList = new ArrayList<>();
 		cidList.add(1);// 濂宠
 		int sort = getCommonSort(cid);
-		result = DaTaoKeApiUtil.search("鍐呰。 濂�", cidList, null, null, page, pageSize, sort);
+		result = DaTaoKeApiUtil.search("", cidList, null, null, page, pageSize, sort);
 		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
 		long count = 0;
 		if (result != null) {
@@ -654,4 +689,57 @@
 		return new CommonContentResult(goodsList, count);
 	}
 
+	/**
+	 * 鑾峰彇鍏嶅崟鍟嗗搧
+	 * 
+	 * @return
+	 */
+	private CommonContentResult getMianDanContent(int page, int pageSize) {
+		CommonContentResult result = new CommonContentResult();
+		List<QualityFactory> listQuery = qualityGoodsService.listFreeGoods((page - 1) * pageSize, pageSize);
+		long count = qualityGoodsService.countFreeGoods();
+		result.setCount(count);
+		List<Long> listGid = new ArrayList<Long>();
+		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+		for (QualityFactory qualityFactory : listQuery) {
+			TaoBaoGoodsBrief taoBaoGoodsBrief = qualityFactory.getTaoBaoGoodsBrief();
+			if (taoBaoGoodsBrief == null) {
+				continue;
+			}
+			listGid.add(taoBaoGoodsBrief.getAuctionId());
+			goodsList.add(taoBaoGoodsBrief);
+		}
+		// 鍘绘帀宸茬粡涓嶅湪鍞殑鍟嗗搧
+		List<TaoBaoGoodsBrief> listTaoKeGoods = null;
+		try {
+			listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid);
+		} catch (TaoKeApiException e) {
+			e.printStackTrace();
+		} catch (TaobaoGoodsDownException e) {
+			e.printStackTrace();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		Map<Long, TaoBaoGoodsBrief> goodsMap = new HashMap<>();
+		for (TaoBaoGoodsBrief goods : listTaoKeGoods)
+			goodsMap.put(goods.getAuctionId(), goods);
+		for (int i = 0; i < goodsList.size(); i++) {
+			if (goodsMap.get(goodsList.get(i).getAuctionId()) == null) {
+				goodsList.remove(i--);
+			}
+		}
+		// 杩囨护鍩烘湰鍟嗗搧淇℃伅
+		goodsList = taoBaoGoodsUpdateService.filterImportantTaoBaoGoods(goodsList);
+
+		for (int i = 0; i < goodsList.size(); i++) {
+			TaoBaoGoodsBrief goods = goodsList.get(i);
+			BigDecimal price = TaoBaoUtil.getAfterUseCouplePrice(goods);
+			if (price.compareTo(new BigDecimal(10)) >= 0) {
+				goodsList.remove(i--);
+			}
+		}
+		result.setGoodsList(goodsList);
+		return result;
+	}
+
 }

--
Gitblit v1.8.0