Pārlūkot izejas kodu

update findExamSiteTimePeriods

deason 8 mēneši atpakaļ
vecāks
revīzija
da350196c9

+ 29 - 0
src/main/java/com/qmth/exam/reserve/bean/apply/ExamSiteTimePeriodQuery.java

@@ -0,0 +1,29 @@
+package com.qmth.exam.reserve.bean.apply;
+
+import com.qmth.exam.reserve.bean.IModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class ExamSiteTimePeriodQuery implements IModel {
+
+    private static final long serialVersionUID = 8158455040867688700L;
+
+    @ApiModelProperty(value = "预约任务ID")
+    private Long applyTaskId;
+
+    @ApiModelProperty(value = "考点ID")
+    private Long examSiteId;
+
+    @ApiModelProperty(value = "预约时段ID")
+    private Long timePeriodId;
+
+    @ApiModelProperty(value = "预约时段起点")
+    private Long timeBegin;
+
+    @ApiModelProperty(value = "预约时段终点")
+    private Long timeEnd;
+
+}

+ 3 - 0
src/main/java/com/qmth/exam/reserve/bean/apply/TimePeriodInfo.java

@@ -27,4 +27,7 @@ public class TimePeriodInfo implements IModel {
     @ApiModelProperty(value = "状态")
     private ApplyStatus status;
 
+    @ApiModelProperty(value = "是否启用")
+    private Boolean enable;
+
 }

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

@@ -2,6 +2,7 @@ package com.qmth.exam.reserve.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodInfo;
+import com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodQuery;
 import com.qmth.exam.reserve.entity.TimePeriodExamSiteEntity;
 import org.apache.ibatis.annotations.Param;
 
@@ -9,15 +10,6 @@ import java.util.List;
 
 public interface TimePeriodExamSiteDao extends BaseMapper<TimePeriodExamSiteEntity> {
 
-    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
-    );
+    List<ExamSiteTimePeriodInfo> findExamSiteTimePeriods(@Param("query") ExamSiteTimePeriodQuery query);
 
 }

+ 5 - 4
src/main/java/com/qmth/exam/reserve/service/TimePeriodExamSiteService.java

@@ -2,6 +2,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.apply.ExamSiteTimePeriodQuery;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteReq;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
 import com.qmth.exam.reserve.entity.TimePeriodExamSiteEntity;
@@ -10,13 +11,13 @@ import java.util.List;
 
 public interface TimePeriodExamSiteService extends IService<TimePeriodExamSiteEntity> {
 
-    List<String> listTimePeriod(Long taskId);
+    List<ExamSiteTimePeriodInfo> findExamSiteTimePeriods(ExamSiteTimePeriodQuery query);
 
-    List<TimePeriodExamSiteVo> ListDetail(Long examSiteId);
+    ExamSiteTimePeriodInfo findOneExamSiteTimePeriod(Long applyTaskId, Long examSiteId, Long timePeriodId);
 
-    List<ExamSiteTimePeriodInfo> findAllTimePeriodsForApply(Long applyTaskId, Long examSiteId);
+    List<String> listTimePeriod(Long taskId);
 
-    ExamSiteTimePeriodInfo findOneTimePeriodForApply(Long applyTaskId, Long examSiteId, Long timePeriodId);
+    List<TimePeriodExamSiteVo> ListDetail(Long examSiteId);
 
     void save(Long operateId, Long examSiteId, List<TimePeriodExamSiteReq> timePeriodExamSiteList);
 

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

@@ -93,10 +93,10 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             throw new StatusException("当前预约任务与学生的不匹配");
         }
 
-        ExamSiteTimePeriodInfo timePeriod = timePeriodExamSiteService.findOneTimePeriodForApply(curApplyTask.getTaskId(), examSiteId, timePeriodId);
+        ExamSiteTimePeriodInfo timePeriod = timePeriodExamSiteService.findOneExamSiteTimePeriod(curApplyTask.getTaskId(), examSiteId, timePeriodId);
         if (timePeriod == null || !timePeriod.getEnable()) {
-            log.warn("预约失败,当前预约时段信息有误!timePeriodId:{}", timePeriodId);
-            throw new StatusException("当前预约时段信息有误");
+            log.warn("预约失败,当前预约时段不存在或未启用!timePeriodId:{}", timePeriodId);
+            throw new StatusException("当前预约时段不存在或未启用");
         }
 
         // 考前N天,禁止考生自主预约
