瀏覽代碼

update api

deason 1 年之前
父節點
當前提交
e01323c58c

+ 1 - 1
src/main/java/com/qmth/exam/reserve/bean/apply/ApplyVO.java

@@ -12,7 +12,7 @@ public class ApplyVO implements IModel {
 
 
     private static final long serialVersionUID = 2804383719693396546L;
     private static final long serialVersionUID = 2804383719693396546L;
 
 
-    @ApiModelProperty(value = "预约ID")
+    @ApiModelProperty(value = "预约记录ID")
     private Long applyId;
     private Long applyId;
 
 
     @ApiModelProperty(value = "预约时段ID")
     @ApiModelProperty(value = "预约时段ID")

+ 1 - 1
src/main/java/com/qmth/exam/reserve/bean/apply/TicketInfo.java

@@ -12,7 +12,7 @@ public class TicketInfo implements IModel {
 
 
     private static final long serialVersionUID = -3123736735932690992L;
     private static final long serialVersionUID = -3123736735932690992L;
 
 
-    @ApiModelProperty(value = "预约ID")
+    @ApiModelProperty(value = "预约记录ID")
     private Long applyId;
     private Long applyId;
 
 
     @JsonIgnore
     @JsonIgnore

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

@@ -36,13 +36,13 @@ public class StudentApplyController extends BaseController {
     @PostMapping(value = "/apply/save")
     @PostMapping(value = "/apply/save")
     public void save(@ApiParam("考点ID") @RequestParam Long examSiteId,
     public void save(@ApiParam("考点ID") @RequestParam Long examSiteId,
                      @ApiParam("预约时段ID") @RequestParam Long timePeriodId) {
                      @ApiParam("预约时段ID") @RequestParam Long timePeriodId) {
-        examReserveService.saveStudentApply(curLoginStudent().getId(), examSiteId, timePeriodId);
+        examReserveService.saveStudentApply(curLoginStudent(), examSiteId, timePeriodId);
     }
     }
 
 
     @ApiOperation(value = "取消考生预约结果")
     @ApiOperation(value = "取消考生预约结果")
     @PostMapping(value = "/apply/cancel")
     @PostMapping(value = "/apply/cancel")
-    public void cancel(@ApiParam("预约ID") @RequestParam Long applyId) {
-        examReserveService.cancelStudentApply(curLoginStudent().getId(), applyId);
+    public void cancel(@ApiParam("预约记录ID") @RequestParam Long applyId) {
+        examReserveService.cancelStudentApply(curLoginStudent(), applyId);
     }
     }
 
 
     @ApiOperation(value = "获取考生预约结果列表(个人中心)")
     @ApiOperation(value = "获取考生预约结果列表(个人中心)")
@@ -59,7 +59,7 @@ public class StudentApplyController extends BaseController {
 
 
     @ApiOperation(value = "获取考生预约-电子准考证")
     @ApiOperation(value = "获取考生预约-电子准考证")
     @PostMapping(value = "/apply/ticket")
     @PostMapping(value = "/apply/ticket")
-    public TicketInfo ticket(@ApiParam("预约ID") @RequestParam Long applyId) {
+    public TicketInfo ticket(@ApiParam("预约记录ID") @RequestParam Long applyId) {
         return examReserveService.getApplyTicket(curLoginStudent().getId(), applyId);
         return examReserveService.getApplyTicket(curLoginStudent().getId(), applyId);
     }
     }
 
 

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

@@ -10,9 +10,9 @@ import java.util.List;
 
 
 public interface ExamReserveService {
 public interface ExamReserveService {
 
 
-    void saveStudentApply(Long studentId, Long examSiteId, Long timePeriodId);
+    void saveStudentApply(LoginUser student, Long examSiteId, Long timePeriodId);
 
 
-    void cancelStudentApply(Long studentId, Long applyId);
+    void cancelStudentApply(LoginUser student, Long applyId);
 
 
     List<ApplyVO> getStudentApplyList(LoginUser student, Boolean cancel);
     List<ApplyVO> getStudentApplyList(LoginUser student, Boolean cancel);
 
 

+ 2 - 0
src/main/java/com/qmth/exam/reserve/service/StudentService.java

@@ -11,6 +11,8 @@ public interface StudentService extends IService<StudentEntity> {
 
 
     StudentEntity findByOpenIdAndUid(String openId, String uid);
     StudentEntity findByOpenIdAndUid(String openId, String uid);
 
 
+    StudentEntity findLessInfoByStudentId(Long studentId);
+
     StudentInfo findInfoByStudentId(Long studentId);
     StudentInfo findInfoByStudentId(Long studentId);
 
 
     void bindingWechat(WechatBindReq req);
     void bindingWechat(WechatBindReq req);

+ 83 - 30
src/main/java/com/qmth/exam/reserve/service/impl/ExamReserveServiceImpl.java

@@ -11,10 +11,7 @@ import com.qmth.exam.reserve.bean.apply.TimePeriodInfo;
 import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.dao.StudentApplyDao;
 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.entity.TimePeriodEntity;
+import com.qmth.exam.reserve.entity.*;
 import com.qmth.exam.reserve.enums.ApplyStatus;
 import com.qmth.exam.reserve.enums.ApplyStatus;
 import com.qmth.exam.reserve.service.*;
 import com.qmth.exam.reserve.service.*;
 import com.qmth.exam.reserve.util.DateUtil;
 import com.qmth.exam.reserve.util.DateUtil;
@@ -35,6 +32,9 @@ public class ExamReserveServiceImpl implements ExamReserveService {
 
 
     private static final Logger log = LoggerFactory.getLogger(ExamReserveServiceImpl.class);
     private static final Logger log = LoggerFactory.getLogger(ExamReserveServiceImpl.class);
 
 
+    @Autowired
+    private StudentService studentService;
+
     @Autowired
     @Autowired
     private StudentApplyService studentApplyService;
     private StudentApplyService studentApplyService;
 
 
@@ -49,7 +49,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
 
 
     @Override
     @Override
     @Transactional
     @Transactional
-    public void saveStudentApply(Long studentId, Long examSiteId, Long timePeriodId) {
+    public void saveStudentApply(LoginUser student, Long examSiteId, Long timePeriodId) {
         if (examSiteId == null) {
         if (examSiteId == null) {
             throw new StatusException("考点ID不能为空");
             throw new StatusException("考点ID不能为空");
         }
         }
@@ -57,47 +57,100 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             throw new StatusException("预约时段ID不能为空");
             throw new StatusException("预约时段ID不能为空");
         }
         }
 
 
+        CurrentApplyTaskVO curApplyTask = applyTaskService.currentApplyTask(student.getOrgId());
+        if (curApplyTask == null) {
+            throw new StatusException("尚未开启预约任务");
+        }
+
+        if (!curApplyTask.getTaskId().equals(student.getApplyTaskId())) {
+            throw new StatusException("当前预约任务与学生的不匹配");
+        }
+
+        StudentEntity stu = studentService.findLessInfoByStudentId(student.getId());
+        if (stu == null) {
+            throw new StatusException("学生信息不存在");
+        }
+
+        if (stu.getApplyFinished()) {
+            String msg = "当前已完成预约时段" + stu.getApplyNumber() + "次,无剩余可约时段";
+            throw new StatusException(msg);
+        }
+
+        TimePeriodEntity timePeriod = timePeriodService.getById(timePeriodId);
+        if (timePeriod == null || !curApplyTask.getTaskId().equals(timePeriod.getApplyTaskId())) {
+            throw new StatusException("当前预约时段信息有误");
+        }
+
+        // 考前N天,禁止考生自主预约
+        Date allowDate = DateUtil.changeDateAndTimeEnd(new Date(), curApplyTask.getAllowApplyDays());
+        Date curDate = new Date(timePeriod.getStartTime());
+        if (curDate.before(allowDate)) {
+            // 跳过过期时段,“当前时段开始时间”在“允许预约时间”之前,则禁止预约
+            throw new StatusException("当前预约时段已禁止预约");
+        }
+
+        // 当前预约时段剩余可约数量
+        int availableCount = 0;//todo
+        // if (availableCount == 0) {
+        //     throw new StatusException("当前预约时段已约满");
+        // }
+
+        // 考生预约操作锁
+        // 更新预约时段、机房容量等操作
+        // 系统自动预约“任务执行期间”不允许预约
+
         LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(StudentApplyEntity::getStudentId, studentId);
+        wrapper.eq(StudentApplyEntity::getStudentId, student.getId());
         wrapper.eq(StudentApplyEntity::getExamSiteId, examSiteId);
         wrapper.eq(StudentApplyEntity::getExamSiteId, examSiteId);
         wrapper.eq(StudentApplyEntity::getTimePeriodId, timePeriodId);
         wrapper.eq(StudentApplyEntity::getTimePeriodId, timePeriodId);
         StudentApplyEntity existEntity = studentApplyService.getOne(wrapper);
         StudentApplyEntity existEntity = studentApplyService.getOne(wrapper);
         if (existEntity != null) {
         if (existEntity != null) {
-            if (existEntity.getCancel()) {
-                existEntity.setCancel(false);
-                existEntity.setOperateId(studentId);
-                existEntity.setUpdateTime(System.currentTimeMillis());
-                studentApplyService.updateById(existEntity);
+            if (!existEntity.getCancel()) {
+                throw new StatusException("当前时段已预约,请勿重复预约");
             }
             }
-            return;
+
+            // 存在“已取消”预约记录,则恢复预约
+            this.updateStudentApplyForCancel(existEntity.getId(), false, student.getId());
+        } else {
+            // 不存在则新增预约记录
+            StudentApplyEntity entity = new StudentApplyEntity();
+            entity.setStudentId(student.getId());
+            entity.setExamSiteId(examSiteId);
+            entity.setTimePeriodId(timePeriodId);
+            entity.setOperateId(student.getId());
+            entity.setCancel(false);
+            studentApplyService.save(entity);
         }
         }
 
 
         // todo
         // todo
-        // 考前多少天,禁止考生自主预约(考前是指待预约时段的开始时间)
-        // 系统自动预约“任务执行期间”不允许预约
-
-        StudentApplyEntity entity = new StudentApplyEntity();
-        entity.setStudentId(studentId);
-        entity.setExamSiteId(examSiteId);
-        entity.setTimePeriodId(timePeriodId);
-        entity.setOperateId(studentId);
-        entity.setCancel(false);
-        studentApplyService.save(entity);
     }
     }
 
 
     @Override
     @Override
     @Transactional
     @Transactional
-    public void cancelStudentApply(Long studentId, Long applyId) {
-        LambdaUpdateWrapper<StudentApplyEntity> updateWrapper = new LambdaUpdateWrapper<>();
-        updateWrapper.set(StudentApplyEntity::getCancel, true);
-        updateWrapper.set(StudentApplyEntity::getOperateId, studentId);
-        updateWrapper.set(StudentApplyEntity::getUpdateTime, System.currentTimeMillis());
-        updateWrapper.eq(StudentApplyEntity::getId, applyId);
-        studentApplyService.update(updateWrapper);
+    public void cancelStudentApply(LoginUser student, Long applyId) {
+        if (applyId == null) {
+            throw new StatusException("预约记录ID不能为空");
+        }
+
+        CurrentApplyTaskVO curApplyTask = applyTaskService.currentApplyTask(student.getOrgId());
+        if (curApplyTask == null) {
+            throw new StatusException("尚未开启预约任务");
+        }
+
         // todo
         // todo
         // 考前多少天,禁止考生自主取消预约(考前是指已预约时段的开始时间)
         // 考前多少天,禁止考生自主取消预约(考前是指已预约时段的开始时间)
         // 系统自动预约“任务执行期间”不允许取消预约
         // 系统自动预约“任务执行期间”不允许取消预约
+        this.updateStudentApplyForCancel(applyId, true, student.getId());
+    }
 
 
+    private void updateStudentApplyForCancel(Long applyId, boolean cancel, Long operateId) {
+        LambdaUpdateWrapper<StudentApplyEntity> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.set(StudentApplyEntity::getCancel, cancel);
+        updateWrapper.set(StudentApplyEntity::getOperateId, operateId);
+        updateWrapper.set(StudentApplyEntity::getUpdateTime, System.currentTimeMillis());
+        updateWrapper.eq(StudentApplyEntity::getId, applyId);
+        studentApplyService.update(updateWrapper);
+        log.warn("更新考生预约记录,ID:{},取消状态:{}", applyId, cancel);
     }
     }
 
 
     @Override
     @Override
@@ -228,7 +281,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
 
 
         CurrentApplyTaskVO curApplyTask = applyTaskService.currentApplyTask(student.getOrgId());
         CurrentApplyTaskVO curApplyTask = applyTaskService.currentApplyTask(student.getOrgId());
         if (curApplyTask == null) {
         if (curApplyTask == null) {
-            throw new StatusException("当前预约任务不存在");
+            throw new StatusException("尚未开启预约任务");
         }
         }
 
 
         LambdaQueryWrapper<TimePeriodEntity> wrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<TimePeriodEntity> wrapper = new LambdaQueryWrapper<>();

+ 9 - 0
src/main/java/com/qmth/exam/reserve/service/impl/StudentServiceImpl.java

@@ -57,6 +57,15 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
         return baseMapper.selectOne(wrapper);
         return baseMapper.selectOne(wrapper);
     }
     }
 
 
+    @Override
+    public StudentEntity findLessInfoByStudentId(Long studentId) {
+        // 只查询id、applyNumber、applyFinished等少量字段
+        LambdaQueryWrapper<StudentEntity> wrapper = new LambdaQueryWrapper<>();
+        wrapper.select(StudentEntity::getId, StudentEntity::getApplyNumber, StudentEntity::getApplyFinished);
+        wrapper.eq(StudentEntity::getId, studentId);
+        return this.getOne(wrapper);
+    }
+
     @Override
     @Override
     public StudentInfo findInfoByStudentId(Long studentId) {
     public StudentInfo findInfoByStudentId(Long studentId) {
         StudentEntity entity = baseMapper.selectById(studentId);
         StudentEntity entity = baseMapper.selectById(studentId);