refactor: 标准导图仅使用报告生成
This commit is contained in:
+22
-16
@@ -36,7 +36,6 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
private final ReviewRecallRecordMapper recallRecordMapper;
|
||||
private final TasksMapper tasksMapper;
|
||||
private final StudyReportsMapper studyReportsMapper;
|
||||
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
|
||||
private final TaskApplicationMapper taskApplicationMapper;
|
||||
private final StudySessionsMapper studySessionsMapper;
|
||||
|
||||
@@ -86,7 +85,8 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
ensureTaskExists(taskNum);
|
||||
ReviewStandardMindMapEntity existing = queryByTaskNum(taskNum);
|
||||
if (existing == null) {
|
||||
throw new NotFindEntitiesException("标准思维导图尚不存在,无法增量更新");
|
||||
log.warn("任务[{}]标准思维导图尚不存在,无法增量更新", taskNum);
|
||||
throw new NotFindEntitiesException("还没有生成过标准思维导图,请先完整生成一次哦");
|
||||
}
|
||||
// 防并发生成
|
||||
AtomicBoolean lock = generatingTasks.computeIfAbsent(taskNum, k -> new AtomicBoolean(false));
|
||||
@@ -201,7 +201,8 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
try {
|
||||
resultJson = objectMapper.writeValueAsString(result);
|
||||
} catch (Exception e) {
|
||||
throw new OperationFailedException("对比结果序列化失败");
|
||||
log.error("任务[{}]对比结果序列化失败", taskNum, e);
|
||||
throw new OperationFailedException("对比结果解析失败了,请稍后再试");
|
||||
}
|
||||
|
||||
// 5. 保存回忆记录
|
||||
@@ -405,7 +406,10 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
@Override
|
||||
public ReviewRecallRecordEntity getRecallRecord(Integer recordId) throws NotFindEntitiesException {
|
||||
return Optional.ofNullable(recallRecordMapper.selectById(recordId))
|
||||
.orElseThrow(() -> new NotFindEntitiesException("回忆记录[" + recordId + "]不存在"));
|
||||
.orElseThrow(() -> {
|
||||
log.warn("回忆记录[{}]不存在", recordId);
|
||||
return new NotFindEntitiesException("这条回忆记录不存在或已被删除");
|
||||
});
|
||||
}
|
||||
|
||||
// ============ 内部方法 ============
|
||||
@@ -415,7 +419,8 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum).last("LIMIT 1"));
|
||||
|
||||
if (task == null) {
|
||||
throw new OperationFailedException("任务[" + taskNum + "]不存在");
|
||||
log.warn("任务[{}]不存在,无法生成思维导图", taskNum);
|
||||
throw new OperationFailedException("这个任务不存在或已被删除");
|
||||
}
|
||||
|
||||
// 收集学习数据
|
||||
@@ -428,14 +433,12 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
List<StudyReportsEntity> reports = sessionNums.isEmpty() ? List.of()
|
||||
: studyReportsMapper.selectList(Wrappers.<StudyReportsEntity>lambdaQuery()
|
||||
.in(StudyReportsEntity::getSessionNum, sessionNums));
|
||||
List<StudyReportFragmentsEntity> fragments = sessionNums.isEmpty() ? List.of()
|
||||
: studyReportFragmentsMapper.selectList(Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
||||
.in(StudyReportFragmentsEntity::getSessionNum, sessionNums));
|
||||
List<TaskApplicationEntity> applications = taskApplicationMapper.selectList(
|
||||
Wrappers.<TaskApplicationEntity>lambdaQuery().eq(TaskApplicationEntity::getTaskNum, taskNum));
|
||||
|
||||
if (reports.isEmpty() && fragments.isEmpty()) {
|
||||
throw new OperationFailedException("任务[" + taskNum + "]没有学习报告或残片,无法生成思维导图");
|
||||
if (reports.isEmpty()) {
|
||||
log.warn("任务[{}]没有学习报告,无法生成思维导图", taskNum);
|
||||
throw new OperationFailedException("这个任务还没开始学习哦,学习后产生学习报告后再来吧");
|
||||
}
|
||||
|
||||
// 优先选 AI 客户端(非 BUILTIN),其次内置生成器
|
||||
@@ -445,10 +448,11 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
.orElse(null);
|
||||
|
||||
if (client == null) {
|
||||
throw new OperationFailedException("没有可用的思维导图生成器");
|
||||
log.warn("任务[{}]没有可用的思维导图生成器", taskNum);
|
||||
throw new OperationFailedException("思维导图暂时生成不了,请稍后再试");
|
||||
}
|
||||
|
||||
Optional<MindMapNode> optRoot = client.generate(task, reports, fragments, applications, null);
|
||||
Optional<MindMapNode> optRoot = client.generate(task, reports, applications, null);
|
||||
// AI 生成失败时尝试降级到内置生成器
|
||||
if (optRoot.isEmpty() && !"BUILTIN".equals(client.generatorName())) {
|
||||
log.info("AI 思维导图生成失败,降级到内置生成器");
|
||||
@@ -456,11 +460,12 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
.filter(c -> "BUILTIN".equals(c.generatorName()) && c.isAvailable())
|
||||
.findFirst().orElse(null);
|
||||
if (fallback != null) {
|
||||
optRoot = fallback.generate(task, reports, fragments, applications, null);
|
||||
optRoot = fallback.generate(task, reports, applications, null);
|
||||
}
|
||||
}
|
||||
if (optRoot.isEmpty()) {
|
||||
throw new OperationFailedException("思维导图生成失败");
|
||||
log.warn("任务[{}]思维导图生成失败,已尝试全部生成器", taskNum);
|
||||
throw new OperationFailedException("思维导图生成失败了,请稍后再试");
|
||||
}
|
||||
|
||||
MindMapNode root = optRoot.get();
|
||||
@@ -483,7 +488,7 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
entity.setGenerator(client.generatorName());
|
||||
entity.setGeneratorVersion("1.0");
|
||||
entity.setSourceReportCount(reports.size());
|
||||
entity.setSourceFragmentCount(fragments.size());
|
||||
entity.setSourceFragmentCount(0);
|
||||
entity.setGeneratedTime(LocalDateTime.now());
|
||||
|
||||
if (create) {
|
||||
@@ -497,7 +502,8 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
private void ensureTaskExists(String taskNum) throws NotFindEntitiesException {
|
||||
if (!StringUtils.hasText(taskNum) || !tasksMapper.exists(
|
||||
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum))) {
|
||||
throw new NotFindEntitiesException("任务[" + taskNum + "]不存在");
|
||||
log.warn("任务[{}]不存在", taskNum);
|
||||
throw new NotFindEntitiesException("这个任务不存在或已被删除");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user