fix: 考试分析-最难题目SQL在不选班级时缺少空格导致语法错误,点分析报错

fix/exam-question-access-material-excel-delete-draft
chenyuan 5 days ago
parent 8d7a4fdaab
commit 61b3c169a9

@ -433,14 +433,7 @@ public class ExamService {
bucket("良好", scores, total.multiply(new BigDecimal("0.80")), total.multiply(new BigDecimal("0.90"))), bucket("良好", scores, total.multiply(new BigDecimal("0.80")), total.multiply(new BigDecimal("0.90"))),
bucket("及格", scores, pass, total.multiply(new BigDecimal("0.80"))), bucket("及格", scores, pass, total.multiply(new BigDecimal("0.80"))),
bucket("不及格", scores, BigDecimal.ZERO, pass)); bucket("不及格", scores, BigDecimal.ZERO, pass));
String hardestSql = "select p.question_id id,p.stem,p.question_score, count(distinct t.id) student_count, " + String hardestSql = analysisHardestSql(StringUtils.isNotBlank(classId));
"sum(case when coalesce(a.awarded_score,0) < p.question_score then 1 else 0 end) wrong_count, " +
"coalesce(sum(coalesce(a.awarded_score,0)),0) earned_score " +
"from exam_assessment_question p join exam_attempt t on t.exam_id=p.exam_id and t.attempt_status='SUBMITTED' " +
"left join exam_attempt_answer a on a.attempt_id=t.id and a.question_id=p.question_id " +
"where p.exam_id=?" + (StringUtils.isBlank(classId) ? "" : " and t.teaching_class_id=? ") +
"group by p.question_id,p.stem,p.question_score " +
"order by (case when count(distinct t.id)=0 then 100 else coalesce(sum(coalesce(a.awarded_score,0)),0) * 100.0 / (count(distinct t.id) * p.question_score) end) asc, wrong_count desc limit 3";
List<Map<String, Object>> hardest = jdbc.query(hardestSql, List<Map<String, Object>> hardest = jdbc.query(hardestSql,
(rs, n) -> { (rs, n) -> {
int students = rs.getInt("student_count"); int students = rs.getInt("student_count");
@ -754,6 +747,17 @@ public class ExamService {
if (!expected.equals(actual)) throw new IllegalArgumentException(message); if (!expected.equals(actual)) throw new IllegalArgumentException(message);
} }
static String analysisHardestSql(boolean withClassFilter) {
return "select p.question_id id,p.stem,p.question_score, count(distinct t.id) student_count, " +
"sum(case when coalesce(a.awarded_score,0) < p.question_score then 1 else 0 end) wrong_count, " +
"coalesce(sum(coalesce(a.awarded_score,0)),0) earned_score " +
"from exam_assessment_question p join exam_attempt t on t.exam_id=p.exam_id and t.attempt_status='SUBMITTED' " +
"left join exam_attempt_answer a on a.attempt_id=t.id and a.question_id=p.question_id " +
"where p.exam_id=? " + (withClassFilter ? "and t.teaching_class_id=? " : "") +
"group by p.question_id,p.stem,p.question_score " +
"order by (case when count(distinct t.id)=0 then 100 else coalesce(sum(coalesce(a.awarded_score,0)),0) * 100.0 / (count(distinct t.id) * p.question_score) end) asc, wrong_count desc limit 3";
}
static void validateDelete(String status, Object exportedAt) { static void validateDelete(String status, Object exportedAt) {
if ("DRAFT".equals(status)) return; if ("DRAFT".equals(status)) return;
requireState(status, "ENDED", "只有未发布或已结束的考试可以删除"); requireState(status, "ENDED", "只有未发布或已结束的考试可以删除");

@ -58,6 +58,15 @@ class ExamServiceTest {
} }
} }
@Test
void analysisHardestSqlKeepsParameterAndGroupBySeparated() {
for (String sql : Arrays.asList(ExamService.analysisHardestSql(false), ExamService.analysisHardestSql(true))) {
assertFalse(sql.contains("?group"));
assertTrue(sql.contains("? group by p.question_id"));
}
assertTrue(ExamService.analysisHardestSql(true).contains("? and t.teaching_class_id=? group by"));
}
@Test @Test
void studentAnswerFilesStillRejectExcel() { void studentAnswerFilesStillRejectExcel() {
IllegalArgumentException error = assertThrows(IllegalArgumentException.class, IllegalArgumentException error = assertThrows(IllegalArgumentException.class,

Loading…
Cancel
Save