From 2f2860b50f24e5e3598d223db03d43df61d95c97 Mon Sep 17 00:00:00 2001
From: yj <Administrator@192>
Date: 星期五, 13 三月 2020 16:31:30 +0800
Subject: [PATCH] Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div

---
 fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java |  129 +++++++++++++++++++++++++++++-------------
 1 files changed, 88 insertions(+), 41 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 c8e606b..7075b9d 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
@@ -17,6 +17,7 @@
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.jsoup.select.Elements;
+import org.yeshi.utils.HttpUtil;
 
 import com.yeshi.fanli.dto.dataoke.DingDongQiangDTO;
 import com.yeshi.fanli.dto.dataoke.DingDongTime;
@@ -25,7 +26,6 @@
 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;
@@ -131,6 +131,41 @@
 			"馃暒",// 鍗佷竴鐐瑰崐
 	};
 
+	static final String[] evaluateEmojis = new String[] { 
+		"馃挓",
+		"馃尭",
+		"馃嵏",
+		"馃嵑",
+		"馃摙",
+		"鉂�",
+		"馃挐",
+		"馃拫",
+		"馃憶",
+		"馃惥",
+		"馃尮",
+		"馃敟",
+		"馃帀",
+		"馃巵",
+		"馃崶",
+		"馃嵀",
+		"馃尯",
+		"馃憫",
+		"鉁�",
+		"馃挮",
+		"馃嵒",
+		"馃巿",
+		"馃挜",
+		"馃挄",
+		"馃挒",
+		"馃挵",
+		"馃拰",
+		"馃挱",
+		"馃尲",
+		"馃崁"
+	};
+	
+	
+	
 	public static List<GoodsClass> goodsClasses;
 	static {
 		goodsClasses = new ArrayList<>();
@@ -380,6 +415,8 @@
 		} catch (IOException e1) {
 			e1.printStackTrace();
 		}
