Răsfoiți Sursa

添加时段缓存验证

haogh 4 săptămâni în urmă
părinte
comite
70e4991320

+ 26 - 7
src/main/java/com/qmth/exam/reserve/service/impl/ApplyTaskServiceImpl.java

@@ -3,6 +3,8 @@ package com.qmth.exam.reserve.service.impl;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -36,6 +38,8 @@ import com.qmth.exam.reserve.util.PageUtil;
 @Service
 public class ApplyTaskServiceImpl extends ServiceImpl<ApplyTaskDao, ApplyTaskEntity> implements ApplyTaskService {
 
+    private static final Logger log = LoggerFactory.getLogger(ApplyTaskServiceImpl.class);
+
     @Autowired
     private OperateLogService logService;
 
@@ -176,19 +180,34 @@ public class ApplyTaskServiceImpl extends ServiceImpl<ApplyTaskDao, ApplyTaskEnt
     }
 
     @Override
-    public void deleteRule(Long timeId) {
-        if (timeId == null) {
+    public void deleteRule(Long timePeriodId) {
+        if (timePeriodId == null) {
             return;
         }
-        LambdaQueryWrapper<StudentApplyEntity> lm = new LambdaQueryWrapper<>();
-        lm.eq(StudentApplyEntity::getTimePeriodId, timeId);
-        lm.eq(StudentApplyEntity::getCancel, Boolean.FALSE);
 
-        if (studentApplyService.count(lm) > 0) {
+        // 检查缓存中是否被预约过
+        try {
+            if (cacheService.existTimePeriodUsedCache(timePeriodId)) {
+                throw new StatusException("该时段已被预约,不能删除");
+            }
+        } catch (Exception e) {
+            log.error("[删除时段]缓存检查异常,timeId={}", timePeriodId, e);
+            throw new StatusException("缓存检查失败,请稍后重试");
+        }
+
+        // 检查数据库中是否有预约记录
+        LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(StudentApplyEntity::getTimePeriodId, timePeriodId);
+
+        if (studentApplyService.count(wrapper) > 0) {
             throw new StatusException("考生已经预约,不能删除预约时段");
         }
 
-        timePeriodService.removeById(timeId);
+        // 执行删除并记录结果
+        boolean removed = timePeriodService.removeById(timePeriodId);
+        if (!removed) {
+            log.warn("[删除时段]删除时段失败,timeId={}", timePeriodId);
+        }
     }
 
 }