From eac2521e9da5c93687bd9d7748f12f834da1b578 Mon Sep 17 00:00:00 2001
From: Mlxa0324 <mlx950324@163.com>
Date: Tue, 20 Dec 2022 19:50:40 +0800
Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E7=9B=AE=E6=88=90=E7=BB=A9=E8=AF=A6?=
 =?UTF-8?q?=E6=83=85=E9=A1=B5bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../ibeetl/jlw/dao/GeneralQuestionLogDao.java |   9 +-
 .../dao/TeacherOpenCourseQuestionLogDao.java  |   4 +-
 .../service/GeneralQuestionLogService.java    |   3 +-
 .../TeacherOpenCourseQuestionLogService.java  |   4 +-
 ...erOpenCourseQuestionSettingController.java |   6 +-
 ...TeacherOpenCourseQuestionSettingQuery.java |   6 +
 .../sql/jlw/teacherOpenCourseQuestionLog.md   | 285 ++++++++++--------
 7 files changed, 186 insertions(+), 131 deletions(-)

diff --git a/web/src/main/java/com/ibeetl/jlw/dao/GeneralQuestionLogDao.java b/web/src/main/java/com/ibeetl/jlw/dao/GeneralQuestionLogDao.java
index 85a56247..0cac03d6 100644
--- a/web/src/main/java/com/ibeetl/jlw/dao/GeneralQuestionLogDao.java
+++ b/web/src/main/java/com/ibeetl/jlw/dao/GeneralQuestionLogDao.java
@@ -87,13 +87,15 @@ public interface GeneralQuestionLogDao extends BaseMapper<GeneralQuestionLog> {
      * 功能描述: <br>
      * 通过题目配置ID和添加类型查询题目日志数量
      *
-     * @param questionSettingId  题目配置ID
-     * @param type               题目添加类型
+     * @param questionSettingId 题目配置ID
+     * @param studentId
+     * @param name
+     * @param type              题目添加类型
      * @return {@link long}
      * @Author: lx
      * @Date: 2022/12/6 22:59
      */
-    default long getCountByQuestionLogAddType(@NotNull Long questionSettingId, String ...type) {
+    default long getCountByQuestionLogAddType(@NotNull Long questionSettingId, @NotNull(message = "学生ID不能为空!") Long studentId, String name, String ...type) {
         LambdaQuery<GeneralQuestionLog> lambdaQuery = createLambdaQuery();
         LambdaQuery<GeneralQuestionLog> andCondition = lambdaQuery.condition();
 
@@ -106,6 +108,7 @@ public interface GeneralQuestionLogDao extends BaseMapper<GeneralQuestionLog> {
 
         return lambdaQuery.and(andCondition)
                 .andEq(GeneralQuestionLog::getGeneralQuestionLogStatus, 1)
+                .andEq(GeneralQuestionLog::getStudentId, studentId)
                 .andEq(GeneralQuestionLog::getGeneralQuestionSettingId, questionSettingId)
                 .count();
     }
diff --git a/web/src/main/java/com/ibeetl/jlw/dao/TeacherOpenCourseQuestionLogDao.java b/web/src/main/java/com/ibeetl/jlw/dao/TeacherOpenCourseQuestionLogDao.java
index cd8bc1d5..13ffc4d4 100644
--- a/web/src/main/java/com/ibeetl/jlw/dao/TeacherOpenCourseQuestionLogDao.java
+++ b/web/src/main/java/com/ibeetl/jlw/dao/TeacherOpenCourseQuestionLogDao.java
@@ -93,12 +93,13 @@ public interface TeacherOpenCourseQuestionLogDao extends BaseMapper<TeacherOpenC
      * 通过题目配置ID和添加类型查询题目日志数量
      *
      * @param questionSettingId  题目配置ID
+     * @param studentId          学生ID
      * @param type               题目添加类型
      * @return {@link long}
      * @Author: lx
      * @Date: 2022/12/6 22:59
      */
-    default long getCountByQuestionLogAddType(@NotNull Long questionSettingId, String ...type) {
+    default long getCountByQuestionLogAddType(@NotNull Long questionSettingId, Long studentId, String ...type) {
         LambdaQuery<TeacherOpenCourseQuestionLog> lambdaQuery = createLambdaQuery();
         LambdaQuery<TeacherOpenCourseQuestionLog> andCondition = lambdaQuery.condition();
 
@@ -111,6 +112,7 @@ public interface TeacherOpenCourseQuestionLogDao extends BaseMapper<TeacherOpenC
 
         return lambdaQuery.and(andCondition)
                 .andEq(TeacherOpenCourseQuestionLog::getTeacherOpenCourseQuestionLogStatus, 1)
+                .andEq(TeacherOpenCourseQuestionLog::getStudentId, studentId)
                 .andEq(TeacherOpenCourseQuestionLog::getTeacherOpenCourseQuestionSettingId, questionSettingId)
                 .count();
     }
diff --git a/web/src/main/java/com/ibeetl/jlw/service/GeneralQuestionLogService.java b/web/src/main/java/com/ibeetl/jlw/service/GeneralQuestionLogService.java
index c2663e1a..2b913c8a 100644
--- a/web/src/main/java/com/ibeetl/jlw/service/GeneralQuestionLogService.java
+++ b/web/src/main/java/com/ibeetl/jlw/service/GeneralQuestionLogService.java
@@ -11,7 +11,6 @@ import cn.hutool.core.util.ReUtil;
 import cn.jlw.util.ToolUtils;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.ibeetl.admin.core.entity.CoreDict;
 import com.ibeetl.admin.core.entity.CoreUser;
 import com.ibeetl.admin.core.service.CoreBaseService;
 import com.ibeetl.admin.core.service.CoreDictService;
@@ -849,7 +848,7 @@ public class GeneralQuestionLogService extends CoreBaseService<GeneralQuestionLo
         // 不是强制发题,则不覆盖现有的题目日志,则继续做题
         // 验证题目日志,是否已经存在试卷
         if(!isReSend) {
-            long logCount = generalQuestionLogDao.getCountByQuestionLogAddType(questionSettingId, PRE_SUBMIT.name(), null);
+            long logCount = generalQuestionLogDao.getCountByQuestionLogAddType(questionSettingId, studentId, PRE_SUBMIT.name(), null);
 
             // 如果题目日志里存在预先布置的题目,则直接返回
             if (logCount > 0) {
diff --git a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionLogService.java b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionLogService.java
index caa925cf..404ea853 100644
--- a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionLogService.java
+++ b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionLogService.java
@@ -436,7 +436,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
                 .studentId(student.getStudentId())
                 .teacherOpenCourseQuestionSettingId(questionSettingId)
                 .build();
-        List<TeacherOpenCourseQuestionLog> logList = teacherOpenCourseQuestionLogDao.getValuesByQuery(questionLogQuery);
+        List<TeacherOpenCourseQuestionLog> logList = teacherOpenCourseQuestionLogDao.getValuesByQueryNotWithPermission(questionLogQuery);
 
         final List<QuestionLogAddTypeEnum> tempList = Arrays.asList(PRE_SUBMIT, null);
         // 只是未提交的数据
@@ -678,7 +678,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
         // 不是强制发题,则不覆盖现有的题目日志,则继续做题
         // 验证题目日志,是否已经存在试卷
         if(!isReSend) {
-            long logCount = teacherOpenCourseQuestionLogDao.getCountByQuestionLogAddType(questionSettingId, judgeAddType.name(), null);
+            long logCount = teacherOpenCourseQuestionLogDao.getCountByQuestionLogAddType(questionSettingId, studentId, judgeAddType.name(), null);
 
             // 如果题目日志里存在预先布置的题目,则直接返回
             if (logCount > 0) {
diff --git a/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseQuestionSettingController.java b/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseQuestionSettingController.java
index c826618c..1e419fb0 100644
--- a/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseQuestionSettingController.java
+++ b/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseQuestionSettingController.java
@@ -77,8 +77,10 @@ public class TeacherOpenCourseQuestionSettingController{
             return JsonResult.failMessage("请登录后再操作");
         }else{
             List<TeacherOpenCourseQuestionSetting>list = teacherOpenCourseQuestionSettingService.getValuesByQuery(param);
-            // 设置分数和完成时间
-            teacherOpenCourseQuestionSettingService.setMyQuestionLogScoreInfo(list, getStudent());
+            if (!param.getNotSelectOther()) {
+                // 设置分数和完成时间
+                teacherOpenCourseQuestionSettingService.setMyQuestionLogScoreInfo(list, getStudent());
+            }
             return  JsonResult.success(list);
         }
     }
diff --git a/web/src/main/java/com/ibeetl/jlw/web/query/TeacherOpenCourseQuestionSettingQuery.java b/web/src/main/java/com/ibeetl/jlw/web/query/TeacherOpenCourseQuestionSettingQuery.java
index bdae84a5..3937f7df 100644
--- a/web/src/main/java/com/ibeetl/jlw/web/query/TeacherOpenCourseQuestionSettingQuery.java
+++ b/web/src/main/java/com/ibeetl/jlw/web/query/TeacherOpenCourseQuestionSettingQuery.java
@@ -9,6 +9,7 @@ import com.ibeetl.jlw.entity.TeacherOpenCourseQuestionSetting;
 import com.ibeetl.jlw.entity.dto.QuestionSettingDTO;
 import com.ibeetl.jlw.enums.GlobalPushStatusEnum;
 import com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum;
+import com.ibeetl.jlw.web.TeacherOpenCourseQuestionSettingController;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
@@ -96,6 +97,11 @@ public class TeacherOpenCourseQuestionSettingQuery extends PageParam {
     private String orgIdPlural;
     private String userIdPlural;
 
+    /**
+     * 是否查询当前用户的得分情况,等其他信息,加速查询速度。 仅支持此方法{@link TeacherOpenCourseQuestionSettingController#getList}
+     */
+    private Boolean notSelectOther = false;
+
     private String teacherOpenCourseQuestionSettingJsonStr;//json格式
 
     private String _given;//指定更新的特定字段,多个逗号隔开
diff --git a/web/src/main/resources/sql/jlw/teacherOpenCourseQuestionLog.md b/web/src/main/resources/sql/jlw/teacherOpenCourseQuestionLog.md
index 8da71019..6d8c4d0b 100644
--- a/web/src/main/resources/sql/jlw/teacherOpenCourseQuestionLog.md
+++ b/web/src/main/resources/sql/jlw/teacherOpenCourseQuestionLog.md
@@ -277,135 +277,178 @@ studentScoreList
     tz.* 
   @}
   from (
-  select
+    SELECT
+      *
+    FROM
+    (
+    SELECT
     t.student_id,
     ta.student_sn,
     ta.student_name,
     t.teacher_open_course_question_setting_id,
-    sum(t.student_score) as sum_student_score
-  from teacher_open_course_question_log t
-  left join student ta on ta.student_id = t.student_id
-  where 1=1  
-  @if(!isEmpty(teacherOpenCourseQuestionLogId)){
-  and t.teacher_open_course_question_log_id =#teacherOpenCourseQuestionLogId#
-  @}
-  @if(!isEmpty(teacherOpenCourseQuestionLogIdPlural)){
-  and find_in_set(t.teacher_open_course_question_log_id,#teacherOpenCourseQuestionLogIdPlural#)
-  @}
-  @if(!isEmpty(teacherOpenCourseQuestionSettingId)){
-  and t.teacher_open_course_question_setting_id =#teacherOpenCourseQuestionSettingId#
-  @}
-  @if(!isEmpty(teacherOpenCourseQuestionSettingIdPlural)){
-  and find_in_set(t.teacher_open_course_question_setting_id,#teacherOpenCourseQuestionSettingIdPlural#)
-  @}
-  @if(!isEmpty(resourcesQuestionSnapshotId)){
-  and t.resources_question_snapshot_id =#resourcesQuestionSnapshotId#
-  @}
-  @if(!isEmpty(resourcesQuestionSnapshotIdPlural)){
-  and find_in_set(t.resources_question_snapshot_id,#resourcesQuestionSnapshotIdPlural#)
-  @}
-  @if(!isEmpty(teacherOpenCourseQuestionLogAnswer)){
-  and t.teacher_open_course_question_log_answer =#teacherOpenCourseQuestionLogAnswer#
-  @}
-  @if(!isEmpty(teacherOpenCourseQuestionLogUploadFile)){
-  and t.teacher_open_course_question_log_upload_file =#teacherOpenCourseQuestionLogUploadFile#
-  @}
-  @if(!isEmpty(teacherOpenCourseQuestionLogAddTime)){
-  and t.teacher_open_course_question_log_add_time =#teacherOpenCourseQuestionLogAddTime#
-  @}
-  @if(isEmpty(teacherOpenCourseQuestionLogStatus) && isEmpty(teacherOpenCourseQuestionLogStatusPlural)){
-  and t.teacher_open_course_question_log_status != 2
-  @}else{
-  @if(!isEmpty(teacherOpenCourseQuestionLogStatus)){
-  and t.teacher_open_course_question_log_status =#teacherOpenCourseQuestionLogStatus#
-  @}else if(!isEmpty(teacherOpenCourseQuestionLogStatusPlural)){
-  and find_in_set(t.teacher_open_course_question_log_status,#teacherOpenCourseQuestionLogStatusPlural#)
-  @}
-  @}
-  @if(!isEmpty(studentId)){
-  and t.student_id =#studentId#
-  @}
-  @if(!isEmpty(studentIdPlural)){
-  and find_in_set(t.student_id,#studentIdPlural#)
-  @}
-  @if(!isEmpty(studentScore)){
-  and t.student_score =#studentScore#
-  @}
-  @if(!isEmpty(questionType)){
-  and t.question_type =#questionType#
-  @}
-  @if(!isEmpty(questionTypePlural)){
-  and find_in_set(t.question_type,#questionTypePlural#)
-  @}
-  @if(!isEmpty(questionScore)){
-  and t.question_score =#questionScore#
-  @}
-  @if(!isEmpty(questionStem)){
-  and t.question_stem =#questionStem#
-  @}
-  @if(!isEmpty(questionOptionA)){
-  and t.question_option_a =#questionOptionA#
-  @}
-  @if(!isEmpty(questionOptionB)){
-  and t.question_option_b =#questionOptionB#
-  @}
-  @if(!isEmpty(questionOptionC)){
-  and t.question_option_c =#questionOptionC#
-  @}
-  @if(!isEmpty(questionOptionD)){
-  and t.question_option_d =#questionOptionD#
-  @}
-  @if(!isEmpty(questionOptionE)){
-  and t.question_option_e =#questionOptionE#
-  @}
-  @if(!isEmpty(questionAnswer)){
-  and t.question_answer =#questionAnswer#
-  @}
-  @if(!isEmpty(isTuck)){
-  and t.is_tuck =#isTuck#
-  @}
-
-  @if(!isEmpty(teacherOpenCourseQuestionLogUpdateTime)){
-  and t.teacher_open_course_question_log_update_time =#teacherOpenCourseQuestionLogUpdateTime#
-  @}
-  @if(!isEmpty(teacherOpenCourseQuestionLogFinishTime)){
-  and t.teacher_open_course_question_log_finish_time =#teacherOpenCourseQuestionLogFinishTime#
-  @}
-  @if(!isEmpty(isErrorFavorite)){
-  and (t.is_error_favorite =#isErrorFavorite# or t.student_score != t.question_score)
-  @}
-  @if(!isEmpty(questionLogAddType)){
-  and tc.teacher_open_course_question_setting_type =#questionLogAddType#
-  @}
-  @if(!isEmpty(orgId)){
-  and t.org_id =#orgId#
-  @}
-  @if(!isEmpty(orgIdPlural)){
-  and find_in_set(t.org_id,#orgIdPlural#)
-  @}
-  @if(!isEmpty(userId)){
-  and t.user_id =#userId#
-  @}
-  @if(!isEmpty(userIdPlural)){
-  and find_in_set(t.user_id,#userIdPlural#)
-  @}
-  @if(!isEmpty(studentSnOrName)){
-  and (ta.student_sn like #'%'+studentSnOrName+'%'# or ta.student_name like #'%'+studentSnOrName+'%'#)
-  @}
-  @if(!isEmpty(schoolClassIdPlural)){
-  and find_in_set(ta.class_id, #schoolClassIdPlural#)
-  @}
-  @if(!isEmpty(questionLogAddType)){
-  and tc.teacher_open_course_question_setting_type = #questionSettingType#
-  and tc.teacher_open_course_question_setting_status = 1
-  and tc.teacher_open_course_question_setting_push_status = 1
-  @}
-
-  group by 
+    sum( t.student_score ) AS sum_student_score,
+    SUBSTRING_INDEX( GROUP_CONCAT( t.teacher_open_course_question_log_add_time ORDER BY t.teacher_open_course_question_log_add_time DESC ), ',', 1 ) AS add_time
+    FROM
+    teacher_open_course_question_log t
+    LEFT JOIN student ta ON ta.student_id = t.student_id
+    WHERE
+    1 = 1
+    AND t.teacher_open_course_question_log_status != 2
+    AND ta.student_sn IS NOT NULL
+     @if(!isEmpty(teacherOpenCourseQuestionLogId)){
+     and t.teacher_open_course_question_log_id =#teacherOpenCourseQuestionLogId#
+     @}
+     @if(!isEmpty(teacherOpenCourseQuestionLogIdPlural)){
+     and find_in_set(t.teacher_open_course_question_log_id,#teacherOpenCourseQuestionLogIdPlural#)
+     @}
+     @if(!isEmpty(teacherOpenCourseQuestionSettingId)){
+     and t.teacher_open_course_question_setting_id =#teacherOpenCourseQuestionSettingId#
+     @}
+     @if(!isEmpty(teacherOpenCourseQuestionSettingIdPlural)){
+     and find_in_set(t.teacher_open_course_question_setting_id,#teacherOpenCourseQuestionSettingIdPlural#)
+     @}
+     @if(!isEmpty(resourcesQuestionSnapshotId)){
+     and t.resources_question_snapshot_id =#resourcesQuestionSnapshotId#
+     @}
+     @if(!isEmpty(resourcesQuestionSnapshotIdPlural)){
+     and find_in_set(t.resources_question_snapshot_id,#resourcesQuestionSnapshotIdPlural#)
+     @}
+     @if(!isEmpty(teacherOpenCourseQuestionLogAnswer)){
+     and t.teacher_open_course_question_log_answer =#teacherOpenCourseQuestionLogAnswer#
+     @}
+     @if(!isEmpty(teacherOpenCourseQuestionLogUploadFile)){
+     and t.teacher_open_course_question_log_upload_file =#teacherOpenCourseQuestionLogUploadFile#
+     @}
+     @if(!isEmpty(teacherOpenCourseQuestionLogAddTime)){
+     and t.teacher_open_course_question_log_add_time =#teacherOpenCourseQuestionLogAddTime#
+     @}
+     @if(isEmpty(teacherOpenCourseQuestionLogStatus) && isEmpty(teacherOpenCourseQuestionLogStatusPlural)){
+     and t.teacher_open_course_question_log_status != 2
+     @}else{
+     @if(!isEmpty(teacherOpenCourseQuestionLogStatus)){
+     and t.teacher_open_course_question_log_status =#teacherOpenCourseQuestionLogStatus#
+     @}else if(!isEmpty(teacherOpenCourseQuestionLogStatusPlural)){
+     and find_in_set(t.teacher_open_course_question_log_status,#teacherOpenCourseQuestionLogStatusPlural#)
+     @}
+     @}
+     @if(!isEmpty(studentId)){
+     and t.student_id =#studentId#
+     @}
+     @if(!isEmpty(studentIdPlural)){
+     and find_in_set(t.student_id,#studentIdPlural#)
+     @}
+     @if(!isEmpty(studentScore)){
+     and t.student_score =#studentScore#
+     @}
+     @if(!isEmpty(questionType)){
+     and t.question_type =#questionType#
+     @}
+     @if(!isEmpty(questionTypePlural)){
+     and find_in_set(t.question_type,#questionTypePlural#)
+     @}
+     @if(!isEmpty(questionScore)){
+     and t.question_score =#questionScore#
+     @}
+     @if(!isEmpty(questionStem)){
+     and t.question_stem =#questionStem#
+     @}
+     @if(!isEmpty(questionOptionA)){
+     and t.question_option_a =#questionOptionA#
+     @}
+     @if(!isEmpty(questionOptionB)){
+     and t.question_option_b =#questionOptionB#
+     @}
+     @if(!isEmpty(questionOptionC)){
+     and t.question_option_c =#questionOptionC#
+     @}
+     @if(!isEmpty(questionOptionD)){
+     and t.question_option_d =#questionOptionD#
+     @}
+     @if(!isEmpty(questionOptionE)){
+     and t.question_option_e =#questionOptionE#
+     @}
+     @if(!isEmpty(questionAnswer)){
+     and t.question_answer =#questionAnswer#
+     @}
+     @if(!isEmpty(isTuck)){
+     and t.is_tuck =#isTuck#
+     @}
+   
+     @if(!isEmpty(teacherOpenCourseQuestionLogUpdateTime)){
+     and t.teacher_open_course_question_log_update_time =#teacherOpenCourseQuestionLogUpdateTime#
+     @}
+     @if(!isEmpty(teacherOpenCourseQuestionLogFinishTime)){
+     and t.teacher_open_course_question_log_finish_time =#teacherOpenCourseQuestionLogFinishTime#
+     @}
+     @if(!isEmpty(isErrorFavorite)){
+     and (t.is_error_favorite =#isErrorFavorite# or t.student_score != t.question_score)
+     @}
+     @if(!isEmpty(questionLogAddType)){
+     and tc.teacher_open_course_question_setting_type =#questionLogAddType#
+     @}
+     @if(!isEmpty(orgId)){
+     and t.org_id =#orgId#
+     @}
+     @if(!isEmpty(orgIdPlural)){
+     and find_in_set(t.org_id,#orgIdPlural#)
+     @}
+     @if(!isEmpty(userId)){
+     and t.user_id =#userId#
+     @}
+     @if(!isEmpty(userIdPlural)){
+     and find_in_set(t.user_id,#userIdPlural#)
+     @}
+     @if(!isEmpty(studentSnOrName)){
+     and (ta.student_sn like #'%'+studentSnOrName+'%'# or ta.student_name like #'%'+studentSnOrName+'%'#)
+     @}
+     @if(!isEmpty(schoolClassIdPlural)){
+     and find_in_set(ta.class_id, #schoolClassIdPlural#)
+     @}
+     @if(!isEmpty(questionLogAddType)){
+     and tc.teacher_open_course_question_setting_type = #questionSettingType#
+     and tc.teacher_open_course_question_setting_status = 1
+     and tc.teacher_open_course_question_setting_push_status = 1
+     @}
+    GROUP BY
+    t.student_id,
+    ta.student_sn,
+    ta.student_name,
+    t.teacher_open_course_question_setting_id
+    HAVING
+    sum( t.student_score ) IS NOT NULL
+    ) a
+    WHERE
+    NOT EXISTS (
+    SELECT
+    1
+    FROM
+    (
+    SELECT
+    t.student_id,
+    ta.student_sn,
+    sum( t.student_score ) AS sum_student_score
+    FROM
+    teacher_open_course_question_log t
+    LEFT JOIN student ta ON ta.student_id = t.student_id
+    WHERE
+    1 = 1
+    AND t.teacher_open_course_question_log_status != 2
+    AND ta.student_sn IS NOT NULL
+    GROUP BY
     t.student_id,
     ta.student_sn,
     ta.student_name,
     t.teacher_open_course_question_setting_id
+    HAVING
+    sum( t.student_score ) IS NOT NULL
+    ) b
+    WHERE
+    a.student_id = b.student_id
+    AND a.student_sn = b.student_sn
+    AND a.sum_student_score < b.sum_student_score
+    )
+    ORDER BY
+    add_time ASC
   )tz