From ec60e757d358636dcac1589c44a66f3e276fe58c Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期一, 29 六月 2020 14:41:42 +0800 Subject: [PATCH] 拉新 --- fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java | 208 +++++++++++++++++++++++++++++++++++---------------- 1 files changed, 143 insertions(+), 65 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java b/fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java index 977fb72..c17a307 100644 --- a/fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java +++ b/fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java @@ -1,12 +1,14 @@ package com.yeshi.fanli.job; import java.math.BigDecimal; +import java.net.URLDecoder; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.annotation.Resource; +import org.apache.commons.lang.StringEscapeUtils; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.yeshi.utils.DateUtil; @@ -16,6 +18,7 @@ import com.yeshi.fanli.dto.ConfigParamsDTO; import com.yeshi.fanli.dto.dataoke.DaTaoKeGoodsResult; import com.yeshi.fanli.dto.taobao.haodanku.HDKGoodsListResultDTO; +import com.yeshi.fanli.dto.taobao.haodanku.HDKWXCircleContentDTO; import com.yeshi.fanli.entity.bus.activity.ActivityRuleUser; import com.yeshi.fanli.entity.bus.activity.ActivityUser; import com.yeshi.fanli.entity.bus.activity.RecommendActivity; @@ -42,9 +45,11 @@ import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil; import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory; +import com.yeshi.fanli.util.factory.goods.TaoBaoGoodsFactory; import com.yeshi.fanli.util.jd.JDApiUtil; import com.yeshi.fanli.util.jd.JDUtil; import com.yeshi.fanli.util.taobao.HaoDanKuApiUtil; +import com.yeshi.fanli.util.taobao.TaoBaoUtil; @Component public class DynamicInfoJob { @@ -362,71 +367,6 @@ /** - * 濂藉崟搴撳晢鍝佸姞鍏ュ彂鍦� - */ - @XxlJob("dynamic-insertEvaluate") - public ReturnT<String> insertEvaluate(String param) throws Exception { - try { - boolean addGoods = false; - Integer minId = 1; - while (minId != null) { - HDKGoodsListResultDTO dto = HaoDanKuApiUtil.getInstance().listHotGoods(minId, 100, 1, null); - if (dto != null) { - minId = dto.getMinId(); - addGoods = addGoodsEvaluate(dto.getGoodsList()); - } else { - minId = null; - } - - if(addGoods) { - break; - } - } - - // 澶ф窐瀹㈠鐢� - if (!addGoods) { - DaTaoKeGoodsResult result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_TIME, null); - if (result != null) { - List<DaTaoKeDetailV2> detailList = result.getGoodsList(); - if (detailList != null && detailList.size() > 0) { - for (DaTaoKeDetailV2 daTaoKeV2: detailList) { - if(goodsEvaluateService.addByDaTaoKeGoods(daTaoKeV2)) - break; - } - } - } - } - } catch (Exception e) { - LogHelper.errorDetailInfo(e); - } - return ReturnT.SUCCESS; - } - - - private boolean addGoodsEvaluate(List<HDKGoodsDetail> hdkList) { - if (hdkList == null || hdkList.size() == 0) { - return false; - } - for (HDKGoodsDetail hdkGoods: hdkList) { - try { - Long itemid = hdkGoods.getItemid(); - String itemdesc = hdkGoods.getItemdesc(); - List<ActivityRuleUser> ruleList = activityUserService.listByRuleCode(ActivityRuleUser.RULE_HAOHUO, 1, 20); - ActivityUser user = ruleList.get((int) (ruleList.size() * Math.random())).getActivityUser(); - goodsEvaluateService.addGoodsEvaluate(itemid + "", null, user, itemdesc, null, new Date()); - return true; - } catch (GoodsEvaluateException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } - return false; - } - - - - /** * 姣忎竴涓皬鏃堕殢鏈哄湪鍒嗕韩鏁扮殑鍩虹涓婂姞10~100銆傚鍔犵殑鏃堕棿娈垫槸姣忓ぉ8~22鐐广�� * 鏃╀笂6,7,15,16,21,22,23鐐规洿鏂�1娆� */ @@ -446,4 +386,142 @@ } } } + + + /** + * 鍟嗗搧鍔犲叆鍙戝湀 + */ + @XxlJob("dynamic-insertEvaluate") + public ReturnT<String> insertEvaluate(String param) throws Exception { + // 濂藉崟搴� + boolean addResult = addHDKListSelected(); + // 澶ф窐瀹㈠鐢� + if (!addResult) { + addDTKFriendsFircleList(); + } + return ReturnT.SUCCESS; + } + + + /** + * 濂藉崟搴撳晢鍝佸姞鍏ュ彂鍦� + * @return + */ + private boolean addHDKListSelected () { + boolean addResult = false; + Integer minId = 1; + while (minId != null) { + HDKGoodsListResultDTO dto = HaoDanKuApiUtil.getInstance().listSelected(minId); + if (dto == null) { + minId = null; + } else { + minId = dto.getMinId(); + List<HDKWXCircleContentDTO> list = dto.getList(); + if (list== null || list.size() == 0) { + continue; + } + + for (HDKWXCircleContentDTO circleContentDTO: list) { + try { + String itemid = circleContentDTO.getItemid(); + HDKGoodsDetail hdkGoods = HaoDanKuApiUtil.getInstance().getItemDetail(itemid); + if (hdkGoods == null) { + continue; + } + + List<String> pics = circleContentDTO.getItempic(); + String copy_content = circleContentDTO.getCopy_content(); + String showtitle = StringEscapeUtils.unescapeHtml(copy_content); + showtitle = showtitle.replace("<br>", "\r\n"); + + List<ActivityRuleUser> ruleList = activityUserService.listByRuleCode(ActivityRuleUser.RULE_HAOHUO, 1, 20); + ActivityUser user = ruleList.get((int) (ruleList.size() * Math.random())).getActivityUser(); + + int addProcess = goodsEvaluateService.addGoodsEvaluate(TaoBaoGoodsFactory.create(hdkGoods), pics, user, showtitle); + if (addProcess == 0) { + addResult = true; + break; + } + } catch (GoodsEvaluateException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + if(addResult) + break; + } + return addResult; + } + + + /** + * 澶ф窐瀹㈠晢鍝佸姞鍏ュ彂鍦� + * @return + */ + private boolean addDTKFriendsFircleList() { + boolean addResult = false; + try { + DaTaoKeGoodsResult result = DaTaoKeApiUtil.getFriendsFircleList("1", 100); + while (result.getGoodsList() != null && result.getGoodsList().size() > 0) { + for (DaTaoKeDetailV2 detailV2 : result.getGoodsList()) { + try { + Long goodsId = detailV2.getGoodsId(); + + String circleText = detailV2.getCircleText(); + if (circleText == null) { + continue; + } + String showtitle = URLDecoder.decode(circleText, "UTF-8"); + showtitle = showtitle.replace(" ", " "); + + DaTaoKeDetailV2 tkGoods = DaTaoKeApiUtil.getGoodsDetailByGoodsId(goodsId); + if(tkGoods == null) { + continue; + } + + ActivityUser user = null; + if (detailV2.getCid() != null) { + user = activityUserService.getRandomByDaTaoKeCid(detailV2.getCid()); + } + if (user == null) { + List<ActivityRuleUser> ruleList = activityUserService + .listByRuleCode(ActivityRuleUser.RULE_HAOHUO, 1, 20); + user = ruleList.get((int) (ruleList.size() * Math.random())).getActivityUser(); + } + + int addProcess = goodsEvaluateService.addGoodsEvaluate(TaoBaoUtil.convert(tkGoods), null, user, showtitle); + if (addProcess == 0) { + addResult = true; + break; + } + } catch (GoodsEvaluateException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + if (addResult) { + break; + } + + try { + result = DaTaoKeApiUtil.getFriendsFircleList(result.getPageId(), 100); + } catch (Exception e) { + result = DaTaoKeApiUtil.getFriendsFircleList(result.getPageId(), 100); + } + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + LogHelper.errorDetailInfo(e); + } + return addResult; + } + } -- Gitblit v1.8.0