Browse Source

update 预约时段校验

deason 8 months ago
parent
commit
3ff5f142bb

+ 10 - 1
src/main/java/com/qmth/exam/reserve/dao/TimePeriodExamSiteDao.java

@@ -9,6 +9,15 @@ import java.util.List;
 
 public interface TimePeriodExamSiteDao extends BaseMapper<TimePeriodExamSiteEntity> {
 
-    List<ExamSiteTimePeriodInfo> allTimePeriods(@Param("applyTaskId") Long applyTaskId, @Param("examSiteId") Long examSiteId);
+    List<ExamSiteTimePeriodInfo> findAllTimePeriodsForApply(
+            @Param("applyTaskId") Long applyTaskId,
+            @Param("examSiteId") Long examSiteId
+    );
+
+    ExamSiteTimePeriodInfo findOneTimePeriodForApply(
+            @Param("applyTaskId") Long applyTaskId,
+            @Param("examSiteId") Long examSiteId,
+            @Param("timePeriodId") Long timePeriodId
+    );
 
 }

+ 6 - 0
src/main/java/com/qmth/exam/reserve/service/TimePeriodExamSiteService.java

@@ -1,6 +1,7 @@
 package com.qmth.exam.reserve.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodInfo;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
 import com.qmth.exam.reserve.entity.TimePeriodExamSiteEntity;
 
@@ -11,4 +12,9 @@ public interface TimePeriodExamSiteService extends IService<TimePeriodExamSiteEn
     List<String> listTimePeriod(Long taskId);
 
     List<TimePeriodExamSiteVo> ListDetail(Long taskId, Long examSiteId);
+
+    List<ExamSiteTimePeriodInfo> findAllTimePeriodsForApply(Long applyTaskId, Long examSiteId);
+
+    ExamSiteTimePeriodInfo findOneTimePeriodForApply(Long applyTaskId, Long examSiteId, Long timePeriodId);
+
 }

+ 3 - 5
src/main/java/com/qmth/exam/reserve/service/impl/ExamReserveServiceImpl.java

@@ -15,7 +15,6 @@ import com.qmth.exam.reserve.cache.CacheConstants;
 import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
 import com.qmth.exam.reserve.cache.impl.ExamSiteCacheService;
 import com.qmth.exam.reserve.dao.StudentApplyDao;
-import com.qmth.exam.reserve.dao.TimePeriodExamSiteDao;
 import com.qmth.exam.reserve.entity.ApplyTaskEntity;
 import com.qmth.exam.reserve.entity.ExamSiteEntity;
 import com.qmth.exam.reserve.entity.StudentApplyEntity;
@@ -94,8 +93,8 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             throw new StatusException("当前预约任务与学生的不匹配");
         }
 
-        TimePeriodEntity timePeriod = timePeriodService.getById(timePeriodId);
-        if (timePeriod == null || !curApplyTask.getTaskId().equals(timePeriod.getApplyTaskId())) {
+        ExamSiteTimePeriodInfo timePeriod = timePeriodExamSiteService.findOneTimePeriodForApply(curApplyTask.getTaskId(), examSiteId, timePeriodId);
+        if (timePeriod == null || !timePeriod.getEnable()) {
             log.warn("预约失败,当前预约时段信息有误!timePeriodId:{}", timePeriodId);
             throw new StatusException("当前预约时段信息有误");
         }
@@ -503,8 +502,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             return dateList;
         }
 
-        TimePeriodExamSiteDao baseMapper = (TimePeriodExamSiteDao) timePeriodExamSiteService.getBaseMapper();
-        List<ExamSiteTimePeriodInfo> timePeriods = baseMapper.allTimePeriods(curApplyTask.getTaskId(), examSiteId);
+        List<ExamSiteTimePeriodInfo> timePeriods = timePeriodExamSiteService.findAllTimePeriodsForApply(curApplyTask.getTaskId(), examSiteId);
         if (CollectionUtils.isEmpty(timePeriods)) {
             return dateList;
         }

+ 12 - 0
src/main/java/com/qmth/exam/reserve/service/impl/TimePeriodExamSiteServiceImpl.java

@@ -2,6 +2,7 @@ package com.qmth.exam.reserve.service.impl;
 
 import com.aliyuncs.utils.StringUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodInfo;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteBean;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteInfo;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
@@ -97,5 +98,16 @@ public class TimePeriodExamSiteServiceImpl extends ServiceImpl<TimePeriodExamSit
         return list;
     }
 
+    @Override
+    public List<ExamSiteTimePeriodInfo> findAllTimePeriodsForApply(Long applyTaskId, Long examSiteId) {
+        // 获取考点下所有的时段列表(含启用禁用状态)
+        return baseMapper.findAllTimePeriodsForApply(applyTaskId, examSiteId);
+    }
+
+    @Override
+    public ExamSiteTimePeriodInfo findOneTimePeriodForApply(Long applyTaskId, Long examSiteId, Long timePeriodId) {
+        // 获取考点下某个具体的时段(含启用禁用状态)
+        return baseMapper.findOneTimePeriodForApply(applyTaskId, examSiteId, timePeriodId);
+    }
 
 }

+ 13 - 1
src/main/resources/mapper/TimePeriodExamSiteMapper.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.exam.reserve.dao.TimePeriodExamSiteDao">
 
-    <select id="allTimePeriods" resultType="com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodInfo">
+    <select id="findAllTimePeriodsForApply" resultType="com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodInfo">
         select p.id                                        as time_period_id,
                p.start_time,
                p.end_time,
@@ -12,4 +12,16 @@
         where p.apply_task_id = #{applyTaskId}
     </select>
 
+    <select id="findOneTimePeriodForApply"
+            resultType="com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodInfo">
+        select p.id                                        as time_period_id,
+               p.start_time,
+               p.end_time,
+               (case when pe.enable = 0 then 0 else 1 end) as enable
+        from t_time_period p
+                 left join t_time_period_exam_site pe on pe.time_period_id = p.id and pe.exam_site_id = #{examSiteId}
+        where p.apply_task_id = #{applyTaskId}
+          and p.id = #{timePeriodId}
+    </select>
+
 </mapper>