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; /** * @author zhibing.pu * @Date 2023/7/19 14:19 */ @Component public class TaskUtil { @Resource private SiteBookingMapper siteBookingMapper; /** * 每隔一分钟去处理的定时任务 */ @Scheduled(fixedRate = 60000) public void taskMinute(){ try { List siteBookings = siteBookingMapper.selectList(new LambdaQueryWrapper().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.updateById(siteBooking); } } //定时修改赛事状态 } catch (Exception e) { e.printStackTrace(); } } //预约场地后,时间超过endTime,状态变为已过期 @Scheduled(fixedRate = 60000) public void taskMinute1(){ try { List siteBookings = siteBookingMapper.selectList(new LambdaQueryWrapper().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(); } } }