|
@@ -135,7 +135,6 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
|
|
|
|
|
|
List<ExamRoomStudentRelation> studentsWithExamRoom = examRoomStudentRelationDao.findStudentsWithExamRoom(examRoomId);
|
|
|
Set<Long> existRegistIds = studentsWithExamRoom.stream().map(ExamRoomStudentRelation::getExamRegistrationId).collect(Collectors.toSet());
|
|
|
- Set<Integer> existStudentIds = studentsWithExamRoom.stream().map(ExamRoomStudentRelation::getStudentId).collect(Collectors.toSet());
|
|
|
|
|
|
String[] registIds = registIdsStr.split(",");
|
|
|
|
|
@@ -143,9 +142,6 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
|
|
|
Map<Integer, ExamRegistration> studentRegistMap = examRegistrations.stream().collect(Collectors.toMap(ExamRegistration::getId, e -> e));
|
|
|
|
|
|
Set<Integer> studentIds = examRegistrations.stream().map(ExamRegistration::getStudentId).collect(Collectors.toSet());
|
|
|
- if(studentIds.size()!=registIds.length){
|
|
|
- throw new BizException("学员重复");
|
|
|
- }
|
|
|
|
|
|
List<ExamRoomStudentRelation> examRoomStudentRelations=new ArrayList<>();
|
|
|
List<ExamCertification> examCertifications=new ArrayList<>();
|
|
@@ -158,9 +154,6 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
|
|
|
if(Objects.isNull(examRegistration)){
|
|
|
throw new BizException("学员信息错误");
|
|
|
}
|
|
|
- if(existStudentIds.contains(examRegistration.getStudentId())){
|
|
|
- throw new BizException("学员重复");
|
|
|
- }
|
|
|
|
|
|
ExamRoomStudentRelation e=new ExamRoomStudentRelation();
|
|
|
e.setExamRegistrationId(Long.valueOf(registId));
|
|
@@ -266,16 +259,64 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
|
|
|
}
|
|
|
//未排考学员
|
|
|
List<ExamRegistration> notInRoomStudents = examRegistrationDao.getNotInRoomStudents(examId);
|
|
|
+ if(CollectionUtils.isEmpty(notInRoomStudents)){
|
|
|
+ throw new BizException("所有学员都已安排考场");
|
|
|
+ }
|
|
|
Map<Integer, List<ExamRegistration>> subjectRegistMap = notInRoomStudents.stream().collect(Collectors.groupingBy(ExamRegistration::getSubjectId));
|
|
|
Set<Integer> subjectIds = subjectRegistMap.keySet();
|
|
|
//未排考学员可排考考场
|
|
|
List<ExamRoom> examRooms = examRoomDao.getWithExamAndSubjects(examId, new ArrayList<>(subjectIds));
|
|
|
+ Set<Long> roomIds = examRooms.stream().map(ExamRoom::getId).collect(Collectors.toSet());
|
|
|
//未排考学员可排考考场学员
|
|
|
- List<ExamRoomStudentRelation> examRoomStudents = examRoomStudentRelationDao.getWithExamAndRoomSubjects(examId, new ArrayList<>(subjectIds));
|
|
|
- Map<Long, List<ExamRoomStudentRelation>> roomStudentsMap = examRoomStudents.stream().collect(Collectors.groupingBy(ExamRoomStudentRelation::getExamRoomId));
|
|
|
- Set<Long> roomIds = roomStudentsMap.keySet();
|
|
|
+ List<ExamRoomStudentRelation> examRoomStudents = examRoomStudentRelationDao.getWithExamRooms(new ArrayList<>(roomIds));
|
|
|
//考场数量
|
|
|
Integer roomNum = roomIds.size();
|
|
|
+ //总学员数量(排除重复学员)
|
|
|
+ Integer allStudentNum = notInRoomStudents.size() + examRoomStudents.size();
|
|
|
+ //每个考场可分配学员数
|
|
|
+ Integer roomStudentNum=allStudentNum/roomNum;
|
|
|
+
|
|
|
+ Set<Long> inRoomRegistIds=new HashSet<>();
|
|
|
+
|
|
|
+ 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>0){
|
|
|
+ int startIndex=0;
|
|
|
+ for (ExamRoom examRoom : examRooms) {
|
|
|
+ List<ExamRegistration> examRegistrations = notInRoomStudents.subList(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 = notInRoomStudents.stream().filter(e -> !inRoomRegistIds.contains(e.getId())).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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ examRoomStudentRelationDao.batchInsert(newRoomStudents);
|
|
|
|
|
|
}
|
|
|
|