Joburgess 5 年之前
父节点
当前提交
4bbfe3bd70

+ 1 - 1
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/ExamOrganizationRelationServiceImpl.java

@@ -229,7 +229,7 @@ public class ExamOrganizationRelationServiceImpl extends BaseServiceImpl<Long, E
 			og.setSelfPaymentAmount(BigDecimal.ZERO);
 		}
 		examOrganizationRelationDao.batchInsert(organizationRelations);
-		sendUrl(examOrganizationRelation.getId().intValue(), selfOrganId);
+//		sendUrl(examOrganizationRelation.getId().intValue(), selfOrganId);
 	}
 
 	@Override

+ 21 - 23
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/ExamRoomStudentRelationServiceImpl.java

@@ -41,7 +41,6 @@ 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;
 
@@ -277,32 +276,23 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 		Set<Long> roomIds = examRooms.stream().map(ExamRoom::getId).collect(Collectors.toSet());
 		//未排考学员可排考考场学员
 		List<ExamRoomStudentRelation> examRoomStudents = examRoomStudentRelationDao.getWithExamRooms(new ArrayList<>(roomIds));
-		Map<Long, List<ExamRoomStudentRelation>> roomStudentsMap = examRoomStudents.stream().collect(Collectors.groupingBy(ExamRoomStudentRelation::getExamRoomId));
-		//考场中学员编号
-		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 allStudentNum = notInRoomStudents.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()));
+		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 = studentDontRepeatRegist.subList(startIndex, roomStudentNum - examRoom.getExamRoomStudentNum());
+				List<ExamRegistration> examRegistrations = notInRoomStudents.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());
@@ -310,22 +300,30 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 					e.setExamRoomId(examRoom.getId());
 					e.setStudentId(examRegistration.getStudentId());
 					e.setTenantId(examinationBasic.getTenantId());
-					roomNewStudents.add(e);
+					newRoomStudents.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());
+				roomStudentNumMap.put(examRoom.getId(), roomStudentNumMap.get(examRoom.getId()) + examRegistrations.size());
 			}
 		}
 
-		List<ExamRegistration> surplusRegists = notInRoomStudents.stream().filter(e -> !inRoomRegistIds.contains(e.getId())).collect(Collectors.toList());
-
-		for (ExamRegistration surplusRegist : surplusRegists) {
+		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);
+			}
 		}
-		Stream<Map.Entry<Long, Integer>> sorted = roomStudentNumMap.entrySet().stream().sorted(Map.Entry.comparingByValue());
-		Long minStudentNumRoomId = roomStudentNumMap.entrySet().stream().min(Map.Entry.comparingByValue()).get().getKey();
+
+		examRoomStudentRelationDao.batchInsert(newRoomStudents);
 
 	}