|
@@ -6,10 +6,7 @@ import com.qmth.boot.core.concurrent.service.ConcurrentService;
|
|
|
import com.qmth.boot.core.exception.StatusException;
|
|
|
import com.qmth.exam.reserve.bean.Constants;
|
|
|
import com.qmth.exam.reserve.bean.RichTextBean;
|
|
|
-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.apply.*;
|
|
|
import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
|
|
|
import com.qmth.exam.reserve.bean.login.LoginUser;
|
|
|
import com.qmth.exam.reserve.cache.CacheConstants;
|
|
@@ -121,9 +118,9 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
|
}
|
|
|
|
|
|
// 当前预约时段剩余可约数量
|
|
|
- int availableCount = this.getApplyAvailableCount(examSiteId, timePeriod.getId());
|
|
|
+ int availableCount = this.getApplyAvailableCount(examSiteId, timePeriodId);
|
|
|
if (availableCount < 1) {
|
|
|
- log.warn("预约失败,当前预约时段已约满!examSiteId:{} timePeriodId:{}", examSiteId, timePeriod.getId());
|
|
|
+ log.warn("预约失败,当前预约时段已约满!examSiteId:{} timePeriodId:{}", examSiteId, timePeriodId);
|
|
|
throw new StatusException("当前预约时段已约满");
|
|
|
}
|
|
|
|
|
@@ -131,29 +128,41 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
|
applyTaskCacheService.increaseApplyFinishCount(examSiteId, timePeriodId);
|
|
|
|
|
|
try {
|
|
|
- StudentApplyEntity existEntity = this.getStudentApply(student.getId(), examSiteId, timePeriodId);
|
|
|
- if (existEntity != null) {
|
|
|
- if (!existEntity.getCancel()) {
|
|
|
+ // StudentApplyEntity existApply = this.getStudentApply(student.getId(), examSiteId, timePeriodId);
|
|
|
+ ApplyRecordCacheBean existApply = applyTaskCacheService.getStudentApplyRecord(student.getId(), examSiteId, timePeriodId);
|
|
|
+ if (existApply != null) {
|
|
|
+ if (!existApply.getCancel()) {
|
|
|
// 某考点某时段的“已预约数量” 累减1(释放1个被占数量)
|
|
|
applyTaskCacheService.decreaseApplyFinishCount(examSiteId, timePeriodId);
|
|
|
|
|
|
- log.warn("预约失败,当前时段已预约,请勿重复预约!applyId:{}", existEntity.getId());
|
|
|
+ log.warn("预约失败,当前时段已预约,请勿重复预约!examSiteId:{} timePeriodId:{}", examSiteId, timePeriodId);
|
|
|
throw new StatusException("当前时段已预约,请勿重复预约");
|
|
|
}
|
|
|
|
|
|
// 存在“已取消”预约记录,则恢复预约
|
|
|
- this.updateStudentApplyForCancel(existEntity.getId(), false, student.getId());
|
|
|
+ existApply.setCancel(false);
|
|
|
+ existApply.setOperateId(student.getId());
|
|
|
+ existApply.setOperateTime(System.currentTimeMillis());
|
|
|
+ applyTaskCacheService.saveStudentApplyRecord(existApply);
|
|
|
+
|
|
|
+ // 推送至预约队列
|
|
|
+ applyTaskCacheService.pushStudentApplyRecordQueue(existApply);
|
|
|
} 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);
|
|
|
- log.warn("新增考生预约记录!applyId:{} examSiteId:{} timePeriodId:{}", entity.getId(), examSiteId, timePeriodId);
|
|
|
+ ApplyRecordCacheBean newApply = new ApplyRecordCacheBean();
|
|
|
+ newApply.setStudentId(student.getId());
|
|
|
+ newApply.setExamSiteId(examSiteId);
|
|
|
+ newApply.setTimePeriodId(timePeriodId);
|
|
|
+ newApply.setCancel(false);
|
|
|
+ newApply.setOperateId(student.getId());
|
|
|
+ newApply.setOperateTime(System.currentTimeMillis());
|
|
|
+ applyTaskCacheService.saveStudentApplyRecord(newApply);
|
|
|
+
|
|
|
+ // 推送至预约队列
|
|
|
+ applyTaskCacheService.pushStudentApplyRecordQueue(newApply);
|
|
|
}
|
|
|
+
|
|
|
+ log.warn("预约成功!studentId:{} examSiteId:{} timePeriodId:{}", student.getId(), examSiteId, timePeriodId);
|
|
|
} catch (Exception e) {
|
|
|
if (e instanceof StatusException) {
|
|
|
throw e;
|
|
@@ -161,7 +170,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
|
|
|
|
// 异常时,释放1个被占数量
|
|
|
applyTaskCacheService.decreaseApplyFinishCount(examSiteId, timePeriodId);
|
|
|
- log.error("预约结果保存失败!examSiteId:{} timePeriodId:{} err:{}", examSiteId, timePeriodId, e.getMessage());
|
|
|
+ log.error("预约异常!examSiteId:{} timePeriodId:{} err:{}", examSiteId, timePeriodId, e.getMessage());
|
|
|
throw new StatusException("预约失败,请稍后再试!", e);
|
|
|
}
|
|
|
} finally {
|
|
@@ -193,14 +202,15 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- StudentApplyEntity studentApply = this.getStudentApply(student.getId(), examSiteId, timePeriodId);
|
|
|
- if (studentApply == null) {
|
|
|
+ // StudentApplyEntity existApply = this.getStudentApply(student.getId(), examSiteId, timePeriodId);
|
|
|
+ ApplyRecordCacheBean existApply = applyTaskCacheService.getStudentApplyRecord(student.getId(), examSiteId, timePeriodId);
|
|
|
+ if (existApply == null) {
|
|
|
log.warn("取消预约失败,预约记录不存在!examSiteId:{} timePeriodId:{}", examSiteId, timePeriodId);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (studentApply.getCancel()) {
|
|
|
- log.warn("当前时段已取消预约,忽略重复取消!examSiteId:{} timePeriodId:{}", examSiteId, timePeriodId);
|
|
|
+ if (existApply.getCancel()) {
|
|
|
+ log.warn("取消预约失败,当前时段已取消,忽略重复取消!examSiteId:{} timePeriodId:{}", examSiteId, timePeriodId);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -225,7 +235,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
|
Lock studentApplyLock = concurrentService.getLock(studentApplyLockKey);
|
|
|
try {
|
|
|
if (!studentApplyLock.tryLock()) {
|
|
|
- log.warn("获取锁失败,不允许同一个考生同时操作预约!lockKey:{}", studentApplyLockKey);
|
|
|
+ log.warn("获取锁失败,同一个考生不允许同时操作预约!lockKey:{}", studentApplyLockKey);
|
|
|
throw new StatusException(Constants.SYSTEM_BUSY);
|
|
|
}
|
|
|
|
|
@@ -235,12 +245,19 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
|
throw new StatusException(Constants.SYSTEM_BUSY);
|
|
|
}
|
|
|
|
|
|
- this.updateStudentApplyForCancel(studentApply.getId(), true, student.getId());
|
|
|
+ existApply.setCancel(true);
|
|
|
+ existApply.setOperateId(student.getId());
|
|
|
+ existApply.setOperateTime(System.currentTimeMillis());
|
|
|
+ applyTaskCacheService.saveStudentApplyRecord(existApply);
|
|
|
+
|
|
|
+ // 推送至预约队列
|
|
|
+ applyTaskCacheService.pushStudentApplyRecordQueue(existApply);
|
|
|
|
|
|
// 某考点某时段的“已预约数量” 累减1
|
|
|
- applyTaskCacheService.decreaseApplyFinishCount(studentApply.getExamSiteId(), studentApply.getTimePeriodId());
|
|
|
+ applyTaskCacheService.decreaseApplyFinishCount(examSiteId, timePeriodId);
|
|
|
|
|
|
// todo 取消预约事件
|
|
|
+ log.warn("取消预约成功!studentId:{} examSiteId:{} timePeriodId:{}", student.getId(), examSiteId, timePeriodId);
|
|
|
} finally {
|
|
|
try {
|
|
|
studentApplyLock.unlock();
|
|
@@ -417,6 +434,19 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
|
wrapper.between(TimePeriodEntity::getStartTime, startTime.getTime(), endTime.getTime());
|
|
|
List<TimePeriodEntity> timePeriods = timePeriodService.list(wrapper);
|
|
|
|
|
|
+ // 获取某考生的 所有的“预约记录”
|
|
|
+ Map<String, ApplyRecordCacheBean> maps = applyTaskCacheService.getStudentApplyRecords(student.getId());
|
|
|
+ int studentApplyFinishCount = 0;
|
|
|
+ for (ApplyRecordCacheBean bean : maps.values()) {
|
|
|
+ if (!bean.getCancel()) {
|
|
|
+ studentApplyFinishCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 考生剩余预约次数 = 允许预约次数 - 已完成预约次数
|
|
|
+ int studentApplyNumber = applyTaskCacheService.getStudentApplyNumber(student.getId());
|
|
|
+ int unApplyNumber = studentApplyNumber - studentApplyFinishCount;
|
|
|
+
|
|
|
List<TimePeriodInfo> periodList = new ArrayList<>();
|
|
|
if (CollectionUtils.isNotEmpty(timePeriods)) {
|
|
|
for (TimePeriodEntity timePeriod : timePeriods) {
|
|
@@ -433,17 +463,16 @@ public class ExamReserveServiceImpl implements ExamReserveService {
|
|
|
info.setStatus(ApplyStatus.AVAILABLE);
|
|
|
}
|
|
|
|
|
|
- // todo 已约
|
|
|
+ String hashKey = String.format("%s_%s", examSiteId, timePeriod.getId());
|
|
|
+ ApplyRecordCacheBean existApply = maps.get(hashKey);
|
|
|
+ if (existApply != null && !existApply.getCancel()) {
|
|
|
+ info.setStatus(ApplyStatus.FINISHED);
|
|
|
+ }
|
|
|
|
|
|
periodList.add(info);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 考生剩余预约次数 = 允许预约次数 - 已完成预约次数
|
|
|
- int studentApplyNumber = applyTaskCacheService.getStudentApplyNumber(student.getId());
|
|
|
- int studentApplyFinishCount = applyTaskCacheService.getStudentApplyFinishCount(student.getId());
|
|
|
- int unApplyNumber = studentApplyNumber - studentApplyFinishCount;
|
|
|
-
|
|
|
ApplyTimePeriodResult result = new ApplyTimePeriodResult();
|
|
|
result.setUnApplyNumber(Math.max(unApplyNumber, 0));
|
|
|
result.setPeriodList(periodList);
|