feat(enlish-service): 新增自动判卷功能及学生单词记忆管理模块

- 支持数据库多语句查询,修改数据源连接配置增加allowMultiQueries参数
- 添加定时任务AutoJudgeExamWordsTask,实现每5秒自动触发判卷
- 增加ExamWordsJudge接口及其实现类ExamWordsJudgeImpl,完成考试判卷逻辑
- 新增多张数据库映射文件及对应Mapper,如ExamWordsDOMapper、ExamWordsJudgeResultDOMapper、StudentExamWordsDOMapper和WordMasteryLogDOMapper,支持相关数据操作
- 扩展PngUtil工具类,支持从答题卡图片中解析学生考试信息和识别未记忆单词
- 修改数据库表结构映射,新增word_mastery_log表和相关字段,管理学生单词记忆强度及复习次数
- 配置@EnableScheduling以启用定时任务调度功能
- 增加测试用例包括ExamWordsJudgeTest和WordMasteryLogInsertTest,验证判卷和学生单词记忆初始化功能
- 重命名测试类TestInsert为TestVocabularyBankInsert,提升代码语义清晰度
This commit is contained in:
lbw
2025-12-14 11:30:26 +08:00
parent a5b23057d3
commit 1002eaf591
22 changed files with 320 additions and 18 deletions

View File

@@ -2,7 +2,7 @@ spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver # 指定数据库驱动类
# 数据库连接信息
url: jdbc:mysql://124.220.58.5:3306/enlish
url: jdbc:mysql://124.220.58.5:3306/enlish?allowMultiQueries=true
username: root # 数据库用户名
password: YLHP@admin123 # 数据库密码
data:

View File

@@ -45,7 +45,7 @@
targetProject="src/main/java"/>
<!-- 需要生成的表-实体类 -->
<table tableName="exam_words_judge_result" domainObjectName="ExamWordsJudgeResultDO"
<table tableName="word_mastery_log" domainObjectName="WordMasteryLogDO"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"

View File

@@ -17,5 +17,9 @@
VALUES (#{gradeId}, #{level}, #{title}, #{wordIds, typeHandler=com.yinlihupo.enlish.service.config.ListWordIdTypeHandler}, #{createdAt})
</insert>
<select id="selectById" resultMap="ResultMapWithBLOBs">
select * from exam_words where id = #{id}
</select>
</mapper>

View File

@@ -19,11 +19,36 @@
<result column="wrong_word_ids" jdbcType="LONGVARCHAR" property="wrongWordIds" typeHandler="com.yinlihupo.enlish.service.config.ListWordIdTypeHandler" />
</resultMap>
<insert id="insert" parameterType="com.yinlihupo.enlish.service.domain.dataobject.ExamWordsJudgeResultDO">
<insert id="insert">
insert into exam_words_judge_result
(ans_sheet_path, is_finished, start_date)
values (#{path}, 0, now())
</insert>
<select id="selectUnfinishedExamWordsJudgeResultDOList" resultMap="BaseResultMap">
select * from exam_words_judge_result
where is_finished = 0
limit #{count}
</select>
<update id="updateErrorMsg">
update exam_words_judge_result
set error_msg = #{errorMsg}
and is_finished = 2
where id = #{id}
</update>
<update id="updateExamWordsJudgeResultDO">
update exam_words_judge_result
set student_id = #{examWordsJudgeResultDO.studentId},
exam_words_id = #{examWordsJudgeResultDO.examWordsId},
correct_word_ids = #{examWordsJudgeResultDO.correctWordIds, typeHandler=com.yinlihupo.enlish.service.config.ListWordIdTypeHandler},
wrong_word_ids = #{examWordsJudgeResultDO.wrongWordIds, typeHandler=com.yinlihupo.enlish.service.config.ListWordIdTypeHandler},
correct_word_count = #{examWordsJudgeResultDO.correctWordCount},
wrong_word_count = #{examWordsJudgeResultDO.wrongWordCount},
is_finished = 1
where id = #{examWordsJudgeResultDO.id}
</update>
</mapper>

View File

@@ -8,6 +8,7 @@
<result column="is_completed" jdbcType="INTEGER" property="isCompleted" />
<result column="start_data" jdbcType="TIMESTAMP" property="startData" />
</resultMap>
<insert id="insertStudentsExam">
insert into student_exam_words
(student_id, exam_words_id, is_completed, start_data)
@@ -17,5 +18,20 @@
</foreach>
</insert>
<select id="selectByStudentIdAndExamWordsId" resultMap="BaseResultMap">
select *
from student_exam_words
where student_id = #{studentId}
and exam_words_id = #{examWordsId}
and is_completed = 0
</select>
<update id="updateStudentExamWordsFinished">
update student_exam_words
set is_completed = 1
where student_id = #{studentId}
and exam_words_id = #{examWordsId}
and is_completed = 0
</update>
</mapper>

View File

@@ -54,6 +54,7 @@
where unit_id = #{unitId}
limit #{wordCount}
</select>
<select id="selectVocabularyBankDOListByIds" resultMap="BaseResultMap">
select *
from vocabulary_bank
@@ -63,4 +64,9 @@
</foreach>
</select>
<select id="selectAllIds" resultType="java.lang.Integer">
select id
from vocabulary_bank
</select>
</mapper>

View File

@@ -7,17 +7,14 @@
<result column="word_id" jdbcType="INTEGER" property="wordId" />
<result column="review_count" jdbcType="INTEGER" property="reviewCount" />
<result column="memory_strength" jdbcType="DECIMAL" property="memoryStrength" />
<result column="update_time" jdbcType="TIMESTAMP" property="update_time" />
</resultMap>
<sql id="Base_Column_List">
id, student_id, word_id, review_count, memory_strength
</sql>
<select id="selectByStudentIdAndUnitIdOrderByMemoryStrength" resultMap="BaseResultMap">
select *
from word_mastery_log
where student_id = #{studentId}
and word_id in (
and word_id in (
select id
from vocabulary_bank
where unit_id = #{unitId}
@@ -26,4 +23,27 @@
limit #{limit}
</select>
<insert id="batchInsertInitialization">
insert into word_mastery_log (student_id, word_id, update_time)
VALUES
<!-- 增加if判断防止wordIds为空时生成错误SQL -->
<if test="wordIds != null and wordIds.size() > 0">
<foreach collection="wordIds" item="id" separator=",">
(#{studentId}, #{id}, now())
</foreach>
</if>
</insert>
<update id="batchUpdateStudentMastery">
<foreach collection="wordMasteryLogDOs" item="wordMasteryLog" separator=";">
update word_mastery_log
set
memory_strength = memory_strength + #{wordMasteryLog.memoryStrength},
review_count = review_count + #{wordMasteryLog.reviewCount},
update_time = now()
where student_id = #{wordMasteryLog.studentId}
and word_id = #{wordMasteryLog.wordId}
</foreach>
</update>
</mapper>