44323
2024-04-23 16b704d18a875d1fb63827aaa507790ba2bef5be
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
package com.stylefeng.guns.modular.system.util.task;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.modular.system.model.CouponReceive;
import com.stylefeng.guns.modular.system.service.ICouponReceiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.Date;
 
@Component
public class MyScheduledTask {
@Autowired
private ICouponReceiveService couponReceiveService;
    @Scheduled(cron = "0 0 0 * * ?") // 每隔60秒执行一次
    public void myTask() {
        EntityWrapper<CouponReceive> wrapper = new EntityWrapper<>();
        wrapper.le("endTime",new Date());
        for (CouponReceive couponReceive : couponReceiveService.selectList(wrapper)) {
            couponReceive.setState(3);
            couponReceiveService.updateById(couponReceive);
        }
        // 这里是定时执行的任务逻辑
        System.out.println("定时任务执行啦!");
    }
}