From 0b9088c509f2a99b5a22b3bdee3b51984e6dbe1e Mon Sep 17 00:00:00 2001 From: Mlxa0324 Date: Sun, 25 Dec 2022 21:10:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=9A=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ibeetl/jlw/dao/GeneralQuestionLogDao.java | 18 ++++ .../dao/TeacherOpenCourseQuestionLogDao.java | 17 ++++ .../jlw/entity/dto/QuestionLogAddDTO.java | 6 +- .../service/GeneralQuestionLogService.java | 83 ++++++++++++++----- .../GeneralQuestionSettingService.java | 10 +-- .../TeacherOpenCourseQuestionLogService.java | 74 ++++++++++++++--- ...acherOpenCourseQuestionSettingService.java | 10 +-- .../resources/sql/jlw/generalQuestionLog.md | 47 ++++++++++- .../jlw/generalResourcesQuestionSnapshot.md | 2 +- .../sql/jlw/resourcesQuestionSnapshot.md | 2 +- .../sql/jlw/teacherOpenCourseQuestionLog.md | 47 ++++++++++- 11 files changed, 269 insertions(+), 47 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 0cac03d6..32425a07 100644 --- a/web/src/main/java/com/ibeetl/jlw/dao/GeneralQuestionLogDao.java +++ b/web/src/main/java/com/ibeetl/jlw/dao/GeneralQuestionLogDao.java @@ -139,5 +139,23 @@ public interface GeneralQuestionLogDao extends BaseMapper { .andEq(GeneralQuestionLog::getGeneralQuestionSettingId, questionSettingId) .select(); } + + /** + * 查询未提交的试卷 + * @param studentId + * @param questionSettingId + * @return + */ + List getNotSubmitQuestionLogs(Long studentId, Long questionSettingId); + + + /** + * 查询未提交试卷的题目数量 + * @param studentId + * @param questionSettingId + * @return + */ + long getNotSubmitQuestionLogsCount(Long studentId, Long questionSettingId); + } 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 13ffc4d4..4d9c3985 100644 --- a/web/src/main/java/com/ibeetl/jlw/dao/TeacherOpenCourseQuestionLogDao.java +++ b/web/src/main/java/com/ibeetl/jlw/dao/TeacherOpenCourseQuestionLogDao.java @@ -143,4 +143,21 @@ public interface TeacherOpenCourseQuestionLogDao extends BaseMapper getNotSubmitQuestionLogs(Long studentId, Long questionSettingId); + + /** + * 查询未提交试卷的题目数量 + * @param studentId + * @param questionSettingId + * @return + */ + long getNotSubmitQuestionLogsCount(Long studentId, Long questionSettingId); + } diff --git a/web/src/main/java/com/ibeetl/jlw/entity/dto/QuestionLogAddDTO.java b/web/src/main/java/com/ibeetl/jlw/entity/dto/QuestionLogAddDTO.java index 38433081..787cf915 100644 --- a/web/src/main/java/com/ibeetl/jlw/entity/dto/QuestionLogAddDTO.java +++ b/web/src/main/java/com/ibeetl/jlw/entity/dto/QuestionLogAddDTO.java @@ -1,6 +1,7 @@ package com.ibeetl.jlw.entity.dto; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.json.JSONUtil; import com.ibeetl.jlw.enums.QuestionLogAddTypeEnum; import lombok.Data; @@ -61,7 +62,10 @@ public class QuestionLogAddDTO { * @return */ public static String answerDistinctSort(@NotEmpty(message = "题目答案不能为空!") String answersText) { - return join(new TreeSet<>(Arrays.asList(answersText.split(","))).toArray(), ","); + if (!JSONUtil.isTypeJSON(answersText)) { + return join(new TreeSet<>(Arrays.asList(answersText.split(","))).toArray(), ","); + } + return answersText; } /** 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 a0c9c0ef..210264e4 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/GeneralQuestionLogService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/GeneralQuestionLogService.java @@ -4,10 +4,8 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.BooleanUtil; -import cn.hutool.core.util.NumberUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.ReUtil; +import cn.hutool.core.util.*; +import cn.hutool.json.JSONUtil; import cn.jlw.util.ToolUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; @@ -582,6 +580,7 @@ public class GeneralQuestionLogService extends CoreBaseService tempList.contains(item.getQuestionLogAddType())).collect(Collectors.toList()); Assert.notEmpty(logList, "未查询到题目信息!"); + // 题目日志IDs汇总 + String logsIds = logList.stream().map(item -> item.getGeneralQuestionLogId().toString()).collect(joining(",")); + // 当前时间, 存储要更新的题目日志集合 Date now = new Date(); List updateList = new ArrayList<>(); + + // 代表填空题和分析题的类型 + List questionType = Arrays.asList(4, 5); // 处理答案和分数 logList.forEach(questionLog -> { // 验证最新的提交时间,防止网络延迟 @@ -623,16 +628,54 @@ public class GeneralQuestionLogService extends CoreBaseService map : questionAnswerArr.entrySet()) { + Object questionAns = map.getValue(); + String k = map.getKey(); + String studentAns = studentAnswerArr.getStr(k, ""); + + // 比对答案 + if (studentAns.equalsIgnoreCase(questionAns.toString()) && StrUtil.isAllNotBlank(questionAns.toString(), studentAns)) { + studentScore.add(eachScore); + } + } + + // 填空题和分析题计算分数 + // 计算该题目学生的得分情况 + questionLog.setStudentScore(studentScore); + // 是否是错题 + questionLog.setIsErrorFavorite(NumberUtil.isLess(studentScore, questionLog.getQuestionScore())); + }else { + answersText = join(answer.split(","), ","); + // 是否是正确答案 + Boolean isCorrectAnswer = questionLog.getQuestionAnswer().equalsIgnoreCase(answersText); + + // 学生得分 + questionLog.setStudentScore(isCorrectAnswer ? questionLog.getQuestionScore() : ZERO); + questionLog.setIsErrorFavorite(!isCorrectAnswer); + } + // 完成时间 long finishSecondTime = DateUtil.between(questionLog.getGeneralQuestionLogAddTime(), now, SECOND); // 填充属性 - // 计算该题目学生的得分情况 - questionLog.setStudentScore(isCorrectAnswer ? questionLog.getQuestionScore() : BigDecimal.valueOf(0)); - questionLog.setIsErrorFavorite(isCorrectAnswer); questionLog.setGeneralQuestionLogUpdateTime(now); questionLog.setGeneralQuestionLogFinishTime(finishSecondTime); questionLog.setGeneralQuestionLogAnswer(answersText); @@ -653,7 +696,7 @@ public class GeneralQuestionLogService extends CoreBaseService * 题目日志信息,分析汇总到某张表里 * - * @param logList 某个questionSettingId对应的题目日志列表 - * @param student 学生 - * @param questionSettingName 题目配置的名称(试卷名称) - * @param fromType 题目配置来源类型 - * @param snapshotFromTypeEnum 题目来源 + * @param logsIds 题目日志IDs保存 + * @param logList 某个questionSettingId对应的题目日志列表 + * @param student 学生 + * @param questionSettingName 题目配置的名称(试卷名称) + * @param fromType 题目配置来源类型 + * @param snapshotFromTypeEnum 题目来源 * @Author: lx * @Date: 2022/12/4 20:16 */ public void addQuestionLogSummary( - @NotEmpty(message = "学生题目日志不能为空!") List logList, + String logsIds, @NotEmpty(message = "学生题目日志不能为空!") List logList, @NotNull Student student, @NotBlank String questionSettingName, @NotNull QuestionBusinessTypeEnum fromType, @NotNull ResourcesQuestionSnapshotFromTypeEnum snapshotFromTypeEnum) { // 构建实体 @@ -790,7 +834,7 @@ public class GeneralQuestionLogService extends CoreBaseService 0) { @@ -884,6 +928,7 @@ public class GeneralQuestionLogService extends CoreBaseService 0, "作答次数设置有误,请联系管理员!"); // 数据库查询该学生已经做过的次数, 这个试卷如果已经交卷的话,就提示用户 - GeneralQuestionLog generalQuestionLog = new GeneralQuestionLog(); - generalQuestionLog.setStudentId(studentId); - generalQuestionLog.setQuestionLogAddType(FINALLY_SUBMIT); - generalQuestionLog.setGeneralQuestionSettingId(generalQuestionSettingId); - long doCount = generalQuestionLogDao.templateCount(generalQuestionLog); + QuestionLogSummary entity = new QuestionLogSummary(); + entity.setPersonId(studentId); + entity.setQuestionSettingType(fromTypeEnum); + entity.setQuestionSettingId(generalQuestionSettingId); + long doCount = questionLogSummaryDao.templateCount(entity); // 断言判断最大作答次数 Assert.isTrue(doCount < generalQuestionSettingSettingDoCount, "已超过最大作答次数!"); } 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 ab7173d4..06c00a63 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionLogService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionLogService.java @@ -5,10 +5,8 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.BooleanUtil; -import cn.hutool.core.util.NumberUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.ReUtil; +import cn.hutool.core.util.*; +import cn.hutool.json.JSONUtil; import cn.jlw.util.ToolUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; @@ -412,6 +410,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService tempList.contains(item.getQuestionLogAddType())).collect(Collectors.toList()); Assert.notEmpty(logList, "未查询到题目信息!"); + // 题目日志IDs汇总 + String logsIds = logList.stream().map(item -> item.getTeacherOpenCourseQuestionLogId().toString()).collect(joining(",")); // 当前时间, 存储要更新的题目日志集合 Date now = new Date(); List updateList = new ArrayList<>(); + // 代表填空题和分析题的类型 + List questionType = Arrays.asList(4, 5); // 处理答案和分数 logList.forEach(questionLog -> { // 验证最新的提交时间,防止网络延迟 @@ -454,7 +457,50 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService map : questionAnswerArr.entrySet()) { + Object questionAns = map.getValue(); + String k = map.getKey(); + String studentAns = studentAnswerArr.getStr(k, ""); + + // 比对答案 + if (studentAns.equalsIgnoreCase(questionAns.toString()) && StrUtil.isAllNotBlank(questionAns.toString(), studentAns)) { + studentScore.add(eachScore); + } + } + + // 填空题和分析题计算分数 + // 计算该题目学生的得分情况 + questionLog.setStudentScore(studentScore); + // 是否是错题 + questionLog.setIsErrorFavorite(NumberUtil.isLess(studentScore, questionLog.getQuestionScore())); + }else { + answersText = join(answer.split(","), ","); + // 是否是正确答案 + Boolean isCorrectAnswer = questionLog.getQuestionAnswer().equalsIgnoreCase(answersText); + + // 学生得分 + questionLog.setStudentScore(isCorrectAnswer ? questionLog.getQuestionScore() : ZERO); + questionLog.setIsErrorFavorite(!isCorrectAnswer); + } + // 完成时间,从生成试卷时候,开始计算 long finishSecondTime = DateUtil.between(questionLog.getTeacherOpenCourseQuestionLogAddTime(), now, SECOND); @@ -478,7 +524,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService * 题目日志信息,分析汇总到某张表里 * - * @param logList 某个questionSettingId对应的题目日志列表 - * @param student 学生 - * @param questionSettingName 题目配置的名称(试卷名称) - * @param snapshotFromTypeEnum 题目来源 + * @param logsIds 题目日志IDs保存 + * @param logList 某个questionSettingId对应的题目日志列表 + * @param student 学生 + * @param questionSettingName 题目配置的名称(试卷名称) + * @param snapshotFromTypeEnum 题目来源 * @Author: lx * @Date: 2022/12/4 20:16 */ public void addQuestionLogSummary( - @NotEmpty(message = "学生题目日志不能为空!") List logList, + String logsIds, @NotEmpty(message = "学生题目日志不能为空!") List logList, @NotNull Student student, @NotBlank String questionSettingName, @NotNull ResourcesQuestionSnapshotFromTypeEnum snapshotFromTypeEnum) { // 构建实体 final QuestionLogSummary questionLogSummary = new QuestionLogSummary(); @@ -618,7 +665,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService 0) { diff --git a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionSettingService.java b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionSettingService.java index cfef77bd..6449ea75 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionSettingService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseQuestionSettingService.java @@ -752,11 +752,11 @@ public class TeacherOpenCourseQuestionSettingService extends CoreBaseService 0, "作答次数设置有误,请联系管理员!"); // 数据库查询该学生已经做过的次数, 这个试卷如果已经交卷的话,就提示用户 - TeacherOpenCourseQuestionLog teacherOpenCourseQuestionLog = new TeacherOpenCourseQuestionLog(); - teacherOpenCourseQuestionLog.setStudentId(studentId); - teacherOpenCourseQuestionLog.setQuestionLogAddType(FINALLY_SUBMIT); - teacherOpenCourseQuestionLog.setTeacherOpenCourseQuestionSettingId(teacherOpenCourseQuestionSettingId); - long doCount = teacherOpenCourseQuestionLogDao.templateCount(teacherOpenCourseQuestionLog); + QuestionLogSummary entity = new QuestionLogSummary(); + entity.setPersonId(studentId); + entity.setQuestionSettingType(fromTypeEnum); + entity.setQuestionSettingId(teacherOpenCourseQuestionSettingId); + long doCount = questionLogSummaryDao.templateCount(entity); // 断言判断最大作答次数 Assert.isTrue(doCount < teacherOpenCourseQuestionSettingSettingDoCount, "已超过最大作答次数!"); } diff --git a/web/src/main/resources/sql/jlw/generalQuestionLog.md b/web/src/main/resources/sql/jlw/generalQuestionLog.md index 5db7602c..883d0424 100644 --- a/web/src/main/resources/sql/jlw/generalQuestionLog.md +++ b/web/src/main/resources/sql/jlw/generalQuestionLog.md @@ -1255,4 +1255,49 @@ verifyLogAddTypeIsReSend AND ta.general_question_log_status = 1 AND ta.student_id = #studentId# AND ta.question_log_add_type = #questionLogAddType# - LIMIT 1 \ No newline at end of file + LIMIT 1 + + +getNotSubmitQuestionLogs +=== +* 查询未提交的试卷 + + SELECT + * + FROM + general_question_log t + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + question_log_summary ta + WHERE + ta.person_id = #studentId# + AND ta.question_setting_id = #questionSettingId# + AND FIND_IN_SET( t.general_question_log_id, ta.question_log_ids ) + ) + AND t.student_id = #studentId# + AND t.general_question_setting_id = #questionSettingId# + +getNotSubmitQuestionLogsCount +=== +* 查询未提交试卷的题目数量 + + SELECT + count(1) + FROM + general_question_log t + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + question_log_summary ta + WHERE + ta.person_id = #studentId# + AND ta.question_setting_id = #questionSettingId# + AND FIND_IN_SET( t.general_question_log_id, ta.question_log_ids ) + ) + AND t.student_id = #studentId# + AND t.general_question_setting_id = #questionSettingId# \ No newline at end of file diff --git a/web/src/main/resources/sql/jlw/generalResourcesQuestionSnapshot.md b/web/src/main/resources/sql/jlw/generalResourcesQuestionSnapshot.md index c2ff4ce8..6f36d686 100644 --- a/web/src/main/resources/sql/jlw/generalResourcesQuestionSnapshot.md +++ b/web/src/main/resources/sql/jlw/generalResourcesQuestionSnapshot.md @@ -471,7 +471,7 @@ selectStudentAnswerFragment from general_question_log b where 1 = 1 and b.student_id = #studentId# and b.general_question_log_status = 1 - and find_in_set(b.question_log_add_type, 'LOCK,FINALLY_SUBMIT') + and b.question_log_add_type != 'FINALLY_SUBMIT' and b.general_question_setting_id = t.general_question_setting_id and b.general_resources_question_snapshot_id = t.general_resources_question_snapshot_id order by general_question_log_add_time desc limit 1 diff --git a/web/src/main/resources/sql/jlw/resourcesQuestionSnapshot.md b/web/src/main/resources/sql/jlw/resourcesQuestionSnapshot.md index 07f8cf6f..3041ba31 100644 --- a/web/src/main/resources/sql/jlw/resourcesQuestionSnapshot.md +++ b/web/src/main/resources/sql/jlw/resourcesQuestionSnapshot.md @@ -486,7 +486,7 @@ selectStudentAnswerFragment from teacher_open_course_question_log b where 1 = 1 and b.student_id = #studentId# and b.teacher_open_course_question_log_status = 1 - @// and find_in_set(b.question_log_add_type, 'LOCK,FINALLY_SUBMIT') + and b.question_log_add_type != 'FINALLY_SUBMIT' and b.teacher_open_course_question_setting_id = t.teacher_open_course_question_setting_id and b.resources_question_snapshot_id = t.resources_question_snapshot_id order by teacher_open_course_question_log_add_time desc limit 1 diff --git a/web/src/main/resources/sql/jlw/teacherOpenCourseQuestionLog.md b/web/src/main/resources/sql/jlw/teacherOpenCourseQuestionLog.md index b90a704a..a809c0b0 100644 --- a/web/src/main/resources/sql/jlw/teacherOpenCourseQuestionLog.md +++ b/web/src/main/resources/sql/jlw/teacherOpenCourseQuestionLog.md @@ -935,4 +935,49 @@ verifyLogAddTypeIsReSend AND ta.teacher_open_course_question_log_status = 1 AND ta.student_id = #studentId# AND ta.question_log_add_type = #questionLogAddType# - LIMIT 1 \ No newline at end of file + LIMIT 1 + + +getNotSubmitQuestionLogs +=== +* 查询未提交的试卷 + + SELECT + * + FROM + teacher_open_course_question_log t + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + question_log_summary ta + WHERE + ta.person_id = #studentId# + AND ta.question_setting_id = #questionSettingId# + AND FIND_IN_SET( t.teacher_open_course_question_log_id, ta.question_log_ids ) + ) + AND t.student_id = #studentId# + AND t.teacher_open_course_question_setting_id = #questionSettingId# + +getNotSubmitQuestionLogsCount +=== +* 查询未提交试卷的题目数量 + + SELECT + count(1) + FROM + teacher_open_course_question_log t + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + question_log_summary ta + WHERE + ta.person_id = #studentId# + AND ta.question_setting_id = #questionSettingId# + AND FIND_IN_SET( t.teacher_open_course_question_log_id, ta.question_log_ids ) + ) + AND t.student_id = #studentId# + AND t.teacher_open_course_question_setting_id = #questionSettingId# \ No newline at end of file