44323
2023-11-17 e863d3485d077c90988c81a756b37ef21cf4962e
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
package com.dsh.other.util;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dsh.other.entity.SiteBooking;
import com.dsh.other.mapper.SiteBookingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
 
/**
 * @author zhibing.pu
 * @Date 2023/7/19 14:19
 */
@Component
public class TaskUtil {
 
    @Resource
    private SiteBookingMapper siteBookingMapper;
 
    /**
     * 每隔一分钟去处理的定时任务
     */
    //预约场地后,待支付的订单 时间超过30分钟,不保留
    @Scheduled(fixedRate = 60000)
    public void taskMinute(){
        try {
            List<SiteBooking> siteBookings = siteBookingMapper.
                    selectList(new LambdaQueryWrapper<SiteBooking>().eq(SiteBooking::getStatus, 0));
            for (SiteBooking siteBooking : siteBookings) {
                long time = siteBooking.getInsertTime().getTime();
                long l = time + 1800 * 1000;
                if(System.currentTimeMillis()>l){
                    siteBooking.setStatus(5);
                    siteBookingMapper.deleteById(siteBooking.getId());
                }
            }
            //定时修改赛事状态
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
 
    //预约场地后,时间超过endTime,状态变为已过期
    @Scheduled(fixedRate = 60000)
    public void taskMinute1(){
        try {
            List<SiteBooking> siteBookings = siteBookingMapper.selectList
                    (new LambdaQueryWrapper<SiteBooking>().eq(SiteBooking::getStatus, 1));
            for (SiteBooking siteBooking : siteBookings) {
                    long time = siteBooking.getEndTime().getTime();
                    if (System.currentTimeMillis() > time) {
                        siteBooking.setStatus(4);
                        siteBookingMapper.updateById(siteBooking);
                    }
            }
            //定时修改赛事状态
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    // 预约场地后,待支付的订单 时间超过30分钟,不保留
    @Scheduled(fixedRate = 60000)
    public void taskMinute3(){
        try {
            // 获取待核销状态的记录
            List<SiteBooking> siteBookings = siteBookingMapper.selectList(new LambdaQueryWrapper<SiteBooking>()
                    .eq(SiteBooking::getStatus, 1));
            for (SiteBooking siteBooking : siteBookings) {
                long time = siteBooking.getEndTime().getTime();
                if (System.currentTimeMillis() > time) {
                    siteBooking.setStatus(4);
                    siteBookingMapper.updateById(siteBooking);
                }
            }
            //定时修改赛事状态
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
 
 
}