feat: persist AI training evaluations

main
chenyuan 1 month ago
parent e21fec9c75
commit 0c2a9a2184

@ -0,0 +1,28 @@
# Task 1: AI Training Evaluation Persistence Report
## Delivered
- Added `docs/sql/2026-07-16-ai-training-evaluation.sql`.
- Creates `ai_training_evaluation` with a unique `(student_user_id, teaching_class_id, task_id)` key.
- Persists independent help and assessment statuses, task/answer snapshots, reports, raw model responses, model names, completion times, errors, and assessment score.
- Adds nullable `student_training_answer.ai_assessment_score`.
- Added `AiTrainingEvaluation`, `AiTrainingEvaluationMapper`, and its MyBatis XML mapping.
- `findByStudentClassAndTask` retrieves the sole evaluation record for a student, teaching class, and task.
- `insertIgnore` safely creates the record under concurrent requests.
- `claimHelp` and `claimAssessment` transition only `NOT_STARTED` or `FAILED` rows to `PROCESSING`.
- Completion and failure operations update only rows currently in `PROCESSING`.
- Added `aiAssessmentScore` to `StudentTrainingAnswer`, its XML result/column/dynamic insert/dynamic update mappings, and `updateAiAssessmentScore` for a targeted score write-back.
- Added the assessment score column to the fresh `student_training_answer` table DDL in `StudentTrainingAnswerServiceImpl`.
## Test-first evidence
1. Added `AiTrainingEvaluationServiceImplTest` before implementation.
2. Ran `mvn -Dtest=AiTrainingEvaluationServiceImplTest test` before production changes.
- Expected RED result: test compilation failed because `AiTrainingEvaluation` and `AiTrainingEvaluationMapper` did not exist.
3. Implemented the persistence files and re-ran the same targeted Maven test.
- GREEN result: 3 tests run; 0 failures; 0 errors; 0 skipped.
## Verification notes
- `git diff --check` completed without whitespace errors.
- Maven emitted existing project-model warnings about local Aspose `systemPath` dependencies and the relocated MySQL connector artifact. They do not originate from this task and did not prevent compilation or the targeted test from succeeding.

