From 298251cfb5014e18fe25191f65bb65a0fca32904 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 08 八月 2019 18:52:47 +0800 Subject: [PATCH] 增加拼多多与京东商品爬取JS --- fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailV2ServiceImpl.java | 54 +++++++++++++++++++++++++++++++++--------------------- 1 files changed, 33 insertions(+), 21 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailV2ServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailV2ServiceImpl.java index 92863ae..d69a4d6 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailV2ServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailV2ServiceImpl.java @@ -40,24 +40,37 @@ @Override public void startSyncGoods() { LogHelper.test("澶ф窐瀹㈠悓姝ュ紑濮�"); - DaTaoKeGoodsResult result = DaTaoKeApiUtil.listAll("1"); - int page = 0; - while (result.getGoodsList() != null && result.getGoodsList().size() > 0) { - System.out.println(page++); - for (DaTaoKeDetailV2 v2 : result.getGoodsList()) - { - try { - daTaoKeGoodsDetailV2Dao.saveWithCommision(v2); - } catch (Exception e) { + + int totalCount = 0; + try { + + DaTaoKeGoodsResult result = DaTaoKeApiUtil.listAll("1"); + int page = 0; + + while (result.getGoodsList() != null && result.getGoodsList().size() > 0) { + System.out.println(page++); + totalCount += result.getGoodsList().size(); + for (DaTaoKeDetailV2 v2 : result.getGoodsList()) { + try { + daTaoKeGoodsDetailV2Dao.saveWithCommision(v2); + } catch (Exception e) { + } } - + + try { + result = DaTaoKeApiUtil.listAll(result.getPageId()); + } catch (Exception e) { + result = DaTaoKeApiUtil.listAll(result.getPageId()); + } + + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } } - result = DaTaoKeApiUtil.listAll(result.getPageId()); - try { - Thread.sleep(10); - } catch (InterruptedException e) { - e.printStackTrace(); - } + } finally { + LogHelper.test("澶ф窐瀹㈡柊鐗堝晢鍝佸悓姝ユ暟閲�:" + totalCount); } } @@ -103,7 +116,7 @@ String startTime = null; DaTaoKeDetailV2 latest = daTaoKeGoodsDetailV2Dao.selectLatest(); if (latest != null) { - startTime =TimeUtil.getGernalTime(latest.getCreateTime().getTime(),"yyyy-MM-dd HH:mm:ss"); + startTime = TimeUtil.getGernalTime(latest.getCreateTime().getTime(), "yyyy-MM-dd HH:mm:ss"); } DaTaoKeGoodsResult result = DaTaoKeApiUtil.getNewGoodsList(null, startTime, null); while (!StringUtil.isNullOrEmpty(result.getPageId())) { @@ -199,8 +212,7 @@ @Override public List<DaTaoKeDetailV2> listPreShareHotGoods(int page) { Map<Long, DaTaoKeDetailV2> map = new HashMap<>(); - List<DaTaoKeDetailV2> list = daTaoKeGoodsDetailV2Dao.listPreShareHotGoods((page - 1) *100, - 100, "monthSales"); + List<DaTaoKeDetailV2> list = daTaoKeGoodsDetailV2Dao.listPreShareHotGoods((page - 1) * 100, 100, "monthSales"); System.out.println(list); for (DaTaoKeDetailV2 v2 : list) { map.put(v2.getId(), v2); @@ -235,7 +247,7 @@ for (DaTaoKeDetailV2 v2 : result.getGoodsList()) { BigDecimal commision = MoneyBigDecimalUtil .div(MoneyBigDecimalUtil.mul(v2.getActualPrice(), v2.getCommissionRate()), new BigDecimal(100)); - + if (commision.multiply(new BigDecimal("0.7")).compareTo(new BigDecimal("1.01")) >= 0 && v2.getActualPrice().compareTo(new BigDecimal(30)) < 0 && v2.getMonthSales() >= 5000) { Date time = new Date(TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss")); @@ -252,7 +264,7 @@ } if (time.getTime() >= targetTime.getTime()) goodsList.add(v2); - } + } } return goodsList; } else -- Gitblit v1.8.0