Browse Source

bug修复

master
luoweijian 2 months ago
parent
commit
8cd828896e
  1. 8
      src/main/java/com/project/classicpaper/domain/service/GenerateClassicPaperDomainService.java
  2. 77
      src/main/java/com/project/classicpaper/domain/service/impl/GenerateClassicPaperDomainServiceImpl.java

8
src/main/java/com/project/classicpaper/domain/service/GenerateClassicPaperDomainService.java

@ -9,4 +9,12 @@ public interface GenerateClassicPaperDomainService {
* 批量生成经典套题N个版本返回套题组信息
*/
Result<ClassicPaperSetDTO> generate(ClassicPaperSetDTO request) throws Exception;
/**
* 重新生成套题
* @param setId 套题组ID
*/
Result<ClassicPaperSetDTO> regenerate(Long setId) throws Exception;
}

77
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<KnowledgeClusterEntity> availableClusters = shuffledClusters.stream()
.filter(c -> !usedSourceClusterIds.contains(c.getId()))
.toList();
List<KnowledgeClusterEntity> 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<ClassicPaperSetDTO> regenerate(Long setId) throws Exception {
// 1. 校验套题组是否存在
ClassicPaperSetEntity paperSet = classicPaperSetBaseService.getById(setId);
if (paperSet == null) {
throw new BusinessErrorException("套题组不存在");
}
// 2. 清理旧数据
// 查询原有的卷子 ID 列表
List<ClassicPaperEntity> oldPapers = classicPaperBaseService.list(
new LambdaQueryWrapper<ClassicPaperEntity>().eq(ClassicPaperEntity::getSetId, setId)
);
if (CollUtil.isNotEmpty(oldPapers)) {
List<Long> paperIds = oldPapers.stream().map(ClassicPaperEntity::getId).collect(Collectors.toList());
// 删除卷子题目关联表
classicPaperQuestionBaseService.remove(new LambdaQueryWrapper<ClassicPaperQuestionEntity>()
.in(ClassicPaperQuestionEntity::getPaperId, paperIds));
// 删除卷子表
classicPaperBaseService.removeByIds(paperIds);
}
// 清理任务关联的知识点和簇数据 (groupId 存的是 setId)
taskKnowledgePointBaseService.remove(new LambdaQueryWrapper<TaskKnowledgePointEntity>()
.eq(TaskKnowledgePointEntity::getGroupId, setId));
taskKnowledgeClusterBaseService.remove(new LambdaQueryWrapper<TaskKnowledgeClusterEntity>()
.eq(TaskKnowledgeClusterEntity::getGroupId, setId));
// 3. 更新状态为生成中
paperSet.setStatus(ClassicPaperStatusEnum.GENERATING.getValue());
classicPaperSetBaseService.updateById(paperSet);
// 4. 构建请求 DTO (复用原有的配置)
ClassicPaperSetDTO request = paperSet.toDTO(ClassicPaperSetDTO::new);
// 5. 重新获取最新的资料、知识点和簇数据 (防止在此期间资料有更新)
List<InformationEntity> informations = informationBaseService.list(
new LambdaQueryWrapper<InformationEntity>()
.eq(InformationEntity::getSubLineId, paperSet.getSubLineId())
.eq(InformationEntity::getParseStatus, InformationParseStatusEnum.Success.getValue())
);
if (CollUtil.isEmpty(informations)) {
throw new BusinessErrorException("该子产品线下没有已解析成功的资料");
}
List<Long> informationIds = informations.stream().map(InformationEntity::getId).collect(Collectors.toList());
String informationIdsJson = toJsonArray(informationIds);
List<KnowledgePointEntity> allKps = knowledgePointBaseService.list(
new LambdaQueryWrapper<KnowledgePointEntity>().in(KnowledgePointEntity::getInformationId, informationIds)
);
List<KnowledgeClusterEntity> allClusters = knowledgeClusterBaseService.list(
new LambdaQueryWrapper<KnowledgeClusterEntity>()
.in(KnowledgeClusterEntity::getInformationId, informationIds)
.gt(KnowledgeClusterEntity::getClusterSize, 1)
);
// 6. 重新执行循环生成逻辑
List<ClassicPaperDTO> 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);
}
}

Loading…
Cancel
Save