[xingyu.guo] fix: 统一Id为Num,在自己的业务领域中使用id,在非本身业务范畴的领域使用num
This commit is contained in:
@@ -5,6 +5,7 @@ import com.guo.learningprogresstracker.common.Ops;
|
|||||||
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
|
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
|
||||||
import com.guo.learningprogresstracker.entity.CommonResult;
|
import com.guo.learningprogresstracker.entity.CommonResult;
|
||||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||||
|
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||||
import com.guo.learningprogresstracker.service.TasksService;
|
import com.guo.learningprogresstracker.service.TasksService;
|
||||||
import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl;
|
import com.guo.learningprogresstracker.service.impl.StudySessionsServiceImpl;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@@ -71,10 +72,10 @@ public class TaskController {
|
|||||||
* 开始或继续一个【学习会话】
|
* 开始或继续一个【学习会话】
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{taskId}/studay-sessions/start-or-continue")
|
@GetMapping("/{taskNum}/studay-sessions/start-or-continue")
|
||||||
public CommonResult startOrContinueStudySession(@NotEmpty(message = "taskId不可为空")
|
public CommonResult startOrContinueStudySession(@NotEmpty(message = "taskId不可为空")
|
||||||
@PathVariable String taskId) {
|
@PathVariable String taskNum) throws NotFindEntitiesException {
|
||||||
StudySessionResponce responce = studySessionsServiceImpl.startOrContinueStudySession(taskId);
|
StudySessionResponce responce = studySessionsServiceImpl.startOrContinueStudySession(taskNum);
|
||||||
return CommonResult.success(responce);
|
return CommonResult.success(responce);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,17 @@ import java.time.LocalDateTime;
|
|||||||
@Data
|
@Data
|
||||||
public class StudySessionsEntity extends BaseEntity implements Serializable {
|
public class StudySessionsEntity extends BaseEntity implements Serializable {
|
||||||
|
|
||||||
@TableId(value = "session_id", type = IdType.AUTO)
|
@TableId(type = IdType.AUTO)
|
||||||
private Integer sessionId;
|
private Integer id;
|
||||||
|
|
||||||
|
@TableField(value = "session_num")
|
||||||
|
private String sessionNum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@TableField(value = "task_id")
|
@TableField(value = "task_num")
|
||||||
private Integer taskId;
|
private String taskNum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学习开始时间
|
* 学习开始时间
|
||||||
|
|||||||
+13
-3
@@ -4,11 +4,14 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
|
import com.guo.learningprogresstracker.dto.response.StudySessionResponce;
|
||||||
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
||||||
|
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||||
import com.guo.learningprogresstracker.enums.StudySessionStateEnum;
|
import com.guo.learningprogresstracker.enums.StudySessionStateEnum;
|
||||||
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||||
|
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||||
import com.guo.learningprogresstracker.mapStruct.StudySessionConvert;
|
import com.guo.learningprogresstracker.mapStruct.StudySessionConvert;
|
||||||
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
||||||
import com.guo.learningprogresstracker.service.StudySessionsService;
|
import com.guo.learningprogresstracker.service.StudySessionsService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -19,18 +22,25 @@ import java.util.Optional;
|
|||||||
* @createDate 2024-06-09 15:28:48
|
* @createDate 2024-06-09 15:28:48
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, StudySessionsEntity>
|
public class StudySessionsServiceImpl extends ServiceImpl<StudySessionsMapper, StudySessionsEntity>
|
||||||
implements StudySessionsService{
|
implements StudySessionsService{
|
||||||
|
|
||||||
public StudySessionResponce startOrContinueStudySession(String taskId) {
|
private final TasksServiceImpl tasksServiceImpl;
|
||||||
// 任务id下是否存在非”已结束“的学习会话
|
|
||||||
|
public StudySessionResponce startOrContinueStudySession(String taskNum) throws NotFindEntitiesException {
|
||||||
|
// taskNum是否存在
|
||||||
|
tasksServiceImpl.getOneOpt(Wrappers.lambdaQuery(TaskEntity.class).eq(TaskEntity::getTaskNum, taskNum))
|
||||||
|
.orElseThrow(() -> new NotFindEntitiesException(String.format("[%s]不存在",taskNum)));
|
||||||
|
// 任务taskNum下是否存在非"已结束"的学习会话
|
||||||
Optional<StudySessionsEntity> oneOpt = this.getOneOpt(Wrappers.<StudySessionsEntity>lambdaQuery()
|
Optional<StudySessionsEntity> oneOpt = this.getOneOpt(Wrappers.<StudySessionsEntity>lambdaQuery()
|
||||||
.eq(StudySessionsEntity::getTaskId, taskId)
|
.eq(StudySessionsEntity::getTaskNum, taskNum)
|
||||||
.ne(StudySessionsEntity::getSessionState, StudySessionStateEnum.ENDED.name()));
|
.ne(StudySessionsEntity::getSessionState, StudySessionStateEnum.ENDED.name()));
|
||||||
// 有则返回该未完成会话,否则创建新的会话
|
// 有则返回该未完成会话,否则创建新的会话
|
||||||
if (oneOpt.isEmpty()) {
|
if (oneOpt.isEmpty()) {
|
||||||
// 返回一个新的会话
|
// 返回一个新的会话
|
||||||
StudySessionsEntity studySessionsEntity = StudySessionsEntity.initNewSession();
|
StudySessionsEntity studySessionsEntity = StudySessionsEntity.initNewSession();
|
||||||
|
studySessionsEntity.setTaskNum(taskNum);
|
||||||
this.save(studySessionsEntity);
|
this.save(studySessionsEntity);
|
||||||
return StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity);
|
return StudySessionConvert.MAPPER.toStudySessionResponce(studySessionsEntity);
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
Reference in New Issue
Block a user