@ -0,0 +1,31 @@
CREATE TABLE IF NOT EXISTS ai_training_evaluation (
id varchar(64) NOT NULL,
student_user_id varchar(64) NOT NULL,
teaching_class_id varchar(64) NOT NULL,
task_id varchar(64) NOT NULL,
task_key varchar(128) NOT NULL,
help_status varchar(16) NOT NULL DEFAULT 'NOT_STARTED',
help_task_snapshot longtext NULL,
help_answer_snapshot longtext NULL,
help_report_json longtext NULL,
help_raw_response longtext NULL,
help_model varchar(128) NULL,
help_completed_at datetime NULL,
help_error_message varchar(1000) NULL,
assessment_status varchar(16) NOT NULL DEFAULT 'NOT_STARTED',
assessment_task_snapshot longtext NULL,
assessment_answer_snapshot longtext NULL,
assessment_score int NULL,
assessment_report_json longtext NULL,
assessment_raw_response longtext NULL,
assessment_model varchar(128) NULL,
assessment_completed_at datetime NULL,
assessment_error_message varchar(1000) NULL,
create_time datetime NOT NULL,
update_time datetime NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_ai_training_evaluation (student_user_id, teaching_class_id, task_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
ALTER TABLE student_training_answer
ADD COLUMN IF NOT EXISTS ai_assessment_score int NULL;

@ -0,0 +1,83 @@
package com.sztzjy.linkCommerce.entity;
import java.util.Date;
public class AiTrainingEvaluation {
private String id;
private String studentUserId;
private String teachingClassId;
private String taskId;
private String taskKey;
private String helpStatus;
private String helpTaskSnapshot;
private String helpAnswerSnapshot;
private String helpReportJson;
private String helpRawResponse;
private String helpModel;
private Date helpCompletedAt;
private String helpErrorMessage;
private String assessmentStatus;
private String assessmentTaskSnapshot;
private String assessmentAnswerSnapshot;
private Integer assessmentScore;
private String assessmentReportJson;
private String assessmentRawResponse;
private String assessmentModel;
private Date assessmentCompletedAt;
private String assessmentErrorMessage;
private Date createTime;
private Date updateTime;
public String getId() { return id; }
public void setId(String id) { this.id = trim(id); }
public String getStudentUserId() { return studentUserId; }
public void setStudentUserId(String studentUserId) { this.studentUserId = trim(studentUserId); }
public String getTeachingClassId() { return teachingClassId; }
public void setTeachingClassId(String teachingClassId) { this.teachingClassId = trim(teachingClassId); }
public String getTaskId() { return taskId; }
public void setTaskId(String taskId) { this.taskId = trim(taskId); }
public String getTaskKey() { return taskKey; }
public void setTaskKey(String taskKey) { this.taskKey = trim(taskKey); }
public String getHelpStatus() { return helpStatus; }
public void setHelpStatus(String helpStatus) { this.helpStatus = trim(helpStatus); }
public String getHelpTaskSnapshot() { return helpTaskSnapshot; }
public void setHelpTaskSnapshot(String helpTaskSnapshot) { this.helpTaskSnapshot = trim(helpTaskSnapshot); }
public String getHelpAnswerSnapshot() { return helpAnswerSnapshot; }
public void setHelpAnswerSnapshot(String helpAnswerSnapshot) { this.helpAnswerSnapshot = trim(helpAnswerSnapshot); }
public String getHelpReportJson() { return helpReportJson; }
public void setHelpReportJson(String helpReportJson) { this.helpReportJson = trim(helpReportJson); }
public String getHelpRawResponse() { return helpRawResponse; }
public void setHelpRawResponse(String helpRawResponse) { this.helpRawResponse = trim(helpRawResponse); }
public String getHelpModel() { return helpModel; }
public void setHelpModel(String helpModel) { this.helpModel = trim(helpModel); }
public Date getHelpCompletedAt() { return helpCompletedAt; }
public void setHelpCompletedAt(Date helpCompletedAt) { this.helpCompletedAt = helpCompletedAt; }
public String getHelpErrorMessage() { return helpErrorMessage; }
public void setHelpErrorMessage(String helpErrorMessage) { this.helpErrorMessage = trim(helpErrorMessage); }
public String getAssessmentStatus() { return assessmentStatus; }
public void setAssessmentStatus(String assessmentStatus) { this.assessmentStatus = trim(assessmentStatus); }
public String getAssessmentTaskSnapshot() { return assessmentTaskSnapshot; }
public void setAssessmentTaskSnapshot(String assessmentTaskSnapshot) { this.assessmentTaskSnapshot = trim(assessmentTaskSnapshot); }
public String getAssessmentAnswerSnapshot() { return assessmentAnswerSnapshot; }
public void setAssessmentAnswerSnapshot(String assessmentAnswerSnapshot) { this.assessmentAnswerSnapshot = trim(assessmentAnswerSnapshot); }
public Integer getAssessmentScore() { return assessmentScore; }
public void setAssessmentScore(Integer assessmentScore) { this.assessmentScore = assessmentScore; }
public String getAssessmentReportJson() { return assessmentReportJson; }
public void setAssessmentReportJson(String assessmentReportJson) { this.assessmentReportJson = trim(assessmentReportJson); }
public String getAssessmentRawResponse() { return assessmentRawResponse; }
public void setAssessmentRawResponse(String assessmentRawResponse) { this.assessmentRawResponse = trim(assessmentRawResponse); }
public String getAssessmentModel() { return assessmentModel; }
public void setAssessmentModel(String assessmentModel) { this.assessmentModel = trim(assessmentModel); }
public Date getAssessmentCompletedAt() { return assessmentCompletedAt; }
public void setAssessmentCompletedAt(Date assessmentCompletedAt) { this.assessmentCompletedAt = assessmentCompletedAt; }
public String getAssessmentErrorMessage() { return assessmentErrorMessage; }
public void setAssessmentErrorMessage(String assessmentErrorMessage) { this.assessmentErrorMessage = trim(assessmentErrorMessage); }
public Date getCreateTime() { return createTime; }
public void setCreateTime(Date createTime) { this.createTime = createTime; }
public Date getUpdateTime() { return updateTime; }
public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; }
private String trim(String value) {
return value == null ? null : value.trim();
}
}

@ -44,6 +44,8 @@ public class StudentTrainingAnswer {
@ApiModelProperty("是否提交") @ApiModelProperty("是否提交")
private Boolean submitted; private Boolean submitted;
private Integer aiAssessmentScore;
@ApiModelProperty("保存动作SAVE/SUBMIT/RESET") @ApiModelProperty("保存动作SAVE/SUBMIT/RESET")
private String saveAction; private String saveAction;
@ -160,6 +162,14 @@ public class StudentTrainingAnswer {
this.submitted = submitted; this.submitted = submitted;
} }
public Integer getAiAssessmentScore() {
return aiAssessmentScore;
}
public void setAiAssessmentScore(Integer aiAssessmentScore) {
this.aiAssessmentScore = aiAssessmentScore;
}
public String getSaveAction() { public String getSaveAction() {
return saveAction; return saveAction;
} }

@ -0,0 +1,30 @@
package com.sztzjy.linkCommerce.mapper;
import com.sztzjy.linkCommerce.entity.AiTrainingEvaluation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
@Mapper
public interface AiTrainingEvaluationMapper {
AiTrainingEvaluation findByStudentClassAndTask(@Param("studentUserId") String studentUserId,
@Param("teachingClassId") String teachingClassId,
@Param("taskId") String taskId);
int insertIgnore(AiTrainingEvaluation record);
int claimHelp(@Param("id") String id, @Param("updateTime") Date updateTime);
int claimAssessment(@Param("id") String id, @Param("updateTime") Date updateTime);
int completeHelp(AiTrainingEvaluation record);
int completeAssessment(AiTrainingEvaluation record);
int failHelp(@Param("id") String id, @Param("errorMessage") String errorMessage,
@Param("updateTime") Date updateTime);
int failAssessment(@Param("id") String id, @Param("errorMessage") String errorMessage,
@Param("updateTime") Date updateTime);
}

@ -4,6 +4,8 @@ import com.sztzjy.linkCommerce.entity.StudentTrainingAnswer;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Date;
@Mapper @Mapper
public interface StudentTrainingAnswerMapper { public interface StudentTrainingAnswerMapper {
int insertSelective(StudentTrainingAnswer record); int insertSelective(StudentTrainingAnswer record);
@ -19,4 +21,8 @@ public interface StudentTrainingAnswerMapper {
int deleteByStudentClassAndTask(@Param("studentUserId") String studentUserId, int deleteByStudentClassAndTask(@Param("studentUserId") String studentUserId,
@Param("teachingClassId") String teachingClassId, @Param("teachingClassId") String teachingClassId,
@Param("taskId") String taskId); @Param("taskId") String taskId);
int updateAiAssessmentScore(@Param("id") String id,
@Param("score") Integer score,
@Param("updateTime") Date updateTime);
} }

@ -242,6 +242,7 @@ public class StudentTrainingAnswerServiceImpl implements StudentTrainingAnswerSe
"current_step int DEFAULT 1 COMMENT 'current step'," + "current_step int DEFAULT 1 COMMENT 'current step'," +
"progress_status varchar(32) DEFAULT 'NOT_STARTED' COMMENT 'progress status'," + "progress_status varchar(32) DEFAULT 'NOT_STARTED' COMMENT 'progress status'," +
"submitted bit(1) DEFAULT b'0' COMMENT 'submitted'," + "submitted bit(1) DEFAULT b'0' COMMENT 'submitted'," +
"ai_assessment_score int NULL COMMENT 'AI assessment score'," +
"submit_time datetime NULL COMMENT 'submit time'," + "submit_time datetime NULL COMMENT 'submit time'," +
"create_time datetime NULL COMMENT 'create time'," + "create_time datetime NULL COMMENT 'create time'," +
"update_time datetime NULL COMMENT 'update time'," + "update_time datetime NULL COMMENT 'update time'," +

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sztzjy.linkCommerce.mapper.AiTrainingEvaluationMapper">
<resultMap id="BaseResultMap" type="com.sztzjy.linkCommerce.entity.AiTrainingEvaluation">
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="student_user_id" jdbcType="VARCHAR" property="studentUserId"/>
<result column="teaching_class_id" jdbcType="VARCHAR" property="teachingClassId"/>
<result column="task_id" jdbcType="VARCHAR" property="taskId"/>
<result column="task_key" jdbcType="VARCHAR" property="taskKey"/>
<result column="help_status" jdbcType="VARCHAR" property="helpStatus"/>
<result column="help_task_snapshot" jdbcType="LONGVARCHAR" property="helpTaskSnapshot"/>
<result column="help_answer_snapshot" jdbcType="LONGVARCHAR" property="helpAnswerSnapshot"/>
<result column="help_report_json" jdbcType="LONGVARCHAR" property="helpReportJson"/>
<result column="help_raw_response" jdbcType="LONGVARCHAR" property="helpRawResponse"/>
<result column="help_model" jdbcType="VARCHAR" property="helpModel"/>
<result column="help_completed_at" jdbcType="TIMESTAMP" property="helpCompletedAt"/>
<result column="help_error_message" jdbcType="VARCHAR" property="helpErrorMessage"/>
<result column="assessment_status" jdbcType="VARCHAR" property="assessmentStatus"/>
<result column="assessment_task_snapshot" jdbcType="LONGVARCHAR" property="assessmentTaskSnapshot"/>
<result column="assessment_answer_snapshot" jdbcType="LONGVARCHAR" property="assessmentAnswerSnapshot"/>
<result column="assessment_score" jdbcType="INTEGER" property="assessmentScore"/>
<result column="assessment_report_json" jdbcType="LONGVARCHAR" property="assessmentReportJson"/>
<result column="assessment_raw_response" jdbcType="LONGVARCHAR" property="assessmentRawResponse"/>
<result column="assessment_model" jdbcType="VARCHAR" property="assessmentModel"/>
<result column="assessment_completed_at" jdbcType="TIMESTAMP" property="assessmentCompletedAt"/>
<result column="assessment_error_message" jdbcType="VARCHAR" property="assessmentErrorMessage"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
</resultMap>
<sql id="Base_Column_List">
id, student_user_id, teaching_class_id, task_id, task_key,
help_status, help_task_snapshot, help_answer_snapshot, help_report_json, help_raw_response,
help_model, help_completed_at, help_error_message,
assessment_status, assessment_task_snapshot, assessment_answer_snapshot, assessment_score,
assessment_report_json, assessment_raw_response, assessment_model, assessment_completed_at,
assessment_error_message, create_time, update_time
</sql>
<select id="findByStudentClassAndTask" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM ai_training_evaluation
WHERE student_user_id = #{studentUserId,jdbcType=VARCHAR}
AND teaching_class_id = #{teachingClassId,jdbcType=VARCHAR}
AND task_id = #{taskId,jdbcType=VARCHAR}
</select>
<insert id="insertIgnore" parameterType="com.sztzjy.linkCommerce.entity.AiTrainingEvaluation">
INSERT IGNORE INTO ai_training_evaluation (
id, student_user_id, teaching_class_id, task_id, task_key,
help_status, assessment_status, create_time, update_time
) VALUES (
#{id,jdbcType=VARCHAR}, #{studentUserId,jdbcType=VARCHAR}, #{teachingClassId,jdbcType=VARCHAR},
#{taskId,jdbcType=VARCHAR}, #{taskKey,jdbcType=VARCHAR},
#{helpStatus,jdbcType=VARCHAR}, #{assessmentStatus,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
)
</insert>
<update id="claimHelp">
UPDATE ai_training_evaluation
SET help_status = 'PROCESSING', help_error_message = NULL, update_time = #{updateTime,jdbcType=TIMESTAMP}
WHERE id = #{id,jdbcType=VARCHAR}
AND help_status IN ('NOT_STARTED', 'FAILED')
</update>
<update id="claimAssessment">
UPDATE ai_training_evaluation
SET assessment_status = 'PROCESSING', assessment_error_message = NULL, update_time = #{updateTime,jdbcType=TIMESTAMP}
WHERE id = #{id,jdbcType=VARCHAR}
AND assessment_status IN ('NOT_STARTED', 'FAILED')
</update>
<update id="completeHelp" parameterType="com.sztzjy.linkCommerce.entity.AiTrainingEvaluation">
UPDATE ai_training_evaluation
SET help_status = 'SUCCEEDED',
help_task_snapshot = #{helpTaskSnapshot},
help_answer_snapshot = #{helpAnswerSnapshot},
help_report_json = #{helpReportJson},
help_raw_response = #{helpRawResponse},
help_model = #{helpModel,jdbcType=VARCHAR},
help_completed_at = #{helpCompletedAt,jdbcType=TIMESTAMP},
help_error_message = NULL,
update_time = #{updateTime,jdbcType=TIMESTAMP}
WHERE id = #{id,jdbcType=VARCHAR} AND help_status = 'PROCESSING'
</update>
<update id="completeAssessment" parameterType="com.sztzjy.linkCommerce.entity.AiTrainingEvaluation">
UPDATE ai_training_evaluation
SET assessment_status = 'SUCCEEDED',
assessment_task_snapshot = #{assessmentTaskSnapshot},
assessment_answer_snapshot = #{assessmentAnswerSnapshot},
assessment_score = #{assessmentScore,jdbcType=INTEGER},
assessment_report_json = #{assessmentReportJson},
assessment_raw_response = #{assessmentRawResponse},
assessment_model = #{assessmentModel,jdbcType=VARCHAR},
assessment_completed_at = #{assessmentCompletedAt,jdbcType=TIMESTAMP},
assessment_error_message = NULL,
update_time = #{updateTime,jdbcType=TIMESTAMP}
WHERE id = #{id,jdbcType=VARCHAR} AND assessment_status = 'PROCESSING'
</update>
<update id="failHelp">
UPDATE ai_training_evaluation
SET help_status = 'FAILED', help_error_message = #{errorMessage,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=TIMESTAMP}
WHERE id = #{id,jdbcType=VARCHAR} AND help_status = 'PROCESSING'
</update>
<update id="failAssessment">
UPDATE ai_training_evaluation
SET assessment_status = 'FAILED', assessment_error_message = #{errorMessage,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=TIMESTAMP}
WHERE id = #{id,jdbcType=VARCHAR} AND assessment_status = 'PROCESSING'
</update>
</mapper>

@ -15,6 +15,7 @@
<result column="current_step" jdbcType="INTEGER" property="currentStep" /> <result column="current_step" jdbcType="INTEGER" property="currentStep" />
<result column="progress_status" jdbcType="VARCHAR" property="progressStatus" /> <result column="progress_status" jdbcType="VARCHAR" property="progressStatus" />
<result column="submitted" jdbcType="BIT" property="submitted" /> <result column="submitted" jdbcType="BIT" property="submitted" />
<result column="ai_assessment_score" jdbcType="INTEGER" property="aiAssessmentScore" />
<result column="submit_time" jdbcType="TIMESTAMP" property="submitTime" /> <result column="submit_time" jdbcType="TIMESTAMP" property="submitTime" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
@ -22,7 +23,7 @@
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, student_user_id, teaching_class_id, task_id, task_key, task_name, step1_answer, step2_answer, id, student_user_id, teaching_class_id, task_id, task_key, task_name, step1_answer, step2_answer,
step3_answer, step4_answer, current_step, progress_status, submitted, submit_time, create_time, update_time step3_answer, step4_answer, current_step, progress_status, submitted, ai_assessment_score, submit_time, create_time, update_time
</sql> </sql>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
@ -64,6 +65,7 @@
<if test="currentStep != null">current_step,</if> <if test="currentStep != null">current_step,</if>
<if test="progressStatus != null">progress_status,</if> <if test="progressStatus != null">progress_status,</if>
<if test="submitted != null">submitted,</if> <if test="submitted != null">submitted,</if>
<if test="aiAssessmentScore != null">ai_assessment_score,</if>
<if test="submitTime != null">submit_time,</if> <if test="submitTime != null">submit_time,</if>
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if> <if test="updateTime != null">update_time,</if>
@ -82,6 +84,7 @@
<if test="currentStep != null">#{currentStep,jdbcType=INTEGER},</if> <if test="currentStep != null">#{currentStep,jdbcType=INTEGER},</if>
<if test="progressStatus != null">#{progressStatus,jdbcType=VARCHAR},</if> <if test="progressStatus != null">#{progressStatus,jdbcType=VARCHAR},</if>
<if test="submitted != null">#{submitted,jdbcType=BIT},</if> <if test="submitted != null">#{submitted,jdbcType=BIT},</if>
<if test="aiAssessmentScore != null">#{aiAssessmentScore,jdbcType=INTEGER},</if>
<if test="submitTime != null">#{submitTime,jdbcType=TIMESTAMP},</if> <if test="submitTime != null">#{submitTime,jdbcType=TIMESTAMP},</if>
<if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if> <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
<if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if> <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
@ -103,10 +106,18 @@
<if test="currentStep != null">current_step = #{currentStep,jdbcType=INTEGER},</if> <if test="currentStep != null">current_step = #{currentStep,jdbcType=INTEGER},</if>
<if test="progressStatus != null">progress_status = #{progressStatus,jdbcType=VARCHAR},</if> <if test="progressStatus != null">progress_status = #{progressStatus,jdbcType=VARCHAR},</if>
<if test="submitted != null">submitted = #{submitted,jdbcType=BIT},</if> <if test="submitted != null">submitted = #{submitted,jdbcType=BIT},</if>
<if test="aiAssessmentScore != null">ai_assessment_score = #{aiAssessmentScore,jdbcType=INTEGER},</if>
<if test="submitTime != null">submit_time = #{submitTime,jdbcType=TIMESTAMP},</if> <if test="submitTime != null">submit_time = #{submitTime,jdbcType=TIMESTAMP},</if>
<if test="createTime != null">create_time = #{createTime,jdbcType=TIMESTAMP},</if> <if test="createTime != null">create_time = #{createTime,jdbcType=TIMESTAMP},</if>
<if test="updateTime != null">update_time = #{updateTime,jdbcType=TIMESTAMP},</if> <if test="updateTime != null">update_time = #{updateTime,jdbcType=TIMESTAMP},</if>
</set> </set>
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
<update id="updateAiAssessmentScore">
update student_training_answer
set ai_assessment_score = #{score,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper> </mapper>

@ -0,0 +1,83 @@
package com.sztzjy.linkCommerce.service.impl;
import com.sztzjy.linkCommerce.entity.AiTrainingEvaluation;
import com.sztzjy.linkCommerce.entity.StudentTrainingAnswer;
import com.sztzjy.linkCommerce.mapper.AiTrainingEvaluationMapper;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class AiTrainingEvaluationServiceImplTest {
@Test
void persistsIndependentHelpAndAssessmentFieldsAndAnswerScore() {
AiTrainingEvaluation evaluation = new AiTrainingEvaluation();
Date completedAt = new Date();
evaluation.setHelpStatus("SUCCEEDED");
evaluation.setHelpTaskSnapshot("{\"task\":\"snapshot\"}");
evaluation.setHelpAnswerSnapshot("{\"step1\":\"answer\"}");
evaluation.setHelpReportJson("{\"overallDiagnosis\":\"ok\"}");
evaluation.setHelpRawResponse("raw-help");
evaluation.setHelpModel("qwen-test");
evaluation.setHelpCompletedAt(completedAt);
evaluation.setHelpErrorMessage("help-error");
evaluation.setAssessmentStatus("SUCCEEDED");
evaluation.setAssessmentTaskSnapshot("{\"task\":\"snapshot\"}");
evaluation.setAssessmentAnswerSnapshot("{\"step1\":\"answer\"}");
evaluation.setAssessmentScore(86);
evaluation.setAssessmentReportJson("{\"score\":86}");
evaluation.setAssessmentRawResponse("raw-assessment");
evaluation.setAssessmentModel("qwen-test");
evaluation.setAssessmentCompletedAt(completedAt);
evaluation.setAssessmentErrorMessage("assessment-error");
StudentTrainingAnswer answer = new StudentTrainingAnswer();
answer.setAiAssessmentScore(86);
assertEquals("SUCCEEDED", evaluation.getHelpStatus());
assertEquals("{\"overallDiagnosis\":\"ok\"}", evaluation.getHelpReportJson());
assertEquals(86, evaluation.getAssessmentScore());
assertEquals("{\"score\":86}", evaluation.getAssessmentReportJson());
assertEquals(completedAt, evaluation.getAssessmentCompletedAt());
assertEquals(86, answer.getAiAssessmentScore());
}
@Test
void mapperProvidesAtomicClaimsAndCompletionOperations() throws Exception {
assertNotNull(AiTrainingEvaluationMapper.class.getDeclaredMethod("findByStudentClassAndTask",
String.class, String.class, String.class));
assertNotNull(AiTrainingEvaluationMapper.class.getDeclaredMethod("insertIgnore", AiTrainingEvaluation.class));
assertNotNull(AiTrainingEvaluationMapper.class.getDeclaredMethod("claimHelp", String.class, Date.class));
assertNotNull(AiTrainingEvaluationMapper.class.getDeclaredMethod("claimAssessment", String.class, Date.class));
assertNotNull(AiTrainingEvaluationMapper.class.getDeclaredMethod("completeHelp", AiTrainingEvaluation.class));
assertNotNull(AiTrainingEvaluationMapper.class.getDeclaredMethod("completeAssessment", AiTrainingEvaluation.class));
assertNotNull(AiTrainingEvaluationMapper.class.getDeclaredMethod("failHelp", String.class, String.class, Date.class));
assertNotNull(AiTrainingEvaluationMapper.class.getDeclaredMethod("failAssessment", String.class, String.class, Date.class));
String xml = readResource("src/main/resources/mappers/AiTrainingEvaluationMapper.xml");
assertTrue(xml.contains("INSERT IGNORE INTO ai_training_evaluation"));
assertTrue(xml.contains("help_status IN ('NOT_STARTED', 'FAILED')"));
assertTrue(xml.contains("assessment_status IN ('NOT_STARTED', 'FAILED')"));
assertTrue(xml.contains("help_status = 'SUCCEEDED'"));
assertTrue(xml.contains("assessment_status = 'SUCCEEDED'"));
}
@Test
void answerMapperIncludesAssessmentScoreAndTargetedScoreUpdate() throws Exception {
String xml = readResource("src/main/resources/mappers/StudentTrainingAnswerMapper.xml");
assertTrue(xml.contains("ai_assessment_score"));
assertTrue(xml.contains("<update id=\"updateAiAssessmentScore\""));
}
private String readResource(String path) throws IOException {
return new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8);
}
}
Loading…
Cancel
Save