From b5cf0267dfc95bf56dceb76ca44e849347a7b85f Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 18 十一月 2019 13:55:49 +0800
Subject: [PATCH] 1.饿了么订单定时爬取 2.相似商品推荐修改

---
 fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java |   48 ++++++++++++++++++++++++++++++------------------
 1 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java
index 471c85b..5705127 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoBaoUtil.java
@@ -1844,6 +1844,12 @@
 		return url;
 	}
 
+	/**
+	 * 鑾峰彇娣樺疂鐨勫晢鍝佽鎯�
+	 * 
+	 * @param actionId
+	 * @return
+	 */
 	public static TaoBaoGoodsBrief getSimpleGoodsBrief(Long actionId) {
 		JSONObject data = new JSONObject();
 		data.put("itemNumId", actionId + "");
@@ -1855,6 +1861,7 @@
 		} catch (UnsupportedEncodingException e) {
 			e.printStackTrace();
 		}
+
 		HttpClient client = new HttpClient();
 		GetMethod gm = new GetMethod(url);
 		String result = null;
@@ -1879,25 +1886,30 @@
 		JSONObject resultOBJ = JSONObject.fromObject(result);
 		if (resultOBJ.optJSONObject("data") != null) {
 			data = resultOBJ.optJSONObject("data");
-			JSONObject item = data.optJSONObject("item");
-			JSONObject seller = data.optJSONObject("seller");
-			TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
-			goods.setTitle(item.optString("title"));
-			goods.setAuctionId(item.optLong("itemId"));
-			goods.setTitle(item.optString("title"));
-			if (item.optJSONArray("images") != null && item.optJSONArray("images").size() > 0) {
-				String picture = item.optJSONArray("images").optString(0);
-				goods.setPictUrl(picture.startsWith("http") ? picture : "https:" + picture);
+			if (data != null) {
+				JSONObject item = data.optJSONObject("item");
+				if (item != null) {
+					JSONObject seller = data.optJSONObject("seller");
+					TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief();
+					goods.setTitle(item.optString("title"));
+					goods.setAuctionId(item.optLong("itemId"));
+					goods.setTitle(item.optString("title"));
+					if (item.optJSONArray("images") != null && item.optJSONArray("images").size() > 0) {
+						String picture = item.optJSONArray("images").optString(0);
+						goods.setPictUrl(picture.startsWith("http") ? picture : "https:" + picture);
+					}
+					if (seller != null) {
+						goods.setSellerId(seller.optLong("shopId"));
+						String shopType = seller.optString("shopType");
+						if ("B".equalsIgnoreCase(shopType)) {
+							goods.setUserType(1);
+						} else
+							goods.setUserType(0);
+						goods.setShopTitle(seller.optString("shopName"));
+					}
+					return goods;
+				}
 			}
-			goods.setSellerId(seller.optLong("shopId"));
-			String shopType = seller.optString("shopType");
-			if ("B".equalsIgnoreCase(shopType)) {
-				goods.setUserType(1);
-			} else
-				goods.setUserType(0);
-
-			goods.setShopTitle(seller.optString("shopName"));
-			return goods;
 		}
 		return null;
 	}

--
Gitblit v1.8.0