|
@@ -187,7 +187,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
throw new StatusException(Constants.SYSTEM_BUSY);
|
|
throw new StatusException(Constants.SYSTEM_BUSY);
|
|
} else {
|
|
} else {
|
|
/*
|
|
/*
|
|
- //先更新数据库
|
|
|
|
|
|
+ //更新数据库
|
|
studentApplyEntity.setCancel(Boolean.TRUE);
|
|
studentApplyEntity.setCancel(Boolean.TRUE);
|
|
updateById(studentApplyEntity);
|
|
updateById(studentApplyEntity);
|
|
*/
|
|
*/
|
|
@@ -254,14 +254,16 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
log.warn("[importPreExam] 获取锁成功!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
|
|
log.warn("[importPreExam] 获取锁成功!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
|
|
|
|
|
|
CurrentApplyTaskVO task = cacheService.currentApplyTask(user.getOrgId());
|
|
CurrentApplyTaskVO task = cacheService.currentApplyTask(user.getOrgId());
|
|
- Date openStartTime = new Date(task.getOpenApplyStartTime());
|
|
|
|
- Date openEndTime = new Date(task.getOpenApplyEndTime());
|
|
|
|
- Date now = new Date();
|
|
|
|
|
|
+ // 开放式预约开始时间
|
|
|
|
+ Long openSelfStartTime = task.getOpenApplyStartTime();
|
|
|
|
+ // 开放式预约结束时间
|
|
|
|
+ Long openSelfEndTime = task.getOpenApplyEndTime();
|
|
|
|
+ long now = System.currentTimeMillis();
|
|
List<StudentImportVO> applyList = new ArrayList<>();
|
|
List<StudentImportVO> applyList = new ArrayList<>();
|
|
//教学点缓存
|
|
//教学点缓存
|
|
Map<String, Long> teachingCache = getTeachingCache(level);
|
|
Map<String, Long> teachingCache = getTeachingCache(level);
|
|
//考点缓存
|
|
//考点缓存
|
|
- Map<String, Long> agentCache = getAgentCache();
|
|
|
|
|
|
+ Map<String, Long> examSiteCache = getExamSiteCache();
|
|
//考试时段缓存
|
|
//考试时段缓存
|
|
Map<String, TimePeriodEntity> timePeriodCache = getTimePeriodCache();
|
|
Map<String, TimePeriodEntity> timePeriodCache = getTimePeriodCache();
|
|
//考点时段缓存
|
|
//考点时段缓存
|
|
@@ -325,16 +327,16 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
}
|
|
}
|
|
//考点所属教学点
|
|
//考点所属教学点
|
|
Long applyTeachingId;
|
|
Long applyTeachingId;
|
|
- Long examSiteId = agentCache.get(examSiteName);
|
|
|
|
|
|
+ Long examSiteId = examSiteCache.get(examSiteName);
|
|
if (examSiteId == null) {
|
|
if (examSiteId == null) {
|
|
msg.append(" 预约考点1不存在");
|
|
msg.append(" 预约考点1不存在");
|
|
} else {
|
|
} else {
|
|
applyTeachingId = examSiteCategoryCache.get(examSiteId);
|
|
applyTeachingId = examSiteCategoryCache.get(examSiteId);
|
|
- if ((now.before(openStartTime) || now.after(openEndTime)) && !categoryId.equals(applyTeachingId)) {
|
|
|
|
|
|
+ if ((now < openSelfStartTime || now > openSelfEndTime) && !categoryId.equals(applyTeachingId)) {
|
|
msg.append(" 未到自由预约时间,不能预约其他教学点下的考点");
|
|
msg.append(" 未到自由预约时间,不能预约其他教学点下的考点");
|
|
}
|
|
}
|
|
//教学点管理员导入-不能预约其他教学点下的考点
|
|
//教学点管理员导入-不能预约其他教学点下的考点
|
|
- if (now.after(openStartTime) && now.before(openEndTime) && user.getRole().equals(Role.TEACHING) && !categoryId.equals(applyTeachingId)) {
|
|
|
|
|
|
+ if (user.getRole().equals(Role.TEACHING) && !categoryId.equals(applyTeachingId)) {
|
|
msg.append(" 不能预约其他教学点下的考点");
|
|
msg.append(" 不能预约其他教学点下的考点");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -368,21 +370,21 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
if (StringUtils.isBlank(agentName) && StringUtils.isBlank(timePeriodName)) {
|
|
if (StringUtils.isBlank(agentName) && StringUtils.isBlank(timePeriodName)) {
|
|
apply.setAgentTimeList(agentTimeList);
|
|
apply.setAgentTimeList(agentTimeList);
|
|
applyList.add(apply);
|
|
applyList.add(apply);
|
|
- if (msg.length() > 0)
|
|
|
|
|
|
+ if (msg.length() > 0) {
|
|
failRecords.add(newError(i + 1, msg.toString()));
|
|
failRecords.add(newError(i + 1, msg.toString()));
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
} else {
|
|
} else {
|
|
- examSiteId = agentCache.get(agentName);
|
|
|
|
|
|
+ examSiteId = examSiteCache.get(agentName);
|
|
if (examSiteId == null) {
|
|
if (examSiteId == null) {
|
|
msg.append(" 预约考点").append(num + 1).append("不存在");
|
|
msg.append(" 预约考点").append(num + 1).append("不存在");
|
|
} else {
|
|
} else {
|
|
applyTeachingId = examSiteCategoryCache.get(examSiteId);
|
|
applyTeachingId = examSiteCategoryCache.get(examSiteId);
|
|
- if ((now.before(openStartTime) || now.after(openEndTime)) && !applyTeachingId.equals(categoryId)) {
|
|
|
|
|
|
+ if ((now < openSelfStartTime || now > openSelfEndTime) && !applyTeachingId.equals(categoryId)) {
|
|
msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
|
|
msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
|
|
}
|
|
}
|
|
//教学点管理员导入-不能预约其他教学点下的考点
|
|
//教学点管理员导入-不能预约其他教学点下的考点
|
|
- if (now.after(openStartTime) && now.before(openEndTime) && user.getRole().equals(Role.TEACHING) && !categoryId.equals(
|
|
|
|
- applyTeachingId)) {
|
|
|
|
|
|
+ if (user.getRole().equals(Role.TEACHING) && !categoryId.equals(applyTeachingId)) {
|
|
msg.append(" 不能预约其他教学点下的考点");
|
|
msg.append(" 不能预约其他教学点下的考点");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -507,7 +509,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
baseMapper.insert(studentApply);
|
|
baseMapper.insert(studentApply);
|
|
}*/
|
|
}*/
|
|
|
|
|
|
- // 队列bean组装
|
|
|
|
|
|
+ // 队列bean
|
|
ApplyRecordCacheBean bean = new ApplyRecordCacheBean();
|
|
ApplyRecordCacheBean bean = new ApplyRecordCacheBean();
|
|
bean.setStudentId(vo.getStudentId());
|
|
bean.setStudentId(vo.getStudentId());
|
|
bean.setExamSiteId(agentTimeVO.getAgentId());
|
|
bean.setExamSiteId(agentTimeVO.getAgentId());
|
|
@@ -532,7 +534,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("[importPreExam] 导入预约失败,msg:{}", e.getMessage());
|
|
log.error("[importPreExam] 导入预约失败,msg:{}", e.getMessage());
|
|
- throw new StatusException("导入预考失败,请稍后重试");
|
|
|
|
|
|
+ throw new StatusException("导入预考失败,错误原因:" + e.getMessage());
|
|
} finally {
|
|
} finally {
|
|
try {
|
|
try {
|
|
if (studentApplyLock.isLocked() && studentApplyLock.isHeldByCurrentThread()) {
|
|
if (studentApplyLock.isLocked() && studentApplyLock.isHeldByCurrentThread()) {
|
|
@@ -545,13 +547,6 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private StudentApplyEntity findStudentApply(StudentApplyEntity studentApply) {
|
|
|
|
- LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
- wrapper.eq(StudentApplyEntity::getExamSiteId, studentApply.getExamSiteId());
|
|
|
|
- wrapper.eq(StudentApplyEntity::getTimePeriodId, studentApply.getTimePeriodId());
|
|
|
|
- wrapper.eq(StudentApplyEntity::getStudentId, studentApply.getStudentId());
|
|
|
|
- return baseMapper.selectOne(wrapper);
|
|
|
|
- }
|
|
|
|
|
|
|
|
private void checkStudentTimePeriod(StudentImportVO studentImportVO, int row, int allowCancelDays, List<Map<String, Object>> failRecords) {
|
|
private void checkStudentTimePeriod(StudentImportVO studentImportVO, int row, int allowCancelDays, List<Map<String, Object>> failRecords) {
|
|
List<AgentAndTimeVO> agentTimeList = studentImportVO.getAgentTimeList();
|
|
List<AgentAndTimeVO> agentTimeList = studentImportVO.getAgentTimeList();
|
|
@@ -636,54 +631,6 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private List<AgentAndTimeVO> listAvailableTime(List<StudentApplyEntity> haveApplyList, List<AgentAndTimeVO> agentTimeList) {
|
|
|
|
- List<AgentAndTimeVO> availableList = new ArrayList<>();
|
|
|
|
- boolean flag;
|
|
|
|
- for (AgentAndTimeVO agentTime : agentTimeList) {
|
|
|
|
- flag = false;
|
|
|
|
- for (StudentApplyEntity apply : haveApplyList) {
|
|
|
|
- if (agentTime.getTimePeriodId().equals(apply.getTimePeriodId())) {
|
|
|
|
- flag = true;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (!flag) {
|
|
|
|
- availableList.add(agentTime);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return availableList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private List<StudentApplyEntity> listStudentHaveApply(Long studentId) {
|
|
|
|
- LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
- wrapper.eq(StudentApplyEntity::getStudentId, studentId);
|
|
|
|
- wrapper.eq(StudentApplyEntity::getCancel, Boolean.FALSE);
|
|
|
|
- return this.baseMapper.selectList(wrapper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void checkStudentApplyTime(List<StudentImportVO> applyList, Integer allowCancelDays, List<Map<String, Object>> failRecords) {
|
|
|
|
- for (int i = 0; i < applyList.size(); i++) {
|
|
|
|
- StudentImportVO vo = applyList.get(i);
|
|
|
|
- List<AgentAndTimeVO> agentTimeList = vo.getAgentTimeList();
|
|
|
|
- if (agentTimeList.size() > vo.getApplyNumber()) {
|
|
|
|
- failRecords.add(newError(i + 1, "考生的预约数量大于考生可预约的数量:" + vo.getApplyNumber()));
|
|
|
|
- }
|
|
|
|
- //是否重复预约时段
|
|
|
|
- boolean isDuplicate = agentTimeList.stream().collect(Collectors.groupingBy(AgentAndTimeVO::getTimePeriodId, Collectors.counting())).entrySet().stream()
|
|
|
|
- .anyMatch(entry -> entry.getValue() > 1);
|
|
|
|
- if (isDuplicate) {
|
|
|
|
- failRecords.add(newError(i + 1, "同一个考生预约的时间不能相同"));
|
|
|
|
- }
|
|
|
|
- //预约的日期,是否在可取消日期之后
|
|
|
|
- LocalDate day = LocalDate.now().plusDays(allowCancelDays);
|
|
|
|
- long epochMilli = day.plusDays(1).atStartOfDay(ZoneId.systemDefault()).minusSeconds(1).toInstant().toEpochMilli();
|
|
|
|
- for (AgentAndTimeVO agentTime : agentTimeList) {
|
|
|
|
- if (agentTime.getStartTime() <= epochMilli) {
|
|
|
|
- failRecords.add(newError(i + 1, "预约的考试时段,只能为" + allowCancelDays + "天之后的时段"));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
private TimePeriodEntity checkTimePeriod(String timePeriodStr, Map<String, TimePeriodEntity> timeCache) {
|
|
private TimePeriodEntity checkTimePeriod(String timePeriodStr, Map<String, TimePeriodEntity> timeCache) {
|
|
if (timePeriodStr == null || timePeriodStr.split(" ").length != 2) {
|
|
if (timePeriodStr == null || timePeriodStr.split(" ").length != 2) {
|
|
@@ -743,7 +690,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|
|
- private Map<String, Long> getAgentCache() {
|
|
|
|
|
|
+ private Map<String, Long> getExamSiteCache() {
|
|
LambdaQueryWrapper<ExamSiteEntity> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<ExamSiteEntity> wrapper = new LambdaQueryWrapper<>();
|
|
wrapper.eq(ExamSiteEntity::getEnable, Boolean.TRUE);
|
|
wrapper.eq(ExamSiteEntity::getEnable, Boolean.TRUE);
|
|
List<ExamSiteEntity> categoryList = examSiteService.list(wrapper);
|
|
List<ExamSiteEntity> categoryList = examSiteService.list(wrapper);
|
|
@@ -781,7 +728,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
Date selfEndTime = new Date(curApplyTask.getSelfApplyEndTime());
|
|
Date selfEndTime = new Date(curApplyTask.getSelfApplyEndTime());
|
|
Date openStartTime = new Date(curApplyTask.getOpenApplyStartTime());
|
|
Date openStartTime = new Date(curApplyTask.getOpenApplyStartTime());
|
|
if (!DateUtil.isBetwwen(selfEndTime, openStartTime)) {
|
|
if (!DateUtil.isBetwwen(selfEndTime, openStartTime)) {
|
|
- //throw new StatusException("自动分配,时间必须要在第一阶段结束之后,第三阶段开始之前");
|
|
|
|
|
|
+ throw new StatusException("自动分配,时间必须要在第一阶段结束之后,第三阶段开始之前");
|
|
}
|
|
}
|
|
|
|
|
|
//是否有可预约的时段
|
|
//是否有可预约的时段
|
|
@@ -792,13 +739,6 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
throw new StatusException("当前时间没有可预约的时段");
|
|
throw new StatusException("当前时间没有可预约的时段");
|
|
}
|
|
}
|
|
|
|
|
|
- /*//未完成预约教学点
|
|
|
|
- List<CategoryVO> teachingList = studentService.listNoFinishCategory(taskId, Boolean.FALSE);
|
|
|
|
- //考位是否充足
|
|
|
|
- checkTeachingCapacity(taskId, teachingList, timePeriodList);
|
|
|
|
- studentAutoAssignService.autoAssign(taskId, userId, timePeriodList);
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
//写入异步任务
|
|
//写入异步任务
|
|
Map<String, Object> taskMap = asyncTaskService.saveAsyncTask(AsyncTaskType.AUTO_ASSIGN, operateId);
|
|
Map<String, Object> taskMap = asyncTaskService.saveAsyncTask(AsyncTaskType.AUTO_ASSIGN, operateId);
|
|
taskMap.computeIfAbsent("taskId", v -> taskId);
|
|
taskMap.computeIfAbsent("taskId", v -> taskId);
|
|
@@ -810,31 +750,6 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void checkTeachingCapacity(Long taskId, List<CategoryVO> teachingList, List<TimePeriodEntity> timePeriodList) {
|
|
|
|
- for (CategoryVO categoryVO : teachingList) {
|
|
|
|
- List<ExamSiteEntity> examSiteList = listExamSite(categoryVO.getId(), null);
|
|
|
|
- if (CollectionUtils.isEmpty(examSiteList)) {
|
|
|
|
- log.warn("[autoAssign] teachingId: {} 下无考点", categoryVO.getId());
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //教学点所有的考位数量
|
|
|
|
- int total = examSiteList.stream().mapToInt(ExamSiteEntity::getCapacity).sum() * timePeriodList.size();
|
|
|
|
- List<Long> examSiteIds = examSiteList.stream().map(BaseEntity::getId).collect(Collectors.toList());
|
|
|
|
- List<Long> timePeriodIds = timePeriodList.stream().map(BaseEntity::getId).collect(Collectors.toList());
|
|
|
|
- //已预约的数量
|
|
|
|
- Integer haveApplyCount = baseMapper.getHaveApplyCount(examSiteIds, timePeriodIds, Boolean.FALSE);
|
|
|
|
- //未预约的数量
|
|
|
|
- Integer noApplyCount = baseMapper.getNoApplyCount(taskId, categoryVO.getId(), timePeriodIds);
|
|
|
|
-
|
|
|
|
- if (noApplyCount > total - haveApplyCount) {
|
|
|
|
- CategoryCacheBean categoryBean = categoryCacheService.getCategoryById(categoryVO.getId());
|
|
|
|
- log.warn("[autoAssign] {} 教学点剩余考位不足,剩余的考位数量:{},实际需要的考位数量:{}", categoryBean.getName(), total - haveApplyCount, noApplyCount);
|
|
|
|
- throw new StatusException("[" + categoryBean.getName() + "]教学点考位不足,剩余的考位数量:" + (total - haveApplyCount) + ",实际需要的考位数量:" + noApplyCount);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
private List<ExamSiteEntity> listExamSite(Long teachingId, Long examSiteId) {
|
|
private List<ExamSiteEntity> listExamSite(Long teachingId, Long examSiteId) {
|
|
LambdaQueryWrapper<ExamSiteEntity> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<ExamSiteEntity> wrapper = new LambdaQueryWrapper<>();
|