Browse Source

补充修改遗漏的JPQL精度问题

luoshi 3 năm trước cách đây
mục cha
commit
3471962c39

+ 14 - 12
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/exam/dao/ExamStudentDao.java

@@ -2,7 +2,6 @@ package cn.com.qmth.stmms.biz.exam.dao;
 
 
 import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
 import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
 import cn.com.qmth.stmms.common.enums.SubjectiveStatus;
 import cn.com.qmth.stmms.common.enums.SubjectiveStatus;
-
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Modifying;
@@ -12,8 +11,8 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
 
 
-public interface ExamStudentDao extends PagingAndSortingRepository<ExamStudent, Integer>,
-        JpaSpecificationExecutor<ExamStudent> {
+public interface ExamStudentDao
+        extends PagingAndSortingRepository<ExamStudent, Integer>, JpaSpecificationExecutor<ExamStudent> {
 
 
     public List<ExamStudent> findByExamId(int examId, Pageable pageable);
     public List<ExamStudent> findByExamId(int examId, Pageable pageable);
 
 
@@ -71,8 +70,8 @@ public interface ExamStudentDao extends PagingAndSortingRepository<ExamStudent,
 
 
     @Modifying
     @Modifying
     @Query("update ExamStudent s set s.subjectiveStatus=?3, s.subjectiveScore=?4, s.subjectiveScoreList=?5,s.inspectTime=?6,s.inspectorId=?7 where s.examId=?1 and s.subjectCode=?2")
     @Query("update ExamStudent s set s.subjectiveStatus=?3, s.subjectiveScore=?4, s.subjectiveScoreList=?5,s.inspectTime=?6,s.inspectorId=?7 where s.examId=?1 and s.subjectCode=?2")
-    public void updateSubjectiveStatusAndScore(Integer examId, String subjetCode, SubjectiveStatus status,
-            double score, String scoreList, Date inspectTime, Integer inspectorId);
+    public void updateSubjectiveStatusAndScore(Integer examId, String subjetCode, SubjectiveStatus status, double score,
+            String scoreList, Date inspectTime, Integer inspectorId);
 
 
     @Modifying
     @Modifying
     @Query("update ExamStudent s set s.subjectiveStatus=?3, s.subjectiveScore=?4, s.subjectiveScoreList=?5 "
     @Query("update ExamStudent s set s.subjectiveStatus=?3, s.subjectiveScore=?4, s.subjectiveScoreList=?5 "
@@ -144,7 +143,8 @@ public interface ExamStudentDao extends PagingAndSortingRepository<ExamStudent,
 
 
     @Query("select s from ExamStudent s where s.examId=?1 and s.subjectCode=?2 and s.upload=true and s.absent=false and s.breach=false and s.uploadTime!=null "
     @Query("select s from ExamStudent s where s.examId=?1 and s.subjectCode=?2 and s.upload=true and s.absent=false and s.breach=false and s.uploadTime!=null "
             + "and not exists (select l.id from MarkLibrary l where l.studentId=s.id and l.groupNumber=?3)")
             + "and not exists (select l.id from MarkLibrary l where l.studentId=s.id and l.groupNumber=?3)")
-    public List<ExamStudent> findUnLibraryStudent(Integer examId, String subjectCode, Integer groupNumber, Pageable page);
+    public List<ExamStudent> findUnLibraryStudent(Integer examId, String subjectCode, Integer groupNumber,
+            Pageable page);
 
 
     @Query("select s from ExamStudent s where s.examId=?1 and s.subjectCode=?2 and s.upload=true and s.absent=false and s.breach=false and s.uploadTime!=null and s.uploadTime>=?4 "
     @Query("select s from ExamStudent s where s.examId=?1 and s.subjectCode=?2 and s.upload=true and s.absent=false and s.breach=false and s.uploadTime!=null and s.uploadTime>=?4 "
             + "and not exists (select l.id from MarkLibrary l where l.studentId=s.id and l.groupNumber=?3)")
             + "and not exists (select l.id from MarkLibrary l where l.studentId=s.id and l.groupNumber=?3)")
@@ -171,17 +171,18 @@ public interface ExamStudentDao extends PagingAndSortingRepository<ExamStudent,
     @Query("select s.className from ExamStudent s where s.examId=?1 and s.subjectCode=?2 group by s.className")
     @Query("select s.className from ExamStudent s where s.examId=?1 and s.subjectCode=?2 group by s.className")
     public List<String> findDistinctClassName(Integer examId, String subjectCode);
     public List<String> findDistinctClassName(Integer examId, String subjectCode);
 
 
-    @Query(value = "select cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) from eb_exam_student s where s.exam_id=?1 and s.subject_code=?2 and s.is_upload =true and s.is_absent=false and s.is_breach=false order by s.objective_score+s.subjective_score desc limit ?3 ", nativeQuery = true)
-    public List<Double> findHighCountTotalSocreByExamIdAndSubjectCode(Integer examId, String subjectCode, int highCount);
+    @Query(value = "select cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) from eb_exam_student s where s.exam_id=?1 and s.subject_code=?2 and s.is_upload =true and s.is_absent=false and s.is_breach=false order by cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) desc limit ?3 ", nativeQuery = true)
+    public List<Double> findHighCountTotalSocreByExamIdAndSubjectCode(Integer examId, String subjectCode,
+            int highCount);
 
 
-    @Query(value = "select cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) from eb_exam_student s where s.exam_id=?1 and s.subject_code=?2 and s.is_upload =true and s.is_absent=false and s.is_breach=false order by s.objective_score+s.subjective_score asc limit ?3 ", nativeQuery = true)
+    @Query(value = "select cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) from eb_exam_student s where s.exam_id=?1 and s.subject_code=?2 and s.is_upload =true and s.is_absent=false and s.is_breach=false order by cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) asc limit ?3 ", nativeQuery = true)
     public List<Double> findLowCountTotalSocreByExamIdAndSubjectCode(Integer examId, String subjectCode, int lowCount);
     public List<Double> findLowCountTotalSocreByExamIdAndSubjectCode(Integer examId, String subjectCode, int lowCount);
 
 
-    @Query(value = "select s.objective_score+s.subjective_score from eb_exam_student s where s.exam_id=?1 and s.subject_code=?2 and s.class_name=?3 and s.is_upload =true and s.is_absent=false and s.is_breach=false order by s.objective_score+s.subjective_score desc limit ?4 ", nativeQuery = true)
+    @Query(value = "select cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) from eb_exam_student s where s.exam_id=?1 and s.subject_code=?2 and s.class_name=?3 and s.is_upload =true and s.is_absent=false and s.is_breach=false order by cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) desc limit ?4 ", nativeQuery = true)
     public List<Double> findHighCountTotalSocreByExamIdAndSubjectCodeAndClass(Integer examId, String subjectCode,
     public List<Double> findHighCountTotalSocreByExamIdAndSubjectCodeAndClass(Integer examId, String subjectCode,
             String className, int highCount);
             String className, int highCount);
 
 
-    @Query(value = "select s.objective_score+s.subjective_score from eb_exam_student s where s.exam_id=?1 and s.subject_code=?2 and s.class_name=?3 and s.is_upload =true and s.is_absent=false and s.is_breach=false order by s.objective_score+s.subjective_score asc limit ?4 ", nativeQuery = true)
+    @Query(value = "select cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) from eb_exam_student s where s.exam_id=?1 and s.subject_code=?2 and s.class_name=?3 and s.is_upload =true and s.is_absent=false and s.is_breach=false order by cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) asc limit ?4 ", nativeQuery = true)
     public List<Double> findLowCountTotalSocreByExamIdAndSubjectCodeAndClass(Integer examId, String subjectCode,
     public List<Double> findLowCountTotalSocreByExamIdAndSubjectCodeAndClass(Integer examId, String subjectCode,
             String className, int lowCount);
             String className, int lowCount);
 
 
@@ -193,6 +194,7 @@ public interface ExamStudentDao extends PagingAndSortingRepository<ExamStudent,
     public void updateSubjectiveStatusAndTimeAndInspectorId(Integer studentId, SubjectiveStatus status,
     public void updateSubjectiveStatusAndTimeAndInspectorId(Integer studentId, SubjectiveStatus status,
             Date inspectTime, Integer inspectorId);
             Date inspectTime, Integer inspectorId);
 
 
-    public List<ExamStudent> findByExamIdAndStudentCodeAndSubjectCode(int examId, String studentCode, String subjectCode);
+    public List<ExamStudent> findByExamIdAndStudentCodeAndSubjectCode(int examId, String studentCode,
+            String subjectCode);
 
 
 }
 }

+ 4 - 5
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/exam/dao/ExamSubjectDao.java

@@ -2,7 +2,6 @@ package cn.com.qmth.stmms.biz.exam.dao;
 
 
 import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
 import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
 import cn.com.qmth.stmms.biz.exam.model.ExamSubjectPK;
 import cn.com.qmth.stmms.biz.exam.model.ExamSubjectPK;
-
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.jpa.repository.Query;
@@ -11,8 +10,8 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 import java.util.List;
 import java.util.List;
 import java.util.Set;
 import java.util.Set;
 
 
-public interface ExamSubjectDao extends PagingAndSortingRepository<ExamSubject, ExamSubjectPK>,
-        JpaSpecificationExecutor<ExamSubject> {
+public interface ExamSubjectDao
+        extends PagingAndSortingRepository<ExamSubject, ExamSubjectPK>, JpaSpecificationExecutor<ExamSubject> {
 
 
     @Query("select s from ExamSubject s where s.pk.examId=?1")
     @Query("select s from ExamSubject s where s.pk.examId=?1")
     public List<ExamSubject> findByExamId(int examId);
     public List<ExamSubject> findByExamId(int examId);
@@ -36,11 +35,11 @@ public interface ExamSubjectDao extends PagingAndSortingRepository<ExamSubject,
     public List<ExamSubject> findByExamIdAndUploadCountGt(int examId, int uploadCount);
     public List<ExamSubject> findByExamIdAndUploadCountGt(int examId, int uploadCount);
 
 
     @Modifying
     @Modifying
-    @Query("update ExamSubject s set s.totalScore=s.objectiveScore+s.subjectiveScore where s.pk.examId=?1")
+    @Query(value = "update eb_exam_subject s set s.total_score=cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) where s.exam_id=?1", nativeQuery = true)
     public void updateTotalScoreByExamId(int examId);
     public void updateTotalScoreByExamId(int examId);
 
 
     @Modifying
     @Modifying
-    @Query("update ExamSubject s set s.totalScore=s.objectiveScore+s.subjectiveScore where s.pk.examId=?1 and s.pk.code=?2")
+    @Query(value = "update eb_exam_subject s set s.total_score=cast(s.objective_score as decimal)+cast(s.subjective_score as decimal) where s.exam_id=?1 and s.code=?2", nativeQuery = true)
     public void updateTotalScoreByExamIdAndCode(int examId, String code);
     public void updateTotalScoreByExamIdAndCode(int examId, String code);
 
 
     @Modifying
     @Modifying