admin
2019-06-05 07c13064382007999e87abe81efe76c98a47dce8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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.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.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;
 
    @Resource
    private BrandClassShopService brandClassShopService;
 
    // 动态商品更新 ,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<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);
        }
    }
 
    // 更新品牌商品,每天早上6点执行一次
    @Scheduled(cron = "0 0 6 * * ? ")
    public void updateBrandGoods() {
        brandClassShopService.updateShopGoods();
    }
 
}