deason 1 سال پیش
والد
کامیت
701f0d1b09

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

@@ -48,13 +48,13 @@ public class StudentApplyController extends BaseController {
     @ApiOperation(value = "获取考生预约结果列表(个人中心)")
     @PostMapping(value = "/apply/list")
     public List<ApplyVO> list(@ApiParam("是否已取消预约") @RequestParam(required = false) Boolean cancel) {
-        return examReserveService.getStudentApplyList(curLoginStudent().getId(), cancel);
+        return examReserveService.getStudentApplyList(curLoginStudent(), cancel);
     }
 
     @ApiOperation(value = "获取考生当前进行中的预约列表(首页)")
     @PostMapping(value = "/apply/list/for/current")
     public List<ApplyVO> listForCurrent() {
-        return examReserveService.getStudentApplyListForCurrent(curLoginStudent().getId());
+        return examReserveService.getStudentApplyListForCurrent(curLoginStudent());
     }
 
     @ApiOperation(value = "获取考生预约-电子准考证")

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

@@ -14,15 +14,15 @@ public interface ExamReserveService {
 
     void cancelStudentApply(Long studentId, Long applyId);
 
-    List<ApplyVO> getStudentApplyList(Long studentId, Boolean cancel);
+    List<ApplyVO> getStudentApplyList(LoginUser student, Boolean cancel);
 
-    List<ApplyVO> getStudentApplyListForCurrent(Long studentId);
+    List<ApplyVO> getStudentApplyListForCurrent(LoginUser student);
 
     TicketInfo getApplyTicket(Long studentId, Long applyId);
 
-    List<String> getApplyDateList(LoginUser loginUser);
+    List<String> getApplyDateList(LoginUser student);
 
-    ApplyTimePeriodResult getApplyTimePeriodList(LoginUser loginUser, Long examSiteId, String date);
+    ApplyTimePeriodResult getApplyTimePeriodList(LoginUser student, Long examSiteId, String date);
 
     RichTextBean getExamNotice(Long applyTaskId);
 

+ 26 - 15
src/main/java/com/qmth/exam/reserve/service/impl/ExamReserveServiceImpl.java

@@ -20,7 +20,6 @@ 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;
@@ -102,26 +101,42 @@ public class ExamReserveServiceImpl implements ExamReserveService {
     }
 
     @Override
-    public List<ApplyVO> getStudentApplyList(Long studentId, Boolean cancel) {
+    public List<ApplyVO> getStudentApplyList(LoginUser student, Boolean cancel) {
+        CurrentApplyTaskVO curApplyTask = applyTaskService.currentApplyTask(student.getOrgId());
+        if (curApplyTask == null) {
+            return new ArrayList<>();
+        }
+
         StudentApplyDao baseMapper = (StudentApplyDao) studentApplyService.getBaseMapper();
-        List<ApplyVO> list = baseMapper.getStudentApplyList(studentId, cancel);
+        List<ApplyVO> list = baseMapper.getStudentApplyList(student.getId(), cancel);
+
+        // 考前N天,禁止考生自主取消预约
+        Date allowDate = DateUtil.changeDateAndTimeEnd(new Date(), curApplyTask.getAllowApplyCancelDays());
 
         for (ApplyVO vo : list) {
             vo.setShowTicket(false);
-            vo.setAllowCancel(true);
+            vo.setAllowCancel(false);
+
             if (StringUtils.isNotEmpty(vo.getTicketNumber())) {
+                // 准考证号已生成,则可查看
                 vo.setShowTicket(true);
             }
-            // todo
+
+            Date curDate = new Date(vo.getTimePeriodStart());
+            if (curDate.after(allowDate)) {
+                // “当前时段开始时间”在“允许取消时间”之后,可以取消预约
+                vo.setAllowCancel(true);
+            }
         }
 
         return list;
     }
 
     @Override
-    public List<ApplyVO> getStudentApplyListForCurrent(Long studentId) {
-        List<ApplyVO> list = this.getStudentApplyList(studentId, null);
+    public List<ApplyVO> getStudentApplyListForCurrent(LoginUser student) {
+        List<ApplyVO> list = this.getStudentApplyList(student, null);
         // todo
+
         return list;
     }
 
@@ -152,7 +167,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
         }
 
         LambdaQueryWrapper<TimePeriodEntity> wrapper = new LambdaQueryWrapper<>();
-        wrapper.select(TimePeriodEntity::getStartTime);
+        wrapper.select(TimePeriodEntity::getStartTime);// 只查询startTime等字段
         wrapper.eq(TimePeriodEntity::getApplyTaskId, curApplyTask.getTaskId());
         List<TimePeriodEntity> timePeriods = timePeriodService.list(wrapper);
         if (CollectionUtils.isEmpty(timePeriods)) {
@@ -160,17 +175,13 @@ public class ExamReserveServiceImpl implements ExamReserveService {
         }
 
         // 考前N天,禁止考生自主预约
-        Date allowDate = DateUtil.changeDateAndBeginZeroTime(curApplyTask.getAllowApplyDays());
+        Date allowDate = DateUtil.changeDateAndTimeEnd(new Date(), 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)) {
-                // 跳过,同一天内的
+            if (curDate.before(allowDate)) {
+                // 跳过过期时段,“当前时段开始时间”在“允许预约时间”之前,则禁止预约
                 continue;
             }
 

+ 18 - 4
src/main/java/com/qmth/exam/reserve/service/impl/StudentServiceImpl.java

@@ -7,11 +7,14 @@ import com.qmth.boot.core.exception.StatusException;
 import com.qmth.exam.reserve.bean.student.StudentInfo;
 import com.qmth.exam.reserve.bean.student.WechatBindReq;
 import com.qmth.exam.reserve.dao.StudentDao;
+import com.qmth.exam.reserve.entity.CategoryEntity;
 import com.qmth.exam.reserve.entity.StudentEntity;
+import com.qmth.exam.reserve.service.CategoryService;
 import com.qmth.exam.reserve.service.StudentService;
 import org.apache.commons.lang3.StringUtils;
 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;
 
@@ -20,6 +23,9 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
 
     private static final Logger log = LoggerFactory.getLogger(StudentServiceImpl.class);
 
+    @Autowired
+    private CategoryService categoryService;
+
     @Override
     public StudentEntity findByStudentCode(Long applyTaskId, String studentCode) {
         if (StringUtils.isEmpty(studentCode)) {
@@ -59,7 +65,6 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
         }
 
         StudentInfo info = new StudentInfo();
-        info.setOrgId(entity.getOrgId());
         info.setId(entity.getId());
         info.setName(entity.getName());
         info.setStudentCode(entity.getStudentCode());
@@ -67,11 +72,20 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
         info.setPhotoPath(entity.getPhotoPath());
         info.setGender(entity.getGender());
         info.setApplyNumber(entity.getApplyNumber());
-        info.setApplyTaskId(entity.getApplyTaskId());
-        info.setCategoryId(entity.getCategoryId());
-        info.setCategoryName("");//todo
         info.setOpenId(entity.getOpenId());
         info.setUid(entity.getUid());
+        info.setOrgId(entity.getOrgId());
+        info.setApplyTaskId(entity.getApplyTaskId());
+        info.setCategoryId(entity.getCategoryId());
+
+        LambdaQueryWrapper<CategoryEntity> wrapper = new LambdaQueryWrapper<>();
+        wrapper.select(CategoryEntity::getName);// 只查询name等字段
+        wrapper.eq(CategoryEntity::getId, entity.getCategoryId());
+        CategoryEntity category = categoryService.getOne(wrapper);
+        if (category != null) {
+            info.setCategoryName(category.getName());
+        }
+
         return info;
     }
 

+ 26 - 5
src/main/java/com/qmth/exam/reserve/util/DateUtil.java

@@ -175,14 +175,16 @@ public class DateUtil {
     }
 
     /**
-     * 获取前几天的日期 且 时间设置为0点开始
-     * 示例:2024-01-01 00:00:00
+     * 获取某天的起点时间
      *
-     * @param days 距离当前几天
+     * @param date       某个日期
+     * @param changeDays 日期前后调整几天
+     * @return 示例:2024-01-01 00:00:00
      */
-    public static Date changeDateAndBeginZeroTime(int days) {
+    public static Date changeDateAndTimeBegin(Date date, int changeDays) {
         Calendar calendar = Calendar.getInstance();
-        calendar.add(Calendar.DATE, -days);
+        calendar.setTime(date);
+        calendar.add(Calendar.DATE, -changeDays);
 
         calendar.set(Calendar.HOUR_OF_DAY, 0);
         calendar.set(Calendar.MINUTE, 0);
@@ -191,4 +193,23 @@ public class DateUtil {
         return calendar.getTime();
     }
 
+    /**
+     * 获取某天的终点时间
+     *
+     * @param date       某个日期
+     * @param changeDays 日期前后调整几天
+     * @return 示例:2024-01-01 23:59:59
+     */
+    public static Date changeDateAndTimeEnd(Date date, int changeDays) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.add(Calendar.DATE, -changeDays);
+
+        calendar.set(Calendar.HOUR_OF_DAY, 23);
+        calendar.set(Calendar.MINUTE, 59);
+        calendar.set(Calendar.SECOND, 59);
+        calendar.set(Calendar.MILLISECOND, 999);
+        return calendar.getTime();
+    }
+
 }

+ 1 - 1
src/test/java/com/qmth/exam/reserve/test/AuthTest.java

@@ -19,7 +19,7 @@ public class AuthTest {
     @Test
     public void demo() throws Exception {
         // LoginUser loginUser = this.loginTest("1500010120019", "123456");
-        // this.logoutTest(loginUser.getSessionId(), loginUser.getToken());
+        // this.apiTest(loginUser.getSessionId(), loginUser.getToken());
         this.apiTest("xxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
     }