refactor: 回忆改用独立存储与请求响应 DTO,服务按域拆包

This commit is contained in:
2026-11-20 09:38:16 +08:00
parent 5ff692b768
commit 4b65eb57b1
280 changed files with 8774 additions and 4364 deletions
@@ -1,6 +1,7 @@
package com.guo.learningprogresstracker;
import cn.dev33.satoken.SaManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -8,12 +9,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @author guo
* 应用程序启动类
*/
@Slf4j
@SpringBootApplication
public class LearningProgressTrackerApplication {
public static void main(String[] args) {
SpringApplication.run(LearningProgressTrackerApplication.class, args);
System.out.println("启动成功,Sa-Token 配置如下:" + SaManager.getConfig());
log.info("启动成功,Sa-Token 配置如下:{}", SaManager.getConfig());
}
}
@@ -15,51 +15,55 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
@ExceptionHandler(com.guo.learningprogresstracker.exception.RecallBusinessException.class)
public CommonResult<com.guo.learningprogresstracker.dto.recall.RecallDtos.BusinessError> recallBusinessException(
com.guo.learningprogresstracker.exception.RecallBusinessException ex) {
return new CommonResult<>(400, ex.getMessage(), ex.getData());
}
@ExceptionHandler({ErrorParameterException.class})
public CommonResult errorParameterException(ErrorParameterException ex) {
public CommonResult<Void> errorParameterException(ErrorParameterException ex) {
log.warn("参数异常: {}", ex.getMessage(), ex);
return CommonResult.error(ex.getMessage());
}
@ExceptionHandler({NotFindEntitiesException.class})
public CommonResult notFindEntitiesException(NotFindEntitiesException ex) {
public CommonResult<Void> notFindEntitiesException(NotFindEntitiesException ex) {
log.warn("数据不存在: {}", ex.getMessage(), ex);
return CommonResult.error(ex.getMessage());
}
@ExceptionHandler({OperationFailedException.class})
public CommonResult operationFailedException(OperationFailedException ex) {
public CommonResult<Void> operationFailedException(OperationFailedException ex) {
log.warn("操作失败: {}", ex.getMessage(), ex);
return CommonResult.error(ex.getMessage());
}
@ExceptionHandler({AppException.class})
public CommonResult AppException(AppException ex) {
public CommonResult<Void> handleAppException(AppException ex) {
log.error("业务异常: {}", ex.getMessage(), ex);
return CommonResult.serverError(ex.getMessage());
}
@ExceptionHandler(MethodArgumentNotValidException.class)
public CommonResult MyMethodArgumentNotValidException(MethodArgumentNotValidException ex) {
public CommonResult<Void> handleArgumentNotValid(MethodArgumentNotValidException ex) {
BindingResult bindingResult = ex.getBindingResult();
return CommonResult.error(bindingResult.getFieldError().getDefaultMessage());
}
@ExceptionHandler(NotLoginException.class)
public CommonResult handleNotLogin(NotLoginException e, HttpServletRequest req, HttpServletResponse res) {
public CommonResult<Void> handleNotLogin(NotLoginException e, HttpServletRequest req, HttpServletResponse res) {
res.setStatus(HttpStatus.UNAUTHORIZED.value());
return new CommonResult<>(HttpStatus.UNAUTHORIZED.value(), "未登录,请重新登录", null);
}
@ExceptionHandler(Exception.class)
public CommonResult Exception(Exception ex) {
public CommonResult<Void> handleUnexpected(Exception ex) {
log.error("系统异常", ex);
return CommonResult.error("操作没有成功,请稍后再试");
return CommonResult.serverError("操作没有成功,请稍后再试");
}
}
@@ -7,10 +7,8 @@ import jakarta.validation.groups.Default;
*/
public interface Ops {
// 创建组
interface CreateG extends Default {
}
interface CreateG extends Default {}
// 更新组
interface UpdateG {
}
interface UpdateG {}
}
@@ -35,8 +35,8 @@ public class StudyTimePolicy {
*/
private final long minEffectiveTimeSeconds;
public StudyTimePolicy(int workDurationMinutes, int forgetThresholdMinutes,
int forcePauseMinutes, long minEffectiveTimeSeconds) {
public StudyTimePolicy(
int workDurationMinutes, int forgetThresholdMinutes, int forcePauseMinutes, long minEffectiveTimeSeconds) {
if (workDurationMinutes <= 0) {
throw new IllegalArgumentException("番茄钟长度必须大于 0 分钟");
}
@@ -18,13 +18,11 @@ public final class TenantContext {
* @param loginId 登录用户
* @param device 设备类型,可为 null(后台任务通常没有设备信息)
*/
public record Identity(String loginId, String device) {
}
public record Identity(String loginId, String device) {}
private static final ThreadLocal<Identity> CURRENT = new ThreadLocal<>();
private TenantContext() {
}
private TenantContext() {}
/** 取当前执行身份;未设置时返回 null(表示应回落到 StpUtil) */
public static Identity get() {
@@ -1,11 +1,10 @@
package com.guo.learningprogresstracker.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.math.BigDecimal;
import java.util.List;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* AI 用量统计配置。
@@ -3,12 +3,11 @@ package com.guo.learningprogresstracker.config;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.guo.learningprogresstracker.common.TenantContext;
import java.time.LocalDateTime;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;
import java.time.LocalDateTime;
/**
* 用于公共字段的自动填充
*
@@ -18,7 +17,6 @@ import java.time.LocalDateTime;
@Slf4j
public class AutoTableField implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.strictInsertFill(metaObject, "createdBy", AutoTableField::currentLoginId, String.class);
@@ -28,7 +26,6 @@ public class AutoTableField implements MetaObjectHandler {
this.strictInsertFill(metaObject, "deviceInfo", AutoTableField::currentDevice, String.class);
}
@Override
public void updateFill(MetaObject metaObject) {
this.strictInsertFill(metaObject, "lastModifiedBy", AutoTableField::currentLoginId, String.class);
@@ -51,5 +48,4 @@ public class AutoTableField implements MetaObjectHandler {
TenantContext.Identity identity = TenantContext.get();
return identity != null ? identity.device() : StpUtil.getLoginDevice();
}
}
@@ -10,5 +10,4 @@ import org.springframework.context.annotation.Configuration;
public class CorsProperties {
private String[] allowedOrigins;
private Boolean allowCredentials;
}
@@ -4,12 +4,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.guo.learningprogresstracker.config.serializer.LocalDateTimeSerializer;
import java.time.LocalDateTime;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import java.time.LocalDateTime;
@Configuration
public class JacksonConfig {
@Bean
@@ -1,18 +1,17 @@
package com.guo.learningprogresstracker.config;
import cn.dev33.satoken.stp.StpUtil;
import com.guo.learningprogresstracker.common.TenantContext;
import net.sf.jsqlparser.expression.StringValue;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import net.sf.jsqlparser.expression.Expression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.guo.learningprogresstracker.common.TenantContext;
import java.util.Arrays;
import java.util.List;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.StringValue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* MyBatis-Plus 多租户配置
@@ -30,12 +29,7 @@ public class MybatisPlusConfig {
* 若按 created_by 过滤,每个人只能看到自己触发的那几次调用,面板等于永远空的。</p>
*/
private static final List<String> EXCLUDE_TABLES = Arrays.asList(
"user",
"flyway_schema_history",
"databasechangelog",
"databasechangeloglock",
"ai_usage_records"
);
"user", "flyway_schema_history", "databasechangelog", "databasechangeloglock", "ai_usage_records");
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
@@ -3,6 +3,7 @@ package com.guo.learningprogresstracker.config;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
@@ -10,8 +11,6 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.Arrays;
@Configuration
@RequiredArgsConstructor
@Slf4j
@@ -49,7 +48,8 @@ public class WebMvcConfig implements WebMvcConfigurer {
.allowedOrigins(origins)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(corsProperties.getAllowCredentials() == null || corsProperties.getAllowCredentials());
.allowCredentials(
corsProperties.getAllowCredentials() == null || corsProperties.getAllowCredentials());
}
}
}
@@ -3,13 +3,12 @@ package com.guo.learningprogresstracker.config.serializer;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class LocalDateTimeSerializer extends StdSerializer<LocalDateTime> {
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
public LocalDateTimeSerializer() {
super(LocalDateTime.class);
@@ -20,7 +19,7 @@ public class LocalDateTimeSerializer extends StdSerializer<LocalDateTime> {
if (value == null) {
gen.writeNull();
} else {
String formattedDate = value.format(formatter);
String formattedDate = value.format(FORMATTER);
gen.writeString(formattedDate);
}
}
@@ -9,7 +9,13 @@ import com.guo.learningprogresstracker.service.AiTaskService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* AI 异步任务控制层(AI-02)。
@@ -49,8 +55,7 @@ public class AiTaskController {
* @return 无任务时 data 为 null
*/
@GetMapping("/latest")
public CommonResult<AiTaskResponse> getLatestTask(@RequestParam String type,
@RequestParam String targetNum) {
public CommonResult<AiTaskResponse> getLatestTask(@RequestParam String type, @RequestParam String targetNum) {
return CommonResult.success(aiTaskService.findLatest(type, targetNum));
}
}
@@ -9,13 +9,12 @@ import com.guo.learningprogresstracker.dto.request.AiUsageQuery;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.exception.ErrorParameterException;
import com.guo.learningprogresstracker.service.AiUsageService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 「AI 用量统计」面板查询接口(契约 2)。
*
@@ -8,6 +8,7 @@ import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.exception.ErrorParameterException;
import com.guo.learningprogresstracker.service.AiUsageService;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -15,8 +16,6 @@ import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* lpt-ai 用量上报(契约 1)。
*
@@ -43,7 +42,8 @@ public class AiUsageInternalController {
@PostMapping("/records")
public CommonResult<AiUsageIngestResult> report(
@RequestHeader(name = "x-api-token", required = false) String apiToken,
@Valid @RequestBody AiUsageReportRequest request) throws ErrorParameterException {
@Valid @RequestBody AiUsageReportRequest request)
throws ErrorParameterException {
if (!isTokenAccepted(apiToken)) {
return CommonResult.error("上报令牌不正确");
}
@@ -5,12 +5,15 @@ import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
import com.guo.learningprogresstracker.exception.OperationFailedException;
import com.guo.learningprogresstracker.service.ExportService;
import java.time.LocalDate;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 数据导出控制层(导出-01):把学习报告、知识碎片与任务统计导出为 Markdown / JSON。
@@ -29,8 +32,7 @@ public class ExportController {
*/
@GetMapping("/task/{taskNum}")
public CommonResult<ExportResult> exportTask(
@PathVariable String taskNum,
@RequestParam(defaultValue = "markdown") String format)
@PathVariable String taskNum, @RequestParam(defaultValue = "markdown") String format)
throws NotFindEntitiesException, OperationFailedException {
return CommonResult.success(exportService.exportTask(taskNum, format));
}
@@ -1,24 +1,34 @@
package com.guo.learningprogresstracker.controller;
import com.guo.learningprogresstracker.dto.AiTaskResponse;
import com.guo.learningprogresstracker.dto.ReviewTiming;
import com.guo.learningprogresstracker.dto.request.AiTaskSubmitRequest;
import com.guo.learningprogresstracker.dto.request.ConfirmGuidanceFragmentRequest;
import com.guo.learningprogresstracker.dto.request.GuidanceStartRequest;
import com.guo.learningprogresstracker.dto.request.GuidanceTurnRequest;
import com.guo.learningprogresstracker.dto.response.GuidanceConversationResponse;
import com.guo.learningprogresstracker.dto.response.ReportFragmentResponse;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.entity.ReviewGuidanceConversationEntity;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.exception.ErrorParameterException;
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
import com.guo.learningprogresstracker.service.AiTaskService;
import com.guo.learningprogresstracker.service.GuidanceService;
import com.guo.learningprogresstracker.dto.AiTaskResponse;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.time.LocalDateTime;
import java.time.format.DateTimeParseException;
import java.util.LinkedHashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 学习引导控制层(复习-06)。
@@ -42,11 +52,10 @@ public class GuidanceController {
*/
@PostMapping
@Operation(summary = "开启学习引导:返回引导编号与首个 AI 任务编号")
public CommonResult<Map<String, Object>> start(@RequestBody Map<String, String> body)
public CommonResult<Map<String, Object>> start(@Valid @RequestBody GuidanceStartRequest request)
throws NotFindEntitiesException, ErrorParameterException {
String taskNum = body == null ? null : body.get("taskNum");
String concept = body == null ? null : body.get("concept");
ReviewGuidanceConversationEntity conversation = guidanceService.start(taskNum, concept);
ReviewGuidanceConversationEntity conversation =
guidanceService.start(request.getTaskNum(), request.getConcept());
Map<String, Object> result = new LinkedHashMap<>();
result.put("guidanceNum", conversation.getGuidanceNum());
@@ -60,10 +69,10 @@ public class GuidanceController {
* 继续一轮:提交用户的回答/追问,返回本轮 AI 任务编号
*/
@PostMapping("/{guidanceNum}/turns")
public CommonResult<AiTaskResponse> continueTurn(@PathVariable String guidanceNum,
@RequestBody Map<String, String> body)
public CommonResult<AiTaskResponse> continueTurn(
@PathVariable String guidanceNum, @Valid @RequestBody GuidanceTurnRequest request)
throws NotFindEntitiesException, ErrorParameterException {
guidanceService.appendUserTurn(guidanceNum, body == null ? null : body.get("message"));
guidanceService.appendUserTurn(guidanceNum, request.getMessage());
return CommonResult.success(submitTurn(guidanceNum));
}
@@ -71,9 +80,9 @@ public class GuidanceController {
* 读取这次引导的当前状态(含对话轮次),用于离开页面后回来继续
*/
@GetMapping("/{guidanceNum}")
public CommonResult<ReviewGuidanceConversationEntity> getConversation(@PathVariable String guidanceNum)
public CommonResult<GuidanceConversationResponse> getConversation(@PathVariable String guidanceNum)
throws NotFindEntitiesException {
return CommonResult.success(guidanceService.getByGuidanceNum(guidanceNum));
return CommonResult.success(GuidanceConversationResponse.of(guidanceService.getByGuidanceNum(guidanceNum)));
}
/**
@@ -81,16 +90,16 @@ public class GuidanceController {
* <p>不确认就不产生任何数据。</p>
*/
@PostMapping("/{guidanceNum}/fragments")
public CommonResult<StudyReportFragmentsEntity> confirmFragment(@PathVariable String guidanceNum,
@RequestBody Map<String, Object> body)
public CommonResult<ReportFragmentResponse> confirmFragment(
@PathVariable String guidanceNum, @RequestBody ConfirmGuidanceFragmentRequest request)
throws ErrorParameterException, NotFindEntitiesException {
String content = body == null ? null : (String) body.get("content");
ReviewTiming timing = new ReviewTiming(
parseTime(body == null ? null : body.get("reviewStartedAt")),
parseTime(body == null ? null : body.get("reviewLastInteractionAt")),
body != null && body.get("reviewDurationSeconds") instanceof Number number
? number.intValue() : null);
return CommonResult.success(guidanceService.confirmFragment(guidanceNum, content, timing));
parseTime(request.getReviewStartedAt()),
parseTime(request.getReviewLastInteractionAt()),
request.getReviewDurationSeconds());
String content = request.getContent();
return CommonResult.success(
ReportFragmentResponse.of(guidanceService.confirmFragment(guidanceNum, content, timing)));
}
/**
@@ -1,8 +1,8 @@
package com.guo.learningprogresstracker.controller;
import com.guo.learningprogresstracker.dto.LoginResult;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.dto.request.LoginBody;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.exception.AppException;
import com.guo.learningprogresstracker.service.AiUsageService;
import com.guo.learningprogresstracker.service.LoginService;
@@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@CrossOrigin
@RestController
@RequiredArgsConstructor
@@ -31,8 +30,8 @@ public class LoginController {
String token = loginService.login(userId);
// 用量面板的入口是否显示由服务端白名单决定,前端只读这个布尔值
boolean aiAdmin = aiUsageService.isAdmin();
//todo 参数传递未加密
return CommonResult.success("登录成功!", new LoginResult(token, aiAdmin));
// todo 参数传递未加密
return CommonResult.success("登录成功!", new LoginResult(token, aiAdmin, userId));
}
@Operation(summary = "退出登录API")
@@ -1,21 +1,34 @@
package com.guo.learningprogresstracker.controller;
import com.guo.learningprogresstracker.dto.MarkerUsage;
import com.guo.learningprogresstracker.dto.request.AddUserTagRequest;
import com.guo.learningprogresstracker.dto.request.CreateDictionaryTagRequest;
import com.guo.learningprogresstracker.dto.request.RenameDictionaryTagRequest;
import com.guo.learningprogresstracker.dto.request.RenameUserTagRequest;
import com.guo.learningprogresstracker.dto.response.MarkerResponse;
import com.guo.learningprogresstracker.dto.response.UserTagResponse;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.entity.MarkerEntity;
import com.guo.learningprogresstracker.entity.UserTagEntity;
import com.guo.learningprogresstracker.enums.MarkerObjectTypeEnum;
import com.guo.learningprogresstracker.exception.ErrorParameterException;
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
import com.guo.learningprogresstracker.service.MarkerService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 统一标记控制层(标记-01)。
@@ -35,20 +48,26 @@ public class MarkerController {
* 列出某个对象上的全部标记(系统标记与用户标签一起返回,前端按 kind 区分展示)
*/
@GetMapping
public CommonResult<List<MarkerEntity>> listByObject(@RequestParam String objectType,
@RequestParam String objectNum) {
return CommonResult.success(markerService.listByObject(MarkerObjectTypeEnum.parse(objectType), objectNum));
public CommonResult<List<MarkerResponse>> listByObject(
@RequestParam String objectType, @RequestParam String objectNum) {
return CommonResult.success(
markerService.listByObject(MarkerObjectTypeEnum.parse(objectType), objectNum).stream()
.map(MarkerResponse::of)
.toList());
}
/**
* 批量列出多个对象的标记(列表页一次取回一页,避免逐个请求)
*/
@PostMapping("/batch")
public CommonResult<Map<String, List<MarkerEntity>>> listByObjects(
@RequestParam String objectType,
@RequestBody Collection<String> objectNums) {
return CommonResult.success(
markerService.listByObjects(MarkerObjectTypeEnum.parse(objectType), objectNums));
public CommonResult<Map<String, List<MarkerResponse>>> listByObjects(
@RequestParam String objectType, @RequestBody Collection<String> objectNums) {
Map<String, List<MarkerResponse>> result = new LinkedHashMap<>();
markerService
.listByObjects(MarkerObjectTypeEnum.parse(objectType), objectNums)
.forEach((key, value) ->
result.put(key, value.stream().map(MarkerResponse::of).toList()));
return CommonResult.success(result);
}
/**
@@ -56,13 +75,10 @@ public class MarkerController {
*/
@PostMapping
@Operation(summary = "打用户标签;系统标记只能由系统写入,不开放此接口")
public CommonResult<MarkerEntity> addUserTag(@RequestBody Map<String, String> body)
public CommonResult<MarkerResponse> addUserTag(@Valid @RequestBody AddUserTagRequest request)
throws ErrorParameterException, NotFindEntitiesException {
String objectType = body == null ? null : body.get("objectType");
String objectNum = body == null ? null : body.get("objectNum");
String markerName = body == null ? null : body.get("markerName");
return CommonResult.success(
markerService.addUserTag(MarkerObjectTypeEnum.parse(objectType), objectNum, markerName));
return CommonResult.success(MarkerResponse.of(markerService.addUserTag(
MarkerObjectTypeEnum.parse(request.getObjectType()), request.getObjectNum(), request.getMarkerName())));
}
/**
@@ -79,18 +95,17 @@ public class MarkerController {
* 重命名一个用户标签(影响所有带该标签的对象)
*/
@PutMapping("/rename")
public CommonResult<Integer> renameUserTag(@RequestBody Map<String, String> body)
public CommonResult<Integer> renameUserTag(@Valid @RequestBody RenameUserTagRequest request)
throws ErrorParameterException {
String from = body == null ? null : body.get("oldName");
String to = body == null ? null : body.get("newName");
return CommonResult.success(markerService.renameUserTag(from, to));
return CommonResult.success(markerService.renameUserTag(request.getOldName(), request.getNewName()));
}
/**
* 按标记筛选对象(点标签即筛选):返回带该标记的对象标识列表
*/
@GetMapping("/filter")
public CommonResult<List<String>> filterByMarker(@RequestParam String objectType,
public CommonResult<List<String>> filterByMarker(
@RequestParam String objectType,
@RequestParam String markerName,
@RequestParam(required = false) String markerValue,
@RequestParam(required = false) String kind) {
@@ -102,37 +117,38 @@ public class MarkerController {
* 当前用户用过的标签及使用情况(标签管理入口)
*/
@GetMapping("/tags")
public CommonResult<List<MarkerUsage>> listUserTagUsage() {
return CommonResult.success(markerService.listUserTagUsage());
public CommonResult<List<MarkerUsage>> listUserTagUsage(@RequestParam(required = false) String objectType) {
return CommonResult.success(
markerService.listUserTagUsage(objectType == null ? null : MarkerObjectTypeEnum.parse(objectType)));
}
/**
* 标签字典:打标签的候选标签(尚未挂在任何对象上的也算)
*/
@GetMapping("/tags/dictionary")
public CommonResult<List<UserTagEntity>> listDictionaryTags() {
return CommonResult.success(markerService.listDictionaryTags());
public CommonResult<List<UserTagResponse>> listDictionaryTags() {
return CommonResult.success(markerService.listDictionaryTags().stream()
.map(UserTagResponse::of)
.toList());
}
/**
* 往字典里新建一个(空)标签;同名(按去空格、大小写不敏感)已存在时幂等返回既有项
*/
@PostMapping("/tags/dictionary")
public CommonResult<UserTagEntity> createDictionaryTag(@RequestBody Map<String, String> body)
public CommonResult<UserTagResponse> createDictionaryTag(@Valid @RequestBody CreateDictionaryTagRequest request)
throws ErrorParameterException {
String tagName = body == null ? null : body.get("tagName");
return CommonResult.success(markerService.createDictionaryTag(tagName));
return CommonResult.success(UserTagResponse.of(markerService.createDictionaryTag(request.getTagName())));
}
/**
* 字典标签改名:只影响候选,不改动任何对象上已经打好的标记
*/
@PutMapping("/tags/dictionary/{id}")
public CommonResult<UserTagEntity> renameDictionaryTag(@PathVariable Integer id,
@RequestBody Map<String, String> body)
public CommonResult<UserTagResponse> renameDictionaryTag(
@PathVariable Integer id, @Valid @RequestBody RenameDictionaryTagRequest request)
throws ErrorParameterException, NotFindEntitiesException {
String newName = body == null ? null : body.get("newName");
return CommonResult.success(markerService.renameDictionaryTag(id, newName));
return CommonResult.success(UserTagResponse.of(markerService.renameDictionaryTag(id, request.getNewName())));
}
/**
@@ -1,18 +1,24 @@
package com.guo.learningprogresstracker.controller;
import com.guo.learningprogresstracker.dto.request.AssignOwnershipRequest;
import com.guo.learningprogresstracker.dto.request.CreateFragmentsRequest;
import com.guo.learningprogresstracker.dto.request.UpdateFragmentsRequest;
import com.guo.learningprogresstracker.dto.response.ReportFragmentResponse;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
import com.guo.learningprogresstracker.service.impl.StudyReportFragmentsServiceImpl;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 知识碎片控制层(归属-01 起同时承载「内容归属」的调整动作)。
@@ -21,14 +27,15 @@ import java.util.Map;
@RestController
@Validated
@RequiredArgsConstructor
public class reportFragmentsController {
public class ReportFragmentsController {
private final StudyReportFragmentsServiceImpl studyReportFragmentsServiceImpl;
/**
* 创建知识碎片(记录上下文为当前学习会话,内容归属默认取该会话所属任务)
*/
@PostMapping
public CommonResult<Void> createFragments(@Valid @RequestBody CreateFragmentsRequest request) throws NotFindEntitiesException {
public CommonResult<Void> createFragments(@Valid @RequestBody CreateFragmentsRequest request)
throws NotFindEntitiesException {
studyReportFragmentsServiceImpl.createFragments(request);
return CommonResult.success();
}
@@ -37,8 +44,8 @@ public class reportFragmentsController {
* 修改知识碎片正文与内容归属(记录上下文不可变)
*/
@PutMapping("/{id}")
public CommonResult<Void> updateFragments(@PathVariable Integer id,
@RequestBody UpdateFragmentsRequest request) throws NotFindEntitiesException {
public CommonResult<Void> updateFragments(@PathVariable Integer id, @RequestBody UpdateFragmentsRequest request)
throws NotFindEntitiesException {
studyReportFragmentsServiceImpl.updateFragments(id, request);
return CommonResult.success();
}
@@ -47,10 +54,10 @@ public class reportFragmentsController {
* 调整内容归属;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);
public CommonResult<Void> assignOwnership(
@PathVariable Integer id, @Valid @RequestBody AssignOwnershipRequest request)
throws NotFindEntitiesException {
studyReportFragmentsServiceImpl.assignOwnership(id, request.getOwnerTaskNum());
return CommonResult.success();
}
@@ -67,8 +74,11 @@ public class reportFragmentsController {
* 获取指定会话产生的所有知识碎片(记录上下文为会话)
*/
@GetMapping("/session/{sessionNum}")
public CommonResult<List<StudyReportFragmentsEntity>> getFragmentsBySession(@PathVariable String sessionNum) {
List<StudyReportFragmentsEntity> fragments = studyReportFragmentsServiceImpl.getFragmentsBySession(sessionNum);
public CommonResult<List<ReportFragmentResponse>> getFragmentsBySession(@PathVariable String sessionNum) {
List<ReportFragmentResponse> fragments =
studyReportFragmentsServiceImpl.getFragmentsBySession(sessionNum).stream()
.map(ReportFragmentResponse::of)
.toList();
return CommonResult.success(fragments);
}
@@ -76,7 +86,9 @@ public class reportFragmentsController {
* 待归类内容:还没有确定内容归属的碎片
*/
@GetMapping("/pending-ownership")
public CommonResult<List<StudyReportFragmentsEntity>> getPendingOwnershipFragments() {
return CommonResult.success(studyReportFragmentsServiceImpl.getPendingOwnershipFragments());
public CommonResult<List<ReportFragmentResponse>> getPendingOwnershipFragments() {
return CommonResult.success(studyReportFragmentsServiceImpl.getPendingOwnershipFragments().stream()
.map(ReportFragmentResponse::of)
.toList());
}
}
@@ -1,30 +1,38 @@
package com.guo.learningprogresstracker.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guo.learningprogresstracker.dto.ReviewFeedItem;
import com.guo.learningprogresstracker.dto.ReviewSortPreference;
import com.guo.learningprogresstracker.dto.ReviewSummary;
import com.guo.learningprogresstracker.dto.ReviewTaskStats;
import com.guo.learningprogresstracker.dto.StudyReportDetail;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guo.learningprogresstracker.dto.request.UpdateStandardMindMapRequest;
import com.guo.learningprogresstracker.dto.request.FindNodeRequest;
import com.guo.learningprogresstracker.dto.request.ReviewFeedbackRequest;
import com.guo.learningprogresstracker.dto.request.SortPreferenceRequest;
import com.guo.learningprogresstracker.dto.request.UpdateStandardMindMapRequest;
import com.guo.learningprogresstracker.dto.request.UpdateStudyReportRequest;
import com.guo.learningprogresstracker.dto.response.ReportFragmentResponse;
import com.guo.learningprogresstracker.dto.response.StandardMindMapResponse;
import com.guo.learningprogresstracker.dto.response.StudyReportResponse;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.entity.ReviewRecallRecordEntity;
import com.guo.learningprogresstracker.entity.ReviewStandardMindMapEntity;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
import com.guo.learningprogresstracker.exception.OperationFailedException;
import com.guo.learningprogresstracker.service.ReviewService;
import com.guo.learningprogresstracker.service.StandardMindMapService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 复习模块控制层 — 复习内容滚动展示与交互
@@ -44,8 +52,7 @@ public class ReviewController {
*/
@GetMapping("/feed")
public CommonResult<List<ReviewFeedItem>> getReviewFeed(
@RequestParam(defaultValue = "30") int limit,
@RequestParam(defaultValue = "recent") String mode) {
@RequestParam(defaultValue = "30") int limit, @RequestParam(defaultValue = "recent") String mode) {
return CommonResult.success(reviewService.getReviewFeed(limit, mode));
}
@@ -55,8 +62,8 @@ public class ReviewController {
*/
@PutMapping("/feed/{fragmentId}/feedback")
public CommonResult<ReviewFeedbackRequest> submitFeedback(
@PathVariable Integer fragmentId,
@RequestBody ReviewFeedbackRequest request) throws NotFindEntitiesException {
@PathVariable Integer fragmentId, @RequestBody ReviewFeedbackRequest request)
throws NotFindEntitiesException {
return CommonResult.success(reviewService.submitFeedback(fragmentId, request));
}
@@ -81,9 +88,8 @@ public class ReviewController {
* 保存复习排序偏好(复习-01):三档预设,不做精确权重。
*/
@PutMapping("/sort-preference")
public CommonResult<ReviewSortPreference> saveSortPreference(@RequestBody Map<String, String> body) {
String preset = body == null ? null : body.get("preset");
return CommonResult.success(reviewService.saveSortPreference(preset));
public CommonResult<ReviewSortPreference> saveSortPreference(@RequestBody SortPreferenceRequest request) {
return CommonResult.success(reviewService.saveSortPreference(request.getPreset()));
}
/**
@@ -132,8 +138,8 @@ public class ReviewController {
* 获取报告详情(原始实体)
*/
@GetMapping("/report/{id}")
public CommonResult<StudyReportsEntity> getReportDetail(@PathVariable int id) throws NotFindEntitiesException {
return CommonResult.success(reviewService.getReportDetail(id));
public CommonResult<StudyReportResponse> getReportDetail(@PathVariable int id) throws NotFindEntitiesException {
return CommonResult.success(StudyReportResponse.of(reviewService.getReportDetail(id)));
}
/**
@@ -149,8 +155,7 @@ public class ReviewController {
* 修改学习报告的三段文本
*/
@PutMapping("/report/{id}")
public CommonResult<Void> updateReport(@PathVariable int id,
@RequestBody UpdateStudyReportRequest request)
public CommonResult<Void> updateReport(@PathVariable int id, @RequestBody UpdateStudyReportRequest request)
throws NotFindEntitiesException {
reviewService.updateReport(id, request);
return CommonResult.success();
@@ -169,8 +174,9 @@ public class ReviewController {
* 获取残片详情
*/
@GetMapping("/fragment/{id}")
public CommonResult<StudyReportFragmentsEntity> getFragmentDetail(@PathVariable int id) throws NotFindEntitiesException {
return CommonResult.success(reviewService.getFragmentDetail(id));
public CommonResult<ReportFragmentResponse> getFragmentDetail(@PathVariable int id)
throws NotFindEntitiesException {
return CommonResult.success(ReportFragmentResponse.of(reviewService.getFragmentDetail(id)));
}
// ============ 标准思维导图与回忆对比 ============
@@ -182,19 +188,20 @@ public class ReviewController {
* {@code POST /ai/tasks}(type=MIND_MAP)后轮询结果。</p>
*/
@GetMapping("/standard-mind-map/{taskNum}")
public CommonResult<ReviewStandardMindMapEntity> getStandardMindMap(
@PathVariable String taskNum) throws NotFindEntitiesException {
return CommonResult.success(standardMindMapService.getExisting(taskNum));
public CommonResult<StandardMindMapResponse> getStandardMindMap(@PathVariable String taskNum)
throws NotFindEntitiesException {
return CommonResult.success(StandardMindMapResponse.of(standardMindMapService.getExisting(taskNum)));
}
/**
* 用户编辑标准思维导图(大纲文本形式)
*/
@PutMapping("/standard-mind-map/{taskNum}")
public CommonResult<ReviewStandardMindMapEntity> updateStandardMindMap(
@PathVariable String taskNum,
@Valid @RequestBody UpdateStandardMindMapRequest request) throws NotFindEntitiesException {
return CommonResult.success(standardMindMapService.updateByOutline(taskNum, request.getOutline()));
public CommonResult<StandardMindMapResponse> updateStandardMindMap(
@PathVariable String taskNum, @Valid @RequestBody UpdateStandardMindMapRequest request)
throws NotFindEntitiesException {
return CommonResult.success(
StandardMindMapResponse.of(standardMindMapService.updateByOutline(taskNum, request.getOutline())));
}
/**
@@ -202,27 +209,9 @@ public class ReviewController {
*/
@PostMapping("/standard-mind-map/{taskNum}/find-node")
public CommonResult<Map<String, Object>> findNode(
@PathVariable String taskNum,
@RequestBody Map<String, String> body) throws NotFindEntitiesException, OperationFailedException {
String content = body != null ? body.getOrDefault("content", "") : "";
@PathVariable String taskNum, @RequestBody FindNodeRequest request)
throws NotFindEntitiesException, OperationFailedException {
String content = request == null || request.getContent() == null ? "" : request.getContent();
return CommonResult.success(standardMindMapService.findNode(taskNum, content));
}
/**
* 获取该任务的所有回忆对比记录
*/
@GetMapping("/standard-mind-map/{taskNum}/recall-records")
public CommonResult<List<ReviewRecallRecordEntity>> listRecallRecords(
@PathVariable String taskNum) throws NotFindEntitiesException {
return CommonResult.success(standardMindMapService.listRecallRecords(taskNum));
}
/**
* 获取单条回忆对比记录详情
*/
@GetMapping("/standard-mind-map/recall-records/{recordId}")
public CommonResult<ReviewRecallRecordEntity> getRecallRecord(
@PathVariable Integer recordId) throws NotFindEntitiesException {
return CommonResult.success(standardMindMapService.getRecallRecord(recordId));
}
}
@@ -0,0 +1,90 @@
package com.guo.learningprogresstracker.controller;
import com.fasterxml.jackson.databind.JsonNode;
import com.guo.learningprogresstracker.dto.recall.RecallDtos.CreateRecallRequest;
import com.guo.learningprogresstracker.dto.recall.RecallDtos.EndRequest;
import com.guo.learningprogresstracker.dto.recall.RecallDtos.RecallDetail;
import com.guo.learningprogresstracker.dto.recall.RecallDtos.RecallPage;
import com.guo.learningprogresstracker.dto.recall.RecallDtos.ReferenceContent;
import com.guo.learningprogresstracker.dto.recall.RecallDtos.ReferencePage;
import com.guo.learningprogresstracker.dto.recall.RecallDtos.ResumeRequest;
import com.guo.learningprogresstracker.dto.recall.RecallDtos.SaveDraftRequest;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.service.ai.RecallJson;
import com.guo.learningprogresstracker.service.recall.ReviewRecallService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/review/recalls")
@RequiredArgsConstructor
public class ReviewRecallController {
private final ReviewRecallService service;
private final RecallJson json;
@PostMapping
public CommonResult<RecallDetail> create(@RequestBody JsonNode body) {
return CommonResult.success(service.create(json.readInput(body, CreateRecallRequest.class)));
}
@GetMapping
public CommonResult<RecallPage> list(
@RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "20") int pageSize,
@RequestParam(required = false) String status,
@RequestParam(required = false) String scopeType,
@RequestParam(required = false) String taskNum,
@RequestParam org.springframework.util.MultiValueMap<String, String> query,
@RequestParam(required = false) String combineMode) {
// Read repeated values verbatim: a comma can be part of a single tag name.
return CommonResult.success(
service.list(pageNum, pageSize, status, scopeType, taskNum, query.get("tags"), combineMode));
}
@GetMapping("/{recallNum}")
public CommonResult<RecallDetail> get(@PathVariable String recallNum) {
return CommonResult.success(service.get(recallNum));
}
@PostMapping("/{recallNum}/resume")
public CommonResult<RecallDetail> resume(@PathVariable String recallNum, @RequestBody JsonNode body) {
return CommonResult.success(service.resume(recallNum, json.readInput(body, ResumeRequest.class)));
}
@PutMapping("/{recallNum}/draft")
public CommonResult<RecallDetail> draft(@PathVariable String recallNum, @RequestBody JsonNode body) {
return CommonResult.success(service.draft(recallNum, json.readInput(body, SaveDraftRequest.class)));
}
@GetMapping("/{recallNum}/references")
public CommonResult<ReferencePage> references(
@PathVariable String recallNum,
@RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "10") int pageSize) {
return CommonResult.success(service.references(recallNum, pageNum, pageSize));
}
@GetMapping("/{recallNum}/references/sources/{sourceId}")
public CommonResult<ReferenceContent> source(@PathVariable String recallNum, @PathVariable String sourceId) {
return CommonResult.success(service.source(recallNum, sourceId));
}
@PostMapping("/{recallNum}/end")
public CommonResult<RecallDetail> end(@PathVariable String recallNum, @RequestBody JsonNode body) {
return CommonResult.success(service.end(recallNum, json.readInput(body, EndRequest.class)));
}
@DeleteMapping("/{recallNum}")
public CommonResult<Void> delete(@PathVariable String recallNum) {
service.delete(recallNum);
return CommonResult.success();
}
}
@@ -1,13 +1,15 @@
package com.guo.learningprogresstracker.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.protobuf.ServiceException;
import com.guo.learningprogresstracker.dto.request.AbortStudySessionRequest;
import com.guo.learningprogresstracker.dto.request.EndedStudySessionRequest;
import com.guo.learningprogresstracker.dto.request.UpsertExpectationRequest;
import com.guo.learningprogresstracker.dto.response.ReportFragmentResponse;
import com.guo.learningprogresstracker.dto.response.StudyExpectationResponse;
import com.guo.learningprogresstracker.dto.response.StudyReportResponse;
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;
@@ -15,12 +17,18 @@ import com.guo.learningprogresstracker.service.StudyExpectationsService;
import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.time.LocalDateTime;
import java.util.ArrayList;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.time.LocalDateTime;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 学习会话控制层
@@ -39,26 +47,27 @@ public class StudySessionController {
* 创建/更新学习会话的学习预期
*/
@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()));
public CommonResult<StudyExpectationResponse> upsertExpectation(
@PathVariable("sessionNum") String sessionNum, @Valid @RequestBody UpsertExpectationRequest request)
throws ErrorParameterException {
return CommonResult.success(StudyExpectationResponse.of(
studyExpectationsService.upsertExpectation(sessionNum, request.getDescription())));
}
/**
* 获取学习会话的学习预期
*/
@GetMapping("/{sessionNum}/expectation")
public CommonResult<StudyExpectationsEntity> getExpectation(
@PathVariable("sessionNum") String sessionNum) {
return CommonResult.success(studyExpectationsService.getBySessionNum(sessionNum));
public CommonResult<StudyExpectationResponse> getExpectation(@PathVariable("sessionNum") String sessionNum) {
return CommonResult.success(StudyExpectationResponse.of(studyExpectationsService.getBySessionNum(sessionNum)));
}
/**
* 通过sessionNum获取一个【学习会话】
*/
@GetMapping("/{sessionNum}")
public CommonResult<StudySessionResponse> getStudySessionBySessionNum(@NotEmpty(message = "请提供学习会话编号") @PathVariable String sessionNum) throws ErrorParameterException {
public CommonResult<StudySessionResponse> getStudySessionBySessionNum(
@NotEmpty(message = "请提供学习会话编号") @PathVariable String sessionNum) throws ErrorParameterException {
// 通过 service 层获取,包含归属校验
StudySessionResponse response = studySessionsServiceImpl.getStudySessionBySessionNum(sessionNum);
return CommonResult.success(response);
@@ -68,7 +77,8 @@ public class StudySessionController {
* 开始一个【学习会话】
*/
@PostMapping("/{sessionNum}/study-sessions/continue")
public CommonResult<Void> startStudySession(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException, ServiceException {
public CommonResult<Void> startStudySession(@PathVariable("sessionNum") String sessionNum)
throws ErrorParameterException, ServiceException {
studySessionsServiceImpl.continueStudySession(sessionNum);
return CommonResult.success();
}
@@ -77,7 +87,8 @@ public class StudySessionController {
* 暂停一个【学习会话】
*/
@PostMapping("/{sessionNum}/study-sessions/pause")
public CommonResult<Void> pauseStudySession(@PathVariable("sessionNum") String sessionNum,
public CommonResult<Void> pauseStudySession(
@PathVariable("sessionNum") String sessionNum,
@RequestParam(value = "endTime", required = false) LocalDateTime endTime)
throws ErrorParameterException, ServiceException {
studySessionsServiceImpl.pauseStudySession(sessionNum, endTime);
@@ -88,9 +99,11 @@ 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,
public CommonResult<Void> endedStudySession(
@PathVariable("sessionNum") String sessionNum, @Valid @RequestBody EndedStudySessionRequest request)
throws ErrorParameterException {
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();
@@ -100,8 +113,9 @@ public class StudySessionController {
* 误操作结束一个【学习会话】:需输入确认语,严格零数据(删除会话与预期),仅未产生学习残片时可用
*/
@PostMapping("/{sessionNum}/study-sessions/abort")
public CommonResult<Void> abortStudySession(@PathVariable("sessionNum") String sessionNum,
@Valid @RequestBody AbortStudySessionRequest request) throws ErrorParameterException {
public CommonResult<Void> abortStudySession(
@PathVariable("sessionNum") String sessionNum, @Valid @RequestBody AbortStudySessionRequest request)
throws ErrorParameterException {
studySessionsServiceImpl.abortStudySession(sessionNum, request.getConfirmation());
return CommonResult.success();
}
@@ -110,36 +124,45 @@ public class StudySessionController {
* 获取【学习会话】所有的学习残片数据,以列表返回
*/
@GetMapping("/{sessionNum}/all-fragments")
public CommonResult<ArrayList<String>> getAllFragments(@PathVariable("sessionNum") String sessionNum) throws ErrorParameterException {
public CommonResult<ArrayList<String>> getAllFragments(@PathVariable("sessionNum") String sessionNum)
throws ErrorParameterException {
ArrayList<String> allFragments = studySessionsServiceImpl.getAllFragments(sessionNum);
return CommonResult.success(allFragments);
}
/** 分页查询任务的残片历史 */
@GetMapping("/tasks/{taskNum}/fragments")
public CommonResult<Page<StudyReportFragmentsEntity>> getTaskFragments(
public CommonResult<Page<ReportFragmentResponse>> 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));
Page<StudyReportFragmentsEntity> entities =
studySessionsServiceImpl.getTaskFragments(taskNum, page, size, keyword);
Page<ReportFragmentResponse> result =
new Page<>(entities.getCurrent(), entities.getSize(), entities.getTotal());
result.setRecords(
entities.getRecords().stream().map(ReportFragmentResponse::of).toList());
return CommonResult.success(result);
}
/** 分页查询任务的报告历史 */
@GetMapping("/tasks/{taskNum}/reports")
public CommonResult<Page<StudyReportsEntity>> getTaskReports(
public CommonResult<Page<StudyReportResponse>> 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));
Page<StudyReportsEntity> entities = studySessionsServiceImpl.getTaskReports(taskNum, page, size, keyword);
Page<StudyReportResponse> result = new Page<>(entities.getCurrent(), entities.getSize(), entities.getTotal());
result.setRecords(
entities.getRecords().stream().map(StudyReportResponse::of).toList());
return CommonResult.success(result);
}
/** 查询当前是否有活跃会话(用于跨页面恢复 + 阻止多任务) */
@GetMapping("/active")
public CommonResult<StudySessionResponse> getActiveSession(
@RequestParam(required = false) String excludeTaskNum) {
public CommonResult<StudySessionResponse> getActiveSession(@RequestParam(required = false) String excludeTaskNum) {
return CommonResult.success(studySessionsServiceImpl.getActiveSession(excludeTaskNum));
}
}
@@ -6,17 +6,20 @@ import com.guo.learningprogresstracker.dto.TagMindMapView;
import com.guo.learningprogresstracker.dto.TagScope;
import com.guo.learningprogresstracker.dto.request.TagScopeRequest;
import com.guo.learningprogresstracker.dto.request.UpdateTagMindMapRequest;
import com.guo.learningprogresstracker.dto.response.TagMindMapResponse;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.entity.ReviewRecallRecordEntity;
import com.guo.learningprogresstracker.entity.ReviewTagMindMapEntity;
import com.guo.learningprogresstracker.exception.ErrorParameterException;
import com.guo.learningprogresstracker.service.ReviewTagMindMapService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 标签导图控制层(闭环-04)。
@@ -24,8 +27,7 @@ import java.util.List;
* <p>按标签复习与按任务复习并存:任务导图仍走 {@code /review/standard-mind-map/{taskNum}},
* 这里只负责以「标签集合 + 取数模式」为范围的那一半。</p>
*
* <p>生成与回忆对比都不在请求线程里等 AI:由前端提交 {@code POST /ai/tasks}
* (type=TAG_MIND_MAP / TAG_RECALL_COMPARE)后轮询结果,与既有 AI 任务链路同一约定。</p>
* <p>生成走 {@code POST /ai/tasks}(type=TAG_MIND_MAP),复习统一进入自由回忆工作区。</p>
*/
@RequestMapping("/review/tag-mind-map")
@RestController
@@ -52,10 +54,11 @@ public class TagMindMapController {
* 用户编辑标签导图(大纲文本形式);该范围还没有导图时保存即为新建。
*/
@PutMapping
public CommonResult<ReviewTagMindMapEntity> updateTagMindMap(
@Valid @RequestBody UpdateTagMindMapRequest request) throws ErrorParameterException {
public CommonResult<TagMindMapResponse> updateTagMindMap(@Valid @RequestBody UpdateTagMindMapRequest request)
throws ErrorParameterException {
TagScope scope = reviewTagMindMapService.resolveScope(request.getTags(), request.getMode());
return CommonResult.success(reviewTagMindMapService.updateByOutline(scope, request.getOutline()));
return CommonResult.success(
TagMindMapResponse.of(reviewTagMindMapService.updateByOutline(scope, request.getOutline())));
}
/**
@@ -70,14 +73,4 @@ public class TagMindMapController {
@RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize) {
return CommonResult.success(reviewTagMindMapService.listMaps(pageNum, pageSize));
}
/**
* 该范围的回忆对比记录(倒序,最近一次在最前);范围里没有记录时返回空列表。
*/
@PostMapping("/recall-records")
public CommonResult<List<ReviewRecallRecordEntity>> listRecallRecords(
@Valid @RequestBody TagScopeRequest request) throws ErrorParameterException {
TagScope scope = reviewTagMindMapService.resolveScope(request.getTags(), request.getMode());
return CommonResult.success(reviewTagMindMapService.listRecallRecords(scope));
}
}
@@ -6,13 +6,14 @@ import com.guo.learningprogresstracker.common.Ops;
import com.guo.learningprogresstracker.dto.TaskInfo;
import com.guo.learningprogresstracker.dto.TaskOption;
import com.guo.learningprogresstracker.dto.request.CreateTaskApplicationRequest;
import com.guo.learningprogresstracker.dto.response.StudySessionResponse;
import com.guo.learningprogresstracker.dto.response.TaskInfoResponse;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.dto.request.PriorityWeightsRequest;
import com.guo.learningprogresstracker.dto.request.TaskRequest;
import com.guo.learningprogresstracker.dto.request.UpdateTaskApplicationRequest;
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
import com.guo.learningprogresstracker.entity.UserPriorityWeightsEntity;
import com.guo.learningprogresstracker.dto.response.PriorityWeightsResponse;
import com.guo.learningprogresstracker.dto.response.StudySessionResponse;
import com.guo.learningprogresstracker.dto.response.TaskApplicationResponse;
import com.guo.learningprogresstracker.dto.response.TaskInfoResponse;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.exception.ErrorParameterException;
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
import com.guo.learningprogresstracker.service.PriorityWeightsService;
@@ -21,6 +22,8 @@ import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.rmi.ServerException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -33,9 +36,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.rmi.ServerException;
import java.util.List;
/**
* 任务控制层
*
@@ -55,20 +55,21 @@ public class TaskController {
@GetMapping("/priority-weights")
@Operation(summary = "获取优先级维度权重配置")
public CommonResult<UserPriorityWeightsEntity> getPriorityWeights() {
return CommonResult.success(priorityWeightsService.getWeights());
public CommonResult<PriorityWeightsResponse> getPriorityWeights() {
return CommonResult.success(PriorityWeightsResponse.of(priorityWeightsService.getWeights()));
}
@PutMapping("/priority-weights")
@Operation(summary = "保存优先级维度权重配置并重算全部任务优先级")
public CommonResult<UserPriorityWeightsEntity> savePriorityWeights(
@RequestBody UserPriorityWeightsEntity weights) throws ErrorParameterException {
return CommonResult.success(priorityWeightsService.saveWeights(weights));
public CommonResult<PriorityWeightsResponse> savePriorityWeights(@Valid @RequestBody PriorityWeightsRequest request)
throws ErrorParameterException {
return CommonResult.success(PriorityWeightsResponse.of(priorityWeightsService.saveWeights(request.toEntity())));
}
@PostMapping
@Operation(summary = "添加新任务")
public CommonResult<String> addTask(@RequestBody @Validated({Ops.CreateG.class}) TaskRequest taskRequest) throws ErrorParameterException {
public CommonResult<String> addTask(@RequestBody @Validated({Ops.CreateG.class}) TaskRequest taskRequest)
throws ErrorParameterException {
return CommonResult.success("请求成功", tasksService.addTask(taskRequest));
}
@@ -80,7 +81,8 @@ public class TaskController {
@PutMapping("/{taskId}")
@Operation(summary = "更新任务详情")
public CommonResult<Void> updateTask(@PathVariable("taskId") String taskId, @Validated(Ops.UpdateG.class) @RequestBody TaskRequest updatedTask) {
public CommonResult<Void> updateTask(
@PathVariable("taskId") String taskId, @Validated(Ops.UpdateG.class) @RequestBody TaskRequest updatedTask) {
tasksService.updateTask(taskId, updatedTask);
return CommonResult.success();
}
@@ -101,25 +103,28 @@ public class TaskController {
@GetMapping("/{taskNum}/applications")
@Operation(summary = "获取任务应用场景列表")
public CommonResult<List<TaskApplicationEntity>> getApplications(@PathVariable String taskNum) throws NotFindEntitiesException {
return CommonResult.success(tasksService.getApplications(taskNum));
public CommonResult<List<TaskApplicationResponse>> getApplications(@PathVariable String taskNum)
throws NotFindEntitiesException {
return CommonResult.success(tasksService.getApplications(taskNum).stream()
.map(TaskApplicationResponse::of)
.toList());
}
@PostMapping("/{taskNum}/applications")
@Operation(summary = "创建任务应用场景")
public CommonResult<TaskApplicationEntity> createApplication(
@PathVariable String taskNum,
@Valid @RequestBody CreateTaskApplicationRequest request) throws NotFindEntitiesException {
public CommonResult<TaskApplicationResponse> createApplication(
@PathVariable String taskNum, @Valid @RequestBody CreateTaskApplicationRequest request)
throws NotFindEntitiesException {
request.setTaskNum(taskNum);
return CommonResult.success(tasksService.createApplication(request));
return CommonResult.success(TaskApplicationResponse.of(tasksService.createApplication(request)));
}
@PutMapping("/applications/{id}")
@Operation(summary = "更新任务应用场景")
public CommonResult<TaskApplicationEntity> updateApplication(
@PathVariable Integer id,
@Valid @RequestBody UpdateTaskApplicationRequest request) throws NotFindEntitiesException {
return CommonResult.success(tasksService.updateApplication(id, request));
public CommonResult<TaskApplicationResponse> updateApplication(
@PathVariable Integer id, @Valid @RequestBody UpdateTaskApplicationRequest request)
throws NotFindEntitiesException {
return CommonResult.success(TaskApplicationResponse.of(tasksService.updateApplication(id, request)));
}
@DeleteMapping("/applications/{id}")
@@ -137,7 +142,8 @@ public class TaskController {
@GetMapping
@Operation(summary = "获取所有任务列表")
public CommonResult<Page<TaskInfo>> tasksList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
public CommonResult<Page<TaskInfo>> tasksList(
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
return CommonResult.success(tasksService.taskList(pageNum, pageSize));
}
@@ -146,19 +152,19 @@ public class TaskController {
* 开始或继续一个【学习会话】
*/
@GetMapping("/{taskNum}/study-sessions/start-or-continue")
public CommonResult<StudySessionResponse> startOrContinueStudySession(@NotEmpty(message = "请提供任务编号")
@PathVariable String taskNum) throws NotFindEntitiesException, ServiceException {
public CommonResult<StudySessionResponse> startOrContinueStudySession(
@NotEmpty(message = "请提供任务编号") @PathVariable String taskNum)
throws NotFindEntitiesException, ErrorParameterException, ServiceException {
StudySessionResponse response = studySessionsServiceImpl.startOrContinueStudySession(taskNum);
return CommonResult.success(response);
}
/**
* 通过学习任务num获取该任务的未结束会话
*/
@GetMapping("/{taskNum}/not-ended-study-session")
public CommonResult<StudySessionResponse> getNotEndedStudySessionByTaskNum(@NotEmpty(message = "请提供任务编号")
@PathVariable String taskNum) throws ErrorParameterException {
public CommonResult<StudySessionResponse> getNotEndedStudySessionByTaskNum(
@NotEmpty(message = "请提供任务编号") @PathVariable String taskNum) throws ErrorParameterException {
StudySessionResponse response = studySessionsServiceImpl.getNotEndedStudySessionByTaskNum(taskNum);
return CommonResult.success(response);
}
@@ -3,13 +3,12 @@ package com.guo.learningprogresstracker.controller;
import com.guo.learningprogresstracker.entity.CommonResult;
import com.guo.learningprogresstracker.utils.TitleFetcher;
import io.swagger.v3.oas.annotations.Operation;
import java.util.Map;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequestMapping("/utils")
public class UtilsController {
@@ -2,10 +2,9 @@ package com.guo.learningprogresstracker.dto;
import com.guo.learningprogresstracker.entity.AiTaskEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Map;
import lombok.Data;
/**
* AI 任务对外视图(AI-02)。
@@ -18,7 +17,7 @@ public class AiTaskResponse {
@Schema(description = "AI 任务编号")
private String taskNum;
@Schema(description = "任务类型:RECALL_COMPARE / MIND_MAP / REPORT_DRAFT")
@Schema(description = "任务类型:RECALL_HINT / RECALL_CHECK / MIND_MAP / TAG_MIND_MAP / REPORT_DRAFT / GUIDANCE")
private String type;
@Schema(description = "目标编号:学习任务编号或学习会话编号")
@@ -30,6 +29,8 @@ public class AiTaskResponse {
@Schema(description = "失败原因(用户可见文案)")
private String errorMessage;
private String errorCode;
@Schema(description = "提交时间")
private LocalDateTime createdTime;
@@ -39,6 +40,28 @@ public class AiTaskResponse {
@Schema(description = "成功结果,随任务类型不同;未完成时为 null")
private Map<String, Object> result;
@com.fasterxml.jackson.annotation.JsonGetter("createdTime")
public Object createdTimeJson() {
return createdTime == null
? null
: isRecall()
? createdTime.atZone(java.time.ZoneId.systemDefault()).toInstant()
: createdTime;
}
@com.fasterxml.jackson.annotation.JsonGetter("finishedTime")
public Object finishedTimeJson() {
return finishedTime == null
? null
: isRecall()
? finishedTime.atZone(java.time.ZoneId.systemDefault()).toInstant()
: finishedTime;
}
private boolean isRecall() {
return "RECALL_HINT".equals(type) || "RECALL_CHECK".equals(type);
}
public static AiTaskResponse from(AiTaskEntity entity, Map<String, Object> result) {
AiTaskResponse response = new AiTaskResponse();
response.setTaskNum(entity.getTaskNum());
@@ -46,6 +69,7 @@ public class AiTaskResponse {
response.setTargetNum(entity.getTargetNum());
response.setStatus(entity.getStatus());
response.setErrorMessage(entity.getErrorMessage());
response.setErrorCode(entity.getErrorCode());
response.setCreatedTime(entity.getCreatedTime());
response.setFinishedTime(entity.getFinishedTime());
response.setResult(result);
@@ -1,8 +1,7 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.math.BigDecimal;
import lombok.Data;
/**
* 用量按任务类型 / 模型 / 用户分组的一项(契约 2.4、v2 第 4.2 节,{@code GET /ai/usage/breakdown})。
@@ -1,8 +1,7 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.math.BigDecimal;
import lombok.Data;
/**
* 用量按任务类型 / 模型分组的聚合结果(Mapper 层直接映射,契约 2.4)。
@@ -1,8 +1,7 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.math.BigDecimal;
import lombok.Data;
/**
* 用量趋势的一个分桶(契约 2.3,{@code GET /ai/usage/series})。
@@ -1,8 +1,7 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.math.BigDecimal;
import lombok.Data;
/**
* 用量趋势的分桶聚合结果(Mapper 层直接映射,契约 2.3)。
@@ -1,8 +1,7 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.math.BigDecimal;
import lombok.Data;
/**
* AI 用量汇总(契约 2.2,{@code GET /ai/usage/summary})。
@@ -1,8 +1,7 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.math.BigDecimal;
import lombok.Data;
/**
* 用量汇总的聚合结果(Mapper 层直接映射,契约 2.2)。
@@ -1,11 +1,10 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
/**
* 一次导出的完整文档(导出-01)。Markdown 与 JSON 都由它渲染,保证两种格式内容一致。
@@ -1,8 +1,7 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.time.LocalDateTime;
import lombok.Data;
/**
* 导出的一条内容(学习报告或知识碎片,导出-01)。
@@ -12,9 +11,14 @@ public class ExportEntry {
private Integer id;
/** 记录上下文:产生这条内容的学习会话编号 */
/** 兼容字段:仅 SESSION 来源填写;复习行为不伪造学习会话。 */
private String sessionNum;
/** SESSION / REVIEW,独立于内容归属。 */
private String contextType;
private String contextNum;
private LocalDateTime createdTime;
/** 报告或碎片的原文 */
@@ -1,9 +1,8 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
/**
* 导出文档中的一个学习任务段落(导出-01)。
@@ -17,4 +17,7 @@ public class LoginResult {
/** 该用户是否在 {@code lpt.ai-usage.admin-usernames} 白名单里 */
private boolean aiAdmin;
/** Stable opaque account identity for user-isolated draft caches; never an AI prompt field. */
private String accountId;
}
@@ -6,5 +6,4 @@ package com.guo.learningprogresstracker.dto;
* <p>碎片正文之外带一个可空的 {@code reportRef}:指向同源的报告上下文。
* LLM 据此知道哪些碎片来自带报告的那次会话,从而只从中提取与这些碎片相关的内容。</p>
*/
public record MindMapFragmentPayload(String content, String reportRef) {
}
public record MindMapFragmentPayload(String content, String reportRef) {}
@@ -14,16 +14,14 @@ import io.swagger.v3.oas.annotations.media.Schema;
* 用于告诉 LLM 哪份报告与哪批碎片同源;{@code taskName} 帮助它判断领域是否一致。</p>
*/
public record MindMapReportContext(
@Schema(description = "报告所属会话编号,用于与碎片记录上下文关联")
String ref,
@Schema(description = "报告所属会话编号,用于与碎片记录上下文关联") String ref,
@Schema(description = "产生该报告的会话所属任务名(仅作判断领域的参考,报告可能来自旁支任务)")
String taskName,
@Schema(description = "会话摘要:这次实际学了什么")
String sessionSummary,
@Schema(description = "预期达成判断:对照学习预期得出的结论")
String expectationVerdict,
@Schema(description = "自由总结:用户对本次学习的叙述")
String freeSummary) {
@Schema(description = "会话摘要:这次实际学了什么") String sessionSummary,
@Schema(description = "预期达成判断:对照学习预期得出的结论") String expectationVerdict,
@Schema(description = "自由总结:用户对本次学习的叙述") String freeSummary) {
/** 三段是否都为空白:全空的报告没有参考价值,不进入导图上下文 */
public boolean isBlank() {
@@ -1,30 +0,0 @@
package com.guo.learningprogresstracker.dto;
/**
* 一次回忆对比的结果(AI-02)。
*
* <p>对比在 AI 任务执行器里完成,因此不再把「标准导图实体」直接返回给提交接口;
* 这个结果写进 AI 任务的 {@code result_payload},由前端在轮询到成功后再取详情。</p>
*
* @param standardMapId 对比所用的标准导图 ID
* @param recallRecordId 本次生成的回忆记录 ID
* @param recallRatio 覆盖率(0-1)
* @param matchedCount 命中节点数
* @param missedCount 遗漏节点数
* @param extraCount 额外节点数
*/
public record RecallCompareOutcome(Integer standardMapId, Integer recallRecordId, Double recallRatio,
Integer matchedCount, Integer missedCount, Integer extraCount) {
/** 转成 AI 任务结果载荷 */
public java.util.Map<String, Object> toPayload() {
java.util.Map<String, Object> payload = new java.util.LinkedHashMap<>();
payload.put("standardMapId", standardMapId);
payload.put("recallRecordId", recallRecordId);
payload.put("recallRatio", recallRatio);
payload.put("matchedCount", matchedCount);
payload.put("missedCount", missedCount);
payload.put("extraCount", extraCount);
return payload;
}
}
@@ -1,8 +1,7 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.time.LocalDateTime;
import lombok.Data;
/**
* 复习滚动 feed 条目 / 任务记录条目。
@@ -14,10 +14,6 @@ import io.swagger.v3.oas.annotations.media.Schema;
* 任务删除后残留的报告也不计入。</p>
*/
public record ReviewSummary(
@Schema(description = "任务总数")
long taskTotal,
@Schema(description = "学习报告总数")
long reportTotal,
@Schema(description = "学习碎片总数")
long fragmentTotal) {
}
@Schema(description = "任务总数") long taskTotal,
@Schema(description = "学习报告总数") long reportTotal,
@Schema(description = "学习碎片总数") long fragmentTotal) {}
@@ -11,5 +11,4 @@ import java.time.LocalDateTime;
* @param lastInteractionAt 最近一次交互时刻
* @param durationSeconds 前端结算出的净耗时(秒)
*/
public record ReviewTiming(LocalDateTime startedAt, LocalDateTime lastInteractionAt, Integer durationSeconds) {
}
public record ReviewTiming(LocalDateTime startedAt, LocalDateTime lastInteractionAt, Integer durationSeconds) {}
@@ -3,10 +3,9 @@ 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;
import lombok.Data;
/**
* 学习报告详情(归属-01:结构化报告)。
@@ -1,8 +1,7 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
import java.time.LocalDateTime;
import lombok.Data;
@Data
public class StudySessionsDto {
@@ -1,10 +1,9 @@
package com.guo.learningprogresstracker.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Data;
/**
* 已有标签导图的摘要(闭环-04):用于「已生成的标签导图」列表。
@@ -1,11 +1,9 @@
package com.guo.learningprogresstracker.dto;
import com.guo.learningprogresstracker.entity.ReviewRecallRecordEntity;
import com.guo.learningprogresstracker.entity.ReviewTagMindMapEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
import lombok.Data;
/**
* 一个标签复习范围的当前状态(闭环-04)。
@@ -28,7 +26,4 @@ public class TagMindMapView {
@Schema(description = "该范围已有的标签导图;没有时为 null")
private ReviewTagMindMapEntity map;
@Schema(description = "该范围最近一次回忆对比记录;没复习过时为 null")
private ReviewRecallRecordEntity latestRecallRecord;
}
@@ -1,7 +1,6 @@
package com.guo.learningprogresstracker.dto;
import com.guo.learningprogresstracker.enums.TagCombineModeEnum;
import java.util.List;
/**
@@ -24,9 +24,6 @@ public class TaskDeletionSummary {
@Schema(description = "将软删除的标准思维导图数")
private int deletedMindMaps;
@Schema(description = "将软删除的回忆记录数")
private int deletedRecallRecords;
@Schema(description = "将软删除的应用场景数")
private int deletedApplications;
}
@@ -12,8 +12,5 @@ import io.swagger.v3.oas.annotations.media.Schema;
* <p>排序与任务列表一致(优先级倒序),保证下拉里的顺序稳定。</p>
*/
public record TaskOption(
@Schema(description = "任务编号")
String taskNum,
@Schema(description = "任务名称")
String taskName) {
}
@Schema(description = "任务编号") String taskNum,
@Schema(description = "任务名称") String taskName) {}
@@ -1,19 +0,0 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
/**
* 任务最近一次回忆对比的覆盖率(复习-04)。
*
* <p>原先按任务取「最近一条回忆记录」是把该任务的全部回忆记录(含体积较大的
* {@code compare_result} JSON)拉回内存再逐条取第一条。改为在 SQL 侧按任务分组取最新,
* 返回行数等于任务数,不随复习次数增长。</p>
*/
@Data
public class TaskRecallRatio {
private String taskNum;
/** 最近一次回忆对比的覆盖率(0-1);记录里为空时按 0 处理 */
private Double recallRatio;
}
@@ -1,16 +0,0 @@
package com.guo.learningprogresstracker.dto;
import lombok.Data;
/**
* 任务维度的复习耗时聚合结果(复习-07)。
* <p>由 Mapper 层的聚合查询直接映射,避免用 Map 承载查询结果。</p>
*/
@Data
public class TaskReviewDuration {
private String taskNum;
/** 该任务累计复习耗时(秒) */
private Long reviewDurationSeconds;
}
@@ -0,0 +1,197 @@
package com.guo.learningprogresstracker.dto.recall;
import java.time.Instant;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
/** Free recall stores one current expression and one current reference set per recall. */
public final class RecallDtos {
private RecallDtos() {}
public record ScopeInput(String type, String taskNum, List<String> tags, String combineMode) {}
public record ScopeSnapshot(
String type,
String taskNum,
List<String> tags,
List<String> normalizedTags,
String combineMode,
String scopeKey,
String displayName,
Instant selectedAt) {}
public record Provenance(String kind, String recallNum, String requestTaskNum, String itemId) {}
public record NodeStyle(String background, String color) {}
public record ExpressionNode(
String id,
String title,
String notes,
List<Provenance> provenance,
NodeStyle style,
List<ExpressionNode> children) {}
public record Expression(int schemaVersion, ExpressionNode root) {}
public record Timing(long segmentActiveMs, Long segmentActualMs, Instant lastInteractionAt) {
/** 兼容尚未上报实际用时的调用方:实际按有效时间处理。 */
public Timing(long segmentActiveMs, Instant lastInteractionAt) {
this(segmentActiveMs, segmentActiveMs, lastInteractionAt);
}
}
public record Entry(String type, String sourceType, String entityId) {}
public record CreateRecallRequest(String clientRequestId, String editorId, ScopeInput scope, Entry entry) {}
public record EditorGuard(String editorId, String writeToken) {}
public record ResumeRequest(String clientRequestId, String editorId, String writeToken) {}
public record SaveDraftRequest(
String clientRequestId, String editorId, String writeToken, Expression expression, Timing timing) {}
public record EndRequest(
String clientRequestId, String editorId, String writeToken, Expression expression, Timing timing) {}
public record AiParams(int schemaVersion, String requestId, String editorId, String writeToken, String hintForm) {}
public record ReferenceSource(
String sourceId,
String type,
String entityId,
String title,
String content,
String role,
String contextType,
String contextNum,
List<String> relatedFragmentSourceIds,
String status) {}
public record ReferenceSourceSummary(String sourceId, String title, String preview, String role, String status) {}
public record ReferencePage(int current, int size, long total, List<ReferenceSourceSummary> records) {}
public record ReferenceContent(String sourceId, String title, String content, String role, String status) {}
public record ReferenceSummary(String status, long total, List<String> limitations) {}
public record ReferenceUnit(
String unitId, String sourceId, int start, int end, String text, String role, String status) {}
/** One source set captured when this recall starts; it is replaced only by starting a new recall. */
public record ReferenceSnapshot(
String status, List<ReferenceSource> sources, List<ReferenceUnit> units, List<String> limitations) {}
public record Citation(String unitId, int start, int end, String quote) {}
public record ExpressionEvidence(String nodeId, String field, int start, int end, String quote) {}
public record UnitAssessment(
String unitId, String status, String reason, String exclusion, List<Citation> citations) {}
public record HintNode(String id, String parentId, String text) {}
public record HintItem(
String id, String form, String clue, String anchorNodeId, List<HintNode> nodes, List<Citation> citations) {}
public record Finding(
String id,
String category,
String clue,
String explanation,
List<Citation> citations,
List<ExpressionEvidence> expressionEvidence) {}
public record RecallAiResult(
int schemaVersion,
String kind,
String model,
String analysisStatus,
List<UnitAssessment> assessments,
List<HintItem> hints,
List<Finding> findings,
List<String> limitations) {}
public record AiReferenceUnit(
String unitId,
String sourceId,
String sourceType,
String role,
String title,
int start,
int end,
String text,
List<String> relatedFragmentSourceIds) {}
public record AiScope(String type, String displayName, List<String> tags, String combineMode) {}
public record Limits(int maxHintItems, int maxHintNodes, int maxFindings) {}
/** AI input expression: presentation-only style is not part of the semantic contract. */
public record AiExpressionNode(
String id, String title, String notes, List<Provenance> provenance, List<AiExpressionNode> children) {}
public record AiExpression(int schemaVersion, AiExpressionNode root) {}
public record RecallAiParams(
int schemaVersion,
String promptVersion,
AiScope scope,
AiExpression expression,
String hintForm,
List<AiReferenceUnit> units,
Limits limits,
List<String> limitations) {}
public record RecallRequest(
String requestId,
String taskNum,
String type,
String hintForm,
String promptVersion,
String status,
String errorCode,
String errorMessage,
Instant submittedAt,
Instant finishedAt,
RecallAiResult result) {}
public record RecallPage(long current, long size, long total, List<RecallSummary> records) {}
public record BusinessError(String reason) {}
@Data
public static class RecallSummary {
private String recallNum;
private String status;
private ScopeSnapshot scope;
private String scopeStatus;
private long activeDurationMs;
private Long actualDurationMs;
private Instant createdAt;
private Instant updatedAt;
private Instant endedAt;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class RecallDetail extends RecallSummary {
private String editorId;
private String writeToken;
private Expression expression;
private ReferenceSummary reference;
private List<RecallRequest> requests;
}
/** Persisted aggregate under a database lock, never returned to the client. */
@Data
public static class RecallDocument {
private RecallDetail detail;
private ReferenceSnapshot reference;
private Instant epochStartedAt;
private long acceptedSegmentMs;
private Long acceptedSegmentActualMs;
private String lastDraftRequestId;
private String lastDraftPayloadHash;
}
}
@@ -0,0 +1,9 @@
package com.guo.learningprogresstracker.dto.recall;
import lombok.Data;
@Data
public class TaskRecallDuration {
private String taskNum;
private Long activeDurationMs;
}
@@ -0,0 +1,18 @@
package com.guo.learningprogresstracker.dto.request;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
/** 给对象打用户标签的请求。 */
@Data
public class AddUserTagRequest {
@NotBlank(message = "对象类型不能为空")
private String objectType;
@NotBlank(message = "对象编号不能为空")
private String objectNum;
@NotBlank(message = "标签名不能为空")
private String markerName;
}
@@ -1,9 +1,8 @@
package com.guo.learningprogresstracker.dto.request;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import java.util.Map;
import lombok.Data;
/**
* 提交 AI 任务请求(AI-02)。
@@ -3,9 +3,8 @@ package com.guo.learningprogresstracker.dto.request;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import java.math.BigDecimal;
import lombok.Data;
/**
* 一条 AI 用量记录(契约 1)。
@@ -2,9 +2,8 @@ package com.guo.learningprogresstracker.dto.request;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.util.List;
import lombok.Data;
/**
* lpt-ai 用量上报请求体(契约 1,{@code POST /internal/ai-usage/records})。
@@ -0,0 +1,10 @@
package com.guo.learningprogresstracker.dto.request;
import lombok.Data;
/** 调整知识碎片内容归属;ownerTaskNum 传空字符串表示清空归属(回到待归类)。 */
@Data
public class AssignOwnershipRequest {
private String ownerTaskNum;
}
@@ -0,0 +1,13 @@
package com.guo.learningprogresstracker.dto.request;
import lombok.Data;
/** 确认引导产出、记成知识碎片的请求。 */
@Data
public class ConfirmGuidanceFragmentRequest {
private String content;
private String reviewStartedAt;
private String reviewLastInteractionAt;
private Integer reviewDurationSeconds;
}
@@ -0,0 +1,12 @@
package com.guo.learningprogresstracker.dto.request;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
/** 新建标签字典项的请求。 */
@Data
public class CreateDictionaryTagRequest {
@NotBlank(message = "标签名不能为空")
private String tagName;
}
@@ -0,0 +1,10 @@
package com.guo.learningprogresstracker.dto.request;
import lombok.Data;
/** 在标准思维导图里查找最接近的节点。 */
@Data
public class FindNodeRequest {
private String content;
}
@@ -0,0 +1,15 @@
package com.guo.learningprogresstracker.dto.request;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
/** 开始一次学习引导的请求。 */
@Data
public class GuidanceStartRequest {
@NotBlank(message = "任务编号不能为空")
private String taskNum;
@NotBlank(message = "概念不能为空")
private String concept;
}
@@ -0,0 +1,12 @@
package com.guo.learningprogresstracker.dto.request;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
/** 提交一轮用户发言的请求。 */
@Data
public class GuidanceTurnRequest {
@NotBlank(message = "发言内容不能为空")
private String message;
}
@@ -0,0 +1,25 @@
package com.guo.learningprogresstracker.dto.request;
import com.guo.learningprogresstracker.entity.UserPriorityWeightsEntity;
import lombok.Data;
/** 优先级权重保存请求。 */
@Data
public class PriorityWeightsRequest {
private Double urgencyWeight;
private Double importanceWeight;
private Double contentDifficultyWeight;
private Double futureValueWeight;
private Double subjectivePriorityWeight;
public UserPriorityWeightsEntity toEntity() {
UserPriorityWeightsEntity entity = new UserPriorityWeightsEntity();
entity.setUrgencyWeight(urgencyWeight);
entity.setImportanceWeight(importanceWeight);
entity.setContentDifficultyWeight(contentDifficultyWeight);
entity.setFutureValueWeight(futureValueWeight);
entity.setSubjectivePriorityWeight(subjectivePriorityWeight);
return entity;
}
}
@@ -1,31 +0,0 @@
package com.guo.learningprogresstracker.dto.request;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 用户回忆对比请求
*/
@Data
public class RecallCompareRequest {
@NotBlank(message = "请先填写回忆大纲")
private String recallOutline;
/** 复习起点节点路径(以 / 分隔),null 为任务维度 */
private String focusPath;
/** 本次回忆复习开始时刻(本地时间),复习-07 */
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime reviewStartedAt;
/** 最近一次交互时刻(本地时间),供服务端按 5 分钟空闲截断,复习-07 */
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime reviewLastInteractionAt;
/** 前端按 5 分钟空闲截断后的净耗时(秒),复习-07 */
private Integer reviewDurationSeconds;
}
@@ -0,0 +1,12 @@
package com.guo.learningprogresstracker.dto.request;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
/** 重命名标签字典项的请求。 */
@Data
public class RenameDictionaryTagRequest {
@NotBlank(message = "标签名不能为空")
private String newName;
}
@@ -0,0 +1,15 @@
package com.guo.learningprogresstracker.dto.request;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
/** 重命名用户标签的请求(影响所有带该标签的对象)。 */
@Data
public class RenameUserTagRequest {
@NotBlank(message = "原标签名不能为空")
private String oldName;
@NotBlank(message = "新标签名不能为空")
private String newName;
}
@@ -0,0 +1,10 @@
package com.guo.learningprogresstracker.dto.request;
import lombok.Data;
/** 保存复习排序偏好的请求(preset 取值见 ReviewSortPresetEnum,非法值回落默认档)。 */
@Data
public class SortPreferenceRequest {
private String preset;
}
@@ -1,9 +1,8 @@
package com.guo.learningprogresstracker.dto.request;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import java.util.List;
import lombok.Data;
/**
* 标签复习范围(闭环-04):标签集合 + 取数模式。
@@ -14,9 +14,10 @@ import lombok.Data;
@Data
public class TaskRequest {
public interface Create{}
@Null(message = "创建任务时不需要填写任务编号",groups = Ops.CreateG.class)
@NotNull(message = "缺少要更新的任务信息,请刷新后重试",groups = Ops.UpdateG.class)
public interface Create {}
@Null(message = "创建任务时不需要填写任务编号", groups = Ops.CreateG.class)
@NotNull(message = "缺少要更新的任务信息,请刷新后重试", groups = Ops.UpdateG.class)
private Integer id;
/**
* 学习任务的名称
@@ -36,40 +37,39 @@ public class TaskRequest {
* 用户设置的任务紧急性
*/
@NotNull(message = "请设置任务紧急性", groups = Ops.CreateG.class)
@Min(value = 0,message = "任务紧急性不能小于 0")
@Max(value = 5,message = "任务紧急性不能大于 5")
@Min(value = 0, message = "任务紧急性不能小于 0")
@Max(value = 5, message = "任务紧急性不能大于 5")
private Integer urgency;
/**
* 用户设置的任务重要性
*/
@NotNull(message = "请设置任务重要性", groups = Ops.CreateG.class)
@Min(value = 0,message = "任务重要性不能小于 0")
@Max(value = 5,message = "任务重要性不能大于 5")
@Min(value = 0, message = "任务重要性不能小于 0")
@Max(value = 5, message = "任务重要性不能大于 5")
private Integer importance;
/**
* 任务的内容难度
*/
@NotNull(message = "请设置内容难度", groups = Ops.CreateG.class)
@Min(value = 0,message = "内容难度不能小于 0")
@Max(value = 5,message = "内容难度不能大于 5")
@Min(value = 0, message = "内容难度不能小于 0")
@Max(value = 5, message = "内容难度不能大于 5")
private Integer contentDifficulty;
/**
* 任务的未来价值
*/
@NotNull(message = "请设置未来价值", groups = Ops.CreateG.class)
@Min(value = 0,message = "未来价值不能小于 0")
@Max(value = 5,message = "未来价值不能大于 5")
@Min(value = 0, message = "未来价值不能小于 0")
@Max(value = 5, message = "未来价值不能大于 5")
private Integer futureValue;
/**
* 用户对任务的主观优先级
*/
@NotNull(message = "请设置主观优先级", groups = Ops.CreateG.class)
@Min(value = 0,message = "主观优先级不能小于 0")
@Max(value = 5,message = "主观优先级不能大于 5")
@Min(value = 0, message = "主观优先级不能小于 0")
@Max(value = 5, message = "主观优先级不能大于 5")
private Integer subjectivePriority;
}
@@ -2,9 +2,8 @@ package com.guo.learningprogresstracker.dto.request;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import java.util.List;
import lombok.Data;
/**
* 用户编辑标签导图(大纲文本形式)请求(闭环-04)。
@@ -0,0 +1,41 @@
package com.guo.learningprogresstracker.dto.response;
import com.guo.learningprogresstracker.entity.ReviewGuidanceConversationEntity;
import java.time.LocalDateTime;
import lombok.Data;
/** 学习引导会话(HTTP 出参;不暴露实体上的租户与审计列)。 */
@Data
public class GuidanceConversationResponse {
private Integer id;
private String guidanceNum;
private String taskNum;
private String concept;
private String turnsPayload;
private Integer reviewDurationSeconds;
private Boolean finished;
private LocalDateTime startedTime;
private LocalDateTime finishedTime;
private LocalDateTime createdTime;
private LocalDateTime lastModifiedTime;
public static GuidanceConversationResponse of(ReviewGuidanceConversationEntity entity) {
if (entity == null) {
return null;
}
GuidanceConversationResponse response = new GuidanceConversationResponse();
response.setId(entity.getId());
response.setGuidanceNum(entity.getGuidanceNum());
response.setTaskNum(entity.getTaskNum());
response.setConcept(entity.getConcept());
response.setTurnsPayload(entity.getTurnsPayload());
response.setReviewDurationSeconds(entity.getReviewDurationSeconds());
response.setFinished(entity.getFinished());
response.setStartedTime(entity.getStartedTime());
response.setFinishedTime(entity.getFinishedTime());
response.setCreatedTime(entity.getCreatedTime());
response.setLastModifiedTime(entity.getLastModifiedTime());
return response;
}
}
@@ -0,0 +1,35 @@
package com.guo.learningprogresstracker.dto.response;
import com.guo.learningprogresstracker.entity.MarkerEntity;
import java.time.LocalDateTime;
import lombok.Data;
/** 对象上的标记(HTTP 出参;不暴露实体上的租户与审计列)。 */
@Data
public class MarkerResponse {
private Integer id;
private String objectType;
private String objectNum;
private String kind;
private String markerName;
private String markerValue;
private LocalDateTime createdTime;
private LocalDateTime lastModifiedTime;
public static MarkerResponse of(MarkerEntity entity) {
if (entity == null) {
return null;
}
MarkerResponse response = new MarkerResponse();
response.setId(entity.getId());
response.setObjectType(entity.getObjectType());
response.setObjectNum(entity.getObjectNum());
response.setKind(entity.getKind());
response.setMarkerName(entity.getMarkerName());
response.setMarkerValue(entity.getMarkerValue());
response.setCreatedTime(entity.getCreatedTime());
response.setLastModifiedTime(entity.getLastModifiedTime());
return response;
}
}
@@ -0,0 +1,35 @@
package com.guo.learningprogresstracker.dto.response;
import com.guo.learningprogresstracker.entity.UserPriorityWeightsEntity;
import java.time.LocalDateTime;
import lombok.Data;
/** 用户优先级权重(HTTP 出参;不暴露实体上的租户与审计列)。 */
@Data
public class PriorityWeightsResponse {
private Integer id;
private Double urgencyWeight;
private Double importanceWeight;
private Double contentDifficultyWeight;
private Double futureValueWeight;
private Double subjectivePriorityWeight;
private LocalDateTime createdTime;
private LocalDateTime lastModifiedTime;
public static PriorityWeightsResponse of(UserPriorityWeightsEntity entity) {
if (entity == null) {
return null;
}
PriorityWeightsResponse response = new PriorityWeightsResponse();
response.setId(entity.getId());
response.setUrgencyWeight(entity.getUrgencyWeight());
response.setImportanceWeight(entity.getImportanceWeight());
response.setContentDifficultyWeight(entity.getContentDifficultyWeight());
response.setFutureValueWeight(entity.getFutureValueWeight());
response.setSubjectivePriorityWeight(entity.getSubjectivePriorityWeight());
response.setCreatedTime(entity.getCreatedTime());
response.setLastModifiedTime(entity.getLastModifiedTime());
return response;
}
}
@@ -0,0 +1,39 @@
package com.guo.learningprogresstracker.dto.response;
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
import java.time.LocalDateTime;
import lombok.Data;
/** 知识碎片(HTTP 出参;不暴露实体上的租户与审计列)。 */
@Data
public class ReportFragmentResponse {
private Integer id;
private String contextNum;
private String contextType;
private String ownerTaskNum;
private Boolean mastered;
private Boolean revisit;
private LocalDateTime lastReviewedTime;
private String content;
private LocalDateTime createdTime;
private LocalDateTime lastModifiedTime;
public static ReportFragmentResponse of(StudyReportFragmentsEntity entity) {
if (entity == null) {
return null;
}
ReportFragmentResponse response = new ReportFragmentResponse();
response.setId(entity.getId());
response.setContextNum(entity.getContextNum());
response.setContextType(entity.getContextType());
response.setOwnerTaskNum(entity.getOwnerTaskNum());
response.setMastered(entity.getMastered());
response.setRevisit(entity.getRevisit());
response.setLastReviewedTime(entity.getLastReviewedTime());
response.setContent(entity.getContent());
response.setCreatedTime(entity.getCreatedTime());
response.setLastModifiedTime(entity.getLastModifiedTime());
return response;
}
}
@@ -0,0 +1,49 @@
package com.guo.learningprogresstracker.dto.response;
import com.guo.learningprogresstracker.entity.ReviewStandardMindMapEntity;
import java.time.LocalDateTime;
import lombok.Data;
/** 标准思维导图(HTTP 出参;不暴露实体上的租户与审计列)。 */
@Data
public class StandardMindMapResponse {
private Integer id;
private String taskNum;
private String title;
private String content;
private String outline;
private String summary;
private String generator;
private String generatorVersion;
private Integer sourceReportCount;
private Integer sourceFragmentCount;
private LocalDateTime generatedTime;
private Boolean needsUpdate;
private LocalDateTime needsUpdateTime;
private LocalDateTime createdTime;
private LocalDateTime lastModifiedTime;
public static StandardMindMapResponse of(ReviewStandardMindMapEntity entity) {
if (entity == null) {
return null;
}
StandardMindMapResponse response = new StandardMindMapResponse();
response.setId(entity.getId());
response.setTaskNum(entity.getTaskNum());
response.setTitle(entity.getTitle());
response.setContent(entity.getContent());
response.setOutline(entity.getOutline());
response.setSummary(entity.getSummary());
response.setGenerator(entity.getGenerator());
response.setGeneratorVersion(entity.getGeneratorVersion());
response.setSourceReportCount(entity.getSourceReportCount());
response.setSourceFragmentCount(entity.getSourceFragmentCount());
response.setGeneratedTime(entity.getGeneratedTime());
response.setNeedsUpdate(entity.getNeedsUpdate());
response.setNeedsUpdateTime(entity.getNeedsUpdateTime());
response.setCreatedTime(entity.getCreatedTime());
response.setLastModifiedTime(entity.getLastModifiedTime());
return response;
}
}
@@ -0,0 +1,29 @@
package com.guo.learningprogresstracker.dto.response;
import com.guo.learningprogresstracker.entity.StudyExpectationsEntity;
import java.time.LocalDateTime;
import lombok.Data;
/** 会话学习预期(HTTP 出参;不暴露实体上的租户与审计列)。 */
@Data
public class StudyExpectationResponse {
private Integer expectationId;
private String sessionNum;
private String description;
private LocalDateTime createdTime;
private LocalDateTime lastModifiedTime;
public static StudyExpectationResponse of(StudyExpectationsEntity entity) {
if (entity == null) {
return null;
}
StudyExpectationResponse response = new StudyExpectationResponse();
response.setExpectationId(entity.getExpectationId());
response.setSessionNum(entity.getSessionNum());
response.setDescription(entity.getDescription());
response.setCreatedTime(entity.getCreatedTime());
response.setLastModifiedTime(entity.getLastModifiedTime());
return response;
}
}
@@ -0,0 +1,35 @@
package com.guo.learningprogresstracker.dto.response;
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
import java.time.LocalDateTime;
import lombok.Data;
/** 学习报告(HTTP 出参;不暴露实体上的租户与审计列)。 */
@Data
public class StudyReportResponse {
private Integer id;
private String sessionNum;
private String sessionSummary;
private String expectationVerdict;
private String freeSummary;
private String sessionExpectation;
private LocalDateTime createdTime;
private LocalDateTime lastModifiedTime;
public static StudyReportResponse of(StudyReportsEntity entity) {
if (entity == null) {
return null;
}
StudyReportResponse response = new StudyReportResponse();
response.setId(entity.getId());
response.setSessionNum(entity.getSessionNum());
response.setSessionSummary(entity.getSessionSummary());
response.setExpectationVerdict(entity.getExpectationVerdict());
response.setFreeSummary(entity.getFreeSummary());
response.setSessionExpectation(entity.getSessionExpectation());
response.setCreatedTime(entity.getCreatedTime());
response.setLastModifiedTime(entity.getLastModifiedTime());
return response;
}
}
@@ -1,9 +1,8 @@
package com.guo.learningprogresstracker.dto.response;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
import lombok.Data;
@Data
public class StudySessionResponse {
@@ -29,23 +28,18 @@ public class StudySessionResponse {
@Schema(description = "上次本会话开始时间")
private LocalDateTime lastStartTime;
@Schema(description = "学习结束时间")
private LocalDateTime endTime;
@Schema(description = "实际使用时间(秒)")
private double actualTime;
@Schema(description = "有效学习时间(秒)")
private double effectiveTime;
@Schema(description = "有效时间比")
private Double effectivenessRatio;
@Schema(description = "学习会话的状态(进行中、暂停、已结束)")
private String sessionState;
@@ -0,0 +1,51 @@
package com.guo.learningprogresstracker.dto.response;
import com.guo.learningprogresstracker.entity.ReviewTagMindMapEntity;
import java.time.LocalDateTime;
import lombok.Data;
/** 标签思维导图(HTTP 出参;不暴露实体上的租户与审计列)。 */
@Data
public class TagMindMapResponse {
private Integer id;
private String scopeKey;
private String combineMode;
private String tagNames;
private String title;
private String content;
private String outline;
private String summary;
private String generator;
private String generatorVersion;
private Integer sourceFragmentCount;
private LocalDateTime generatedTime;
private Boolean needsUpdate;
private LocalDateTime needsUpdateTime;
private LocalDateTime createdTime;
private LocalDateTime lastModifiedTime;
public static TagMindMapResponse of(ReviewTagMindMapEntity entity) {
if (entity == null) {
return null;
}
TagMindMapResponse response = new TagMindMapResponse();
response.setId(entity.getId());
response.setScopeKey(entity.getScopeKey());
response.setCombineMode(entity.getCombineMode());
response.setTagNames(entity.getTagNames());
response.setTitle(entity.getTitle());
response.setContent(entity.getContent());
response.setOutline(entity.getOutline());
response.setSummary(entity.getSummary());
response.setGenerator(entity.getGenerator());
response.setGeneratorVersion(entity.getGeneratorVersion());
response.setSourceFragmentCount(entity.getSourceFragmentCount());
response.setGeneratedTime(entity.getGeneratedTime());
response.setNeedsUpdate(entity.getNeedsUpdate());
response.setNeedsUpdateTime(entity.getNeedsUpdateTime());
response.setCreatedTime(entity.getCreatedTime());
response.setLastModifiedTime(entity.getLastModifiedTime());
return response;
}
}
@@ -0,0 +1,35 @@
package com.guo.learningprogresstracker.dto.response;
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
import java.time.LocalDateTime;
import lombok.Data;
/** 任务应用场景(HTTP 出参;不暴露实体上的租户与审计列)。 */
@Data
public class TaskApplicationResponse {
private Integer id;
private String taskNum;
private String title;
private String description;
private String resourceUrl;
private String status;
private LocalDateTime createdTime;
private LocalDateTime lastModifiedTime;
public static TaskApplicationResponse of(TaskApplicationEntity entity) {
if (entity == null) {
return null;
}
TaskApplicationResponse response = new TaskApplicationResponse();
response.setId(entity.getId());
response.setTaskNum(entity.getTaskNum());
response.setTitle(entity.getTitle());
response.setDescription(entity.getDescription());
response.setResourceUrl(entity.getResourceUrl());
response.setStatus(entity.getStatus());
response.setCreatedTime(entity.getCreatedTime());
response.setLastModifiedTime(entity.getLastModifiedTime());
return response;
}
}
@@ -22,7 +22,7 @@ public class TaskInfoResponse {
private String materialUrl;
/**
/**
* /**
* 用户设置的任务紧急性
*/
private Integer urgency;
@@ -1,9 +1,8 @@
package com.guo.learningprogresstracker.dto.response;
import com.guo.learningprogresstracker.dto.TaskInfo;
import lombok.Data;
import java.util.List;
import lombok.Data;
/**
* 任务列表信息响应体
@@ -12,6 +11,4 @@ import java.util.List;
public class TasksListInfoResponse {
// 任务列表
private List<TaskInfo> taskList;
}
@@ -0,0 +1,29 @@
package com.guo.learningprogresstracker.dto.response;
import com.guo.learningprogresstracker.entity.UserTagEntity;
import java.time.LocalDateTime;
import lombok.Data;
/** 用户标签字典项(HTTP 出参;不暴露实体上的租户与审计列)。 */
@Data
public class UserTagResponse {
private Integer id;
private String tagName;
private String normalizedName;
private LocalDateTime createdTime;
private LocalDateTime lastModifiedTime;
public static UserTagResponse of(UserTagEntity entity) {
if (entity == null) {
return null;
}
UserTagResponse response = new UserTagResponse();
response.setId(entity.getId());
response.setTagName(entity.getTagName());
response.setNormalizedName(entity.getNormalizedName());
response.setCreatedTime(entity.getCreatedTime());
response.setLastModifiedTime(entity.getLastModifiedTime());
return response;
}
}
@@ -6,10 +6,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.guo.learningprogresstracker.enums.AiTaskStatusEnum;
import com.guo.learningprogresstracker.utils.GenerateNumTool;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
/**
* AI 异步任务(AI-02):提交后立即返回任务标识,结果由执行器回写、按标识重复获取。
@@ -49,6 +48,9 @@ public class AiTaskEntity extends BaseEntity implements Serializable {
@TableField(value = "error_message")
private String errorMessage;
@TableField(value = "error_code")
private String errorCode;
@TableField(value = "started_time")
private LocalDateTime startedTime;
@@ -4,11 +4,10 @@ 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 lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import lombok.Data;
/**
* AI 用量记录:lpt-ai 每完成一次 AI 任务后上报一条,供「AI 用量统计」面板聚合。
@@ -34,7 +33,7 @@ public class AiUsageRecordEntity extends BaseEntity implements Serializable {
@TableField(value = "occurred_at")
private LocalDateTime occurredAt;
/** 任务类型:aggregate-report/generate-mind-map/compare-recall/guidance/fetch-title */
/** 任务类型:aggregate-report/generate-mind-map/recall-hint/recall-check/guidance/fetch-title */
@TableField(value = "task_type")
private String taskType;
@@ -3,9 +3,8 @@ package com.guo.learningprogresstracker.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
import java.time.LocalDateTime;
import lombok.Data;
/**
* @author guo
@@ -4,9 +4,8 @@ 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 lombok.Data;
import java.io.Serializable;
import lombok.Data;
/**
* 统一标记(标记-01):附加在对象上的一段轻量元信息。
@@ -45,6 +44,8 @@ public class MarkerEntity extends BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
public boolean isSystemMarker() {
return com.guo.learningprogresstracker.enums.MarkerKindEnum.SYSTEM.name().equals(kind);
return com.guo.learningprogresstracker.enums.MarkerKindEnum.SYSTEM
.name()
.equals(kind);
}
}
@@ -5,10 +5,9 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.guo.learningprogresstracker.utils.GenerateNumTool;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
/**
* 学习引导会话(复习-06):一次复习行为。
@@ -0,0 +1,21 @@
package com.guo.learningprogresstracker.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("review_recalls")
public class ReviewRecallEntity extends BaseEntity {
@TableId(type = IdType.AUTO)
private Long id;
private String recallNum;
private String scopeType;
private String taskNum;
private String scopeKey;
private String status;
private Long activeDurationMs;
private String documentJson;
}
@@ -0,0 +1,18 @@
package com.guo.learningprogresstracker.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("review_recall_receipts")
public class ReviewRecallReceiptEntity extends BaseEntity {
@TableId(type = IdType.AUTO)
private Long id;
private String receiptKey;
private String payloadHash;
private String recallNum;
private String taskNum;
}
@@ -1,86 +0,0 @@
package com.guo.learningprogresstracker.entity;
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 lombok.Data;
import java.io.Serializable;
/**
* 复习回忆与标准导图的对比记录
*/
@TableName(value = "review_recall_records")
@Data
public class ReviewRecallRecordEntity extends BaseEntity implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/** 任务编码;标签范围复习时为空,取值口径见 {@code scopeType} */
@TableField(value = "task_num")
private String taskNum;
/** 复习范围:TASK=任务导图 / TAG=标签导图,取值见 {@code ReviewScopeTypeEnum} */
@TableField(value = "scope_type")
private String scopeType;
/** 标签范围的规范键(与标签导图同源);任务范围为空 */
@TableField(value = "scope_key")
private String scopeKey;
/** 范围的标签集合(JSON 数组,按归一化名排序);任务范围为空 */
@TableField(value = "scope_tags")
private String scopeTags;
/** 标签范围的取数模式:UNION / INTERSECT;任务范围为空 */
@TableField(value = "scope_mode")
private String scopeMode;
/** 对比时使用的基准导图 ID:任务范围指向任务导图,标签范围指向标签导图 */
@TableField(value = "standard_map_id")
private Integer standardMapId;
/**
* 复习起点节点路径(以 / 分隔),null 表示整棵树
*/
@TableField(value = "focus_path")
private String focusPath;
/**
* 用户回忆绘制的导图大纲文本
*/
@TableField(value = "recall_content")
private String recallContent;
/**
* 与标准导图的结构对比结果 JSON
*/
@TableField(value = "compare_result")
private String compareResult;
/**
* 回忆覆盖率(0-1)
*/
@TableField(value = "recall_ratio")
private Double recallRatio;
@TableField(value = "matched_count")
private Integer matchedCount;
@TableField(value = "missed_count")
private Integer missedCount;
@TableField(value = "extra_count")
private Integer extraCount;
/**
* 本次复习耗时(秒),已按「超过 5 分钟无交互则截断」规则结算
*/
@TableField(value = "review_duration_seconds")
private Integer reviewDurationSeconds;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
@@ -0,0 +1,19 @@
package com.guo.learningprogresstracker.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("review_recall_requests")
public class ReviewRecallRequestEntity extends BaseEntity {
@TableId(type = IdType.AUTO)
private Long id;
private String recallNum;
private String taskNum;
private String paramsJson;
private String remoteTaskId;
private Integer redacted;
}
@@ -4,10 +4,9 @@ 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 lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
/**
* 任务标准思维导图:由内置规则或 AI 从学习报告生成,用户可修改
@@ -4,10 +4,9 @@ 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 lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
/**
* 标签思维导图(闭环-04):以一个「标签集合 + 取数模式」为范围的导图,与任务导图并存。
@@ -4,9 +4,8 @@ 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 lombok.Data;
import java.io.Serializable;
import lombok.Data;
/**
* 存储每次学习开始前的预期
@@ -5,9 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.guo.learningprogresstracker.enums.FragmentContextTypeEnum;
import lombok.Data;
import java.io.Serializable;
import lombok.Data;
/**
* 记录学习过程中的学习内容报告残片(知识碎片)。
@@ -4,9 +4,8 @@ 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 lombok.Data;
import java.io.Serializable;
import lombok.Data;
/**
* 存储每次学习结束时的完整学习报告。
@@ -8,19 +8,18 @@ import com.google.protobuf.ServiceException;
import com.guo.learningprogresstracker.common.StudyTimePolicy;
import com.guo.learningprogresstracker.enums.StudySessionStateEnum;
import com.guo.learningprogresstracker.utils.GenerateNumTool;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import java.io.Serializable;
import java.time.Duration;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
/**
* 记录每次学习会话的具体数据
* @TableName study_sessions
*/
@TableName(value ="study_sessions")
@TableName(value = "study_sessions")
@Slf4j
@Data
public class StudySessionsEntity extends BaseEntity implements Serializable {
@@ -83,7 +82,6 @@ public class StudySessionsEntity extends BaseEntity implements Serializable {
@TableField(value = "auto_converged")
private Boolean autoConverged;
/**
* 计时器指针位置,时间戳形式存储(毫秒)
*/
@@ -96,14 +94,14 @@ public class StudySessionsEntity extends BaseEntity implements Serializable {
/**
* 初始化新会话(使用默认时间口径)
*/
public static StudySessionsEntity initNewSession(){
public static StudySessionsEntity initNewSession() {
return initNewSession(StudyTimePolicy.DEFAULT);
}
/**
* 初始化新会话
*/
public static StudySessionsEntity initNewSession(StudyTimePolicy policy){
public static StudySessionsEntity initNewSession(StudyTimePolicy policy) {
StudySessionsEntity studySessionsEntity = new StudySessionsEntity();
studySessionsEntity.setSessionNum(GenerateNumTool.generateNum("SESSION"));
studySessionsEntity.setStartTime(LocalDateTime.now());
@@ -126,35 +124,36 @@ public class StudySessionsEntity extends BaseEntity implements Serializable {
* 继续会话
*/
public void continueStudySession(StudyTimePolicy policy) throws ServiceException {
if (this.getSessionState().equals(StudySessionStateEnum.PAUSED.name())){
if (this.getSessionState().equals(StudySessionStateEnum.PAUSED.name())) {
this.setSessionState(StudySessionStateEnum.ONGOING.name());
this.setLastStartTime(LocalDateTime.now());
this.calculatePointerPosition(policy);
} else if (this.getSessionState().equals(StudySessionStateEnum.ONGOING.name())) {
log.info("进行中的学习会话({})被重新开始",this.getSessionNum());
} else{
log.warn("不应出现的情况:开始了一个状态为【{}】的学习会话({})",this.getSessionState(),this.getSessionNum());
log.info("进行中的学习会话({})被重新开始", this.getSessionNum());
} else {
log.warn("不应出现的情况:开始了一个状态为【{}】的学习会话({})", this.getSessionState(), this.getSessionNum());
}
}
/**
* 暂停会话(使用默认时间口径)
*/
public void pausedStudySession(LocalDateTime endTime){
public void pausedStudySession(LocalDateTime endTime) {
pausedStudySession(endTime, StudyTimePolicy.DEFAULT);
}
/**
* 暂停会话
*/
public void pausedStudySession(LocalDateTime endTime, StudyTimePolicy policy){
public void pausedStudySession(LocalDateTime endTime, StudyTimePolicy policy) {
if (this.getSessionState().equals(StudySessionStateEnum.PAUSED.name())) {
log.warn("不应出现的情况:暂停了一个状态为【{}】的学习会话({})", this.getSessionState(), this.getSessionNum());
} else {
LocalDateTime settlementTime = this.resolveSettlementTime(endTime, policy);
this.setEndTime(settlementTime);
this.setActualTime(Duration.between(this.startTime, this.endTime).toSeconds());
this.setEffectiveTime(this.getEffectiveTime() + Duration.between(this.lastStartTime, this.endTime).toSeconds());
this.setEffectiveTime(this.getEffectiveTime()
+ Duration.between(this.lastStartTime, this.endTime).toSeconds());
this.setEffectivenessRatio(this.effectiveTime / this.actualTime);
this.setSessionState(StudySessionStateEnum.PAUSED.name());
}
@@ -181,8 +180,11 @@ public class StudySessionsEntity extends BaseEntity implements Serializable {
}
long minutes = Duration.between(this.lastStartTime, end).toMinutes();
if (minutes >= policy.getForgetThresholdMinutes()) {
log.info("会话[{}]本段学习已超过{}分钟无操作,按{}分钟结算",
this.getSessionNum(), policy.getForgetThresholdMinutes(), policy.getWorkDurationMinutes());
log.info(
"会话[{}]本段学习已超过{}分钟无操作,按{}分钟结算",
this.getSessionNum(),
policy.getForgetThresholdMinutes(),
policy.getWorkDurationMinutes());
return this.lastStartTime.plusMinutes(policy.getWorkDurationMinutes());
}
return end;
@@ -199,15 +201,18 @@ public class StudySessionsEntity extends BaseEntity implements Serializable {
* 结束会话
*/
public void endedStudySession(StudyTimePolicy policy) {
if (this.isEnded()){
log.warn("不应出现的情况:结束了一个状态为【{}】的学习会话",this.getSessionState());
}else {
if (this.isEnded()) {
log.warn("不应出现的情况:结束了一个状态为【{}】的学习会话", this.getSessionState());
} else {
if (this.getSessionState().equals(StudySessionStateEnum.ONGOING.name())) {
this.pausedStudySession(LocalDateTime.now(), policy);
}
if (this.getEffectiveTime() < policy.getMinEffectiveTimeSeconds()) {
log.info("会话[{}]有效学习时间({}秒)不足{}分钟,不计入总学习时间",
this.getSessionNum(), this.getEffectiveTime(), policy.getMinEffectiveTimeSeconds() / 60);
log.info(
"会话[{}]有效学习时间({}秒)不足{}分钟,不计入总学习时间",
this.getSessionNum(),
this.getEffectiveTime(),
policy.getMinEffectiveTimeSeconds() / 60);
this.setEffectiveTime(0);
this.setEffectivenessRatio(0);
}
@@ -253,7 +258,6 @@ public class StudySessionsEntity extends BaseEntity implements Serializable {
return ObjectUtils.isEmpty(this.pointerPosition);
}
/**
* 计算当前倒计时指针的位置(使用默认时间口径)
*/
@@ -287,10 +291,10 @@ public class StudySessionsEntity extends BaseEntity implements Serializable {
return;
case ONGOING:
long elapsedMillis = Duration.between(lastStartTime, LocalDateTime.now()).toMillis();
long basePointerPosition = ObjectUtils.isEmpty(pointerPosition)
? policy.workDurationMillis()
: pointerPosition;
long elapsedMillis =
Duration.between(lastStartTime, LocalDateTime.now()).toMillis();
long basePointerPosition =
ObjectUtils.isEmpty(pointerPosition) ? policy.workDurationMillis() : pointerPosition;
long newPointerPosition = basePointerPosition - elapsedMillis;
if (newPointerPosition <= 0) {
// 如果循环已经结束,则需要重置指针位置
@@ -313,7 +317,6 @@ public class StudySessionsEntity extends BaseEntity implements Serializable {
}
}
/**
* 学习会话是否已经结束。
*/

Some files were not shown because too many files have changed in this diff Show More