浏览代码

Merge branch 'dev_1.0.0' of http://git.qmth.com.cn/exam-reserve/server into dev_1.0.0

haogh 1 年之前
父节点
当前提交
e0c1892f1e

+ 14 - 0
src/main/java/com/qmth/exam/reserve/cache/CacheConstants.java

@@ -25,6 +25,20 @@ public interface CacheConstants {
      */
      */
     String CACHE_STUDENT_LOGIN = "S_";
     String CACHE_STUDENT_LOGIN = "S_";
 
 
+    /**
+     * 当前预约任务 - 某考点某时段的“可预约总量”的缓存
+     * $cache:apply_total_{examSiteId}_{timePeriodId}
+     * Value:总量
+     */
+    String CACHE_APPLY_TOTAL = "apply_total_%s_%s";
+
+    /**
+     * 当前预约任务 - 某考点某时段的“已预约数量”的缓存
+     * $cache:apply_finish_{examSiteId}_{timePeriodId}
+     * Value:已约量
+     */
+    String CACHE_APPLY_FINISH = "apply_finish_%s_%s";
+
     /**
     /**
      * 某考生预约操作锁
      * 某考生预约操作锁
      * $lock:student_apply_{studentId}
      * $lock:student_apply_{studentId}

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

@@ -0,0 +1,41 @@
+package com.qmth.exam.reserve.cache.impl;
+
+import com.qmth.exam.reserve.cache.CacheConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ApplyTaskCacheService implements CacheConstants {
+
+    private static final Logger log = LoggerFactory.getLogger(ApplyTaskCacheService.class);
+
+    /**
+     * 获取某考点某时段的“可预约总量”
+     */
+    public int getApplyTotalCount(Long examSiteId, Long timePeriodId) {
+        return 1;
+    }
+
+    /**
+     * 获取某考点某时段的“已预约数量”
+     */
+    public int getApplyFinishCount(Long examSiteId, Long timePeriodId) {
+        return 0;
+    }
+
+    /**
+     * 累加 某考点某时段的“已预约数量”
+     */
+    public void increaseApplyFinishCount(Long examSiteId, Long timePeriodId) {
+
+    }
+
+    /**
+     * 累减 某考点某时段的“已预约数量”
+     */
+    public void decreaseApplyFinishCount(Long examSiteId, Long timePeriodId) {
+
+    }
+
+}

+ 0 - 13
src/main/java/com/qmth/exam/reserve/cache/impl/CacheManager.java

@@ -1,13 +0,0 @@
-package com.qmth.exam.reserve.cache.impl;
-
-import com.qmth.exam.reserve.cache.CacheConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
-
-@Component
-public class CacheManager implements CacheConstants {
-
-    private static final Logger log = LoggerFactory.getLogger(CacheManager.class);
-
-}

+ 2 - 3
src/main/java/com/qmth/exam/reserve/entity/StudentEntity.java

@@ -2,7 +2,6 @@ package com.qmth.exam.reserve.entity;
 
 
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.qmth.exam.reserve.entity.base.BaseEntity;
 import com.qmth.exam.reserve.entity.base.BaseEntity;
-
 import lombok.Getter;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.Setter;
 
 
