|
@@ -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<>();
|