From b21fb4c288c98971f9859cf5d85cef4c86e131bb Mon Sep 17 00:00:00 2001
From: nickchange <126672920+nickchange@users.noreply.github.com>
Date: 星期五, 08 十二月 2023 14:46:21 +0800
Subject: [PATCH] 12.8
---
cloud-server-other/src/main/java/com/dsh/other/util/TaskUtil.java | 80 +++++++++++++++++++++++++++++++++++++++
1 files changed, 79 insertions(+), 1 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 ca148cc..e05a3f2 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,7 +1,17 @@
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.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
/**
* @author zhibing.pu
@@ -10,16 +20,84 @@
@Component
public class TaskUtil {
+ @Resource
+ private SiteBookingMapper siteBookingMapper;
/**
* 每隔一分钟去处理的定时任务
*/
+ //预约场地后,待支付的订单 时间超过30分钟,不保留
@Scheduled(fixedRate = 60000)
- public void taskMinute(){
+ public void taskMinute() {
try {
+ Date date = new Date(); // 要增加的日期
+
+ List<SiteBooking> siteBookings = siteBookingMapper.
+ selectList(new LambdaQueryWrapper<SiteBooking>().eq(SiteBooking::getStatus, 0));
+ for (SiteBooking siteBooking : siteBookings) {
+
+ 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) {
+ 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();
+ }
+ }
+
+
}
--
Gitblit v1.7.1