@@ -64,7 +63,7 @@ public class StudentEntity extends BaseEntity {
     private Integer applyNumber;
     private Integer applyNumber;
 
 
     /**
     /**
-     * 预约时段是否全部完成
+     * 预约时段是否全部完成(该字段已废弃)
      */
      */
     private Boolean applyFinished;
     private Boolean applyFinished;
 
 
@@ -72,7 +71,7 @@ public class StudentEntity extends BaseEntity {
      * 所属机构ID(学校)
      * 所属机构ID(学校)
      */
      */
     private Long orgId;
     private Long orgId;
-    
+
     /**
     /**
      * 考生密码
      * 考生密码
      */
      */

+ 29 - 11
src/main/java/com/qmth/exam/reserve/service/impl/ExamReserveServiceImpl.java

@@ -13,6 +13,7 @@ import com.qmth.exam.reserve.bean.apply.TimePeriodInfo;
 import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.cache.CacheConstants;
 import com.qmth.exam.reserve.cache.CacheConstants;
+import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
 import com.qmth.exam.reserve.dao.StudentApplyDao;
 import com.qmth.exam.reserve.dao.StudentApplyDao;
 import com.qmth.exam.reserve.entity.*;
 import com.qmth.exam.reserve.entity.*;
 import com.qmth.exam.reserve.enums.ApplyStatus;
 import com.qmth.exam.reserve.enums.ApplyStatus;
@@ -51,6 +52,9 @@ public class ExamReserveServiceImpl implements ExamReserveService {
     @Autowired
     @Autowired
     private ExamSiteService examSiteService;
     private ExamSiteService examSiteService;
 
 
+    @Autowired
+    private ApplyTaskCacheService applyTaskCacheService;
+
     @Autowired
     @Autowired
     private ConcurrentService concurrentService;
     private ConcurrentService concurrentService;
 
 
@@ -112,19 +116,21 @@ public class ExamReserveServiceImpl implements ExamReserveService {
                 throw new StatusException("学生信息不存在");
                 throw new StatusException("学生信息不存在");
             }
             }
 
 
-            if (stu.getApplyFinished()) {
-                String msg = "当前学生无剩余可约时段,已完成预约" + stu.getApplyNumber() + "次";
+            int studentApplyFinishCount = this.getStudentApplyFinishCount(student.getId());
+            if (stu.getApplyNumber() - studentApplyFinishCount < 1) {
+                String msg = "当前学生无剩余可约时段次数,已完成预约" + stu.getApplyNumber() + "次";
                 log.warn(msg);
                 log.warn(msg);
-                // throw new StatusException(msg);
+                // throw new StatusException(msg);todo
             }
             }
 
 
             // 当前预约时段剩余可约数量
             // 当前预约时段剩余可约数量
-            int availableCount = 0;//todo
-            // if (availableCount == 0) {
-            //     throw new StatusException("当前预约时段已约满");
-            // }
-
-            // 更新预约时段、机房容量等操作
+            int totalCount = applyTaskCacheService.getApplyTotalCount(examSiteId, timePeriodId);
+            int finishCount = applyTaskCacheService.getApplyFinishCount(examSiteId, timePeriodId);
+            int availableCount = totalCount - finishCount;
+            if (availableCount < 1) {
+                log.warn("预约失败,当前预约时段已约满!totalCount:{} finishCount:{}", totalCount, finishCount);
+                throw new StatusException("当前预约时段已约满");
+            }
 
 
             LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
             LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
             wrapper.eq(StudentApplyEntity::getStudentId, student.getId());
             wrapper.eq(StudentApplyEntity::getStudentId, student.getId());
@@ -150,6 +156,9 @@ public class ExamReserveServiceImpl implements ExamReserveService {
                 studentApplyService.save(entity);
                 studentApplyService.save(entity);
                 log.warn("新增考生预约记录!applyId:{} examSiteId:{} timePeriodId:{}", entity.getId(), examSiteId, timePeriodId);
                 log.warn("新增考生预约记录!applyId:{} examSiteId:{} timePeriodId:{}", entity.getId(), examSiteId, timePeriodId);
             }
             }
+
+            // 某考点某时段的“已预约数量” 累加1
+            applyTaskCacheService.increaseApplyFinishCount(examSiteId, timePeriodId);
         } finally {
         } finally {
             studentApplyLock.unlock();
             studentApplyLock.unlock();
         }
         }
@@ -220,8 +229,10 @@ public class ExamReserveServiceImpl implements ExamReserveService {
 
 
             this.updateStudentApplyForCancel(applyId, true, student.getId());
             this.updateStudentApplyForCancel(applyId, true, student.getId());
 
 
-            // todo
-            // 更新预约时段、机房容量等操作
+            // 某考点某时段的“已预约数量” 累减1
+            applyTaskCacheService.decreaseApplyFinishCount(studentApply.getExamSiteId(), studentApply.getTimePeriodId());
+
+            // todo 取消预约事件
         } finally {
         } finally {
             studentApplyLock.unlock();
             studentApplyLock.unlock();
         }
         }
@@ -237,6 +248,13 @@ public class ExamReserveServiceImpl implements ExamReserveService {
         log.warn("更新考生预约记录!applyId:{} cancel:{}", applyId, cancel);
         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);
+    }
+
     @Override
     @Override
     public List<ApplyVO> getStudentApplyList(LoginUser student, Boolean cancel) {
     public List<ApplyVO> getStudentApplyList(LoginUser student, Boolean cancel) {
         CurrentApplyTaskVO curApplyTask = applyTaskService.currentApplyTask(student.getOrgId());
         CurrentApplyTaskVO curApplyTask = applyTaskService.currentApplyTask(student.getOrgId());