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);
|
||||
|
||||
Reference in New Issue
Block a user