fix(examWords): 处理生成单词为空的异常情况

- 增加判断如果生成的单词对象为空或单词列表为空,则抛出运行时异常
- 防止后续处理中因单词缺失导致的错误
- 提升系统稳定性与异常提示的准确性
This commit is contained in:
lbw
2025-12-15 17:25:00 +08:00
parent e5fbb445cf
commit d027c9c7e6

View File

@@ -50,6 +50,9 @@ public class ExamWordsController {
} }
try { try {
ExamWordsDO examWordsDO = examWordsService.generateExamWords(gradeId, level, studentIds); ExamWordsDO examWordsDO = examWordsService.generateExamWords(gradeId, level, studentIds);
if (examWordsDO == null || examWordsDO.getWordIds().isEmpty()) {
throw new RuntimeException("没有单词");
}
List<VocabularyBankDO> vocabularyBankDOS = vocabularyService.findVocabularyBankDOListById(examWordsDO.getWordIds()); List<VocabularyBankDO> vocabularyBankDOS = vocabularyService.findVocabularyBankDOListById(examWordsDO.getWordIds());
List<Word> assessmentWords = vocabularyBankDOS.stream().map(vocabularyBankDO -> Word.builder() List<Word> assessmentWords = vocabularyBankDOS.stream().map(vocabularyBankDO -> Word.builder()
.id(vocabularyBankDO.getId()) .id(vocabularyBankDO.getId())