|
@@ -655,16 +655,15 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
@Override
|
|
|
public void autoAssign(Long taskId, Long userId) {
|
|
|
checkAfterOpenTime();
|
|
|
- // 未完成预约的考生
|
|
|
- List<StudentEntity> studentList = studentService.listNoFinishStudent(taskId, Boolean.FALSE);
|
|
|
- Map<Long, List<StudentEntity>> noFinishApplyMap = studentList.stream().collect(Collectors.groupingBy(StudentEntity::getCategoryId));
|
|
|
- // 考位是否充足
|
|
|
+ // 未完成预约的教学点
|
|
|
+ List<CategoryVO> categoryList = studentService.listNoFinishCategory(taskId, Boolean.FALSE);
|
|
|
List<TimePeriodEntity> timeList = listTimePeriod(taskId);
|
|
|
timeList = listNoCancelExamTimePeriod(timeList, taskId);
|
|
|
if (timeList == null || timeList.isEmpty()) {
|
|
|
throw new StatusException("可以取消预约的考试时段为0");
|
|
|
}
|
|
|
- checkTeachingCapacity(noFinishApplyMap, timeList);
|
|
|
+ // 考位是否充足
|
|
|
+ checkTeachingCapacity(taskId, categoryList, timeList);
|
|
|
RLock lock = (RLock) concurrentService.getLock(CacheConstants.LOCK_AUTO_APPLY);
|
|
|
if (lock.isLocked()) {
|
|
|
throw new StatusException("其他老师正在执行自动分配,请不要重复执行!");
|
|
@@ -673,9 +672,9 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
studentAutoAssignService.autoAssign(taskId, userId, timeList);
|
|
|
}
|
|
|
|
|
|
- private void checkTeachingCapacity(Map<Long, List<StudentEntity>> map, List<TimePeriodEntity> timeList) {
|
|
|
- for (Long key : map.keySet()) {
|
|
|
- List<ExamSiteEntity> siteList = listExamSite(key, null);
|
|
|
+ private void checkTeachingCapacity(Long taskId, List<CategoryVO> categoryList, List<TimePeriodEntity> timeList) {
|
|
|
+ for (CategoryVO vo : categoryList) {
|
|
|
+ List<ExamSiteEntity> siteList = listExamSite(vo.getId(), null);
|
|
|
// 总考位数量
|
|
|
Integer total = siteList.stream().mapToInt(ExamSiteEntity::getCapacity).sum() * timeList.size();
|
|
|
// 已经预约的数量
|
|
@@ -683,26 +682,14 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
List<Long> timePeriodIds = timeList.stream().map(BaseEntity::getId).collect(Collectors.toList());
|
|
|
Integer haveApplyNum = baseMapper.getHaveApplyCount(examSiteIds, timePeriodIds, Boolean.FALSE);
|
|
|
// 未预约的数量
|
|
|
- Integer noApplyNum = getNoApplyNum(map.get(key));
|
|
|
+ Integer noApplyNum = baseMapper.getNoApplyCount(taskId,vo.getId(),timePeriodIds);
|
|
|
if (noApplyNum > total - haveApplyNum) {
|
|
|
- CategoryEntity category = categoryService.getById(key);
|
|
|
+ CategoryEntity category = categoryService.getById(vo.getId());
|
|
|
throw new StatusException("【" + category.getName() + "】教学点考位不足!剩余的考位数量:【" + (total - haveApplyNum) + "】,实际需要的考位数量:【" + noApplyNum + "】");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Integer getNoApplyNum(List<StudentEntity> list) {
|
|
|
- int noApplyNum = 0;
|
|
|
- for (StudentEntity student : list) {
|
|
|
- if (student.getApplyNumber() == 1) {
|
|
|
- noApplyNum++;
|
|
|
- } else if (student.getApplyNumber() > 1) {
|
|
|
- int haveApplyNum = cacheService.getStudentApplyFinishCount(student.getId());
|
|
|
- noApplyNum = noApplyNum + (student.getApplyNumber() - haveApplyNum);
|
|
|
- }
|
|
|
- }
|
|
|
- return noApplyNum;
|
|
|
- }
|
|
|
|
|
|
private List<TimePeriodEntity> listNoCancelExamTimePeriod(List<TimePeriodEntity> timeList, Long taskId) {
|
|
|
ApplyTaskEntity task = applyTaskService.getById(taskId);
|