|
@@ -41,6 +41,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import static com.keao.edu.user.enums.ExamStatusEnum.RESULT_CONFIRM;
|
|
|
|
|
@@ -266,16 +267,65 @@ 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));
|
|
|
+ List<ExamRoomStudentRelation> examRoomStudents = examRoomStudentRelationDao.getWithExamRooms(new ArrayList<>(roomIds));
|
|
|
Map<Long, List<ExamRoomStudentRelation>> roomStudentsMap = examRoomStudents.stream().collect(Collectors.groupingBy(ExamRoomStudentRelation::getExamRoomId));
|
|
|
- Set<Long> roomIds = roomStudentsMap.keySet();
|
|
|
+ //考场中学员编号
|
|
|
+ Set<Integer> roomStudentIds = examRoomStudents.stream().map(ExamRoomStudentRelation::getStudentId).collect(Collectors.toSet());
|
|
|
+ //考场中未出现的学员报名记录
|
|
|
+ List<ExamRegistration> studentDontRepeatRegist = notInRoomStudents.stream().filter(e -> !roomStudentIds.contains(e.getStudentId())).collect(Collectors.toList());
|
|
|
//考场数量
|
|
|
Integer roomNum = roomIds.size();
|
|
|
+ //总学员数量(排除重复学员)
|
|
|
+ Integer allStudentNum = studentDontRepeatRegist.size() + examRoomStudents.size();
|
|
|
+ //每个考场可分配学员数
|
|
|
+ Integer roomStudentNum=allStudentNum/roomNum;
|
|
|
+
|
|
|
+ Set<Long> inRoomRegistIds=new HashSet<>();
|
|
|
+
|
|
|
+ Map<Long, List<ExamRoomStudentRelation>> roomNewStudentMap=new HashMap<>();
|
|
|
+ Map<Long, Integer> roomStudentNumMap = examRoomStudents.stream().collect(Collectors.toMap(ExamRoomStudentRelation::getExamRoomId, e->e.getExamRoomStudentNum()));
|
|
|
+
|
|
|
+ if(roomStudentNum>0){
|
|
|
+ int startIndex=0;
|
|
|
+ for (ExamRoom examRoom : examRooms) {
|
|
|
+ List<ExamRegistration> examRegistrations = studentDontRepeatRegist.subList(startIndex, roomStudentNum - examRoom.getExamRoomStudentNum());
|
|
|
+ startIndex = startIndex+examRegistrations.size();
|
|
|
+ if(!roomNewStudentMap.containsKey(examRoom.getId())){
|
|
|
+ roomNewStudentMap.put(examRoom.getId(), new ArrayList<>());
|
|
|
+ }
|
|
|
+ List<ExamRoomStudentRelation> roomNewStudents = new ArrayList<>();
|
|
|
+ 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());
|
|
|
+ roomNewStudents.add(e);
|
|
|
+ inRoomRegistIds.add(examRegistration.getId().longValue());
|
|
|
+ }
|
|
|
+ roomNewStudentMap.get(examRoom.getId()).addAll(roomNewStudents);
|
|
|
+ roomStudentsMap.get(examRoom.getId()).addAll(roomNewStudents);
|
|
|
+ roomStudentNumMap.put(examRoom.getId(), roomStudentNumMap.get(examRoom.getId()) + roomNewStudents.size());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ExamRegistration> surplusRegists = notInRoomStudents.stream().filter(e -> !inRoomRegistIds.contains(e.getId())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (ExamRegistration surplusRegist : surplusRegists) {
|
|
|
+
|
|
|
+ }
|
|
|
+ Stream<Map.Entry<Long, Integer>> sorted = roomStudentNumMap.entrySet().stream().sorted(Map.Entry.comparingByValue());
|
|
|
+ Long minStudentNumRoomId = roomStudentNumMap.entrySet().stream().min(Map.Entry.comparingByValue()).get().getKey();
|
|
|
|
|
|
}
|
|
|
|