From 20d1a38a0f8049873f1fbbaef96c22e971ea9d77 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期三, 17 七月 2019 15:50:09 +0800
Subject: [PATCH] 搜索词

---
 fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java |  301 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 247 insertions(+), 54 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java
index 9db75a2..81a08be 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java
@@ -5,8 +5,6 @@
 import java.math.BigDecimal;
 import java.net.URLEncoder;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 
 import org.jsoup.Jsoup;
@@ -19,9 +17,11 @@
 import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
 import com.yeshi.fanli.entity.taobao.TaoBaoHead;
 import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
+import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
+import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
 import com.yeshi.fanli.tag.PageEntity;
+import com.yeshi.fanli.util.MoneyBigDecimalUtil;
 import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.TimeUtil;
 
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
@@ -33,6 +33,114 @@
  *
  */
 public class DaTaoKeUtil {
+
+	static final String[] commonEmojis = new String[] { "馃榾", // 绗戝樆鍢�
+			"馃榿", // 绗戝樆鍢荤殑鑴革紝鍚瑧鐨勭溂鐫�
+			"馃槂", // 寮�鍙g瑧鑴�
+			"馃槃", // 寮�鍙g瑧鑴稿拰寰瑧鐨勭溂鐫�
+			"馃槅", // 寮�鍙g瑧绱ч棴鐨勭溂鐫�
+			"馃槈", // 鐪ㄧ溂琛ㄦ儏
+			"馃槉", // 闈㈠甫寰瑧鐨勭溂鐫�
+			"馃構", // 鍝佸皾缇庡懗椋熺墿琛ㄦ儏
+			"馃槑", // 澶槼闀滅瑧鑴�
+			"馃槏", // 闈㈠甫蹇冨舰鐪肩潧
+			"馃槝", // 椋炲惢琛ㄦ儏
+			"馃槜", // 浜插惢琛ㄦ儏
+			"馃槞", // 鍚瑧浜插惢琛ㄦ儏
+			"馃槡", // 闂溂浜插惢琛ㄦ儏
+			"鈽�", // 绗戣劯
+			"馃槆", // 鍏夌幆绗戣劯
+			"馃槓", // 涓�ч潰
+			"馃槒", // 鍌荤瑧
+			"馃槷", // 寮犵潃鍢�
+			"馃槢", // 鍚愯垖澶�
+			"馃槣", // 鍚愯垖澶达紝鐪ㄧ溂鐪�
+			"馃槤", // 闂溂鍚愯垖澶�
+			"馃憛", // 鑸屽ご
+			"馃憚", // 鍙�
+			"馃憖", // 鐪肩潧
+			"鉂�", // 蹇�
+			"馃挀", // 璺冲姩鐨勫績
+			"馃挄", // 涓ら蹇�
+			"馃挆", // 鎴愰暱鐨勫績
+			"馃挐", // 鎵庝笣甯︾殑蹇冨舰绀肩洅
+			"馃挒", // 鏃嬭浆蹇�
+			"馃拹", // 鑺辨潫
+			"馃尭", // 妯辫姳
+			"馃尮", // 鐜懓
+			"馃尯", // 妲�
+			"馃尰", // 鍚戞棩钁�
+			"馃尲", // 寮�鑺�
+			"馃尫", // 閮侀噾棣�
+			"馃崌", // 钁¤悇
+			"馃崍", // 鐡�
+			"馃崏", // 瑗跨摐
+			"馃崐", // 鏌戞
+			"馃崑", // 鏌犳
+			"馃崒", // 棣欒晧
+			"馃崓", // 鑿犺悵
+			"馃崕", // 绾㈣嫻鏋�
+			"馃崗", // 闈掕嫻鏋�
+			"馃崘", // 姊�
+			"馃崙", // 妗冨瓙
+			"馃崚", // 妯辨
+			"馃崜", // 鑽夎帗
+			"馃尶", // 鏋濆彾
+			"馃崁", // 鍥涘彾鑽�
+			"馃崄", // 鏋彾
+			"馃崅", // 钀藉彾
+			"馃崈", // 鍙跺瓙鍦ㄩ涓钀�
+			"鈽�", // 涓夊彾鑽�(閰㈡祮鑽�)
+			"鈽�", // 澶槼鍏夎姃鍥涘皠
+			"馃尀", // 澶槼浜鸿劯
+			"猸�", // 鏄熸槦锛屼簲瑙掓槦
+			"馃専",// 鍙戝厜鐨勬槦鏄�
+	};
+
+	static final String[] timeEmojis = new String[] { "馃暃", // 鍗佷簩鐐�
+			"馃暓", // 鍗佷簩鐐瑰崐
+			"馃晲", // 涓�鐐归挓
+			"馃暅", // 涓�鐐瑰崐
+			"馃晳", // 涓ょ偣
+			"馃暆", // 涓ょ偣鍗�
+			"馃晵", // 涓夌偣閽�
+			"馃暈", // 涓夌偣鍗�
+			"馃晸", // 鍥涚偣閽�
+			"馃暉", // 鍥涚偣鍗�
+			"馃晹", // 浜旀椂
+			"馃暊", // 浜旂偣鍗�
+			"馃晻", // 鍏偣
+			"馃暋", // 鍏偣鍗�
+			"馃晼", // 涓冪偣
+			"馃暍", // 涓冪偣鍗�
+			"馃晽", // 鍏偣
+			"馃暎", // 鍏偣鍗�
+			"馃晿", // 涔濈偣閽�
+			"馃暏", // 涔濈偣鍗�
+			"馃暀", // 鐨勫崄鐐�
+			"馃暐", // 鍗佺偣鍗�
+			"馃暁", // 鍗佷竴鐐�
+			"馃暒",// 鍗佷竴鐐瑰崐
+	};
+
+	public static List<GoodsClass> goodsClasses;
+	static {
+		goodsClasses = new ArrayList<>();
+		goodsClasses.add(new GoodsClass(4L, "灞呭鏃ョ敤"));
+		goodsClasses.add(new GoodsClass(6L, "缇庨"));
+		goodsClasses.add(new GoodsClass(2L, "姣嶅┐"));
+		goodsClasses.add(new GoodsClass(3L, "缇庡"));
+		goodsClasses.add(new GoodsClass(1L, "濂宠"));
+		goodsClasses.add(new GoodsClass(8L, "鏁扮爜瀹剁數"));
+		goodsClasses.add(new GoodsClass(7L, "鏂囧ū杞﹀搧"));
+		goodsClasses.add(new GoodsClass(10L, "鍐呰。"));
+		goodsClasses.add(new GoodsClass(14L, "瀹惰瀹剁汉"));
+		goodsClasses.add(new GoodsClass(5L, "闉嬪搧"));
+		goodsClasses.add(new GoodsClass(9L, "鐢疯"));
+		goodsClasses.add(new GoodsClass(12L, "閰嶉グ"));
+		goodsClasses.add(new GoodsClass(13L, "鎴峰杩愬姩"));
+		goodsClasses.add(new GoodsClass(11L, "绠卞寘"));
+	}
 
 	public static final String HOST = "http://dataoke.yeshitv.com";
 
@@ -78,7 +186,7 @@
 		int[] ids = new int[] { 1, 9, 10, 2, 3, 4, 5, 6, 7, 8 };
 		for (int i = 0; i < names.length; i++) {
 			GoodsClass gc = new GoodsClass();
-			gc.setId(Long.parseLong(ids[i]+""));
+			gc.setId(Long.parseLong(ids[i] + ""));
 			gc.setName(names[i]);
 			list.add(gc);
 		}
@@ -256,64 +364,25 @@
 	 * 
 	 * @return
 	 */
-	public static List<TaoBaoGoodsBrief> getDingDongQiang() {
-		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+	public static List<DaTaoKeDetail> getDingDongQiang() {
+		List<DaTaoKeDetail> goodsList = new ArrayList<>();
 		try {
-			Document doc = Jsoup.connect("http://dataoke.yeshitv.com/index.php?r=ddq/wap")
+			Document doc = Jsoup.connect("http://www.dataoke.com/ddq")
 					.userAgent(
 							"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Mobile Safari/537.36")
 					.get();
-			Elements els = doc.getElementsByTag("script");
-			for (int i = 0; i < els.size(); i++) {
-				Element item = els.get(i);
-				if (item.toString().length() > 5000) {
-					String html = item.html();
-					int endIndex = html.indexOf("} ;") + 1;
-					int startIndex = html.indexOf("data =");
-					String json = html.substring(startIndex + "data =".length(), endIndex).trim();
-					JSONObject root = JSONObject.fromObject(json);
-					Iterator<String> keys = root.keySet().iterator();
-					List<String> ids = new ArrayList<>();
-					while (keys.hasNext()) {
-						String key = keys.next();
-						JSONArray array = root.optJSONObject(key).optJSONArray("list");
-						for (int j = 0; j < array.size(); j++) {
-							if (TimeUtil.convertToTimeTemp(array.optJSONObject(j).optString("paiqi"),
-									"yyyy-MM-dd HH:mm:ss") < System.currentTimeMillis())
-								ids.add(array.optJSONObject(j).optString("id"));
-						}
-					}
-					Collections.shuffle(ids);
-					List<Long> goodsIdList = new ArrayList<>();
-					ids.parallelStream().forEach(id -> {
-						try {
-							long auctionId = getAuctionId(Long.parseLong(id));
-							goodsIdList.add(auctionId);
-						} catch (Exception e) {
-						}
-					});
-
-					goodsIdList.parallelStream().forEach(goods -> {
-						try {
-							TaoBaoGoodsBrief gds = TaoKeApiUtil.searchGoodsDetail(goods);
-							if (gds != null)
-								goodsList.add(gds);
-						} catch (Exception e) {
-
-						}
-
-					});
-
-				}
-
+			Elements items = doc.getElementsByClass("main").get(0).getElementsByClass("clearfix").get(0)
+					.getElementsByTag("li");
+			for (int i = 0; i < items.size(); i++) {
+				DaTaoKeDetail detail = new DaTaoKeDetail();
+				String id = items.get(i).getElementsByTag("a").get(0).attr("href").split("\\?")[1].replace("id=", "");
+				detail.setId(Long.parseLong(id));
+				goodsList.add(detail);
 			}
+		} catch (Exception e) {
 
-		} catch (IOException e) {
-			e.printStackTrace();
 		}
-
 		return goodsList;
-
 	}
 
 	//
@@ -344,4 +413,128 @@
 		return couponList;
 	}
 
+	private static List<DaTaoKeDetail> parseCurrent(String url) {
+
+		List<DaTaoKeDetail> list = new ArrayList<>();
+		try {
+			Document doc = Jsoup.connect(url)
+					.userAgent(
+							"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36")
+					.get();
+			Elements items = doc.getElementsByClass("goods-list").get(0).getElementsByClass("goods-item");
+			for (int i = 0; i < items.size(); i++) {
+				Long id = Long.parseLong(items.get(i).attr("id").replace("goods-items_", ""));
+				String currentSale = items.get(i).getElementsByClass("goods-item-content").get(0)
+						.getElementsByClass("goods-info").get(0).getElementsByClass("tg-show").get(0)
+						.getElementsByTag("b").get(0).text();
+
+				System.out.println(id + "-" + currentSale);
+				DaTaoKeDetail detail = new DaTaoKeDetail();
+				detail.setId(id);
+				detail.setSalesNum(Integer.parseInt(currentSale));
+				list.add(detail);
+
+			}
+
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		// TODO 闇�瑕佽繑鍥炲��
+		return list;
+	}
+
+	// 鑾峰彇瀹炴椂姒滃崟
+	/**
+	 * 鑾峰彇瀹炴椂閿�閲忔
+	 * 
+	 * @param cid
+	 * @return
+	 */
+	public static List<DaTaoKeDetail> getCurrentSalesRank(Integer cid) {
+		String url = null;
+		if (cid == null)
+			url = "http://www.dataoke.com/top_sell";
+		else
+			url = String.format("http://www.dataoke.com/top_sell?cid=%s&type=1", cid);
+		return parseCurrent(url);
+	}
+
+	/**
+	 * 鍏ㄥぉ閿�閲忔
+	 * 
+	 * @param cid
+	 * @return
+	 */
+	public static List<DaTaoKeDetail> getCurrentDaySalesRank(Integer cid) {
+		String url = null;
+		if (cid == null)
+			url = "http://www.dataoke.com/top_all";
+		else
+			url = String.format("http://www.dataoke.com/top_all?cid=%s", cid);
+		return parseCurrent(url);
+	}
+
+	/**
+	 * 鑾峰彇鐑帹姒�
+	 * 
+	 * @param cid
+	 * @return
+	 */
+	public static List<DaTaoKeDetail> getCurrentHotSalesRank() {
+		String url = "http://www.dataoke.com/top_tui";
+		return parseCurrent(url);
+	}
+
+	private static String getRandomCommonEmoji() {
+		return commonEmojis[(int) (Math.random() * commonEmojis.length)];
+	}
+
+	public static String getDesc(DaTaoKeDetail detail) {
+
+		// 鏍囬+鍒稿悗浠�+鍖呴偖+鎻忚堪
+		String desc = detail.getdTitle();
+		desc += "\n";
+		desc += String.format("鍒稿悗浠�%s銆�%s鍏冦�戝寘閭鏉� ", Math.random() > 0.5 ? "馃挵" : "",
+				MoneyBigDecimalUtil.getWithNoZera(detail.getPrice()).toString())
+				+ (Math.random() > 0.5 ? getRandomCommonEmoji() : "");
+		desc += "\n";
+		// desc += detail.getIntroduce();
+		String introduce = detail.getIntroduce().replace("锛�", ",").replace("銆�", ",").replace("锛�", ",").replace(",",
+				",");
+		introduce = introduce.replace(",,,", ",").replace(",,", ",");
+
+		String[] sts = introduce.split(",");
+		introduce = "";
+		for (int i = 0; i < sts.length; i++) {
+			if (i % 2 == 1) {// 闇�瑕佹崲琛�
+				introduce += sts[i] + (Math.random() > 0.5 ? getRandomCommonEmoji() : i == sts.length - 1 ? "" : "锛�")
+						+ "\n";
+			} else
+				introduce += sts[i] + (Math.random() > 0.5 ? getRandomCommonEmoji() : i == sts.length - 1 ? "" : "锛�");
+		}
+		desc += introduce;
+		return desc;
+	}
+
+	public static TaoBaoGoodsBrief filterTaoBaoGoods(TaoBaoGoodsBrief goods, DaTaoKeDetail detail) {
+		if (detail != null && goods != null) {
+			// 閲嶆柊璁剧疆鏍囬涓庡埜浠锋牸
+			goods.setTitle(detail.getdTitle());
+			if (!StringUtil.isNullOrEmpty(detail.getPic()))
+				goods.setPictUrlWhite(detail.getPic());
+		}
+		return goods;
+	}
+
+	public static TaoBaoGoodsBrief filterTaoBaoGoods(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 detail) {
+		if (detail != null && goods != null) {
+			// 閲嶆柊璁剧疆鏍囬涓庡埜浠锋牸
+			goods.setTitle(detail.getDtitle());
+			if (!StringUtil.isNullOrEmpty(detail.getMainPic()))
+				goods.setPictUrlWhite(detail.getMainPic());
+		}
+		return goods;
+	}
+
 }

--
Gitblit v1.8.0