feat: 报告作为思维导图生成的参考上下文

This commit is contained in:
2026-10-22 21:58:50 +08:00
parent 6075839937
commit 13e12ba4da
23 changed files with 656 additions and 63 deletions
@@ -0,0 +1,10 @@
package com.guo.learningprogresstracker.dto;
/**
* 传给 lpt-ai 的一条碎片素材及其报告关联(报告-02)。
*
* <p>碎片正文之外带一个可空的 {@code reportRef}:指向同源的报告上下文。
* LLM 据此知道哪些碎片来自带报告的那次会话,从而只从中提取与这些碎片相关的内容。</p>
*/
public record MindMapFragmentPayload(String content, String reportRef) {
}
@@ -0,0 +1,36 @@
package com.guo.learningprogresstracker.dto;
import io.swagger.v3.oas.annotations.media.Schema;
/**
* 导图生成的报告参考上下文(报告-02)。
*
* <p>一次总结可能把若干碎片拼接出新的定义与观点,这些内容只存在于报告里、不在碎片里。
* 生成导图时,把碎片所在会话的报告一并带上作为 LLM 的参考,让它自行判断
* 「报告是否实质讨论了这些碎片的同一主题」:只有强相关才提取其内容,
* 只是简单提及或没提及则完全不用。</p>
*
* <p>{@code ref} 是报告所属会话编号,与碎片记录上下文的 {@code contextNum} 对应,
* 用于告诉 LLM 哪份报告与哪批碎片同源;{@code taskName} 帮助它判断领域是否一致。</p>
*/
public record MindMapReportContext(
@Schema(description = "报告所属会话编号,用于与碎片记录上下文关联")
String ref,
@Schema(description = "产生该报告的会话所属任务名(仅作判断领域的参考,报告可能来自旁支任务)")
String taskName,
@Schema(description = "会话摘要:这次实际学了什么")
String sessionSummary,
@Schema(description = "预期达成判断:对照学习预期得出的结论")
String expectationVerdict,
@Schema(description = "自由总结:用户对本次学习的叙述")
String freeSummary) {
/** 三段是否都为空白:全空的报告没有参考价值,不进入导图上下文 */
public boolean isBlank() {
return isBlank(sessionSummary) && isBlank(expectationVerdict) && isBlank(freeSummary);
}
private static boolean isBlank(String text) {
return text == null || text.isBlank();
}
}
@@ -1,5 +1,6 @@
package com.guo.learningprogresstracker.service;
import com.guo.learningprogresstracker.dto.MindMapReportContext;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
import com.guo.learningprogresstracker.entity.TaskEntity;
@@ -26,12 +27,15 @@ public interface MindMapAiClient {
* @param task 学习任务
* @param fragments 该任务名下的知识碎片(**按内容归属取**,不是按产生它的会话取)
* @param applications 该任务的应用场景(可选)
* @param reports 碎片同源会话的学习报告(**参考上下文**,报告-02):总结里由碎片拼接出的
* 新定义/观点只能从报告里取到。是否采用由实现按相关性判断;内置规则可用于忽略
* @param clientHint 前端已有的大纲文本(可选,用于 AI 续写而非全量生成)
* @return 标准思维导图的根节点;若无可生成数据则返回 {@link Optional#empty()}
*/
Optional<MindMapNode> generate(TaskEntity task,
List<StudyReportFragmentsEntity> fragments,
List<TaskApplicationEntity> applications,
List<MindMapReportContext> reports,
String clientHint);
/**
@@ -35,4 +35,12 @@ public interface StudyReportFragmentsService extends IService<StudyReportFragmen
/** 待归类内容的条数,用于复习总览的独立区块 */
long countPendingOwnershipFragments();
/**
* 报告内容变化(新增/编辑/删除)后,把该会话碎片对应的任务导图与标签导图置「待更新」(报告-02)。
*
* <p>报告现在是导图生成的参考上下文,因此它也属于「导图素材」的一部分:
* 变化只置「待更新」,重建仍由用户手动触发,与碎片/标签变化同口径。</p>
*/
void markMindMapsStaleForSession(String sessionNum);
}
@@ -5,6 +5,8 @@ import cn.dev33.satoken.stp.StpUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.guo.learningprogresstracker.common.TenantContext;
import com.guo.learningprogresstracker.dto.MindMapFragmentPayload;
import com.guo.learningprogresstracker.dto.MindMapReportContext;
import com.guo.learningprogresstracker.dto.ReportSections;
import jakarta.annotation.PostConstruct;
import lombok.Setter;
@@ -130,19 +132,27 @@ public class AiServiceClient {
/**
* 调用 lpt-ai 从知识碎片生成思维导图大纲。
*
* @param fragments 该任务名下的知识碎片正文(按内容归属取)
* @param fragments 该任务名下的知识碎片正文(按内容归属取),带可空的报告关联
* @param reports 碎片同源会话的学习报告,作为参考上下文(报告-02);由 LLM 按相关性决定是否采用
*/
public Optional<String> generateMindMap(String taskName, String taskDescription,
List<String> fragments) {
List<MindMapFragmentPayload> fragments,
List<MindMapReportContext> reports) {
if (!isConfigured()) {
return Optional.empty();
}
try {
Map<String, Object> params = Map.of(
"taskName", taskName,
"taskDescription", taskDescription != null ? taskDescription : "",
"fragments", fragments != null ? fragments : List.of()
);
List<Map<String, Object>> fragmentBodies = fragments == null ? List.of()
: fragments.stream().map(AiServiceClient::fragmentPayload).toList();
List<Map<String, Object>> reportBodies = reports == null ? List.of()
: reports.stream().map(AiServiceClient::reportPayload).toList();
// 用 LinkedHashMap 而不是 Map.of:字段多于 10 个时 Map.of 会直接抛异常
Map<String, Object> params = new LinkedHashMap<>();
params.put("taskName", taskName);
params.put("taskDescription", taskDescription != null ? taskDescription : "");
params.put("fragments", fragmentBodies);
params.put("reports", reportBodies);
Optional<JsonNode> result = submitAndWait("generate-mind-map", params);
return result.map(r -> r.path("outline").asText(null)).filter(s -> s != null && !s.isBlank());
@@ -152,6 +162,35 @@ public class AiServiceClient {
}
}
/** 一条碎片素材:正文 + 可空的报告关联(报告-02) */
private static Map<String, Object> fragmentPayload(MindMapFragmentPayload fragment) {
Map<String, Object> body = new LinkedHashMap<>();
body.put("content", fragment.content());
if (fragment.reportRef() != null) {
body.put("reportRef", fragment.reportRef());
}
return body;
}
/** 一份报告参考:只带上非空段落,避免 prompt 里出现一串空字段 */
private static Map<String, Object> reportPayload(MindMapReportContext report) {
Map<String, Object> body = new LinkedHashMap<>();
body.put("ref", report.ref());
if (report.taskName() != null) {
body.put("taskName", report.taskName());
}
if (report.sessionSummary() != null) {
body.put("sessionSummary", report.sessionSummary());
}
if (report.expectationVerdict() != null) {
body.put("expectationVerdict", report.expectationVerdict());
}
if (report.freeSummary() != null) {
body.put("freeSummary", report.freeSummary());
}
return body;
}
/**
* 调用 lpt-ai 进行学习引导的一轮对话(复习-06)。
*
@@ -1,5 +1,6 @@
package com.guo.learningprogresstracker.service.impl;
import com.guo.learningprogresstracker.dto.MindMapReportContext;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
import com.guo.learningprogresstracker.entity.TaskEntity;
@@ -50,7 +51,10 @@ public class BuiltinMindMapGenerator implements MindMapAiClient {
public Optional<MindMapNode> generate(TaskEntity task,
List<StudyReportFragmentsEntity> fragments,
List<TaskApplicationEntity> applications,
List<MindMapReportContext> reports,
String clientHint) {
// 报告是参考上下文,需要语义判断「是否与碎片强相关」才能采用;内置规则不做这种判断,
// 因此报告只在 AI 路径参与(报告-02)。
if (fragments == null || fragments.isEmpty()) {
return Optional.empty();
}
@@ -1,5 +1,6 @@
package com.guo.learningprogresstracker.service.impl;
import com.guo.learningprogresstracker.dto.MindMapReportContext;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
import com.guo.learningprogresstracker.entity.TaskEntity;
@@ -42,7 +43,8 @@ public class MindMapOutlineGenerator {
*/
public GeneratedOutline generate(TaskEntity scope,
List<StudyReportFragmentsEntity> fragments,
List<TaskApplicationEntity> applications) throws OperationFailedException {
List<TaskApplicationEntity> applications,
List<MindMapReportContext> reports) throws OperationFailedException {
// 优先选 AI 客户端(非 BUILTIN),其次内置生成器:AI 提升结构质量,内置规则保证 AI 不可用时仍能生成
MindMapAiClient client = aiClients.stream()
.filter(MindMapAiClient::isAvailable)
@@ -53,14 +55,14 @@ public class MindMapOutlineGenerator {
throw new OperationFailedException("思维导图暂时生成不了,请稍后再试");
}
Optional<MindMapNode> optRoot = client.generate(scope, fragments, applications, null);
Optional<MindMapNode> optRoot = client.generate(scope, fragments, applications, reports, null);
if (optRoot.isEmpty() && !GENERATOR_BUILTIN.equals(client.generatorName())) {
log.info("AI 思维导图生成失败,降级到内置生成器");
MindMapAiClient fallback = aiClients.stream()
.filter(c -> GENERATOR_BUILTIN.equals(c.generatorName()) && c.isAvailable())
.findFirst().orElse(null);
if (fallback != null) {
optRoot = fallback.generate(scope, fragments, applications, null);
optRoot = fallback.generate(scope, fragments, applications, reports, null);
}
}
if (optRoot.isEmpty()) {
@@ -0,0 +1,127 @@
package com.guo.learningprogresstracker.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.guo.learningprogresstracker.dto.MindMapReportContext;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
import com.guo.learningprogresstracker.entity.TaskEntity;
import com.guo.learningprogresstracker.enums.FragmentContextTypeEnum;
import com.guo.learningprogresstracker.mapper.StudyReportsMapper;
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
import com.guo.learningprogresstracker.mapper.TasksMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 导图取材时的报告上下文装载(报告-02)。
*
* <p>报告与碎片按会话隐式绑定:碎片记录上下文是 {@code SESSION} 时,{@code contextNum} 就是
* 报告所属的 {@code session_num}。因此给定一批碎片,就能找到它们同源的报告,
* 交给 LLM 作为参考——总结里由碎片拼接出的新定义/观点只能从报告里取到。</p>
*
* <p>报告只是「参考」而非「素材」:是否使用由 LLM 按相关性强弱判断,本类只负责把
* 同源、非空的报告按时间顺序带过去。复习行为产生的碎片({@code context_type=REVIEW})
* 没有报告,自然不参与。</p>
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class MindMapReportContextLoader {
/** 单次导图最多携带的报告数:报告可能很长,带上限避免把 prompt 撑爆 */
private static final int MAX_REPORT_CONTEXTS = 20;
private final StudyReportsMapper studyReportsMapper;
private final StudySessionsMapper studySessionsMapper;
private final TasksMapper tasksMapper;
/**
* 取出这批碎片同源的报告上下文,按报告产生时间正序;没有报告时返回空列表。
*/
public List<MindMapReportContext> load(List<StudyReportFragmentsEntity> fragments) {
if (fragments == null || fragments.isEmpty()) {
return List.of();
}
Set<String> sessionNums = fragments.stream()
.filter(fragment -> FragmentContextTypeEnum.SESSION.name().equals(fragment.getContextType()))
.map(StudyReportFragmentsEntity::getContextNum)
.filter(StringUtils::hasText)
.collect(Collectors.toCollection(LinkedHashSet::new));
if (sessionNums.isEmpty()) {
return List.of();
}
// 最近若干份(id 倒序),最后再翻回时间正序呈现,先记的在前
List<StudyReportsEntity> reports = studyReportsMapper.selectList(
Wrappers.<StudyReportsEntity>lambdaQuery()
.in(StudyReportsEntity::getSessionNum, sessionNums)
.orderByDesc(StudyReportsEntity::getId));
if (reports.isEmpty()) {
return List.of();
}
Map<String, String> taskNameBySession = loadTaskNamesBySession(sessionNums);
List<MindMapReportContext> contexts = new ArrayList<>();
for (StudyReportsEntity report : reports) {
MindMapReportContext context = new MindMapReportContext(
report.getSessionNum(),
taskNameBySession.get(report.getSessionNum()),
report.getSessionSummary(),
report.getExpectationVerdict(),
report.getFreeSummary());
// 三段全空的报告没有参考价值,不进入上下文
if (context.isBlank()) {
continue;
}
contexts.add(context);
if (contexts.size() >= MAX_REPORT_CONTEXTS) {
break;
}
}
Collections.reverse(contexts);
if (contexts.size() < reports.size()) {
log.info("导图取材携带报告 {} 份(同源报告共 {} 份)", contexts.size(), reports.size());
}
return contexts;
}
/** 会话 → 所属任务名;任务被删除时缺省,交给 LLM 只看内容判断领域 */
private Map<String, String> loadTaskNamesBySession(Set<String> sessionNums) {
List<StudySessionsEntity> sessions = studySessionsMapper.selectList(
Wrappers.<StudySessionsEntity>lambdaQuery()
.in(StudySessionsEntity::getSessionNum, sessionNums));
if (sessions.isEmpty()) {
return Map.of();
}
Set<String> taskNums = sessions.stream()
.map(StudySessionsEntity::getTaskNum)
.filter(StringUtils::hasText)
.collect(Collectors.toSet());
Map<String, String> taskNameByNum = taskNums.isEmpty() ? Map.of()
: tasksMapper.selectList(Wrappers.<TaskEntity>lambdaQuery()
.in(TaskEntity::getTaskNum, taskNums))
.stream()
.filter(task -> StringUtils.hasText(task.getTaskName()))
.collect(Collectors.toMap(TaskEntity::getTaskNum, TaskEntity::getTaskName, (a, b) -> a));
Map<String, String> nameBySession = new LinkedHashMap<>();
for (StudySessionsEntity session : sessions) {
String taskName = taskNameByNum.get(session.getTaskNum());
if (taskName != null) {
nameBySession.put(session.getSessionNum(), taskName);
}
}
return nameBySession;
}
}
@@ -1,8 +1,11 @@
package com.guo.learningprogresstracker.service.impl;
import com.guo.learningprogresstracker.dto.MindMapFragmentPayload;
import com.guo.learningprogresstracker.dto.MindMapReportContext;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
import com.guo.learningprogresstracker.entity.TaskEntity;
import com.guo.learningprogresstracker.enums.FragmentContextTypeEnum;
import com.guo.learningprogresstracker.service.MindMapAiClient;
import com.guo.learningprogresstracker.utils.MindMapNode;
import com.guo.learningprogresstracker.utils.MindMapTreeTool;
@@ -10,8 +13,10 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -40,25 +45,23 @@ public class RemoteAiMindMapClient implements MindMapAiClient {
public Optional<MindMapNode> generate(TaskEntity task,
List<StudyReportFragmentsEntity> fragments,
List<TaskApplicationEntity> applications,
List<MindMapReportContext> reports,
String clientHint) {
if (!isAvailable()) {
return Optional.empty();
}
// 素材是「该任务名下的知识碎片」(按内容归属取),旁支知识因此会进入它真正的归属任务
List<String> fragmentTexts = fragments == null ? List.of() : fragments.stream()
.map(StudyReportFragmentsEntity::getContent)
.filter(c -> c != null && !c.isBlank())
.collect(Collectors.toList());
if (fragmentTexts.isEmpty()) {
List<MindMapFragmentPayload> payloads = buildFragmentPayloads(fragments, reports);
if (payloads.isEmpty()) {
return Optional.empty();
}
Optional<String> optOutline = aiServiceClient.generateMindMap(
task.getTaskName(),
task.getTaskDescription(),
fragmentTexts
payloads,
reports == null ? List.of() : reports
);
if (optOutline.isEmpty() || optOutline.get().isBlank()) {
@@ -68,8 +71,35 @@ public class RemoteAiMindMapClient implements MindMapAiClient {
String outline = optOutline.get();
MindMapNode root = MindMapTreeTool.parseOutline(outline);
log.info("RemoteAiMindMapClient: 为任务[{}]生成 AI 导图,共 {} 个节点,{} 层",
task.getTaskNum(), MindMapTreeTool.countNodes(root), MindMapTreeTool.maxDepth(root));
log.info("RemoteAiMindMapClient: 为任务[{}]生成 AI 导图,共 {} 个节点,{} 层,携带报告 {} 份",
task.getTaskNum(), MindMapTreeTool.countNodes(root), MindMapTreeTool.maxDepth(root),
reports == null ? 0 : reports.size());
return Optional.of(root);
}
/**
* 碎片正文 + 报告关联:只有记录上下文是学习会话、且该会话确有报告时才挂 {@code reportRef},
* 让 LLM 知道哪些碎片来自带报告的那次会话。空正文的碎片直接丢弃。
*/
private static List<MindMapFragmentPayload> buildFragmentPayloads(
List<StudyReportFragmentsEntity> fragments, List<MindMapReportContext> reports) {
if (fragments == null || fragments.isEmpty()) {
return List.of();
}
Set<String> reportRefs = reports == null ? Set.of()
: reports.stream().map(MindMapReportContext::ref).collect(Collectors.toSet());
List<MindMapFragmentPayload> payloads = new ArrayList<>();
for (StudyReportFragmentsEntity fragment : fragments) {
String content = fragment.getContent();
if (content == null || content.isBlank()) {
continue;
}
String reportRef = FragmentContextTypeEnum.SESSION.name().equals(fragment.getContextType())
&& reportRefs.contains(fragment.getContextNum())
? fragment.getContextNum()
: null;
payloads.add(new MindMapFragmentPayload(content, reportRef));
}
return payloads;
}
}
@@ -29,6 +29,7 @@ import com.guo.learningprogresstracker.mapper.UserReviewPreferencesMapper;
import com.guo.learningprogresstracker.dto.request.UpdateStudyReportRequest;
import com.guo.learningprogresstracker.service.ReviewService;
import com.guo.learningprogresstracker.service.StudyExpectationsService;
import com.guo.learningprogresstracker.service.StudyReportFragmentsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -70,6 +71,7 @@ public class ReviewServiceImpl implements ReviewService {
private final StudyReportsMapper studyReportsMapper;
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
private final StudyReportFragmentsService studyReportFragmentsService;
private final StudySessionsMapper studySessionsMapper;
private final TasksMapper tasksMapper;
private final ReviewRecallRecordMapper reviewRecallRecordMapper;
@@ -360,6 +362,8 @@ public class ReviewServiceImpl implements ReviewService {
patch.setExpectationVerdict(request.getExpectationVerdict());
patch.setFreeSummary(request.getFreeSummary());
studyReportsMapper.updateById(patch);
// 报告-02:报告内容作为导图参考上下文,改动后相关导图置「待更新」
studyReportFragmentsService.markMindMapsStaleForSession(existing.getSessionNum());
log.info("学习报告[{}]已修改", id);
}
@@ -368,6 +372,8 @@ public class ReviewServiceImpl implements ReviewService {
StudyReportsEntity existing = getReportDetail(id);
// 软删除。刻意不连带删除同一会话的知识碎片:碎片是独立原料,可能已被归类到其他任务
studyReportsMapper.deleteById(existing.getId());
// 报告-02:报告不再作为参考上下文,相关导图置「待更新」
studyReportFragmentsService.markMindMapsStaleForSession(existing.getSessionNum());
log.info("学习报告[{}]已删除(知识碎片保留)", id);
}
@@ -1,10 +1,13 @@
package com.guo.learningprogresstracker.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.guo.learningprogresstracker.dto.FragmentTagMatch;
import com.guo.learningprogresstracker.dto.MindMapReportContext;
import com.guo.learningprogresstracker.dto.RecallCompareOutcome;
import com.guo.learningprogresstracker.dto.ReviewTiming;
import com.guo.learningprogresstracker.dto.TagMindMapSummary;
import com.guo.learningprogresstracker.dto.TagMindMapView;
import com.guo.learningprogresstracker.dto.TagScope;
import com.guo.learningprogresstracker.entity.ReviewRecallRecordEntity;
@@ -65,6 +68,7 @@ public class ReviewTagMindMapServiceImpl implements ReviewTagMindMapService {
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
private final StandardMindMapService standardMindMapService;
private final MindMapOutlineGenerator outlineGenerator;
private final MindMapReportContextLoader reportContextLoader;
private final ObjectMapper objectMapper;
// ============ 范围解析 ============
@@ -299,7 +303,7 @@ public class ReviewTagMindMapServiceImpl implements ReviewTagMindMapService {
+ "(" + scope.mode().getDescription() + "),共取材 " + fragments.size() + " 条知识碎片");
MindMapOutlineGenerator.GeneratedOutline generated =
outlineGenerator.generate(scopeTask, fragments, List.of());
outlineGenerator.generate(scopeTask, fragments, List.of(), reportContextLoader.load(fragments));
MindMapNode root = generated.root();
ReviewTagMindMapEntity entity = queryByScopeKey(scope.scopeKey());
@@ -3,6 +3,7 @@ package com.guo.learningprogresstracker.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.guo.learningprogresstracker.dto.MindMapReportContext;
import com.guo.learningprogresstracker.dto.RecallCompareOutcome;
import com.guo.learningprogresstracker.dto.ReviewTiming;
import com.guo.learningprogresstracker.entity.*;
@@ -40,6 +41,7 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
private final MindMapOutlineGenerator outlineGenerator;
private final MindMapReportContextLoader reportContextLoader;
private final ObjectMapper objectMapper;
private final AiServiceClient aiServiceClient;
@@ -439,8 +441,11 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
throw new OperationFailedException("这个任务还没开始学习哦,学习后产生知识碎片后再来吧");
}
// 「碎片 → 缩进大纲」生成链路(AI 优先、内置规则降级)与标签导图共用同一套口径
MindMapOutlineGenerator.GeneratedOutline generated = outlineGenerator.generate(task, fragments, applications);
// 「碎片 → 缩进大纲」生成链路(AI 优先、内置规则降级)与标签导图共用同一套口径;
// 报告-02:把碎片同源会话的报告作为参考上下文带上,让 AI 提取总结里由碎片拼接出的新定义/观点
List<MindMapReportContext> reports = reportContextLoader.load(fragments);
MindMapOutlineGenerator.GeneratedOutline generated =
outlineGenerator.generate(task, fragments, applications, reports);
MindMapNode root = generated.root();
String contentJson = MindMapTreeTool.toJson(root, objectMapper);
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guo.learningprogresstracker.dto.request.CreateFragmentsRequest;
import com.guo.learningprogresstracker.dto.request.UpdateFragmentsRequest;
import com.guo.learningprogresstracker.entity.ReviewStandardMindMapEntity;
import com.guo.learningprogresstracker.entity.MarkerEntity;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
import com.guo.learningprogresstracker.entity.TaskEntity;
@@ -16,6 +17,7 @@ import com.guo.learningprogresstracker.mapper.ReviewStandardMindMapMapper;
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
import com.guo.learningprogresstracker.mapper.TasksMapper;
import com.guo.learningprogresstracker.service.MarkerService;
import com.guo.learningprogresstracker.service.ReviewTagMindMapService;
import com.guo.learningprogresstracker.service.StudyReportFragmentsService;
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
import lombok.RequiredArgsConstructor;
@@ -25,8 +27,11 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* 知识碎片服务(归属-01)。
@@ -45,6 +50,7 @@ public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFrag
private final TasksMapper tasksMapper;
private final ReviewStandardMindMapMapper reviewStandardMindMapMapper;
private final MarkerService markerService;
private final ReviewTagMindMapService reviewTagMindMapService;
@Override
@Transactional
@@ -178,6 +184,41 @@ public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFrag
return taskNum;
}
@Override
public void markMindMapsStaleForSession(String sessionNum) {
List<StudyReportFragmentsEntity> fragments = getFragmentsBySession(sessionNum);
if (fragments.isEmpty()) {
return;
}
// 任务导图:按这批碎片的内容归属逐个置位
Set<String> ownerTaskNums = new LinkedHashSet<>();
List<String> fragmentIds = new java.util.ArrayList<>(fragments.size());
for (StudyReportFragmentsEntity fragment : fragments) {
if (StringUtils.hasText(fragment.getOwnerTaskNum())) {
ownerTaskNums.add(fragment.getOwnerTaskNum());
}
fragmentIds.add(String.valueOf(fragment.getId()));
}
ownerTaskNums.forEach(this::markMindMapStale);
// 标签导图:按这批碎片身上的用户标签置位(系统标记如任务名标签不参与)
Map<String, List<MarkerEntity>> markers =
markerService.listByObjects(MarkerObjectTypeEnum.FRAGMENT, fragmentIds);
Set<String> changedTags = new LinkedHashSet<>();
for (List<MarkerEntity> objectMarkers : markers.values()) {
for (MarkerEntity marker : objectMarkers) {
if (!marker.isSystemMarker() && StringUtils.hasText(marker.getMarkerName())) {
changedTags.add(marker.getMarkerName());
}
}
}
if (!changedTags.isEmpty()) {
reviewTagMindMapService.markStaleForTags(changedTags);
}
log.info("会话[{}]的报告内容变化,{} 个任务的导图与 {} 个标签的导图已置为待更新",
sessionNum, ownerTaskNums.size(), changedTags.size());
}
/** 内容归属变化后把该任务的导图标记为待更新(重建由用户手动触发,不自动跑 AI) */
private void markMindMapStale(String taskNum) {
if (!StringUtils.hasText(taskNum)) {
@@ -20,6 +20,7 @@ import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
import com.guo.learningprogresstracker.mapper.StudyReportsMapper;
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
import com.guo.learningprogresstracker.service.StudyExpectationsService;
import com.guo.learningprogresstracker.service.StudyReportFragmentsService;
import com.guo.learningprogresstracker.service.StudySessionsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -50,7 +51,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
private static final int SCAN_BATCH_SIZE = 200;
private final TasksServiceImpl tasksServiceImpl;
private final StudyReportFragmentsServiceImpl studyReportFragmentsServiceImpl;
private final StudyReportFragmentsService studyReportFragmentsService;
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
private final StudyReportsMapper studyReportsMapper;
private final AiServiceClient aiServiceClient;
@@ -152,6 +153,9 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
studyReportsEntity.setExpectationVerdict(sections.expectationVerdict());
studyReportsEntity.setFreeSummary(sections.freeSummary());
studyReportsMapper.insert(studyReportsEntity);
// 报告-02:报告是导图的参考上下文,它一诞生就把本会话碎片对应的导图置「待更新」
// (新碎片本身也应触发;重建仍由用户手动发起)
studyReportFragmentsService.markMindMapsStaleForSession(sessionNum);
if (wasOngoing && studySessionsEntity.getEffectiveTime() == 0) {
return "本次有效学习时间不足" + (studyTimePolicy.getMinEffectiveTimeSeconds() / 60) + "分钟,不计入总学习时间";
}