From 8cd828896ee9e545cf41b28a3bba8e41f575a7dc Mon Sep 17 00:00:00 2001 From: luoweijian <1329394916@qq.com> Date: Mon, 13 Jul 2026 17:30:52 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenerateClassicPaperDomainService.java | 8 ++ ...GenerateClassicPaperDomainServiceImpl.java | 77 ++++++++++++++++++- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/project/classicpaper/domain/service/GenerateClassicPaperDomainService.java b/src/main/java/com/project/classicpaper/domain/service/GenerateClassicPaperDomainService.java index d8011f7..b51390c 100644 --- a/src/main/java/com/project/classicpaper/domain/service/GenerateClassicPaperDomainService.java +++ b/src/main/java/com/project/classicpaper/domain/service/GenerateClassicPaperDomainService.java @@ -9,4 +9,12 @@ public interface GenerateClassicPaperDomainService { * 批量生成经典套题(N个版本),返回套题组信息 */ Result generate(ClassicPaperSetDTO request) throws Exception; + + + + /** + * 重新生成套题 + * @param setId 套题组ID + */ + Result regenerate(Long setId) throws Exception; } 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 5d97ca5..747e2d0 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 @@ -311,11 +311,10 @@ public class GenerateClassicPaperDomainServiceImpl implements GenerateClassicPap } } - // 4. 多选题(排除已用于简答题的簇) + // 4. 多选题 int multipleChoiceNum = Optional.ofNullable(request.getMultipleChoiceNum()).orElse(0); if (multipleChoiceNum > 0) { List availableClusters = shuffledClusters.stream() - .filter(c -> !usedSourceClusterIds.contains(c.getId())) .toList(); List sampledClusters = sampleClusters(availableClusters, multipleChoiceNum); for (KnowledgeClusterEntity cluster : sampledClusters) { @@ -501,4 +500,78 @@ public class GenerateClassicPaperDomainServiceImpl implements GenerateClassicPap Collections.shuffle(shuffled); return shuffled.subList(0, sampleSize); } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result regenerate(Long setId) throws Exception { + // 1. 校验套题组是否存在 + ClassicPaperSetEntity paperSet = classicPaperSetBaseService.getById(setId); + if (paperSet == null) { + throw new BusinessErrorException("套题组不存在"); + } + + // 2. 清理旧数据 + // 查询原有的卷子 ID 列表 + List oldPapers = classicPaperBaseService.list( + new LambdaQueryWrapper().eq(ClassicPaperEntity::getSetId, setId) + ); + + if (CollUtil.isNotEmpty(oldPapers)) { + List paperIds = oldPapers.stream().map(ClassicPaperEntity::getId).collect(Collectors.toList()); + // 删除卷子题目关联表 + classicPaperQuestionBaseService.remove(new LambdaQueryWrapper() + .in(ClassicPaperQuestionEntity::getPaperId, paperIds)); + // 删除卷子表 + classicPaperBaseService.removeByIds(paperIds); + } + + // 清理任务关联的知识点和簇数据 (groupId 存的是 setId) + taskKnowledgePointBaseService.remove(new LambdaQueryWrapper() + .eq(TaskKnowledgePointEntity::getGroupId, setId)); + taskKnowledgeClusterBaseService.remove(new LambdaQueryWrapper() + .eq(TaskKnowledgeClusterEntity::getGroupId, setId)); + + // 3. 更新状态为生成中 + paperSet.setStatus(ClassicPaperStatusEnum.GENERATING.getValue()); + classicPaperSetBaseService.updateById(paperSet); + + // 4. 构建请求 DTO (复用原有的配置) + ClassicPaperSetDTO request = paperSet.toDTO(ClassicPaperSetDTO::new); + + // 5. 重新获取最新的资料、知识点和簇数据 (防止在此期间资料有更新) + List informations = informationBaseService.list( + new LambdaQueryWrapper() + .eq(InformationEntity::getSubLineId, paperSet.getSubLineId()) + .eq(InformationEntity::getParseStatus, InformationParseStatusEnum.Success.getValue()) + ); + if (CollUtil.isEmpty(informations)) { + throw new BusinessErrorException("该子产品线下没有已解析成功的资料"); + } + + List informationIds = informations.stream().map(InformationEntity::getId).collect(Collectors.toList()); + String informationIdsJson = toJsonArray(informationIds); + + List allKps = knowledgePointBaseService.list( + new LambdaQueryWrapper().in(KnowledgePointEntity::getInformationId, informationIds) + ); + List allClusters = knowledgeClusterBaseService.list( + new LambdaQueryWrapper() + .in(KnowledgeClusterEntity::getInformationId, informationIds) + .gt(KnowledgeClusterEntity::getClusterSize, 1) + ); + + // 6. 重新执行循环生成逻辑 + List paperDTOs = new ArrayList<>(); + for (int i = 1; i <= paperSet.getSetCount(); i++) { + ClassicPaperDTO paperDTO = generateOnePaper(paperSet.getId(), i, request, allKps, allClusters, informationIdsJson); + paperDTOs.add(paperDTO); + } + + log.info(">>> [经典套题] 重新生成任务已提交, setId={}, 版本数={}", setId, paperSet.getSetCount()); + + ClassicPaperSetDTO setDTO = paperSet.toDTO(ClassicPaperSetDTO::new); + setDTO.setStatusText(ClassicPaperStatusEnum.GENERATING.getDesc()); + setDTO.setPaperList(paperDTOs); + return Result.success(setDTO); + } }