|
|
|
@@ -16,6 +16,7 @@ import com.guo.learningprogresstracker.mapper.StudySessionsMapper;
|
|
|
|
|
import com.guo.learningprogresstracker.mapper.TasksMapper;
|
|
|
|
|
import com.guo.learningprogresstracker.service.ReviewService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
@@ -29,6 +30,7 @@ import java.util.stream.Stream;
|
|
|
|
|
/**
|
|
|
|
|
* 复习模块 Service 实现
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class ReviewServiceImpl implements ReviewService {
|
|
|
|
@@ -53,13 +55,6 @@ public class ReviewServiceImpl implements ReviewService {
|
|
|
|
|
}
|
|
|
|
|
boolean random = RANDOM_MODE.equalsIgnoreCase(mode);
|
|
|
|
|
|
|
|
|
|
List<StudyReportsEntity> reports = random
|
|
|
|
|
? studyReportsMapper.selectList(Wrappers.<StudyReportsEntity>lambdaQuery()
|
|
|
|
|
.last("ORDER BY RAND() LIMIT " + safeLimit))
|
|
|
|
|
: studyReportsMapper.selectList(Wrappers.<StudyReportsEntity>lambdaQuery()
|
|
|
|
|
.orderByDesc(StudyReportsEntity::getCreatedTime)
|
|
|
|
|
.last("LIMIT " + safeLimit));
|
|
|
|
|
|
|
|
|
|
List<StudyReportFragmentsEntity> fragments = random
|
|
|
|
|
? studyReportFragmentsMapper.selectList(Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
|
|
|
|
.last("ORDER BY RAND() LIMIT " + safeLimit))
|
|
|
|
@@ -67,7 +62,7 @@ public class ReviewServiceImpl implements ReviewService {
|
|
|
|
|
.orderByDesc(StudyReportFragmentsEntity::getCreatedTime)
|
|
|
|
|
.last("LIMIT " + safeLimit));
|
|
|
|
|
|
|
|
|
|
List<ReviewFeedItem> items = mergeAndConvert(reports, fragments);
|
|
|
|
|
List<ReviewFeedItem> items = mergeAndConvert(List.of(), fragments);
|
|
|
|
|
if (random) {
|
|
|
|
|
Collections.shuffle(items);
|
|
|
|
|
}
|
|
|
|
@@ -82,14 +77,11 @@ public class ReviewServiceImpl implements ReviewService {
|
|
|
|
|
private List<ReviewFeedItem> getSmartFeed(int safeLimit) {
|
|
|
|
|
int candidateLimit = Math.min(safeLimit * SMART_CANDIDATE_MULTIPLIER, 500);
|
|
|
|
|
|
|
|
|
|
List<StudyReportsEntity> reports = studyReportsMapper.selectList(
|
|
|
|
|
Wrappers.<StudyReportsEntity>lambdaQuery()
|
|
|
|
|
.last("ORDER BY RAND() LIMIT " + candidateLimit));
|
|
|
|
|
List<StudyReportFragmentsEntity> fragments = studyReportFragmentsMapper.selectList(
|
|
|
|
|
Wrappers.<StudyReportFragmentsEntity>lambdaQuery()
|
|
|
|
|
.last("ORDER BY RAND() LIMIT " + candidateLimit));
|
|
|
|
|
|
|
|
|
|
List<ReviewFeedItem> candidates = mergeAndConvert(reports, fragments);
|
|
|
|
|
List<ReviewFeedItem> candidates = mergeAndConvert(List.of(), fragments);
|
|
|
|
|
if (candidates.size() <= safeLimit) {
|
|
|
|
|
Collections.shuffle(candidates);
|
|
|
|
|
return candidates;
|
|
|
|
@@ -224,13 +216,19 @@ public class ReviewServiceImpl implements ReviewService {
|
|
|
|
|
@Override
|
|
|
|
|
public StudyReportsEntity getReportDetail(int id) throws NotFindEntitiesException {
|
|
|
|
|
return Optional.ofNullable(studyReportsMapper.selectById(id))
|
|
|
|
|
.orElseThrow(() -> new NotFindEntitiesException("学习报告[" + id + "]不存在"));
|
|
|
|
|
.orElseThrow(() -> {
|
|
|
|
|
log.warn("学习报告[{}]不存在", id);
|
|
|
|
|
return new NotFindEntitiesException("这份学习报告不存在或已被删除");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public StudyReportFragmentsEntity getFragmentDetail(int id) throws NotFindEntitiesException {
|
|
|
|
|
return Optional.ofNullable(studyReportFragmentsMapper.selectById(id))
|
|
|
|
|
.orElseThrow(() -> new NotFindEntitiesException("学习残片[" + id + "]不存在"));
|
|
|
|
|
.orElseThrow(() -> {
|
|
|
|
|
log.warn("学习残片[{}]不存在", id);
|
|
|
|
|
return new NotFindEntitiesException("这条学习残片不存在或已被删除");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -321,7 +319,8 @@ public class ReviewServiceImpl implements ReviewService {
|
|
|
|
|
private void ensureTaskExists(String taskNum) throws NotFindEntitiesException {
|
|
|
|
|
if (!StringUtils.hasText(taskNum) || !tasksMapper.exists(
|
|
|
|
|
Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskNum, taskNum))) {
|
|
|
|
|
throw new NotFindEntitiesException("任务[" + taskNum + "]不存在");
|
|
|
|
|
log.warn("任务[{}]不存在", taskNum);
|
|
|
|
|
throw new NotFindEntitiesException("这个任务不存在或已被删除");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|