|
|
@@ -1300,27 +1300,35 @@ class ExamAnswerAnalysisService
|
|
|
*/
|
|
|
private function saveExamAnswerRecords(array $examData, array $questionMappings = []): void
|
|
|
{
|
|
|
- $studentId = $examData['student_id'];
|
|
|
- $examId = $examData['paper_id'];
|
|
|
+ // 【修复】确保类型正确,避免 SQL 类型转换问题
|
|
|
+ $studentId = (string) $examData['student_id'];
|
|
|
+ $examId = (string) $examData['paper_id'];
|
|
|
$now = now();
|
|
|
|
|
|
// 先清理该考试的所有答题记录(支持重复提交)
|
|
|
try {
|
|
|
DB::connection('mysql')->table('student_answer_questions')
|
|
|
- ->where('student_id', $studentId)
|
|
|
- ->where('exam_id', $examId)
|
|
|
+ ->where('student_id', '=', $studentId)
|
|
|
+ ->where('exam_id', '=', $examId)
|
|
|
->delete();
|
|
|
|
|
|
DB::connection('mysql')->table('student_answer_steps')
|
|
|
- ->where('student_id', $studentId)
|
|
|
- ->where('exam_id', $examId)
|
|
|
+ ->where('student_id', '=', $studentId)
|
|
|
+ ->where('exam_id', '=', $examId)
|
|
|
->delete();
|
|
|
+
|
|
|
+ Log::info('清理旧答题记录成功', [
|
|
|
+ 'student_id' => $studentId,
|
|
|
+ 'exam_id' => $examId,
|
|
|
+ ]);
|
|
|
} catch (\Exception $e) {
|
|
|
- Log::warning('清理旧答题记录时出错(可忽略)', [
|
|
|
+ // 清理失败时抛出异常,避免后续插入重复数据
|
|
|
+ Log::error('清理旧答题记录失败', [
|
|
|
'student_id' => $studentId,
|
|
|
'exam_id' => $examId,
|
|
|
'error' => $e->getMessage(),
|
|
|
]);
|
|
|
+ throw $e;
|
|
|
}
|
|
|
|
|
|
// 【优化】收集所有要插入的记录,最后批量INSERT
|
|
|
@@ -1424,7 +1432,7 @@ class ExamAnswerAnalysisService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 【优化】批量INSERT(每500条一批,避免超过MySQL限制)
|
|
|
+ // 【优化】批量 INSERT(每500条一批,避免超过MySQL限制)
|
|
|
try {
|
|
|
if (!empty($stepsToInsert)) {
|
|
|
foreach (array_chunk($stepsToInsert, 500) as $chunk) {
|