From 28cf328a098334b51a3e9d2d56f983fb8c862211 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 23 五月 2020 09:54:38 +0800
Subject: [PATCH] 足迹、收藏订单兼容新需求

---
 fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java |  392 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 299 insertions(+), 93 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 3e0c5e3..6f14c5b 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,21 +5,29 @@
 import java.math.BigDecimal;
 import java.net.URLEncoder;
 import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Calendar;
 import java.util.Iterator;
 import java.util.List;
+
+import javax.script.Invocable;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
 
 import org.jsoup.Jsoup;
 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;
+import com.yeshi.fanli.dto.taobao.DaTaoKeFilterResult;
 import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
 import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
 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;
@@ -99,32 +107,35 @@
 			"馃専",// 鍙戝厜鐨勬槦鏄�
 	};
 
-	static final String[] timeEmojis = new String[] { 
-			"馃暃",// 鍗佷簩鐐�
-			"馃暓",// 鍗佷簩鐐瑰崐
-			"馃晲",// 涓�鐐归挓
-			"馃暅",// 涓�鐐瑰崐
-			"馃晳",// 涓ょ偣
-			"馃暆",// 涓ょ偣鍗�
-			"馃晵",// 涓夌偣閽�
-			"馃暈",// 涓夌偣鍗�
-			"馃晸",// 鍥涚偣閽�
-			"馃暉",// 鍥涚偣鍗�
-			"馃晹",// 浜旀椂
-			"馃暊",// 浜旂偣鍗�
-			"馃晻",// 鍏偣
-			"馃暋",// 鍏偣鍗�
-			"馃晼",// 涓冪偣
-			"馃暍",// 涓冪偣鍗�
-			"馃晽",// 鍏偣
-			"馃暎",// 鍏偣鍗�
-			"馃晿",// 涔濈偣閽�
-			"馃暏",// 涔濈偣鍗�
-			"馃暀",// 鐨勫崄鐐�
-			"馃暐",// 鍗佺偣鍗�
-			"馃暁",// 鍗佷竴鐐�
+	static final String[] timeEmojis = new String[] { "馃暃", // 鍗佷簩鐐�
+			"馃暓", // 鍗佷簩鐐瑰崐
+			"馃晲", // 涓�鐐归挓
+			"馃暅", // 涓�鐐瑰崐
+			"馃晳", // 涓ょ偣
+			"馃暆", // 涓ょ偣鍗�
+			"馃晵", // 涓夌偣閽�
+			"馃暈", // 涓夌偣鍗�
+			"馃晸", // 鍥涚偣閽�
+			"馃暉", // 鍥涚偣鍗�
+			"馃晹", // 浜旀椂
+			"馃暊", // 浜旂偣鍗�
+			"馃晻", // 鍏偣
+			"馃暋", // 鍏偣鍗�
+			"馃晼", // 涓冪偣
+			"馃暍", // 涓冪偣鍗�
+			"馃晽", // 鍏偣
+			"馃暎", // 鍏偣鍗�
+			"馃晿", // 涔濈偣閽�
+			"馃暏", // 涔濈偣鍗�
+			"馃暀", // 鐨勫崄鐐�
+			"馃暐", // 鍗佺偣鍗�
+			"馃暁", // 鍗佷竴鐐�
 			"馃暒",// 鍗佷竴鐐瑰崐
 	};
+
+	static final String[] evaluateEmojis = new String[] { "馃挓", "馃尭", "馃嵏", "馃嵑", "馃摙", "鉂�", "馃挐", "馃拫", "馃憶", "馃惥",
+			"馃尮", "馃敟", "馃帀", "馃巵", "馃崶", "馃嵀", "馃尯", "馃憫", "鉁�", "馃挮", "馃嵒", "馃巿", "馃挜", "馃挄", "馃挒", "馃挵", "馃拰", "馃挱",
+			"馃尲", "馃崁" };
 
 	public static List<GoodsClass> goodsClasses;
 	static {
@@ -367,67 +378,50 @@
 	 * 
 	 * @return
 	 */
-	public static List<TaoBaoGoodsBrief> getDingDongQiang() {
-		List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
+	public static List<DingDongQiangDTO> getDingDongQiang() {
+		List<DingDongQiangDTO> list = new ArrayList<>();
+		Document doc = null;
 		try {
-			Document doc = Jsoup.connect("http://dataoke.yeshitv.com/index.php?r=ddq/wap")
-					.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"));
+			doc = Jsoup.connect("http://www.dataoke.com/ddq").userAgent("").get();
+		} 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();
+			if (content.indexOf("var dataDef") > -1) {
+				ScriptEngineManager manager = new ScriptEngineManager();
+				ScriptEngine engine = manager.getEngineByName("javascript");
+				try {
+					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;
+						String data = in.invokeFunction("getData").toString();
+						System.out.println(data);
+						JSONObject dataJson = JSONObject.fromObject(data);
+						for (Iterator<String> its = dataJson.keys(); its.hasNext();) {
+							String key = its.next();
+							JSONArray array = dataJson.optJSONArray(key);
+							List<DaTaoKeDetailV2> detailList = new ArrayList<>();
+							for (int n = 0; n < array.size(); n++) {
+								DaTaoKeDetailV2 v2 = new DaTaoKeDetailV2();
+								v2.setId(array.optJSONObject(n).optLong("id"));
+								detailList.add(v2);
+							}
+							list.add(new DingDongQiangDTO(key, detailList));
 						}
 					}
-					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) {
-
-						}
-
-					});
-
+				} catch (Exception e) {
+					e.printStackTrace();
 				}
-
 			}
