deason 1 rok temu
rodzic
commit
429e38c9f1

+ 2 - 2
src/main/java/com/qmth/exam/reserve/bean/applytask/CurrentApplyTaskVO.java

@@ -24,10 +24,10 @@ public class CurrentApplyTaskVO implements IModel {
     private String taskName;
 
     @ApiModelProperty("考前多少天,禁止考生自主预约")
-    private Long allowApplyDays;
+    private Integer allowApplyDays;
 
     @ApiModelProperty("考前多少天,禁止考生自主取消预约")
-    private Long allowApplyCancelDays;
+    private Integer allowApplyCancelDays;
 
     @ApiModelProperty("自主预约起始时间")
     private Long selfApplyStartTime;

+ 2 - 2
src/main/java/com/qmth/exam/reserve/controller/student/StudentApplyController.java

@@ -75,10 +75,10 @@ public class StudentApplyController extends BaseController {
         return examReserveService.getExamSiteGuide(examSiteId);
     }
 
-    @ApiOperation(value = "获取可预约的“日期”列表")
+    @ApiOperation(value = "获取可预约的“日期”列表", notes = "日期格式:yyyyMMdd")
     @PostMapping(value = "/apply/date/list")
     public List<String> dateList() {
-        return examReserveService.getApplyDateList(curLoginStudent().getId());
+        return examReserveService.getApplyDateList();
     }
 
     @ApiOperation(value = "获取可预约的“时段”列表")

+ 1 - 1
src/main/java/com/qmth/exam/reserve/service/ExamReserveService.java

@@ -19,7 +19,7 @@ public interface ExamReserveService {
 
     TicketInfo getApplyTicket(Long studentId, Long applyId);
 
-    List<String> getApplyDateList(Long studentId);
+    List<String> getApplyDateList();
 
     ApplyTimePeriodResult getApplyTimePeriodList(Long studentId, Long examSiteId, String date);
 

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

@@ -8,23 +8,25 @@ import com.qmth.exam.reserve.bean.apply.ApplyTimePeriodResult;
 import com.qmth.exam.reserve.bean.apply.ApplyVO;
 import com.qmth.exam.reserve.bean.apply.TicketInfo;
 import com.qmth.exam.reserve.bean.apply.TimePeriodInfo;
+import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import com.qmth.exam.reserve.dao.StudentApplyDao;
 import com.qmth.exam.reserve.entity.ApplyTaskEntity;
 import com.qmth.exam.reserve.entity.ExamSiteEntity;
 import com.qmth.exam.reserve.entity.StudentApplyEntity;
-import com.qmth.exam.reserve.service.ApplyTaskService;
-import com.qmth.exam.reserve.service.ExamReserveService;
-import com.qmth.exam.reserve.service.ExamSiteService;
-import com.qmth.exam.reserve.service.StudentApplyService;
+import com.qmth.exam.reserve.entity.TimePeriodEntity;
+import com.qmth.exam.reserve.service.*;
+import com.qmth.exam.reserve.util.DateUtil;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.DateUtils;
+import org.apache.commons.lang3.time.FastDateFormat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 
 @Service
 public class ExamReserveServiceImpl implements ExamReserveService {
@@ -37,6 +39,9 @@ public class ExamReserveServiceImpl implements ExamReserveService {
     @Autowired
     private ApplyTaskService applyTaskService;
 
+    @Autowired
+    private TimePeriodService timePeriodService;
+
     @Autowired
     private ExamSiteService examSiteService;
 
@@ -134,12 +139,44 @@ public class ExamReserveServiceImpl implements ExamReserveService {
     }
 
     @Override
-    public List<String> getApplyDateList(Long studentId) {
+    public List<String> getApplyDateList() {
+        // 日期格式:yyyyMMdd
         List<String> dateList = new ArrayList<>();
-        dateList.add("20240410");
-        dateList.add("20240411");
-        dateList.add("20240412");
-        // todo
+
+        // 获取当前启用的预约任务
+        CurrentApplyTaskVO curApplyTask = applyTaskService.currentApplyTask();
+        if (curApplyTask == null) {
+            return dateList;
+        }
+
+        LambdaQueryWrapper<TimePeriodEntity> wrapper = new LambdaQueryWrapper<>();
+        wrapper.select(TimePeriodEntity::getStartTime);
+        wrapper.eq(TimePeriodEntity::getApplyTaskId, curApplyTask.getTaskId());
+        List<TimePeriodEntity> timePeriods = timePeriodService.list(wrapper);
+        if (CollectionUtils.isEmpty(timePeriods)) {
+            return dateList;
+        }
+
+        // 考前N天,禁止考生自主预约
+        Date allowDate = DateUtil.changeDateAndBeginZeroTime(curApplyTask.getAllowApplyDays());
+        Set<String> dates = new HashSet<>();
+        FastDateFormat fdf = FastDateFormat.getInstance("yyyyMMdd");
+        for (TimePeriodEntity timePeriod : timePeriods) {
+            Date curDate = new Date(timePeriod.getStartTime());
+            if (allowDate.after(curDate)) {
+                // 跳过,不在允许的时间内的
+                continue;
+            }
+            if (DateUtils.isSameDay(allowDate, curDate)) {
+                // 跳过,同一天内的
+                continue;
+            }
+
+            dates.add(fdf.format(curDate));
+        }
+
+        dateList.addAll(dates);
+        Collections.sort(dateList);
         return dateList;
     }
 

+ 17 - 0
src/main/java/com/qmth/exam/reserve/util/DateUtil.java

@@ -174,4 +174,21 @@ public class DateUtil {
         return sdf;
     }
 
+    /**
+     * 获取前几天的日期 且 时间设置为0点开始
+     * 示例:2024-01-01 00:00:00
+     *
+     * @param days 距离当前几天
+     */
+    public static Date changeDateAndBeginZeroTime(int days) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.add(Calendar.DATE, -days);
+
+        calendar.set(Calendar.HOUR_OF_DAY, 0);
+        calendar.set(Calendar.MINUTE, 0);
+        calendar.set(Calendar.SECOND, 0);
+        calendar.set(Calendar.MILLISECOND, 0);
+        return calendar.getTime();
+    }
+
 }