From 1d9f7b0cf4251f3058badb07dd7a2bc06b6bc09a Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期五, 11 四月 2025 10:05:32 +0800 Subject: [PATCH] bug修改 --- cloud-server-other/src/main/java/com/dsh/other/util/TaskUtil.java | 104 +++++++++++++++++++++++++++++++++++----------------- 1 files changed, 70 insertions(+), 34 deletions(-) diff --git a/cloud-server-other/src/main/java/com/dsh/other/util/TaskUtil.java b/cloud-server-other/src/main/java/com/dsh/other/util/TaskUtil.java index 8457a24..c23e459 100644 --- a/cloud-server-other/src/main/java/com/dsh/other/util/TaskUtil.java +++ b/cloud-server-other/src/main/java/com/dsh/other/util/TaskUtil.java @@ -1,13 +1,18 @@ package com.dsh.other.util; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.dsh.other.entity.SiteBooking; +import com.dsh.other.feignclient.account.StudentHonorClient; +import com.dsh.other.feignclient.account.model.StudentHonor; 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.Arrays; +import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit; @@ -22,19 +27,72 @@ @Resource private SiteBookingMapper siteBookingMapper; + @Resource + private StudentHonorClient studentHonorClient; + + + + /** * 每隔一分钟去处理的定时任务 */ + //预约场地后,待支付的订单 时间超过30分钟,不保留 @Scheduled(fixedRate = 60000) - public void taskMinute(){ + public void taskMinute() { try { - List<SiteBooking> siteBookings = siteBookingMapper.selectList(new LambdaQueryWrapper<SiteBooking>().eq(SiteBooking::getStatus, 0)); + Date date = new Date(); // 要增加的日期 + + 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){ + + Date insert = siteBooking.getInsertTime(); + // 创建 Calendar 对象,并设置为指定的日期 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(insert); + + // 增加 30 分钟 + calendar.add(Calendar.MINUTE, 30); + + // 获取增加后的日期 + Date newDate = calendar.getTime(); + +// long time = siteBooking.getInsertTime().getTime(); +// long l = time + 1800 * 1000; + if (date.after(newDate)) { siteBooking.setStatus(5); siteBookingMapper.updateById(siteBooking); + } + } + //定时修改赛事状态 + } 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) { + if(null == siteBooking.getEndTime()){ + continue; + } + long time = siteBooking.getEndTime().getTime(); + if (System.currentTimeMillis() > time) { + siteBooking.setStatus(4); + siteBookingMapper.updateById(siteBooking); + + //添加勋章数据 + Integer number = siteBookingMapper.selectCount(new QueryWrapper<SiteBooking>() + .eq("appUserId", siteBooking.getAppUserId()).in("status", Arrays.asList(3, 4))); + StudentHonor studentHonor = new StudentHonor(); + studentHonor.setAppUserId(siteBooking.getAppUserId()); + studentHonor.setHonorType(3); + studentHonor.setNumber(number); + studentHonorClient.saveStudentHonor(studentHonor); } } @@ -44,39 +102,17 @@ } } - - - //预约场地后,时间超过endTime,状态变为已过期 + // 预约场地后,待支付的订单 时间超过30分钟,不保留 @Scheduled(fixedRate = 60000) - public void taskMinute1(){ + 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(); - } - } - - - @Scheduled(fixedRate = 60000) - public void taskMinute2(){ - try { - List<SiteBooking> siteBookings = siteBookingMapper.selectList(new LambdaQueryWrapper<SiteBooking>().eq(SiteBooking::getStatus, 0)); + // 获取待核销状态的记录 + List<SiteBooking> siteBookings = siteBookingMapper.selectList(new LambdaQueryWrapper<SiteBooking>() + .eq(SiteBooking::getStatus, 0).eq(SiteBooking::getState, 1)); for (SiteBooking siteBooking : siteBookings) { long time = siteBooking.getInsertTime().getTime(); - long currentTime = System.currentTimeMillis(); - long timeDifference = currentTime - time; - long minutes = TimeUnit.MILLISECONDS.toMinutes(timeDifference); - if (minutes > 30) { - siteBooking.setStatus(5); + if (System.currentTimeMillis() > time + 1800000L) { + siteBooking.setState(3); siteBookingMapper.updateById(siteBooking); } } -- Gitblit v1.7.1