WANG 6 rokov pred
rodič
commit
9eba512453

+ 43 - 42
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamStudentRepo.java

@@ -1,42 +1,43 @@
-package cn.com.qmth.examcloud.core.examwork.dao;
-
-import java.util.List;
-
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
-import org.springframework.data.jpa.repository.Modifying;
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
-
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
-
-public interface ExamStudentRepo
-		extends
-			JpaRepository<ExamStudentEntity, Long>,
-			QueryByExampleExecutor<ExamStudentEntity>,
-			JpaSpecificationExecutor<ExamStudentEntity> {
-
-	List<ExamStudentEntity> findByStudentId(Long examId);
-
-	List<ExamStudentEntity> findByIdIn(List<Long> ids);
-
-	@Modifying
-	@Query("delete from ExamStudentEntity s where s.examId = ?1")
-	void deleteByExamId(Long examId);
-
-	ExamStudentEntity findByExamIdAndStudentIdAndCourseId(Long examId, Long studentId,
-			Long courseId);
-
-	@Modifying
-	@Query("update ExamStudentEntity s set s.name = ?1, s.studentCode=?2 where s.studentId = ?3")
-	void updateStudent(String name, String studentCode, Long studentId);
-
-	@Modifying
-	@Query("update ExamStudentEntity s set s.courseName = ?1, s.courseLevel  = ?2  where s.courseId = ?3")
-	void updateCourse(String courseName, String courseLevel, Long courseId);
-
-	int countByExamIdAndCourseIdAndPaperType(Long examId, Long courseId, String paperType);
-
-	int countByExamIdAndCourseId(Long examId, Long courseId);
-
-}
+package cn.com.qmth.examcloud.core.examwork.dao;
+
+import java.util.List;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
+
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
+
+public interface ExamStudentRepo
+		extends
+			JpaRepository<ExamStudentEntity, Long>,
+			QueryByExampleExecutor<ExamStudentEntity>,
+			JpaSpecificationExecutor<ExamStudentEntity> {
+
+	List<ExamStudentEntity> findByStudentId(Long examId);
+
+	List<ExamStudentEntity> findByIdIn(List<Long> ids);
+
+	@Modifying
+	@Query("delete from ExamStudentEntity s where s.examId = ?1")
+	void deleteByExamId(Long examId);
+
+	ExamStudentEntity findByExamIdAndStudentIdAndCourseId(Long examId, Long studentId,
+			Long courseId);
+
+	@Modifying
+	@Query("update ExamStudentEntity s set s.name = ?1, s.studentCode=?2 where s.studentId = ?3")
+	void updateStudent(String name, String studentCode, Long studentId);
+
+	@Modifying
+	@Query("update ExamStudentEntity s set s.courseName = ?1, s.courseLevel  = ?2  where s.courseId = ?3")
+	void updateCourse(String courseName, String courseLevel, Long courseId);
+
+	List<ExamStudentEntity> findTop2ByExamIdAndCourseIdAndPaperType(Long examId, Long courseId,
+			String paperType);
+
+	List<ExamStudentEntity> findTop2ByExamIdAndCourseId(Long examId, Long courseId);
+
+}

+ 16 - 20
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamStudentServiceImpl.java

@@ -127,16 +127,16 @@ public class ExamStudentServiceImpl implements ExamStudentService {
 			}
 			examStudentRepo.delete(examStudent);
 
-			int countCourseId = examStudentRepo.countByExamIdAndCourseId(examStudent.getExamId(),
-					examStudent.getCourseId());
-			if (1 > countCourseId) {
+			List<ExamStudentEntity> top2 = examStudentRepo.findTop2ByExamIdAndCourseId(
+					examStudent.getExamId(), examStudent.getCourseId());
+			if (1 > top2.size()) {
 				examCourseRelationRepo.deleteByExamIdAndCourseId(examStudent.getExamId(),
 						examStudent.getCourseId());
 			}
 
-			int countPaperType = examStudentRepo.countByExamIdAndCourseIdAndPaperType(
-					examStudent.getExamId(), examStudent.getCourseId(), examStudent.getPaperType());
-			if (1 > countPaperType) {
+			top2 = examStudentRepo.findTop2ByExamIdAndCourseIdAndPaperType(examStudent.getExamId(),
+					examStudent.getCourseId(), examStudent.getPaperType());
+			if (1 > top2.size()) {
 				examPaperTypeRelationRepo.deleteByExamIdAndCourseIdAndPaperType(
 						examStudent.getExamId(), examStudent.getCourseId(),
 						examStudent.getPaperType());
@@ -263,20 +263,16 @@ public class ExamStudentServiceImpl implements ExamStudentService {
 			examStudent = new ExamStudentEntity();
 			examStudent.setEnable(true);
 		} else {
-//			int countCourseId = examStudentRepo.countByExamIdAndCourseId(examStudent.getExamId(),
-//					examStudent.getCourseId());
-//			if (2 > countCourseId) {
-//				examCourseRelationRepo.deleteByExamIdAndCourseId(examStudent.getExamId(),
-//						examStudent.getCourseId());
-//			}
-//
-//			int countPaperType = examStudentRepo.countByExamIdAndCourseIdAndPaperType(
-//					examStudent.getExamId(), examStudent.getCourseId(), examStudent.getPaperType());
-//			if (2 > countPaperType) {
-//				examPaperTypeRelationRepo.deleteByExamIdAndCourseIdAndPaperType(
-//						examStudent.getExamId(), examStudent.getCourseId(),
-//						examStudent.getPaperType());
-//			}
+			if (!paperType.equals(examStudent.getPaperType())) {
+				List<ExamStudentEntity> top2 = examStudentRepo
+						.findTop2ByExamIdAndCourseIdAndPaperType(examStudent.getExamId(),
+								examStudent.getCourseId(), examStudent.getPaperType());
+				if (2 > top2.size()) {
+					examPaperTypeRelationRepo.deleteByExamIdAndCourseIdAndPaperType(
+							examStudent.getExamId(), examStudent.getCourseId(),
+							examStudent.getPaperType());
+				}
+			}
 		}
 
 		examStudent.setInfoCollector(examStudentInfo.getInfoCollector());