|
|
@@ -1,9 +1,12 @@
|
|
|
package beilv.competition.task;
|
|
|
|
|
|
+import beilv.common.utils.DateUtils;
|
|
|
import beilv.competition.domain.Competition;
|
|
|
import beilv.competition.domain.RedisTask;
|
|
|
import beilv.competition.mapper.CompetitionMapper;
|
|
|
import beilv.stadium.domain.Stadium;
|
|
|
+import beilv.vipCardLog.domain.VipCardLog;
|
|
|
+import beilv.vipCardLog.mapper.VipCardLogMapper;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
@@ -14,7 +17,7 @@ import javax.annotation.Resource;
|
|
|
import java.util.Date;
|
|
|
import java.util.Set;
|
|
|
|
|
|
-import static beilv.competition.domain.Constant.TASK_QUEUE_QUERY;
|
|
|
+import static beilv.competition.domain.Constant.*;
|
|
|
|
|
|
/**
|
|
|
* 轮询Redis有序集合, 处理到期的任务.
|
|
|
@@ -31,6 +34,9 @@ public class RedisTaskChecker {
|
|
|
@Resource
|
|
|
private CompetitionMapper competitionMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private VipCardLogMapper vipCardLogMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 检测到期任务, 并将消息发布
|
|
|
*/
|
|
|
@@ -39,7 +45,7 @@ public class RedisTaskChecker {
|
|
|
long currentTime = System.currentTimeMillis() / 1000;
|
|
|
|
|
|
// 获取所有有序集合的键
|
|
|
- Set<String> keys = stringRedisTemplate.keys(TASK_QUEUE_QUERY);
|
|
|
+ Set<String> keys = stringRedisTemplate.keys(TASK_QUEUE_QUERY_APPLY);
|
|
|
if (keys != null && !keys.isEmpty()) {
|
|
|
for (String key : keys) {
|
|
|
// 获取当前时间之前的所有任务
|
|
|
@@ -53,17 +59,99 @@ public class RedisTaskChecker {
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
RedisTask task = objectMapper.readValue(taskJson, RedisTask.class);
|
|
|
|
|
|
+ //赛事报名结束: 参赛订单核销, 赛事状态:报名结束
|
|
|
+
|
|
|
Competition competition = new Competition();
|
|
|
competition.setId(task.getCompetitionId());
|
|
|
competition.setCompetitionState(task.getCompetitionState());
|
|
|
competitionMapper.updateCompetition(competition);
|
|
|
|
|
|
- //核验当前赛事下已支付的订单
|
|
|
- Stadium stadium = new Stadium();
|
|
|
- stadium.setCompetitionId(String.valueOf(task.getCompetitionId()));
|
|
|
- stadium.setPaymentStatus(task.getPaymentStatus());
|
|
|
- stadium.setVerificationTime(new Date());
|
|
|
- competitionMapper.updateBookARace(stadium);
|
|
|
+
|
|
|
+ //赛事id, 订单状态, 核验时间
|
|
|
+ VipCardLog vipCardLog = new VipCardLog(String.valueOf(task.getCompetitionId()), "cansai", task.getPaymentStatus(), DateUtils.getNowDate());
|
|
|
+ vipCardLogMapper.updateVipCardLogByBusId(vipCardLog);
|
|
|
+
|
|
|
+ // 移除当前已发布的任务
|
|
|
+ stringRedisTemplate.opsForZSet().remove(key, taskJson);
|
|
|
+ System.out.println("Removed task: " + taskJson);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Scheduled(fixedRate = 1000)
|
|
|
+ public void checkTasksStart() {
|
|
|
+ long currentTime = System.currentTimeMillis() / 1000;
|
|
|
+
|
|
|
+ // 获取所有有序集合的键
|
|
|
+ Set<String> keys = stringRedisTemplate.keys(TASK_QUEUE_QUERY_START);
|
|
|
+ if (keys != null && !keys.isEmpty()) {
|
|
|
+ for (String key : keys) {
|
|
|
+ // 获取当前时间之前的所有任务
|
|
|
+ Set<String> tasks = stringRedisTemplate.opsForZSet().rangeByScore(key, 0, currentTime);
|
|
|
+ if (tasks != null && !tasks.isEmpty()) {
|
|
|
+ for (String taskJson : tasks) {
|
|
|
+ try {
|
|
|
+// System.out.println("taskJson => " + taskJson);
|
|
|
+
|
|
|
+ //获取任务信息
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ RedisTask task = objectMapper.readValue(taskJson, RedisTask.class);
|
|
|
+
|
|
|
+ //比赛开始, 门票订单核销, 赛事状态, 比赛开始
|
|
|
+
|
|
|
+ Competition competition = new Competition();
|
|
|
+ competition.setId(task.getCompetitionId());
|
|
|
+ competition.setCompetitionState(task.getCompetitionState());
|
|
|
+ competitionMapper.updateCompetition(competition);
|
|
|
+
|
|
|
+ //赛事id, 订单状态, 核验时间
|
|
|
+ VipCardLog vipCardLog = new VipCardLog(String.valueOf(task.getCompetitionId()), "menpiao", task.getPaymentStatus(), DateUtils.getNowDate());
|
|
|
+ vipCardLogMapper.updateVipCardLogByBusId(vipCardLog);
|
|
|
+
|
|
|
+
|
|
|
+ // 移除当前已发布的任务
|
|
|
+ stringRedisTemplate.opsForZSet().remove(key, taskJson);
|
|
|
+ System.out.println("Removed task: " + taskJson);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(fixedRate = 1000)
|
|
|
+ public void checkTasksEnd() {
|
|
|
+ long currentTime = System.currentTimeMillis() / 1000;
|
|
|
+
|
|
|
+ // 获取所有有序集合的键
|
|
|
+ Set<String> keys = stringRedisTemplate.keys(TASK_QUEUE_QUERY_END);
|
|
|
+ if (keys != null && !keys.isEmpty()) {
|
|
|
+ for (String key : keys) {
|
|
|
+ // 获取当前时间之前的所有任务
|
|
|
+ Set<String> tasks = stringRedisTemplate.opsForZSet().rangeByScore(key, 0, currentTime);
|
|
|
+ if (tasks != null && !tasks.isEmpty()) {
|
|
|
+ for (String taskJson : tasks) {
|
|
|
+ try {
|
|
|
+// System.out.println("taskJson => " + taskJson);
|
|
|
+
|
|
|
+ //获取任务信息
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ RedisTask task = objectMapper.readValue(taskJson, RedisTask.class);
|
|
|
+
|
|
|
+ //比赛开始, 门票订单核销, 赛事状态, 比赛开始
|
|
|
+
|
|
|
+ Competition competition = new Competition();
|
|
|
+ competition.setId(task.getCompetitionId());
|
|
|
+ competition.setCompetitionState(task.getCompetitionState());
|
|
|
+ competitionMapper.updateCompetition(competition);
|
|
|
|
|
|
|
|
|
// 移除当前已发布的任务
|