|
@@ -266,56 +266,67 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
|
|
|
if(CollectionUtils.isEmpty(examRooms)){
|
|
|
throw new BizException("请先建立考场");
|
|
|
}
|
|
|
- Set<Long> roomIds = examRooms.stream().map(ExamRoom::getId).collect(Collectors.toSet());
|
|
|
- //未排考学员可排考考场学员
|
|
|
- List<ExamRoomStudentRelation> examRoomStudents = examRoomStudentRelationDao.getWithExamRooms(new ArrayList<>(roomIds));
|
|
|
- //考场数量
|
|
|
- Integer roomNum = roomIds.size();
|
|
|
- //总学员数量(排除重复学员)
|
|
|
- Integer allStudentNum = notInRoomStudents.size() + examRoomStudents.size();
|
|
|
- //每个考场可分配学员数
|
|
|
- Integer roomStudentNum=allStudentNum/roomNum;
|
|
|
+ Map<String, List<ExamRoom>> subjectExamRoomMap = examRooms.stream().collect(Collectors.groupingBy(ExamRoom::getSubjectIdList));
|
|
|
|
|
|
- Integer existRoomStudentAvgNum = examRoomStudents.size()/roomNum;
|
|
|
+ List<ExamRoomStudentRelation> newRoomStudents = new ArrayList<>();
|
|
|
|
|
|
- Set<Long> inRoomRegistIds=new HashSet<>();
|
|
|
+ for (Map.Entry<Integer, List<ExamRegistration>> subjectRegistEntry : subjectRegistMap.entrySet()) {
|
|
|
+ List<ExamRegistration> subjectRegists = subjectRegistEntry.getValue();
|
|
|
+ List<ExamRoom> subjectRooms = subjectExamRoomMap.get(subjectRegistEntry.getKey().toString());
|
|
|
+ if(CollectionUtils.isEmpty(subjectRooms)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- List<ExamRoomStudentRelation> newRoomStudents = new ArrayList<>();
|
|
|
- Map<Long, Integer> roomStudentNumMap = examRooms.stream().collect(Collectors.toMap(ExamRoom::getId, e->Objects.isNull(e.getExamRoomStudentNum())?0:e.getExamRoomStudentNum()));
|
|
|
-
|
|
|
- if(roomStudentNum>existRoomStudentAvgNum){
|
|
|
- int startIndex=0;
|
|
|
- for (ExamRoom examRoom : examRooms) {
|
|
|
- List<ExamRegistration> examRegistrations = notInRoomStudents.subList(startIndex, startIndex + roomStudentNum - examRoom.getExamRoomStudentNum());
|
|
|
- startIndex = startIndex+examRegistrations.size();
|
|
|
- for (ExamRegistration examRegistration : examRegistrations) {
|
|
|
+ Set<Long> roomIds = subjectRooms.stream().map(ExamRoom::getId).collect(Collectors.toSet());
|
|
|
+ //未排考学员可排考考场学员
|
|
|
+ List<ExamRoomStudentRelation> examRoomStudents = examRoomStudentRelationDao.getWithExamRooms(new ArrayList<>(roomIds));
|
|
|
+ //考场数量
|
|
|
+ Integer roomNum = roomIds.size();
|
|
|
+ //总学员数量(排除重复学员)
|
|
|
+ Integer allStudentNum = subjectRegists.size() + examRoomStudents.size();
|
|
|
+ //每个考场可分配学员数
|
|
|
+ Integer roomStudentNum=allStudentNum/roomNum;
|
|
|
+
|
|
|
+ Integer existRoomStudentAvgNum = examRoomStudents.size()/roomNum;
|
|
|
+
|
|
|
+ Set<Long> inRoomRegistIds=new HashSet<>();
|
|
|
+
|
|
|
+ Map<Long, Integer> roomStudentNumMap = subjectRooms.stream().collect(Collectors.toMap(ExamRoom::getId, e->Objects.isNull(e.getExamRoomStudentNum())?0:e.getExamRoomStudentNum()));
|
|
|
+
|
|
|
+ if(roomStudentNum>existRoomStudentAvgNum){
|
|
|
+ int startIndex=0;
|
|
|
+ for (ExamRoom examRoom : subjectRooms) {
|
|
|
+ List<ExamRegistration> examRegistrations = subjectRegists.subList(startIndex, startIndex + roomStudentNum - examRoom.getExamRoomStudentNum());
|
|
|
+ startIndex = startIndex+examRegistrations.size();
|
|
|
+ for (ExamRegistration examRegistration : examRegistrations) {
|
|
|
+ ExamRoomStudentRelation e=new ExamRoomStudentRelation();
|
|
|
+ e.setExamRegistrationId(examRegistration.getId().longValue());
|
|
|
+ e.setExaminationBasicId(examId);
|
|
|
+ e.setExamRoomId(examRoom.getId());
|
|
|
+ e.setStudentId(examRegistration.getStudentId());
|
|
|
+ e.setTenantId(examinationBasic.getTenantId());
|
|
|
+ newRoomStudents.add(e);
|
|
|
+ inRoomRegistIds.add(examRegistration.getId().longValue());
|
|
|
+ }
|
|
|
+ roomStudentNumMap.put(examRoom.getId(), roomStudentNumMap.get(examRoom.getId()) + examRegistrations.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ExamRegistration> surplusRegist = subjectRegists.stream().filter(e -> !inRoomRegistIds.contains(e.getId().longValue())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (ExamRegistration examRegistration : surplusRegist) {
|
|
|
+ List<Long> sortedRoomIds=new LinkedList<>();
|
|
|
+ roomStudentNumMap.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEach(e->sortedRoomIds.add(e.getKey()));
|
|
|
+ for (Long sortedRoomId : sortedRoomIds) {
|
|
|
ExamRoomStudentRelation e=new ExamRoomStudentRelation();
|
|
|
e.setExamRegistrationId(examRegistration.getId().longValue());
|
|
|
e.setExaminationBasicId(examId);
|
|
|
- e.setExamRoomId(examRoom.getId());
|
|
|
+ e.setExamRoomId(sortedRoomId);
|
|
|
e.setStudentId(examRegistration.getStudentId());
|
|
|
e.setTenantId(examinationBasic.getTenantId());
|
|
|
newRoomStudents.add(e);
|
|
|
- inRoomRegistIds.add(examRegistration.getId().longValue());
|
|
|
+ break;
|
|
|
}
|
|
|
- roomStudentNumMap.put(examRoom.getId(), roomStudentNumMap.get(examRoom.getId()) + examRegistrations.size());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- List<ExamRegistration> surplusRegist = notInRoomStudents.stream().filter(e -> !inRoomRegistIds.contains(e.getId().longValue())).collect(Collectors.toList());
|
|
|
-
|
|
|
- for (ExamRegistration examRegistration : surplusRegist) {
|
|
|
- List<Long> sortedRoomIds=new LinkedList<>();
|
|
|
- roomStudentNumMap.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEach(e->sortedRoomIds.add(e.getKey()));
|
|
|
- for (Long sortedRoomId : sortedRoomIds) {
|
|
|
- ExamRoomStudentRelation e=new ExamRoomStudentRelation();
|
|
|
- e.setExamRegistrationId(examRegistration.getId().longValue());
|
|
|
- e.setExaminationBasicId(examId);
|
|
|
- e.setExamRoomId(sortedRoomId);
|
|
|
- e.setStudentId(examRegistration.getStudentId());
|
|
|
- e.setTenantId(examinationBasic.getTenantId());
|
|
|
- newRoomStudents.add(e);
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
|