feat: 拆分记录上下文与内容归属并把报告改为结构化
This commit is contained in:
@@ -2,7 +2,9 @@ package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.ReviewFeedItem;
|
||||
import com.guo.learningprogresstracker.dto.ReviewTaskStats;
|
||||
import com.guo.learningprogresstracker.dto.StudyReportDetail;
|
||||
import com.guo.learningprogresstracker.dto.request.UpdateStandardMindMapRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.UpdateStudyReportRequest;
|
||||
import com.guo.learningprogresstracker.entity.CommonResult;
|
||||
import com.guo.learningprogresstracker.entity.ReviewRecallRecordEntity;
|
||||
import com.guo.learningprogresstracker.entity.ReviewStandardMindMapEntity;
|
||||
@@ -68,13 +70,42 @@ public class ReviewController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取报告详情
|
||||
* 获取报告详情(原始实体)
|
||||
*/
|
||||
@GetMapping("/report/{id}")
|
||||
public CommonResult<StudyReportsEntity> getReportDetail(@PathVariable int id) throws NotFindEntitiesException {
|
||||
return CommonResult.success(reviewService.getReportDetail(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取学习报告详情:三段文本 + 按当前内容归属实时聚合的碎片分组(归属-01)
|
||||
*/
|
||||
@GetMapping("/report/{id}/structured")
|
||||
public CommonResult<StudyReportDetail> getReportDetailStructured(@PathVariable int id)
|
||||
throws NotFindEntitiesException {
|
||||
return CommonResult.success(reviewService.getReportDetailStructured(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改学习报告的三段文本
|
||||
*/
|
||||
@PutMapping("/report/{id}")
|
||||
public CommonResult<Void> updateReport(@PathVariable int id,
|
||||
@RequestBody UpdateStudyReportRequest request)
|
||||
throws NotFindEntitiesException {
|
||||
reviewService.updateReport(id, request);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除学习报告(软删除)。不连带删除知识碎片:碎片是独立原料,可能已归属到其他任务。
|
||||
*/
|
||||
@DeleteMapping("/report/{id}")
|
||||
public CommonResult<Void> deleteReport(@PathVariable int id) throws NotFindEntitiesException {
|
||||
reviewService.deleteReport(id);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取残片详情
|
||||
*/
|
||||
|
||||
+3
-1
@@ -90,7 +90,9 @@ public class StudySessionController {
|
||||
@PostMapping("/{sessionNum}/study-sessions/ended")
|
||||
public CommonResult<Void> endedStudySession(@PathVariable("sessionNum") String sessionNum,
|
||||
@Valid @RequestBody EndedStudySessionRequest request) throws ErrorParameterException {
|
||||
String message = studySessionsServiceImpl.endedStudySession(sessionNum, request.getContent());
|
||||
String message = studySessionsServiceImpl.endedStudySession(sessionNum,
|
||||
new com.guo.learningprogresstracker.dto.ReportSections(
|
||||
request.getSessionSummary(), request.getExpectationVerdict(), request.getFreeSummary()));
|
||||
return message != null ? CommonResult.success(message) : CommonResult.success();
|
||||
}
|
||||
|
||||
|
||||
@@ -84,8 +84,15 @@ public class TaskController {
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
@GetMapping("/{taskId}/deletion-preview")
|
||||
@Operation(summary = "删除任务前的影响范围:将删除什么、将保留什么(碎片进入待归类)")
|
||||
public CommonResult<com.guo.learningprogresstracker.dto.TaskDeletionSummary> previewDeletion(
|
||||
@PathVariable("taskId") String taskId) {
|
||||
return CommonResult.success(tasksService.previewDeletion(taskId));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{taskId}")
|
||||
@Operation(summary = "删除指定任务")
|
||||
@Operation(summary = "删除指定任务(保留其知识碎片并进入待归类)")
|
||||
public CommonResult<Void> deleteTask(@PathVariable("taskId") String taskId) throws ServerException {
|
||||
tasksService.deleteTask(taskId);
|
||||
return CommonResult.success();
|
||||
|
||||
+34
-5
@@ -12,9 +12,10 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 学习残片控制层
|
||||
* 知识碎片控制层(归属-01 起同时承载「内容归属」的调整动作)。
|
||||
*/
|
||||
@RequestMapping("/report-fragments")
|
||||
@RestController
|
||||
@@ -24,7 +25,7 @@ public class reportFragmentsController {
|
||||
private final StudyReportFragmentsServiceImpl studyReportFragmentsServiceImpl;
|
||||
|
||||
/**
|
||||
* 创建学习残片
|
||||
* 创建知识碎片(记录上下文为当前学习会话,内容归属默认取该会话所属任务)
|
||||
*/
|
||||
@PostMapping
|
||||
public CommonResult<Void> createFragments(@Valid @RequestBody CreateFragmentsRequest request) throws NotFindEntitiesException {
|
||||
@@ -33,21 +34,49 @@ public class reportFragmentsController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新学习残片
|
||||
* 修改知识碎片正文与内容归属(记录上下文不可变)
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
public CommonResult<Void> updateFragments(@PathVariable Integer id,
|
||||
@Valid @RequestBody UpdateFragmentsRequest request) throws NotFindEntitiesException {
|
||||
@RequestBody UpdateFragmentsRequest request) throws NotFindEntitiesException {
|
||||
studyReportFragmentsServiceImpl.updateFragments(id, request);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定会话的所有学习残片
|
||||
* 调整内容归属;body 传 {"ownerTaskNum": "TASK-xxx"},传空字符串表示清空归属(回到待归类)
|
||||
*/
|
||||
@PutMapping("/{id}/ownership")
|
||||
public CommonResult<Void> assignOwnership(@PathVariable Integer id,
|
||||
@RequestBody Map<String, String> body) throws NotFindEntitiesException {
|
||||
String ownerTaskNum = body == null ? null : body.get("ownerTaskNum");
|
||||
studyReportFragmentsServiceImpl.assignOwnership(id, ownerTaskNum);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除知识碎片(软删除)
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public CommonResult<Void> deleteFragment(@PathVariable Integer id) throws NotFindEntitiesException {
|
||||
studyReportFragmentsServiceImpl.deleteFragment(id);
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定会话产生的所有知识碎片(记录上下文为会话)
|
||||
*/
|
||||
@GetMapping("/session/{sessionNum}")
|
||||
public CommonResult<List<StudyReportFragmentsEntity>> getFragmentsBySession(@PathVariable String sessionNum) {
|
||||
List<StudyReportFragmentsEntity> fragments = studyReportFragmentsServiceImpl.getFragmentsBySession(sessionNum);
|
||||
return CommonResult.success(fragments);
|
||||
}
|
||||
|
||||
/**
|
||||
* 待归类内容:还没有确定内容归属的碎片
|
||||
*/
|
||||
@GetMapping("/pending-ownership")
|
||||
public CommonResult<List<StudyReportFragmentsEntity>> getPendingOwnershipFragments() {
|
||||
return CommonResult.success(studyReportFragmentsServiceImpl.getPendingOwnershipFragments());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.guo.learningprogresstracker.dto;
|
||||
|
||||
/**
|
||||
* 学习报告的三段文本(归属-01 / 报告-01)。
|
||||
*
|
||||
* <p>报告的第四部分「按归属分组的碎片」不在此列:它是查看时按当前内容归属实时聚合的视图,不落库。</p>
|
||||
*
|
||||
* @param sessionSummary 会话摘要:这次实际学了什么
|
||||
* @param expectationVerdict 预期达成判断:对照学习预期得出的结论
|
||||
* @param freeSummary 自由总结:用户对本次学习的叙述
|
||||
*/
|
||||
public record ReportSections(String sessionSummary, String expectationVerdict, String freeSummary) {
|
||||
|
||||
/** 三段是否都为空 */
|
||||
public boolean isEmpty() {
|
||||
return isBlank(sessionSummary) && isBlank(expectationVerdict) && isBlank(freeSummary);
|
||||
}
|
||||
|
||||
private static boolean isBlank(String text) {
|
||||
return text == null || text.isBlank();
|
||||
}
|
||||
|
||||
/** 报告落库时的兜底:至少保留一段,避免出现完全空的报告 */
|
||||
public ReportSections orFallbackTo(String fallback) {
|
||||
if (!isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return new ReportSections(null, null, fallback);
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,38 @@ import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 复习滚动 feed 条目;首页仅使用残片,任务详情仍可同时包含报告和残片
|
||||
* 复习滚动 feed 条目 / 任务记录条目。
|
||||
*
|
||||
* <p>归属-01 之后这里同时承载两个维度,不要混用:</p>
|
||||
* <ul>
|
||||
* <li>{@code taskNum} / {@code taskName} 是<b>内容归属</b>:碎片取它自己的归属任务,
|
||||
* 报告取产生它的会话所属任务(报告按会话生成)。</li>
|
||||
* <li>{@code contextType} / {@code contextNum} 是<b>记录上下文</b>:这条内容产生于哪次学习会话
|
||||
* 或复习行为,用于界面按来源分组。</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Data
|
||||
public class ReviewFeedItem {
|
||||
private Integer id;
|
||||
private String sessionNum;
|
||||
|
||||
/** REPORT | FRAGMENT */
|
||||
private String sourceType;
|
||||
|
||||
/** 内容归属的任务编号;碎片待归类时为 null */
|
||||
private String taskNum;
|
||||
|
||||
private String taskName;
|
||||
private String sourceType; // REPORT | FRAGMENT
|
||||
|
||||
private String content;
|
||||
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
/** 仅碎片有意义:内容归属为空,等待归类 */
|
||||
private boolean pendingOwnership;
|
||||
|
||||
/** 记录上下文类型:SESSION | REVIEW */
|
||||
private String contextType;
|
||||
|
||||
/** 记录上下文编号:学习会话编号或复习行为编号 */
|
||||
private String contextNum;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.guo.learningprogresstracker.dto;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学习报告详情(归属-01:结构化报告)。
|
||||
*
|
||||
* <p>报告由四部分组成,其中前三部分是落库的文本,第四部分是<b>实时聚合</b>出来的视图:</p>
|
||||
* <ol>
|
||||
* <li>会话摘要</li>
|
||||
* <li>预期达成判断</li>
|
||||
* <li>按内容归属分组的碎片 —— 查看时按碎片的<b>当前</b>归属聚合,不落库。
|
||||
* 这样它与标准导图的取材口径始终一致,不会出现「报告说属于甲、导图放在乙」。</li>
|
||||
* <li>自由总结</li>
|
||||
* </ol>
|
||||
*/
|
||||
@Data
|
||||
public class StudyReportDetail {
|
||||
|
||||
private Integer id;
|
||||
|
||||
/** 产生这份报告的会话 */
|
||||
private String sessionNum;
|
||||
|
||||
/** 产生这份报告的会话所属任务(报告按会话生成,这是「这次学习属于哪个任务」) */
|
||||
private String sessionTaskNum;
|
||||
|
||||
private String sessionTaskName;
|
||||
|
||||
/** 会话对应的学习预期 */
|
||||
private String sessionExpectation;
|
||||
|
||||
@Schema(description = "会话摘要:这次实际学了什么")
|
||||
private String sessionSummary;
|
||||
|
||||
@Schema(description = "预期达成判断:对照学习预期得出的结论")
|
||||
private String expectationVerdict;
|
||||
|
||||
@Schema(description = "自由总结:用户对本次学习的叙述")
|
||||
private String freeSummary;
|
||||
|
||||
private java.time.LocalDateTime createdTime;
|
||||
|
||||
@Schema(description = "按当前内容归属分组的碎片")
|
||||
private List<FragmentGroup> fragmentGroups = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 一条碎片按内容归属分组的结果。
|
||||
*/
|
||||
@Data
|
||||
public static class FragmentGroup {
|
||||
|
||||
/** 归属任务编号;null 表示待归类 */
|
||||
private String taskNum;
|
||||
|
||||
private String taskName;
|
||||
|
||||
/** 是否「旁支」:归属不等于本次报告所属会话的任务 */
|
||||
private boolean branch;
|
||||
|
||||
private List<StudyReportFragmentsEntity> fragments = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static StudyReportDetail of(StudyReportsEntity report) {
|
||||
StudyReportDetail detail = new StudyReportDetail();
|
||||
detail.setId(report.getId());
|
||||
detail.setSessionNum(report.getSessionNum());
|
||||
detail.setSessionSummary(report.getSessionSummary());
|
||||
detail.setExpectationVerdict(report.getExpectationVerdict());
|
||||
detail.setFreeSummary(report.getFreeSummary());
|
||||
detail.setCreatedTime(report.getCreatedTime());
|
||||
detail.setSessionExpectation(report.getSessionExpectation());
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.guo.learningprogresstracker.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 删除学习任务的影响范围(归属-01)。
|
||||
*
|
||||
* <p>删除确认弹窗必须分别列出「即将删除」与「即将保留」,避免用户以为删干净了:
|
||||
* 知识碎片会保留下来并进入待归类。</p>
|
||||
*/
|
||||
@Data
|
||||
public class TaskDeletionSummary {
|
||||
|
||||
@Schema(description = "将保留的知识碎片条数(内容归属置空,进入待归类)")
|
||||
private int releasedFragments;
|
||||
|
||||
@Schema(description = "将软删除的学习会话数")
|
||||
private int deletedSessions;
|
||||
|
||||
@Schema(description = "将软删除的学习报告数")
|
||||
private int deletedReports;
|
||||
|
||||
@Schema(description = "将软删除的标准思维导图数")
|
||||
private int deletedMindMaps;
|
||||
|
||||
@Schema(description = "将软删除的回忆记录数")
|
||||
private int deletedRecallRecords;
|
||||
|
||||
@Schema(description = "将软删除的应用场景数")
|
||||
private int deletedApplications;
|
||||
}
|
||||
+2
-2
@@ -9,9 +9,9 @@ import lombok.Data;
|
||||
@Data
|
||||
public class CreateFragmentsRequest {
|
||||
/**
|
||||
* 会话编号
|
||||
* 记录上下文编号:产生这条碎片的学习会话编号(归属-01 起上下文由类型 + 编号共同描述)
|
||||
*/
|
||||
private String sessionNum;
|
||||
private String contextNum;
|
||||
|
||||
/**
|
||||
* 残片内容,学习内容的描述
|
||||
|
||||
+13
-4
@@ -1,13 +1,22 @@
|
||||
package com.guo.learningprogresstracker.dto.request;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author guo
|
||||
* 结束学习会话时提交的学习报告(归属-01 起报告为结构化三段)。
|
||||
*
|
||||
* <p>三段都可为空,但至少要有一段;第四部分「按归属分组的碎片」是实时聚合的视图,不需要提交。</p>
|
||||
*/
|
||||
@Data
|
||||
public class EndedStudySessionRequest {
|
||||
@NotBlank(message = "请填写学习报告内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "会话摘要:这次实际学了什么")
|
||||
private String sessionSummary;
|
||||
|
||||
@Schema(description = "预期达成判断:对照学习预期得出的结论")
|
||||
private String expectationVerdict;
|
||||
|
||||
@Schema(description = "自由总结:用户对本次学习的叙述")
|
||||
private String freeSummary;
|
||||
}
|
||||
|
||||
+8
-4
@@ -1,16 +1,20 @@
|
||||
package com.guo.learningprogresstracker.dto.request;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author guo
|
||||
* 修改知识碎片:只允许改正文与内容归属,记录上下文不可变。
|
||||
*/
|
||||
@Data
|
||||
public class UpdateFragmentsRequest {
|
||||
/**
|
||||
* 残片内容,学习内容的描述
|
||||
* 残片内容(学习内容的描述);为空表示本次不改正文
|
||||
*/
|
||||
@NotBlank(message = "请填写学习内容")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 内容归属的任务编号;不传表示本次不改归属。
|
||||
* <p>若要清空归属(回到待归类),传空字符串。</p>
|
||||
*/
|
||||
private String ownerTaskNum;
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.guo.learningprogresstracker.dto.request;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 修改学习报告的三段文本(归属-01 / 报告-01)。
|
||||
*
|
||||
* <p>不传或传 null 表示本次不改该段;传空字符串表示清空该段。</p>
|
||||
*/
|
||||
@Data
|
||||
public class UpdateStudyReportRequest {
|
||||
|
||||
@Schema(description = "会话摘要:这次实际学了什么")
|
||||
private String sessionSummary;
|
||||
|
||||
@Schema(description = "预期达成判断:对照学习预期得出的结论")
|
||||
private String expectationVerdict;
|
||||
|
||||
@Schema(description = "自由总结:用户对本次学习的叙述")
|
||||
private String freeSummary;
|
||||
}
|
||||
@@ -58,6 +58,15 @@ public class ReviewStandardMindMapEntity extends BaseEntity implements Serializa
|
||||
@TableField(value = "generated_time")
|
||||
private LocalDateTime generatedTime;
|
||||
|
||||
/**
|
||||
* 内容归属发生变化后置为 true,表示这张导图需要重建;重建由用户手动触发(归属-01)
|
||||
*/
|
||||
@TableField(value = "needs_update")
|
||||
private Boolean needsUpdate;
|
||||
|
||||
@TableField(value = "needs_update_time")
|
||||
private LocalDateTime needsUpdateTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
+38
-14
@@ -4,36 +4,60 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.guo.learningprogresstracker.enums.FragmentContextTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 记录学习过程中的学习内容报告残片
|
||||
* @TableName study_report_fragments
|
||||
* 记录学习过程中的学习内容报告残片(知识碎片)。
|
||||
*
|
||||
* <p>归属-01 后本实体承载两个互相独立的维度:</p>
|
||||
* <ul>
|
||||
* <li><b>记录上下文</b>({@code contextType} + {@code contextNum}):产生于哪次学习会话或复习行为,
|
||||
* 由系统确定、不可变、不可为空,用于时间统计与报告归属。</li>
|
||||
* <li><b>内容归属</b>({@code ownerTaskNum}):内容在知识结构上属于哪个任务,由用户确定、可变、可为空
|
||||
* (为空即「待归类」),用于导图取材与按任务聚合。</li>
|
||||
* </ul>
|
||||
*/
|
||||
@TableName(value ="study_report_fragments")
|
||||
@TableName(value = "study_report_fragments")
|
||||
@Data
|
||||
public class StudyReportFragmentsEntity extends BaseEntity implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
*
|
||||
* 记录上下文编号:学习会话编号或复习行为编号
|
||||
*/
|
||||
@TableField(value = "session_num")
|
||||
private String sessionNum;
|
||||
@TableField(value = "context_num")
|
||||
private String contextNum;
|
||||
|
||||
/**
|
||||
* 学习内容的描述
|
||||
* 记录上下文类型:SESSION / REVIEW
|
||||
*/
|
||||
@TableField(value = "context_type")
|
||||
private String contextType;
|
||||
|
||||
/**
|
||||
* 内容归属的学习任务编号;null 表示待归类
|
||||
*/
|
||||
@TableField(value = "owner_task_num")
|
||||
private String ownerTaskNum;
|
||||
|
||||
@TableField(value = "content")
|
||||
private String content;
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
/** 是否来自学习会话(记录上下文为 SESSION) */
|
||||
public boolean fromSession() {
|
||||
return FragmentContextTypeEnum.SESSION.name().equals(contextType);
|
||||
}
|
||||
|
||||
/** 是否待归类(没有内容归属) */
|
||||
public boolean isPendingOwnership() {
|
||||
return ownerTaskNum == null || ownerTaskNum.isBlank();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,41 +4,51 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 存储每次学习结束时的完整学习报告
|
||||
* @TableName study_reports
|
||||
* 存储每次学习结束时的完整学习报告。
|
||||
*
|
||||
* <p>报告按会话生成,是「这次学习产出了什么」的事实记录,三部分为文本:
|
||||
* 会话摘要、预期达成判断、自由总结。报告的第四部分「按归属分组的碎片」不落库,
|
||||
* 查看时按碎片的当前内容归属实时聚合(见 lpt-docs「内容归属」实现级结论 4)。</p>
|
||||
*/
|
||||
@TableName(value ="study_reports")
|
||||
@TableName(value = "study_reports")
|
||||
@Data
|
||||
public class StudyReportsEntity extends BaseEntity implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 会话编码
|
||||
*/
|
||||
@TableField(value = "session_num")
|
||||
private String sessionNum;
|
||||
|
||||
/**
|
||||
* 完整的学习报告内容
|
||||
* 会话摘要:这次实际学了什么
|
||||
*/
|
||||
@TableField(value = "content")
|
||||
private String content;
|
||||
@TableField(value = "session_summary")
|
||||
private String sessionSummary;
|
||||
|
||||
/**
|
||||
* 对应学习会话的预期目标(非数据库字段,查询时填充)
|
||||
* 预期达成判断:对照学习预期得出的结论
|
||||
*/
|
||||
@TableField(value = "expectation_verdict")
|
||||
private String expectationVerdict;
|
||||
|
||||
/**
|
||||
* 自由总结:用户对本次学习的叙述
|
||||
*/
|
||||
@TableField(value = "free_summary")
|
||||
private String freeSummary;
|
||||
|
||||
/**
|
||||
* 会话对应的学习预期,仅用于返回,不落库
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String sessionExpectation;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.guo.learningprogresstracker.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 知识碎片的记录上下文类型(归属-01)。
|
||||
*
|
||||
* <p>记录上下文回答「这条碎片是在哪次学习行为里产生的」,不可变、不可为空。
|
||||
* 它是时间轴上的归因,与「内容归属」(内容属于哪个任务)是两件事。</p>
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum FragmentContextTypeEnum {
|
||||
|
||||
/** 产生于某次学习会话 */
|
||||
SESSION("学习会话"),
|
||||
|
||||
/** 产生于某次复习行为(回忆对比、学习引导) */
|
||||
REVIEW("复习行为");
|
||||
|
||||
private final String description;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.guo.learningprogresstracker.service;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.guo.learningprogresstracker.utils.MindMapNode;
|
||||
@@ -24,13 +24,13 @@ public interface MindMapAiClient {
|
||||
* 根据学习数据生成标准思维导图根节点
|
||||
*
|
||||
* @param task 学习任务
|
||||
* @param reports 该任务的全部学习报告
|
||||
* @param fragments 该任务名下的知识碎片(**按内容归属取**,不是按产生它的会话取)
|
||||
* @param applications 该任务的应用场景(可选)
|
||||
* @param clientHint 前端已有的大纲文本(可选,用于 AI 续写而非全量生成)
|
||||
* @return 标准思维导图的根节点;若无可生成数据则返回 {@link Optional#empty()}
|
||||
*/
|
||||
Optional<MindMapNode> generate(TaskEntity task,
|
||||
List<StudyReportsEntity> reports,
|
||||
List<StudyReportFragmentsEntity> fragments,
|
||||
List<TaskApplicationEntity> applications,
|
||||
String clientHint);
|
||||
|
||||
|
||||
@@ -38,6 +38,25 @@ public interface ReviewService {
|
||||
*/
|
||||
StudyReportsEntity getReportDetail(int id) throws NotFindEntitiesException;
|
||||
|
||||
/**
|
||||
* 学习报告详情:三段文本 + 按当前内容归属实时聚合的碎片分组(归属-01)。
|
||||
*/
|
||||
com.guo.learningprogresstracker.dto.StudyReportDetail getReportDetailStructured(int id)
|
||||
throws NotFindEntitiesException;
|
||||
|
||||
/**
|
||||
* 修改学习报告的三段文本。
|
||||
* <p>只允许改这三段;报告所属会话与生成时间不可变。</p>
|
||||
*/
|
||||
void updateReport(int id, com.guo.learningprogresstracker.dto.request.UpdateStudyReportRequest request)
|
||||
throws NotFindEntitiesException;
|
||||
|
||||
/**
|
||||
* 删除学习报告(软删除)。
|
||||
* <p>不连带删除该会话产生的知识碎片:碎片是独立原料,且可能已被归类到其他任务。</p>
|
||||
*/
|
||||
void deleteReport(int id) throws NotFindEntitiesException;
|
||||
|
||||
/**
|
||||
* 获取残片详情
|
||||
*/
|
||||
|
||||
+15
@@ -20,4 +20,19 @@ public interface StudyReportFragmentsService extends IService<StudyReportFragmen
|
||||
void updateFragments(Integer id, UpdateFragmentsRequest request) throws NotFindEntitiesException;
|
||||
|
||||
List<StudyReportFragmentsEntity> getFragmentsBySession(String sessionNum);
|
||||
|
||||
/**
|
||||
* 修改内容归属(归属-01)。传空表示清空归属、回到待归类。
|
||||
* <p>归属变化会把原任务与新任务的导图标记为待更新。</p>
|
||||
*/
|
||||
void assignOwnership(Integer id, String ownerTaskNum) throws NotFindEntitiesException;
|
||||
|
||||
/** 删除知识碎片(软删除);所属任务的导图会被标记为待更新 */
|
||||
void deleteFragment(Integer id) throws NotFindEntitiesException;
|
||||
|
||||
/** 待归类内容:没有内容归属的碎片,按时间倒序 */
|
||||
List<StudyReportFragmentsEntity> getPendingOwnershipFragments();
|
||||
|
||||
/** 待归类内容的条数,用于复习总览的独立区块 */
|
||||
long countPendingOwnershipFragments();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,13 @@ public interface StudySessionsService extends IService<StudySessionsEntity> {
|
||||
|
||||
ArrayList<String> getAllFragments(String sessionNum) throws ErrorParameterException;
|
||||
|
||||
String endedStudySession(String sessionNum, String content) throws ErrorParameterException;
|
||||
/**
|
||||
* 结束学习会话并保存结构化学习报告(三段)。
|
||||
*
|
||||
* @return 需要提示给用户的消息(如有效时间不足),无提示时返回 null
|
||||
*/
|
||||
String endedStudySession(String sessionNum, com.guo.learningprogresstracker.dto.ReportSections report)
|
||||
throws ErrorParameterException;
|
||||
|
||||
/**
|
||||
* 误操作结束学习会话:需输入确认语,严格零数据(删除会话与预期),仅未产生学习残片时可用
|
||||
@@ -46,7 +52,8 @@ public interface StudySessionsService extends IService<StudySessionsEntity> {
|
||||
*
|
||||
* <p>由 AI 任务执行器调用,不在请求线程内执行(AI-02)。</p>
|
||||
*/
|
||||
String buildReportDraft(String sessionNum) throws ErrorParameterException;
|
||||
com.guo.learningprogresstracker.dto.ReportSections buildReportDraft(String sessionNum)
|
||||
throws ErrorParameterException;
|
||||
|
||||
/**
|
||||
* 惰性收敛(会话-04):把当前用户悬挂的进行中会话按硬兜底阈值强制暂停。
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.guo.learningprogresstracker.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.guo.learningprogresstracker.dto.TaskDeletionSummary;
|
||||
import com.guo.learningprogresstracker.dto.TaskInfo;
|
||||
import com.guo.learningprogresstracker.dto.request.CreateTaskApplicationRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
@@ -32,6 +33,11 @@ public interface TasksService extends IService<TaskEntity> {
|
||||
|
||||
void deleteTask(String taskId) throws ServerException;
|
||||
|
||||
/**
|
||||
* 删除任务前的影响范围预览(归属-01):弹窗要分别列出「即将删除」与「即将保留(进入待归类)」
|
||||
*/
|
||||
TaskDeletionSummary previewDeletion(String taskId);
|
||||
|
||||
List<TaskApplicationEntity> getApplications(String taskNum) throws NotFindEntitiesException;
|
||||
|
||||
TaskApplicationEntity createApplication(CreateTaskApplicationRequest request) throws NotFindEntitiesException;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.guo.learningprogresstracker.dto.ReportSections;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.Setter;
|
||||
@@ -69,9 +70,12 @@ public class AiServiceClient {
|
||||
// ============ 公开 API(签名不变,内部改为 submit + poll)============
|
||||
|
||||
/**
|
||||
* 调用 lpt-ai 将残片聚合为学习报告草稿。
|
||||
* 调用 lpt-ai 将碎片聚合为结构化学习报告草稿(三段)。
|
||||
*
|
||||
* <p>lpt-ai 侧要求返回严格 JSON;它自身对「返回了纯文本」也做了降级(整段当作自由总结),
|
||||
* 因此这里只负责把三段取出来。取不到时返回 empty,由调用方走规则降级。</p>
|
||||
*/
|
||||
public Optional<String> aggregateReport(String taskName, List<String> fragments, String expectation) {
|
||||
public Optional<ReportSections> aggregateReport(String taskName, List<String> fragments, String expectation) {
|
||||
if (!isConfigured() || fragments == null || fragments.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -84,18 +88,29 @@ public class AiServiceClient {
|
||||
: Map.of("taskName", taskName, "fragments", fragmentBodies, "expectation", expectation);
|
||||
|
||||
Optional<JsonNode> result = submitAndWait("aggregate-report", params);
|
||||
return result.map(r -> r.path("report").asText(null)).filter(s -> s != null && !s.isBlank());
|
||||
return result.map(r -> new ReportSections(
|
||||
textOrNull(r, "sessionSummary"),
|
||||
textOrNull(r, "expectationVerdict"),
|
||||
textOrNull(r, "freeSummary")
|
||||
)).filter(sections -> !sections.isEmpty());
|
||||
} catch (Exception e) {
|
||||
log.warn("lpt-ai 聚合报告异常,将降级: {}", e.getMessage());
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private static String textOrNull(JsonNode node, String field) {
|
||||
String value = node.path(field).asText(null);
|
||||
return value != null && !value.isBlank() ? value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用 lpt-ai 从学习报告生成思维导图大纲。
|
||||
* 调用 lpt-ai 从知识碎片生成思维导图大纲。
|
||||
*
|
||||
* @param fragments 该任务名下的知识碎片正文(按内容归属取)
|
||||
*/
|
||||
public Optional<String> generateMindMap(String taskName, String taskDescription,
|
||||
List<String> reports) {
|
||||
List<String> fragments) {
|
||||
if (!isConfigured()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -103,7 +118,7 @@ public class AiServiceClient {
|
||||
Map<String, Object> params = Map.of(
|
||||
"taskName", taskName,
|
||||
"taskDescription", taskDescription != null ? taskDescription : "",
|
||||
"reports", reports != null ? reports : List.of()
|
||||
"fragments", fragments != null ? fragments : List.of()
|
||||
);
|
||||
|
||||
Optional<JsonNode> result = submitAndWait("generate-mind-map", params);
|
||||
|
||||
+31
-26
@@ -1,6 +1,6 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.guo.learningprogresstracker.service.MindMapAiClient;
|
||||
@@ -15,12 +15,16 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 内置规则引擎:从学习报告提取内容并组织为树形思维导图。
|
||||
* 内置规则引擎:从知识碎片提取内容并组织为树形思维导图(AI 不可用时的降级路径)。
|
||||
*
|
||||
* <p>素材按**内容归属**给:一个任务名下的碎片,而不是产生于该任务会话的报告。
|
||||
* 因此学 A 时记下但归属到 B 的旁支知识,会出现在 B 的导图里。</p>
|
||||
*
|
||||
* <p>规则策略:</p>
|
||||
* <ol>
|
||||
* <li>根节点 = 任务名称</li>
|
||||
* <li>一级分支 = 按会话(日期+报告摘要)分组</li>
|
||||
* <li>二级分支 = 该会话下的报告</li>
|
||||
* <li>一级分支 = 按记录上下文(日期 + 首条碎片摘要)分组</li>
|
||||
* <li>二级分支 = 该上下文下的碎片</li>
|
||||
* <li>附加分支"应用场景" = 任务应用场景(如有)</li>
|
||||
* <li>去重:标准化后标题对比,合并内容相似的节点</li>
|
||||
* <li>引用追溯:每个节点携带 sourceType / sourceId</li>
|
||||
@@ -44,44 +48,45 @@ public class BuiltinMindMapGenerator implements MindMapAiClient {
|
||||
|
||||
@Override
|
||||
public Optional<MindMapNode> generate(TaskEntity task,
|
||||
List<StudyReportsEntity> reports,
|
||||
List<StudyReportFragmentsEntity> fragments,
|
||||
List<TaskApplicationEntity> applications,
|
||||
String clientHint) {
|
||||
if (reports == null || reports.isEmpty()) {
|
||||
if (fragments == null || fragments.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
MindMapNode root = new MindMapNode(task.getTaskName() != null ? task.getTaskName() : "学习任务");
|
||||
root.setNotes(task.getTaskDescription() != null ? task.getTaskDescription() : "");
|
||||
|
||||
// 按 session 分组
|
||||
Map<String, List<StudyReportsEntity>> reportsBySession = reports.stream()
|
||||
.filter(r -> r.getSessionNum() != null)
|
||||
.collect(Collectors.groupingBy(StudyReportsEntity::getSessionNum));
|
||||
// 按记录上下文分组:同一次学习会话(或复习行为)产生的碎片归在一支下
|
||||
Map<String, List<StudyReportFragmentsEntity>> fragmentsByContext = fragments.stream()
|
||||
.filter(f -> f.getContextNum() != null)
|
||||
.collect(Collectors.groupingBy(StudyReportFragmentsEntity::getContextNum,
|
||||
LinkedHashMap::new, Collectors.toList()));
|
||||
|
||||
for (Map.Entry<String, List<StudyReportsEntity>> entry : reportsBySession.entrySet()) {
|
||||
List<StudyReportsEntity> sessReports = entry.getValue();
|
||||
for (Map.Entry<String, List<StudyReportFragmentsEntity>> entry : fragmentsByContext.entrySet()) {
|
||||
List<StudyReportFragmentsEntity> contextFragments = entry.getValue();
|
||||
|
||||
// 会话分支标题:取第一条报告的前 60 字作为摘要
|
||||
StudyReportsEntity firstReport = sessReports.get(0);
|
||||
String sessionTitle = truncate(firstReport.getContent(), MAX_TITLE_LENGTH);
|
||||
if (firstReport.getCreatedTime() != null) {
|
||||
sessionTitle = formatDate(firstReport.getCreatedTime()) + " " + sessionTitle;
|
||||
// 分支标题:日期 + 第一条碎片的前 60 字
|
||||
StudyReportFragmentsEntity first = contextFragments.get(0);
|
||||
String contextTitle = truncate(first.getContent(), MAX_TITLE_LENGTH);
|
||||
if (first.getCreatedTime() != null) {
|
||||
contextTitle = formatDate(first.getCreatedTime()) + " " + contextTitle;
|
||||
}
|
||||
|
||||
MindMapNode sessionNode = new MindMapNode(sessionTitle);
|
||||
MindMapNode contextNode = new MindMapNode(contextTitle);
|
||||
|
||||
for (StudyReportsEntity report : sessReports) {
|
||||
String content = report.getContent();
|
||||
for (StudyReportFragmentsEntity fragment : contextFragments) {
|
||||
String content = fragment.getContent();
|
||||
if (content == null || content.isBlank()) continue;
|
||||
MindMapNode reportNode = new MindMapNode(truncate(content, MAX_TITLE_LENGTH));
|
||||
reportNode.setNotes(content);
|
||||
reportNode.setSourceType("REPORT");
|
||||
reportNode.setSourceId(report.getId());
|
||||
sessionNode.getChildren().add(reportNode);
|
||||
MindMapNode fragmentNode = new MindMapNode(truncate(content, MAX_TITLE_LENGTH));
|
||||
fragmentNode.setNotes(content);
|
||||
fragmentNode.setSourceType("FRAGMENT");
|
||||
fragmentNode.setSourceId(fragment.getId());
|
||||
contextNode.getChildren().add(fragmentNode);
|
||||
}
|
||||
|
||||
root.getChildren().add(sessionNode);
|
||||
root.getChildren().add(contextNode);
|
||||
}
|
||||
|
||||
// 应用场景分支(如有)
|
||||
|
||||
@@ -124,6 +124,28 @@ public class ExportServiceImpl implements ExportService {
|
||||
return buildResult(document, safeFormat, "LPT-学习数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 报告的导出正文:结构化报告由三段文本组成,导出时按段拼成可独立阅读的文本。
|
||||
* 第四段「按归属分组的碎片」是实时聚合的视图,不在这里重复导出(碎片本身会各自导出)。
|
||||
*/
|
||||
private static String reportFreeText(StudyReportsEntity report) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
appendSection(text, "会话摘要", report.getSessionSummary());
|
||||
appendSection(text, "预期达成判断", report.getExpectationVerdict());
|
||||
appendSection(text, "自由总结", report.getFreeSummary());
|
||||
return text.length() == 0 ? "" : text.toString().trim();
|
||||
}
|
||||
|
||||
private static void appendSection(StringBuilder text, String title, String body) {
|
||||
if (body == null || body.isBlank()) {
|
||||
return;
|
||||
}
|
||||
if (text.length() > 0) {
|
||||
text.append("\n\n");
|
||||
}
|
||||
text.append("【").append(title).append("】\n").append(body.trim());
|
||||
}
|
||||
|
||||
/** 任务级导出:把 feed 条目按来源拆成报告与碎片 */
|
||||
private void applyFeedItems(ExportTaskSection section, List<ReviewFeedItem> items) {
|
||||
if (items == null) {
|
||||
@@ -132,7 +154,7 @@ public class ExportServiceImpl implements ExportService {
|
||||
for (ReviewFeedItem item : items) {
|
||||
ExportEntry entry = new ExportEntry();
|
||||
entry.setId(item.getId());
|
||||
entry.setSessionNum(item.getSessionNum());
|
||||
entry.setSessionNum(item.getContextNum());
|
||||
entry.setCreatedTime(item.getCreatedTime());
|
||||
entry.setContent(item.getContent());
|
||||
if (SOURCE_REPORT.equals(item.getSourceType())) {
|
||||
@@ -152,10 +174,11 @@ public class ExportServiceImpl implements ExportService {
|
||||
List<StudyReportFragmentsEntity> fragments) {
|
||||
List<RangeItem> items = new ArrayList<>();
|
||||
for (StudyReportsEntity report : reports) {
|
||||
items.add(new RangeItem(report.getSessionNum(), report.getId(), report.getCreatedTime(), report.getContent(), true));
|
||||
items.add(new RangeItem(report.getSessionNum(), report.getId(), report.getCreatedTime(),
|
||||
reportFreeText(report), true));
|
||||
}
|
||||
for (StudyReportFragmentsEntity fragment : fragments) {
|
||||
items.add(new RangeItem(fragment.getSessionNum(), fragment.getId(), fragment.getCreatedTime(), fragment.getContent(), false));
|
||||
items.add(new RangeItem(fragment.getContextNum(), fragment.getId(), fragment.getCreatedTime(), fragment.getContent(), false));
|
||||
}
|
||||
items.sort(Comparator.comparing(RangeItem::createdTime, Comparator.nullsLast(Comparator.reverseOrder())));
|
||||
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.guo.learningprogresstracker.service.MindMapAiClient;
|
||||
@@ -38,27 +38,27 @@ public class RemoteAiMindMapClient implements MindMapAiClient {
|
||||
|
||||
@Override
|
||||
public Optional<MindMapNode> generate(TaskEntity task,
|
||||
List<StudyReportsEntity> reports,
|
||||
List<StudyReportFragmentsEntity> fragments,
|
||||
List<TaskApplicationEntity> applications,
|
||||
String clientHint) {
|
||||
if (!isAvailable()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
// 提取学习报告的内容文本
|
||||
List<String> reportTexts = reports.stream()
|
||||
.map(StudyReportsEntity::getContent)
|
||||
// 素材是「该任务名下的知识碎片」(按内容归属取),旁支知识因此会进入它真正的归属任务
|
||||
List<String> fragmentTexts = fragments == null ? List.of() : fragments.stream()
|
||||
.map(StudyReportFragmentsEntity::getContent)
|
||||
.filter(c -> c != null && !c.isBlank())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (reportTexts.isEmpty()) {
|
||||
if (fragmentTexts.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
Optional<String> optOutline = aiServiceClient.generateMindMap(
|
||||
task.getTaskName(),
|
||||
task.getTaskDescription(),
|
||||
reportTexts
|
||||
fragmentTexts
|
||||
);
|
||||
|
||||
if (optOutline.isEmpty() || optOutline.get().isBlank()) {
|
||||
|
||||
+6
-2
@@ -1,6 +1,7 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.AiTaskEntity;
|
||||
import com.guo.learningprogresstracker.dto.ReportSections;
|
||||
import com.guo.learningprogresstracker.enums.AiTaskTypeEnum;
|
||||
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||
import com.guo.learningprogresstracker.service.StudySessionsService;
|
||||
@@ -32,9 +33,12 @@ public class ReportDraftAiTaskHandler implements AiTaskHandler {
|
||||
@Override
|
||||
public Map<String, Object> execute(AiTaskEntity task, Map<String, Object> params) {
|
||||
try {
|
||||
String draft = studySessionsService.buildReportDraft(task.getTargetNum());
|
||||
ReportSections draft = studySessionsService.buildReportDraft(task.getTargetNum());
|
||||
Map<String, Object> payload = new LinkedHashMap<>();
|
||||
payload.put("draft", draft);
|
||||
// 结构化报告草稿:三段分别返回,前端在结束会话弹窗里分别可编辑
|
||||
payload.put("sessionSummary", draft.sessionSummary());
|
||||
payload.put("expectationVerdict", draft.expectationVerdict());
|
||||
payload.put("freeSummary", draft.freeSummary());
|
||||
return payload;
|
||||
} catch (ErrorParameterException e) {
|
||||
throw new AiTaskFailedException(e.getMessage());
|
||||
|
||||
+149
-35
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.guo.learningprogresstracker.dto.IdRange;
|
||||
import com.guo.learningprogresstracker.dto.ReviewFeedItem;
|
||||
import com.guo.learningprogresstracker.dto.ReviewTaskStats;
|
||||
import com.guo.learningprogresstracker.dto.StudyReportDetail;
|
||||
import com.guo.learningprogresstracker.dto.TaskContentCount;
|
||||
import com.guo.learningprogresstracker.dto.TaskReviewDuration;
|
||||
import com.guo.learningprogresstracker.dto.TaskSessionStats;
|
||||
@@ -12,13 +13,16 @@ 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.exception.NotFindEntitiesException;
|
||||
import com.guo.learningprogresstracker.mapper.ReviewRecallRecordMapper;
|
||||
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.dto.request.UpdateStudyReportRequest;
|
||||
import com.guo.learningprogresstracker.service.ReviewService;
|
||||
import com.guo.learningprogresstracker.service.StudyExpectationsService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -45,12 +49,17 @@ public class ReviewServiceImpl implements ReviewService {
|
||||
private static final String RANDOM_MODE = "random";
|
||||
private static final String SMART_MODE = "smart";
|
||||
private static final int SMART_CANDIDATE_MULTIPLIER = 5;
|
||||
private static final String SOURCE_REPORT = "REPORT";
|
||||
private static final String SOURCE_FRAGMENT = "FRAGMENT";
|
||||
/** 待归类分组在内部的键名(不会作为任务编号出现在响应里,响应里 taskNum 为 null) */
|
||||
private static final String PENDING_OWNERSHIP_KEY = "__PENDING__";
|
||||
|
||||
private final StudyReportsMapper studyReportsMapper;
|
||||
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
|
||||
private final StudySessionsMapper studySessionsMapper;
|
||||
private final TasksMapper tasksMapper;
|
||||
private final ReviewRecallRecordMapper reviewRecallRecordMapper;
|
||||
private final StudyExpectationsService studyExpectationsService;
|
||||
|
||||
@Override
|
||||
public List<ReviewFeedItem> getReviewFeed(int limit, String mode) {
|
||||
@@ -231,6 +240,7 @@ public class ReviewServiceImpl implements ReviewService {
|
||||
|
||||
@Override
|
||||
public List<ReviewFeedItem> getTaskReview(String taskNum) {
|
||||
// 报告按会话生成:取属于该任务的会话所产生的报告
|
||||
List<String> sessionNums = studySessionsMapper.selectList(
|
||||
Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
||||
@@ -239,18 +249,16 @@ public class ReviewServiceImpl implements ReviewService {
|
||||
.map(StudySessionsEntity::getSessionNum)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (sessionNums.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<StudyReportsEntity> reports = studyReportsMapper.selectList(
|
||||
Wrappers.<StudyReportsEntity>lambdaQuery()
|
||||
.in(StudyReportsEntity::getSessionNum, sessionNums)
|
||||
.orderByDesc(StudyReportsEntity::getCreatedTime));
|
||||
List<StudyReportsEntity> reports = sessionNums.isEmpty() ? List.of()
|
||||
: studyReportsMapper.selectList(
|
||||
Wrappers.<StudyReportsEntity>lambdaQuery()
|
||||
.in(StudyReportsEntity::getSessionNum, sessionNums)
|
||||
.orderByDesc(StudyReportsEntity::getCreatedTime));
|
||||
|
||||
// 知识碎片按内容归属:只看它属于谁,不看它产生于哪次会话(归属-01)
|
||||
List<StudyReportFragmentsEntity> fragments = studyReportFragmentsMapper.selectList(
|
||||
Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
||||
.in(StudyReportFragmentsEntity::getSessionNum, sessionNums)
|
||||
.eq(StudyReportFragmentsEntity::getOwnerTaskNum, taskNum)
|
||||
.orderByDesc(StudyReportFragmentsEntity::getCreatedTime));
|
||||
|
||||
return mergeAndConvert(reports, fragments);
|
||||
@@ -265,6 +273,81 @@ public class ReviewServiceImpl implements ReviewService {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public StudyReportDetail getReportDetailStructured(int id) throws NotFindEntitiesException {
|
||||
StudyReportsEntity report = getReportDetail(id);
|
||||
StudyReportDetail detail = StudyReportDetail.of(report);
|
||||
|
||||
// 报告所属会话与任务:用于判断哪些碎片是「旁支」(归属不等于本会话的任务)
|
||||
StudySessionsEntity session = StringUtils.hasText(report.getSessionNum())
|
||||
? studySessionsMapper.selectOne(Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||
.eq(StudySessionsEntity::getSessionNum, report.getSessionNum())
|
||||
.last("LIMIT 1"))
|
||||
: null;
|
||||
if (session != null) {
|
||||
detail.setSessionTaskNum(session.getTaskNum());
|
||||
detail.setSessionTaskName(loadTaskName(session.getTaskNum()));
|
||||
}
|
||||
Optional.ofNullable(studyExpectationsService.getBySessionNum(report.getSessionNum()))
|
||||
.ifPresent(e -> detail.setSessionExpectation(e.getDescription()));
|
||||
|
||||
// 第四部分不落库:按会话产生的碎片 + 它们的**当前**内容归属实时聚合
|
||||
List<StudyReportFragmentsEntity> fragments = studyReportFragmentsMapper.selectList(
|
||||
Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
||||
.eq(StudyReportFragmentsEntity::getContextNum, report.getSessionNum())
|
||||
.orderByAsc(StudyReportFragmentsEntity::getCreatedTime));
|
||||
|
||||
Map<String, StudyReportDetail.FragmentGroup> groups = new LinkedHashMap<>();
|
||||
for (StudyReportFragmentsEntity fragment : fragments) {
|
||||
String owner = fragment.getOwnerTaskNum();
|
||||
String key = StringUtils.hasText(owner) ? owner : PENDING_OWNERSHIP_KEY;
|
||||
StudyReportDetail.FragmentGroup group = groups.computeIfAbsent(key, k -> {
|
||||
StudyReportDetail.FragmentGroup created = new StudyReportDetail.FragmentGroup();
|
||||
created.setTaskNum(StringUtils.hasText(owner) ? owner : null);
|
||||
created.setTaskName(StringUtils.hasText(owner) ? loadTaskName(owner) : null);
|
||||
// 旁支 = 归属不是本会话所属任务的内容
|
||||
created.setBranch(!StringUtils.hasText(owner)
|
||||
|| !Objects.equals(owner, detail.getSessionTaskNum()));
|
||||
return created;
|
||||
});
|
||||
group.getFragments().add(fragment);
|
||||
}
|
||||
detail.setFragmentGroups(new ArrayList<>(groups.values()));
|
||||
return detail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateReport(int id, UpdateStudyReportRequest request) throws NotFindEntitiesException {
|
||||
StudyReportsEntity existing = getReportDetail(id);
|
||||
StudyReportsEntity patch = new StudyReportsEntity();
|
||||
patch.setId(existing.getId());
|
||||
patch.setSessionSummary(request.getSessionSummary());
|
||||
patch.setExpectationVerdict(request.getExpectationVerdict());
|
||||
patch.setFreeSummary(request.getFreeSummary());
|
||||
studyReportsMapper.updateById(patch);
|
||||
log.info("学习报告[{}]已修改", id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteReport(int id) throws NotFindEntitiesException {
|
||||
StudyReportsEntity existing = getReportDetail(id);
|
||||
// 软删除。刻意不连带删除同一会话的知识碎片:碎片是独立原料,可能已被归类到其他任务
|
||||
studyReportsMapper.deleteById(existing.getId());
|
||||
log.info("学习报告[{}]已删除(知识碎片保留)", id);
|
||||
}
|
||||
|
||||
/** 取任务名,任务不存在时返回 null(任务被删除后碎片会进入待归类,报告仍可能引用旧任务号) */
|
||||
private String loadTaskName(String taskNum) {
|
||||
if (!StringUtils.hasText(taskNum)) {
|
||||
return null;
|
||||
}
|
||||
return tasksMapper.selectOne(Wrappers.<TaskEntity>lambdaQuery()
|
||||
.eq(TaskEntity::getTaskNum, taskNum)
|
||||
.select(TaskEntity::getTaskName)
|
||||
.last("LIMIT 1"))
|
||||
.getTaskName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StudyReportFragmentsEntity getFragmentDetail(int id) throws NotFindEntitiesException {
|
||||
return Optional.ofNullable(studyReportFragmentsMapper.selectById(id))
|
||||
@@ -279,43 +362,50 @@ public class ReviewServiceImpl implements ReviewService {
|
||||
*/
|
||||
private List<ReviewFeedItem> mergeAndConvert(List<StudyReportsEntity> reports,
|
||||
List<StudyReportFragmentsEntity> fragments) {
|
||||
Set<String> allSessionNums = Stream.concat(
|
||||
reports.stream().map(StudyReportsEntity::getSessionNum),
|
||||
fragments.stream().map(StudyReportFragmentsEntity::getSessionNum)
|
||||
).collect(Collectors.toSet());
|
||||
|
||||
if (allSessionNums.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Map<String, String> sessionToTaskMap = studySessionsMapper.selectList(
|
||||
Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||
.in(StudySessionsEntity::getSessionNum, allSessionNums)
|
||||
.select(StudySessionsEntity::getSessionNum, StudySessionsEntity::getTaskNum))
|
||||
// 报告的任务取自它所属的会话(报告按会话生成)
|
||||
Set<String> reportSessionNums = reports.stream()
|
||||
.map(StudyReportsEntity::getSessionNum)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
Map<String, String> sessionToTaskMap = reportSessionNums.isEmpty()
|
||||
? Collections.emptyMap()
|
||||
: studySessionsMapper.selectList(
|
||||
Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||
.in(StudySessionsEntity::getSessionNum, reportSessionNums)
|
||||
.select(StudySessionsEntity::getSessionNum, StudySessionsEntity::getTaskNum))
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
StudySessionsEntity::getSessionNum,
|
||||
StudySessionsEntity::getTaskNum,
|
||||
(a, b) -> a));
|
||||
|
||||
// 碎片的任务取自它自己的内容归属
|
||||
Set<String> taskNums = new HashSet<>(sessionToTaskMap.values());
|
||||
Map<String, String> taskNameMap = tasksMapper.selectList(
|
||||
Wrappers.<TaskEntity>lambdaQuery()
|
||||
.in(TaskEntity::getTaskNum, taskNums)
|
||||
.select(TaskEntity::getTaskNum, TaskEntity::getTaskName))
|
||||
fragments.stream()
|
||||
.map(StudyReportFragmentsEntity::getOwnerTaskNum)
|
||||
.filter(StringUtils::hasText)
|
||||
.forEach(taskNums::add);
|
||||
taskNums.removeIf(num -> !StringUtils.hasText(num));
|
||||
|
||||
Map<String, String> taskNameMap = taskNums.isEmpty() ? Collections.emptyMap()
|
||||
: tasksMapper.selectList(
|
||||
Wrappers.<TaskEntity>lambdaQuery()
|
||||
.in(TaskEntity::getTaskNum, taskNums)
|
||||
.select(TaskEntity::getTaskNum, TaskEntity::getTaskName))
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
TaskEntity::getTaskNum,
|
||||
TaskEntity::getTaskName,
|
||||
task -> task.getTaskName() == null ? "" : task.getTaskName(),
|
||||
(a, b) -> a));
|
||||
|
||||
List<ReviewFeedItem> reportItems = reports.stream().map(r -> {
|
||||
ReviewFeedItem item = new ReviewFeedItem();
|
||||
item.setId(r.getId());
|
||||
item.setSessionNum(r.getSessionNum());
|
||||
item.setSourceType("REPORT");
|
||||
item.setContent(r.getContent());
|
||||
item.setSourceType(SOURCE_REPORT);
|
||||
item.setContent(reportDisplayText(r));
|
||||
item.setCreatedTime(r.getCreatedTime());
|
||||
item.setContextType(FragmentContextTypeEnum.SESSION.name());
|
||||
item.setContextNum(r.getSessionNum());
|
||||
String taskNum = sessionToTaskMap.get(r.getSessionNum());
|
||||
item.setTaskNum(taskNum);
|
||||
item.setTaskName(taskNum != null ? taskNameMap.get(taskNum) : null);
|
||||
@@ -325,13 +415,16 @@ public class ReviewServiceImpl implements ReviewService {
|
||||
List<ReviewFeedItem> fragmentItems = fragments.stream().map(f -> {
|
||||
ReviewFeedItem item = new ReviewFeedItem();
|
||||
item.setId(f.getId());
|
||||
item.setSessionNum(f.getSessionNum());
|
||||
item.setSourceType("FRAGMENT");
|
||||
item.setSourceType(SOURCE_FRAGMENT);
|
||||
item.setContent(f.getContent());
|
||||
item.setCreatedTime(f.getCreatedTime());
|
||||
String taskNum = sessionToTaskMap.get(f.getSessionNum());
|
||||
item.setTaskNum(taskNum);
|
||||
item.setTaskName(taskNum != null ? taskNameMap.get(taskNum) : null);
|
||||
item.setContextType(f.getContextType());
|
||||
item.setContextNum(f.getContextNum());
|
||||
// 内容归属:为空即「待归类」,前端据此打标并提供就地归类入口
|
||||
item.setPendingOwnership(f.isPendingOwnership());
|
||||
item.setTaskNum(f.getOwnerTaskNum());
|
||||
item.setTaskName(StringUtils.hasText(f.getOwnerTaskNum())
|
||||
? taskNameMap.get(f.getOwnerTaskNum()) : null);
|
||||
return item;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
@@ -341,6 +434,27 @@ public class ReviewServiceImpl implements ReviewService {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 报告在列表/Feed 中的展示文本:结构化报告由三段组成,这里按段拼接。
|
||||
*/
|
||||
private static String reportDisplayText(StudyReportsEntity report) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
appendSection(text, "会话摘要", report.getSessionSummary());
|
||||
appendSection(text, "预期达成判断", report.getExpectationVerdict());
|
||||
appendSection(text, "自由总结", report.getFreeSummary());
|
||||
return text.length() == 0 ? "" : text.toString().trim();
|
||||
}
|
||||
|
||||
private static void appendSection(StringBuilder text, String title, String body) {
|
||||
if (body == null || body.isBlank()) {
|
||||
return;
|
||||
}
|
||||
if (text.length() > 0) {
|
||||
text.append("\n\n");
|
||||
}
|
||||
text.append("【").append(title).append("】\n").append(body.trim());
|
||||
}
|
||||
|
||||
private ReviewTaskStats newTaskStats(TaskEntity task) {
|
||||
return newTaskStats(task.getTaskNum(), task.getTaskName());
|
||||
}
|
||||
|
||||
+17
-19
@@ -36,9 +36,8 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
private final ReviewStandardMindMapMapper standardMindMapMapper;
|
||||
private final ReviewRecallRecordMapper recallRecordMapper;
|
||||
private final TasksMapper tasksMapper;
|
||||
private final StudyReportsMapper studyReportsMapper;
|
||||
private final TaskApplicationMapper taskApplicationMapper;
|
||||
private final StudySessionsMapper studySessionsMapper;
|
||||
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
|
||||
|
||||
private final List<MindMapAiClient> aiClients;
|
||||
private final ObjectMapper objectMapper;
|
||||
@@ -415,22 +414,18 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
throw new OperationFailedException("这个任务不存在或已被删除");
|
||||
}
|
||||
|
||||
// 收集学习数据
|
||||
List<String> sessionNums = studySessionsMapper.selectList(
|
||||
Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
||||
.select(StudySessionsEntity::getSessionNum))
|
||||
.stream().map(StudySessionsEntity::getSessionNum).collect(Collectors.toList());
|
||||
|
||||
List<StudyReportsEntity> reports = sessionNums.isEmpty() ? List.of()
|
||||
: studyReportsMapper.selectList(Wrappers.<StudyReportsEntity>lambdaQuery()
|
||||
.in(StudyReportsEntity::getSessionNum, sessionNums));
|
||||
// 素材按**内容归属**取:该任务名下的知识碎片(归属-01)。
|
||||
// 不再按「任务的会话里的报告」取,否则学 A 时记录的旁支知识会错误地进入 A 的导图。
|
||||
List<StudyReportFragmentsEntity> fragments = studyReportFragmentsMapper.selectList(
|
||||
Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
||||
.eq(StudyReportFragmentsEntity::getOwnerTaskNum, taskNum)
|
||||
.orderByAsc(StudyReportFragmentsEntity::getCreatedTime));
|
||||
List<TaskApplicationEntity> applications = taskApplicationMapper.selectList(
|
||||
Wrappers.<TaskApplicationEntity>lambdaQuery().eq(TaskApplicationEntity::getTaskNum, taskNum));
|
||||
|
||||
if (reports.isEmpty()) {
|
||||
log.warn("任务[{}]没有学习报告,无法生成思维导图", taskNum);
|
||||
throw new OperationFailedException("这个任务还没开始学习哦,学习后产生学习报告后再来吧");
|
||||
if (fragments.isEmpty()) {
|
||||
log.warn("任务[{}]没有归属到它的知识碎片,无法生成思维导图", taskNum);
|
||||
throw new OperationFailedException("这个任务还没开始学习哦,学习后产生知识碎片后再来吧");
|
||||
}
|
||||
|
||||
// 优先选 AI 客户端(非 BUILTIN),其次内置生成器
|
||||
@@ -444,7 +439,7 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
throw new OperationFailedException("思维导图暂时生成不了,请稍后再试");
|
||||
}
|
||||
|
||||
Optional<MindMapNode> optRoot = client.generate(task, reports, applications, null);
|
||||
Optional<MindMapNode> optRoot = client.generate(task, fragments, applications, null);
|
||||
// AI 生成失败时尝试降级到内置生成器
|
||||
if (optRoot.isEmpty() && !"BUILTIN".equals(client.generatorName())) {
|
||||
log.info("AI 思维导图生成失败,降级到内置生成器");
|
||||
@@ -452,7 +447,7 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
.filter(c -> "BUILTIN".equals(c.generatorName()) && c.isAvailable())
|
||||
.findFirst().orElse(null);
|
||||
if (fallback != null) {
|
||||
optRoot = fallback.generate(task, reports, applications, null);
|
||||
optRoot = fallback.generate(task, fragments, applications, null);
|
||||
}
|
||||
}
|
||||
if (optRoot.isEmpty()) {
|
||||
@@ -479,9 +474,12 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
||||
entity.setSummary("共 " + nodeCount + " 个节点,最大层级 " + depth);
|
||||
entity.setGenerator(client.generatorName());
|
||||
entity.setGeneratorVersion("1.0");
|
||||
entity.setSourceReportCount(reports.size());
|
||||
entity.setSourceFragmentCount(0);
|
||||
entity.setSourceReportCount(0);
|
||||
entity.setSourceFragmentCount(fragments.size());
|
||||
entity.setGeneratedTime(LocalDateTime.now());
|
||||
// 重建完成后清除「待更新」标记
|
||||
entity.setNeedsUpdate(false);
|
||||
entity.setNeedsUpdateTime(null);
|
||||
|
||||
if (create) {
|
||||
standardMindMapMapper.insert(entity);
|
||||
|
||||
+121
-9
@@ -4,22 +4,34 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
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.StudyReportFragmentsEntity;
|
||||
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.guo.learningprogresstracker.enums.FragmentContextTypeEnum;
|
||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||
import com.guo.learningprogresstracker.mapStruct.FragmentsConvert;
|
||||
import com.guo.learningprogresstracker.mapper.ReviewStandardMindMapMapper;
|
||||
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
||||
import com.guo.learningprogresstracker.mapper.TasksMapper;
|
||||
import com.guo.learningprogresstracker.service.StudyReportFragmentsService;
|
||||
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 针对表【study_report_fragments(记录学习过程中的学习内容报告残片)】的数据库操作Service实现
|
||||
* 知识碎片服务(归属-01)。
|
||||
*
|
||||
* <p>本类负责维护两个彼此独立的维度:记录上下文(系统确定、不可变)与内容归属(用户确定、可变)。
|
||||
* 新建碎片时记录上下文默认取「当前学习会话」,内容归属默认取该会话所属任务——这与用户的直觉一致
|
||||
* (在学某个任务时记下的内容先算作该任务的内容),之后可以随时改归属或清空为待归类。</p>
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -28,18 +40,27 @@ public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFrag
|
||||
implements StudyReportFragmentsService {
|
||||
|
||||
private final StudySessionsMapper studySessionsMapper;
|
||||
private final TasksMapper tasksMapper;
|
||||
private final ReviewStandardMindMapMapper reviewStandardMindMapMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void createFragments(CreateFragmentsRequest request) throws NotFindEntitiesException {
|
||||
StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request);
|
||||
|
||||
StudySessionsEntity session = studySessionsMapper.selectOne(
|
||||
Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||
.eq(StudySessionsEntity::getSessionNum, entity.getSessionNum()));
|
||||
Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||
.eq(StudySessionsEntity::getSessionNum, entity.getContextNum()));
|
||||
if (session == null) {
|
||||
log.warn("未能找到学习会话sessionNum[{}]", entity.getSessionNum());
|
||||
log.warn("未能找到学习会话sessionNum[{}]", entity.getContextNum());
|
||||
throw new NotFindEntitiesException("这次学习会话不存在或已结束");
|
||||
}
|
||||
|
||||
// 记录上下文由系统确定:产生于一次学习会话,不可变
|
||||
entity.setContextType(FragmentContextTypeEnum.SESSION.name());
|
||||
// 内容归属默认取该会话所属任务;用户看过之后可以改成别的任务或置空为待归类
|
||||
entity.setOwnerTaskNum(session.getTaskNum());
|
||||
|
||||
this.save(entity);
|
||||
}
|
||||
|
||||
@@ -50,16 +71,107 @@ public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFrag
|
||||
log.warn("未能找到学习残片id[{}]", id);
|
||||
throw new NotFindEntitiesException("这条学习残片不存在或已被删除");
|
||||
}
|
||||
StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request);
|
||||
entity.setId(id);
|
||||
this.updateById(entity);
|
||||
// 只允许改正文与内容归属;记录上下文不可变
|
||||
StudyReportFragmentsEntity patch = new StudyReportFragmentsEntity();
|
||||
patch.setId(id);
|
||||
patch.setContent(request.getContent());
|
||||
if (request.getOwnerTaskNum() != null) {
|
||||
patch.setOwnerTaskNum(resolveOwnerTaskNum(request.getOwnerTaskNum()));
|
||||
}
|
||||
this.updateById(patch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assignOwnership(Integer id, String ownerTaskNum) throws NotFindEntitiesException {
|
||||
StudyReportFragmentsEntity existing = this.getById(id);
|
||||
if (existing == null) {
|
||||
log.warn("未能找到学习残片id[{}]", id);
|
||||
throw new NotFindEntitiesException("这条学习残片不存在或已被删除");
|
||||
}
|
||||
String resolved = resolveOwnerTaskNum(ownerTaskNum);
|
||||
String previous = existing.getOwnerTaskNum();
|
||||
if (Objects.equals(previous, resolved)) {
|
||||
return;
|
||||
}
|
||||
|
||||
StudyReportFragmentsEntity patch = new StudyReportFragmentsEntity();
|
||||
patch.setId(id);
|
||||
patch.setOwnerTaskNum(resolved);
|
||||
this.updateById(patch);
|
||||
|
||||
// 归属改变后,原任务与新任务的导图都需要重建(由用户手动触发)
|
||||
markMindMapStale(previous);
|
||||
markMindMapStale(resolved);
|
||||
log.info("碎片[{}]内容归属由[{}]变更为[{}]", id, previous, resolved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFragment(Integer id) throws NotFindEntitiesException {
|
||||
StudyReportFragmentsEntity existing = this.getById(id);
|
||||
if (existing == null) {
|
||||
log.warn("未能找到学习残片id[{}]", id);
|
||||
throw new NotFindEntitiesException("这条学习残片不存在或已被删除");
|
||||
}
|
||||
// 软删除;所属任务的导图需要重建
|
||||
this.removeById(id);
|
||||
markMindMapStale(existing.getOwnerTaskNum());
|
||||
log.info("碎片[{}]已删除", id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StudyReportFragmentsEntity> getFragmentsBySession(String sessionNum) {
|
||||
return this.list(
|
||||
Wrappers.lambdaQuery(StudyReportFragmentsEntity.class)
|
||||
.eq(StudyReportFragmentsEntity::getSessionNum, sessionNum)
|
||||
Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
||||
.eq(StudyReportFragmentsEntity::getContextType, FragmentContextTypeEnum.SESSION.name())
|
||||
.eq(StudyReportFragmentsEntity::getContextNum, sessionNum)
|
||||
.orderByAsc(StudyReportFragmentsEntity::getCreatedTime));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StudyReportFragmentsEntity> getPendingOwnershipFragments() {
|
||||
return this.list(
|
||||
Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
||||
.and(w -> w.isNull(StudyReportFragmentsEntity::getOwnerTaskNum)
|
||||
.or().eq(StudyReportFragmentsEntity::getOwnerTaskNum, ""))
|
||||
.orderByDesc(StudyReportFragmentsEntity::getCreatedTime));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countPendingOwnershipFragments() {
|
||||
return this.count(
|
||||
Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
||||
.and(w -> w.isNull(StudyReportFragmentsEntity::getOwnerTaskNum)
|
||||
.or().eq(StudyReportFragmentsEntity::getOwnerTaskNum, "")));
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验并规范化内容归属:空串等同于「待归类」;非空时任务必须存在。
|
||||
*/
|
||||
private String resolveOwnerTaskNum(String ownerTaskNum) throws NotFindEntitiesException {
|
||||
if (!StringUtils.hasText(ownerTaskNum)) {
|
||||
return null;
|
||||
}
|
||||
String taskNum = ownerTaskNum.trim();
|
||||
if (!tasksMapper.exists(Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum))) {
|
||||
log.warn("内容归属目标任务[{}]不存在", taskNum);
|
||||
throw new NotFindEntitiesException("这个任务不存在或已被删除");
|
||||
}
|
||||
return taskNum;
|
||||
}
|
||||
|
||||
/** 内容归属变化后把该任务的导图标记为待更新(重建由用户手动触发,不自动跑 AI) */
|
||||
private void markMindMapStale(String taskNum) {
|
||||
if (!StringUtils.hasText(taskNum)) {
|
||||
return;
|
||||
}
|
||||
var update = Wrappers.<ReviewStandardMindMapEntity>lambdaUpdate()
|
||||
.eq(ReviewStandardMindMapEntity::getTaskNum, taskNum)
|
||||
.eq(ReviewStandardMindMapEntity::getNeedsUpdate, false)
|
||||
.set(ReviewStandardMindMapEntity::getNeedsUpdate, true)
|
||||
.set(ReviewStandardMindMapEntity::getNeedsUpdateTime, LocalDateTime.now());
|
||||
int updated = reviewStandardMindMapMapper.update(null, update);
|
||||
if (updated > 0) {
|
||||
log.info("任务[{}]的标准导图已标记为待更新", taskNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+33
-9
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.protobuf.ServiceException;
|
||||
import com.guo.learningprogresstracker.common.StudyTimePolicy;
|
||||
import com.guo.learningprogresstracker.dto.ReportSections;
|
||||
import com.guo.learningprogresstracker.dto.StudySessionsDto;
|
||||
import com.guo.learningprogresstracker.dto.response.StudySessionResponse;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
@@ -118,7 +119,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String endedStudySession(String sessionNum, String content) throws ErrorParameterException {
|
||||
public String endedStudySession(String sessionNum, ReportSections report) throws ErrorParameterException {
|
||||
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
||||
.orElseThrow(() -> sessionNotFound(sessionNum));
|
||||
@@ -144,7 +145,12 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
||||
|
||||
StudyReportsEntity studyReportsEntity = new StudyReportsEntity();
|
||||
studyReportsEntity.setSessionNum(sessionNum);
|
||||
studyReportsEntity.setContent(content);
|
||||
// 结构化三段:摘要、达成判断、自由总结。第四部分(按归属分组的碎片)是实时聚合的视图,不落库。
|
||||
ReportSections sections = (report == null ? new ReportSections(null, null, null) : report)
|
||||
.orFallbackTo("本次学习未填写总结");
|
||||
studyReportsEntity.setSessionSummary(sections.sessionSummary());
|
||||
studyReportsEntity.setExpectationVerdict(sections.expectationVerdict());
|
||||
studyReportsEntity.setFreeSummary(sections.freeSummary());
|
||||
studyReportsMapper.insert(studyReportsEntity);
|
||||
if (wasOngoing && studySessionsEntity.getEffectiveTime() == 0) {
|
||||
return "本次有效学习时间不足" + (studyTimePolicy.getMinEffectiveTimeSeconds() / 60) + "分钟,不计入总学习时间";
|
||||
@@ -166,7 +172,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
||||
throw new ErrorParameterException("确认语输入不正确,请核对后重新输入");
|
||||
}
|
||||
long fragmentCount = studyReportFragmentsMapper.selectCount(Wrappers.lambdaQuery(StudyReportFragmentsEntity.class)
|
||||
.eq(StudyReportFragmentsEntity::getSessionNum, sessionNum));
|
||||
.eq(StudyReportFragmentsEntity::getContextNum, sessionNum));
|
||||
if (fragmentCount > 0) {
|
||||
log.warn("会话[{}]已产生{}条学习残片,不能误操作结束", sessionNum, fragmentCount);
|
||||
throw new ErrorParameterException("这次学习已经产生了学习残片,不能按误操作结束了哦");
|
||||
@@ -197,7 +203,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
||||
if (this.exists(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))) {
|
||||
return studyReportFragmentsMapper.selectList(Wrappers.lambdaQuery(StudyReportFragmentsEntity.class)
|
||||
.eq(StudyReportFragmentsEntity::getSessionNum, sessionNum))
|
||||
.eq(StudyReportFragmentsEntity::getContextNum, sessionNum))
|
||||
.stream().map(StudyReportFragmentsEntity::getContent).collect(Collectors.toCollection(ArrayList::new));
|
||||
} else {
|
||||
throw sessionNotFound(sessionNum);
|
||||
@@ -239,14 +245,14 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
||||
* 不能放在读取接口里,否则一个 GET 就会阻塞并按 AI 计费。</p>
|
||||
*/
|
||||
@Override
|
||||
public String buildReportDraft(String sessionNum) throws ErrorParameterException {
|
||||
public ReportSections buildReportDraft(String sessionNum) throws ErrorParameterException {
|
||||
StudySessionsEntity session = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
||||
.orElseThrow(() -> sessionNotFound(sessionNum));
|
||||
|
||||
ArrayList<String> fragments = getAllFragments(sessionNum);
|
||||
if (fragments.isEmpty()) {
|
||||
return "";
|
||||
return new ReportSections(null, null, null);
|
||||
}
|
||||
|
||||
String taskName = tasksServiceImpl.getOneOpt(
|
||||
@@ -257,8 +263,23 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
||||
.map(e -> e.getDescription())
|
||||
.orElse(null);
|
||||
|
||||
// AI 可用时由它给出三段草稿;不可用(或失败)时降级为规则拼接:
|
||||
// 会话摘要 = 碎片条数 + 首条摘要,自由总结留给用户填写,达成判断只在有预期时给一句规则结论。
|
||||
return aiServiceClient.aggregateReport(taskName, fragments, expectation)
|
||||
.orElseGet(() -> String.join("\n", fragments));
|
||||
.orElseGet(() -> ruleBasedReportDraft(fragments, expectation));
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则降级:不依赖 AI 也能给出一份可编辑的草稿。
|
||||
* <p>只做能确定的事——摘要按碎片拼接、达成判断只在存在学习预期时给规则结论,
|
||||
* 自由总结刻意留空由用户填写(AI 不可用时不应该替他编造卡点与下一步)。</p>
|
||||
*/
|
||||
private ReportSections ruleBasedReportDraft(List<String> fragments, String expectation) {
|
||||
String summary = String.join("\n", fragments);
|
||||
String verdict = (expectation == null || expectation.isBlank())
|
||||
? null
|
||||
: "本次学习记录了 " + fragments.size() + " 条知识碎片,请对照预期自行判断达成情况。";
|
||||
return new ReportSections(summary, verdict, null);
|
||||
}
|
||||
|
||||
// ============ 分页查询任务的历史残片/报告 ============
|
||||
@@ -266,8 +287,9 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
||||
@Override
|
||||
public Page<StudyReportFragmentsEntity> getTaskFragments(String taskNum, int page, int size, String keyword) {
|
||||
Page<StudyReportFragmentsEntity> pg = new Page<>(page, size);
|
||||
// 归属-01:按内容归属取,而不是按产生于该任务的哪次会话取
|
||||
var wrapper = Wrappers.lambdaQuery(StudyReportFragmentsEntity.class)
|
||||
.apply("session_num in (select session_num from study_sessions where task_num = {0})", taskNum)
|
||||
.eq(StudyReportFragmentsEntity::getOwnerTaskNum, taskNum)
|
||||
.orderByDesc(StudyReportFragmentsEntity::getCreatedTime);
|
||||
if (keyword != null && !keyword.isBlank()) {
|
||||
wrapper.like(StudyReportFragmentsEntity::getContent, keyword);
|
||||
@@ -282,7 +304,9 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
||||
.apply("session_num in (select session_num from study_sessions where task_num = {0})", taskNum)
|
||||
.orderByDesc(StudyReportsEntity::getCreatedTime);
|
||||
if (keyword != null && !keyword.isBlank()) {
|
||||
wrapper.like(StudyReportsEntity::getContent, keyword);
|
||||
wrapper.and(w -> w.like(StudyReportsEntity::getFreeSummary, keyword)
|
||||
.or().like(StudyReportsEntity::getSessionSummary, keyword)
|
||||
.or().like(StudyReportsEntity::getExpectationVerdict, keyword));
|
||||
}
|
||||
Page<StudyReportsEntity> result = studyReportsMapper.selectPage(pg, wrapper);
|
||||
// 填充每个报告对应会话的预期目标
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.guo.learningprogresstracker.dto.TaskDeletionSummary;
|
||||
import com.guo.learningprogresstracker.entity.*;
|
||||
import com.guo.learningprogresstracker.mapper.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 删除学习任务时对名下学习记录的处置(归属-01)。
|
||||
*
|
||||
* <p>口径(维护者 2026-10-09 确认):</p>
|
||||
* <ul>
|
||||
* <li><b>知识碎片保留</b>,内容归属置空 → 进入待归类。删任务撤销的是「这次学习的时间记录与收敛结果」,
|
||||
* 不是知识本身;碎片是原料,不因归属消失而消失。</li>
|
||||
* <li>学习会话、学习报告、标准思维导图、回忆记录、应用场景随任务一并<b>软删除</b>。</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>拆成独立组件的原因:{@code TasksServiceImpl} 若直接依赖这些 mapper 会与
|
||||
* {@code ReviewServiceImpl}、{@code StudySessionsServiceImpl} 形成循环依赖。</p>
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TaskDeletionService {
|
||||
|
||||
private final StudySessionsMapper studySessionsMapper;
|
||||
private final StudyReportsMapper studyReportsMapper;
|
||||
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
|
||||
private final ReviewStandardMindMapMapper standardMindMapMapper;
|
||||
private final ReviewRecallRecordMapper recallRecordMapper;
|
||||
private final TaskApplicationMapper taskApplicationMapper;
|
||||
|
||||
/**
|
||||
* 处置任务名下的学习记录。
|
||||
*
|
||||
* @return 各对象的处理条数,供接口返回给前端展示(删除确认弹窗要分别列出「即将删除」与「即将保留」)
|
||||
*/
|
||||
@Transactional
|
||||
public TaskDeletionSummary detachAndCleanUp(String taskNum) {
|
||||
TaskDeletionSummary summary = new TaskDeletionSummary();
|
||||
|
||||
// 1. 知识碎片:保留,只把内容归属置空 → 待归类
|
||||
List<StudyReportFragmentsEntity> owned = studyReportFragmentsMapper.selectList(
|
||||
Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
||||
.eq(StudyReportFragmentsEntity::getOwnerTaskNum, taskNum)
|
||||
.select(StudyReportFragmentsEntity::getId));
|
||||
if (!owned.isEmpty()) {
|
||||
List<Integer> ids = owned.stream().map(StudyReportFragmentsEntity::getId).collect(Collectors.toList());
|
||||
int released = studyReportFragmentsMapper.update(null,
|
||||
Wrappers.<StudyReportFragmentsEntity>lambdaUpdate()
|
||||
.in(StudyReportFragmentsEntity::getId, ids)
|
||||
.set(StudyReportFragmentsEntity::getOwnerTaskNum, null));
|
||||
summary.setReleasedFragments(released);
|
||||
}
|
||||
|
||||
// 2. 学习会话及其产生的报告:软删除
|
||||
List<String> sessionNums = studySessionsMapper.selectList(
|
||||
Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
||||
.select(StudySessionsEntity::getSessionNum))
|
||||
.stream().map(StudySessionsEntity::getSessionNum)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!sessionNums.isEmpty()) {
|
||||
summary.setDeletedReports(studyReportsMapper.delete(
|
||||
Wrappers.<StudyReportsEntity>lambdaQuery().in(StudyReportsEntity::getSessionNum, sessionNums)));
|
||||
summary.setDeletedSessions(studySessionsMapper.delete(
|
||||
Wrappers.<StudySessionsEntity>lambdaQuery().in(StudySessionsEntity::getSessionNum, sessionNums)));
|
||||
}
|
||||
|
||||
// 3. 标准思维导图与回忆记录:按任务软删除
|
||||
summary.setDeletedMindMaps(standardMindMapMapper.delete(
|
||||
Wrappers.<ReviewStandardMindMapEntity>lambdaQuery()
|
||||
.eq(ReviewStandardMindMapEntity::getTaskNum, taskNum)));
|
||||
summary.setDeletedRecallRecords(recallRecordMapper.delete(
|
||||
Wrappers.<ReviewRecallRecordEntity>lambdaQuery()
|
||||
.eq(ReviewRecallRecordEntity::getTaskNum, taskNum)));
|
||||
|
||||
// 4. 应用场景:按任务软删除
|
||||
summary.setDeletedApplications(taskApplicationMapper.delete(
|
||||
Wrappers.<TaskApplicationEntity>lambdaQuery()
|
||||
.eq(TaskApplicationEntity::getTaskNum, taskNum)));
|
||||
|
||||
log.info("任务[{}]删除:释放碎片 {} 条,软删会话 {} 个/报告 {} 份/导图 {} 张/回忆记录 {} 条/应用场景 {} 个",
|
||||
taskNum, summary.getReleasedFragments(), summary.getDeletedSessions(), summary.getDeletedReports(),
|
||||
summary.getDeletedMindMaps(), summary.getDeletedRecallRecords(), summary.getDeletedApplications());
|
||||
return summary;
|
||||
}
|
||||
|
||||
/** 收集任务名下各类对象的数量,供前端在删除前展示影响范围 */
|
||||
public TaskDeletionSummary previewDeletion(String taskNum) {
|
||||
TaskDeletionSummary summary = new TaskDeletionSummary();
|
||||
|
||||
summary.setReleasedFragments(Math.toIntExact(studyReportFragmentsMapper.selectCount(
|
||||
Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
||||
.eq(StudyReportFragmentsEntity::getOwnerTaskNum, taskNum))));
|
||||
|
||||
List<String> sessionNums = studySessionsMapper.selectList(
|
||||
Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
||||
.select(StudySessionsEntity::getSessionNum))
|
||||
.stream().map(StudySessionsEntity::getSessionNum)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
summary.setDeletedSessions(sessionNums.size());
|
||||
if (!sessionNums.isEmpty()) {
|
||||
summary.setDeletedReports(Math.toIntExact(studyReportsMapper.selectCount(
|
||||
Wrappers.<StudyReportsEntity>lambdaQuery().in(StudyReportsEntity::getSessionNum, sessionNums))));
|
||||
}
|
||||
|
||||
summary.setDeletedRecallRecords(Math.toIntExact(recallRecordMapper.selectCount(
|
||||
Wrappers.<ReviewRecallRecordEntity>lambdaQuery()
|
||||
.eq(ReviewRecallRecordEntity::getTaskNum, taskNum))));
|
||||
summary.setDeletedMindMaps(Math.toIntExact(standardMindMapMapper.selectCount(
|
||||
Wrappers.<ReviewStandardMindMapEntity>lambdaQuery()
|
||||
.eq(ReviewStandardMindMapEntity::getTaskNum, taskNum))));
|
||||
summary.setDeletedApplications(Math.toIntExact(taskApplicationMapper.selectCount(
|
||||
Wrappers.<TaskApplicationEntity>lambdaQuery()
|
||||
.eq(TaskApplicationEntity::getTaskNum, taskNum))));
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guo.learningprogresstracker.dto.PriorityDto;
|
||||
import com.guo.learningprogresstracker.dto.TaskDeletionSummary;
|
||||
import com.guo.learningprogresstracker.dto.TaskInfo;
|
||||
import com.guo.learningprogresstracker.dto.request.CreateTaskApplicationRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
@@ -25,6 +26,7 @@ import com.guo.learningprogresstracker.utils.GenerateNumTool;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
@@ -43,6 +45,8 @@ public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
||||
|
||||
private final TaskApplicationMapper taskApplicationMapper;
|
||||
|
||||
private final TaskDeletionService taskDeletionService;
|
||||
|
||||
private final PriorityWeightsService priorityWeightsService;
|
||||
|
||||
@Override
|
||||
@@ -99,14 +103,27 @@ public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteTask(String taskId) {
|
||||
TaskEntity existingTask = this.getById(taskId);
|
||||
if (existingTask == null) {
|
||||
throw new IllegalArgumentException("任务不存在: " + taskId);
|
||||
}
|
||||
// 归属-01:名下的知识碎片保留并进入待归类,其余学习记录随任务软删除。
|
||||
// 注意顺序——先按 task_num 处理子对象,再软删任务本身。
|
||||
taskDeletionService.detachAndCleanUp(existingTask.getTaskNum());
|
||||
this.removeById(taskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskDeletionSummary previewDeletion(String taskId) {
|
||||
TaskEntity existingTask = this.getById(taskId);
|
||||
if (existingTask == null) {
|
||||
throw new IllegalArgumentException("任务不存在: " + taskId);
|
||||
}
|
||||
return taskDeletionService.previewDeletion(existingTask.getTaskNum());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskApplicationEntity> getApplications(String taskNum) throws NotFindEntitiesException {
|
||||
ensureTaskExists(taskNum);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
-- 归属-01 + 报告-01:拆分「记录上下文」与「内容归属」,并把学习报告改为结构化。
|
||||
--
|
||||
-- 口径来源(2026-10-09 维护者确认,结论见 lpt-docs):
|
||||
-- 记录上下文:不可变、不可为空,取值是学习会话或复习行为 → context_type + context_num
|
||||
-- 内容归属:可变、单一、可为空 → owner_task_num(NULL = 待归类)
|
||||
-- 报告:只存三段文本,第四段「按归属分组的碎片」在查看时实时聚合,不落库
|
||||
-- 导图:内容归属变化后打「待更新」标记,重建由用户手动触发
|
||||
|
||||
-- ============ 1. 知识碎片:记录上下文 + 内容归属 ============
|
||||
|
||||
ALTER TABLE study_report_fragments
|
||||
RENAME COLUMN session_num TO context_num;
|
||||
|
||||
ALTER TABLE study_report_fragments
|
||||
MODIFY COLUMN context_num VARCHAR(255) NOT NULL COMMENT '记录上下文编号:学习会话编号或复习行为编号';
|
||||
|
||||
ALTER TABLE study_report_fragments
|
||||
ADD COLUMN context_type VARCHAR(20) NOT NULL DEFAULT 'SESSION'
|
||||
COMMENT '记录上下文类型:SESSION=学习会话 / REVIEW=复习行为' AFTER context_num;
|
||||
|
||||
ALTER TABLE study_report_fragments
|
||||
ADD COLUMN owner_task_num VARCHAR(255) NULL
|
||||
COMMENT '内容归属的学习任务编号;NULL 表示待归类' AFTER context_type;
|
||||
|
||||
-- 存量碎片的内容归属:默认取它所属会话的任务。
|
||||
-- 这与当前行为一致(记在哪次会话里就算哪个任务的内容),避免升级后所有碎片突然变成「待归类」。
|
||||
-- 找不到会话的碎片保持 NULL,进入待归类。
|
||||
UPDATE study_report_fragments
|
||||
SET owner_task_num = (SELECT s.task_num
|
||||
FROM study_sessions s
|
||||
WHERE s.session_num = study_report_fragments.context_num
|
||||
AND s.deleted = 0)
|
||||
WHERE owner_task_num IS NULL
|
||||
AND deleted = 0;
|
||||
|
||||
-- 按归属取内容(导图取材、按任务检索、碎片计数)
|
||||
CREATE INDEX idx_fragments_owner_task ON study_report_fragments (created_by, owner_task_num, created_time);
|
||||
-- 待归类列表
|
||||
CREATE INDEX idx_fragments_pending_owner ON study_report_fragments (created_by, owner_task_num);
|
||||
-- 按记录上下文取碎片(会话详情)
|
||||
CREATE INDEX idx_fragments_context ON study_report_fragments (created_by, context_type, context_num);
|
||||
|
||||
-- ============ 2. 学习报告:结构化三段文本 ============
|
||||
|
||||
ALTER TABLE study_reports
|
||||
RENAME COLUMN content TO free_summary;
|
||||
|
||||
ALTER TABLE study_reports
|
||||
MODIFY COLUMN free_summary TEXT NULL COMMENT '自由总结:用户对本次学习的叙述(卡点、疑问、下一步)';
|
||||
|
||||
ALTER TABLE study_reports
|
||||
ADD COLUMN session_summary TEXT NULL
|
||||
COMMENT '会话摘要:这次实际学了什么' AFTER free_summary;
|
||||
|
||||
ALTER TABLE study_reports
|
||||
ADD COLUMN expectation_verdict TEXT NULL
|
||||
COMMENT '预期达成判断:对照学习预期得出的结论' AFTER session_summary;
|
||||
|
||||
-- ============ 3. 标准导图:待更新标记 ============
|
||||
|
||||
ALTER TABLE review_standard_mind_maps
|
||||
ADD COLUMN needs_update TINYINT(1) NOT NULL DEFAULT 0
|
||||
COMMENT '内容归属发生变化,导图需要重建(由用户手动触发)' AFTER generated_time;
|
||||
|
||||
ALTER TABLE review_standard_mind_maps
|
||||
ADD COLUMN needs_update_time DATETIME NULL
|
||||
COMMENT '标记待更新的时间' AFTER needs_update;
|
||||
@@ -45,21 +45,22 @@
|
||||
</select>
|
||||
|
||||
<!--
|
||||
按内容归属统计任务下的碎片条数(数据-02)。
|
||||
两表都含 created_by,租户条件由拦截器分别追加;自定义 SQL 需显式写 deleted = 0。
|
||||
按内容归属统计任务下的碎片条数(数据-02 / 归属-01)。
|
||||
归属-01 之后碎片自带 owner_task_num,不再需要 join 学习会话——
|
||||
这也正是「内容按归属聚合」与「时间按行为统计」两条轴分开后的直接结果。
|
||||
-->
|
||||
<select id="countFragmentsByTask" resultMap="TaskContentCountMap">
|
||||
SELECT ss.task_num AS task_num,
|
||||
COUNT(f.id) AS content_count
|
||||
FROM study_sessions ss
|
||||
JOIN study_report_fragments f ON f.session_num = ss.session_num AND f.deleted = 0
|
||||
WHERE ss.deleted = 0
|
||||
SELECT owner_task_num AS task_num,
|
||||
COUNT(id) AS content_count
|
||||
FROM study_report_fragments
|
||||
WHERE deleted = 0
|
||||
AND owner_task_num IS NOT NULL
|
||||
<if test="taskNums != null and !taskNums.isEmpty()">
|
||||
AND ss.task_num IN
|
||||
AND owner_task_num IN
|
||||
<foreach collection="taskNums" item="num" open="(" separator="," close=")">
|
||||
#{num}
|
||||
</foreach>
|
||||
</if>
|
||||
GROUP BY ss.task_num
|
||||
GROUP BY owner_task_num
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ class ReportFragmentsControllerUnitTest {
|
||||
@Test
|
||||
void createFragments_delegatesToService() throws Exception {
|
||||
CreateFragmentsRequest request = new CreateFragmentsRequest();
|
||||
request.setSessionNum("S-1");
|
||||
request.setContextNum("S-1");
|
||||
request.setContent("今日学习内容");
|
||||
|
||||
CommonResult<Void> result = controller.createFragments(request);
|
||||
|
||||
+6
-4
@@ -21,6 +21,8 @@ import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
@@ -101,8 +103,8 @@ class StudySessionControllerUnitTest {
|
||||
@Test
|
||||
void endedStudySession_withReportMessage_returnsMessageInData() throws Exception {
|
||||
EndedStudySessionRequest request = new EndedStudySessionRequest();
|
||||
request.setContent("报告内容");
|
||||
when(studySessionsServiceImpl.endedStudySession("S006", "报告内容")).thenReturn("报告摘要");
|
||||
request.setFreeSummary("报告内容");
|
||||
when(studySessionsServiceImpl.endedStudySession(eq("S006"), any())).thenReturn("报告摘要");
|
||||
|
||||
CommonResult<Void> result = controller.endedStudySession("S006", request);
|
||||
|
||||
@@ -115,8 +117,8 @@ class StudySessionControllerUnitTest {
|
||||
@Test
|
||||
void endedStudySession_withoutReportMessage_returnsEmptySuccess() throws Exception {
|
||||
EndedStudySessionRequest request = new EndedStudySessionRequest();
|
||||
request.setContent("无报告内容");
|
||||
when(studySessionsServiceImpl.endedStudySession("S007", "无报告内容")).thenReturn(null);
|
||||
request.setFreeSummary("无报告内容");
|
||||
when(studySessionsServiceImpl.endedStudySession(eq("S007"), any())).thenReturn(null);
|
||||
|
||||
CommonResult<Void> result = controller.endedStudySession("S007", request);
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@ class FragmentsConvertTest {
|
||||
assertNotNull(FragmentsConvert.MAPPER);
|
||||
|
||||
CreateFragmentsRequest request = new CreateFragmentsRequest();
|
||||
request.setSessionNum("SESSION_A");
|
||||
request.setContextNum("SESSION_A");
|
||||
request.setContent("学习内容");
|
||||
|
||||
StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request);
|
||||
|
||||
assertNotNull(entity);
|
||||
assertEquals("SESSION_A", entity.getSessionNum());
|
||||
assertEquals("SESSION_A", entity.getContextNum());
|
||||
assertEquals("学习内容", entity.getContent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.guo.learningprogresstracker.dto.ReportSections;
|
||||
import com.guo.learningprogresstracker.support.TestHttpServer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -60,18 +61,18 @@ class AiServiceClientTest extends TestHttpServer {
|
||||
@Test
|
||||
void aggregateReport_success_coversExpectationBothBranches() {
|
||||
route("POST", "/ai/tasks", 201, "{\"taskId\":\"t1\"}");
|
||||
route("GET", "/ai/tasks/t1", 200, "{\"status\":\"done\",\"result\":{\"report\":\"聚合报告内容\"}}");
|
||||
route("GET", "/ai/tasks/t1", 200, "{\"status\":\"done\",\"result\":{\"sessionSummary\":\"聚合报告内容\",\"expectationVerdict\":\"\",\"freeSummary\":\"\"}}");
|
||||
AiServiceClient client = newClient(baseUrl(), 2);
|
||||
|
||||
// expectation 为 null → 参数不含 expectation
|
||||
Optional<String> noExpectation = client.aggregateReport("任务A", List.of("片段1"), null);
|
||||
Optional<ReportSections> noExpectation = client.aggregateReport("任务A", List.of("片段1"), null);
|
||||
assertTrue(noExpectation.isPresent());
|
||||
assertEquals("聚合报告内容", noExpectation.get());
|
||||
assertEquals("聚合报告内容", noExpectation.get().sessionSummary());
|
||||
|
||||
// expectation 非空 → 参数带 expectation
|
||||
Optional<String> withExpectation = client.aggregateReport("任务A", List.of("片段1"), "期望目标");
|
||||
Optional<ReportSections> withExpectation = client.aggregateReport("任务A", List.of("片段1"), "期望目标");
|
||||
assertTrue(withExpectation.isPresent());
|
||||
assertEquals("聚合报告内容", withExpectation.get());
|
||||
assertEquals("聚合报告内容", withExpectation.get().sessionSummary());
|
||||
|
||||
assertEquals("application/json", requestHeader("POST", "/ai/tasks", "Content-Type"));
|
||||
}
|
||||
@@ -207,7 +208,7 @@ class AiServiceClientTest extends TestHttpServer {
|
||||
AiServiceClient client = newClient(baseUrl(), 1);
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
Optional<String> result = client.aggregateReport("任务A", List.of("片段"), null);
|
||||
Optional<ReportSections> result = client.aggregateReport("任务A", List.of("片段"), null);
|
||||
long elapsed = System.currentTimeMillis() - start;
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
|
||||
+17
-1
@@ -4,10 +4,12 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.guo.learningprogresstracker.dto.AiTaskResponse;
|
||||
import com.guo.learningprogresstracker.dto.request.AiTaskSubmitRequest;
|
||||
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;
|
||||
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
|
||||
import com.guo.learningprogresstracker.mapper.StudyReportsMapper;
|
||||
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
||||
import com.guo.learningprogresstracker.mapper.TasksMapper;
|
||||
@@ -58,6 +60,9 @@ class AiTaskIntegrationTest {
|
||||
@Autowired
|
||||
private StudyReportsMapper studyReportsMapper;
|
||||
|
||||
@Autowired
|
||||
private StudyReportFragmentsMapper studyReportFragmentsMapper;
|
||||
|
||||
/** 用假的 AI 客户端记录「调用 AI 时是否存在事务」,并让思维导图走 AI 分支 */
|
||||
@MockBean
|
||||
private AiServiceClient aiServiceClient;
|
||||
@@ -93,6 +98,10 @@ class AiTaskIntegrationTest {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 造一个「已学习过」的任务:归属-01 之后导图与回忆对比的素材是<b>归属该任务的知识碎片</b>,
|
||||
* 不再是按会话产生的报告,因此这里必须写一条带 owner_task_num 的碎片。
|
||||
*/
|
||||
private String createTaskWithReport() {
|
||||
String taskNum = GenerateNumTool.generateNum("TASKAI");
|
||||
TaskEntity task = new TaskEntity();
|
||||
@@ -110,8 +119,15 @@ class AiTaskIntegrationTest {
|
||||
|
||||
StudyReportsEntity report = new StudyReportsEntity();
|
||||
report.setSessionNum(session.getSessionNum());
|
||||
report.setContent("报告正文");
|
||||
report.setFreeSummary("报告正文");
|
||||
studyReportsMapper.insert(report);
|
||||
|
||||
StudyReportFragmentsEntity fragment = new StudyReportFragmentsEntity();
|
||||
fragment.setContextType("SESSION");
|
||||
fragment.setContextNum(session.getSessionNum());
|
||||
fragment.setOwnerTaskNum(taskNum);
|
||||
fragment.setContent("线程池的核心参数");
|
||||
studyReportFragmentsMapper.insert(fragment);
|
||||
return taskNum;
|
||||
}
|
||||
|
||||
|
||||
+26
-23
@@ -1,6 +1,6 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.guo.learningprogresstracker.utils.MindMapNode;
|
||||
@@ -26,12 +26,15 @@ class BuiltinMindMapGeneratorTest {
|
||||
return task;
|
||||
}
|
||||
|
||||
private static StudyReportsEntity report(String sessionNum, String content, Integer id) {
|
||||
StudyReportsEntity report = new StudyReportsEntity();
|
||||
report.setSessionNum(sessionNum);
|
||||
report.setContent(content);
|
||||
report.setId(id);
|
||||
return report;
|
||||
/** 归属-01:降级导图的素材是该任务名下的知识碎片(按内容归属取,不再按会话产生的报告) */
|
||||
private static StudyReportFragmentsEntity fragment(String contextNum, String content, Integer id) {
|
||||
StudyReportFragmentsEntity fragment = new StudyReportFragmentsEntity();
|
||||
fragment.setContextType("SESSION");
|
||||
fragment.setContextNum(contextNum);
|
||||
fragment.setOwnerTaskNum("T1");
|
||||
fragment.setContent(content);
|
||||
fragment.setId(id);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
private static TaskApplicationEntity app(Integer id, String title, String description) {
|
||||
@@ -60,9 +63,9 @@ class BuiltinMindMapGeneratorTest {
|
||||
task.setTaskName(null); // → 兜底"学习任务"
|
||||
task.setTaskDescription("任务描述内容");
|
||||
|
||||
StudyReportsEntity withDate = report("S1", "会话一的学习内容", 1);
|
||||
StudyReportFragmentsEntity withDate = fragment("S1", "会话一的学习内容", 1);
|
||||
withDate.setCreatedTime(LocalDateTime.of(2024, 5, 6, 10, 30));
|
||||
StudyReportsEntity noDate = report("S2", "会话二的学习内容", 2);
|
||||
StudyReportFragmentsEntity noDate = fragment("S2", "会话二的学习内容", 2);
|
||||
noDate.setCreatedTime(null);
|
||||
|
||||
MindMapNode root = generator.generate(task, List.of(withDate, noDate), List.of(), null).get();
|
||||
@@ -87,7 +90,7 @@ class BuiltinMindMapGeneratorTest {
|
||||
MindMapNode reportNode = dated.getChildren().get(0);
|
||||
assertEquals("会话一的学习内容", reportNode.getTitle());
|
||||
assertEquals("会话一的学习内容", reportNode.getNotes());
|
||||
assertEquals("REPORT", reportNode.getSourceType());
|
||||
assertEquals("FRAGMENT", reportNode.getSourceType());
|
||||
assertEquals(1, reportNode.getSourceId());
|
||||
}
|
||||
|
||||
@@ -95,8 +98,8 @@ class BuiltinMindMapGeneratorTest {
|
||||
void generate_truncatesTitlesAt60CharsWithEllipsis() {
|
||||
String exact60 = "界".repeat(60);
|
||||
String long70 = "长".repeat(70);
|
||||
StudyReportsEntity r1 = report("S1", exact60, 1);
|
||||
StudyReportsEntity r2 = report("S1", long70, 2);
|
||||
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();
|
||||
|
||||
@@ -110,15 +113,15 @@ class BuiltinMindMapGeneratorTest {
|
||||
assertEquals("长".repeat(60) + "…", truncated.getTitle());
|
||||
assertEquals(61, truncated.getTitle().length());
|
||||
assertEquals(long70, truncated.getNotes());
|
||||
assertEquals("REPORT", truncated.getSourceType());
|
||||
assertEquals("FRAGMENT", truncated.getSourceType());
|
||||
assertEquals(2, truncated.getSourceId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void generate_skipsNullOrBlankReportContent() {
|
||||
StudyReportsEntity nullContent = report("S1", null, 1);
|
||||
StudyReportsEntity blankContent = report("S1", " ", 2);
|
||||
StudyReportsEntity valid = report("S1", "有效学习内容", 3);
|
||||
StudyReportFragmentsEntity nullContent = fragment("S1", null, 1);
|
||||
StudyReportFragmentsEntity blankContent = fragment("S1", " ", 2);
|
||||
StudyReportFragmentsEntity valid = fragment("S1", "有效学习内容", 3);
|
||||
|
||||
MindMapNode root =
|
||||
generator.generate(task(), List.of(nullContent, blankContent, valid), List.of(), null).get();
|
||||
@@ -134,11 +137,11 @@ class BuiltinMindMapGeneratorTest {
|
||||
@Test
|
||||
void generate_applications_nullOrEmptyAddsNoBranch() {
|
||||
MindMapNode withNull =
|
||||
generator.generate(task(), List.of(report("S1", "内容", 1)), null, null).get();
|
||||
generator.generate(task(), List.of(fragment("S1", "内容", 1)), null, null).get();
|
||||
assertTrue(withNull.getChildren().stream().noneMatch(n -> "应用场景".equals(n.getTitle())));
|
||||
|
||||
MindMapNode withEmpty =
|
||||
generator.generate(task(), List.of(report("S1", "内容", 1)), List.of(), null).get();
|
||||
generator.generate(task(), List.of(fragment("S1", "内容", 1)), List.of(), null).get();
|
||||
assertTrue(withEmpty.getChildren().stream().noneMatch(n -> "应用场景".equals(n.getTitle())));
|
||||
}
|
||||
|
||||
@@ -149,7 +152,7 @@ class BuiltinMindMapGeneratorTest {
|
||||
TaskApplicationEntity valid = app(3, "缓存设计", null);
|
||||
|
||||
MindMapNode root = generator.generate(task(),
|
||||
List.of(report("S1", "内容", 9)), List.of(nullTitle, blankTitle, valid), null).get();
|
||||
List.of(fragment("S1", "内容", 9)), List.of(nullTitle, blankTitle, valid), null).get();
|
||||
|
||||
MindMapNode appNode = root.getChildren().stream()
|
||||
.filter(n -> "应用场景".equals(n.getTitle()))
|
||||
@@ -167,8 +170,8 @@ class BuiltinMindMapGeneratorTest {
|
||||
@Test
|
||||
void generate_deduplicatesSameLevelTitles_keepsLongerNotes() {
|
||||
// 两条报告标准化后同名:"重复" 与 "重复。" → 合并,notes 长者胜
|
||||
StudyReportsEntity r1 = report("S1", "重复", 1);
|
||||
StudyReportsEntity r2 = report("S1", "重复。", 2);
|
||||
StudyReportFragmentsEntity r1 = fragment("S1", "重复", 1);
|
||||
StudyReportFragmentsEntity r2 = fragment("S1", "重复。", 2);
|
||||
|
||||
MindMapNode root = generator.generate(task(), List.of(r1, r2), List.of(), null).get();
|
||||
|
||||
@@ -182,8 +185,8 @@ class BuiltinMindMapGeneratorTest {
|
||||
@Test
|
||||
void generate_deduplicatesSessionNodes_mergesChildren() {
|
||||
// 两个会话首条报告内容相同 → 会话节点同名合并,报告子节点拼接
|
||||
StudyReportsEntity r1 = report("S1", "相同会话内容", 1);
|
||||
StudyReportsEntity r2 = report("S2", "相同会话内容", 2);
|
||||
StudyReportFragmentsEntity r1 = fragment("S1", "相同会话内容", 1);
|
||||
StudyReportFragmentsEntity r2 = fragment("S2", "相同会话内容", 2);
|
||||
|
||||
MindMapNode root = generator.generate(task(), List.of(r1, r2), List.of(), null).get();
|
||||
|
||||
|
||||
+3
-3
@@ -132,12 +132,12 @@ class ExportServiceImplTest {
|
||||
StudyReportsEntity report = new StudyReportsEntity();
|
||||
report.setId(1);
|
||||
report.setSessionNum("SESSION-1");
|
||||
report.setContent("报告正文");
|
||||
report.setFreeSummary("报告正文");
|
||||
report.setCreatedTime(LocalDateTime.of(2026, 10, 1, 20, 15));
|
||||
|
||||
StudyReportFragmentsEntity fragment = new StudyReportFragmentsEntity();
|
||||
fragment.setId(2);
|
||||
fragment.setSessionNum("SESSION-2");
|
||||
fragment.setContextNum("SESSION-2");
|
||||
fragment.setContent("碎片正文");
|
||||
fragment.setCreatedTime(LocalDateTime.of(2026, 10, 2, 9, 0));
|
||||
|
||||
@@ -209,7 +209,7 @@ class ExportServiceImplTest {
|
||||
LocalDateTime createdTime) {
|
||||
ReviewFeedItem item = new ReviewFeedItem();
|
||||
item.setId(id);
|
||||
item.setSessionNum(sessionNum);
|
||||
item.setContextNum(sessionNum);
|
||||
item.setSourceType(sourceType);
|
||||
item.setContent(content);
|
||||
item.setCreatedTime(createdTime);
|
||||
|
||||
+17
-14
@@ -1,6 +1,6 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.guo.learningprogresstracker.utils.MindMapNode;
|
||||
import com.guo.learningprogresstracker.utils.MindMapTreeTool;
|
||||
@@ -37,12 +37,15 @@ class RemoteAiMindMapClientTest {
|
||||
return task;
|
||||
}
|
||||
|
||||
private static StudyReportsEntity report(String content) {
|
||||
StudyReportsEntity report = new StudyReportsEntity();
|
||||
report.setSessionNum("S1");
|
||||
report.setContent(content);
|
||||
report.setId(1);
|
||||
return report;
|
||||
/** 归属-01:导图素材是「该任务名下的知识碎片」,不再是按会话产生的报告 */
|
||||
private static StudyReportFragmentsEntity fragment(String content) {
|
||||
StudyReportFragmentsEntity fragment = new StudyReportFragmentsEntity();
|
||||
fragment.setContextType("SESSION");
|
||||
fragment.setContextNum("S1");
|
||||
fragment.setOwnerTaskNum("T1");
|
||||
fragment.setContent(content);
|
||||
fragment.setId(1);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,16 +64,16 @@ class RemoteAiMindMapClientTest {
|
||||
@Test
|
||||
void generate_notAvailable_returnsEmpty() {
|
||||
when(aiServiceClient.isConfigured()).thenReturn(false);
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(report("内容")), List.of(), null);
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(fragment("内容")), List.of(), null);
|
||||
assertTrue(result.isEmpty());
|
||||
verify(aiServiceClient, never()).generateMindMap(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void generate_reportsAllBlank_returnsEmpty() {
|
||||
void generate_allBlankFragments_returnsEmpty() {
|
||||
when(aiServiceClient.isConfigured()).thenReturn(true);
|
||||
StudyReportsEntity nullContent = report(null);
|
||||
StudyReportsEntity blankContent = report(" ");
|
||||
StudyReportFragmentsEntity nullContent = fragment(null);
|
||||
StudyReportFragmentsEntity blankContent = fragment(" ");
|
||||
|
||||
Optional<MindMapNode> result =
|
||||
client.generate(task(), List.of(nullContent, blankContent), List.of(), null);
|
||||
@@ -84,7 +87,7 @@ class RemoteAiMindMapClientTest {
|
||||
when(aiServiceClient.isConfigured()).thenReturn(true);
|
||||
when(aiServiceClient.generateMindMap(any(), any(), any())).thenReturn(Optional.empty());
|
||||
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(report("内容")), List.of(), null);
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(fragment("内容")), List.of(), null);
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
@@ -94,7 +97,7 @@ class RemoteAiMindMapClientTest {
|
||||
when(aiServiceClient.isConfigured()).thenReturn(true);
|
||||
when(aiServiceClient.generateMindMap(any(), any(), any())).thenReturn(Optional.of(" "));
|
||||
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(report("内容")), List.of(), null);
|
||||
Optional<MindMapNode> result = client.generate(task(), List.of(fragment("内容")), List.of(), null);
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
@@ -106,7 +109,7 @@ class RemoteAiMindMapClientTest {
|
||||
.thenReturn(Optional.of("学习Java\n- 线程基础\n - 线程安全"));
|
||||
|
||||
Optional<MindMapNode> result =
|
||||
client.generate(task(), List.of(report("报告内容")), List.of(), "前端已有大纲");
|
||||
client.generate(task(), List.of(fragment("碎片内容")), List.of(), "前端已有大纲");
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
MindMapNode root = result.get();
|
||||
|
||||
+3
-1
@@ -62,7 +62,9 @@ class ReviewFeedSamplingIntegrationTest {
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
StudyReportFragmentsEntity fragment = new StudyReportFragmentsEntity();
|
||||
fragment.setSessionNum(session.getSessionNum());
|
||||
fragment.setContextNum(session.getSessionNum());
|
||||
fragment.setContextType("SESSION");
|
||||
fragment.setOwnerTaskNum(taskNum);
|
||||
fragment.setContent("碎片-" + i);
|
||||
fragmentsMapper.insert(fragment);
|
||||
}
|
||||
|
||||
+10
-16
@@ -69,23 +69,20 @@ class ReviewServiceImplTest {
|
||||
|
||||
StudyReportFragmentsEntity oldLowMastery = new StudyReportFragmentsEntity();
|
||||
oldLowMastery.setId(1);
|
||||
oldLowMastery.setSessionNum("S_LOW");
|
||||
oldLowMastery.setContextNum("S_LOW");
|
||||
oldLowMastery.setContextType("SESSION");
|
||||
oldLowMastery.setOwnerTaskNum("T_LOW");
|
||||
oldLowMastery.setContent("很久没复习且掌握度低");
|
||||
oldLowMastery.setCreatedTime(now.minusDays(60));
|
||||
|
||||
StudyReportFragmentsEntity freshHighMastery = new StudyReportFragmentsEntity();
|
||||
freshHighMastery.setId(2);
|
||||
freshHighMastery.setSessionNum("S_HIGH");
|
||||
freshHighMastery.setContextNum("S_HIGH");
|
||||
freshHighMastery.setContextType("SESSION");
|
||||
freshHighMastery.setOwnerTaskNum("T_HIGH");
|
||||
freshHighMastery.setContent("刚学完且掌握度高");
|
||||
freshHighMastery.setCreatedTime(now);
|
||||
|
||||
StudySessionsEntity sessionLow = new StudySessionsEntity();
|
||||
sessionLow.setSessionNum("S_LOW");
|
||||
sessionLow.setTaskNum("T_LOW");
|
||||
StudySessionsEntity sessionHigh = new StudySessionsEntity();
|
||||
sessionHigh.setSessionNum("S_HIGH");
|
||||
sessionHigh.setTaskNum("T_HIGH");
|
||||
|
||||
TaskEntity taskLow = new TaskEntity();
|
||||
taskLow.setTaskNum("T_LOW");
|
||||
taskLow.setTaskName("低掌握任务");
|
||||
@@ -101,7 +98,6 @@ class ReviewServiceImplTest {
|
||||
// 复习-03:随机取样改为「主键区间 + 顺序取窗口」,因此需要提供 id 区间
|
||||
when(studyReportFragmentsMapper.selectIdRange()).thenReturn(idRange(1, 2));
|
||||
when(studyReportFragmentsMapper.selectList(any())).thenReturn(List.of(oldLowMastery, freshHighMastery));
|
||||
when(studySessionsMapper.selectList(any())).thenReturn(List.of(sessionLow, sessionHigh));
|
||||
when(tasksMapper.selectList(any())).thenReturn(List.of(taskLow, taskHigh));
|
||||
when(reviewRecallRecordMapper.selectList(any())).thenReturn(List.of(highRatioRecord));
|
||||
|
||||
@@ -125,20 +121,18 @@ class ReviewServiceImplTest {
|
||||
void getReviewFeed_shouldReturnFragmentsOnly() {
|
||||
StudyReportFragmentsEntity fragment = new StudyReportFragmentsEntity();
|
||||
fragment.setId(1);
|
||||
fragment.setSessionNum("S1");
|
||||
fragment.setContextNum("S1");
|
||||
fragment.setContextType("SESSION");
|
||||
// 归属-01:Feed 条目上的任务名取自「内容归属」,不再取自产生它的会话
|
||||
fragment.setOwnerTaskNum("T1");
|
||||
fragment.setContent("fragment");
|
||||
fragment.setCreatedTime(LocalDateTime.now().minusMinutes(1));
|
||||
|
||||
StudySessionsEntity session = new StudySessionsEntity();
|
||||
session.setSessionNum("S1");
|
||||
session.setTaskNum("T1");
|
||||
|
||||
TaskEntity task = new TaskEntity();
|
||||
task.setTaskNum("T1");
|
||||
task.setTaskName("Task");
|
||||
|
||||
when(studyReportFragmentsMapper.selectList(any())).thenReturn(List.of(fragment));
|
||||
when(studySessionsMapper.selectList(any())).thenReturn(List.of(session));
|
||||
when(tasksMapper.selectList(any())).thenReturn(List.of(task));
|
||||
|
||||
List<ReviewFeedItem> items = reviewService.getReviewFeed(1, "recent");
|
||||
|
||||
+8
-5
@@ -105,7 +105,7 @@ class ReviewStatsAggregationIntegrationTest {
|
||||
|
||||
insertReport(first.getSessionNum());
|
||||
insertReport(first.getSessionNum());
|
||||
insertFragment(second.getSessionNum());
|
||||
insertFragment(second.getSessionNum(), taskNum);
|
||||
|
||||
List<TaskContentCount> reports = studyReportsMapper.countReportsByTask(Set.of(taskNum));
|
||||
List<TaskContentCount> fragments = studyReportFragmentsMapper.countFragmentsByTask(Set.of(taskNum));
|
||||
@@ -125,7 +125,7 @@ class ReviewStatsAggregationIntegrationTest {
|
||||
StudyReportsEntity deleted = insertReport(session.getSessionNum());
|
||||
studyReportsMapper.deleteById(deleted.getId());
|
||||
|
||||
StudyReportFragmentsEntity deletedFragment = insertFragment(session.getSessionNum());
|
||||
StudyReportFragmentsEntity deletedFragment = insertFragment(session.getSessionNum(), taskNum);
|
||||
studyReportFragmentsMapper.deleteById(deletedFragment.getId());
|
||||
|
||||
List<TaskContentCount> reports = studyReportsMapper.countReportsByTask(Set.of(taskNum));
|
||||
@@ -169,14 +169,17 @@ class ReviewStatsAggregationIntegrationTest {
|
||||
private StudyReportsEntity insertReport(String sessionNum) {
|
||||
StudyReportsEntity report = new StudyReportsEntity();
|
||||
report.setSessionNum(sessionNum);
|
||||
report.setContent("集成测试报告");
|
||||
report.setFreeSummary("集成测试报告");
|
||||
studyReportsMapper.insert(report);
|
||||
return report;
|
||||
}
|
||||
|
||||
private StudyReportFragmentsEntity insertFragment(String sessionNum) {
|
||||
private StudyReportFragmentsEntity insertFragment(String sessionNum, String ownerTaskNum) {
|
||||
StudyReportFragmentsEntity fragment = new StudyReportFragmentsEntity();
|
||||
fragment.setSessionNum(sessionNum);
|
||||
fragment.setContextNum(sessionNum);
|
||||
fragment.setContextType("SESSION");
|
||||
// 归属-01:碎片计数按内容归属聚合,因此必须带上归属任务
|
||||
fragment.setOwnerTaskNum(ownerTaskNum);
|
||||
fragment.setContent("集成测试碎片");
|
||||
studyReportFragmentsMapper.insert(fragment);
|
||||
return fragment;
|
||||
|
||||
+3
-6
@@ -34,11 +34,9 @@ class StandardMindMapServiceImplTest {
|
||||
@Mock
|
||||
private TasksMapper tasksMapper;
|
||||
@Mock
|
||||
private StudyReportsMapper studyReportsMapper;
|
||||
@Mock
|
||||
private TaskApplicationMapper taskApplicationMapper;
|
||||
@Mock
|
||||
private StudySessionsMapper studySessionsMapper;
|
||||
private StudyReportFragmentsMapper studyReportFragmentsMapper;
|
||||
@Mock
|
||||
private List<MindMapAiClient> aiClients;
|
||||
@Mock
|
||||
@@ -186,9 +184,8 @@ class StandardMindMapServiceImplTest {
|
||||
|
||||
private StandardMindMapServiceImpl createService() {
|
||||
StandardMindMapServiceImpl s = new StandardMindMapServiceImpl(
|
||||
standardMindMapMapper, recallRecordMapper,
|
||||
tasksMapper, studyReportsMapper,
|
||||
taskApplicationMapper, studySessionsMapper,
|
||||
standardMindMapMapper, recallRecordMapper, tasksMapper,
|
||||
taskApplicationMapper, studyReportFragmentsMapper,
|
||||
List.of(mockAiClient), objectMapper, aiServiceClient);
|
||||
return s;
|
||||
}
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ class StudyReportFragmentsServiceImplTest {
|
||||
|
||||
private CreateFragmentsRequest createRequest(String sessionNum, String content) {
|
||||
CreateFragmentsRequest request = new CreateFragmentsRequest();
|
||||
request.setSessionNum(sessionNum);
|
||||
request.setContextNum(sessionNum);
|
||||
request.setContent(content);
|
||||
return request;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class StudyReportFragmentsServiceImplTest {
|
||||
studyReportFragmentsService.createFragments(createRequest("SESSION_A", "今天学了导数"));
|
||||
|
||||
verify(studyReportFragmentsService).save(argThat(entity ->
|
||||
"SESSION_A".equals(entity.getSessionNum())
|
||||
"SESSION_A".equals(entity.getContextNum())
|
||||
&& "今天学了导数".equals(entity.getContent())));
|
||||
}
|
||||
|
||||
|
||||
+15
-14
@@ -2,6 +2,7 @@ package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.guo.learningprogresstracker.common.StudyTimePolicy;
|
||||
import com.guo.learningprogresstracker.dto.ReportSections;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
||||
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
@@ -97,7 +98,7 @@ class StudySessionsServiceImplTest {
|
||||
StudySessionsEntity session = createSession(StudySessionStateEnum.ONGOING.name(), 5);
|
||||
mockGetOneOpt(session);
|
||||
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", "学习内容");
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", new ReportSections(null, null, "学习内容"));
|
||||
|
||||
assertEquals("本次有效学习时间不足10分钟,不计入总学习时间", message);
|
||||
assertEquals(0, session.getEffectiveTime(), "effectiveTime 应被清零");
|
||||
@@ -113,7 +114,7 @@ class StudySessionsServiceImplTest {
|
||||
StudySessionsEntity session = createSession(StudySessionStateEnum.ONGOING.name(), 15);
|
||||
mockGetOneOpt(session);
|
||||
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", "学习内容");
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", new ReportSections(null, null, "学习内容"));
|
||||
|
||||
assertNull(message, "有效时间超过10分钟不应返回提示");
|
||||
assertTrue(session.getEffectiveTime() > 0, "effectiveTime 应保留");
|
||||
@@ -129,7 +130,7 @@ class StudySessionsServiceImplTest {
|
||||
session.setEffectiveTime(5 * 60);
|
||||
mockGetOneOpt(session);
|
||||
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", "学习内容");
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", new ReportSections(null, null, "学习内容"));
|
||||
|
||||
assertNull(message, "PAUSED 状态结束不返回提示(用户已主动暂停)");
|
||||
assertEquals(0, session.getEffectiveTime(), "effectiveTime 仍应被实体层清零");
|
||||
@@ -144,7 +145,7 @@ class StudySessionsServiceImplTest {
|
||||
session.setEffectiveTime(15 * 60);
|
||||
mockGetOneOpt(session);
|
||||
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", "学习内容");
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", new ReportSections(null, null, "学习内容"));
|
||||
|
||||
assertNull(message);
|
||||
assertTrue(session.getEffectiveTime() > 0, "effectiveTime 应保留");
|
||||
@@ -158,11 +159,11 @@ class StudySessionsServiceImplTest {
|
||||
StudySessionsEntity session = createSession(StudySessionStateEnum.ONGOING.name(), 3);
|
||||
mockGetOneOpt(session);
|
||||
|
||||
studySessionsService.endedStudySession("SESSION_TEST", "测试报告内容");
|
||||
studySessionsService.endedStudySession("SESSION_TEST", new ReportSections(null, null, "测试报告内容"));
|
||||
|
||||
verify(studyReportsMapper).insert(argThat(report ->
|
||||
"SESSION_TEST".equals(((StudyReportsEntity) report).getSessionNum())
|
||||
&& "测试报告内容".equals(((StudyReportsEntity) report).getContent())
|
||||
&& "测试报告内容".equals(((StudyReportsEntity) report).getFreeSummary())
|
||||
));
|
||||
}
|
||||
|
||||
@@ -174,7 +175,7 @@ class StudySessionsServiceImplTest {
|
||||
StudySessionsEntity session = createSession(StudySessionStateEnum.ONGOING.name(), 10);
|
||||
mockGetOneOpt(session);
|
||||
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", "学习内容");
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", new ReportSections(null, null, "学习内容"));
|
||||
|
||||
assertNull(message, "有效时间等于10分钟应保留(阈值为 < 600)");
|
||||
assertTrue(session.getEffectiveTime() >= 10 * 60, "effectiveTime 应保留");
|
||||
@@ -188,7 +189,7 @@ class StudySessionsServiceImplTest {
|
||||
doReturn(Optional.empty()).when(studySessionsService).getOneOpt(any(Wrapper.class));
|
||||
|
||||
assertThrows(Exception.class, () ->
|
||||
studySessionsService.endedStudySession("NOT_EXIST", "内容"));
|
||||
studySessionsService.endedStudySession("NOT_EXIST", new ReportSections(null, null, "内容")));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,7 +200,7 @@ class StudySessionsServiceImplTest {
|
||||
StudySessionsEntity session = createSession(StudySessionStateEnum.ONGOING.name(), 1);
|
||||
mockGetOneOpt(session);
|
||||
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", "学习内容");
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", new ReportSections(null, null, "学习内容"));
|
||||
|
||||
assertEquals("本次有效学习时间不足10分钟,不计入总学习时间", message);
|
||||
assertEquals(0, session.getEffectiveTime());
|
||||
@@ -219,7 +220,7 @@ class StudySessionsServiceImplTest {
|
||||
session.setActualTime(0);
|
||||
mockGetOneOpt(session);
|
||||
|
||||
String message = studySessionsService.endedStudySession("SESSION_INSTANT", "内容");
|
||||
String message = studySessionsService.endedStudySession("SESSION_INSTANT", new ReportSections(null, null, "内容"));
|
||||
|
||||
assertEquals("本次有效学习时间不足10分钟,不计入总学习时间", message);
|
||||
assertEquals(0, session.getEffectiveTime());
|
||||
@@ -234,7 +235,7 @@ class StudySessionsServiceImplTest {
|
||||
session.setId(10);
|
||||
mockGetOneOpt(session);
|
||||
|
||||
studySessionsService.endedStudySession("SESSION_TEST", "内容");
|
||||
studySessionsService.endedStudySession("SESSION_TEST", new ReportSections(null, null, "内容"));
|
||||
|
||||
verify(studySessionsService).update(eq(session), any(Wrapper.class));
|
||||
}
|
||||
@@ -344,7 +345,7 @@ class StudySessionsServiceImplTest {
|
||||
session.setId(20);
|
||||
mockGetOneOpt(session);
|
||||
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", "内容");
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", new ReportSections(null, null, "内容"));
|
||||
|
||||
assertNull(message, "截断后 25 分钟 ≥ 10 分钟,不应提示时间不足");
|
||||
assertEquals(25 * 60, session.getEffectiveTime(), "3 小时无人操作只应计入 25 分钟");
|
||||
@@ -398,7 +399,7 @@ class StudySessionsServiceImplTest {
|
||||
session.setEffectiveTime(5 * 60);
|
||||
mockGetOneOpt(session);
|
||||
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", "内容");
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", new ReportSections(null, null, "内容"));
|
||||
|
||||
assertNull(message);
|
||||
verify(studyReportsMapper, never()).insert(any(StudyReportsEntity.class));
|
||||
@@ -415,7 +416,7 @@ class StudySessionsServiceImplTest {
|
||||
mockGetOneOpt(session);
|
||||
doReturn(false).when(studySessionsService).update(any(StudySessionsEntity.class), any(Wrapper.class));
|
||||
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", "内容");
|
||||
String message = studySessionsService.endedStudySession("SESSION_TEST", new ReportSections(null, null, "内容"));
|
||||
|
||||
assertNull(message);
|
||||
verify(studyReportsMapper, never()).insert(any(StudyReportsEntity.class));
|
||||
|
||||
+2
-2
@@ -74,8 +74,8 @@ class StudySessionsSettlementIntegrationTest {
|
||||
void endedStudySession_repeatedCall_shouldCreateOnlyOneReport() throws Exception {
|
||||
StudySessionsEntity session = saveForgottenOngoingSession();
|
||||
|
||||
studySessionsService.endedStudySession(session.getSessionNum(), "第一次结束");
|
||||
studySessionsService.endedStudySession(session.getSessionNum(), "重复结束");
|
||||
studySessionsService.endedStudySession(session.getSessionNum(), new com.guo.learningprogresstracker.dto.ReportSections(null, null, "第一次结束"));
|
||||
studySessionsService.endedStudySession(session.getSessionNum(), new com.guo.learningprogresstracker.dto.ReportSections(null, null, "重复结束"));
|
||||
|
||||
StudySessionsEntity reloaded = reload(session.getSessionNum());
|
||||
assertEquals(StudySessionStateEnum.ENDED.name(), reloaded.getSessionState());
|
||||
|
||||
Reference in New Issue
Block a user