|
|
|
@ -214,6 +214,58 @@ public class AssemblePaperDomainServiceImpl implements AssemblePaperDomainServic |
|
|
|
List<TaskKnowledgePointDTO> kpList = taskKnowledgePointBaseService.lambdaQuery() |
|
|
|
.eq(TaskKnowledgePointEntity::getTaskId, dto.getId()).list().stream() |
|
|
|
.map(entity -> entity.toDTO(TaskKnowledgePointDTO::new)).toList(); |
|
|
|
|
|
|
|
// ========== 新增:批量查询库存,内存过滤 ==========
|
|
|
|
// 1. 批量查询知识点级别的各题型库存
|
|
|
|
Set<Long> allKpIds = kpList.stream().map(TaskKnowledgePointDTO::getId).collect(Collectors.toSet()); |
|
|
|
Map<Long, Map<Integer, Integer>> kpStockMap = new HashMap<>(); |
|
|
|
if (CollUtil.isNotEmpty(allKpIds)) { |
|
|
|
List<Map<String, Object>> kpStockList = taskKnowledgePointMapper.batchCountByKpAndType(allKpIds); |
|
|
|
for (Map<String, Object> row : kpStockList) { |
|
|
|
Long kpId = ((Number) row.get("kpId")).longValue(); |
|
|
|
Integer questionType = ((Number) row.get("questionType")).intValue(); |
|
|
|
Integer stock = ((Number) row.get("stock")).intValue(); |
|
|
|
kpStockMap.computeIfAbsent(kpId, k -> new HashMap<>()).put(questionType, stock); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 2. 批量查询簇级别的多选题库存
|
|
|
|
Set<Long> allClusterIds = kpList.stream() |
|
|
|
.filter(kp -> Objects.nonNull(kp.getClusterId())) |
|
|
|
.map(TaskKnowledgePointDTO::getClusterId) |
|
|
|
.collect(Collectors.toSet()); |
|
|
|
Map<Long, Integer> clusterStockMap = new HashMap<>(); |
|
|
|
if (CollUtil.isNotEmpty(allClusterIds)) { |
|
|
|
List<Map<String, Object>> clusterStockList = taskKnowledgePointMapper.batchCountByCluster(allClusterIds); |
|
|
|
for (Map<String, Object> row : clusterStockList) { |
|
|
|
Long clusterId = ((Number) row.get("clusterId")).longValue(); |
|
|
|
Integer stock = ((Number) row.get("stock")).intValue(); |
|
|
|
clusterStockMap.put(clusterId, stock); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 内存过滤:只保留有库存的知识点
|
|
|
|
kpList = kpList.stream().filter(kp -> { |
|
|
|
// 多选题种子:需要簇级别有多选题库存(排除单知识点簇)
|
|
|
|
if (Objects.nonNull(kp.getClusterSize()) && kp.getClusterSize() > 1) { |
|
|
|
Integer clusterStock = clusterStockMap.getOrDefault(kp.getClusterId(), 0); |
|
|
|
if (clusterStock > 0) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
// 单选/判断种子:需要知识点级别有对应题型库存
|
|
|
|
Map<Integer, Integer> typeStock = kpStockMap.getOrDefault(kp.getId(), Collections.emptyMap()); |
|
|
|
return typeStock.getOrDefault(QuestionTypeEnum.SINGLE_CHOICE.getValue(), 0) > 0 |
|
|
|
|| typeStock.getOrDefault(QuestionTypeEnum.TRUE_FALSE.getValue(), 0) > 0; |
|
|
|
}).toList(); |
|
|
|
|
|
|
|
// 4. 检查过滤后的种子数量是否足够
|
|
|
|
if (kpList.size() < totalNum) { |
|
|
|
log.warn(">>> [库存不足] 任务: {}, 需要种子: {}, 可用种子: {}", dto.getId(), totalNum, kpList.size()); |
|
|
|
throw new BusinessErrorException("当前题库可用题目不足,请联系管理员补货"); |
|
|
|
} |
|
|
|
// ========== 新增结束 ==========
|
|
|
|
|
|
|
|
// 按簇分组
|
|
|
|
Map<Long, List<TaskKnowledgePointDTO>> clusterGroup = kpList.stream() |
|
|
|
.collect(Collectors.groupingBy(TaskKnowledgePointDTO::getClusterId)); |
|
|
|
|