From f4548a3ee46afe45da4ee2a42dc169c575deee9f Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期三, 31 七月 2019 11:57:36 +0800
Subject: [PATCH] 动态v2兼容

---
 fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java |   70 ++++++++++++++++++++++++++++++-----
 1 files changed, 60 insertions(+), 10 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
index 165ada6..3e8b365 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/SearchControllerV2.java
@@ -16,6 +16,7 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.yeshi.utils.JsonUtil;
+import org.yeshi.utils.NumberUtil;
 import org.yeshi.utils.taobao.TbImgUtil;
 
 import com.google.gson.Gson;
@@ -32,6 +33,7 @@
 import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
 import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
 import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
+import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
 import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.service.inter.config.BusinessSystemService;
 import com.yeshi.fanli.service.inter.config.ConfigService;
@@ -56,6 +58,7 @@
 import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil;
 import com.yeshi.fanli.util.taobao.SearchFilterUtil;
 import com.yeshi.fanli.util.taobao.TaoBaoUtil;
+import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
 import com.yeshi.fanli.vo.brand.TaoBaoShopVO;
 import com.yeshi.fanli.vo.goods.GoodsDetailVO;
 
@@ -110,8 +113,8 @@
 	 *            鍟嗗搧閾炬帴
 	 * @param out
 	 */
-	@RequestMapping(value = "getNewGoodsInfo", method = RequestMethod.POST)
-	public void getNewGoodsInfo(AcceptData acceptData, String text, PrintWriter out) {
+	@RequestMapping(value = "getRecommendInfo", method = RequestMethod.POST)
+	public void getRecommendInfo(AcceptData acceptData, String text, PrintWriter out) {
 		if (StringUtil.isNullOrEmpty(text)) {
 			out.print(JsonUtil.loadFalseResult("鍊间负绌�"));
 			return;
@@ -137,12 +140,22 @@
 					text = text.substring(1, end);
 			}
 
+			if (NumberUtil.isNumeric(text)) {
+				out.println(JsonUtil.loadFalseResult("涓嶆敮鎸佺函鏁板瓧"));
+				return;
+			}
+
 			LogHelper.test("鏍规嵁绮樿创鏉挎帹鑽�:" + text);
 
 			if (text.length() > 80) {
 				out.print(JsonUtil.loadFalseResult("鍊艰繃闀�"));
 				return;
 			}
+
+			if (analysisTaoToken(text, out)) {
+				return;
+			}
+
 			JSONObject root = new JSONObject();
 
 			root.put("type", 2);
@@ -195,20 +208,59 @@
 		JSONObject taoBaoGoodsJSON = new JSONObject();
 		taoBaoGoodsJSON.put("title", tb.getTitle());
 		taoBaoGoodsJSON.put("zkPrice", tb.getZkPrice());
-		taoBaoGoodsJSON.put("auctionId", tb.getAuctionId());
+		taoBaoGoodsJSON.put("id", tb.getAuctionId());
+		taoBaoGoodsJSON.put("goodsType", Constant.SOURCE_TYPE_TAOBAO);
 		taoBaoGoodsJSON.put("url", "http://item.taobao.com/item.htm?id=" + tb.getAuctionId());
-		data.put("taoBaoGoodsBrief", taoBaoGoodsJSON);
+		data.put("goods", taoBaoGoodsJSON);
 		if (!StringUtil.isNullOrEmpty(tb.getPictUrl())) {
 			if (tb.getImgList() == null)
 				tb.setImgList(new ArrayList<>());
 			tb.getImgList().add(0, TbImgUtil.getTBSize220Img(tb.getPictUrl()));
 		}
-		data.put("tbImgs", tb.getImgList());
+		data.put("imgs", tb.getImgList());
 		JSONObject root = new JSONObject();
 		root.put("type", 1);
 		root.put("data", data);
 
 		out.print(JsonUtil.loadTrueResult(root));
+	}
+
+	private boolean analysisTaoToken(String text, PrintWriter out) {
+		String token = StringUtil.picUpTaoToken(text);
+		if (!StringUtil.isNullOrEmpty(token)) {
+			Long auctionId = TaoKeApiUtil.tokenConvertAuctionId(token);
+			if (auctionId != null) {
+				TaoBaoGoodsBrief tb = null;
+				try {
+					tb = TaoKeApiUtil.getSimpleGoodsInfo(auctionId);
+				} catch (TaobaoGoodsDownException e) {
+					e.printStackTrace();
+				}
+
+				if (tb != null) {
+					JSONObject data = new JSONObject();
+					JSONObject taoBaoGoodsJSON = new JSONObject();
+					taoBaoGoodsJSON.put("title", tb.getTitle());
+					taoBaoGoodsJSON.put("zkPrice", tb.getZkPrice());
+					taoBaoGoodsJSON.put("id", tb.getAuctionId());
+					taoBaoGoodsJSON.put("goodsType", Constant.SOURCE_TYPE_TAOBAO);
+					taoBaoGoodsJSON.put("url", "http://item.taobao.com/item.htm?id=" + tb.getAuctionId());
+					data.put("goods", taoBaoGoodsJSON);
+					if (!StringUtil.isNullOrEmpty(tb.getPictUrl())) {
+						if (tb.getImgList() == null)
+							tb.setImgList(new ArrayList<>());
+						tb.getImgList().add(0, TbImgUtil.getTBSize220Img(tb.getPictUrl()));
+					}
+					data.put("imgs", tb.getImgList());
+					JSONObject root = new JSONObject();
+					root.put("type", 1);
+					root.put("data", data);
+					out.print(JsonUtil.loadTrueResult(root));
+					return true;
+				}
+			}
+		}
+		return false;
 	}
 
 	/**
@@ -591,8 +643,7 @@
 				Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
 						.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
 				for (JDGoods goods : goodsList) {
-					GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertJDGoods(goods, null, fanLiRate,
-							shareRate);
+					GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertJDGoods(goods, fanLiRate, shareRate);
 					array.add(gson.toJson(goodsDetailVO));
 				}
 			}
@@ -604,7 +655,7 @@
 	}
 
 	/**
-	 * 浜笢
+	 * 鎷煎澶�
 	 * 
 	 * @param kw
 	 * @param page
@@ -668,8 +719,7 @@
 				BigDecimal shareRate = hongBaoManageService.getShareRate();
 
 				for (PDDGoodsDetail goods : goodsList) {
-					GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertPDDGoods(goods, null, fanLiRate,
-							shareRate);
+					GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertPDDGoods(goods, fanLiRate, shareRate);
 					array.add(gson.toJson(goodsDetailVO));
 				}
 			}

--
Gitblit v1.8.0