- 移除 MindMapNode.sessionNum、filterBySession、getTaskSessions
- 新增 MindMapTreeTool.extractSubtree() 按路径提取子树作为对比基准
- 新增 findClosestNode/getPath/similarityScore 支持节点匹配
- 新增 POST /review/standard-mind-map/{taskNum}/find-node
- recallCompare 使用 focusPath 替代 sessionNum
- ReviewRecallRecordEntity.focusPath 替代 sessionNum
- Flyway V20260706_1: review_recall_records 加 focus_path 列
141 lines
6.2 KiB
Java
141 lines
6.2 KiB
Java
package com.guo.learningprogresstracker.controller;
|
|
|
|
import com.google.protobuf.ServiceException;
|
|
import com.guo.learningprogresstracker.dto.request.EndedStudySessionRequest;
|
|
import com.guo.learningprogresstracker.dto.request.UpsertExpectationRequest;
|
|
import com.guo.learningprogresstracker.dto.response.StudySessionResponse;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.guo.learningprogresstracker.entity.CommonResult;
|
|
import com.guo.learningprogresstracker.entity.StudyExpectationsEntity;
|
|
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
|
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
|
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
|
import com.guo.learningprogresstracker.service.StudyExpectationsService;
|
|
import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl;
|
|
import jakarta.validation.Valid;
|
|
import jakarta.validation.constraints.NotEmpty;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.ArrayList;
|
|
import java.time.LocalDateTime;
|
|
|
|
/**
|
|
* 学习会话控制层
|
|
*/
|
|
@RequestMapping("/study-sessions")
|
|
@RestController
|
|
@RequiredArgsConstructor
|
|
@Validated
|
|
public class StudySessionController {
|
|
|
|
private final StudySessionsServiceImpl studySessionsServiceImpl;
|
|
|
|
private final StudyExpectationsService studyExpectationsService;
|
|
|
|
/**
|
|
* 创建/更新学习会话的学习预期
|
|
*/
|
|
@PutMapping("/{sessionNum}/expectation")
|
|
public CommonResult<StudyExpectationsEntity> upsertExpectation(
|
|
@PathVariable("sessionNum") String sessionNum,
|
|
@Valid @RequestBody UpsertExpectationRequest request) throws ErrorParameterException {
|
|
return CommonResult.success(studyExpectationsService.upsertExpectation(sessionNum, request.getDescription()));
|
|
}
|
|
|
|
/**
|
|
* 获取学习会话的学习预期
|
|
*/
|
|
@GetMapping("/{sessionNum}/expectation")
|
|
public CommonResult<StudyExpectationsEntity> getExpectation(
|
|
@PathVariable("sessionNum") String sessionNum) {
|
|
return CommonResult.success(studyExpectationsService.getBySessionNum(sessionNum));
|
|
}
|
|
|
|
/**
|
|
* 通过sessionNum获取一个【学习会话】
|
|
*/
|
|
@GetMapping("/{sessionNum}")
|
|
public CommonResult<StudySessionResponse> getStudySessionBySessionNum(@NotEmpty(message = "sessionNum不可为空") @PathVariable String sessionNum) throws ErrorParameterException {
|
|
// 通过 service 层获取,包含归属校验
|
|
StudySessionResponse response = studySessionsServiceImpl.getStudySessionBySessionNum(sessionNum);
|
|
return CommonResult.success(response);
|
|
}
|
|
|
|
/**
|
|
* 开始一个【学习会话】
|
|
*/
|
|
@PostMapping("/{sessionNum}/study-sessions/continue")
|
|
public CommonResult<Void> startStudySession(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException, ServiceException {
|
|
studySessionsServiceImpl.continueStudySession(sessionNum);
|
|
return CommonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 暂停一个【学习会话】
|
|
*/
|
|
@PostMapping("/{sessionNum}/study-sessions/pause")
|
|
public CommonResult<Void> pauseStudySession(@PathVariable("sessionNum") String sessionNum,
|
|
@RequestParam(value = "endTime", required = false) LocalDateTime endTime)
|
|
throws ErrorParameterException, ServiceException {
|
|
studySessionsServiceImpl.pauseStudySession(sessionNum, endTime);
|
|
return CommonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 结束一个【学习会话】
|
|
*/
|
|
@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());
|
|
return message != null ? CommonResult.success(message) : CommonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 获取【学习会话】所有的学习残片数据,以列表返回
|
|
*/
|
|
@GetMapping("/{sessionNum}/all-fragments")
|
|
public CommonResult<ArrayList<String>> getAllFragments(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException {
|
|
ArrayList<String> allFragments = studySessionsServiceImpl.getAllFragments(sessionNum);
|
|
return CommonResult.success(allFragments);
|
|
|
|
}
|
|
|
|
/**
|
|
* 生成学习报告草稿:AI 聚合残片(不可用时降级为拼接),返回给前端作为编辑起点
|
|
*/
|
|
@GetMapping("/{sessionNum}/report-draft")
|
|
public CommonResult<String> getReportDraft(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException {
|
|
return CommonResult.success("请求成功", studySessionsServiceImpl.generateReportDraft(sessionNum));
|
|
}
|
|
|
|
/** 分页查询任务的残片历史 */
|
|
@GetMapping("/tasks/{taskNum}/fragments")
|
|
public CommonResult<Page<StudyReportFragmentsEntity>> getTaskFragments(
|
|
@PathVariable String taskNum,
|
|
@RequestParam(defaultValue = "1") int page,
|
|
@RequestParam(defaultValue = "10") int size,
|
|
@RequestParam(required = false) String keyword) {
|
|
return CommonResult.success(studySessionsServiceImpl.getTaskFragments(taskNum, page, size, keyword));
|
|
}
|
|
|
|
/** 分页查询任务的报告历史 */
|
|
@GetMapping("/tasks/{taskNum}/reports")
|
|
public CommonResult<Page<StudyReportsEntity>> getTaskReports(
|
|
@PathVariable String taskNum,
|
|
@RequestParam(defaultValue = "1") int page,
|
|
@RequestParam(defaultValue = "10") int size,
|
|
@RequestParam(required = false) String keyword) {
|
|
return CommonResult.success(studySessionsServiceImpl.getTaskReports(taskNum, page, size, keyword));
|
|
}
|
|
|
|
/** 查询当前是否有活跃会话(用于跨页面恢复 + 阻止多任务) */
|
|
@GetMapping("/active")
|
|
public CommonResult<StudySessionResponse> getActiveSession(
|
|
@RequestParam(required = false) String excludeTaskNum) {
|
|
return CommonResult.success(studySessionsServiceImpl.getActiveSession(excludeTaskNum));
|
|
}
|
|
}
|