deason 8 月之前
父节点
当前提交
cd60ed0c31

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

@@ -154,7 +154,6 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             }
 
             try {
-                // StudentApplyEntity existApply = applyTaskCacheService.getStudentApplyRecordFormDB(student.getId(), examSiteId, timePeriodId);
                 ApplyRecordCacheBean existApply = applyTaskCacheService.getStudentApplyRecord(student.getId(), examSiteId, timePeriodId);
                 if (existApply != null) {
                     if (!existApply.getCancel()) {
@@ -169,12 +168,14 @@ public class ExamReserveServiceImpl implements ExamReserveService {
                     existApply.setCancel(false);
                     existApply.setOperateId(student.getId());
                     existApply.setOperateTime(System.currentTimeMillis());
+
                     // 推送至预约队列
-                    applyTaskCacheService.pushStudentApplyRecordQueue(existApply);
+                    boolean pushSuccess = applyTaskCacheService.pushStudentApplyRecordQueue(existApply);
+                    if (!pushSuccess) {
+                        throw new RuntimeException("预约消息推送失败,请稍后再试!");
+                    }
                     // 保存至预约缓存
                     applyTaskCacheService.saveStudentApplyRecord(existApply);
-
-                    // this.updateStudentApplyForCancel(existApply.getId(), false, student.getId());
                 } else {
                     // 不存在则新增预约记录
                     ApplyRecordCacheBean newApply = new ApplyRecordCacheBean();
@@ -184,12 +185,14 @@ public class ExamReserveServiceImpl implements ExamReserveService {
                     newApply.setCancel(false);
                     newApply.setOperateId(student.getId());
                     newApply.setOperateTime(System.currentTimeMillis());
+
                     // 推送至预约队列
-                    applyTaskCacheService.pushStudentApplyRecordQueue(newApply);
+                    boolean pushSuccess = applyTaskCacheService.pushStudentApplyRecordQueue(newApply);
+                    if (!pushSuccess) {
+                        throw new RuntimeException("预约消息推送失败,请稍后再试!");
+                    }
                     // 保存至预约缓存
                     applyTaskCacheService.saveStudentApplyRecord(newApply);
-
-                    // this.addStudentApply(newApply);
                 }
 
                 log.warn("预约成功!studentId:{} examSiteId:{} timePeriodId:{}", student.getId(), examSiteId, timePeriodId);
@@ -282,15 +285,17 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             existApply.setCancel(true);
             existApply.setOperateId(student.getId());
             existApply.setOperateTime(System.currentTimeMillis());
+
             // 推送至预约队列
-            applyTaskCacheService.pushStudentApplyRecordQueue(existApply);
+            boolean pushSuccess = applyTaskCacheService.pushStudentApplyRecordQueue(existApply);
+            if (!pushSuccess) {
+                throw new RuntimeException("预约消息推送失败,请稍后再试!");
+            }
             // 保存至预约缓存
             applyTaskCacheService.saveStudentApplyRecord(existApply);
-
-            // this.updateStudentApplyForCancel(existApply.getId(), true, student.getId());
-
             // 某考点某时段的“剩余可约数量” 累加1(归还1个被占数量)
             applyTaskCacheService.increaseApplyAvailableCount(examSiteId, timePeriodId);
+
             log.warn("取消预约成功!studentId:{} examSiteId:{} timePeriodId:{}", student.getId(), examSiteId, timePeriodId);
         } finally {
             try {

+ 10 - 3
src/main/java/com/qmth/exam/reserve/service/impl/StudentApplyServiceImpl.java

@@ -202,7 +202,10 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 bean.setOperateTime(System.currentTimeMillis());
 
                 // 推送至预约队列
-                cacheService.pushStudentApplyRecordQueue(bean);
+                boolean pushSuccess = cacheService.pushStudentApplyRecordQueue(bean);
+                if (!pushSuccess) {
+                    throw new RuntimeException("预约消息推送失败,请稍后再试!");
+                }
                 // 保存至预约缓存
                 cacheService.saveStudentApplyRecord(bean);
                 // 某考点某时段的“剩余可约数量”(归还1个被占数量)
@@ -517,12 +520,16 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                         throw new StatusException(message);
                     }
                     // 推送至预约队列
-                    cacheService.pushStudentApplyRecordQueue(bean);
+                    boolean pushSuccess = cacheService.pushStudentApplyRecordQueue(bean);
+                    if (!pushSuccess) {
+                        // 推送失败时,归还1个被占数量
+                        cacheService.increaseApplyAvailableCount(bean.getExamSiteId(), bean.getTimePeriodId());
+                        throw new RuntimeException("预约消息推送失败,请稍后再试!");
+                    }
                     // 保存至预约缓存
                     cacheService.saveStudentApplyRecord(bean);
                 }
             }
-
         } catch (Exception e) {
             log.error("[importPreExam] 导入预约失败,msg:{}", e.getMessage());
             throw new StatusException("导入预考失败,错误原因:" + e.getMessage());

+ 10 - 3
src/main/java/com/qmth/exam/reserve/service/impl/StudentAutoAssignServiceImpl.java

@@ -252,12 +252,19 @@ public class StudentAutoAssignServiceImpl extends ServiceImpl<StudentApplyDao, S
                         // 某考点某时段的“剩余可约数量”(抢占1个数量)
                         boolean takeSuccess = cacheService.decreaseApplyAvailableCount(bean.getExamSiteId(), bean.getTimePeriodId());
                         if (!takeSuccess) {
-                            log.warn("预约失败,当前预约时段已约满!examSiteId:{} timePeriodId:{} studentId:{}", bean.getExamSiteId(), bean.getTimePeriodId(),
-                                    bean.getStudentId());
+                            log.warn("预约失败,当前预约时段已约满!examSiteId:{} timePeriodId:{} studentId:{}",
+                                    bean.getExamSiteId(), bean.getTimePeriodId(), bean.getStudentId());
                             continue;
                         }
                         // 推送至预约队列
-                        cacheService.pushStudentApplyRecordQueue(bean);
+                        boolean pushSuccess = cacheService.pushStudentApplyRecordQueue(bean);
+                        if (!pushSuccess) {
+                            // 推送失败时,归还1个被占数量
+                            cacheService.increaseApplyAvailableCount(bean.getExamSiteId(), bean.getTimePeriodId());
+                            log.warn("预约消息推送失败!examSiteId:{} timePeriodId:{} studentId:{}", bean.getExamSiteId(),
+                                    bean.getTimePeriodId(), bean.getStudentId());
+                            continue;
+                        }
                         // 保存至预约缓存
                         cacheService.saveStudentApplyRecord(bean);