diff --git a/src/main/java/com/project/classicpaper/domain/service/impl/GenerateClassicPaperDomainServiceImpl.java b/src/main/java/com/project/classicpaper/domain/service/impl/GenerateClassicPaperDomainServiceImpl.java index 747e2d0..3dddfc2 100644 --- a/src/main/java/com/project/classicpaper/domain/service/impl/GenerateClassicPaperDomainServiceImpl.java +++ b/src/main/java/com/project/classicpaper/domain/service/impl/GenerateClassicPaperDomainServiceImpl.java @@ -29,6 +29,7 @@ import com.project.question.domain.entity.TaskKnowledgePointEntity; import com.project.question.domain.service.TaskKnowledgeClusterBaseService; import com.project.question.domain.service.TaskKnowledgePointBaseService; import com.project.task.domain.enums.QuestionTypeEnum; +import io.vavr.control.Try; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -36,6 +37,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @Service @@ -129,6 +131,9 @@ public class GenerateClassicPaperDomainServiceImpl implements GenerateClassicPap if (totalPerSet <= 0) { throw new BusinessErrorException("至少需要一种题型的数量大于0"); } + if (totalPerSet > 100) { + throw new BusinessErrorException("总题数不得超过100题"); + } // 校验:单选题+判断题 <= 知识点总数 int singleAndTrueFalse = Optional.ofNullable(request.getSingleChoiceNum()).orElse(0) @@ -359,9 +364,10 @@ public class GenerateClassicPaperDomainServiceImpl implements GenerateClassicPap for (PaperQuestionTask task : paperQuestionTasks) { Long clusterId = task.knowledgePoints != null && !task.knowledgePoints.isEmpty() ? task.knowledgePoints.get(0).getClusterId() : null; - classicPaperQuestionGenerator.generateAsync( + CompletableFuture.runAsync(() -> Try.run(() -> classicPaperQuestionGenerator.generateAsync( task.paperQuestionId, task.knowledgePoints, task.questionType, - 1 + sparePerQuestion, clusterId); + 1 + sparePerQuestion, clusterId))); + } // ============ Phase 3: 立即返回 ============