|
@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.MessageFormat;
|
|
import java.text.MessageFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -69,6 +70,10 @@ public class StudentAutoAssignServiceImpl extends ServiceImpl<StudentApplyDao, S
|
|
|
|
|
|
// 未完成预约的考生
|
|
// 未完成预约的考生
|
|
List<StudentEntity> studentList = studentService.listNoFinishStudent(taskId, Boolean.FALSE);
|
|
List<StudentEntity> studentList = studentService.listNoFinishStudent(taskId, Boolean.FALSE);
|
|
|
|
+ //过滤掉已完成预约的考生
|
|
|
|
+ studentList = studentList.stream()
|
|
|
|
+ .filter(item -> item.getApplyNumber() - cacheService.getStudentApplyFinishCount(item.getId()) > 0)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
//按照教学点分组
|
|
//按照教学点分组
|
|
Map<Long, List<StudentEntity>> noFinishApplyMap = studentList.stream().collect(Collectors.groupingBy(StudentEntity::getCategoryId));
|
|
Map<Long, List<StudentEntity>> noFinishApplyMap = studentList.stream().collect(Collectors.groupingBy(StudentEntity::getCategoryId));
|
|
@@ -78,9 +83,8 @@ public class StudentAutoAssignServiceImpl extends ServiceImpl<StudentApplyDao, S
|
|
stringJoiner.add(MessageFormat.format("未完成预约的考生数:{0} 个", studentList.size()));
|
|
stringJoiner.add(MessageFormat.format("未完成预约的考生数:{0} 个", studentList.size()));
|
|
|
|
|
|
// 考位是否充足
|
|
// 考位是否充足
|
|
- /*List<TimePeriodEntity> timeList = listTimePeriod(taskId);
|
|
|
|
- timeList = listNoCancelExamTimePeriod(timeList, taskId);
|
|
|
|
- checkTeachingCapacity(noFinishApplyMap, timeList, taskId);*/
|
|
|
|
|
|
+ checkTeachingCapacity(noFinishApplyMap, timeList, taskId);
|
|
|
|
+
|
|
int successNum = 0;
|
|
int successNum = 0;
|
|
// 按照教学点安排考位。规则:不能和已预约的时间上有冲突
|
|
// 按照教学点安排考位。规则:不能和已预约的时间上有冲突
|
|
for (Long teachingId : noFinishApplyMap.keySet()) {
|
|
for (Long teachingId : noFinishApplyMap.keySet()) {
|
|
@@ -128,6 +132,37 @@ public class StudentAutoAssignServiceImpl extends ServiceImpl<StudentApplyDao, S
|
|
return stringJoiner.toString();
|
|
return stringJoiner.toString();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void checkTeachingCapacity(Map<Long, List<StudentEntity>> noFinishApplyMap, List<TimePeriodExamSiteBean> timeList, Long taskId) {
|
|
|
|
+ for (Long teachingId : noFinishApplyMap.keySet()) {
|
|
|
|
+ List<ExamSiteEntity> siteList = listExamSite(teachingId);
|
|
|
|
+ if (siteList.isEmpty()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ List<StudentEntity> teachingStudentList = noFinishApplyMap.get(teachingId);
|
|
|
|
+ // 未预约的考位
|
|
|
|
+ AtomicInteger toBeApplySum = new AtomicInteger();
|
|
|
|
+ teachingStudentList.forEach(item -> {
|
|
|
|
+ toBeApplySum.addAndGet(item.getApplyNumber() - cacheService.getStudentApplyFinishCount(item.getId()));
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ AtomicInteger remainSum = new AtomicInteger();
|
|
|
|
+ for (ExamSiteEntity site : siteList) {
|
|
|
|
+ //考点对应的可用时段
|
|
|
|
+ List<TimePeriodExamSiteBean> timePeriodExamSiteList = listAvailableTimePeriod(taskId, site, timeList);
|
|
|
|
+ //剩余可用考位数
|
|
|
|
+ timePeriodExamSiteList.forEach(item -> {
|
|
|
|
+ remainSum.addAndGet(cacheService.getApplyAvailableCount(site.getId(), item.getTimePeriodId()));
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int difference = remainSum.get() - toBeApplySum.get();
|
|
|
|
+ if (difference < 0) {
|
|
|
|
+ CategoryCacheBean teachingBean = categoryCacheService.getCategoryById(teachingId);
|
|
|
|
+ throw new StatusException("【" + teachingBean.getName() + "】教学点考位不足,还需要【" + (-difference) + "】个考位");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private List<TimePeriodExamSiteBean> listAvailableTimePeriod(Long taskId, ExamSiteEntity site, List<TimePeriodExamSiteBean> timeList) {
|
|
private List<TimePeriodExamSiteBean> listAvailableTimePeriod(Long taskId, ExamSiteEntity site, List<TimePeriodExamSiteBean> timeList) {
|
|
List<TimePeriodExamSiteBean> timePeriodExamSiteList = timePeriodService.listTimePeriodByExamSiteId(taskId, site.getId());
|
|
List<TimePeriodExamSiteBean> timePeriodExamSiteList = timePeriodService.listTimePeriodByExamSiteId(taskId, site.getId());
|
|
if (CollectionUtils.isEmpty(timePeriodExamSiteList)) {
|
|
if (CollectionUtils.isEmpty(timePeriodExamSiteList)) {
|
|
@@ -253,27 +288,4 @@ public class StudentAutoAssignServiceImpl extends ServiceImpl<StudentApplyDao, S
|
|
return studentApply != null;
|
|
return studentApply != null;
|
|
}
|
|
}
|
|
|
|
|
|
- private List<StudentApplyEntity> listStudentApply(Long stdId) {
|
|
|
|
- LambdaQueryWrapper<StudentApplyEntity> lm = new LambdaQueryWrapper<>();
|
|
|
|
- lm.eq(StudentApplyEntity::getStudentId, stdId);
|
|
|
|
- lm.eq(StudentApplyEntity::getCancel, Boolean.FALSE);
|
|
|
|
- return baseMapper.selectList(lm);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private StudentApplyEntity findStudentApply(StudentApplyEntity studentApply) {
|
|
|
|
- LambdaQueryWrapper<StudentApplyEntity> lm = new LambdaQueryWrapper<>();
|
|
|
|
- lm.eq(StudentApplyEntity::getExamSiteId, studentApply.getExamSiteId());
|
|
|
|
- lm.eq(StudentApplyEntity::getTimePeriodId, studentApply.getTimePeriodId());
|
|
|
|
- lm.eq(StudentApplyEntity::getStudentId, studentApply.getStudentId());
|
|
|
|
- return baseMapper.selectOne(lm);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Integer getHaveApplyNum(Long siteId, Long timeId) {
|
|
|
|
- LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
- wrapper.eq(StudentApplyEntity::getExamSiteId, siteId);
|
|
|
|
- wrapper.eq(StudentApplyEntity::getTimePeriodId, timeId);
|
|
|
|
- wrapper.eq(StudentApplyEntity::getCancel, Boolean.FALSE);
|
|
|
|
- return baseMapper.selectCount(wrapper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|