+		if (doc == null)
+			return new ArrayList<>();
 		Elements els = doc.getElementsByTag("script");
 		for (int i = 0; i < els.size(); i++) {
 			String content = els.get(i).html();
@@ -387,7 +424,8 @@
 				ScriptEngineManager manager = new ScriptEngineManager();
 				ScriptEngine engine = manager.getEngineByName("javascript");
 				try {
-					String js = "function getData(){return  JSON.stringify(dataDef);}" + content;
+					String js = "function getData(){return  JSON.stringify(dataDef);} var test1='--';function test2(res){};"
+							+ content.replace("$(window).load", "test2").replace("window.location.search.", "test1.");
 					engine.eval(js);
 					if (engine instanceof Invocable) {
 						Invocable in = (Invocable) engine;
@@ -440,9 +478,9 @@
 		return couponList;
 	}
 
-	private static List<DaTaoKeDetail> parseCurrent(String url) {
+	private static List<DaTaoKeDetailV2> parseCurrent(String url) {
 
-		List<DaTaoKeDetail> list = new ArrayList<>();
+		List<DaTaoKeDetailV2> list = new ArrayList<>();
 		try {
 			Document doc = Jsoup.connect(url)
 					.userAgent(
@@ -456,9 +494,9 @@
 						.getElementsByTag("b").get(0).text();
 
 				System.out.println(id + "-" + currentSale);
-				DaTaoKeDetail detail = new DaTaoKeDetail();
+				DaTaoKeDetailV2 detail = new DaTaoKeDetailV2();
 				detail.setId(id);
-				detail.setSalesNum(Integer.parseInt(currentSale));
+				detail.setMonthSales(Integer.parseInt(currentSale));
 				list.add(detail);
 
 			}
@@ -478,7 +516,7 @@
 	 * @param cid
 	 * @return
 	 */
-	public static List<DaTaoKeDetail> getCurrentSalesRank(Integer cid) {
+	public static List<DaTaoKeDetailV2> getCurrentSalesRank(Integer cid) {
 		String url = null;
 		if (cid == null)
 			url = "http://www.dataoke.com/top_sell";
@@ -493,7 +531,7 @@
 	 * @param cid
 	 * @return
 	 */
-	public static List<DaTaoKeDetail> getCurrentDaySalesRank(Integer cid) {
+	public static List<DaTaoKeDetailV2> getCurrentDaySalesRank(Integer cid) {
 		String url = null;
 		if (cid == null)
 			url = "http://www.dataoke.com/top_all";
@@ -508,27 +546,31 @@
 	 * @param cid
 	 * @return
 	 */
-	public static List<DaTaoKeDetail> getCurrentHotSalesRank() {
+	public static List<DaTaoKeDetailV2> getCurrentHotSalesRank() {
 		String url = "http://www.dataoke.com/top_tui";
 		return parseCurrent(url);
 	}
 
-	private static String getRandomCommonEmoji() {
+	public static String getRandomCommonEmoji() {
 		return commonEmojis[(int) (Math.random() * commonEmojis.length)];
 	}
 
-	public static String getDesc(DaTaoKeDetail detail) {
+	
+	public static String getEvaluateEmojis() {
+		return evaluateEmojis[(int) (Math.random() * evaluateEmojis.length)];
+	}
+	
+	public static String getDesc(DaTaoKeDetailV2 detail) {
 
 		// 鏍囬+鍒稿悗浠�+鍖呴偖+鎻忚堪
-		String desc = detail.getdTitle();
+		String desc = detail.getDtitle();
 		desc += "\n";
 		desc += String.format("鍒稿悗浠�%s銆�%s鍏冦�戝寘閭鏉� ", Math.random() > 0.5 ? "馃挵" : "",
-				MoneyBigDecimalUtil.getWithNoZera(detail.getPrice()).toString())
+				MoneyBigDecimalUtil.getWithNoZera(detail.getActualPrice()).toString())
 				+ (Math.random() > 0.5 ? getRandomCommonEmoji() : "");
 		desc += "\n";
 		// desc += detail.getIntroduce();
-		String introduce = detail.getIntroduce().replace("锛�", ",").replace("銆�", ",").replace("锛�", ",").replace(",",
-				",");
+		String introduce = detail.getDesc().replace("锛�", ",").replace("銆�", ",").replace("锛�", ",").replace(",", ",");
 		introduce = introduce.replace(",,,", ",").replace(",,", ",");
 
 		String[] sts = introduce.split(",");
@@ -544,16 +586,6 @@
 		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) {
 			// 閲嶆柊璁剧疆鏍囬涓庡埜浠锋牸
@@ -564,29 +596,27 @@
 		return goods;
 	}
 
-	public static DaTaoKeDetail filterDaTaoKe(TaoBaoGoodsBrief goods, DaTaoKeDetail detail) {
+	public static DaTaoKeDetailV2 filterDaTaoKe(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 detail) {
 		if (goods != null) {
 			BigDecimal price = TaoBaoUtil.getAfterUseCouplePrice(goods);
-			detail.setOrgPrice(goods.getZkPrice());
-			detail.setPrice(price);
+			detail.setOriginalPrice(goods.getZkPrice());
+			detail.setActualPrice(price);
 			if (goods.getCouponStartFee() != null)
-				detail.setQuanCondition(goods.getCouponStartFee() + "");
-			detail.setQuanId(goods.getCouponActivityId());
-			detail.setQuanPrice(goods.getCouponAmount());
+				detail.setCouponConditions(goods.getCouponStartFee() + "");
+			detail.setCouponPrice(goods.getCouponAmount());
 			return detail;
 		}
 
 		return detail;
 	}
 
-	public static List<String> getDingDongQiangTime() {
+	public static List<DingDongTime> getDingDongQiangTime(Calendar nowDate) {
 
 		// 鑾峰彇褰撳墠鐨勫皬鏃舵暟
 		DingDongTime[] times = new DingDongTime[] { new DingDongTime("0", "00:00"), new DingDongTime("8", "08:00"),
 				new DingDongTime("10", "10:00"), new DingDongTime("13", "13:00"), new DingDongTime("15", "15:00"),
 				new DingDongTime("17", "17:00"), new DingDongTime("19", "19:00"), new DingDongTime("20", "20:00"),
 				new DingDongTime("21", "21:00") };
-		Calendar nowDate = Calendar.getInstance();
 		Calendar preDate = Calendar.getInstance();
 		preDate.setTimeInMillis(nowDate.getTimeInMillis() - 24 * 60 * 60 * 1000L);
 
@@ -601,7 +631,7 @@
 				? "0" + nowDate.get(Calendar.DAY_OF_MONTH) : nowDate.get(Calendar.DAY_OF_MONTH) + "";
 
 		int hour = nowDate.get(Calendar.HOUR_OF_DAY);
-		int pos = 0;
+		int pos = times.length - 1;
 		for (int i = 0; i < times.length - 1; i++) {
 			if (hour >= Integer.parseInt(times[i].getKey()) && hour < Integer.parseInt(times[i + 1].getKey())) {
 				pos = i;
@@ -611,37 +641,54 @@
 
 		List<DingDongTime> list = new ArrayList<>();
 
+		// 鑾峰彇褰撳墠鏃堕棿涔嬪墠鐨�5涓暟鎹�
 		for (int i = 5; i >= 0; i--) {
 			int p = pos - i < 0 ? (times.length + pos - i) : pos - i;
-			DingDongTime itemData = new DingDongTime(times[p].getKey(), times[p].getValue());
+			DingDongTime itemData = new DingDongTime(times[p].getKey(), times[p].getValue(), -1);
 			if (pos - i < 0)
 				itemData.setTime(
 						preDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
 			else
 				itemData.setTime(
 						nowDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
+
+			if (pos == p)
+				itemData.setState(0);
 			list.add(itemData);
 		}
 
+		// 鍚戝悗娣诲姞鍓╀笅鐨�
 		if (pos + 1 < times.length)
 			for (int i = pos + 1; i < times.length; i++) {
-				DingDongTime itemData = new DingDongTime(times[i].getKey(), times[i].getValue());
+				DingDongTime itemData = new DingDongTime(times[i].getKey(), times[i].getValue(), 1);
 				itemData.setTime(
 						nowDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
 				list.add(itemData);
 			}
 
 		if (times.length - (pos + 1) < 2) {
-			DingDongTime itemData = new DingDongTime(times[0].getKey(), times[0].getValue());
+			DingDongTime itemData = new DingDongTime(times[0].getKey(), times[0].getValue(), 1);
 			itemData.setTime(
 					nextDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
 			list.add(itemData);
 		}
+		return list;
+	}
 
-		List<String> finalTimeList = new ArrayList<>();
-		for (DingDongTime time : list)
-			finalTimeList.add(time.getTime());
-		return finalTimeList;
+	// 鑾峰彇鎺ㄥ箍鏂囨
+	public static void getPublishDoc(String id) {
+		String url = String.format("http://www.dataoke.com/detailtpl?gid=%s&type=1", id);
+		String response = HttpUtil.get(url);
+		try {
+			JSONObject json = JSONObject.fromObject(new String(response.getBytes("ISO-8859-1"), "UTF-8"));
+			JSONObject data = json.optJSONObject("data");
+			String tpl2 = data.optString("tpl2");
+			tpl2 = tpl2.substring(0, tpl2.indexOf("---------"));
+			System.out.println(tpl2.replace("</br>", "\n").trim());
+		} catch (Exception e) {
+
+		}
+
 	}
 
 }

--
Gitblit v1.8.0