feat(会话):新增活跃会话查询接口
StudySessionsServiceImpl.getActiveSession(excludeTaskNum): - 查询所有 ONGOING/PAUSED 状态的 session - 如果活跃会话属于 excludeTaskNum 则返回 null(同一任务继续) - 否则返回活跃会话的 StudySessionResponse Controller 新增 GET /study-sessions/active?excludeTaskNum= 用于前端页面恢复 + 阻止多任务同时开始
This commit is contained in:
@@ -130,4 +130,11 @@ public class StudySessionController {
|
|||||||
@RequestParam(required = false) String keyword) {
|
@RequestParam(required = false) String keyword) {
|
||||||
return CommonResult.success(studySessionsServiceImpl.getTaskReports(taskNum, page, size, keyword));
|
return CommonResult.success(studySessionsServiceImpl.getTaskReports(taskNum, page, size, keyword));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 查询当前是否有活跃会话(用于跨页面恢复 + 阻止多任务) */
|
||||||
|
@GetMapping("/active")
|
||||||
|
public CommonResult<StudySessionResponse> getActiveSession(
|
||||||
|
@RequestParam(required = false) String excludeTaskNum) {
|
||||||
|
return CommonResult.success(studySessionsServiceImpl.getActiveSession(excludeTaskNum));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,4 +33,6 @@ public interface StudySessionsService extends IService<StudySessionsEntity> {
|
|||||||
Page<StudyReportFragmentsEntity> getTaskFragments(String taskNum, int page, int size, String keyword);
|
Page<StudyReportFragmentsEntity> getTaskFragments(String taskNum, int page, int size, String keyword);
|
||||||
|
|
||||||
Page<StudyReportsEntity> getTaskReports(String taskNum, int page, int size, String keyword);
|
Page<StudyReportsEntity> getTaskReports(String taskNum, int page, int size, String keyword);
|
||||||
|
|
||||||
|
StudySessionResponse getActiveSession(String excludeTaskNum);
|
||||||
}
|
}
|
||||||
|
|||||||
+35
@@ -217,4 +217,39 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
|
|||||||
return studyReportsMapper.selectPage(pg, wrapper);
|
return studyReportsMapper.selectPage(pg, wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============ 活跃会话查询 ============
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当前用户是否有活跃会话(ONGOING 或 PAUSED)。
|
||||||
|
*
|
||||||
|
* @param excludeTaskNum 可选,排除指定任务(同一任务继续学习时不会视为冲突)
|
||||||
|
* @return 活跃会话响应;无活跃会话时返回 null
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public StudySessionResponse getActiveSession(String excludeTaskNum) {
|
||||||
|
var wrapper = Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||||
|
.in(StudySessionsEntity::getSessionState,
|
||||||
|
StudySessionStateEnum.ONGOING.name(),
|
||||||
|
StudySessionStateEnum.PAUSED.name())
|
||||||
|
.orderByDesc(StudySessionsEntity::getCreatedTime)
|
||||||
|
.last("LIMIT 1");
|
||||||
|
|
||||||
|
StudySessionsEntity session = this.getOne(wrapper);
|
||||||
|
if (session == null) return null;
|
||||||
|
|
||||||
|
// 如果活跃会话属于被排除的任务,视为无冲突
|
||||||
|
if (excludeTaskNum != null && excludeTaskNum.equals(session.getTaskNum())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskName = tasksServiceImpl.getOneOpt(
|
||||||
|
Wrappers.lambdaQuery(TaskEntity.class).eq(TaskEntity::getTaskNum, session.getTaskNum()))
|
||||||
|
.map(TaskEntity::getTaskName)
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
StudySessionResponse response = StudySessionConvert.MAPPER.toStudySessionResponse(session);
|
||||||
|
response.setTaskName(taskName);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user