题目作答

beetlsql3-dev
Mlxa0324 2 years ago
parent 593d2d7d6a
commit f897ce9b5c

@ -56,7 +56,6 @@ import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.hutool.core.date.DateUnit.SECOND; import static cn.hutool.core.date.DateUnit.SECOND;
import static cn.hutool.core.util.ArrayUtil.isAllNotEmpty;
import static cn.hutool.core.util.ArrayUtil.join; import static cn.hutool.core.util.ArrayUtil.join;
import static cn.hutool.core.util.ObjectUtil.defaultIfNull; import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
import static cn.jlw.util.CacheUserUtil.getStudent; import static cn.jlw.util.CacheUserUtil.getStudent;
@ -64,8 +63,6 @@ import static com.ibeetl.admin.core.util.ExcelUtil.getCellFormatValue;
import static com.ibeetl.admin.core.util.StreamUtils.listJoin; import static com.ibeetl.admin.core.util.StreamUtils.listJoin;
import static com.ibeetl.jlw.enums.QuestionLogAddTypeEnum.*; import static com.ibeetl.jlw.enums.QuestionLogAddTypeEnum.*;
import static com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum.CHAPTER_EXERCISE; import static com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum.CHAPTER_EXERCISE;
import static com.ibeetl.jlw.enums.ResourcesQuestionTypeEnum.isOneQuestion;
import static java.lang.Math.abs;
import static java.lang.Math.toIntExact; import static java.lang.Math.toIntExact;
import static java.math.BigDecimal.ZERO; import static java.math.BigDecimal.ZERO;
import static java.util.stream.Collectors.groupingBy; import static java.util.stream.Collectors.groupingBy;
@ -662,7 +659,7 @@ public class GeneralQuestionLogService extends CoreBaseService<GeneralQuestionLo
// 比对答案 // 比对答案
if (studentAns.equalsIgnoreCase(questionAns.toString()) && StrUtil.isAllNotBlank(questionAns.toString(), studentAns)) { if (studentAns.equalsIgnoreCase(questionAns.toString()) && StrUtil.isAllNotBlank(questionAns.toString(), studentAns)) {
studentScore.add(eachScore); studentScore = studentScore.add(eachScore);
} }
} }
@ -670,7 +667,7 @@ public class GeneralQuestionLogService extends CoreBaseService<GeneralQuestionLo
// 计算该题目学生的得分情况 // 计算该题目学生的得分情况
questionLog.setStudentScore(studentScore); questionLog.setStudentScore(studentScore);
// 是否是错题 // 是否是错题
questionLog.setIsErrorFavorite(NumberUtil.isLess(studentScore, questionLog.getQuestionScore())); questionLog.setIsErrorFavorite(NumberUtil.equals(studentScore, ZERO));
}else { }else {
answersText = join(answer.split(","), ","); answersText = join(answer.split(","), ",");
// 是否是正确答案 // 是否是正确答案
@ -701,7 +698,7 @@ public class GeneralQuestionLogService extends CoreBaseService<GeneralQuestionLo
// 最后提交试卷答案时候,才会记录错题 // 最后提交试卷答案时候,才会记录错题
if (addType.equals(FINALLY_SUBMIT)) { if (addType.equals(FINALLY_SUBMIT)) {
// 计算学生分数,并标记错题 // 计算学生分数,并标记错题
calculateScoreOnSubmit(updateList); // calculateScoreOnSubmit(updateList);
// 学生做的题目的答案与日志关联 // 学生做的题目的答案与日志关联
updateBatchTemplate(updateList); updateBatchTemplate(updateList);
// 添加到题目日志汇总中 // 添加到题目日志汇总中
@ -720,75 +717,75 @@ public class GeneralQuestionLogService extends CoreBaseService<GeneralQuestionLo
* @Author: lx * @Author: lx
* @Date: 2022/12/4 20:16 * @Date: 2022/12/4 20:16
*/ */
public void calculateScoreOnSubmit(@NotEmpty(message = "学生题目日志不能为空!") List<GeneralQuestionLog> logList) { // public void calculateScoreOnSubmit(@NotEmpty(message = "学生题目日志不能为空!") List<GeneralQuestionLog> logList) {
logList.forEach(questionLog -> { // logList.forEach(questionLog -> {
// 题目原本设置的分数 // // 题目原本设置的分数
final BigDecimal questionScore = questionLog.getQuestionScore(); // final BigDecimal questionScore = questionLog.getQuestionScore();
// 学生提交的结果 // // 学生提交的结果
final String studentAnswer = defaultIfNull(questionLog.getGeneralQuestionLogAnswer(), ""); // final String studentAnswer = defaultIfNull(questionLog.getGeneralQuestionLogAnswer(), "");
// 题目的答案 // // 题目的答案
final String questionAnswer = defaultIfNull(questionLog.getQuestionAnswer(), ""); // final String questionAnswer = defaultIfNull(questionLog.getQuestionAnswer(), "");
// 判断答案和学生提交的结果,都不能为空 // // 判断答案和学生提交的结果,都不能为空
final boolean allNotEmpty = isAllNotEmpty(questionAnswer, studentAnswer); // final boolean allNotEmpty = isAllNotEmpty(questionAnswer, studentAnswer);
// 题目类型,答案属于一道题 // // 题目类型,答案属于一道题
final boolean oneQuestion = isOneQuestion(questionLog.getQuestionType()); // final boolean oneQuestion = isOneQuestion(questionLog.getQuestionType());
//
// 一条日志记录,属于一道题 // // 一条日志记录,属于一道题
if (oneQuestion) { // if (oneQuestion) {
boolean isTrue = allNotEmpty && studentAnswer.equalsIgnoreCase(questionAnswer); // boolean isTrue = allNotEmpty && studentAnswer.equalsIgnoreCase(questionAnswer);
final BigDecimal mySimpleScore = isTrue ? questionScore: ZERO; // final BigDecimal mySimpleScore = isTrue ? questionScore: ZERO;
// 计算学生最后的得分 // // 计算学生最后的得分
questionLog.setStudentScore(mySimpleScore); // questionLog.setStudentScore(mySimpleScore);
//
if (isTrue) { // if (isTrue) {
questionLog.setSuccessCount(1); // questionLog.setSuccessCount(1);
} // }
else { // else {
questionLog.setErrorCount(1); // questionLog.setErrorCount(1);
} // }
// 错题标记 // // 错题标记
questionLog.setIsErrorFavorite(!isTrue); // questionLog.setIsErrorFavorite(!isTrue);
} // }
//
// 一条日志记录,属于多道题的逻辑处理 // // 一条日志记录,属于多道题的逻辑处理
else { // else {
// 分数,正确数量 // // 分数,正确数量
BigDecimal score = ZERO; int successCount = 0; // BigDecimal score = ZERO; int successCount = 0;
// 学生提交的题目结果 // // 学生提交的题目结果
final String[] studentAnswerArr = studentAnswer.split(","); // final String[] studentAnswerArr = studentAnswer.split(",");
// 正确答案和学生答案对比 // // 正确答案和学生答案对比
//
String[] successAnswerArr = questionAnswer.split(","); // String[] successAnswerArr = questionAnswer.split(",");
final int studentAnswerLength = studentAnswerArr.length; // final int studentAnswerLength = studentAnswerArr.length;
final int questionLength = successAnswerArr.length; // final int questionLength = successAnswerArr.length;
// 断言需要判断,题目答案的数量是否相等,不然会对不上答案,导致分数计算错误 // // 断言需要判断,题目答案的数量是否相等,不然会对不上答案,导致分数计算错误
// Assert.isTrue(studentAnswerLength == questionLength, "题干:" + questionLog.getQuestionStem()+ ",有选项未提交!"); //// Assert.isTrue(studentAnswerLength == questionLength, "题干:" + questionLog.getQuestionStem()+ ",有选项未提交!");
//
// 一道题的分数 // // 一道题的分数
BigDecimal simpleQuestionScore = NumberUtil.mul(questionScore, questionLength); // BigDecimal simpleQuestionScore = NumberUtil.div(questionScore, questionLength);
// 循环比对这个题目,是否是复杂的题目:如选词填空或者分析题 // // 循环比对这个题目,是否是复杂的题目:如选词填空或者分析题
for (int i = 0; i < questionLength; i++) { // for (int i = 0; i < questionLength; i++) {
String sqs = successAnswerArr[i]; // String sqs = successAnswerArr[i];
boolean isTrue = allNotEmpty && sqs.equalsIgnoreCase(studentAnswerArr[i]); // boolean isTrue = allNotEmpty && sqs.equalsIgnoreCase(studentAnswerArr[i]);
BigDecimal oneScore = isTrue ? simpleQuestionScore : ZERO; // BigDecimal oneScore = isTrue ? simpleQuestionScore : ZERO;
score = score.add(oneScore); // score = score.add(oneScore);
//
// 正确的数量计数 // // 正确的数量计数
if (isTrue) { // if (isTrue) {
successCount++; // successCount++;
} // }
} // }
// 全对的题目,才算做正确答案 // // 全对的题目,才算做正确答案
final boolean isAllTrue = successCount == questionLength; // final boolean isAllTrue = successCount == questionLength;
// 计算学生最后的得分 // // 计算学生最后的得分
questionLog.setStudentScore(score); // questionLog.setStudentScore(score);
questionLog.setSuccessCount(successCount); // questionLog.setSuccessCount(successCount);
questionLog.setErrorCount(abs(questionLength - successCount)); // questionLog.setErrorCount(abs(questionLength - successCount));
// 错题标记 // // 错题标记
questionLog.setIsErrorFavorite(!isAllTrue); // questionLog.setIsErrorFavorite(!isAllTrue);
} // }
}); // });
} // }
/** /**

@ -53,7 +53,6 @@ import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.hutool.core.date.DateUnit.SECOND; import static cn.hutool.core.date.DateUnit.SECOND;
import static cn.hutool.core.util.ArrayUtil.isAllNotEmpty;
import static cn.hutool.core.util.ArrayUtil.join; import static cn.hutool.core.util.ArrayUtil.join;
import static cn.hutool.core.util.ObjectUtil.defaultIfNull; import static cn.hutool.core.util.ObjectUtil.defaultIfNull;
import static cn.jlw.util.CacheUserUtil.getStudent; import static cn.jlw.util.CacheUserUtil.getStudent;
@ -63,8 +62,6 @@ import static com.ibeetl.jlw.enums.QuestionBusinessTypeEnum.FROM_OPEN_COURSE;
import static com.ibeetl.jlw.enums.QuestionLogAddTypeEnum.*; import static com.ibeetl.jlw.enums.QuestionLogAddTypeEnum.*;
import static com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum.CHAPTER_EXERCISE; import static com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum.CHAPTER_EXERCISE;
import static com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum.HOMEWORK_FILE; import static com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum.HOMEWORK_FILE;
import static com.ibeetl.jlw.enums.ResourcesQuestionTypeEnum.isOneQuestion;
import static java.lang.Math.abs;
import static java.lang.Math.toIntExact; import static java.lang.Math.toIntExact;
import static java.math.BigDecimal.ZERO; import static java.math.BigDecimal.ZERO;
import static java.util.stream.Collectors.groupingBy; import static java.util.stream.Collectors.groupingBy;
@ -516,7 +513,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
// 比对答案 // 比对答案
if ( StrUtil.isAllNotBlank(questionAns.toString(), studentAns) && questionAns.toString().equalsIgnoreCase(studentAns)) { if ( StrUtil.isAllNotBlank(questionAns.toString(), studentAns) && questionAns.toString().equalsIgnoreCase(studentAns)) {
studentScore.add(eachScore); studentScore = studentScore.add(eachScore);
} }
} }
@ -524,7 +521,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
// 计算该题目学生的得分情况 // 计算该题目学生的得分情况
questionLog.setStudentScore(studentScore); questionLog.setStudentScore(studentScore);
// 是否是错题 // 是否是错题
questionLog.setIsErrorFavorite(NumberUtil.isLess(studentScore, questionLog.getQuestionScore())); questionLog.setIsErrorFavorite(NumberUtil.equals(studentScore, ZERO));
}else { }else {
answersText = join(answer.split(","), ","); answersText = join(answer.split(","), ",");
// 是否是正确答案 // 是否是正确答案
@ -555,7 +552,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
// 最后提交试卷答案时候,才会记录错题 // 最后提交试卷答案时候,才会记录错题
if (addType.equals(FINALLY_SUBMIT)) { if (addType.equals(FINALLY_SUBMIT)) {
// 计算学生分数,并标记错题 // 计算学生分数,并标记错题
calculateScoreOnSubmit(updateList); // calculateScoreOnSubmit(updateList);
updateBatchTemplate(updateList); updateBatchTemplate(updateList);
// 添加到题目日志汇总中 // 添加到题目日志汇总中
addQuestionLogSummary(student, questionSettingId, updateList); addQuestionLogSummary(student, questionSettingId, updateList);
@ -568,86 +565,86 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
} }
/** // /**
* : <br> // * 功能描述: <br>
* // * 计算学生分数
* // * 会判断题目是否打完,并抛出异常
* // *
* @param logList // * @param logList
* @Author: lx // * @Author: lx
* @Date: 2022/12/4 20:16 // * @Date: 2022/12/4 20:16
*/ // */
public void calculateScoreOnSubmit(@NotEmpty(message = "学生题目日志不能为空!") List<TeacherOpenCourseQuestionLog> logList) { // public void calculateScoreOnSubmit(@NotEmpty(message = "学生题目日志不能为空!") List<TeacherOpenCourseQuestionLog> logList) {
logList.forEach(questionLog -> { // logList.forEach(questionLog -> {
// 题目原本设置的分数 // // 题目原本设置的分数
final BigDecimal questionScore = questionLog.getQuestionScore(); // final BigDecimal questionScore = questionLog.getQuestionScore();
// 题目类型 // // 题目类型
final Integer questionType = questionLog.getQuestionType(); // final Integer questionType = questionLog.getQuestionType();
// 学生提交的结果 // // 学生提交的结果
final String studentAnswer = defaultIfNull(questionLog.getTeacherOpenCourseQuestionLogAnswer(), ""); // final String studentAnswer = defaultIfNull(questionLog.getTeacherOpenCourseQuestionLogAnswer(), "");
// 题目的答案 // // 题目的答案
final String questionAnswer = defaultIfNull(questionLog.getQuestionAnswer(), ""); // final String questionAnswer = defaultIfNull(questionLog.getQuestionAnswer(), "");
// 判断答案和学生提交的结果,都不能为空 // // 判断答案和学生提交的结果,都不能为空
final boolean allNotEmpty = isAllNotEmpty(questionAnswer, studentAnswer); // final boolean allNotEmpty = isAllNotEmpty(questionAnswer, studentAnswer);
// 题目类型,答案属于一道题 // // 题目类型,答案属于一道题
final boolean oneQuestion = isOneQuestion(questionType); // final boolean oneQuestion = isOneQuestion(questionType);
//
// 一条日志记录,属于一道题 // // 一条日志记录,属于一道题
if (oneQuestion) { // if (oneQuestion) {
final boolean isTrue = allNotEmpty && studentAnswer.equalsIgnoreCase(questionAnswer); // final boolean isTrue = allNotEmpty && studentAnswer.equalsIgnoreCase(questionAnswer);
final BigDecimal mySimpleScore = isTrue ? questionScore: ZERO; // final BigDecimal mySimpleScore = isTrue ? questionScore: ZERO;
// 计算学生最后的得分 // // 计算学生最后的得分
questionLog.setStudentScore(mySimpleScore); // questionLog.setStudentScore(mySimpleScore);
//
if (isTrue) { // if (isTrue) {
questionLog.setSuccessCount(1); // questionLog.setSuccessCount(1);
} // }
else { // else {
questionLog.setErrorCount(1); // questionLog.setErrorCount(1);
} // }
// 错题标记 // // 错题标记
questionLog.setIsErrorFavorite(!isTrue); // questionLog.setIsErrorFavorite(!isTrue);
} // }
//
// 一条日志记录,属于多道题的逻辑处理 // // 一条日志记录,属于多道题的逻辑处理
else { // else {
// 分数,正确数量 // // 分数,正确数量
BigDecimal score = ZERO; int successCount = 0; // BigDecimal score = ZERO; int successCount = 0;
// 学生提交的题目结果 // // 学生提交的题目结果
final String[] studentAnswerArr = studentAnswer.split(","); // final String[] studentAnswerArr = studentAnswer.split(",");
// 正确答案和学生答案对比 // // 正确答案和学生答案对比
//
String[] successAnswerArr = questionAnswer.split(","); // String[] successAnswerArr = questionAnswer.split(",");
final int studentAnswerLength = studentAnswerArr.length; // final int studentAnswerLength = studentAnswerArr.length;
final int questionLength = successAnswerArr.length; // final int questionLength = successAnswerArr.length;
// 断言需要判断,题目答案的数量是否相等,不然会对不上答案,导致分数计算错误 // // 断言需要判断,题目答案的数量是否相等,不然会对不上答案,导致分数计算错误
// Assert.isTrue(studentAnswerLength == questionLength, "题干:" + questionLog.getQuestionStem()+ ",有选项未提交!"); //// Assert.isTrue(studentAnswerLength == questionLength, "题干:" + questionLog.getQuestionStem()+ ",有选项未提交!");
//
// 一道题的分数 // // 一道题的分数
BigDecimal simpleQuestionScore = NumberUtil.mul(questionScore, questionLength); // BigDecimal simpleQuestionScore = NumberUtil.div(questionScore, questionLength);
// 循环比对这个题目,是否是复杂的题目:如选词填空或者分析题 // // 循环比对这个题目,是否是复杂的题目:如选词填空或者分析题
for (int i = 0; i < questionLength; i++) { // for (int i = 0; i < questionLength; i++) {
String sqs = successAnswerArr[i]; // String sqs = successAnswerArr[i];
boolean isTrue = allNotEmpty && sqs.equalsIgnoreCase(studentAnswerArr[i]); // boolean isTrue = allNotEmpty && sqs.equalsIgnoreCase(studentAnswerArr[i]);
BigDecimal oneScore = isTrue ? simpleQuestionScore : ZERO; // BigDecimal oneScore = isTrue ? simpleQuestionScore : ZERO;
score = score.add(oneScore); // score = score.add(oneScore);
//
// 正确的数量计数 // // 正确的数量计数
if (isTrue) { // if (isTrue) {
successCount++; // successCount++;
} // }
} // }
// 全对的题目,才算做正确答案 // // 全对的题目,才算做正确答案
final boolean isAllTrue = successCount == questionLength; // final boolean isAllTrue = successCount == questionLength;
// 计算学生最后的得分 // // 计算学生最后的得分
questionLog.setStudentScore(score); // questionLog.setStudentScore(score);
questionLog.setSuccessCount(successCount); // questionLog.setSuccessCount(successCount);
questionLog.setErrorCount(abs(questionLength - successCount)); // questionLog.setErrorCount(abs(questionLength - successCount));
// 错题标记 // // 错题标记
questionLog.setIsErrorFavorite(!isAllTrue); // questionLog.setIsErrorFavorite(!isAllTrue);
} // }
}); // });
} // }
/** /**

@ -180,7 +180,7 @@ queryByConditionQuery
and t.teacher_open_course_question_log_add_time =#teacherOpenCourseQuestionLogAddTime# and t.teacher_open_course_question_log_add_time =#teacherOpenCourseQuestionLogAddTime#
@} @}
@if(isEmpty(teacherOpenCourseQuestionLogStatus) && isEmpty(teacherOpenCourseQuestionLogStatusPlural)){ @if(isEmpty(teacherOpenCourseQuestionLogStatus) && isEmpty(teacherOpenCourseQuestionLogStatusPlural)){
and t.teacher_open_course_question_log_status != 2 @// and t.teacher_open_course_question_log_status != 2
@}else{ @}else{
@if(!isEmpty(teacherOpenCourseQuestionLogStatus)){ @if(!isEmpty(teacherOpenCourseQuestionLogStatus)){
and t.teacher_open_course_question_log_status =#teacherOpenCourseQuestionLogStatus# and t.teacher_open_course_question_log_status =#teacherOpenCourseQuestionLogStatus#

Loading…
Cancel
Save