[xingyu.guo] feat: 【创建学习残片】API
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.guo.learningprogresstracker.service;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.request.CreateFragmentsRequest;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||
|
||||
/**
|
||||
* @author guo
|
||||
@@ -10,4 +12,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface StudyReportFragmentsService extends IService<StudyReportFragmentsEntity> {
|
||||
|
||||
void createFragments(CreateFragmentsRequest request) throws NotFindEntitiesException;
|
||||
}
|
||||
|
||||
+21
@@ -1,7 +1,12 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guo.learningprogresstracker.dto.request.CreateFragmentsRequest;
|
||||
import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity;
|
||||
import com.guo.learningprogresstracker.entity.StudySessionsEntity;
|
||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||
import com.guo.learningprogresstracker.mapStruct.FragmentsConvert;
|
||||
import com.guo.learningprogresstracker.service.StudyReportFragmentsService;
|
||||
import com.guo.learningprogresstracker.mapper.StudyReportFragmentsMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -15,6 +20,22 @@ import org.springframework.stereotype.Service;
|
||||
public class StudyReportFragmentsServiceImpl extends ServiceImpl<StudyReportFragmentsMapper, StudyReportFragmentsEntity>
|
||||
implements StudyReportFragmentsService{
|
||||
|
||||
private final StudySessionsServiceImpl studySessionsServiceImpl;
|
||||
|
||||
public StudyReportFragmentsServiceImpl(StudySessionsServiceImpl studySessionsServiceImpl) {
|
||||
this.studySessionsServiceImpl = studySessionsServiceImpl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createFragments(CreateFragmentsRequest request) throws NotFindEntitiesException {
|
||||
StudyReportFragmentsEntity entity = FragmentsConvert.MAPPER.toFragmentsEntity(request);
|
||||
if (studySessionsServiceImpl.exists(Wrappers.lambdaQuery(StudySessionsEntity.class)
|
||||
.eq(StudySessionsEntity::getSessionNum,entity.getSessionNum()))) {
|
||||
this.save(entity);
|
||||
}else {
|
||||
throw new NotFindEntitiesException(String.format("未能找到学习会话sessionNum[%s]",entity.getSessionNum()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user