|
@@ -8,9 +8,11 @@ import com.qmth.exam.reserve.bean.Constants;
|
|
import com.qmth.exam.reserve.bean.RichTextBean;
|
|
import com.qmth.exam.reserve.bean.RichTextBean;
|
|
import com.qmth.exam.reserve.bean.apply.*;
|
|
import com.qmth.exam.reserve.bean.apply.*;
|
|
import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
|
|
import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
|
|
|
|
+import com.qmth.exam.reserve.bean.examsite.ExamSiteCacheBean;
|
|
import com.qmth.exam.reserve.bean.login.LoginUser;
|
|
import com.qmth.exam.reserve.bean.login.LoginUser;
|
|
import com.qmth.exam.reserve.cache.CacheConstants;
|
|
import com.qmth.exam.reserve.cache.CacheConstants;
|
|
import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
|
|
import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
|
|
|
|
+import com.qmth.exam.reserve.cache.impl.ExamSiteCacheService;
|
|
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.ApplyTaskEntity;
|
|
import com.qmth.exam.reserve.entity.ExamSiteEntity;
|
|
import com.qmth.exam.reserve.entity.ExamSiteEntity;
|
|
@@ -20,6 +22,7 @@ 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;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.time.FastDateFormat;
|
|
import org.apache.commons.lang3.time.FastDateFormat;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -31,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.locks.Lock;
|
|
import java.util.concurrent.locks.Lock;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class ExamReserveServiceImpl implements ExamReserveService {
|
|
public class ExamReserveServiceImpl implements ExamReserveService {
|
|
@@ -46,6 +50,9 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
@Autowired
|
|
@Autowired
|
|
private ExamSiteService examSiteService;
|
|
private ExamSiteService examSiteService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ExamSiteCacheService examSiteCacheService;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private TimePeriodService timePeriodService;
|
|
private TimePeriodService timePeriodService;
|
|
|
|
|
|
@@ -56,7 +63,6 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
private ConcurrentService concurrentService;
|
|
private ConcurrentService concurrentService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @Transactional
|
|
|
|
public void saveStudentApply(LoginUser student, 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不能为空");
|
|
@@ -183,7 +189,6 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @Transactional
|
|
|
|
public void cancelStudentApply(LoginUser student, Long examSiteId, Long timePeriodId) {
|
|
public void cancelStudentApply(LoginUser student, Long examSiteId, Long timePeriodId) {
|
|
if (examSiteId == null) {
|
|
if (examSiteId == null) {
|
|
throw new StatusException("考点ID不能为空");
|
|
throw new StatusException("考点ID不能为空");
|
|
@@ -256,7 +261,6 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
// 某考点某时段的“已预约数量” 累减1
|
|
// 某考点某时段的“已预约数量” 累减1
|
|
applyTaskCacheService.decreaseApplyFinishCount(examSiteId, timePeriodId);
|
|
applyTaskCacheService.decreaseApplyFinishCount(examSiteId, timePeriodId);
|
|
|
|
|
|
- // todo 取消预约事件
|
|
|
|
log.warn("取消预约成功!studentId:{} examSiteId:{} timePeriodId:{}", student.getId(), examSiteId, timePeriodId);
|
|
log.warn("取消预约成功!studentId:{} examSiteId:{} timePeriodId:{}", student.getId(), examSiteId, timePeriodId);
|
|
} finally {
|
|
} finally {
|
|
try {
|
|
try {
|
|
@@ -267,6 +271,14 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private int getApplyAvailableCount(Long examSiteId, Long timePeriodId) {
|
|
|
|
+ // 当前预约时段剩余可约数量
|
|
|
|
+ int totalCount = applyTaskCacheService.getApplyTotalCount(examSiteId);
|
|
|
|
+ int finishCount = applyTaskCacheService.getApplyFinishCount(examSiteId, timePeriodId);
|
|
|
|
+ int availableCount = totalCount - finishCount;
|
|
|
|
+ return Math.max(availableCount, 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
private StudentApplyEntity getStudentApply(Long studentId, Long examSiteId, Long timePeriodId) {
|
|
private StudentApplyEntity getStudentApply(Long studentId, Long examSiteId, Long timePeriodId) {
|
|
LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
|
|
wrapper.eq(StudentApplyEntity::getExamSiteId, examSiteId);
|
|
wrapper.eq(StudentApplyEntity::getExamSiteId, examSiteId);
|
|
@@ -275,7 +287,8 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
return studentApplyService.getOne(wrapper);
|
|
return studentApplyService.getOne(wrapper);
|
|
}
|
|
}
|
|
|
|
|
|
- private void updateStudentApplyForCancel(Long applyId, boolean cancel, Long operateId) {
|
|
|
|
|
|
+ @Transactional
|
|
|
|
+ public void updateStudentApplyForCancel(Long applyId, boolean cancel, Long operateId) {
|
|
LambdaUpdateWrapper<StudentApplyEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<StudentApplyEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
updateWrapper.set(StudentApplyEntity::getCancel, cancel);
|
|
updateWrapper.set(StudentApplyEntity::getCancel, cancel);
|
|
updateWrapper.set(StudentApplyEntity::getOperateId, operateId);
|
|
updateWrapper.set(StudentApplyEntity::getOperateId, operateId);
|
|
@@ -285,12 +298,26 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
log.warn("更新考生预约记录!applyId:{} cancel:{}", applyId, cancel);
|
|
log.warn("更新考生预约记录!applyId:{} cancel:{}", applyId, cancel);
|
|
}
|
|
}
|
|
|
|
|
|
- private int getApplyAvailableCount(Long examSiteId, Long timePeriodId) {
|
|
|
|
- // 当前预约时段剩余可约数量
|
|
|
|
- int totalCount = applyTaskCacheService.getApplyTotalCount(examSiteId);
|
|
|
|
- int finishCount = applyTaskCacheService.getApplyFinishCount(examSiteId, timePeriodId);
|
|
|
|
- int availableCount = totalCount - finishCount;
|
|
|
|
- return Math.max(availableCount, 0);
|
|
|
|
|
|
+ private boolean hasTicketNumber(Long studentId, Long examSiteId, Long timePeriodId) {
|
|
|
|
+ LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.select(StudentApplyEntity::getTicketNumber);//只查询ticketNumber等字段
|
|
|
|
+ wrapper.eq(StudentApplyEntity::getExamSiteId, examSiteId);
|
|
|
|
+ wrapper.eq(StudentApplyEntity::getTimePeriodId, timePeriodId);
|
|
|
|
+ wrapper.eq(StudentApplyEntity::getStudentId, studentId);
|
|
|
|
+ StudentApplyEntity e = studentApplyService.getOne(wrapper);
|
|
|
|
+ return e != null && StringUtils.isNotEmpty(e.getTicketNumber());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Map<Long, TimePeriodEntity> getTimePeriods(Set<Long> timePeriodIds) {
|
|
|
|
+ LambdaQueryWrapper<TimePeriodEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.select(TimePeriodEntity::getId, TimePeriodEntity::getStartTime, TimePeriodEntity::getEndTime);
|
|
|
|
+ wrapper.in(TimePeriodEntity::getId, timePeriodIds);
|
|
|
|
+ List<TimePeriodEntity> timePeriods = timePeriodService.list(wrapper);
|
|
|
|
+ Map<Long, TimePeriodEntity> maps = new HashMap<>();
|
|
|
|
+ for (TimePeriodEntity timePeriod : timePeriods) {
|
|
|
|
+ maps.put(timePeriod.getId(), timePeriod);
|
|
|
|
+ }
|
|
|
|
+ return maps;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -313,9 +340,11 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
vo.setShowTicket(false);
|
|
vo.setShowTicket(false);
|
|
vo.setAllowCancel(false);
|
|
vo.setAllowCancel(false);
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(vo.getTicketNumber())) {
|
|
|
|
- // 准考证号已生成,则可查看
|
|
|
|
- vo.setShowTicket(true);
|
|
|
|
|
|
+ if (!vo.getCancel()) {
|
|
|
|
+ if (StringUtils.isNotEmpty(vo.getTicketNumber())) {
|
|
|
|
+ // 准考证号已生成,则可查看
|
|
|
|
+ vo.setShowTicket(true);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
Date curDate = new Date(vo.getTimePeriodStart());
|
|
Date curDate = new Date(vo.getTimePeriodStart());
|
|
@@ -328,10 +357,73 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<ApplyVO> getStudentApplyListFromCache(LoginUser student, Boolean cancel) {
|
|
|
|
+ CurrentApplyTaskVO curApplyTask = applyTaskCacheService.currentApplyTask(student.getOrgId());
|
|
|
|
+ if (curApplyTask == null) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, ApplyRecordCacheBean> maps = applyTaskCacheService.getStudentApplyRecords(student.getId());
|
|
|
|
+ if (MapUtils.isEmpty(maps)) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Set<Long> timePeriodIds = maps.values().stream().map(ApplyRecordCacheBean::getTimePeriodId).collect(Collectors.toSet());
|
|
|
|
+ Map<Long, TimePeriodEntity> timePeriods = this.getTimePeriods(timePeriodIds);
|
|
|
|
+
|
|
|
|
+ // 考前N天,禁止考生自主取消预约
|
|
|
|
+ Date allowDate = DateUtil.changeDateAndTimeEnd(new Date(), curApplyTask.getAllowApplyCancelDays());
|
|
|
|
+
|
|
|
|
+ List<ApplyVO> list = new ArrayList<>();
|
|
|
|
+ for (ApplyRecordCacheBean bean : maps.values()) {
|
|
|
|
+ if (cancel != null && cancel != bean.getCancel()) {
|
|
|
|
+ // 按“取消预约”状态过滤
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ApplyVO vo = new ApplyVO();
|
|
|
|
+ vo.setShowTicket(false);
|
|
|
|
+ vo.setAllowCancel(false);
|
|
|
|
+ vo.setCancel(bean.getCancel());
|
|
|
|
+
|
|
|
|
+ TimePeriodEntity timePeriod = timePeriods.get(bean.getTimePeriodId());
|
|
|
|
+ vo.setTimePeriodId(bean.getTimePeriodId());
|
|
|
|
+ if (timePeriod != null) {
|
|
|
|
+ vo.setTimePeriodStart(timePeriod.getStartTime());
|
|
|
|
+ vo.setTimePeriodEnd(timePeriod.getEndTime());
|
|
|
|
+
|
|
|
|
+ Date curDate = new Date(vo.getTimePeriodStart());
|
|
|
|
+ if (curDate.after(allowDate)) {
|
|
|
|
+ // “当前时段开始时间”在“允许取消时间”之后,可以取消预约
|
|
|
|
+ vo.setAllowCancel(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ExamSiteCacheBean examSite = examSiteCacheService.getExamSiteById(bean.getExamSiteId());
|
|
|
|
+ vo.setExamSiteId(bean.getExamSiteId());
|
|
|
|
+ if (examSite != null) {
|
|
|
|
+ vo.setExamSiteName(examSite.getExamSiteName());
|
|
|
|
+ vo.setExamSiteAddress(examSite.getExamSiteAddress());
|
|
|
|
+ vo.setCategoryId(examSite.getCategoryId());
|
|
|
|
+ vo.setCategoryName(examSite.getCategoryName());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!vo.getCancel()) {
|
|
|
|
+ // 准考证号已生成,则可查看
|
|
|
|
+ vo.setShowTicket(this.hasTicketNumber(bean.getStudentId(), bean.getExamSiteId(), bean.getTimePeriodId()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ list.add(vo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<ApplyVO> getStudentApplyListForCurrent(LoginUser student) {
|
|
public List<ApplyVO> getStudentApplyListForCurrent(LoginUser student) {
|
|
// 默认过滤掉“已取消预约”的记录
|
|
// 默认过滤掉“已取消预约”的记录
|
|
- List<ApplyVO> list = this.getStudentApplyList(student, false);
|
|
|
|
|
|
+ List<ApplyVO> list = this.getStudentApplyListFromCache(student, false);
|
|
|
|
|
|
Date now = new Date();
|
|
Date now = new Date();
|
|
List<ApplyVO> newList = new ArrayList<>();
|
|
List<ApplyVO> newList = new ArrayList<>();
|