| | |
| | | package com.yeshi.fanli.job;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.scheduling.annotation.Scheduled;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import com.yeshi.fanli.entity.bus.activity.RecommendActivity;
|
| | | import com.yeshi.fanli.exception.ActivityException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.activity.ActivityService;
|
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
|
| | | import com.yeshi.fanli.service.inter.lable.LabelService;
|
| | | import com.yeshi.fanli.service.inter.lable.QualityFactoryService;
|
| | | import com.yeshi.fanli.service.inter.lable.QualityFlashSaleService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
|
| | | import com.yeshi.fanli.util.CMQManager;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | |
|
| | | /**
|
| | | * 淘宝商品更细
|
| | | * |
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | |
|
| | | @Component
|
| | | public class UpdateTaoBaoGoodsJob {
|
| | |
|
| | | @Resource
|
| | | private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
|
| | |
|
| | | @Resource
|
| | | private ActivityService activityService;
|
| | |
|
| | | @Resource
|
| | | private QualityFactoryService qualityFactoryService;
|
| | |
|
| | | @Resource
|
| | | private LabelService labelService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
|
| | |
|
| | | @Resource
|
| | | private QualityFlashSaleService qualityFlashSaleService;
|
| | |
|
| | | // 动态商品更新 ,1个小时更新
|
| | | @Scheduled(cron = "0 0 */1 * * ?")
|
| | | public void updateActivityGoodsJob() {
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | |
|
| | | Long count = activityService.getRecommendActivityCount(RecommendActivity.TYPE_SHARE_GOODS);
|
| | | int pageSize = 50;
|
| | | int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
|
| | | // 最多更新50页数据
|
| | | if (totalPage > 50)
|
| | | totalPage = 50;
|
| | | for (int i = 1; i <= totalPage; i++) {
|
| | | List<RecommendActivity> list = activityService.getRecommendActivityList(RecommendActivity.TYPE_SHARE_GOODS,
|
| | | i, pageSize);
|
| | | if (list != null)
|
| | | for (RecommendActivity activity : list) {
|
| | | try {
|
| | | activityService.upgradeShareGoodsRecommendActivity(activity.getId());
|
| | | } catch (ActivityException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | // 调整超过3个小时未更新 的商品权重值设为10
|
| | | @Scheduled(cron = "0 0 0/3 * * ?")
|
| | | public void updateQualityFactoryWeightJob() {
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | qualityFactoryService.updateWeight(1, 4);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | // 删除过期商品资源(30分钟)
|
| | | @Scheduled(cron = "0 0/30 * * * ? ")
|
| | | public void deleteOutOfDateTaoBaoGoods() {
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | | taoBaoGoodsUpdateService.deleteOutOfDate();
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 更新超过4个小时未更新的商品
|
| | | */
|
| | | //1个小时更新
|
| | | @Scheduled(cron = "0 0 1/1 * * ? ")
|
| | | public void addNeddUpdateTaoBaoGoods() {
|
| | | if (!Constant.IS_TASK) |
| | | return;
|
| | | |
| | | List<Long> list = taoBaoGoodsUpdateService.listNeedUpdateGoodsId(0, 2000, 4);
|
| | | if (list == null || list.size() == 0) {
|
| | | return;
|
| | | }
|
| | | |
| | | for (Long id : list) {
|
| | | try {
|
| | | CMQManager.getInstance().addNeedUpdateTaoBaoGoodsId(id);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 定时清理超过6个小时未更新的限时抢购商品
|
| | | */
|
| | | @Scheduled(cron = "0 15 0/6 * * ? ")
|
| | | public void removeFlashSaleGoods() {
|
| | |
|
| | | if (!Constant.IS_TASK) {
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | while (true) {
|
| | | List<Long> list = qualityFlashSaleService.queryNeedRemove(0, 200, 6);
|
| | | if (list == null || list.size() == 0) {
|
| | | break;
|
| | | }
|
| | | qualityFlashSaleService.deleteBatchByPrimaryKey(list);
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.job; |
| | | |
| | | import com.yeshi.fanli.entity.bus.activity.RecommendActivity; |
| | | import com.yeshi.fanli.exception.ActivityException; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.service.inter.activity.ActivityService; |
| | | import com.yeshi.fanli.service.inter.brand.BrandClassShopGoodsService; |
| | | import com.yeshi.fanli.service.inter.brand.BrandClassShopService; |
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; |
| | | import com.yeshi.fanli.service.inter.lable.LabelService; |
| | | import com.yeshi.fanli.service.inter.lable.QualityFactoryService; |
| | | import com.yeshi.fanli.service.inter.lable.QualityFlashSaleService; |
| | | import com.yeshi.fanli.service.inter.taobao.ShareHotGoodsService; |
| | | import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsActivityService; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.cache.HttpGoodsCacheManager; |
| | | import com.yeshi.fanli.util.mq.rabbit.RabbitmqManager; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 淘宝商品更细 |
| | | * |
| | | * @author Administrator |
| | | * |
| | | */ |
| | | |
| | | @Component |
| | | public class UpdateTaoBaoGoodsJob { |
| | | |
| | | @Resource |
| | | private TaoBaoGoodsBriefService taoBaoGoodsBriefService; |
| | | |
| | | @Resource |
| | | private ActivityService activityService; |
| | | |
| | | @Resource |
| | | private QualityFactoryService qualityFactoryService; |
| | | |
| | | @Resource |
| | | private LabelService labelService; |
| | | |
| | | @Resource |
| | | private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService; |
| | | |
| | | @Resource |
| | | private QualityFlashSaleService qualityFlashSaleService; |
| | | |
| | | @Resource |
| | | private BrandClassShopService brandClassShopService; |
| | | |
| | | @Resource |
| | | private TaoBaoGoodsActivityService taoBaoGoodsActivityService; |
| | | |
| | | @Resource |
| | | private ShareHotGoodsService shareHotGoodsService; |
| | | |
| | | @Resource |
| | | private TLJBuyGoodsService tljBuyGoodsService; |
| | | |
| | | @Resource |
| | | private BrandClassShopGoodsService brandClassShopGoodsService; |
| | | |
| | | @Resource |
| | | private HttpGoodsCacheManager httpGoodsCacheManager; |
| | | |
| | | @Resource |
| | | private RabbitmqManager rabbitmqManager; |
| | | |
| | | // 动态商品更新 ,1个小时更新 |
| | | @Scheduled(cron = "0 0 */1 * * ?") |
| | | public void updateActivityGoodsJob() { |
| | | if (!Constant.IS_TASK) { |
| | | return; |
| | | } |
| | | |
| | | Long count = activityService.getRecommendActivityCount(RecommendActivity.TYPE_SHARE_GOODS); |
| | | int pageSize = 50; |
| | | int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); |
| | | // 最多更新50页数据 |
| | | if (totalPage > 50) |
| | | totalPage = 50; |
| | | for (int i = 1; i <= totalPage; i++) { |
| | | List<RecommendActivity> list = activityService.getRecommendActivityList(RecommendActivity.TYPE_SHARE_GOODS, |
| | | i, pageSize); |
| | | if (list != null) |
| | | for (RecommendActivity activity : list) { |
| | | try { |
| | | activityService.upgradeShareGoodsRecommendActivity(activity.getId()); |
| | | } catch (ActivityException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | // 调整超过3个小时未更新 的商品权重值设为10 |
| | | @Scheduled(cron = "0 0 0/3 * * ?") |
| | | public void updateQualityFactoryWeightJob() { |
| | | if (!Constant.IS_TASK) { |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | qualityFactoryService.updateWeight(1, 4); |
| | | } catch (Exception e) { |
| | | LogHelper.errorDetailInfo(e); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 删除过期商品资源(30分钟) |
| | | @Scheduled(cron = "0 0/30 * * * ? ") |
| | | public void deleteOutOfDateTaoBaoGoods() { |
| | | if (!Constant.IS_TASK) { |
| | | return; |
| | | } |
| | | taoBaoGoodsUpdateService.deleteOutOfDate(); |
| | | } |
| | | |
| | | /** |
| | | * 更新超过4个小时未更新的商品 |
| | | */ |
| | | // 1个小时更新 |
| | | @Scheduled(cron = "0 0 1/1 * * ? ") |
| | | public void addNeedUpdateTaoBaoGoods() { |
| | | if (!Constant.IS_TASK) |
| | | return; |
| | | |
| | | List<String> list = taoBaoGoodsUpdateService.listNeedUpdateGoodsId(0, 2000, 4); |
| | | if (list == null || list.size() == 0) { |
| | | return; |
| | | } |
| | | |
| | | for (String id : list) { |
| | | try { |
| | | rabbitmqManager.addNeedUpdateTaoBaoGoodsId(id); |
| | | } catch (Exception e) { |
| | | LogHelper.errorDetailInfo(e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 定时清理超过6个小时未更新的限时抢购商品 |
| | | */ |
| | | @Scheduled(cron = "0 15 0/6 * * ? ") |
| | | public void removeFlashSaleGoods() { |
| | | if (!Constant.IS_TASK) { |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | while (true) { |
| | | List<Long> list = qualityFlashSaleService.queryNeedRemove(0, 200, 6); |
| | | if (list == null || list.size() == 0) { |
| | | break; |
| | | } |
| | | qualityFlashSaleService.deleteBatchByPrimaryKey(list); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | LogHelper.errorDetailInfo(e); |
| | | } |
| | | } |
| | | |
| | | // 更新增加品牌商品,每天早上6点执行一次 |
| | | @Scheduled(cron = "0 0 6 * * ? ") |
| | | public void updateAddBrandGoods() { |
| | | if (!Constant.IS_TASK) |
| | | return; |
| | | brandClassShopService.updateShopGoods(); |
| | | } |
| | | |
| | | // 更新原有精品库的品牌商品,每天凌晨3点执行一次 |
| | | @Scheduled(cron = "0 0 3 * * ? ") |
| | | public void updateBrandGoods() { |
| | | if (!Constant.IS_TASK) |
| | | return; |
| | | brandClassShopGoodsService.startUpdateGoods(); |
| | | } |
| | | |
| | | // 每天凌晨4点模拟请求 |
| | | @Scheduled(cron = "0 0 4 * * ? ") |
| | | public void simulateRequest() { |
| | | httpGoodsCacheManager.requestHomeRecommend(); |
| | | httpGoodsCacheManager.requestClassGoods(); |
| | | httpGoodsCacheManager.requestBrandGoods(); |
| | | httpGoodsCacheManager.requestDynamic(); |
| | | httpGoodsCacheManager.requestCommonTemplate(); |
| | | } |
| | | } |