admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
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
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.user.UserSystemCoupon;
import com.yeshi.fanli.entity.bus.user.UserSystemCouponGiveRecord;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.user.UserSystemCouponGiveRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.util.Constant;
 
@Component
public class UserSystemCouponJob {
 
    @Resource
    private UserSystemCouponGiveRecordService userSystemCouponGiveRecordService;
    
    @Resource
    private UserSystemCouponService userSystemCouponService;
    
    /**
     * 每天一个小时更新券
     */
    @Scheduled(cron = "0 0 0/1 * * ? ")
    public void updateCouponInfo() {
        if (!Constant.IS_TASK)
            return;
        
        // 1、赠送退回券
        giveSendBack();
        
        // 2、券失效
        updateInvalid();
    }
    
    /**
     * 赠送退回券
     */
    public void giveSendBack() {
        try {
            for (int i = 0; i < 100; i++) {
                List<UserSystemCouponGiveRecord> overdueList = userSystemCouponGiveRecordService.overdueList(500);
                if (overdueList == null || overdueList.size() == 0) {
                    break;
                }
                userSystemCouponService.sendBackGiveCoupon(overdueList);
            }
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
    }
    
    /**
     * 更新券失效
     */
    public void updateInvalid() {
        try {
            for (int i = 0; i < 100; i++) {
                List<UserSystemCoupon> list = userSystemCouponService.getCounponNowInvalid(500);
                if (list == null || list.size() == 0) {
                    break;
                }
                userSystemCouponService.updateCounponInvalid(list);
            }
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
    }
}