b67cf238c2
- 迁移:study_expectations.session_num 改为 varchar 对齐会话编码
- StudyExpectationsEntity / Mapper / Service:每会话一条预期,重复创建覆盖
- StudySessionController:PUT/GET /{sessionNum}/expectation
- 移除空的 studySessionList 占位方法
53 lines
2.1 KiB
Java
53 lines
2.1 KiB
Java
package com.guo.learningprogresstracker.service.impl;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.guo.learningprogresstracker.entity.StudyExpectationsEntity;
|
|
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
|
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
|
import com.guo.learningprogresstracker.mapper.StudyExpectationsMapper;
|
|
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
|
import com.guo.learningprogresstracker.service.StudyExpectationsService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
/**
|
|
* 学习预期服务实现
|
|
*/
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
public class StudyExpectationsServiceImpl implements StudyExpectationsService {
|
|
|
|
private final StudyExpectationsMapper studyExpectationsMapper;
|
|
private final StudySessionsMapper studySessionsMapper;
|
|
|
|
@Override
|
|
public StudyExpectationsEntity upsertExpectation(String sessionNum, String description) throws ErrorParameterException {
|
|
boolean sessionExists = studySessionsMapper.exists(
|
|
Wrappers.<StudySessionsEntity>lambdaQuery()
|
|
.eq(StudySessionsEntity::getSessionNum, sessionNum));
|
|
if (!sessionExists) {
|
|
throw new ErrorParameterException("学习会话[" + sessionNum + "]不存在");
|
|
}
|
|
|
|
StudyExpectationsEntity existing = getBySessionNum(sessionNum);
|
|
if (existing == null) {
|
|
StudyExpectationsEntity entity = new StudyExpectationsEntity();
|
|
entity.setSessionNum(sessionNum);
|
|
entity.setDescription(description);
|
|
studyExpectationsMapper.insert(entity);
|
|
return entity;
|
|
}
|
|
existing.setDescription(description);
|
|
studyExpectationsMapper.updateById(existing);
|
|
return existing;
|
|
}
|
|
|
|
@Override
|
|
public StudyExpectationsEntity getBySessionNum(String sessionNum) {
|
|
return studyExpectationsMapper.selectOne(
|
|
Wrappers.<StudyExpectationsEntity>lambdaQuery()
|
|
.eq(StudyExpectationsEntity::getSessionNum, sessionNum)
|
|
.last("LIMIT 1"));
|
|
}
|
|
}
|