|
|
@ -73,6 +73,12 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo |
|
|
@Value("${classicpaper.spare.replenish-threshold:1}") |
|
|
@Value("${classicpaper.spare.replenish-threshold:1}") |
|
|
private int replenishThreshold; |
|
|
private int replenishThreshold; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${classicpaper.spare.replenish-count:2}") |
|
|
|
|
|
private int replenishCount; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${classicpaper.spare.replenish-delay-ms:10000}") |
|
|
|
|
|
private long replenishDelayMs; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public Result<ClassicPaperQuestionDTO> regenerate(Long paperId, Long paperQuestionId) throws Exception { |
|
|
public Result<ClassicPaperQuestionDTO> regenerate(Long paperId, Long paperQuestionId) throws Exception { |
|
|
@ -115,6 +121,7 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo |
|
|
if (knowledgePoints.isEmpty()) { |
|
|
if (knowledgePoints.isEmpty()) { |
|
|
throw new BusinessErrorException("关联知识点数据不存在"); |
|
|
throw new BusinessErrorException("关联知识点数据不存在"); |
|
|
} |
|
|
} |
|
|
|
|
|
QuestionTypeEnum questionType = QuestionTypeEnum.findByValue(originalQuestion.getQuestionType()); |
|
|
|
|
|
|
|
|
// 6. 优先从备用池取题
|
|
|
// 6. 优先从备用池取题
|
|
|
QuestionEntity spareQuestion = spareQuestionService.takeOneSpare(paperQuestionId); |
|
|
QuestionEntity spareQuestion = spareQuestionService.takeOneSpare(paperQuestionId); |
|
|
@ -128,7 +135,7 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo |
|
|
if (remaining <= replenishThreshold) { |
|
|
if (remaining <= replenishThreshold) { |
|
|
log.info(">>> [经典套题-重新生题] 备用池不足(剩余{}),异步补充 paperQuestionId={}", |
|
|
log.info(">>> [经典套题-重新生题] 备用池不足(剩余{}),异步补充 paperQuestionId={}", |
|
|
remaining, paperQuestionId); |
|
|
remaining, paperQuestionId); |
|
|
// 异步补充由回调流程处理,这里不阻塞
|
|
|
triggerReplenish(paperQuestionId, knowledgePoints, questionType); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log.info(">>> [经典套题-重新生题][备用池] 套卷{} 关联记录{} 原题{} -> 新题{}", |
|
|
log.info(">>> [经典套题-重新生题][备用池] 套卷{} 关联记录{} 原题{} -> 新题{}", |
|
|
@ -143,7 +150,6 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo |
|
|
|
|
|
|
|
|
mockSleep(); |
|
|
mockSleep(); |
|
|
|
|
|
|
|
|
QuestionTypeEnum questionType = QuestionTypeEnum.findByValue(originalQuestion.getQuestionType()); |
|
|
|
|
|
List<QuestionEntity> newQuestions = classicPaperQuestionGenerator.generate( |
|
|
List<QuestionEntity> newQuestions = classicPaperQuestionGenerator.generate( |
|
|
knowledgePoints, questionType, 1); |
|
|
knowledgePoints, questionType, 1); |
|
|
if (newQuestions.isEmpty()) { |
|
|
if (newQuestions.isEmpty()) { |
|
|
@ -174,6 +180,7 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo |
|
|
int remaining = spareQuestionService.getRemainingSpares(paperQuestionId); |
|
|
int remaining = spareQuestionService.getRemainingSpares(paperQuestionId); |
|
|
if (remaining <= replenishThreshold) { |
|
|
if (remaining <= replenishThreshold) { |
|
|
log.info(">>> [经典套题-重新生题-异步][备用池] 备用池不足,异步补充 paperQuestionId={}", paperQuestionId); |
|
|
log.info(">>> [经典套题-重新生题-异步][备用池] 备用池不足,异步补充 paperQuestionId={}", paperQuestionId); |
|
|
|
|
|
triggerReplenish(paperQuestionId); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
log.info(">>> [经典套题-重新生题-异步][备用池] 直接替换成功, paperQuestionId={}, newQuestionId={}", |
|
|
log.info(">>> [经典套题-重新生题-异步][备用池] 直接替换成功, paperQuestionId={}, newQuestionId={}", |
|
|
@ -319,4 +326,69 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo |
|
|
log.warn(">>> [经典套题-重新生题] Mock 延迟被中断"); |
|
|
log.warn(">>> [经典套题-重新生题] Mock 延迟被中断"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ==================== 备用题补充 ====================
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 异步补充备用题(已知知识点的场景,regenerate 使用) |
|
|
|
|
|
*/ |
|
|
|
|
|
private void triggerReplenish(Long paperQuestionId, |
|
|
|
|
|
List<KnowledgePointEntity> knowledgePoints, |
|
|
|
|
|
QuestionTypeEnum questionType) { |
|
|
|
|
|
CompletableFuture.runAsync(() -> { |
|
|
|
|
|
try { |
|
|
|
|
|
Thread.sleep(replenishDelayMs); |
|
|
|
|
|
classicPaperQuestionGenerator.generateAsync( |
|
|
|
|
|
paperQuestionId, knowledgePoints, questionType, replenishCount, null); |
|
|
|
|
|
log.info(">>> [备用补充] 已提交补充任务, paperQuestionId={}, 数量={}", |
|
|
|
|
|
paperQuestionId, replenishCount); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error(">>> [备用补充] 失败, paperQuestionId={}", paperQuestionId, e); |
|
|
|
|
|
} |
|
|
|
|
|
}, regenerateExecutor); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 异步补充备用题(需查询知识点的场景,regenerateAsync 使用) |
|
|
|
|
|
*/ |
|
|
|
|
|
private void triggerReplenish(Long paperQuestionId) { |
|
|
|
|
|
CompletableFuture.runAsync(() -> { |
|
|
|
|
|
try { |
|
|
|
|
|
Thread.sleep(replenishDelayMs); |
|
|
|
|
|
|
|
|
|
|
|
ClassicPaperQuestionEntity pq = classicPaperQuestionBaseService.getById(paperQuestionId); |
|
|
|
|
|
if (pq == null || pq.getQuestionId() == null) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QuestionEntity original = questionBaseService.getById(pq.getQuestionId()); |
|
|
|
|
|
if (original == null) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<QuestionKpRelEntity> kpRels = questionKpRelBaseService.list( |
|
|
|
|
|
new LambdaQueryWrapper<QuestionKpRelEntity>() |
|
|
|
|
|
.eq(QuestionKpRelEntity::getQuestionId, original.getId())); |
|
|
|
|
|
if (kpRels.isEmpty()) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<Long> kpIds = kpRels.stream() |
|
|
|
|
|
.map(QuestionKpRelEntity::getKpId).collect(Collectors.toList()); |
|
|
|
|
|
List<KnowledgePointEntity> kps = knowledgePointBaseService.listByIds(kpIds); |
|
|
|
|
|
if (kps.isEmpty()) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QuestionTypeEnum questionType = QuestionTypeEnum.findByValue(original.getQuestionType()); |
|
|
|
|
|
|
|
|
|
|
|
classicPaperQuestionGenerator.generateAsync( |
|
|
|
|
|
paperQuestionId, kps, questionType, replenishCount, null); |
|
|
|
|
|
log.info(">>> [备用补充] 已提交补充任务, paperQuestionId={}, 数量={}", |
|
|
|
|
|
paperQuestionId, replenishCount); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error(">>> [备用补充] 失败, paperQuestionId={}", paperQuestionId, e); |
|
|
|
|
|
} |
|
|
|
|
|
}, regenerateExecutor); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|