From 3824cbcaec6e6c67418d5280a53e9c2fedeef6f9 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 11 七月 2019 16:34:13 +0800 Subject: [PATCH] 订单bug,分享爆款自购修改 --- fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java | 165 +++++++++++++++++++++++++++---------------------------- 1 files changed, 81 insertions(+), 84 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..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; @@ -20,10 +18,10 @@ 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; @@ -99,30 +97,29 @@ "馃専",// 鍙戝厜鐨勬槦鏄� }; - static final String[] timeEmojis = new String[] { - "馃暃",// 鍗佷簩鐐� - "馃暓",// 鍗佷簩鐐瑰崐 - "馃晲",// 涓�鐐归挓 - "馃暅",// 涓�鐐瑰崐 - "馃晳",// 涓ょ偣 - "馃暆",// 涓ょ偣鍗� - "馃晵",// 涓夌偣閽� - "馃暈",// 涓夌偣鍗� - "馃晸",// 鍥涚偣閽� - "馃暉",// 鍥涚偣鍗� - "馃晹",// 浜旀椂 - "馃暊",// 浜旂偣鍗� - "馃晻",// 鍏偣 - "馃暋",// 鍏偣鍗� - "馃晼",// 涓冪偣 - "馃暍",// 涓冪偣鍗� - "馃晽",// 鍏偣 - "馃暎",// 鍏偣鍗� - "馃晿",// 涔濈偣閽� - "馃暏",// 涔濈偣鍗� - "馃暀",// 鐨勫崄鐐� - "馃暐",// 鍗佺偣鍗� - "馃暁",// 鍗佷竴鐐� + static final String[] timeEmojis = new String[] { "馃暃", // 鍗佷簩鐐� + "馃暓", // 鍗佷簩鐐瑰崐 + "馃晲", // 涓�鐐归挓 + "馃暅", // 涓�鐐瑰崐 + "馃晳", // 涓ょ偣 + "馃暆", // 涓ょ偣鍗� + "馃晵", // 涓夌偣閽� + "馃暈", // 涓夌偣鍗� + "馃晸", // 鍥涚偣閽� + "馃暉", // 鍥涚偣鍗� + "馃晹", // 浜旀椂 + "馃暊", // 浜旂偣鍗� + "馃晻", // 鍏偣 + "馃暋", // 鍏偣鍗� + "馃晼", // 涓冪偣 + "馃暍", // 涓冪偣鍗� + "馃晽", // 鍏偣 + "馃暎", // 鍏偣鍗� + "馃晿", // 涔濈偣閽� + "馃暏", // 涔濈偣鍗� + "馃暀", // 鐨勫崄鐐� + "馃暐", // 鍗佺偣鍗� + "馃暁", // 鍗佷竴鐐� "馃暒",// 鍗佷竴鐐瑰崐 }; @@ -367,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; - } // @@ -456,8 +414,8 @@ } private static List<DaTaoKeDetail> parseCurrent(String url) { - - List<DaTaoKeDetail> list=new ArrayList<>(); + + List<DaTaoKeDetail> list = new ArrayList<>(); try { Document doc = Jsoup.connect(url) .userAgent( @@ -471,7 +429,7 @@ .getElementsByTag("b").get(0).text(); System.out.println(id + "-" + currentSale); - DaTaoKeDetail detail=new DaTaoKeDetail(); + DaTaoKeDetail detail = new DaTaoKeDetail(); detail.setId(id); detail.setSalesNum(Integer.parseInt(currentSale)); list.add(detail); @@ -528,16 +486,55 @@ return parseCurrent(url); } + private static String getRandomCommonEmoji() { + return commonEmojis[(int) (Math.random() * commonEmojis.length)]; + } + public static String getDesc(DaTaoKeDetail 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.getPrice()).toString()) + + (Math.random() > 0.5 ? getRandomCommonEmoji() : ""); desc += "\n"; - desc += detail.getIntroduce(); + // 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