|
@@ -0,0 +1,50 @@
|
|
|
+package com.qmth.exam.reserve.job;
|
|
|
+
|
|
|
+import com.qmth.exam.reserve.bean.apply.ApplyRecordCacheBean;
|
|
|
+import com.qmth.exam.reserve.cache.CacheConstants;
|
|
|
+import com.qmth.exam.reserve.cache.RedisClient;
|
|
|
+import com.qmth.exam.reserve.service.StudentApplyService;
|
|
|
+import org.redisson.api.RBlockingQueue;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class StudentApplyRecordJob {
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(StudentApplyRecordJob.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentApplyService studentApplyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisClient redisClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定时将“考生预约记录队列”中的数据保存至数据库
|
|
|
+ * 注:每N秒执行一次
|
|
|
+ */
|
|
|
+ // @Scheduled(fixedDelay = 30000, initialDelay = 30000)
|
|
|
+ public void saveStudentApplyRecordJob() {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ try {
|
|
|
+ RBlockingQueue<ApplyRecordCacheBean> queue = redisClient.getRedissonClient()
|
|
|
+ .getBlockingQueue(CacheConstants.QUEUE_STUDENT_APPLY_RECORD);
|
|
|
+
|
|
|
+ log.info("[QUEUE] curSize:{}", queue.size());
|
|
|
+ while (!queue.isEmpty()) {
|
|
|
+ ApplyRecordCacheBean value = queue.take();
|
|
|
+ log.info("[QUEUE] {}_{}_{}", value.getStudentId(), value.getExamSiteId(), value.getTimePeriodId());
|
|
|
+ // todo
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("[QUEUE] job err:{}", e.getMessage(), e);
|
|
|
+ } finally {
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ log.info("[QUEUE] job cost {}ms", end - start);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|