feat: 新增会话误操作结束接口

This commit is contained in:
2026-08-15 21:24:59 +08:00
parent 0413013f24
commit a6f684c8b7
7 changed files with 175 additions and 0 deletions
@@ -40,6 +40,11 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
public static final int WORK_DURATION = 25;
/**
* 误操作结束的确认语:用户必须输入完全一致的内容才能零数据关闭会话
*/
public static final String MISOPERATION_CONFIRMATION = "我误操作导致开启了本次学习";
private final TasksServiceImpl tasksServiceImpl;
private final StudyReportFragmentsServiceImpl studyReportFragmentsServiceImpl;
private final StudyReportFragmentsMapper studyReportFragmentsMapper;
@@ -120,6 +125,31 @@ public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, S
}
return null;
}
@Override
@Transactional
public void abortStudySession(String sessionNum, String confirmation) throws ErrorParameterException {
StudySessionsEntity studySessionsEntity = this.getOneOpt(Wrappers.lambdaQuery(StudySessionsEntity.class)
.eq(StudySessionsEntity::getSessionNum, sessionNum))
.orElseThrow(() -> sessionNotFound(sessionNum));
if (StudySessionStateEnum.ENDED.name().equals(studySessionsEntity.getSessionState())) {
log.warn("会话[{}]已结束,不能误操作结束", sessionNum);
throw new ErrorParameterException("这次学习会话已经结束,不能再误操作结束了");
}
if (!MISOPERATION_CONFIRMATION.equals(confirmation == null ? "" : confirmation.trim())) {
log.warn("会话[{}]误操作结束的确认语不正确", sessionNum);
throw new ErrorParameterException("确认语输入不正确,请核对后重新输入");
}
long fragmentCount = studyReportFragmentsMapper.selectCount(Wrappers.lambdaQuery(StudyReportFragmentsEntity.class)
.eq(StudyReportFragmentsEntity::getSessionNum, sessionNum));
if (fragmentCount > 0) {
log.warn("会话[{}]已产生{}条学习残片,不能误操作结束", sessionNum, fragmentCount);
throw new ErrorParameterException("这次学习已经产生了学习残片,不能按误操作结束了哦");
}
// 严格零数据:学习预期与会话本身一并删除,系统视角下会话从未发生
studyExpectationsService.deleteBySessionNum(sessionNum);
this.removeById(studySessionsEntity.getId());
log.info("会话[{}]误操作结束,未产生任何学习数据", sessionNum);
}
@Override
public StudySessionResponse getNotEndedStudySessionByTaskNum(String taskNum) throws ErrorParameterException {