Joburgess 5 سال پیش
والد
کامیت
1d5ac9cab2

+ 9 - 0
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/dao/ExamRoomStudentRelationDao.java

@@ -178,6 +178,15 @@ public interface ExamRoomStudentRelationDao extends BaseDAO<Long, ExamRoomStuden
     int countStudentsWithRoom(Long examRoomId);
 
     /**
+     * @describe 根据考场获取考场学员
+     * @author Joburgess
+     * @date 2020.08.06
+     * @param examRoomIds:
+     * @return java.util.List<com.keao.edu.user.api.entity.ExamRoomStudentRelation>
+     */
+    List<ExamRoomStudentRelation> getWithExamRooms(@Param("examRoomIds") List<Long> examRoomIds);
+
+    /**
      * @describe 根据考级项目及声部获取考场学员
      * @author Joburgess
      * @date 2020.08.06

+ 12 - 1
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/entity/ExamManualLedger.java

@@ -32,6 +32,9 @@ public class ExamManualLedger {
 	
 	@ApiModelProperty(value = "交易时间")
 	private java.util.Date transTime;
+
+	@ApiModelProperty(value = "交易流水号")
+	private String transNo;
 	
 	@ApiModelProperty(value = "备注")
 	private String memo;
@@ -117,7 +120,15 @@ public class ExamManualLedger {
 	public java.util.Date getTransTime(){
 		return this.transTime;
 	}
-			
+
+	public String getTransNo() {
+		return transNo;
+	}
+
+	public void setTransNo(String transNo) {
+		this.transNo = transNo;
+	}
+
 	public void setMemo(String memo){
 		this.memo = memo;
 	}

+ 52 - 2
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/ExamRoomStudentRelationServiceImpl.java

@@ -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();
 
 	}
 

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

@@ -171,7 +171,7 @@ public class ExaminationBasicServiceImpl extends BaseServiceImpl<Long, Examinati
     @Override
     public void examEndRemind() {
         LocalDate today = LocalDate.now();
-        List<ExaminationBasic> endExams = examinationBasicDao.getEndExamsWithDayAndStatus(today.plusDays(-1).toString());
+        List<ExaminationBasic> endExams = examinationBasicDao.getEndExamsWithDayAndStatus(today.toString());
         if(CollectionUtils.isEmpty(endExams)){
             return;
         }

+ 6 - 2
edu-user/edu-user-biz/src/main/resources/config/mybatis/ExamManualLedgerMapper.xml

@@ -14,6 +14,7 @@
 		<result column="trans_direction_" property="transDirection" />
 		<result column="amount_" property="amount" />
 		<result column="trans_time_" property="transTime" />
+		<result column="trans_no_" property="transNo" />
 		<result column="memo_" property="memo" />
 		<result column="operator_user_id_" property="operatorUserId" />
 		<result column="tenant_id_" property="tenantId" />
@@ -39,8 +40,8 @@
 		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
 		</selectKey>
 		-->
-		INSERT INTO exam_manual_ledger (organ_id_,target_organ_id_,examination_basic_id_,trans_direction_,amount_,trans_time_,memo_,operator_user_id_,tenant_id_,create_time_)
-		VALUES(#{organId},#{targetOrganId},#{examinationBasicId},#{transDirection},#{amount},#{transTime},#{memo},#{operatorUserId},#{tenantId},NOW())
+		INSERT INTO exam_manual_ledger (organ_id_,target_organ_id_,examination_basic_id_,trans_direction_,amount_,trans_time_,trans_no_,memo_,operator_user_id_,tenant_id_,create_time_)
+		VALUES(#{organId},#{targetOrganId},#{examinationBasicId},#{transDirection},#{amount},#{transTime},#{transNo},#{memo},#{operatorUserId},#{tenantId},NOW())
 	</insert>
 	
 	<!-- 根据主键查询一条记录 -->
@@ -65,6 +66,9 @@
 			<if test="transTime != null">
 				trans_time_ = #{transTime},
 			</if>
+			<if test="transNo != null">
+				trans_no_ = #{transNo},
+			</if>
 			<if test="memo != null">
 				memo_ = #{memo},
 			</if>

+ 12 - 0
edu-user/edu-user-biz/src/main/resources/config/mybatis/ExamRoomStudentRelationMapper.xml

@@ -306,4 +306,16 @@
 				#{subjectId}
 			</foreach>
 	</select>
+
+	<select id="getWithExamRooms" resultMap="ExamRoomStudentRelation">
+		SELECT
+			*
+		FROM
+			exam_room_student_relation
+		WHERE
+			exam_room_id_ IN
+			<foreach collection="examRoomIds" item="examRoomId" separator="," open="(" close=")">
+				#{examRoomId}
+			</foreach>
+	</select>
 </mapper>

+ 1 - 1
edu-user/edu-user-biz/src/main/resources/config/mybatis/ExaminationBasicMapper.xml

@@ -281,6 +281,6 @@
 	</select>
 
     <select id="getEndExamsWithDayAndStatus" resultMap="ExaminationBasic">
-		SELECT * FROM examination_basic WHERE DATE_FORMAT(actual_exam_end_time_, '%Y-%m-%d') = #{day}
+		SELECT * FROM examination_basic WHERE status_ IN ('EXAM_END') AND DATE_FORMAT(actual_exam_end_time_, '%Y-%m-%d') = #{day}
 	</select>
 </mapper>