feat: 报告作为思维导图生成的参考上下文
This commit is contained in:
@@ -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)。
|
||||
*
|
||||
|
||||
+4
@@ -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();
|
||||
}
|
||||
|
||||
+5
-3
@@ -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()) {
|
||||
|
||||
+127
@@ -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;
|
||||
}
|
||||
}
|
||||
+39
-9
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -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());
|
||||
|
||||
+7
-2
@@ -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);
|
||||
|
||||
+41
@@ -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)) {
|
||||
|
||||
+5
-1
@@ -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) + "分钟,不计入总学习时间";
|
||||
}
|
||||
|
||||
+12
-6
@@ -1,6 +1,7 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.guo.learningprogresstracker.dto.MindMapFragmentPayload;
|
||||
import com.guo.learningprogresstracker.dto.ReportSections;
|
||||
import com.guo.learningprogresstracker.support.TestHttpServer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -23,6 +24,11 @@ class AiServiceClientTest extends TestHttpServer {
|
||||
return client;
|
||||
}
|
||||
|
||||
/** 构造碎片素材:无报告关联的普通碎片 */
|
||||
private static List<MindMapFragmentPayload> fragments(String... contents) {
|
||||
return java.util.Arrays.stream(contents).map(content -> new MindMapFragmentPayload(content, null)).toList();
|
||||
}
|
||||
|
||||
// ============ 配置状态 ============
|
||||
|
||||
@Test
|
||||
@@ -45,7 +51,7 @@ class AiServiceClientTest extends TestHttpServer {
|
||||
client.setTimeoutSeconds(1);
|
||||
client.init();
|
||||
assertTrue(client.aggregateReport("任务", List.of("片段"), null).isEmpty());
|
||||
assertTrue(client.generateMindMap("任务", "描述", List.of("报告")).isEmpty());
|
||||
assertTrue(client.generateMindMap("任务", "描述", fragments("报告"), List.of()).isEmpty());
|
||||
assertTrue(client.compareRecall("任务", "标准大纲", "回忆大纲").isEmpty());
|
||||
}
|
||||
|
||||
@@ -86,7 +92,7 @@ class AiServiceClientTest extends TestHttpServer {
|
||||
"{\"status\":\"done\",\"result\":{\"outline\":\"- 分支A\\n- 分支B\"}}");
|
||||
AiServiceClient client = newClient(baseUrl(), 2);
|
||||
|
||||
Optional<String> outline = client.generateMindMap("任务A", null, List.of("报告内容"));
|
||||
Optional<String> outline = client.generateMindMap("任务A", null, fragments("报告内容"), List.of());
|
||||
assertTrue(outline.isPresent());
|
||||
assertEquals("- 分支A\n- 分支B", outline.get());
|
||||
}
|
||||
@@ -97,7 +103,7 @@ class AiServiceClientTest extends TestHttpServer {
|
||||
route("GET", "/ai/tasks/t3", 200, "{\"status\":\"done\",\"result\":{}}");
|
||||
AiServiceClient client = newClient(baseUrl(), 2);
|
||||
|
||||
assertTrue(client.generateMindMap("任务A", "描述", List.of("报告内容")).isEmpty());
|
||||
assertTrue(client.generateMindMap("任务A", "描述", fragments("报告内容"), List.of()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,7 +112,7 @@ class AiServiceClientTest extends TestHttpServer {
|
||||
route("GET", "/ai/tasks/t4", 200, "{\"status\":\"done\",\"result\":{\"outline\":\" \"}}");
|
||||
AiServiceClient client = newClient(baseUrl(), 2);
|
||||
|
||||
assertTrue(client.generateMindMap("任务A", "描述", List.of("报告内容")).isEmpty());
|
||||
assertTrue(client.generateMindMap("任务A", "描述", fragments("报告内容"), List.of()).isEmpty());
|
||||
}
|
||||
|
||||
// ============ compareRecall ============
|
||||
@@ -153,7 +159,7 @@ class AiServiceClientTest extends TestHttpServer {
|
||||
void submitTask_connectionRefused_returnsEmpty() {
|
||||
AiServiceClient client = newClient("http://localhost:1", 1);
|
||||
|
||||
assertTrue(client.generateMindMap("任务A", "描述", List.of("报告内容")).isEmpty());
|
||||
assertTrue(client.generateMindMap("任务A", "描述", fragments("报告内容"), List.of()).isEmpty());
|
||||
}
|
||||
|
||||
// ============ 轮询阶段 ============
|
||||
@@ -268,7 +274,7 @@ class AiServiceClientTest extends TestHttpServer {
|
||||
AiServiceClient client = newClient(baseUrl(), 2);
|
||||
|
||||
assertTrue(client.aggregateReport("任务A", List.of("片段"), null).isEmpty());
|
||||
assertTrue(client.generateMindMap("任务A", "描述", List.of("报告内容")).isEmpty());
|
||||
assertTrue(client.generateMindMap("任务A", "描述", fragments("报告内容"), List.of()).isEmpty());
|
||||
assertTrue(client.compareRecall("任务A", "标准大纲", "回忆大纲").isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ class AiTaskIntegrationTest {
|
||||
aiCallThread.set(null);
|
||||
|
||||
when(aiServiceClient.isConfigured()).thenReturn(true);
|
||||
when(aiServiceClient.generateMindMap(anyString(), any(), any())).thenAnswer(invocation -> {
|
||||
when(aiServiceClient.generateMindMap(anyString(), any(), any(), any())).thenAnswer(invocation -> {
|
||||
aiCalled.set(true);
|
||||
aiCallThread.set(Thread.currentThread().getName());
|
||||
transactionActiveDuringAiCall.set(TransactionSynchronizationManager.isActualTransactionActive());
|
||||
|
||||
+10
-10
@@ -53,8 +53,8 @@ class BuiltinMindMapGeneratorTest {
|
||||
|
||||
@Test
|
||||
void generate_nullOrEmptyReports_returnsEmpty() {
|
||||
assertTrue(generator.generate(task(), null, List.of(), null).isEmpty());
|
||||
assertTrue(generator.generate(task(), List.of(), List.of(), null).isEmpty());
|
||||
assertTrue(generator.generate(task(), null, List.of(), List.of(), null).isEmpty());
|
||||
assertTrue(generator.generate(task(), List.of(), List.of(), List.of(), null).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +68,7 @@ class BuiltinMindMapGeneratorTest {
|
||||
StudyReportFragmentsEntity noDate = fragment("S2", "会话二的学习内容", 2);
|
||||
noDate.setCreatedTime(null);
|
||||
|
||||
MindMapNode root = generator.generate(task, List.of(withDate, noDate), List.of(), null).get();
|
||||
MindMapNode root = generator.generate(task, List.of(withDate, noDate), List.of(), List.of(), null).get();
|
||||
|
||||
assertEquals("学习任务", root.getTitle());
|
||||
assertEquals("任务描述内容", root.getNotes());
|
||||
@@ -101,7 +101,7 @@ class BuiltinMindMapGeneratorTest {
|
||||
StudyReportFragmentsEntity r1 = fragment("S1", exact60, 1);
|
||||
StudyReportFragmentsEntity r2 = fragment("S1", long70, 2);
|
||||
|
||||
MindMapNode root = generator.generate(task(), List.of(r1, r2), List.of(), null).get();
|
||||
MindMapNode root = generator.generate(task(), List.of(r1, r2), List.of(), List.of(), null).get();
|
||||
|
||||
// 会话标题取第一条报告,恰好 60 字不截断
|
||||
MindMapNode session = root.getChildren().get(0);
|
||||
@@ -124,7 +124,7 @@ class BuiltinMindMapGeneratorTest {
|
||||
StudyReportFragmentsEntity valid = fragment("S1", "有效学习内容", 3);
|
||||
|
||||
MindMapNode root =
|
||||
generator.generate(task(), List.of(nullContent, blankContent, valid), List.of(), null).get();
|
||||
generator.generate(task(), List.of(nullContent, blankContent, valid), List.of(), List.of(), null).get();
|
||||
|
||||
MindMapNode session = root.getChildren().get(0);
|
||||
// 会话标题取第一条报告内容,null → truncate 返回 ""
|
||||
@@ -137,11 +137,11 @@ class BuiltinMindMapGeneratorTest {
|
||||
@Test
|
||||
void generate_applications_nullOrEmptyAddsNoBranch() {
|
||||
MindMapNode withNull =
|
||||
generator.generate(task(), List.of(fragment("S1", "内容", 1)), null, null).get();
|
||||
generator.generate(task(), List.of(fragment("S1", "内容", 1)), null, List.of(), null).get();
|
||||
assertTrue(withNull.getChildren().stream().noneMatch(n -> "应用场景".equals(n.getTitle())));
|
||||
|
||||
MindMapNode withEmpty =
|
||||
generator.generate(task(), List.of(fragment("S1", "内容", 1)), List.of(), null).get();
|
||||
generator.generate(task(), List.of(fragment("S1", "内容", 1)), List.of(), List.of(), null).get();
|
||||
assertTrue(withEmpty.getChildren().stream().noneMatch(n -> "应用场景".equals(n.getTitle())));
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ class BuiltinMindMapGeneratorTest {
|
||||
TaskApplicationEntity valid = app(3, "缓存设计", null);
|
||||
|
||||
MindMapNode root = generator.generate(task(),
|
||||
List.of(fragment("S1", "内容", 9)), List.of(nullTitle, blankTitle, valid), null).get();
|
||||
List.of(fragment("S1", "内容", 9)), List.of(nullTitle, blankTitle, valid), List.of(), null).get();
|
||||
|
||||
MindMapNode appNode = root.getChildren().stream()
|
||||
.filter(n -> "应用场景".equals(n.getTitle()))
|
||||
@@ -173,7 +173,7 @@ class BuiltinMindMapGeneratorTest {
|
||||
StudyReportFragmentsEntity r1 = fragment("S1", "重复", 1);
|
||||
StudyReportFragmentsEntity r2 = fragment("S1", "重复。", 2);
|
||||
|
||||
MindMapNode root = generator.generate(task(), List.of(r1, r2), List.of(), null).get();
|
||||
MindMapNode root = generator.generate(task(), List.of(r1, r2), List.of(), List.of(), null).get();
|
||||
|
||||
MindMapNode session = root.getChildren().get(0);
|
||||
assertEquals(1, session.getChildren().size());
|
||||
@@ -188,7 +188,7 @@ class BuiltinMindMapGeneratorTest {
|
||||
StudyReportFragmentsEntity r1 = fragment("S1", "相同会话内容", 1);
|
||||
StudyReportFragmentsEntity r2 = fragment("S2", "相同会话内容", 2);
|
||||
|
||||
MindMapNode root = generator.generate(task(), List.of(r1, r2), List.of(), null).get();
|
||||
MindMapNode root = generator.generate(task(), List.of(r1, r2), List.of(), List.of(), null).get();
|
||||
|
||||
assertEquals(1, root.getChildren().size());
|
||||
MindMapNode session = root.getChildren().get(0);
|
||||
|
||||
+12
-12
@@ -45,25 +45,25 @@ class MindMapOutlineGeneratorTest {
|
||||
void prefersAiClientOverBuiltin() throws Exception {
|
||||
MindMapAiClient builtin = client("BUILTIN", true);
|
||||
MindMapAiClient ai = client("AI", true);
|
||||
when(ai.generate(any(), any(), any(), isNull())).thenReturn(Optional.of(node("AI 导图")));
|
||||
when(ai.generate(any(), any(), any(), any(), isNull())).thenReturn(Optional.of(node("AI 导图")));
|
||||
MindMapOutlineGenerator generator = new MindMapOutlineGenerator(List.of(builtin, ai));
|
||||
|
||||
MindMapOutlineGenerator.GeneratedOutline outline = generator.generate(SCOPE, FRAGMENTS, List.of());
|
||||
MindMapOutlineGenerator.GeneratedOutline outline = generator.generate(SCOPE, FRAGMENTS, List.of(), List.of());
|
||||
|
||||
assertEquals("AI 导图", outline.root().getTitle());
|
||||
assertEquals("AI", outline.generatorName());
|
||||
verify(builtin, never()).generate(any(), any(), any(), any());
|
||||
verify(builtin, never()).generate(any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fallsBackToBuiltinWhenAiReturnsNothing() throws Exception {
|
||||
MindMapAiClient builtin = client("BUILTIN", true);
|
||||
MindMapAiClient ai = client("AI", true);
|
||||
when(ai.generate(any(), any(), any(), isNull())).thenReturn(Optional.empty());
|
||||
when(builtin.generate(any(), any(), any(), isNull())).thenReturn(Optional.of(node("内置导图")));
|
||||
when(ai.generate(any(), any(), any(), any(), isNull())).thenReturn(Optional.empty());
|
||||
when(builtin.generate(any(), any(), any(), any(), isNull())).thenReturn(Optional.of(node("内置导图")));
|
||||
MindMapOutlineGenerator generator = new MindMapOutlineGenerator(List.of(ai, builtin));
|
||||
|
||||
MindMapOutlineGenerator.GeneratedOutline outline = generator.generate(SCOPE, FRAGMENTS, List.of());
|
||||
MindMapOutlineGenerator.GeneratedOutline outline = generator.generate(SCOPE, FRAGMENTS, List.of(), List.of());
|
||||
|
||||
assertEquals("内置导图", outline.root().getTitle());
|
||||
}
|
||||
@@ -72,14 +72,14 @@ class MindMapOutlineGeneratorTest {
|
||||
void skipsUnavailableAiAndUsesBuiltin() throws Exception {
|
||||
MindMapAiClient builtin = client("BUILTIN", true);
|
||||
MindMapAiClient ai = client("AI", false);
|
||||
when(builtin.generate(any(), any(), any(), isNull())).thenReturn(Optional.of(node("内置导图")));
|
||||
when(builtin.generate(any(), any(), any(), any(), isNull())).thenReturn(Optional.of(node("内置导图")));
|
||||
MindMapOutlineGenerator generator = new MindMapOutlineGenerator(List.of(ai, builtin));
|
||||
|
||||
MindMapOutlineGenerator.GeneratedOutline outline = generator.generate(SCOPE, FRAGMENTS, List.of());
|
||||
MindMapOutlineGenerator.GeneratedOutline outline = generator.generate(SCOPE, FRAGMENTS, List.of(), List.of());
|
||||
|
||||
assertEquals("内置导图", outline.root().getTitle());
|
||||
assertEquals("BUILTIN", outline.generatorName());
|
||||
verify(ai, never()).generate(any(), any(), any(), any());
|
||||
verify(ai, never()).generate(any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,15 +87,15 @@ class MindMapOutlineGeneratorTest {
|
||||
MindMapOutlineGenerator generator =
|
||||
new MindMapOutlineGenerator(List.of(client("AI", false)));
|
||||
|
||||
assertThrows(OperationFailedException.class, () -> generator.generate(SCOPE, FRAGMENTS, List.of()));
|
||||
assertThrows(OperationFailedException.class, () -> generator.generate(SCOPE, FRAGMENTS, List.of(), List.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void failsWhenAllGeneratorsReturnNothing() {
|
||||
MindMapAiClient builtin = client("BUILTIN", true);
|
||||
when(builtin.generate(any(), any(), any(), isNull())).thenReturn(Optional.empty());
|
||||
when(builtin.generate(any(), any(), any(), any(), isNull())).thenReturn(Optional.empty());
|
||||
MindMapOutlineGenerator generator = new MindMapOutlineGenerator(List.of(builtin));
|
||||
|
||||
assertThrows(OperationFailedException.class, () -> generator.generate(SCOPE, FRAGMENTS, List.of()));
|
||||
assertThrows(OperationFailedException.class, () -> generator.generate(SCOPE, FRAGMENTS, List.of(), List.of()));
|
||||
}
|
||||
}
|
||||
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
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.mapper.StudyReportsMapper;
|
||||
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
||||
import com.guo.learningprogresstracker.mapper.TasksMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* 报告上下文装载的单元测试(报告-02):按会话隐式绑定找同源报告、补任务名、过滤空报告。
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class MindMapReportContextLoaderTest {
|
||||
|
||||
@Mock
|
||||
private StudyReportsMapper studyReportsMapper;
|
||||
@Mock
|
||||
private StudySessionsMapper studySessionsMapper;
|
||||
@Mock
|
||||
private TasksMapper tasksMapper;
|
||||
|
||||
@InjectMocks
|
||||
private MindMapReportContextLoader loader;
|
||||
|
||||
private static StudyReportFragmentsEntity fragment(String contextType, String contextNum) {
|
||||
StudyReportFragmentsEntity fragment = new StudyReportFragmentsEntity();
|
||||
fragment.setContextType(contextType);
|
||||
fragment.setContextNum(contextNum);
|
||||
fragment.setContent("碎片");
|
||||
return fragment;
|
||||
}
|
||||
|
||||
private static StudyReportsEntity report(String sessionNum, String summary) {
|
||||
StudyReportsEntity report = new StudyReportsEntity();
|
||||
report.setSessionNum(sessionNum);
|
||||
report.setSessionSummary(summary);
|
||||
return report;
|
||||
}
|
||||
|
||||
private static StudySessionsEntity session(String sessionNum, String taskNum) {
|
||||
StudySessionsEntity session = new StudySessionsEntity();
|
||||
session.setSessionNum(sessionNum);
|
||||
session.setTaskNum(taskNum);
|
||||
return session;
|
||||
}
|
||||
|
||||
private static TaskEntity task(String taskNum, String taskName) {
|
||||
TaskEntity task = new TaskEntity();
|
||||
task.setTaskNum(taskNum);
|
||||
task.setTaskName(taskName);
|
||||
return task;
|
||||
}
|
||||
|
||||
@Test
|
||||
void load_noSessionFragments_returnsEmptyWithoutQueryingReports() {
|
||||
// 复习行为产生的碎片没有报告,不该触发报告查询
|
||||
List<MindMapReportContext> contexts =
|
||||
loader.load(List.of(fragment("REVIEW", "R1")));
|
||||
|
||||
assertTrue(contexts.isEmpty());
|
||||
verify(studyReportsMapper, never()).selectList(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void load_returnsReportsInTimeOrderWithSourceTaskName() {
|
||||
// 报告 id 倒序返回(最近在前),loader 应翻回时间正序
|
||||
when(studyReportsMapper.selectList(any())).thenReturn(List.of(
|
||||
report("S2", "第二次总结"), report("S1", "第一次总结")));
|
||||
when(studySessionsMapper.selectList(any())).thenReturn(List.of(
|
||||
session("S1", "T1"), session("S2", "T1")));
|
||||
when(tasksMapper.selectList(any())).thenReturn(List.of(task("T1", "Java 并发")));
|
||||
|
||||
List<MindMapReportContext> contexts = loader.load(List.of(
|
||||
fragment("SESSION", "S1"), fragment("SESSION", "S2")));
|
||||
|
||||
assertEquals(2, contexts.size());
|
||||
assertEquals("S1", contexts.get(0).ref(), "先记的报告排在前面");
|
||||
assertEquals("第一次总结", contexts.get(0).sessionSummary());
|
||||
assertEquals("Java 并发", contexts.get(0).taskName());
|
||||
assertEquals("S2", contexts.get(1).ref());
|
||||
}
|
||||
|
||||
@Test
|
||||
void load_skipsBlankReports() {
|
||||
StudyReportsEntity blank = report("S1", null);
|
||||
when(studyReportsMapper.selectList(any())).thenReturn(List.of(report("S2", "有内容"), blank));
|
||||
when(studySessionsMapper.selectList(any())).thenReturn(List.of(
|
||||
session("S1", "T1"), session("S2", "T1")));
|
||||
when(tasksMapper.selectList(any())).thenReturn(List.of(task("T1", "Java 并发")));
|
||||
|
||||
List<MindMapReportContext> contexts = loader.load(List.of(fragment("SESSION", "S1")));
|
||||
|
||||
assertEquals(1, contexts.size());
|
||||
assertEquals("S2", contexts.get(0).ref(), "三段全空的报告不进上下文");
|
||||
}
|
||||
|
||||
@Test
|
||||
void load_taskDeleted_stillReturnsReportWithoutTaskName() {
|
||||
when(studyReportsMapper.selectList(any())).thenReturn(List.of(report("S1", "总结")));
|
||||
when(studySessionsMapper.selectList(any())).thenReturn(List.of(session("S1", "T9")));
|
||||
when(tasksMapper.selectList(any())).thenReturn(List.of());
|
||||
|
||||
List<MindMapReportContext> contexts = loader.load(List.of(fragment("SESSION", "S1")));
|
||||
|
||||
assertEquals(1, contexts.size());
|
||||
assertNull(contexts.get(0).taskName(), "任务被删时缺省任务名,不阻止报告进入上下文");
|
||||
}
|
||||
}
|
||||
+54
-10
@@ -1,11 +1,14 @@
|
||||
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.TaskEntity;
|
||||
import com.guo.learningprogresstracker.utils.MindMapNode;
|
||||
import com.guo.learningprogresstracker.utils.MindMapTreeTool;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
@@ -64,9 +67,9 @@ class RemoteAiMindMapClientTest {
|
||||
@Test
|
||||
void generate_notAvailable_returnsEmpty() {
|
||||
when(aiServiceClient.isConfigured()).thenReturn(false);
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(fragment("内容")), List.of(), null);
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(fragment("内容")), List.of(), List.of(), null);
|
||||
assertTrue(result.isEmpty());
|
||||
verify(aiServiceClient, never()).generateMindMap(any(), any(), any());
|
||||
verify(aiServiceClient, never()).generateMindMap(any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,18 +79,18 @@ class RemoteAiMindMapClientTest {
|
||||
StudyReportFragmentsEntity blankContent = fragment(" ");
|
||||
|
||||
Optional<MindMapNode> result =
|
||||
client.generate(task(), List.of(nullContent, blankContent), List.of(), null);
|
||||
client.generate(task(), List.of(nullContent, blankContent), List.of(), List.of(), null);
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
verify(aiServiceClient, never()).generateMindMap(any(), any(), any());
|
||||
verify(aiServiceClient, never()).generateMindMap(any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void generate_aiReturnsEmpty_returnsEmpty() {
|
||||
when(aiServiceClient.isConfigured()).thenReturn(true);
|
||||
when(aiServiceClient.generateMindMap(any(), any(), any())).thenReturn(Optional.empty());
|
||||
when(aiServiceClient.generateMindMap(any(), any(), any(), any())).thenReturn(Optional.empty());
|
||||
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(fragment("内容")), List.of(), null);
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(fragment("内容")), List.of(), List.of(), null);
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
@@ -95,9 +98,9 @@ class RemoteAiMindMapClientTest {
|
||||
@Test
|
||||
void generate_aiReturnsBlankOutline_returnsEmpty() {
|
||||
when(aiServiceClient.isConfigured()).thenReturn(true);
|
||||
when(aiServiceClient.generateMindMap(any(), any(), any())).thenReturn(Optional.of(" "));
|
||||
when(aiServiceClient.generateMindMap(any(), any(), any(), any())).thenReturn(Optional.of(" "));
|
||||
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(fragment("内容")), List.of(), null);
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(fragment("内容")), List.of(), List.of(), null);
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
@@ -105,11 +108,11 @@ class RemoteAiMindMapClientTest {
|
||||
@Test
|
||||
void generate_success_parsesOutlineToTree() {
|
||||
when(aiServiceClient.isConfigured()).thenReturn(true);
|
||||
when(aiServiceClient.generateMindMap(any(), any(), any()))
|
||||
when(aiServiceClient.generateMindMap(any(), any(), any(), any()))
|
||||
.thenReturn(Optional.of("学习Java\n- 线程基础\n - 线程安全"));
|
||||
|
||||
Optional<MindMapNode> result =
|
||||
client.generate(task(), List.of(fragment("碎片内容")), List.of(), "前端已有大纲");
|
||||
client.generate(task(), List.of(fragment("碎片内容")), List.of(), List.of(), "前端已有大纲");
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
MindMapNode root = result.get();
|
||||
@@ -120,4 +123,45 @@ class RemoteAiMindMapClientTest {
|
||||
assertEquals(3, MindMapTreeTool.countNodes(root));
|
||||
assertEquals(3, MindMapTreeTool.maxDepth(root));
|
||||
}
|
||||
|
||||
/** 报告-02:碎片同源会话有报告时,碎片带 reportRef、报告原样传给 lpt-ai */
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void generate_withSameSessionReport_marksReportRefAndPassesReport() {
|
||||
when(aiServiceClient.isConfigured()).thenReturn(true);
|
||||
when(aiServiceClient.generateMindMap(any(), any(), any(), any()))
|
||||
.thenReturn(Optional.of("学习Java\n- 线程基础"));
|
||||
|
||||
MindMapReportContext report = new MindMapReportContext(
|
||||
"S1", "学习Java入门", "线程池参数总结", null, "还需补队列取舍");
|
||||
|
||||
client.generate(task(), List.of(fragment("碎片内容")), List.of(), List.of(report), null);
|
||||
|
||||
ArgumentCaptor<List<MindMapFragmentPayload>> fragmentsCaptor =
|
||||
ArgumentCaptor.forClass(List.class);
|
||||
ArgumentCaptor<List<MindMapReportContext>> reportsCaptor =
|
||||
ArgumentCaptor.forClass(List.class);
|
||||
verify(aiServiceClient).generateMindMap(any(), any(),
|
||||
fragmentsCaptor.capture(), reportsCaptor.capture());
|
||||
assertEquals("S1", fragmentsCaptor.getValue().get(0).reportRef());
|
||||
assertEquals(1, reportsCaptor.getValue().size());
|
||||
assertEquals("线程池参数总结", reportsCaptor.getValue().get(0).sessionSummary());
|
||||
}
|
||||
|
||||
/** 报告与碎片不同源(无匹配 ref)时,不挂 reportRef,避免张冠李戴 */
|
||||
@Test
|
||||
void generate_withUnrelatedReport_leavesReportRefNull() {
|
||||
when(aiServiceClient.isConfigured()).thenReturn(true);
|
||||
when(aiServiceClient.generateMindMap(any(), any(), any(), any()))
|
||||
.thenReturn(Optional.of("学习Java\n- 线程基础"));
|
||||
|
||||
MindMapReportContext unrelated = new MindMapReportContext("S999", "别的任务", "别的总结", null, null);
|
||||
|
||||
client.generate(task(), List.of(fragment("碎片内容")), List.of(), List.of(unrelated), null);
|
||||
|
||||
ArgumentCaptor<List<MindMapFragmentPayload>> fragmentsCaptor =
|
||||
ArgumentCaptor.forClass(List.class);
|
||||
verify(aiServiceClient).generateMindMap(any(), any(), fragmentsCaptor.capture(), any());
|
||||
assertNull(fragmentsCaptor.getValue().get(0).reportRef());
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -40,6 +40,8 @@ class StandardMindMapServiceImplTest {
|
||||
@Mock
|
||||
private MindMapOutlineGenerator outlineGenerator;
|
||||
@Mock
|
||||
private MindMapReportContextLoader reportContextLoader;
|
||||
@Mock
|
||||
private AiServiceClient aiServiceClient;
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
@@ -184,7 +186,7 @@ class StandardMindMapServiceImplTest {
|
||||
StandardMindMapServiceImpl s = new StandardMindMapServiceImpl(
|
||||
standardMindMapMapper, recallRecordMapper, tasksMapper,
|
||||
taskApplicationMapper, studyReportFragmentsMapper,
|
||||
outlineGenerator, objectMapper, aiServiceClient);
|
||||
outlineGenerator, reportContextLoader, objectMapper, aiServiceClient);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -12,6 +12,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 org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -47,6 +48,9 @@ class StudySessionsServiceImplTest {
|
||||
@Mock
|
||||
private StudyReportFragmentsMapper studyReportFragmentsMapper;
|
||||
|
||||
@Mock
|
||||
private StudyReportFragmentsService studyReportFragmentsService;
|
||||
|
||||
@Mock
|
||||
private StudySessionsMapper studySessionsMapper;
|
||||
|
||||
|
||||
+91
@@ -3,16 +3,21 @@ package com.guo.learningprogresstracker.service.impl;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.guo.learningprogresstracker.dto.AiTaskResponse;
|
||||
import com.guo.learningprogresstracker.dto.MindMapFragmentPayload;
|
||||
import com.guo.learningprogresstracker.dto.MindMapReportContext;
|
||||
import com.guo.learningprogresstracker.dto.RecallCompareOutcome;
|
||||
import com.guo.learningprogresstracker.dto.ReviewTiming;
|
||||
import com.guo.learningprogresstracker.dto.TaskRecallRatio;
|
||||
import com.guo.learningprogresstracker.dto.TaskReviewDuration;
|
||||
import com.guo.learningprogresstracker.dto.TagMindMapSummary;
|
||||
import com.guo.learningprogresstracker.dto.TagScope;
|
||||
import com.guo.learningprogresstracker.dto.request.AiTaskSubmitRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.CreateFragmentsRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.UpdateStudyReportRequest;
|
||||
import com.guo.learningprogresstracker.entity.ReviewRecallRecordEntity;
|
||||
import com.guo.learningprogresstracker.entity.ReviewTagMindMapEntity;
|
||||
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.AiTaskStatusEnum;
|
||||
@@ -24,10 +29,12 @@ import com.guo.learningprogresstracker.exception.OperationFailedException;
|
||||
import com.guo.learningprogresstracker.mapper.ReviewRecallRecordMapper;
|
||||
import com.guo.learningprogresstracker.mapper.ReviewTagMindMapMapper;
|
||||
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
|
||||
import com.guo.learningprogresstracker.mapper.StudyReportsMapper;
|
||||
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
||||
import com.guo.learningprogresstracker.mapper.TasksMapper;
|
||||
import com.guo.learningprogresstracker.service.AiTaskService;
|
||||
import com.guo.learningprogresstracker.service.MarkerService;
|
||||
import com.guo.learningprogresstracker.service.ReviewService;
|
||||
import com.guo.learningprogresstracker.service.ReviewTagMindMapService;
|
||||
import com.guo.learningprogresstracker.service.StandardMindMapService;
|
||||
import com.guo.learningprogresstracker.service.StudyReportFragmentsService;
|
||||
@@ -35,13 +42,16 @@ import com.guo.learningprogresstracker.utils.GenerateNumTool;
|
||||
import com.guo.learningprogresstracker.utils.TagScopeTool;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -52,6 +62,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* 标签导图与标签范围回忆对比的落库集成测试(闭环-04)。
|
||||
@@ -92,6 +105,12 @@ class TagMindMapIntegrationTest {
|
||||
@Autowired
|
||||
private StudySessionsMapper studySessionsMapper;
|
||||
|
||||
@Autowired
|
||||
private StudyReportsMapper studyReportsMapper;
|
||||
|
||||
@Autowired
|
||||
private ReviewService reviewService;
|
||||
|
||||
@Autowired
|
||||
private TasksMapper tasksMapper;
|
||||
|
||||
@@ -490,6 +509,78 @@ class TagMindMapIntegrationTest {
|
||||
assertNull(record.getTaskNum());
|
||||
}
|
||||
|
||||
// ============ 已有导图列表(按标签复习的主入口) ============
|
||||
|
||||
@Test
|
||||
void listMaps_returnsExistingScopesWithTagsAndMode_perUser() throws Exception {
|
||||
String taskNum = saveTask("导图列表任务-" + SEQ.incrementAndGet());
|
||||
String tagA = tag("导图列表A");
|
||||
String tagB = tag("导图列表B");
|
||||
// 两个碎片:一个同时带两标签、一个只带 tagA,用来区分并集/交集的取材
|
||||
StudyReportFragmentsEntity both = createFragment(taskNum, "导图列表碎片");
|
||||
addTag(both, tagA);
|
||||
addTag(both, tagB);
|
||||
addTag(createFragment(taskNum, "导图列表碎片A"), tagA);
|
||||
|
||||
TagScope unionScope = scope("UNION", tagA, tagB);
|
||||
TagScope intersectScope = scope("INTERSECT", tagA, tagB);
|
||||
ReviewTagMindMapEntity unionMap = tagMindMapService.regenerate(unionScope);
|
||||
tagMindMapService.regenerate(intersectScope);
|
||||
|
||||
TagMindMapSummary unionSummary = findSummary(unionScope.scopeKey());
|
||||
TagMindMapSummary intersectSummary = findSummary(intersectScope.scopeKey());
|
||||
assertNotNull(unionSummary, "已生成的导图应出现在列表里");
|
||||
assertEquals(unionMap.getId(), unionSummary.getId());
|
||||
assertEquals(unionScope.tags(), unionSummary.getTags(), "标签集合按范围名还原,前端可直接展示与复用");
|
||||
assertEquals(TagCombineModeEnum.UNION.name(), unionSummary.getMode());
|
||||
assertEquals(TagCombineModeEnum.INTERSECT.name(), intersectSummary.getMode());
|
||||
assertFalse(unionSummary.getNeedsUpdate(), "刚生成的导图不是待更新");
|
||||
assertEquals(2, unionSummary.getSourceFragmentCount().intValue(), "并集取带任一标签的两个碎片");
|
||||
assertEquals(1, intersectSummary.getSourceFragmentCount().intValue(), "交集只取同时带全部标签的碎片");
|
||||
|
||||
// 范围内出现新碎片后,列表能反映「待更新」,供前端把补充入口顶到前面
|
||||
addTag(createFragment(taskNum, "导图列表新增碎片"), tagA);
|
||||
assertTrue(findSummary(unionScope.scopeKey()).getNeedsUpdate(), "素材变化后列表能反映待更新状态");
|
||||
|
||||
// 列表按当前用户隔离
|
||||
StpUtil.login(USER + "-导图列表其他用户", "test_device");
|
||||
assertNull(findSummary(unionScope.scopeKey()), "其他用户看不到本用户的已有导图");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listMaps_pagesWithoutDuplicatesOrGaps() throws Exception {
|
||||
String taskNum = saveTask("导图分页任务-" + SEQ.incrementAndGet());
|
||||
String tagA = tag("导图分页A");
|
||||
String tagB = tag("导图分页B");
|
||||
addTag(createFragment(taskNum, "导图分页碎片A"), tagA);
|
||||
addTag(createFragment(taskNum, "导图分页碎片B"), tagB);
|
||||
TagScope scopeA = scope("UNION", tagA);
|
||||
TagScope scopeB = scope("UNION", tagB);
|
||||
tagMindMapService.regenerate(scopeA);
|
||||
tagMindMapService.regenerate(scopeB);
|
||||
|
||||
// 每页只取 1 条,逐页取完:排序不稳定时这里会重复或漏掉
|
||||
Set<String> seen = new LinkedHashSet<>();
|
||||
long total = tagMindMapService.listMaps(1, 1).getTotal();
|
||||
assertTrue(total >= 2, "本用例自己造了 2 张导图");
|
||||
for (int page = 1; page <= total; page++) {
|
||||
for (TagMindMapSummary item : tagMindMapService.listMaps(page, 1).getRecords()) {
|
||||
assertTrue(seen.add(item.getScopeKey()), "同一张导图不该跨页重复:" + item.getScopeKey());
|
||||
}
|
||||
}
|
||||
assertEquals(total, seen.size(), "逐页取完应恰好等于总数,不重不漏");
|
||||
assertTrue(seen.contains(scopeA.scopeKey()));
|
||||
assertTrue(seen.contains(scopeB.scopeKey()));
|
||||
}
|
||||
|
||||
private TagMindMapSummary findSummary(String scopeKey) {
|
||||
// 列表已分页;用例只关心「这张导图在不在列表里」
|
||||
return tagMindMapService.listMaps(1, 100).getRecords().stream()
|
||||
.filter(item -> scopeKey.equals(item.getScopeKey()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
// ============ 用户编辑与参数校验 ============
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user