@@ -502,7 +502,10 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             return dateList;
         }
 
-        List<ExamSiteTimePeriodInfo> timePeriods = timePeriodExamSiteService.findAllTimePeriodsForApply(curApplyTask.getTaskId(), examSiteId);
+        ExamSiteTimePeriodQuery periodQuery = new ExamSiteTimePeriodQuery();
+        periodQuery.setApplyTaskId(curApplyTask.getTaskId());
+        periodQuery.setExamSiteId(examSiteId);
+        List<ExamSiteTimePeriodInfo> timePeriods = timePeriodExamSiteService.findExamSiteTimePeriods(periodQuery);
         if (CollectionUtils.isEmpty(timePeriods)) {
             return dateList;
         }
@@ -540,11 +543,11 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             throw new StatusException("预约日期不能为空");
         }
 
-        Date startTime, endTime;
+        Date timeBegin, timeEnd;
         try {
             FastDateFormat fdf = FastDateFormat.getInstance("yyyyMMddHHmmss");
-            startTime = fdf.parse(date + "000000");
-            endTime = fdf.parse(date + "235959");
+            timeBegin = fdf.parse(date + "000000");
+            timeEnd = fdf.parse(date + "235959");
         } catch (ParseException e) {
             log.error(e.getMessage(), e);
             throw new StatusException("预约日期值的格式不正确");
@@ -560,11 +563,12 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             throw new StatusException("未到预约时间");
         }
 
-        LambdaQueryWrapper<TimePeriodEntity> wrapper = new LambdaQueryWrapper<>();
-        wrapper.select(TimePeriodEntity::getId, TimePeriodEntity::getStartTime, TimePeriodEntity::getEndTime);
-        wrapper.eq(TimePeriodEntity::getApplyTaskId, curApplyTask.getTaskId());
-        wrapper.between(TimePeriodEntity::getStartTime, startTime.getTime(), endTime.getTime());
-        List<TimePeriodEntity> timePeriods = timePeriodService.list(wrapper);
+        ExamSiteTimePeriodQuery periodQuery = new ExamSiteTimePeriodQuery();
+        periodQuery.setApplyTaskId(curApplyTask.getTaskId());
+        periodQuery.setExamSiteId(examSiteId);
+        periodQuery.setTimeBegin(timeBegin.getTime());
+        periodQuery.setTimeEnd(timeEnd.getTime());
+        List<ExamSiteTimePeriodInfo> timePeriods = timePeriodExamSiteService.findExamSiteTimePeriods(periodQuery);
 
         // 获取某考生的 所有的“预约记录”
         Map<String, ApplyRecordCacheBean> maps = applyTaskCacheService.getStudentApplyRecordsFromDB(student.getId());
