deason 1 жил өмнө
parent
commit
45e1072412

+ 35 - 24
src/main/java/com/qmth/exam/reserve/service/impl/ExamReserveServiceImpl.java

@@ -130,32 +130,43 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             // 某考点某时段的“已预约数量” 累加1(优先执行抢占1个数量)
             applyTaskCacheService.increaseApplyFinishCount(examSiteId, timePeriodId);
 
-            LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
-            wrapper.eq(StudentApplyEntity::getStudentId, student.getId());
-            wrapper.eq(StudentApplyEntity::getExamSiteId, examSiteId);
-            wrapper.eq(StudentApplyEntity::getTimePeriodId, timePeriodId);
-            StudentApplyEntity existEntity = studentApplyService.getOne(wrapper);
-            if (existEntity != null) {
-                if (!existEntity.getCancel()) {
-                    // 某考点某时段的“已预约数量” 累减1(释放1个数量)
-                    applyTaskCacheService.decreaseApplyFinishCount(examSiteId, timePeriodId);
-
-                    log.warn("预约失败,当前时段已预约,请勿重复预约!applyId:{}", existEntity.getId());
-                    throw new StatusException("当前时段已预约,请勿重复预约");
+            try {
+                LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
+                wrapper.eq(StudentApplyEntity::getStudentId, student.getId());
+                wrapper.eq(StudentApplyEntity::getExamSiteId, examSiteId);
+                wrapper.eq(StudentApplyEntity::getTimePeriodId, timePeriodId);
+                StudentApplyEntity existEntity = studentApplyService.getOne(wrapper);
+                if (existEntity != null) {
+                    if (!existEntity.getCancel()) {
+                        // 某考点某时段的“已预约数量” 累减1(释放1个被占数量)
+                        applyTaskCacheService.decreaseApplyFinishCount(examSiteId, timePeriodId);
+
+                        log.warn("预约失败,当前时段已预约,请勿重复预约!applyId:{}", existEntity.getId());
+                        throw new StatusException("当前时段已预约,请勿重复预约");
+                    }
+
+                    // 存在“已取消”预约记录,则恢复预约
+                    this.updateStudentApplyForCancel(existEntity.getId(), false, student.getId());
+                } else {
+                    // 不存在则新增预约记录
+                    StudentApplyEntity entity = new StudentApplyEntity();
+                    entity.setStudentId(student.getId());
+                    entity.setExamSiteId(examSiteId);
+                    entity.setTimePeriodId(timePeriodId);
+                    entity.setOperateId(student.getId());
+                    entity.setCancel(false);
+                    studentApplyService.save(entity);
+                    log.warn("新增考生预约记录!applyId:{} examSiteId:{} timePeriodId:{}", entity.getId(), examSiteId, timePeriodId);
+                }
+            } catch (Exception e) {
+                if (e instanceof StatusException) {
+                    throw e;
                 }
 
-                // 存在“已取消”预约记录,则恢复预约
-                this.updateStudentApplyForCancel(existEntity.getId(), false, student.getId());
-            } else {
-                // 不存在则新增预约记录
-                StudentApplyEntity entity = new StudentApplyEntity();
-                entity.setStudentId(student.getId());
-                entity.setExamSiteId(examSiteId);
-                entity.setTimePeriodId(timePeriodId);
-                entity.setOperateId(student.getId());
-                entity.setCancel(false);
-                studentApplyService.save(entity);
-                log.warn("新增考生预约记录!applyId:{} examSiteId:{} timePeriodId:{}", entity.getId(), examSiteId, timePeriodId);
+                // 异常时,释放1个被占数量
+                applyTaskCacheService.decreaseApplyFinishCount(examSiteId, timePeriodId);
+                log.error("预约结果保存失败!examSiteId:{} timePeriodId:{} err:{}", examSiteId, timePeriodId, e.getMessage());
+                throw new StatusException("预约失败,请稍后再试!", e);
             }
         } finally {
             studentApplyLock.unlock();