admin
2019-07-18 6a9b0088e6f2aa600cf134d8723e80e9a418eff5
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.yeshi.fanli.job;
 
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import com.yeshi.fanli.entity.taobao.ShareHotGoods;
import com.yeshi.fanli.entity.taobao.TLJBuyGoods;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.taobao.ShareHotGoodsService;
import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService;
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinReportService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
 
@Component
public class TaoLiJinJob {
 
    @Resource
    private UserTaoLiJinReportService userTaoLiJinReportService;
 
    @Resource
    private ShareHotGoodsService shareHotGoodsService;
 
    @Resource
    private TLJBuyGoodsService tljBuyGoodsService;
 
    @Resource
    private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
 
    /**
     * 更新报告
     */
    @Scheduled(cron = "0 0 1,10 * * ?")
    public void insetDynamicInfo() {
 
        if (!Constant.IS_TASK) {
            return;
        }
 
        try {
            userTaoLiJinReportService.needUpdateReport();
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
    }
 
    /**
     * 退回超过3天无领取的淘礼金
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void refundNotWin() {
 
        if (!Constant.IS_TASK) {
            return;
        }
 
        try {
            userTaoLiJinReportService.refundNotWin();
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
    }
 
    /**
     * 每天凌晨过5分钟验证
     */
    @Scheduled(cron = "0 2 0 * * ?")
    public void updateShareTLJGoods() {
        if (!Constant.IS_TASK)
            return;
        LogHelper.test("验证爆款商品库商品");
        String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd");
        List<ShareHotGoods> list = shareHotGoodsService.listByDay(day, 15);
        int count = 0;
        for (int i = 0; i < list.size(); i++) {
            if (count >= 10)
                break;
            boolean success = shareHotGoodsService.verifyCanCreateTLJ(list.get(i).getGoods().getAuctionId(),
                    new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
                            TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
            if (success) {
                count++;
            }
        }
    }
 
    /**
     * 每天凌晨5点过10分钟验证
     */
    @Scheduled(cron = "0 10 5 * * ? ")
    public void updateBuyTLJGoods() {
        if (!Constant.IS_TASK)
            return;
        LogHelper.test("验证自购立减商品");
        String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd");
        List<TLJBuyGoods> list = tljBuyGoodsService.listByDay(day, 15);
        int count = 0;
        for (int i = 0; i < list.size(); i++) {
            if (count >= 10)
                break;
            boolean success = tljBuyGoodsService.verifyCanCreateTLJ(list.get(i).getGoods().getAuctionId());
            if (success) {
                count++;
            }
        }
    }
 
    private void addTLJBuyGoods(List<TaoBaoGoodsBrief> list, String day) {
        for (TaoBaoGoodsBrief goods : list) {
            // 获取商品详情
            try {
                goods = TaoKeApiUtil.searchGoodsDetail(goods.getAuctionId());
            } catch (TaobaoGoodsDownException e) {
                e.printStackTrace();
            }
            if (goods != null && goods.getCouponAmount() != null
                    && goods.getCouponAmount().compareTo(new BigDecimal(0)) > 0) {
 
                if (TaoBaoUtil.getAfterUseCouplePrice(goods).multiply(goods.getTkRate())
                        .compareTo(new BigDecimal("143")) >= 0) {
                    goods = daTaoKeGoodsDetailService.filterTaoBaoGoods(goods);
                    int totalHongBaoCount = 2000 + (int) (Math.random() * 8000);
                    int leftHongBaoCount = 200 + (int) (Math.random() * 2000);
                    tljBuyGoodsService.addTLJBuyGoods(
                            new TLJBuyGoods(null, day, new Date(), goods, totalHongBaoCount, leftHongBaoCount),
                            TaoBaoConstant.ownBuyApp);
                }
            }
        }
    }
 
    /**
     * 每天晚上11点50添加淘礼金1个商品,用于兼容Android前端没有商品不显示banner的问题
     */
    @Scheduled(cron = "0 50 23 * * ? ")
    public void autoAddTLJBuyGoods() {
        if (!Constant.IS_TASK)
            return;
        String day = TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24L, "yyyy-MM-dd");
        List<TaoBaoGoodsBrief> list = tljBuyGoodsService.listPreGoods(1);
        Collections.shuffle(list);
        if (list.size() > 0)
            list = list.subList(0, 1);
        addTLJBuyGoods(list, day);
    }
 
    /**
     * 每天凌晨5点过1分开始爬取剩余9个商品
     */
    @Scheduled(cron = "0 1 5 * * ? ")
    public void autoAddTLJBuyGoods2() {
        if (!Constant.IS_TASK)
            return;
        String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd");
        List<TaoBaoGoodsBrief> list = tljBuyGoodsService.listPreGoods(1);
        Collections.shuffle(list);
        if (list.size() > 20)
            list = list.subList(0, 1);
        addTLJBuyGoods(list, day);
    }
 
}