@@ -581,13 +585,14 @@ public class ExamReserveServiceImpl implements ExamReserveService {
 
         List<TimePeriodInfo> periodList = new ArrayList<>();
         if (CollectionUtils.isNotEmpty(timePeriods)) {
-            for (TimePeriodEntity timePeriod : timePeriods) {
+            for (ExamSiteTimePeriodInfo timePeriod : timePeriods) {
                 TimePeriodInfo info = new TimePeriodInfo();
-                info.setTimePeriodId(timePeriod.getId());
+                info.setTimePeriodId(timePeriod.getTimePeriodId());
                 info.setTimePeriodStart(timePeriod.getStartTime());
                 info.setTimePeriodEnd(timePeriod.getEndTime());
+                info.setEnable(timePeriod.getEnable());
 
-                int availableCount = applyTaskCacheService.getApplyAvailableCount(examSiteId, timePeriod.getId());
+                int availableCount = applyTaskCacheService.getApplyAvailableCount(examSiteId, timePeriod.getTimePeriodId());
                 info.setAvailableCount(availableCount);
                 if (availableCount < 1) {
                     info.setStatus(ApplyStatus.FULL);
@@ -595,7 +600,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
                     info.setStatus(ApplyStatus.AVAILABLE);
                 }
 
-                String hashKey = String.format("%s_%s", examSiteId, timePeriod.getId());
+                String hashKey = String.format("%s_%s", examSiteId, timePeriod.getTimePeriodId());
                 ApplyRecordCacheBean existApply = maps.get(hashKey);
                 if (existApply != null && !existApply.getCancel()) {
                     info.setStatus(ApplyStatus.FINISHED);

+ 25 - 6
src/main/java/com/qmth/exam/reserve/service/impl/TimePeriodExamSiteServiceImpl.java

@@ -2,7 +2,9 @@ package com.qmth.exam.reserve.service.impl;
 
 import com.aliyuncs.utils.StringUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.core.exception.StatusException;
 import com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodInfo;
+import com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodQuery;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteBean;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteInfo;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteReq;
@@ -53,7 +55,7 @@ public class TimePeriodExamSiteServiceImpl extends ServiceImpl<TimePeriodExamSit
     }
 
     @Override
-    public List<TimePeriodExamSiteVo> ListDetail( Long examSiteId) {
+    public List<TimePeriodExamSiteVo> ListDetail(Long examSiteId) {
         Long taskId = getTaskId(null);
         // 所有的预约日期
         List<String> dateList = timePeriodService.listTimePeriodDate(taskId);
@@ -151,15 +153,32 @@ public class TimePeriodExamSiteServiceImpl extends ServiceImpl<TimePeriodExamSit
     }
 
     @Override
-    public List<ExamSiteTimePeriodInfo> findAllTimePeriodsForApply(Long applyTaskId, Long examSiteId) {
-        // 获取考点下所有的时段列表(含启用禁用状态)
-        return baseMapper.findAllTimePeriodsForApply(applyTaskId, examSiteId);
+    public List<ExamSiteTimePeriodInfo> findExamSiteTimePeriods(ExamSiteTimePeriodQuery query) {
+        if (query.getApplyTaskId() == null) {
+            throw new StatusException("预约任务ID不能为空");
+        }
+        if (query.getExamSiteId() == null) {
+            throw new StatusException("考点ID不能为空");
+        }
+
+        // 获取考点下所有相关的时段列表(含启用禁用状态)
+        return baseMapper.findExamSiteTimePeriods(query);
     }
 
     @Override
-    public ExamSiteTimePeriodInfo findOneTimePeriodForApply(Long applyTaskId, Long examSiteId, Long timePeriodId) {
+    public ExamSiteTimePeriodInfo findOneExamSiteTimePeriod(Long applyTaskId, Long examSiteId, Long timePeriodId) {
+        if (timePeriodId == null) {
+            throw new StatusException("预约时段ID不能为空");
+        }
+
         // 获取考点下某个具体的时段(含启用禁用状态)
-        return baseMapper.findOneTimePeriodForApply(applyTaskId, examSiteId, timePeriodId);
+        ExamSiteTimePeriodQuery periodQuery = new ExamSiteTimePeriodQuery();
+        periodQuery.setApplyTaskId(applyTaskId);
+        periodQuery.setExamSiteId(examSiteId);
+        periodQuery.setTimePeriodId(timePeriodId);
+
+        List<ExamSiteTimePeriodInfo> periods = this.findExamSiteTimePeriods(periodQuery);
+        return CollectionUtils.isEmpty(periods) ? null : periods.get(0);
     }
 
 }

+ 15 - 18
src/main/resources/mapper/TimePeriodExamSiteMapper.xml

@@ -2,26 +2,23 @@
 <!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="findAllTimePeriodsForApply" 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
+    <select id="findExamSiteTimePeriods" 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}
-    </select>
+        left join t_time_period_exam_site pe on pe.time_period_id = p.id and pe.exam_site_id = #{query.examSiteId}
 
-    <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}
+        where p.apply_task_id = #{query.applyTaskId}
+
+        <if test="query.timePeriodId != null">
+            and p.id = #{query.timePeriodId}
+        </if>
+
+        <if test="query.timeBegin != null and query.timeEnd != null">
+            and p.start_time between #{query.timeBegin} and #{query.timeEnd}
+        </if>
     </select>
 
 </mapper>