deason 1 жил өмнө
parent
commit
a1a213acf3

+ 6 - 0
src/main/java/com/qmth/exam/reserve/bean/apply/ApplyRecordCacheBean.java

@@ -20,4 +20,10 @@ public class ApplyRecordCacheBean implements IModel {
     @ApiModelProperty(value = "是否已取消预约")
     private Boolean cancel;
 
+    @ApiModelProperty(value = "操作人ID")
+    private Long operateId;
+
+    @ApiModelProperty(value = "操作时间")
+    private Long operateTime;
+
 }

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

@@ -151,6 +151,28 @@ public class ApplyTaskCacheService implements CacheConstants {
         atomic.decrementAndGet();
     }
 
+    /**
+     * 获取某考生的 已完成预约次数
+     */
+    public int getStudentApplyFinishCount(Long studentId) {
+        String cacheKey = String.format(CACHE_STUDENT_APPLY_RECORD, studentId);
+        if (!redisClient.exist(cacheKey)) {
+            LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(StudentApplyEntity::getStudentId, studentId);
+            wrapper.eq(StudentApplyEntity::getCancel, Boolean.FALSE);
+            return studentApplyService.count(wrapper);
+        }
+
+        Map<String, ApplyRecordCacheBean> maps = this.getStudentApplyRecords(studentId);
+        int studentApplyFinishCount = 0;
+        for (ApplyRecordCacheBean bean : maps.values()) {
+            if (!bean.getCancel()) {
+                studentApplyFinishCount++;
+            }
+        }
+        return studentApplyFinishCount;
+    }
+
     /**
      * 获取某考生的 所有的“预约记录”缓存
      */
@@ -167,10 +189,13 @@ public class ApplyTaskCacheService implements CacheConstants {
                     bean.setTimePeriodId(entity.getTimePeriodId());
                     bean.setExamSiteId(entity.getExamSiteId());
                     bean.setCancel(entity.getCancel());
+                    bean.setOperateId(entity.getOperateId());
+                    bean.setOperateTime(entity.getUpdateTime());
                     this.saveStudentApplyRecord(studentId, bean);
                 }
+
+                redisClient.expire(cacheKey, 30, TimeUnit.DAYS);
             }
-            redisClient.expire(cacheKey, 30, TimeUnit.DAYS);
         }
 
         return redisClient.getEntriesForHash(cacheKey, ApplyRecordCacheBean.class);

+ 2 - 9
src/main/java/com/qmth/exam/reserve/service/impl/ExamReserveServiceImpl.java

@@ -112,7 +112,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
 
             // 考生剩余预约次数 = 允许预约次数 - 已完成预约次数
             int studentApplyNumber = applyTaskCacheService.getStudentApplyNumber(student.getId());
-            int studentApplyFinishCount = this.getStudentApplyFinishCount(student.getId());
+            int studentApplyFinishCount = applyTaskCacheService.getStudentApplyFinishCount(student.getId());
             int unApplyNumber = studentApplyNumber - studentApplyFinishCount;
             if (unApplyNumber < 1) {
                 String msg = "当前学生无剩余可约时段次数,已完成预约" + studentApplyNumber + "次";
@@ -257,13 +257,6 @@ public class ExamReserveServiceImpl implements ExamReserveService {
         log.warn("更新考生预约记录!applyId:{} cancel:{}", applyId, cancel);
     }
 
-    private int getStudentApplyFinishCount(Long studentId) {
-        LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(StudentApplyEntity::getStudentId, studentId);
-        wrapper.eq(StudentApplyEntity::getCancel, Boolean.FALSE);
-        return studentApplyService.count(wrapper);
-    }
-
     private int getApplyAvailableCount(Long examSiteId, Long timePeriodId) {
         // 当前预约时段剩余可约数量
         int totalCount = applyTaskCacheService.getApplyTotalCount(examSiteId);
@@ -433,7 +426,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
 
         // 考生剩余预约次数 = 允许预约次数 - 已完成预约次数
         int studentApplyNumber = applyTaskCacheService.getStudentApplyNumber(student.getId());
-        int studentApplyFinishCount = this.getStudentApplyFinishCount(student.getId());
+        int studentApplyFinishCount = applyTaskCacheService.getStudentApplyFinishCount(student.getId());
         int unApplyNumber = studentApplyNumber - studentApplyFinishCount;
 
         ApplyTimePeriodResult result = new ApplyTimePeriodResult();