From bad4d780334c203337d1112be128e2f16b4b9b3d Mon Sep 17 00:00:00 2001 From: malog <2153315236@qq.com> Date: Mon, 1 Dec 2025 16:37:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E8=B7=9F=E8=B8=AA?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=A1=8C=E4=B8=BA=E5=B5=8C=E5=85=A5=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=8A=E4=BC=A0=E5=AD=A6=E7=A7=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ocr/service/impl/DefaultOcrService.java | 21 ------------------- .../impl/MistakeQuestionServiceImpl.java | 20 ++++++++++++++++++ .../achobeta/trigger/http/OcrController.java | 14 ++++++------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/refine-domain/src/main/java/com/achobeta/domain/ocr/service/impl/DefaultOcrService.java b/refine-domain/src/main/java/com/achobeta/domain/ocr/service/impl/DefaultOcrService.java index 069cfdd..12165d7 100644 --- a/refine-domain/src/main/java/com/achobeta/domain/ocr/service/impl/DefaultOcrService.java +++ b/refine-domain/src/main/java/com/achobeta/domain/ocr/service/impl/DefaultOcrService.java @@ -127,27 +127,6 @@ else if (lowerType.endsWith(".txt") || "txt".equals(lowerType)) { questionEntity.setQuestionId(uuid); questionEntity.setUserId(userId); - // 发布用户上传事件,由事件监听器处理向量存储 - try { - UserUploadEvent uploadEvent = new UserUploadEvent( - this, - userId, - uuid, - recognizedText, - null, // subject 暂时为空,可以从AI分析中获取 - null // knowledgePointId 暂时为空,可以从AI分析中获取 - ); - eventPublisher.publishEvent(uploadEvent); - log.info("用户上传题目事件已发布,userId:{}, questionId:{}", userId, uuid); - } catch (Exception e) { - // 事件发布失败不应该影响OCR主流程,只记录日志 - log.error("发布用户上传题目事件时发生异常,userId:{} questionId:{}", userId, uuid, e); - } - - // TODO 将题干存储到Redis中,通过uuid可以查询,设置24小时过期时间 -// String redisKey = "ocr:question:" + uuid; -// redissonService.setValue(redisKey, recognizedText, 24 * 60 * 60 * 1000L); // 24小时过期,单位毫秒 - return questionEntity; } } diff --git a/refine-domain/src/main/java/com/achobeta/domain/ocr/service/impl/MistakeQuestionServiceImpl.java b/refine-domain/src/main/java/com/achobeta/domain/ocr/service/impl/MistakeQuestionServiceImpl.java index 2ce174b..a0ade57 100644 --- a/refine-domain/src/main/java/com/achobeta/domain/ocr/service/impl/MistakeQuestionServiceImpl.java +++ b/refine-domain/src/main/java/com/achobeta/domain/ocr/service/impl/MistakeQuestionServiceImpl.java @@ -3,8 +3,10 @@ import com.achobeta.domain.ocr.adapter.port.IMistakeQuestionRepository; import com.achobeta.domain.ocr.model.entity.QuestionEntity; import com.achobeta.domain.ocr.service.IMistakeQuestionService; +import com.achobeta.domain.user.event.UserUploadEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; /** @@ -18,6 +20,7 @@ public class MistakeQuestionServiceImpl implements IMistakeQuestionService { private final IMistakeQuestionRepository mistakeQuestionRepository; + private final ApplicationEventPublisher eventPublisher; @Override public boolean saveMistakeQuestion(QuestionEntity questionEntity) { @@ -53,6 +56,23 @@ public boolean saveMistakeQuestion(QuestionEntity questionEntity) { questionEntity.getUserId(), questionEntity.getQuestionId()); } + // 发布用户上传事件,由事件监听器处理向量存储 + try { + UserUploadEvent uploadEvent = new UserUploadEvent( + this, + questionEntity.getUserId(), + questionEntity.getQuestionId(), + questionEntity.getQuestionText(), + questionEntity.getSubject(), + null // knowledgePointId 暂时为空,可以从AI分析中获取 + ); + eventPublisher.publishEvent(uploadEvent); + log.info("用户上传题目事件已发布,userId:{}, questionId:{}", questionEntity.getUserId(), questionEntity.getQuestionId()); + } catch (Exception e) { + // 事件发布失败不应该影响OCR主流程,只记录日志 + log.error("发布用户上传题目事件时发生异常,userId:{} questionId:{}", questionEntity.getUserId(), questionEntity.getQuestionId(), e); + } + return success; } catch (Exception e) { log.error("保存错题数据时发生异常: userId={}, questionId={}", diff --git a/refine-trigger/src/main/java/com/achobeta/trigger/http/OcrController.java b/refine-trigger/src/main/java/com/achobeta/trigger/http/OcrController.java index ed06794..e20d82c 100644 --- a/refine-trigger/src/main/java/com/achobeta/trigger/http/OcrController.java +++ b/refine-trigger/src/main/java/com/achobeta/trigger/http/OcrController.java @@ -88,6 +88,13 @@ public Response extractFirst(@RequestPart("file") Multi questionEntity.setSubject(knowledgePoint.subject()); questionEntity.setKnowledgePointId(knowledgePointId); mistakeQuestionService.insertKnowledgePointAndSubject(userId, questionEntity.getQuestionId(), knowledgePointId, knowledgePoint.subject()); + + // 将错题数据保存到数据库中 + boolean saveSuccess = mistakeQuestionService.saveMistakeQuestion(questionEntity); + if (!saveSuccess) { + log.warn("错题保存失败,但继续返回OCR识别结果: userId={}, questionId={}", + userId, questionEntity.getQuestionId()); + } } catch (Exception e) { log.error("ai生成知识点失败", e); } @@ -99,13 +106,6 @@ public Response extractFirst(@RequestPart("file") Multi } }); - // 将错题数据保存到数据库中 - boolean saveSuccess = mistakeQuestionService.saveMistakeQuestion(questionEntity); - if (!saveSuccess) { - log.warn("错题保存失败,但继续返回OCR识别结果: userId={}, questionId={}", - userId, questionEntity.getQuestionId()); - } - // 将题目信息保存到Redis中,用于后续对话查询 boolean redisSaveSuccess = questionRedisRepository.saveQuestion(questionEntity); if (!redisSaveSuccess) {