Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -18,6 +20,7 @@
public class MistakeQuestionServiceImpl implements IMistakeQuestionService {

private final IMistakeQuestionRepository mistakeQuestionRepository;
private final ApplicationEventPublisher eventPublisher;

@Override
public boolean saveMistakeQuestion(QuestionEntity questionEntity) {
Expand Down Expand Up @@ -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={}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ public Response<QuestionInfoResponseDTO> 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);
}
Expand All @@ -99,13 +106,6 @@ public Response<QuestionInfoResponseDTO> 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) {
Expand Down
Loading