Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6678c2b8c0 | ||
|
|
b434520eff | ||
|
|
5b6f7d6a2a | ||
|
|
c8d0584f11 |
@@ -73,6 +73,7 @@ lpt-be/src/main/java/com/guo/learningprogresstracker/
|
|||||||
- 业务错误:`CommonResult.error(msg)`,code=400,HTTP 200。
|
- 业务错误:`CommonResult.error(msg)`,code=400,HTTP 200。
|
||||||
- 未登录:`GlobalExceptionHandler.handleNotLogin()`,HTTP 401 + code=401。
|
- 未登录:`GlobalExceptionHandler.handleNotLogin()`,HTTP 401 + code=401。
|
||||||
- 参数校验失败:`MethodArgumentNotValidException`,code=400。
|
- 参数校验失败:`MethodArgumentNotValidException`,code=400。
|
||||||
|
- 用户可见错误文案必须口语化、可理解,避免“无法生成”“不存在”等技术化表述;技术细节写入日志。例如无学习报告时应提示“这个任务还没开始学习哦,学习后产生学习报告后再来吧”,而不是“没有学习报告,无法生成思维导图”。
|
||||||
|
|
||||||
## DTO 转换
|
## DTO 转换
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.guo.learningprogresstracker.entity.CommonResult;
|
|||||||
import com.guo.learningprogresstracker.exception.AppException;
|
import com.guo.learningprogresstracker.exception.AppException;
|
||||||
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||||
|
import com.guo.learningprogresstracker.exception.OperationFailedException;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -21,16 +22,25 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
@ExceptionHandler({ErrorParameterException.class})
|
@ExceptionHandler({ErrorParameterException.class})
|
||||||
public CommonResult errorParameterException(ErrorParameterException ex) {
|
public CommonResult errorParameterException(ErrorParameterException ex) {
|
||||||
|
log.warn("参数异常: {}", ex.getMessage(), ex);
|
||||||
return CommonResult.error(ex.getMessage());
|
return CommonResult.error(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler({NotFindEntitiesException.class})
|
@ExceptionHandler({NotFindEntitiesException.class})
|
||||||
public CommonResult notFindEntitiesException(NotFindEntitiesException ex) {
|
public CommonResult notFindEntitiesException(NotFindEntitiesException ex) {
|
||||||
|
log.warn("数据不存在: {}", ex.getMessage(), ex);
|
||||||
|
return CommonResult.error(ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler({OperationFailedException.class})
|
||||||
|
public CommonResult operationFailedException(OperationFailedException ex) {
|
||||||
|
log.warn("操作失败: {}", ex.getMessage(), ex);
|
||||||
return CommonResult.error(ex.getMessage());
|
return CommonResult.error(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler({AppException.class})
|
@ExceptionHandler({AppException.class})
|
||||||
public CommonResult AppException(AppException ex) {
|
public CommonResult AppException(AppException ex) {
|
||||||
|
log.error("业务异常: {}", ex.getMessage(), ex);
|
||||||
return CommonResult.serverError(ex.getMessage());
|
return CommonResult.serverError(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +59,7 @@ public class GlobalExceptionHandler {
|
|||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public CommonResult Exception(Exception ex) {
|
public CommonResult Exception(Exception ex) {
|
||||||
log.error("系统异常", ex);
|
log.error("系统异常", ex);
|
||||||
return CommonResult.error(ex.getMessage());
|
return CommonResult.error("操作没有成功,请稍后再试");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class ReviewController {
|
|||||||
private final StandardMindMapService standardMindMapService;
|
private final StandardMindMapService standardMindMapService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取复习 feed,合并报告和残片按时间倒序
|
* 获取复习 feed,仅返回学习残片(首页滚动条使用)
|
||||||
*/
|
*/
|
||||||
@GetMapping("/feed")
|
@GetMapping("/feed")
|
||||||
public CommonResult<List<ReviewFeedItem>> getReviewFeed(
|
public CommonResult<List<ReviewFeedItem>> getReviewFeed(
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ public class StudySessionController {
|
|||||||
* 通过sessionNum获取一个【学习会话】
|
* 通过sessionNum获取一个【学习会话】
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{sessionNum}")
|
@GetMapping("/{sessionNum}")
|
||||||
public CommonResult<StudySessionResponse> getStudySessionBySessionNum(@NotEmpty(message = "sessionNum不可为空") @PathVariable String sessionNum) throws ErrorParameterException {
|
public CommonResult<StudySessionResponse> getStudySessionBySessionNum(@NotEmpty(message = "请提供学习会话编号") @PathVariable String sessionNum) throws ErrorParameterException {
|
||||||
// 通过 service 层获取,包含归属校验
|
// 通过 service 层获取,包含归属校验
|
||||||
StudySessionResponse response = studySessionsServiceImpl.getStudySessionBySessionNum(sessionNum);
|
StudySessionResponse response = studySessionsServiceImpl.getStudySessionBySessionNum(sessionNum);
|
||||||
return CommonResult.success(response);
|
return CommonResult.success(response);
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public class TaskController {
|
|||||||
* 开始或继续一个【学习会话】
|
* 开始或继续一个【学习会话】
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{taskNum}/study-sessions/start-or-continue")
|
@GetMapping("/{taskNum}/study-sessions/start-or-continue")
|
||||||
public CommonResult<StudySessionResponse> startOrContinueStudySession(@NotEmpty(message = "taskNum不可为空")
|
public CommonResult<StudySessionResponse> startOrContinueStudySession(@NotEmpty(message = "请提供任务编号")
|
||||||
@PathVariable String taskNum) throws NotFindEntitiesException, ServiceException {
|
@PathVariable String taskNum) throws NotFindEntitiesException, ServiceException {
|
||||||
StudySessionResponse response = studySessionsServiceImpl.startOrContinueStudySession(taskNum);
|
StudySessionResponse response = studySessionsServiceImpl.startOrContinueStudySession(taskNum);
|
||||||
return CommonResult.success(response);
|
return CommonResult.success(response);
|
||||||
@@ -143,7 +143,7 @@ public class TaskController {
|
|||||||
* 通过学习任务num获取该任务的未结束会话
|
* 通过学习任务num获取该任务的未结束会话
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{taskNum}/not-ended-study-session")
|
@GetMapping("/{taskNum}/not-ended-study-session")
|
||||||
public CommonResult<StudySessionResponse> getNotEndedStudySessionByTaskNum(@NotEmpty(message = "taskNum不可为空")
|
public CommonResult<StudySessionResponse> getNotEndedStudySessionByTaskNum(@NotEmpty(message = "请提供任务编号")
|
||||||
@PathVariable String taskNum) throws ErrorParameterException {
|
@PathVariable String taskNum) throws ErrorParameterException {
|
||||||
StudySessionResponse response = studySessionsServiceImpl.getNotEndedStudySessionByTaskNum(taskNum);
|
StudySessionResponse response = studySessionsServiceImpl.getNotEndedStudySessionByTaskNum(taskNum);
|
||||||
return CommonResult.success(response);
|
return CommonResult.success(response);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import lombok.Data;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 复习滚动 feed 条目,合并展示学习报告和残片
|
* 复习滚动 feed 条目;首页仅使用残片,任务详情仍可同时包含报告和残片
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class ReviewFeedItem {
|
public class ReviewFeedItem {
|
||||||
|
|||||||
+1
-1
@@ -16,6 +16,6 @@ public class CreateFragmentsRequest {
|
|||||||
/**
|
/**
|
||||||
* 残片内容,学习内容的描述
|
* 残片内容,学习内容的描述
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "啊?无字天书?")
|
@NotBlank(message = "请填写学习内容")
|
||||||
private String content;
|
private String content;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ public class CreateTaskApplicationRequest {
|
|||||||
|
|
||||||
private String taskNum;
|
private String taskNum;
|
||||||
|
|
||||||
@NotBlank(message = "应用项目标题不可为空")
|
@NotBlank(message = "请填写应用项目标题")
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|||||||
+1
-1
@@ -8,6 +8,6 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class EndedStudySessionRequest {
|
public class EndedStudySessionRequest {
|
||||||
@NotBlank(message = "啊?搞无字天书是吧?报告内容不可为空")
|
@NotBlank(message = "请填写学习报告内容")
|
||||||
private String content;
|
private String content;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class RecallCompareRequest {
|
public class RecallCompareRequest {
|
||||||
|
|
||||||
@NotBlank(message = "回忆大纲不可为空")
|
@NotBlank(message = "请先填写回忆大纲")
|
||||||
private String recallOutline;
|
private String recallOutline;
|
||||||
|
|
||||||
/** 复习起点节点路径(以 / 分隔),null 为任务维度 */
|
/** 复习起点节点路径(以 / 分隔),null 为任务维度 */
|
||||||
|
|||||||
@@ -15,16 +15,16 @@ import lombok.Data;
|
|||||||
public class TaskRequest {
|
public class TaskRequest {
|
||||||
|
|
||||||
public interface Create{}
|
public interface Create{}
|
||||||
@Null(message = "创建时不可指定任务ID",groups = Ops.CreateG.class)
|
@Null(message = "创建任务时不需要填写任务编号",groups = Ops.CreateG.class)
|
||||||
@NotNull(message = "更新时必须指定任务ID",groups = Ops.UpdateG.class)
|
@NotNull(message = "缺少要更新的任务信息,请刷新后重试",groups = Ops.UpdateG.class)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
/**
|
/**
|
||||||
* 学习任务的名称
|
* 学习任务的名称
|
||||||
*/
|
*/
|
||||||
@NotEmpty(message = "必须指定非空的任务名称", groups = Ops.CreateG.class)
|
@NotEmpty(message = "请填写任务名称", groups = Ops.CreateG.class)
|
||||||
private String taskName;
|
private String taskName;
|
||||||
|
|
||||||
@NotEmpty(message = "必须指定非空的任务描述", groups = Ops.CreateG.class)
|
@NotEmpty(message = "请填写任务描述", groups = Ops.CreateG.class)
|
||||||
private String taskDescription;
|
private String taskDescription;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,41 +35,41 @@ public class TaskRequest {
|
|||||||
/**
|
/**
|
||||||
* 用户设置的任务紧急性
|
* 用户设置的任务紧急性
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "必须指定【任务紧急性】指标", groups = Ops.CreateG.class)
|
@NotNull(message = "请设置任务紧急性", groups = Ops.CreateG.class)
|
||||||
@Min(value = 0,message = "urgency参数值必须大于等于0")
|
@Min(value = 0,message = "任务紧急性不能小于 0")
|
||||||
@Max(value = 5,message = "urgency参数值必须小于等于5")
|
@Max(value = 5,message = "任务紧急性不能大于 5")
|
||||||
private Integer urgency;
|
private Integer urgency;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户设置的任务重要性
|
* 用户设置的任务重要性
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "必须指定【任务重要性】指标", groups = Ops.CreateG.class)
|
@NotNull(message = "请设置任务重要性", groups = Ops.CreateG.class)
|
||||||
@Min(value = 0,message = "importance参数值必须大于等于0")
|
@Min(value = 0,message = "任务重要性不能小于 0")
|
||||||
@Max(value = 5,message = "importance参数值必须小于等于5")
|
@Max(value = 5,message = "任务重要性不能大于 5")
|
||||||
private Integer importance;
|
private Integer importance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 任务的内容难度
|
* 任务的内容难度
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "必须指定【内容难度】指标", groups = Ops.CreateG.class)
|
@NotNull(message = "请设置内容难度", groups = Ops.CreateG.class)
|
||||||
@Min(value = 0,message = "contentDifficulty参数值必须大于等于0")
|
@Min(value = 0,message = "内容难度不能小于 0")
|
||||||
@Max(value = 5,message = "contentDifficulty参数值必须小于等于5")
|
@Max(value = 5,message = "内容难度不能大于 5")
|
||||||
private Integer contentDifficulty;
|
private Integer contentDifficulty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 任务的未来价值
|
* 任务的未来价值
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "必须指定【未来价值】指标", groups = Ops.CreateG.class)
|
@NotNull(message = "请设置未来价值", groups = Ops.CreateG.class)
|
||||||
@Min(value = 0,message = "futureValue参数值必须大于等于0")
|
@Min(value = 0,message = "未来价值不能小于 0")
|
||||||
@Max(value = 5,message = "futureValue参数值必须小于等于5")
|
@Max(value = 5,message = "未来价值不能大于 5")
|
||||||
private Integer futureValue;
|
private Integer futureValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户对任务的主观优先级
|
* 用户对任务的主观优先级
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "必须指定【主观优先级】指标", groups = Ops.CreateG.class)
|
@NotNull(message = "请设置主观优先级", groups = Ops.CreateG.class)
|
||||||
@Min(value = 0,message = "subjectivePriority参数值必须大于等于0")
|
@Min(value = 0,message = "主观优先级不能小于 0")
|
||||||
@Max(value = 5,message = "subjectivePriority参数值必须小于等于5")
|
@Max(value = 5,message = "主观优先级不能大于 5")
|
||||||
private Integer subjectivePriority;
|
private Integer subjectivePriority;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -11,6 +11,6 @@ public class UpdateFragmentsRequest {
|
|||||||
/**
|
/**
|
||||||
* 残片内容,学习内容的描述
|
* 残片内容,学习内容的描述
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "啊?无字天书?")
|
@NotBlank(message = "请填写学习内容")
|
||||||
private String content;
|
private String content;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -9,6 +9,6 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class UpdateStandardMindMapRequest {
|
public class UpdateStandardMindMapRequest {
|
||||||
|
|
||||||
@NotBlank(message = "思维导图大纲不可为空")
|
@NotBlank(message = "请填写思维导图大纲")
|
||||||
private String outline;
|
private String outline;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class UpdateTaskApplicationRequest {
|
public class UpdateTaskApplicationRequest {
|
||||||
|
|
||||||
@NotBlank(message = "应用项目标题不可为空")
|
@NotBlank(message = "请填写应用项目标题")
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|||||||
+1
-1
@@ -9,6 +9,6 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class UpsertExpectationRequest {
|
public class UpsertExpectationRequest {
|
||||||
|
|
||||||
@NotBlank(message = "学习预期不可为空")
|
@NotBlank(message = "请填写学习预期")
|
||||||
private String description;
|
private String description;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import java.io.Serializable;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 任务标准思维导图:由内置规则或 AI 从学习报告/残片生成,用户可修改
|
* 任务标准思维导图:由内置规则或 AI 从学习报告生成,用户可修改
|
||||||
*/
|
*/
|
||||||
@TableName(value = "review_standard_mind_maps")
|
@TableName(value = "review_standard_mind_maps")
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.guo.learningprogresstracker.service;
|
package com.guo.learningprogresstracker.service;
|
||||||
|
|
||||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
|
||||||
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
||||||
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
|
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
|
||||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||||
@@ -26,14 +25,12 @@ public interface MindMapAiClient {
|
|||||||
*
|
*
|
||||||
* @param task 学习任务
|
* @param task 学习任务
|
||||||
* @param reports 该任务的全部学习报告
|
* @param reports 该任务的全部学习报告
|
||||||
* @param fragments 该任务的全部学习残片
|
|
||||||
* @param applications 该任务的应用场景(可选)
|
* @param applications 该任务的应用场景(可选)
|
||||||
* @param clientHint 前端已有的大纲文本(可选,用于 AI 续写而非全量生成)
|
* @param clientHint 前端已有的大纲文本(可选,用于 AI 续写而非全量生成)
|
||||||
* @return 标准思维导图的根节点;若无可生成数据则返回 {@link Optional#empty()}
|
* @return 标准思维导图的根节点;若无可生成数据则返回 {@link Optional#empty()}
|
||||||
*/
|
*/
|
||||||
Optional<MindMapNode> generate(TaskEntity task,
|
Optional<MindMapNode> generate(TaskEntity task,
|
||||||
List<StudyReportsEntity> reports,
|
List<StudyReportsEntity> reports,
|
||||||
List<StudyReportFragmentsEntity> fragments,
|
|
||||||
List<TaskApplicationEntity> applications,
|
List<TaskApplicationEntity> applications,
|
||||||
String clientHint);
|
String clientHint);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
public interface ReviewService {
|
public interface ReviewService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取复习 feed 列表,合并报告和残片按时间倒序
|
* 获取复习 feed 列表,仅返回学习残片并按时间倒序
|
||||||
*/
|
*/
|
||||||
List<ReviewFeedItem> getReviewFeed(int limit, String mode);
|
List<ReviewFeedItem> getReviewFeed(int limit, String mode);
|
||||||
|
|
||||||
|
|||||||
@@ -82,10 +82,10 @@ public class AiServiceClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调用 lpt-ai 从学习数据生成思维导图大纲。
|
* 调用 lpt-ai 从学习报告生成思维导图大纲。
|
||||||
*/
|
*/
|
||||||
public Optional<String> generateMindMap(String taskName, String taskDescription,
|
public Optional<String> generateMindMap(String taskName, String taskDescription,
|
||||||
List<String> reports, List<String> fragments) {
|
List<String> reports) {
|
||||||
if (!isConfigured()) {
|
if (!isConfigured()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
@@ -93,8 +93,7 @@ public class AiServiceClient {
|
|||||||
Map<String, Object> params = Map.of(
|
Map<String, Object> params = Map.of(
|
||||||
"taskName", taskName,
|
"taskName", taskName,
|
||||||
"taskDescription", taskDescription != null ? taskDescription : "",
|
"taskDescription", taskDescription != null ? taskDescription : "",
|
||||||
"reports", reports != null ? reports : List.of(),
|
"reports", reports != null ? reports : List.of()
|
||||||
"fragments", fragments != null ? fragments : List.of()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Optional<JsonNode> result = submitAndWait("generate-mind-map", params);
|
Optional<JsonNode> result = submitAndWait("generate-mind-map", params);
|
||||||
|
|||||||
+11
-37
@@ -1,6 +1,5 @@
|
|||||||
package com.guo.learningprogresstracker.service.impl;
|
package com.guo.learningprogresstracker.service.impl;
|
||||||
|
|
||||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
|
||||||
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
||||||
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
|
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
|
||||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||||
@@ -16,12 +15,12 @@ import java.util.*;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内置规则引擎:从学习报告和残片提取关键词并组织为树形思维导图。
|
* 内置规则引擎:从学习报告提取内容并组织为树形思维导图。
|
||||||
* <p>规则策略:</p>
|
* <p>规则策略:</p>
|
||||||
* <ol>
|
* <ol>
|
||||||
* <li>根节点 = 任务名称</li>
|
* <li>根节点 = 任务名称</li>
|
||||||
* <li>一级分支 = 按会话(日期+报告摘要)分组</li>
|
* <li>一级分支 = 按会话(日期+报告摘要)分组</li>
|
||||||
* <li>二级分支 = 该会话下的残片标题</li>
|
* <li>二级分支 = 该会话下的报告</li>
|
||||||
* <li>附加分支"应用场景" = 任务应用场景(如有)</li>
|
* <li>附加分支"应用场景" = 任务应用场景(如有)</li>
|
||||||
* <li>去重:标准化后标题对比,合并内容相似的节点</li>
|
* <li>去重:标准化后标题对比,合并内容相似的节点</li>
|
||||||
* <li>引用追溯:每个节点携带 sourceType / sourceId</li>
|
* <li>引用追溯:每个节点携带 sourceType / sourceId</li>
|
||||||
@@ -46,10 +45,9 @@ public class BuiltinMindMapGenerator implements MindMapAiClient {
|
|||||||
@Override
|
@Override
|
||||||
public Optional<MindMapNode> generate(TaskEntity task,
|
public Optional<MindMapNode> generate(TaskEntity task,
|
||||||
List<StudyReportsEntity> reports,
|
List<StudyReportsEntity> reports,
|
||||||
List<StudyReportFragmentsEntity> fragments,
|
|
||||||
List<TaskApplicationEntity> applications,
|
List<TaskApplicationEntity> applications,
|
||||||
String clientHint) {
|
String clientHint) {
|
||||||
if (reports.isEmpty() && fragments.isEmpty()) {
|
if (reports == null || reports.isEmpty()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,34 +56,21 @@ public class BuiltinMindMapGenerator implements MindMapAiClient {
|
|||||||
|
|
||||||
// 按 session 分组
|
// 按 session 分组
|
||||||
Map<String, List<StudyReportsEntity>> reportsBySession = reports.stream()
|
Map<String, List<StudyReportsEntity>> reportsBySession = reports.stream()
|
||||||
|
.filter(r -> r.getSessionNum() != null)
|
||||||
.collect(Collectors.groupingBy(StudyReportsEntity::getSessionNum));
|
.collect(Collectors.groupingBy(StudyReportsEntity::getSessionNum));
|
||||||
Map<String, List<StudyReportFragmentsEntity>> fragmentsBySession = fragments.stream()
|
|
||||||
.collect(Collectors.groupingBy(StudyReportFragmentsEntity::getSessionNum));
|
|
||||||
|
|
||||||
// 合并所有 session
|
for (Map.Entry<String, List<StudyReportsEntity>> entry : reportsBySession.entrySet()) {
|
||||||
Set<String> allSessions = new LinkedHashSet<>();
|
List<StudyReportsEntity> sessReports = entry.getValue();
|
||||||
allSessions.addAll(reportsBySession.keySet());
|
|
||||||
allSessions.addAll(fragmentsBySession.keySet());
|
|
||||||
|
|
||||||
for (String sessionNum : allSessions) {
|
// 会话分支标题:取第一条报告的前 60 字作为摘要
|
||||||
List<StudyReportsEntity> sessReports = reportsBySession.getOrDefault(sessionNum, List.of());
|
StudyReportsEntity firstReport = sessReports.get(0);
|
||||||
List<StudyReportFragmentsEntity> sessFragments = fragmentsBySession.getOrDefault(sessionNum, List.of());
|
String sessionTitle = truncate(firstReport.getContent(), MAX_TITLE_LENGTH);
|
||||||
|
if (firstReport.getCreatedTime() != null) {
|
||||||
// 会话分支标题:取第一条报告的前 60 字作为摘要,或直接写"学习记录"
|
sessionTitle = formatDate(firstReport.getCreatedTime()) + " " + sessionTitle;
|
||||||
String sessionTitle;
|
|
||||||
if (!sessReports.isEmpty()) {
|
|
||||||
String firstReport = sessReports.get(0).getContent();
|
|
||||||
sessionTitle = truncate(firstReport, MAX_TITLE_LENGTH);
|
|
||||||
if (sessReports.get(0).getCreatedTime() != null) {
|
|
||||||
sessionTitle = formatDate(sessReports.get(0).getCreatedTime()) + " " + sessionTitle;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sessionTitle = "学习记录 " + (sessFragments.isEmpty() ? "" : formatDate(sessFragments.get(0).getCreatedTime()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MindMapNode sessionNode = new MindMapNode(sessionTitle);
|
MindMapNode sessionNode = new MindMapNode(sessionTitle);
|
||||||
|
|
||||||
// 报告作为子节点
|
|
||||||
for (StudyReportsEntity report : sessReports) {
|
for (StudyReportsEntity report : sessReports) {
|
||||||
String content = report.getContent();
|
String content = report.getContent();
|
||||||
if (content == null || content.isBlank()) continue;
|
if (content == null || content.isBlank()) continue;
|
||||||
@@ -96,17 +81,6 @@ public class BuiltinMindMapGenerator implements MindMapAiClient {
|
|||||||
sessionNode.getChildren().add(reportNode);
|
sessionNode.getChildren().add(reportNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 残片作为子节点
|
|
||||||
for (StudyReportFragmentsEntity frag : sessFragments) {
|
|
||||||
String content = frag.getContent();
|
|
||||||
if (content == null || content.isBlank()) continue;
|
|
||||||
MindMapNode fragNode = new MindMapNode(truncate(content, MAX_TITLE_LENGTH));
|
|
||||||
fragNode.setNotes(content);
|
|
||||||
fragNode.setSourceType("FRAGMENT");
|
|
||||||
fragNode.setSourceId(frag.getId());
|
|
||||||
sessionNode.getChildren().add(fragNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
root.getChildren().add(sessionNode);
|
root.getChildren().add(sessionNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-10
@@ -1,6 +1,5 @@
|
|||||||
package com.guo.learningprogresstracker.service.impl;
|
package com.guo.learningprogresstracker.service.impl;
|
||||||
|
|
||||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
|
||||||
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
import com.guo.learningprogresstracker.entity.StudyReportsEntity;
|
||||||
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
|
import com.guo.learningprogresstracker.entity.TaskApplicationEntity;
|
||||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||||
@@ -40,32 +39,26 @@ public class RemoteAiMindMapClient implements MindMapAiClient {
|
|||||||
@Override
|
@Override
|
||||||
public Optional<MindMapNode> generate(TaskEntity task,
|
public Optional<MindMapNode> generate(TaskEntity task,
|
||||||
List<StudyReportsEntity> reports,
|
List<StudyReportsEntity> reports,
|
||||||
List<StudyReportFragmentsEntity> fragments,
|
|
||||||
List<TaskApplicationEntity> applications,
|
List<TaskApplicationEntity> applications,
|
||||||
String clientHint) {
|
String clientHint) {
|
||||||
if (!isAvailable()) {
|
if (!isAvailable()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提取报告和残片的内容文本
|
// 提取学习报告的内容文本
|
||||||
List<String> reportTexts = reports.stream()
|
List<String> reportTexts = reports.stream()
|
||||||
.map(StudyReportsEntity::getContent)
|
.map(StudyReportsEntity::getContent)
|
||||||
.filter(c -> c != null && !c.isBlank())
|
.filter(c -> c != null && !c.isBlank())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<String> fragmentTexts = fragments.stream()
|
|
||||||
.map(StudyReportFragmentsEntity::getContent)
|
|
||||||
.filter(c -> c != null && !c.isBlank())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (reportTexts.isEmpty() && fragmentTexts.isEmpty()) {
|
if (reportTexts.isEmpty()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<String> optOutline = aiServiceClient.generateMindMap(
|
Optional<String> optOutline = aiServiceClient.generateMindMap(
|
||||||
task.getTaskName(),
|
task.getTaskName(),
|
||||||
task.getTaskDescription(),
|
task.getTaskDescription(),
|
||||||
reportTexts,
|
reportTexts
|
||||||
fragmentTexts
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (optOutline.isEmpty() || optOutline.get().isBlank()) {
|
if (optOutline.isEmpty() || optOutline.get().isBlank()) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
|||||||
import com.guo.learningprogresstracker.mapper.TasksMapper;
|
import com.guo.learningprogresstracker.mapper.TasksMapper;
|
||||||
import com.guo.learningprogresstracker.service.ReviewService;
|
import com.guo.learningprogresstracker.service.ReviewService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ import java.util.stream.Stream;
|
|||||||
/**
|
/**
|
||||||
* 复习模块 Service 实现
|
* 复习模块 Service 实现
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ReviewServiceImpl implements ReviewService {
|
public class ReviewServiceImpl implements ReviewService {
|
||||||
@@ -53,13 +55,6 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
}
|
}
|
||||||
boolean random = RANDOM_MODE.equalsIgnoreCase(mode);
|
boolean random = RANDOM_MODE.equalsIgnoreCase(mode);
|
||||||
|
|
||||||
List<StudyReportsEntity> reports = random
|
|
||||||
? studyReportsMapper.selectList(Wrappers.<StudyReportsEntity>lambdaQuery()
|
|
||||||
.last("ORDER BY RAND() LIMIT " + safeLimit))
|
|
||||||
: studyReportsMapper.selectList(Wrappers.<StudyReportsEntity>lambdaQuery()
|
|
||||||
.orderByDesc(StudyReportsEntity::getCreatedTime)
|
|
||||||
.last("LIMIT " + safeLimit));
|
|
||||||
|
|
||||||
List<StudyReportFragmentsEntity> fragments = random
|
List<StudyReportFragmentsEntity> fragments = random
|
||||||
? studyReportFragmentsMapper.selectList(Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
? studyReportFragmentsMapper.selectList(Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
||||||
.last("ORDER BY RAND() LIMIT " + safeLimit))
|
.last("ORDER BY RAND() LIMIT " + safeLimit))
|
||||||
@@ -67,7 +62,7 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
.orderByDesc(StudyReportFragmentsEntity::getCreatedTime)
|
.orderByDesc(StudyReportFragmentsEntity::getCreatedTime)
|
||||||
.last("LIMIT " + safeLimit));
|
.last("LIMIT " + safeLimit));
|
||||||
|
|
||||||
List<ReviewFeedItem> items = mergeAndConvert(reports, fragments);
|
List<ReviewFeedItem> items = mergeAndConvert(List.of(), fragments);
|
||||||
if (random) {
|
if (random) {
|
||||||
Collections.shuffle(items);
|
Collections.shuffle(items);
|
||||||
}
|
}
|
||||||
@@ -82,14 +77,11 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
private List<ReviewFeedItem> getSmartFeed(int safeLimit) {
|
private List<ReviewFeedItem> getSmartFeed(int safeLimit) {
|
||||||
int candidateLimit = Math.min(safeLimit * SMART_CANDIDATE_MULTIPLIER, 500);
|
int candidateLimit = Math.min(safeLimit * SMART_CANDIDATE_MULTIPLIER, 500);
|
||||||
|
|
||||||
List<StudyReportsEntity> reports = studyReportsMapper.selectList(
|
|
||||||
Wrappers.<StudyReportsEntity>lambdaQuery()
|
|
||||||
.last("ORDER BY RAND() LIMIT " + candidateLimit));
|
|
||||||
List<StudyReportFragmentsEntity> fragments = studyReportFragmentsMapper.selectList(
|
List<StudyReportFragmentsEntity> fragments = studyReportFragmentsMapper.selectList(
|
||||||
Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
||||||
.last("ORDER BY RAND() LIMIT " + candidateLimit));
|
.last("ORDER BY RAND() LIMIT " + candidateLimit));
|
||||||
|
|
||||||
List<ReviewFeedItem> candidates = mergeAndConvert(reports, fragments);
|
List<ReviewFeedItem> candidates = mergeAndConvert(List.of(), fragments);
|
||||||
if (candidates.size() <= safeLimit) {
|
if (candidates.size() <= safeLimit) {
|
||||||
Collections.shuffle(candidates);
|
Collections.shuffle(candidates);
|
||||||
return candidates;
|
return candidates;
|
||||||
@@ -224,13 +216,19 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
@Override
|
@Override
|
||||||
public StudyReportsEntity getReportDetail(int id) throws NotFindEntitiesException {
|
public StudyReportsEntity getReportDetail(int id) throws NotFindEntitiesException {
|
||||||
return Optional.ofNullable(studyReportsMapper.selectById(id))
|
return Optional.ofNullable(studyReportsMapper.selectById(id))
|
||||||
.orElseThrow(() -> new NotFindEntitiesException("学习报告[" + id + "]不存在"));
|
.orElseThrow(() -> {
|
||||||
|
log.warn("学习报告[{}]不存在", id);
|
||||||
|
return new NotFindEntitiesException("这份学习报告不存在或已被删除");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StudyReportFragmentsEntity getFragmentDetail(int id) throws NotFindEntitiesException {
|
public StudyReportFragmentsEntity getFragmentDetail(int id) throws NotFindEntitiesException {
|
||||||
return Optional.ofNullable(studyReportFragmentsMapper.selectById(id))
|
return Optional.ofNullable(studyReportFragmentsMapper.selectById(id))
|
||||||
.orElseThrow(() -> new NotFindEntitiesException("学习残片[" + id + "]不存在"));
|
.orElseThrow(() -> {
|
||||||
|
log.warn("学习残片[{}]不存在", id);
|
||||||
|
return new NotFindEntitiesException("这条学习残片不存在或已被删除");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -321,7 +319,8 @@ public class ReviewServiceImpl implements ReviewService {
|
|||||||
private void ensureTaskExists(String taskNum) throws NotFindEntitiesException {
|
private void ensureTaskExists(String taskNum) throws NotFindEntitiesException {
|
||||||
if (!StringUtils.hasText(taskNum) || !tasksMapper.exists(
|
if (!StringUtils.hasText(taskNum) || !tasksMapper.exists(
|
||||||
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum))) {
|
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum))) {
|
||||||
throw new NotFindEntitiesException("任务[" + taskNum + "]不存在");
|
log.warn("任务[{}]不存在", taskNum);
|
||||||
|
throw new NotFindEntitiesException("这个任务不存在或已被删除");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+22
-16
@@ -36,7 +36,6 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
|||||||
private final ReviewRecallRecordMapper recallRecordMapper;
|
private final ReviewRecallRecordMapper recallRecordMapper;
|
||||||
private final TasksMapper tasksMapper;
|
private final TasksMapper tasksMapper;
|
||||||
private final StudyReportsMapper studyReportsMapper;
|
private final StudyReportsMapper studyReportsMapper;
|
||||||
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
|
|
||||||
private final TaskApplicationMapper taskApplicationMapper;
|
private final TaskApplicationMapper taskApplicationMapper;
|
||||||
private final StudySessionsMapper studySessionsMapper;
|
private final StudySessionsMapper studySessionsMapper;
|
||||||
|
|
||||||
@@ -86,7 +85,8 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
|||||||
ensureTaskExists(taskNum);
|
ensureTaskExists(taskNum);
|
||||||
ReviewStandardMindMapEntity existing = queryByTaskNum(taskNum);
|
ReviewStandardMindMapEntity existing = queryByTaskNum(taskNum);
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
throw new NotFindEntitiesException("标准思维导图尚不存在,无法增量更新");
|
log.warn("任务[{}]标准思维导图尚不存在,无法增量更新", taskNum);
|
||||||
|
throw new NotFindEntitiesException("还没有生成过标准思维导图,请先完整生成一次哦");
|
||||||
}
|
}
|
||||||
// 防并发生成
|
// 防并发生成
|
||||||
AtomicBoolean lock = generatingTasks.computeIfAbsent(taskNum, k -> new AtomicBoolean(false));
|
AtomicBoolean lock = generatingTasks.computeIfAbsent(taskNum, k -> new AtomicBoolean(false));
|
||||||
@@ -201,7 +201,8 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
|||||||
try {
|
try {
|
||||||
resultJson = objectMapper.writeValueAsString(result);
|
resultJson = objectMapper.writeValueAsString(result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new OperationFailedException("对比结果序列化失败");
|
log.error("任务[{}]对比结果序列化失败", taskNum, e);
|
||||||
|
throw new OperationFailedException("对比结果解析失败了,请稍后再试");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 保存回忆记录
|
// 5. 保存回忆记录
|
||||||
@@ -405,7 +406,10 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
|||||||
@Override
|
@Override
|
||||||
public ReviewRecallRecordEntity getRecallRecord(Integer recordId) throws NotFindEntitiesException {
|
public ReviewRecallRecordEntity getRecallRecord(Integer recordId) throws NotFindEntitiesException {
|
||||||
return Optional.ofNullable(recallRecordMapper.selectById(recordId))
|
return Optional.ofNullable(recallRecordMapper.selectById(recordId))
|
||||||
.orElseThrow(() -> new NotFindEntitiesException("回忆记录[" + recordId + "]不存在"));
|
.orElseThrow(() -> {
|
||||||
|
log.warn("回忆记录[{}]不存在", recordId);
|
||||||
|
return new NotFindEntitiesException("这条回忆记录不存在或已被删除");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ 内部方法 ============
|
// ============ 内部方法 ============
|
||||||
@@ -415,7 +419,8 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
|||||||
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum).last("LIMIT 1"));
|
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum).last("LIMIT 1"));
|
||||||
|
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
throw new OperationFailedException("任务[" + taskNum + "]不存在");
|
log.warn("任务[{}]不存在,无法生成思维导图", taskNum);
|
||||||
|
throw new OperationFailedException("这个任务不存在或已被删除");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 收集学习数据
|
// 收集学习数据
|
||||||
@@ -428,14 +433,12 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
|||||||
List<StudyReportsEntity> reports = sessionNums.isEmpty() ? List.of()
|
List<StudyReportsEntity> reports = sessionNums.isEmpty() ? List.of()
|
||||||
: studyReportsMapper.selectList(Wrappers.<StudyReportsEntity>lambdaQuery()
|
: studyReportsMapper.selectList(Wrappers.<StudyReportsEntity>lambdaQuery()
|
||||||
.in(StudyReportsEntity::getSessionNum, sessionNums));
|
.in(StudyReportsEntity::getSessionNum, sessionNums));
|
||||||
List<StudyReportFragmentsEntity> fragments = sessionNums.isEmpty() ? List.of()
|
|
||||||
: studyReportFragmentsMapper.selectList(Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
|
||||||
.in(StudyReportFragmentsEntity::getSessionNum, sessionNums));
|
|
||||||
List<TaskApplicationEntity> applications = taskApplicationMapper.selectList(
|
List<TaskApplicationEntity> applications = taskApplicationMapper.selectList(
|
||||||
Wrappers.<TaskApplicationEntity>lambdaQuery().eq(TaskApplicationEntity::getTaskNum, taskNum));
|
Wrappers.<TaskApplicationEntity>lambdaQuery().eq(TaskApplicationEntity::getTaskNum, taskNum));
|
||||||
|
|
||||||
if (reports.isEmpty() && fragments.isEmpty()) {
|
if (reports.isEmpty()) {
|
||||||
throw new OperationFailedException("任务[" + taskNum + "]没有学习报告或残片,无法生成思维导图");
|
log.warn("任务[{}]没有学习报告,无法生成思维导图", taskNum);
|
||||||
|
throw new OperationFailedException("这个任务还没开始学习哦,学习后产生学习报告后再来吧");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 优先选 AI 客户端(非 BUILTIN),其次内置生成器
|
// 优先选 AI 客户端(非 BUILTIN),其次内置生成器
|
||||||
@@ -445,10 +448,11 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
|||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
throw new OperationFailedException("没有可用的思维导图生成器");
|
log.warn("任务[{}]没有可用的思维导图生成器", taskNum);
|
||||||
|
throw new OperationFailedException("思维导图暂时生成不了,请稍后再试");
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<MindMapNode> optRoot = client.generate(task, reports, fragments, applications, null);
|
Optional<MindMapNode> optRoot = client.generate(task, reports, applications, null);
|
||||||
// AI 生成失败时尝试降级到内置生成器
|
// AI 生成失败时尝试降级到内置生成器
|
||||||
if (optRoot.isEmpty() && !"BUILTIN".equals(client.generatorName())) {
|
if (optRoot.isEmpty() && !"BUILTIN".equals(client.generatorName())) {
|
||||||
log.info("AI 思维导图生成失败,降级到内置生成器");
|
log.info("AI 思维导图生成失败,降级到内置生成器");
|
||||||
@@ -456,11 +460,12 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
|||||||
.filter(c -> "BUILTIN".equals(c.generatorName()) && c.isAvailable())
|
.filter(c -> "BUILTIN".equals(c.generatorName()) && c.isAvailable())
|
||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
if (fallback != null) {
|
if (fallback != null) {
|
||||||
optRoot = fallback.generate(task, reports, fragments, applications, null);
|
optRoot = fallback.generate(task, reports, applications, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (optRoot.isEmpty()) {
|
if (optRoot.isEmpty()) {
|
||||||
throw new OperationFailedException("思维导图生成失败");
|
log.warn("任务[{}]思维导图生成失败,已尝试全部生成器", taskNum);
|
||||||
|
throw new OperationFailedException("思维导图生成失败了,请稍后再试");
|
||||||
}
|
}
|
||||||
|
|
||||||
MindMapNode root = optRoot.get();
|
MindMapNode root = optRoot.get();
|
||||||
@@ -483,7 +488,7 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
|||||||
entity.setGenerator(client.generatorName());
|
entity.setGenerator(client.generatorName());
|
||||||
entity.setGeneratorVersion("1.0");
|
entity.setGeneratorVersion("1.0");
|
||||||
entity.setSourceReportCount(reports.size());
|
entity.setSourceReportCount(reports.size());
|
||||||
entity.setSourceFragmentCount(fragments.size());
|
entity.setSourceFragmentCount(0);
|
||||||
entity.setGeneratedTime(LocalDateTime.now());
|
entity.setGeneratedTime(LocalDateTime.now());
|
||||||
|
|
||||||
if (create) {
|
if (create) {
|
||||||
@@ -497,7 +502,8 @@ public class StandardMindMapServiceImpl implements StandardMindMapService {
|
|||||||
private void ensureTaskExists(String taskNum) throws NotFindEntitiesException {
|
private void ensureTaskExists(String taskNum) throws NotFindEntitiesException {
|
||||||
if (!StringUtils.hasText(taskNum) || !tasksMapper.exists(
|
if (!StringUtils.hasText(taskNum) || !tasksMapper.exists(
|
||||||
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum))) {
|
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum))) {
|
||||||
throw new NotFindEntitiesException("任务[" + taskNum + "]不存在");
|
log.warn("任务[{}]不存在", taskNum);
|
||||||
|
throw new NotFindEntitiesException("这个任务不存在或已被删除");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -8,11 +8,13 @@ import com.guo.learningprogresstracker.mapper.StudyExpectationsMapper;
|
|||||||
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
||||||
import com.guo.learningprogresstracker.service.StudyExpectationsService;
|
import com.guo.learningprogresstracker.service.StudyExpectationsService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学习预期服务实现
|
* 学习预期服务实现
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class StudyExpectationsServiceImpl implements StudyExpectationsService {
|
public class StudyExpectationsServiceImpl implements StudyExpectationsService {
|
||||||
@@ -26,7 +28,8 @@ public class StudyExpectationsServiceImpl implements StudyExpectationsService {
|
|||||||
Wrappers.<StudySessionsEntity>lambdaQuery()
|
Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||||
.eq(StudySessionsEntity::getSessionNum, sessionNum));
|
.eq(StudySessionsEntity::getSessionNum, sessionNum));
|
||||||
if (!sessionExists) {
|
if (!sessionExists) {
|
||||||
throw new ErrorParameterException("学习会话[" + sessionNum + "]不存在");
|
log.warn("学习会话[{}]不存在", sessionNum);
|
||||||
|
throw new ErrorParameterException("这次学习会话不存在或已结束");
|
||||||
}
|
}
|
||||||
|
|
||||||
StudyExpectationsEntity existing = getBySessionNum(sessionNum);
|
StudyExpectationsEntity existing = getBySessionNum(sessionNum);
|
||||||
|
|||||||
+6
-2
@@ -12,6 +12,7 @@ import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
|||||||
import com.guo.learningprogresstracker.service.StudyReportFragmentsService;
|
import com.guo.learningprogresstracker.service.StudyReportFragmentsService;
|
||||||
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
|
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 针对表【study_report_fragments(记录学习过程中的学习内容报告残片)】的数据库操作Service实现
|
* 针对表【study_report_fragments(记录学习过程中的学习内容报告残片)】的数据库操作Service实现
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFragmentsMapper, StudyReportFragmentsEntity>
|
public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFragmentsMapper, StudyReportFragmentsEntity>
|
||||||
@@ -35,7 +37,8 @@ public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFrag
|
|||||||
Wrappers.lambdaQuery(StudySessionsEntity.class)
|
Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, entity.getSessionNum()));
|
.eq(StudySessionsEntity::getSessionNum, entity.getSessionNum()));
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
throw new NotFindEntitiesException(String.format("未能找到学习会话sessionNum[%s]", entity.getSessionNum()));
|
log.warn("未能找到学习会话sessionNum[{}]", entity.getSessionNum());
|
||||||
|
throw new NotFindEntitiesException("这次学习会话不存在或已结束");
|
||||||
}
|
}
|
||||||
this.save(entity);
|
this.save(entity);
|
||||||
}
|
}
|
||||||
@@ -44,7 +47,8 @@ public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFrag
|
|||||||
public void updateFragments(Integer id, UpdateFragmentsRequest request) throws NotFindEntitiesException {
|
public void updateFragments(Integer id, UpdateFragmentsRequest request) throws NotFindEntitiesException {
|
||||||
StudyReportFragmentsEntity existing = this.getById(id);
|
StudyReportFragmentsEntity existing = this.getById(id);
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
throw new NotFindEntitiesException(String.format("未能找到学习残片id[%d]", id));
|
log.warn("未能找到学习残片id[{}]", id);
|
||||||
|
throw new NotFindEntitiesException("这条学习残片不存在或已被删除");
|
||||||
}
|
}
|
||||||
StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request);
|
StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request);
|
||||||
entity.setId(id);
|
entity.setId(id);
|
||||||
|
|||||||
+28
-12
@@ -50,7 +50,10 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
public StudySessionResponse startOrContinueStudySession(String taskNum) throws NotFindEntitiesException, ServiceException {
|
public StudySessionResponse startOrContinueStudySession(String taskNum) throws NotFindEntitiesException, ServiceException {
|
||||||
TaskEntity taskEntity = tasksServiceImpl.getOneOpt(
|
TaskEntity taskEntity = tasksServiceImpl.getOneOpt(
|
||||||
Wrappers.lambdaQuery(TaskEntity.class).eq(TaskEntity::getTaskNum, taskNum))
|
Wrappers.lambdaQuery(TaskEntity.class).eq(TaskEntity::getTaskNum, taskNum))
|
||||||
.orElseThrow(() -> new NotFindEntitiesException(String.format("[%s]不存在", taskNum)));
|
.orElseThrow(() -> {
|
||||||
|
log.warn("[{}]不存在", taskNum);
|
||||||
|
return new NotFindEntitiesException("这个任务不存在或已被删除");
|
||||||
|
});
|
||||||
|
|
||||||
StudySessionsEntity session = this.getOneOpt(Wrappers.<StudySessionsEntity>lambdaQuery()
|
StudySessionsEntity session = this.getOneOpt(Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||||
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
||||||
@@ -88,10 +91,10 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
public void pauseStudySession(String sessionNum, LocalDateTime endTime) throws ErrorParameterException, ServiceException {
|
public void pauseStudySession(String sessionNum, LocalDateTime endTime) throws ErrorParameterException, ServiceException {
|
||||||
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
.orElseThrow(() -> sessionNotFound(sessionNum));
|
||||||
if (StudySessionStateEnum.PAUSED.name().equals(studySessionsEntity.getSessionState())) {
|
if (StudySessionStateEnum.PAUSED.name().equals(studySessionsEntity.getSessionState())) {
|
||||||
log.error("会话[" + studySessionsEntity.getSessionNum() + "]重复暂停");
|
log.error("会话[" + studySessionsEntity.getSessionNum() + "]重复暂停");
|
||||||
throw new ErrorParameterException("会话[" + sessionNum + "]已经暂停,请勿重复暂停!");
|
throw new ErrorParameterException("这次学习会话已经暂停了,不用重复暂停哦");
|
||||||
}
|
}
|
||||||
studySessionsEntity.calculatePointerPosition();
|
studySessionsEntity.calculatePointerPosition();
|
||||||
studySessionsEntity.pausedStudySession(endTime);
|
studySessionsEntity.pausedStudySession(endTime);
|
||||||
@@ -104,7 +107,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
public String endedStudySession(String sessionNum, String content) throws ErrorParameterException {
|
public String endedStudySession(String sessionNum, String content) throws ErrorParameterException {
|
||||||
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
.orElseThrow(() -> sessionNotFound(sessionNum));
|
||||||
boolean wasOngoing = StudySessionStateEnum.ONGOING.name().equals(studySessionsEntity.getSessionState());
|
boolean wasOngoing = StudySessionStateEnum.ONGOING.name().equals(studySessionsEntity.getSessionState());
|
||||||
studySessionsEntity.endedStudySession();
|
studySessionsEntity.endedStudySession();
|
||||||
this.updateById(studySessionsEntity);
|
this.updateById(studySessionsEntity);
|
||||||
@@ -122,9 +125,12 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
public StudySessionResponse getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException {
|
public StudySessionResponse getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException {
|
||||||
TaskEntity task = tasksServiceImpl.getOneOpt(Wrappers.lambdaQuery(TaskEntity.class)
|
TaskEntity task = tasksServiceImpl.getOneOpt(Wrappers.lambdaQuery(TaskEntity.class)
|
||||||
.eq(TaskEntity::getTaskNum, taskNum))
|
.eq(TaskEntity::getTaskNum, taskNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("任务[" + taskNum + "]不存在"));
|
.orElseThrow(() -> taskNotFound(taskNum));
|
||||||
StudySessionsDto dto = Optional.ofNullable(studyReportsMapper.getNotEndedStudySessionDtoByTaskNum(taskNum))
|
StudySessionsDto dto = Optional.ofNullable(studyReportsMapper.getNotEndedStudySessionDtoByTaskNum(taskNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("任务[" + taskNum + "]不存在进行中或暂停中的会话"));
|
.orElseThrow(() -> {
|
||||||
|
log.warn("任务[{}]不存在进行中或暂停中的会话", taskNum);
|
||||||
|
return new ErrorParameterException("这个任务当前没有进行中或已暂停的学习会话");
|
||||||
|
});
|
||||||
return StudySessionConvert.MAPPER.toStudySessionResponse(dto);
|
return StudySessionConvert.MAPPER.toStudySessionResponse(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +142,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
.eq(StudyReportFragmentsEntity::getSessionNum, sessionNum))
|
.eq(StudyReportFragmentsEntity::getSessionNum, sessionNum))
|
||||||
.stream().map(StudyReportFragmentsEntity::getContent).collect(Collectors.toCollection(ArrayList::new));
|
.stream().map(StudyReportFragmentsEntity::getContent).collect(Collectors.toCollection(ArrayList::new));
|
||||||
} else {
|
} else {
|
||||||
throw new ErrorParameterException("会话[" + sessionNum + "]不存在");
|
throw sessionNotFound(sessionNum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,13 +151,13 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
public void continueStudySession(String sessionNum) throws ErrorParameterException, ServiceException {
|
public void continueStudySession(String sessionNum) throws ErrorParameterException, ServiceException {
|
||||||
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
.orElseThrow(() -> sessionNotFound(sessionNum));
|
||||||
if (StudySessionStateEnum.ONGOING.name().equals(studySessionsEntity.getSessionState())) {
|
if (StudySessionStateEnum.ONGOING.name().equals(studySessionsEntity.getSessionState())) {
|
||||||
log.error("会话[" + studySessionsEntity.getSessionNum() + "]重复开始");
|
log.error("会话[" + studySessionsEntity.getSessionNum() + "]重复开始");
|
||||||
throw new ErrorParameterException("会话[" + sessionNum + "]已经开始,请勿重复开始!");
|
throw new ErrorParameterException("这次学习会话已经开始了,不用重复开始哦");
|
||||||
} else if (StudySessionStateEnum.ENDED.name().equals(studySessionsEntity.getSessionState())) {
|
} else if (StudySessionStateEnum.ENDED.name().equals(studySessionsEntity.getSessionState())) {
|
||||||
log.error("会话[" + studySessionsEntity.getSessionNum() + "]处于结束状态,不可开始该会话!");
|
log.error("会话[" + studySessionsEntity.getSessionNum() + "]处于结束状态,不可开始该会话!");
|
||||||
throw new ErrorParameterException("会话[" + sessionNum + "]处于结束状态,不可开始该会话!");
|
throw new ErrorParameterException("这次学习会话已经结束,无法再次开始");
|
||||||
}
|
}
|
||||||
studySessionsEntity.continueStudySession();
|
studySessionsEntity.continueStudySession();
|
||||||
this.updateById(studySessionsEntity);
|
this.updateById(studySessionsEntity);
|
||||||
@@ -163,7 +169,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
public StudySessionResponse getStudySessionBySessionNum(String sessionNum) throws ErrorParameterException {
|
public StudySessionResponse getStudySessionBySessionNum(String sessionNum) throws ErrorParameterException {
|
||||||
StudySessionsEntity session = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
StudySessionsEntity session = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
.orElseThrow(() -> sessionNotFound(sessionNum));
|
||||||
return StudySessionConvert.MAPPER.toStudySessionResponse(session);
|
return StudySessionConvert.MAPPER.toStudySessionResponse(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +180,7 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
public String generateReportDraft(String sessionNum) throws ErrorParameterException {
|
public String generateReportDraft(String sessionNum) throws ErrorParameterException {
|
||||||
StudySessionsEntity session = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
StudySessionsEntity session = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
.eq(StudySessionsEntity::getSessionNum, sessionNum))
|
||||||
.orElseThrow(() -> new ErrorParameterException("会话[" + sessionNum + "]不存在"));
|
.orElseThrow(() -> sessionNotFound(sessionNum));
|
||||||
|
|
||||||
ArrayList<String> fragments = getAllFragments(sessionNum);
|
ArrayList<String> fragments = getAllFragments(sessionNum);
|
||||||
if (fragments.isEmpty()) {
|
if (fragments.isEmpty()) {
|
||||||
@@ -262,4 +268,14 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ErrorParameterException sessionNotFound(String sessionNum) {
|
||||||
|
log.warn("会话[{}]不存在", sessionNum);
|
||||||
|
return new ErrorParameterException("这次学习会话不存在或已结束");
|
||||||
|
}
|
||||||
|
|
||||||
|
private ErrorParameterException taskNotFound(String taskNum) {
|
||||||
|
log.warn("任务[{}]不存在", taskNum);
|
||||||
|
return new ErrorParameterException("这个任务不存在或已被删除");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
|||||||
|
|
||||||
if (this.exists(Wrappers.lambdaQuery(TaskEntity.class)
|
if (this.exists(Wrappers.lambdaQuery(TaskEntity.class)
|
||||||
.eq(TaskEntity::getTaskName, task.getTaskName()))) {
|
.eq(TaskEntity::getTaskName, task.getTaskName()))) {
|
||||||
throw new ErrorParameterException(String.format("任务名[%s]重复", task.getTaskName()));
|
log.warn("任务名[{}]重复", task.getTaskName());
|
||||||
|
throw new ErrorParameterException("已经有同名任务了,换个任务名称吧");
|
||||||
}
|
}
|
||||||
|
|
||||||
task.setTaskNum(GenerateNumTool.generateNum("TASK"));
|
task.setTaskNum(GenerateNumTool.generateNum("TASK"));
|
||||||
@@ -132,7 +133,10 @@ public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
|||||||
@Override
|
@Override
|
||||||
public TaskApplicationEntity updateApplication(Integer id, UpdateTaskApplicationRequest request) throws NotFindEntitiesException {
|
public TaskApplicationEntity updateApplication(Integer id, UpdateTaskApplicationRequest request) throws NotFindEntitiesException {
|
||||||
TaskApplicationEntity existing = Optional.ofNullable(taskApplicationMapper.selectById(id))
|
TaskApplicationEntity existing = Optional.ofNullable(taskApplicationMapper.selectById(id))
|
||||||
.orElseThrow(() -> new NotFindEntitiesException("应用场景[" + id + "]不存在"));
|
.orElseThrow(() -> {
|
||||||
|
log.warn("应用场景[{}]不存在", id);
|
||||||
|
return new NotFindEntitiesException("这个应用场景不存在或已被删除");
|
||||||
|
});
|
||||||
existing.setTitle(request.getTitle());
|
existing.setTitle(request.getTitle());
|
||||||
existing.setDescription(request.getDescription());
|
existing.setDescription(request.getDescription());
|
||||||
existing.setResourceUrl(request.getResourceUrl());
|
existing.setResourceUrl(request.getResourceUrl());
|
||||||
@@ -144,14 +148,18 @@ public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
|||||||
@Override
|
@Override
|
||||||
public void deleteApplication(Integer id) throws NotFindEntitiesException {
|
public void deleteApplication(Integer id) throws NotFindEntitiesException {
|
||||||
TaskApplicationEntity existing = Optional.ofNullable(taskApplicationMapper.selectById(id))
|
TaskApplicationEntity existing = Optional.ofNullable(taskApplicationMapper.selectById(id))
|
||||||
.orElseThrow(() -> new NotFindEntitiesException("应用场景[" + id + "]不存在"));
|
.orElseThrow(() -> {
|
||||||
|
log.warn("应用场景[{}]不存在", id);
|
||||||
|
return new NotFindEntitiesException("这个应用场景不存在或已被删除");
|
||||||
|
});
|
||||||
taskApplicationMapper.deleteById(existing.getId());
|
taskApplicationMapper.deleteById(existing.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureTaskExists(String taskNum) throws NotFindEntitiesException {
|
private void ensureTaskExists(String taskNum) throws NotFindEntitiesException {
|
||||||
if (!StringUtils.hasText(taskNum) || !tasksMapper.exists(
|
if (!StringUtils.hasText(taskNum) || !tasksMapper.exists(
|
||||||
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum))) {
|
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum))) {
|
||||||
throw new NotFindEntitiesException("任务[" + taskNum + "]不存在");
|
log.warn("任务[{}]不存在", taskNum);
|
||||||
|
throw new NotFindEntitiesException("这个任务不存在或已被删除");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-14
@@ -62,13 +62,13 @@ class ReviewServiceImplTest {
|
|||||||
void getReviewFeed_smartMode_prefersLowRecallRatioContent() {
|
void getReviewFeed_smartMode_prefersLowRecallRatioContent() {
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
StudyReportsEntity oldLowMastery = new StudyReportsEntity();
|
StudyReportFragmentsEntity oldLowMastery = new StudyReportFragmentsEntity();
|
||||||
oldLowMastery.setId(1);
|
oldLowMastery.setId(1);
|
||||||
oldLowMastery.setSessionNum("S_LOW");
|
oldLowMastery.setSessionNum("S_LOW");
|
||||||
oldLowMastery.setContent("很久没复习且掌握度低");
|
oldLowMastery.setContent("很久没复习且掌握度低");
|
||||||
oldLowMastery.setCreatedTime(now.minusDays(60));
|
oldLowMastery.setCreatedTime(now.minusDays(60));
|
||||||
|
|
||||||
StudyReportsEntity freshHighMastery = new StudyReportsEntity();
|
StudyReportFragmentsEntity freshHighMastery = new StudyReportFragmentsEntity();
|
||||||
freshHighMastery.setId(2);
|
freshHighMastery.setId(2);
|
||||||
freshHighMastery.setSessionNum("S_HIGH");
|
freshHighMastery.setSessionNum("S_HIGH");
|
||||||
freshHighMastery.setContent("刚学完且掌握度高");
|
freshHighMastery.setContent("刚学完且掌握度高");
|
||||||
@@ -93,8 +93,7 @@ class ReviewServiceImplTest {
|
|||||||
highRatioRecord.setRecallRatio(1.0);
|
highRatioRecord.setRecallRatio(1.0);
|
||||||
highRatioRecord.setCreatedTime(now);
|
highRatioRecord.setCreatedTime(now);
|
||||||
|
|
||||||
when(studyReportsMapper.selectList(any())).thenReturn(List.of(oldLowMastery, freshHighMastery));
|
when(studyReportFragmentsMapper.selectList(any())).thenReturn(List.of(oldLowMastery, freshHighMastery));
|
||||||
when(studyReportFragmentsMapper.selectList(any())).thenReturn(List.of());
|
|
||||||
when(studySessionsMapper.selectList(any())).thenReturn(List.of(sessionLow, sessionHigh));
|
when(studySessionsMapper.selectList(any())).thenReturn(List.of(sessionLow, sessionHigh));
|
||||||
when(tasksMapper.selectList(any())).thenReturn(List.of(taskLow, taskHigh));
|
when(tasksMapper.selectList(any())).thenReturn(List.of(taskLow, taskHigh));
|
||||||
when(reviewRecallRecordMapper.selectList(any())).thenReturn(List.of(highRatioRecord));
|
when(reviewRecallRecordMapper.selectList(any())).thenReturn(List.of(highRatioRecord));
|
||||||
@@ -116,15 +115,9 @@ class ReviewServiceImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getReviewFeed_shouldApplyFinalLimitAfterMerge() {
|
void getReviewFeed_shouldReturnFragmentsOnly() {
|
||||||
StudyReportsEntity report = new StudyReportsEntity();
|
|
||||||
report.setId(1);
|
|
||||||
report.setSessionNum("S1");
|
|
||||||
report.setContent("report");
|
|
||||||
report.setCreatedTime(LocalDateTime.now());
|
|
||||||
|
|
||||||
StudyReportFragmentsEntity fragment = new StudyReportFragmentsEntity();
|
StudyReportFragmentsEntity fragment = new StudyReportFragmentsEntity();
|
||||||
fragment.setId(2);
|
fragment.setId(1);
|
||||||
fragment.setSessionNum("S1");
|
fragment.setSessionNum("S1");
|
||||||
fragment.setContent("fragment");
|
fragment.setContent("fragment");
|
||||||
fragment.setCreatedTime(LocalDateTime.now().minusMinutes(1));
|
fragment.setCreatedTime(LocalDateTime.now().minusMinutes(1));
|
||||||
@@ -137,7 +130,6 @@ class ReviewServiceImplTest {
|
|||||||
task.setTaskNum("T1");
|
task.setTaskNum("T1");
|
||||||
task.setTaskName("Task");
|
task.setTaskName("Task");
|
||||||
|
|
||||||
when(studyReportsMapper.selectList(any())).thenReturn(List.of(report));
|
|
||||||
when(studyReportFragmentsMapper.selectList(any())).thenReturn(List.of(fragment));
|
when(studyReportFragmentsMapper.selectList(any())).thenReturn(List.of(fragment));
|
||||||
when(studySessionsMapper.selectList(any())).thenReturn(List.of(session));
|
when(studySessionsMapper.selectList(any())).thenReturn(List.of(session));
|
||||||
when(tasksMapper.selectList(any())).thenReturn(List.of(task));
|
when(tasksMapper.selectList(any())).thenReturn(List.of(task));
|
||||||
@@ -145,7 +137,7 @@ class ReviewServiceImplTest {
|
|||||||
List<ReviewFeedItem> items = reviewService.getReviewFeed(1, "recent");
|
List<ReviewFeedItem> items = reviewService.getReviewFeed(1, "recent");
|
||||||
|
|
||||||
assertEquals(1, items.size());
|
assertEquals(1, items.size());
|
||||||
assertEquals("REPORT", items.get(0).getSourceType());
|
assertEquals("FRAGMENT", items.get(0).getSourceType());
|
||||||
assertEquals("Task", items.get(0).getTaskName());
|
assertEquals("Task", items.get(0).getTaskName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -36,8 +36,6 @@ class StandardMindMapServiceImplTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private StudyReportsMapper studyReportsMapper;
|
private StudyReportsMapper studyReportsMapper;
|
||||||
@Mock
|
@Mock
|
||||||
private StudyReportFragmentsMapper studyReportFragmentsMapper;
|
|
||||||
@Mock
|
|
||||||
private TaskApplicationMapper taskApplicationMapper;
|
private TaskApplicationMapper taskApplicationMapper;
|
||||||
@Mock
|
@Mock
|
||||||
private StudySessionsMapper studySessionsMapper;
|
private StudySessionsMapper studySessionsMapper;
|
||||||
@@ -189,7 +187,7 @@ class StandardMindMapServiceImplTest {
|
|||||||
private StandardMindMapServiceImpl createService() {
|
private StandardMindMapServiceImpl createService() {
|
||||||
StandardMindMapServiceImpl s = new StandardMindMapServiceImpl(
|
StandardMindMapServiceImpl s = new StandardMindMapServiceImpl(
|
||||||
standardMindMapMapper, recallRecordMapper,
|
standardMindMapMapper, recallRecordMapper,
|
||||||
tasksMapper, studyReportsMapper, studyReportFragmentsMapper,
|
tasksMapper, studyReportsMapper,
|
||||||
taskApplicationMapper, studySessionsMapper,
|
taskApplicationMapper, studySessionsMapper,
|
||||||
List.of(mockAiClient), objectMapper, aiServiceClient);
|
List.of(mockAiClient), objectMapper, aiServiceClient);
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
Reference in New Issue
Block a user