-
-		} catch (IOException e) {
-			e.printStackTrace();
 		}
-
-		return goodsList;
-
+		return list;
 	}
-
-	//
 
 	public static List<TaoBaoCoupon> getRecommendCouple() {
 		List<TaoBaoCoupon> couponList = new ArrayList<>();
@@ -455,9 +449,9 @@
 		return couponList;
 	}
 
-	private static List<DaTaoKeDetail> parseCurrent(String url) {
-		
-		List<DaTaoKeDetail> list=new ArrayList<>();
+	private static List<DaTaoKeDetailV2> parseCurrent(String url) {
+
+		List<DaTaoKeDetailV2> list = new ArrayList<>();
 		try {
 			Document doc = Jsoup.connect(url)
 					.userAgent(
@@ -471,9 +465,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);
 
 			}
@@ -493,7 +487,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";
@@ -508,7 +502,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";
@@ -523,21 +517,233 @@
 	 * @param cid
 	 * @return
 	 */
-	public static List<DaTaoKeDetail> getCurrentHotSalesRank() {
+	public static List<DaTaoKeDetailV2> getCurrentHotSalesRank() {
 		String url = "http://www.dataoke.com/top_tui";
 		return parseCurrent(url);
 	}
 
-	public static String getDesc(DaTaoKeDetail detail) {
+	public static String getRandomCommonEmoji() {
+		return commonEmojis[(int) (Math.random() * commonEmojis.length)];
+	}
+
+	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鍏冦�戝寘閭鏉� ", MoneyBigDecimalUtil.getWithNoZera(detail.getPrice()).toString())
-				+ "馃槢";
+		desc += String.format("鍒稿悗浠�%s銆�%s鍏冦�戝寘閭鏉� ", Math.random() > 0.5 ? "馃挵" : "",
+				MoneyBigDecimalUtil.getWithNoZera(detail.getActualPrice()).toString())
+				+ (Math.random() > 0.5 ? getRandomCommonEmoji() : "");
 		desc += "\n";
-		desc += detail.getIntroduce();
+		// desc += detail.getIntroduce();
+		String introduce = detail.getDesc().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 DaTaoKeFilterResult filterTaoBaoGoods(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 v2,
+			boolean filterCouponInfo) {
+		if (v2 != null && goods != null) {
+			// 閲嶆柊璁剧疆鏍囬涓庡埜浠锋牸
+			goods.setTitle(v2.getDtitle());
+			if (!StringUtil.isNullOrEmpty(v2.getMainPic()))
+				goods.setPictUrlWhite(v2.getMainPic());
+			// 璁剧疆绠�浠�
+
+			goods.setDescription(v2.getDesc());
+			// 濡傛灉娌℃湁鍒镐俊鎭�,鍒欐彁渚涘埜淇℃伅
+			if (canFilterCouponInfo(goods, v2)) {
+				try {
+					long time = System.currentTimeMillis();
+					// 鍒稿湪鏈夋晥鏈熷唴骞朵笖杩樻湁鍓╀綑鍒�
+					if (time >= TimeUtil.convertToTimeTemp(v2.getCouponStartTime(), "yyyy-MM-dd HH:mm:ss")
+							&& time <= TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss")
+							&& (v2.getCouponTotalNum() - v2.getCouponReceiveNum()) > 0) {
+						goods.setCouponStartFee(v2.getOriginalPrice());
+
+						goods.setCouponEffectiveEndTime(TimeUtil.getGernalTime(
+								TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss"),
+								"yyyy-MM-dd"));
+						goods.setCouponEffectiveStartTime(TimeUtil.getGernalTime(
+								TimeUtil.convertToTimeTemp(v2.getCouponStartTime(), "yyyy-MM-dd HH:mm:ss"),
+								"yyyy-MM-dd"));
+
+						goods.setCouponAmount(v2.getCouponPrice());
+						goods.setCouponInfo(
+								String.format("婊�%s鍏冨噺%s鍏�", v2.getOriginalPrice() + "", v2.getCouponPrice() + ""));
+						goods.setCouponLeftCount(v2.getCouponTotalNum() - v2.getCouponReceiveNum());
+						goods.setCouponLink(v2.getCouponLink());
+						goods.setCouponTotalCount(v2.getCouponTotalNum());
+						goods.setShopCoupon(false);
+						goods.setZkPrice(v2.getOriginalPrice());
+						return new DaTaoKeFilterResult(goods, DaTaoKeFilterResult.FILTER_TYPE_PRICE_AND_COUPON);
+					}
+
+				} catch (Exception e) {
+
+				}
+			} else {// 閮芥湁鍒�
+				long time = System.currentTimeMillis();
+				// 鍒稿湪鏈夋晥鏈熷唴骞朵笖杩樻湁鍓╀綑鍒�
+				if (time >= TimeUtil.convertToTimeTemp(v2.getCouponStartTime(), "yyyy-MM-dd HH:mm:ss")
+						&& time <= TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss")
+						&& (v2.getCouponTotalNum() - v2.getCouponReceiveNum()) > 0) {
+					// 濡傛灉涓や釜鍒哥殑闈㈤涓�鏍凤紝娣樺疂鍘熶环姣斿ぇ娣樺鍘熶环楂橈紝灏变互澶ф窐瀹㈠師浠蜂负鍑�
+					if (goods.getCouponAmount() != null && v2.getCouponPrice() != null
+							&& goods.getCouponAmount().compareTo(v2.getCouponPrice()) == 0) {
+
+						if (goods.getZkPrice().compareTo(v2.getOriginalPrice()) > 0) {
+							goods.setZkPrice(v2.getOriginalPrice());
+							return new DaTaoKeFilterResult(goods, DaTaoKeFilterResult.FILTER_TYPE_PRICE);
+						}
+					}
+				}
+			}
+		}
+		return new DaTaoKeFilterResult(goods, DaTaoKeFilterResult.FILTER_TYPE_NONE);
+	}
+
+	/**
+	 * 鏄惁鍙互杩囨护鎺夊埜淇℃伅
+	 * @Title: filterCouponInfo
+	 * @Description: 
+	 * @param goods
+	 * @param v2 
+	 * void 杩斿洖绫诲瀷
+	 * @throws
+	 */
+	public static boolean canFilterCouponInfo(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 v2) {
+		if (StringUtil.isNullOrEmpty(goods.getCouponInfo()) && v2 != null
+				&& !StringUtil.isNullOrEmpty(v2.getCouponLink())) {
+			try {
+				long time = System.currentTimeMillis();
+				// 鍒稿湪鏈夋晥鏈熷唴骞朵笖杩樻湁鍓╀綑鍒�
+				if (time >= TimeUtil.convertToTimeTemp(v2.getCouponStartTime(), "yyyy-MM-dd HH:mm:ss")
+						&& time <= TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss")
+						&& (v2.getCouponTotalNum() - v2.getCouponReceiveNum()) > 0) {
+					return true;
+				}
+
+			} catch (Exception e) {
+
+			}
+		}
+
+		return false;
+	}
+
+	public static TaoBaoGoodsBrief filterTaoBaoGoods(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 v2) {
+		return filterTaoBaoGoods(goods, v2, false).getGoods();
+	}
+
+	public static DaTaoKeDetailV2 filterDaTaoKe(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 detail) {
+		if (goods != null) {
+			BigDecimal price = TaoBaoUtil.getAfterUseCouplePrice(goods);
+			detail.setOriginalPrice(goods.getZkPrice());
+			detail.setActualPrice(price);
+			if (goods.getCouponStartFee() != null)
+				detail.setCouponConditions(goods.getCouponStartFee() + "");
+			detail.setCouponPrice(goods.getCouponAmount());
+			return detail;
+		}
+
+		return detail;
+	}
+
+	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 preDate = Calendar.getInstance();
+		preDate.setTimeInMillis(nowDate.getTimeInMillis() - 24 * 60 * 60 * 1000L);
+
+		Calendar nextDate = Calendar.getInstance();
+		nextDate.setTimeInMillis(nowDate.getTimeInMillis() + 24 * 60 * 60 * 1000L);
+
+		String preDay = (preDate.get(Calendar.DAY_OF_MONTH) + "").length() < 2
+				? "0" + preDate.get(Calendar.DAY_OF_MONTH) : preDate.get(Calendar.DAY_OF_MONTH) + "";
+		String nextDay = (nextDate.get(Calendar.DAY_OF_MONTH) + "").length() < 2
+				? "0" + nextDate.get(Calendar.DAY_OF_MONTH) : nextDate.get(Calendar.DAY_OF_MONTH) + "";
+		String nowDay = (nowDate.get(Calendar.DAY_OF_MONTH) + "").length() < 2
+				? "0" + nowDate.get(Calendar.DAY_OF_MONTH) : nowDate.get(Calendar.DAY_OF_MONTH) + "";
+
+		int hour = nowDate.get(Calendar.HOUR_OF_DAY);
+		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;
+				break;
+			}
+		}
+
+		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(), -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(), 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(), 1);
+			itemData.setTime(
+					nextDay + "" + (itemData.getKey().length() < 2 ? ("0" + itemData.getKey()) : itemData.getKey()));
+			list.add(itemData);
+		}
+		return list;
+	}
+
+	// 鑾峰彇鎺ㄥ箍鏂囨
+	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