xuhy
2024-08-17 5a5b01fa9824a42e3eb033088a20e24c32b30dda
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
package com.ruoyi.account.task;
 
 
import com.ruoyi.account.api.model.TAppUserVipDetail;
import com.ruoyi.account.service.TAppUserVipDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;
 
 
/**
 * 定时任务工具类
 */
@Component
public class TaskUtil {
 
    @Resource
    private TAppUserVipDetailService tAppUserVipDetailService;
 
 
 
    /**
     * 每隔一分钟去处理的定时任务
     */
    @Scheduled(fixedRate = 1000 * 60)
    public void sendVipCoupon(){
        try {
            //首先获取当前的月份,用int类型标识
            LocalDate currentDate = LocalDate.now();
            int monthNum = currentDate.getMonthValue();
            //获取在当前时间内生效的vipDetail
            List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery()
                    .ge(TAppUserVipDetail::getStartTime, currentDate)
                    .le(TAppUserVipDetail::getEndTime, currentDate)
                    .orderByDesc(TAppUserVipDetail::getStartTime).list();
            //判断sendNum是否包括当前月份
            for (TAppUserVipDetail recentDetail : recentDetails) {
 
                    //赠送优惠卷
                    tAppUserVipDetailService.giveVipCoupun(recentDetail.getAppUserId(), recentDetail.getVipId(),recentDetail.getId(),monthNum);
 
 
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
}