feat: 新增标签导图列表接口
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.guo.learningprogresstracker.dto.TagMindMapSummary;
|
||||
import com.guo.learningprogresstracker.dto.TagMindMapView;
|
||||
import com.guo.learningprogresstracker.dto.TagScope;
|
||||
import com.guo.learningprogresstracker.dto.request.TagScopeRequest;
|
||||
@@ -56,6 +58,19 @@ public class TagMindMapController {
|
||||
return CommonResult.success(reviewTagMindMapService.updateByOutline(scope, request.getOutline()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页列出已经生成过导图的标签范围:「按标签复习」的主入口。
|
||||
*
|
||||
* <p>用户先看到已有导图(标签集合 + 取数模式),可直接进入复习或把新碎片补充进去,
|
||||
* 不必先选标签再判断这个范围有没有导图。读取不触发生成。</p>
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public CommonResult<Page<TagMindMapSummary>> list(
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize) {
|
||||
return CommonResult.success(reviewTagMindMapService.listMaps(pageNum, pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 该范围的回忆对比记录(倒序,最近一次在最前);范围里没有记录时返回空列表。
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.guo.learningprogresstracker.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 已有标签导图的摘要(闭环-04):用于「已生成的标签导图」列表。
|
||||
*
|
||||
* <p>列表是「按标签复习」的主入口:用户先看到已经生成过导图的标签集合,
|
||||
* 直接进入复习或把新碎片补充进去,不必先选标签再判断这个范围有没有导图。
|
||||
* 导图生成后标签集合一般不再变化,因此列表只读地还原 {@code tags + mode},
|
||||
* 前端可直接用它们发起复查或增量生成(与 {@code scopeKey} 一一对应)。</p>
|
||||
*/
|
||||
@Data
|
||||
public class TagMindMapSummary {
|
||||
|
||||
@Schema(description = "标签导图 ID")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "范围键:标签集合与取数模式的稳定哈希,同时作为 AI 任务的 targetNum")
|
||||
private String scopeKey;
|
||||
|
||||
@Schema(description = "范围的标签集合(展示用,按归一化名排序)")
|
||||
private List<String> tags;
|
||||
|
||||
@Schema(description = "取数模式:UNION=并集 / INTERSECT=交集")
|
||||
private String mode;
|
||||
|
||||
@Schema(description = "导图标题")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "生成来源:BUILTIN/AI/USER/USER_MERGE")
|
||||
private String generator;
|
||||
|
||||
@Schema(description = "取材的碎片数量")
|
||||
private Integer sourceFragmentCount;
|
||||
|
||||
@Schema(description = "素材变化后置 true:有新碎片待整理,重建由用户手动触发")
|
||||
private Boolean needsUpdate;
|
||||
|
||||
@Schema(description = "导图生成时间")
|
||||
private LocalDateTime generatedTime;
|
||||
}
|
||||
@@ -2,9 +2,11 @@ package com.guo.learningprogresstracker.service;
|
||||
|
||||
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;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.guo.learningprogresstracker.entity.ReviewTagMindMapEntity;
|
||||
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||
@@ -40,6 +42,14 @@ public interface ReviewTagMindMapService {
|
||||
*/
|
||||
TagMindMapView query(TagScope scope);
|
||||
|
||||
/**
|
||||
* 分页列出当前用户已经生成过导图的标签范围(待更新优先,其次按生成时间倒序)。
|
||||
*
|
||||
* <p>「按标签复习」的主入口:用户先看到已经生成过导图的标签集合,
|
||||
* 直接进入复习或把新碎片补充进去,不必先选标签再判断这个范围有没有导图。</p>
|
||||
*/
|
||||
Page<TagMindMapSummary> listMaps(int pageNum, int pageSize);
|
||||
|
||||
/**
|
||||
* 用户手动编辑标签导图(用缩进大纲文本替换);该范围还没有导图时保存即为新建。
|
||||
*/
|
||||
|
||||
+35
@@ -123,6 +123,41 @@ public class ReviewTagMindMapServiceImpl implements ReviewTagMindMapService {
|
||||
.orderByDesc(ReviewRecallRecordEntity::getCreatedTime));
|
||||
}
|
||||
|
||||
// ============ 列表 ============
|
||||
|
||||
@Override
|
||||
public Page<TagMindMapSummary> listMaps(int pageNum, int pageSize) {
|
||||
// 待更新的导图排在前面(新碎片已经等着被整理),其余按生成时间倒序;
|
||||
// id 兜底:生成时间相同的导图之间要有稳定次序,否则翻页会重复或漏掉
|
||||
Page<ReviewTagMindMapEntity> page = tagMindMapMapper.selectPage(
|
||||
new Page<>(pageNum, pageSize),
|
||||
Wrappers.<ReviewTagMindMapEntity>lambdaQuery()
|
||||
.orderByDesc(ReviewTagMindMapEntity::getNeedsUpdate)
|
||||
.orderByDesc(ReviewTagMindMapEntity::getGeneratedTime)
|
||||
.orderByDesc(ReviewTagMindMapEntity::getId));
|
||||
|
||||
Page<TagMindMapSummary> result = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
|
||||
result.setRecords(page.getRecords().stream()
|
||||
.map(ReviewTagMindMapServiceImpl::toSummary)
|
||||
.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 列表项只还原只读状态:标签集合按范围名回读,供前端直接展示与复用 */
|
||||
private static TagMindMapSummary toSummary(ReviewTagMindMapEntity entity) {
|
||||
TagMindMapSummary summary = new TagMindMapSummary();
|
||||
summary.setId(entity.getId());
|
||||
summary.setScopeKey(entity.getScopeKey());
|
||||
summary.setTags(TagScopeTool.parseStoredTags(entity.getTagNames()));
|
||||
summary.setMode(entity.getCombineMode());
|
||||
summary.setTitle(entity.getTitle());
|
||||
summary.setGenerator(entity.getGenerator());
|
||||
summary.setSourceFragmentCount(entity.getSourceFragmentCount());
|
||||
summary.setNeedsUpdate(Boolean.TRUE.equals(entity.getNeedsUpdate()));
|
||||
summary.setGeneratedTime(entity.getGeneratedTime());
|
||||
return summary;
|
||||
}
|
||||
|
||||
// ============ 用户编辑 ============
|
||||
|
||||
@Override
|
||||
|
||||
+16
@@ -1,5 +1,7 @@
|
||||
package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.guo.learningprogresstracker.dto.TagMindMapSummary;
|
||||
import com.guo.learningprogresstracker.dto.TagMindMapView;
|
||||
import com.guo.learningprogresstracker.dto.TagScope;
|
||||
import com.guo.learningprogresstracker.dto.request.TagScopeRequest;
|
||||
@@ -87,6 +89,20 @@ class TagMindMapControllerUnitTest {
|
||||
assertSame(updated, result.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_returnsExistingMaps() {
|
||||
TagMindMapSummary summary = new TagMindMapSummary();
|
||||
Page<TagMindMapSummary> page = new Page<>(1, 20, 1);
|
||||
page.setRecords(List.of(summary));
|
||||
when(reviewTagMindMapService.listMaps(1, 20)).thenReturn(page);
|
||||
|
||||
CommonResult<Page<TagMindMapSummary>> result = controller.list(1, 20);
|
||||
|
||||
assertEquals(200, result.getCode());
|
||||
assertSame(page, result.getData());
|
||||
assertEquals(1, result.getData().getTotal());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listRecallRecords_returnsRangeHistory() throws Exception {
|
||||
List<ReviewRecallRecordEntity> records = List.of(new ReviewRecallRecordEntity());
|
||||
|
||||
+66
@@ -581,6 +581,72 @@ class TagMindMapIntegrationTest {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
// ============ 报告作为导图参考上下文(报告-02) ============
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void generate_carriesSameSessionReportAsReference() throws Exception {
|
||||
String taskNum = saveTask("报告参考任务-" + SEQ.incrementAndGet());
|
||||
String tagA = tag("报告参考");
|
||||
StudyReportFragmentsEntity fragment = createFragment(taskNum, "报告参考碎片");
|
||||
addTag(fragment, tagA);
|
||||
|
||||
StudyReportsEntity report = new StudyReportsEntity();
|
||||
report.setSessionNum(fragment.getContextNum());
|
||||
report.setSessionSummary("这次学了线程池参数");
|
||||
report.setFreeSummary("还需补队列取舍");
|
||||
studyReportsMapper.insert(report);
|
||||
|
||||
when(aiServiceClient.isConfigured()).thenReturn(true);
|
||||
when(aiServiceClient.generateMindMap(any(), any(), any(), any()))
|
||||
.thenReturn(Optional.of("- 报告参考\n - 线程池参数"));
|
||||
|
||||
tagMindMapService.regenerate(scope("UNION", tagA));
|
||||
|
||||
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(1, reportsCaptor.getValue().size(), "同源会话的报告应作为参考带给 AI");
|
||||
MindMapReportContext context = reportsCaptor.getValue().get(0);
|
||||
assertEquals(fragment.getContextNum(), context.ref());
|
||||
assertEquals("这次学了线程池参数", context.sessionSummary());
|
||||
assertEquals("还需补队列取舍", context.freeSummary());
|
||||
assertEquals(1, fragmentsCaptor.getValue().size());
|
||||
assertEquals(fragment.getContextNum(), fragmentsCaptor.getValue().get(0).reportRef(),
|
||||
"碎片应标注同源报告,便于模型判断报告与碎片是否相关");
|
||||
}
|
||||
|
||||
@Test
|
||||
void reportChange_marksTaskAndTagMapsNeedsUpdate() throws Exception {
|
||||
String taskNum = saveTask("报告置位任务-" + SEQ.incrementAndGet());
|
||||
String tagA = tag("报告置位");
|
||||
StudyReportFragmentsEntity fragment = createFragment(taskNum, "报告置位碎片");
|
||||
addTag(fragment, tagA);
|
||||
|
||||
standardMindMapService.regenerate(taskNum);
|
||||
tagMindMapService.regenerate(scope("UNION", tagA));
|
||||
assertFalse(standardMindMapService.getExisting(taskNum).getNeedsUpdate());
|
||||
assertFalse(tagMindMapService.query(scope("UNION", tagA)).getMap().getNeedsUpdate());
|
||||
|
||||
StudyReportsEntity report = new StudyReportsEntity();
|
||||
report.setSessionNum(fragment.getContextNum());
|
||||
report.setSessionSummary("这次学习的总结");
|
||||
studyReportsMapper.insert(report);
|
||||
|
||||
UpdateStudyReportRequest request = new UpdateStudyReportRequest();
|
||||
request.setSessionSummary("改过的总结");
|
||||
reviewService.updateReport(report.getId(), request);
|
||||
|
||||
assertTrue(standardMindMapService.getExisting(taskNum).getNeedsUpdate(),
|
||||
"报告内容变化后任务导图应置为待更新");
|
||||
assertTrue(tagMindMapService.query(scope("UNION", tagA)).getMap().getNeedsUpdate(),
|
||||
"报告内容变化后标签导图应置为待更新");
|
||||
}
|
||||
|
||||
// ============ 用户编辑与参数校验 ============
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user