From 51a4ff5d777028d52a19c314a99f796334cb7b51 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 23 十一月 2019 18:30:01 +0800 Subject: [PATCH] 配置文件修改 --- fanli/src/main/java/com/yeshi/fanli/util/taobao/DaTaoKeUtil.java | 172 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 133 insertions(+), 39 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 4c74dc1..9d20dc1 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,13 +5,22 @@ import java.math.BigDecimal; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +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 com.yeshi.fanli.dto.dataoke.DingDongQiangDTO; +import com.yeshi.fanli.dto.dataoke.DingDongTime; import com.yeshi.fanli.entity.bus.clazz.GoodsClass; import com.yeshi.fanli.entity.taobao.TaoBaoCoupon; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; @@ -364,28 +373,47 @@ * * @return */ - public static List<DaTaoKeDetail> getDingDongQiang() { - List<DaTaoKeDetail> goodsList = new ArrayList<>(); + public static List<DingDongQiangDTO> getDingDongQiang() { + List<DingDongQiangDTO> list = new ArrayList<>(); + Document doc = null; try { - 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 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) { - + doc = Jsoup.connect("http://www.dataoke.com/ddq").userAgent("").get(); + } catch (IOException e1) { + e1.printStackTrace(); } - return goodsList; + 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)); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return list; } - - // public static List<TaoBaoCoupon> getRecommendCouple() { List<TaoBaoCoupon> couponList = new ArrayList<>(); @@ -518,37 +546,103 @@ } public static TaoBaoGoodsBrief filterTaoBaoGoods(TaoBaoGoodsBrief goods, DaTaoKeDetail detail) { - if (detail != null) { + if (detail != null && goods != null) { // 閲嶆柊璁剧疆鏍囬涓庡埜浠锋牸 goods.setTitle(detail.getdTitle()); - if (goods.getCouponAmount() != null && detail.getQuanPrice() != null - && goods.getCouponAmount().compareTo(detail.getQuanPrice()) < 0) - goods.setCouponAmount(detail.getQuanPrice()); - goods.setZkPrice(detail.getOrgPrice()); - if (new BigDecimal(detail.getQuanCondition()).compareTo(new BigDecimal(0)) > 0) - goods.setCouponInfo(String.format("婊�%s鍏冨噺%s鍏�", detail.getQuanCondition(), - MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()).toString())); - else - goods.setCouponInfo(String.format("%s鍏冩棤鏉′欢鍒�", goods.getCouponAmount())); + if (!StringUtil.isNullOrEmpty(detail.getPic())) + goods.setPictUrlWhite(detail.getPic()); } return goods; } public static TaoBaoGoodsBrief filterTaoBaoGoods(TaoBaoGoodsBrief goods, DaTaoKeDetailV2 detail) { - if (detail != null) { + if (detail != null && goods != null) { // 閲嶆柊璁剧疆鏍囬涓庡埜浠锋牸 goods.setTitle(detail.getDtitle()); - if (goods.getCouponAmount() != null && detail.getCouponPrice() != null - && goods.getCouponAmount().compareTo(detail.getCouponPrice()) < 0) - goods.setCouponAmount(detail.getCouponPrice()); - goods.setZkPrice(detail.getOriginalPrice()); - if (new BigDecimal(detail.getCouponConditions()).compareTo(new BigDecimal(0)) > 0) - goods.setCouponInfo(String.format("婊�%s鍏冨噺%s鍏�", detail.getCouponConditions(), - MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()).toString())); - else - goods.setCouponInfo(String.format("%s鍏冩棤鏉′欢鍒�", goods.getCouponAmount())); + if (!StringUtil.isNullOrEmpty(detail.getMainPic())) + goods.setPictUrlWhite(detail.getMainPic()); } return goods; } + public static DaTaoKeDetail filterDaTaoKe(TaoBaoGoodsBrief goods, DaTaoKeDetail detail) { + if (goods != null) { + BigDecimal price = TaoBaoUtil.getAfterUseCouplePrice(goods); + detail.setOrgPrice(goods.getZkPrice()); + detail.setPrice(price); + if (goods.getCouponStartFee() != null) + detail.setQuanCondition(goods.getCouponStartFee() + ""); + detail.setQuanId(goods.getCouponActivityId()); + detail.setQuanPrice(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; + } + } -- Gitblit v1.8.0