| | |
| | | package com.yeshi.fanli.job;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | |
| | | import org.springframework.stereotype.Component;
|
| | | import org.yeshi.utils.DateUtil;
|
| | |
|
| | | import com.xxl.job.core.biz.model.ReturnT;
|
| | | import com.xxl.job.core.handler.annotation.XxlJob;
|
| | | import com.yeshi.fanli.dto.ConfigParamsDTO;
|
| | | import com.yeshi.fanli.entity.bus.activity.RecommendActivity;
|
| | | import com.yeshi.fanli.entity.bus.activity.RecommendActivityInviteInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
|
| | | import com.yeshi.fanli.entity.dynamic.GoodsPicture;
|
| | | import com.yeshi.fanli.entity.dynamic.WXMPDynamicInfo;
|
| | | import com.yeshi.fanli.entity.goods.jd.NYouHuiGoods;
|
| | | import com.yeshi.fanli.entity.jd.JDGoods;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.activity.ActivityService;
|
| | | import com.yeshi.fanli.service.inter.activity.ActivityUserService;
|
| | | import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
|
| | | import com.yeshi.fanli.service.inter.dynamic.DynamicInfoService;
|
| | | import com.yeshi.fanli.service.inter.dynamic.GoodsEvaluateService;
|
| | | import com.yeshi.fanli.service.inter.dynamic.WXMPDynamicInfoService;
|
| | | import com.yeshi.fanli.service.inter.goods.jd.NYouHuiService;
|
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.manger.goods.ConvertLinkManager;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
|
| | | import com.yeshi.fanli.util.jd.JDApiUtil;
|
| | | import com.yeshi.fanli.util.jd.JDUtil;
|
| | |
|
| | | @Component
|
| | | public class DynamicInfoJob {
|
| | | |
| | |
|
| | | @Resource
|
| | | private DynamicInfoService dynamicInfoService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private ActivityService activityService;
|
| | | |
| | | |
| | |
|
| | | @Resource
|
| | | private NYouHuiService nyouHuiService;
|
| | |
|
| | | @Resource
|
| | | private ActivityUserService activityUserService;
|
| | |
|
| | | @Resource
|
| | | private WXMPDynamicInfoService wxmpDynamicInfoService;
|
| | |
|
| | | @Resource
|
| | | private ConvertLinkManager convertLinkManager;
|
| | |
|
| | | @Resource
|
| | | private HongBaoManageService hongBaoManageService;
|
| | |
|
| | | @Resource
|
| | | private JumpDetailV2Service jumpDetailV2Service;
|
| | |
|
| | | @Resource
|
| | | private GoodsEvaluateService goodsEvaluateService;
|
| | |
|
| | | /**
|
| | | * 每10分钟 晚上00:00~06:00不下发任何一个商品
|
| | | * 每10分钟 晚上00:00~06:00不下发任何一个商品
|
| | | */
|
| | | @Scheduled(cron = "0 0/10 6-23 * * ?")
|
| | | public void insetDynamicInfo() {
|
| | | |
| | |
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | try {
|
| | | dynamicInfoService.insertTimeHotSale();
|
| | | } catch (Exception e) {
|
| | |
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | try {
|
| | | dynamicInfoService.insertTimeRecommend();
|
| | | } catch (Exception e) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 早上6,7,15,16,21,22,23点更新1次
|
| | | */
|
| | | @Scheduled(cron = "0 0 6,7,15,16,21,22,23 * * ? ")
|
| | | public void insetShopInfo1() {
|
| | | |
| | |
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | try {
|
| | | dynamicInfoService.insertShopInfo();
|
| | | } catch (Exception e) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * 早上8:00~10:00每半个小时更新
|
| | | */
|
| | | @Scheduled(cron = "0 0/30 8,9,10 * * ?")
|
| | | public void insetShopInfo2() {
|
| | | |
| | |
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | try {
|
| | | dynamicInfoService.insertShopInfo();
|
| | | } catch (Exception e) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 早上11:00~14:00每半个小时更新
|
| | | */
|
| | | @Scheduled(cron = "0 0/30 11,12,13,14 * * ?")
|
| | | public void insetShopInfo3() {
|
| | | |
| | |
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | try {
|
| | | dynamicInfoService.insertShopInfo();
|
| | | } catch (Exception e) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 下午17:00~20:00每半个小时更新
|
| | | */
|
| | | @Scheduled(cron = "0 0/30 17,18,19,20 * * ? ")
|
| | | public void insetShopInfo4() {
|
| | | |
| | |
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | try {
|
| | | dynamicInfoService.insertShopInfo();
|
| | | } catch (Exception e) {
|
| | |
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | } |
| | | |
| | | |
| | | }
|
| | |
|
| | | /**
|
| | | * 每天零点删除3天之前数据
|
| | | */
|
| | | @Scheduled(cron = "0 0 1,10 * * ?")
|
| | | public void remove() {
|
| | | |
| | |
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | try {
|
| | | LogHelper.test("DynamicInfoJob-remove-开始执行态");
|
| | | dynamicInfoService.removeByDate(DateUtil.reduceDay(2, new Date()));
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 后台编辑动态: 每3分钟检索
|
| | | * 后台编辑动态: 每3分钟检索
|
| | | */
|
| | | @Scheduled(cron = "0 0/3 * * * ?")
|
| | | public void activityNeedPublish() {
|
| | | |
| | |
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | try {
|
| | | List<RecommendActivity> list = activityService.getNeedPublish();
|
| | | if (list == null || list.size() == 0) {
|
| | | return;
|
| | | }
|
| | | |
| | | |
| | |
|
| | | for (RecommendActivity activity : list) {
|
| | | Integer type = activity.getType();
|
| | | if (RecommendActivity.TYPE_SHARE_GOODS == type) {
|
| | | // 商品动态
|
| | | dynamicInfoService.insertActivityRecommend(activity);
|
| | | |
| | |
|
| | | activity.setState(1);
|
| | | activityService.updateByPrimaryKeySelective(activity);
|
| | | |
| | |
|
| | | } else if (RecommendActivity.TYPE_INVITE == type) {
|
| | | // 邀请素材
|
| | | RecommendActivityInviteInfo inviteInfo = activityService.getRecommendActivityInviteInfoByActivityId(activity.getId());
|
| | | RecommendActivityInviteInfo inviteInfo = activityService
|
| | | .getRecommendActivityInviteInfoByActivityId(activity.getId());
|
| | | activity.setInviteInfo(inviteInfo);
|
| | | |
| | |
|
| | | dynamicInfoService.insertInviteActivity(activity);
|
| | | |
| | |
|
| | | activity.setState(1);
|
| | | activityService.updateByPrimaryKeySelective(activity);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 每天6点天更新邀请素材
|
| | | */
|
| | | @Scheduled(cron = "0 0 6 * * ?")
|
| | | public void insertTimeInvite() {
|
| | | |
| | |
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | try {
|
| | | dynamicInfoService.insertTimeInvite();
|
| | | } catch (Exception e) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * |
| | | * @Title: demoJobHandler @Description: 更新小程序动态商品 @param
|
| | | * param @return @throws Exception ReturnT<String> 返回类型 @throws
|
| | | */
|
| | | @XxlJob("dynamic-updateWXMPDynamicInfo")
|
| | | public ReturnT<String> updateWXMPDynamicInfoHandler(String param) throws Exception {
|
| | | addJDNYHInfo();
|
| | | return ReturnT.SUCCESS;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 添加内优惠相关商品 @Title: addJDNYHInfo @Description: void 返回类型 @throws
|
| | | */
|
| | | private void addJDNYHInfo() throws Exception {
|
| | |
|
| | | List<NYouHuiGoods> list = nyouHuiService.list(1, 1);
|
| | | if (list != null && list.size() > 0) {
|
| | | NYouHuiGoods goods = list.get(0);
|
| | | String id = goods.toId();
|
| | | WXMPDynamicInfo info = new WXMPDynamicInfo();
|
| | | info.setId(WXMPDynamicInfo.SOURCE_NYH + "#" + id);
|
| | | String desc = goods.getDesc();
|
| | |
|
| | | info.setSource(WXMPDynamicInfo.SOURCE_NYH);
|
| | | info.setUser(activityUserService.getRandomHaoHuo());
|
| | | // 做链接转换
|
| | | for (String link : goods.getLinkList()) {
|
| | | desc = desc.replaceFirst("\\[链接\\]", link);
|
| | | }
|
| | |
|
| | | desc = convertLinkManager.convertJDLinkFromText(desc, 0L, true);
|
| | | info.setContent(desc);
|
| | |
|
| | | List<JDGoods> goodsList = JDApiUtil.queryGoodsDetail(goods.getSkuList());
|
| | | List<GoodsPicture> imgs = new ArrayList<>();
|
| | |
|
| | | BigDecimal totalMoney = new BigDecimal(0);
|
| | | List<String> lastPicture = new ArrayList<>();
|
| | | for (JDGoods jdGoods : goodsList) {
|
| | | GoodsPicture picture = new GoodsPicture();
|
| | | BigDecimal money = JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getShareRate());
|
| | | totalMoney = totalMoney.add(money);
|
| | | picture.setGoodsVO(
|
| | | GoodsDetailVOFactory.convertJDGoods(jdGoods,
|
| | | new ConfigParamsDTO(hongBaoManageService.getFanLiRate(),
|
| | | hongBaoManageService.getShareRate(), null,
|
| | | hongBaoManageService.getFanLiRate(UserLevelEnum.superVIP))));
|
| | | picture.setGoodState(0);
|
| | | picture.setJumpDetail(jumpDetailV2Service.getByTypeCache("goodsdetail"));
|
| | | picture.setParams(null);
|
| | | picture.setUrl(jdGoods.getPicUrl());
|
| | | imgs.add(picture);
|
| | | if (jdGoods.getImageList() != null)
|
| | | if (jdGoods.getImageList().size() > 4)
|
| | | lastPicture.addAll(jdGoods.getImageList().subList(1, 4));
|
| | | else if (jdGoods.getImageList().size() > 1)
|
| | | lastPicture.addAll(jdGoods.getImageList().subList(1, jdGoods.getImageList().size()));
|
| | | }
|
| | | info.setShareMoney(totalMoney);
|
| | | int count = 0;
|
| | | while (imgs.size() < 4 && count < 4) {
|
| | | count++;
|
| | | String picurl = lastPicture.get((int) (lastPicture.size() * Math.random()));
|
| | | if (picurl != null) {
|
| | | lastPicture.remove(picurl);
|
| | | GoodsPicture picture = new GoodsPicture();
|
| | | picture.setUrl(picurl);
|
| | | imgs.add(picture);
|
| | | }
|
| | | }
|
| | |
|
| | | info.setImgs(imgs);
|
| | |
|
| | | wxmpDynamicInfoService.addWXMPDynamicInfo(info);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 动态发圈
|
| | | * |
| | | * @param param
|
| | | * @return
|
| | | * @throws Exception
|
| | | */
|
| | | // @Scheduled(cron = "0 0 6,7,15,16,21,22,23 * * ? ")
|
| | | @XxlJob("dynamic-insertEvaluate")
|
| | | public ReturnT<String> insertEvaluate(String param) throws Exception {
|
| | | try {
|
| | | goodsEvaluateService.addGoodsEvaluateByDaTaoKe();
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | return ReturnT.SUCCESS;
|
| | | }
|
| | |
|
| | |
|
| | | |
| | | /**
|
| | | * 每一个小时随机在分享数的基础上加10~100。增加的时间段是每天8~22点。
|
| | | * 早上6,7,15,16,21,22,23点更新1次
|
| | | */
|
| | | @Scheduled(cron = "0 0 8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 * * ? ")
|
| | | public void addRanDomShareCount() {
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | goodsEvaluateService.addRanDomShareCount();
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|