deason 1 vuosi sitten
vanhempi
commit
ec225ca447

+ 5 - 5
src/main/java/com/qmth/exam/reserve/cache/impl/ApplyTaskCacheService.java

@@ -12,7 +12,7 @@ import com.qmth.exam.reserve.service.StudentApplyService;
 import com.qmth.exam.reserve.service.StudentService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.redisson.api.RAtomicLong;
-import org.redisson.api.RBlockingQueue;
+import org.redisson.api.RQueue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -238,8 +238,8 @@ public class ApplyTaskCacheService implements CacheConstants {
             return;
         }
 
-        RBlockingQueue<ApplyRecordCacheBean> queue = redisClient.getRedissonClient()
-                .getBlockingQueue(QUEUE_STUDENT_APPLY_RECORD);
+        RQueue<ApplyRecordCacheBean> queue = redisClient.getRedissonClient()
+                .getQueue(QUEUE_STUDENT_APPLY_RECORD);
 
         boolean success = queue.offer(value);
         log.info("{}_{}_{}_{} offerQueue:{}", value.getStudentId(), value.getExamSiteId(),
@@ -253,8 +253,8 @@ public class ApplyTaskCacheService implements CacheConstants {
      * 获取考生预约记录队列数量
      */
     public int getStudentApplyRecordQueueSize() {
-        RBlockingQueue<ApplyRecordCacheBean> queue = redisClient.getRedissonClient()
-                .getBlockingQueue(QUEUE_STUDENT_APPLY_RECORD);
+        RQueue<ApplyRecordCacheBean> queue = redisClient.getRedissonClient()
+                .getQueue(QUEUE_STUDENT_APPLY_RECORD);
         return queue.size();
     }
 

+ 9 - 4
src/main/java/com/qmth/exam/reserve/job/StudentApplyRecordJob.java

@@ -8,7 +8,7 @@ import com.qmth.exam.reserve.cache.CacheConstants;
 import com.qmth.exam.reserve.cache.RedisClient;
 import com.qmth.exam.reserve.entity.StudentApplyEntity;
 import com.qmth.exam.reserve.service.StudentApplyService;
-import org.redisson.api.RBlockingQueue;
+import org.redisson.api.RQueue;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,13 +46,14 @@ public class StudentApplyRecordJob {
                 return;
             }
 
-            RBlockingQueue<ApplyRecordCacheBean> queue = redisClient.getRedissonClient()
-                    .getBlockingQueue(CacheConstants.QUEUE_STUDENT_APPLY_RECORD);
+            RQueue<ApplyRecordCacheBean> queue = redisClient.getRedissonClient()
+                    .getQueue(CacheConstants.QUEUE_STUDENT_APPLY_RECORD);
 
             int queueSize = queue.size();
             log.info("[JOB] queue size:{}", queueSize);
+
             for (int i = 0; i < queueSize; i++) {
-                ApplyRecordCacheBean value = queue.take();
+                ApplyRecordCacheBean value = queue.poll();
 
                 try {
                     this.saveOrUpdate(value);
@@ -74,6 +75,10 @@ public class StudentApplyRecordJob {
 
     // @Transactional
     public void saveOrUpdate(ApplyRecordCacheBean bean) {
+        if (bean == null) {
+            return;
+        }
+
         LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(StudentApplyEntity::getExamSiteId, bean.getExamSiteId());
         wrapper.eq(StudentApplyEntity::getTimePeriodId, bean.getTimePeriodId());