|
|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.project.question.domain.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.project.base.domain.result.Result; |
|
|
|
@ -19,10 +20,13 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
@ -113,6 +117,18 @@ public class QuestionInventoryDomainServiceImpl implements QuestionInventoryDoma |
|
|
|
List<TaskKnowledgePointEntity> kpList = taskKpMapper.selectList( |
|
|
|
new LambdaQueryWrapper<TaskKnowledgePointEntity>().eq(TaskKnowledgePointEntity::getTaskId , taskId)); |
|
|
|
|
|
|
|
// 批量查询知识点库存: Map<kpId, Map<questionType, stock>>,避免 N+1
|
|
|
|
Map<Long, Map<Integer, Integer>> kpStockMap = new HashMap<>(); |
|
|
|
Set<Long> kpIdSet = kpList.stream().map(TaskKnowledgePointEntity::getId).collect(Collectors.toSet()); |
|
|
|
if (CollUtil.isNotEmpty(kpIdSet)) { |
|
|
|
for (Map<String, Object> row : taskKpMapper.batchCountByKpAndType(kpIdSet)) { |
|
|
|
Long kpId = ((Number) row.get("kpId")).longValue(); |
|
|
|
Integer qType = ((Number) row.get("questionType")).intValue(); |
|
|
|
Integer stock = ((Number) row.get("stock")).intValue(); |
|
|
|
kpStockMap.computeIfAbsent(kpId, k -> new HashMap<>()).put(qType, stock); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (QuestionTypeEnum questionType : QuestionTypeEnum.values()) { |
|
|
|
if (QuestionTypeEnum.MULTIPLE_CHOICE.equals(questionType)) { |
|
|
|
continue; |
|
|
|
@ -128,7 +144,8 @@ public class QuestionInventoryDomainServiceImpl implements QuestionInventoryDoma |
|
|
|
int passedCount = 0; |
|
|
|
for (TaskKnowledgePointEntity kp : kpList) { |
|
|
|
kpCount++; |
|
|
|
int currentStock = questionKpMapper.countAvailableByKp(kp.getId(), questionType.getValue()); |
|
|
|
int currentStock = kpStockMap.getOrDefault(kp.getId(), Collections.emptyMap()) |
|
|
|
.getOrDefault(questionType.getValue(), 0); |
|
|
|
boolean isEnough = currentStock >= watermark; |
|
|
|
if (isEnough) { |
|
|
|
passedCount++; |
|
|
|
@ -144,6 +161,15 @@ public class QuestionInventoryDomainServiceImpl implements QuestionInventoryDoma |
|
|
|
List<TaskKnowledgeClusterEntity> clusterList = clusterMapper.selectList( |
|
|
|
new LambdaQueryWrapper<TaskKnowledgeClusterEntity>().eq(TaskKnowledgeClusterEntity::getTaskId, taskId)); |
|
|
|
|
|
|
|
// 批量查询簇库存: Map<clusterId, stock>,避免 N+1
|
|
|
|
Map<Long, Integer> clusterStockMap = new HashMap<>(); |
|
|
|
Set<Long> clusterIdSet = clusterList.stream().map(TaskKnowledgeClusterEntity::getId).collect(Collectors.toSet()); |
|
|
|
if (CollUtil.isNotEmpty(clusterIdSet)) { |
|
|
|
for (Map<String, Object> row : taskKpMapper.batchCountByCluster(clusterIdSet)) { |
|
|
|
clusterStockMap.put(((Number) row.get("clusterId")).longValue(), ((Number) row.get("stock")).intValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 按簇大小分组统计
|
|
|
|
Map<Integer, Integer> sizeTotalMap = new HashMap<>(); |
|
|
|
Map<Integer, Integer> sizePassedMap = new HashMap<>(); |
|
|
|
@ -154,7 +180,7 @@ public class QuestionInventoryDomainServiceImpl implements QuestionInventoryDoma |
|
|
|
} |
|
|
|
int w = cluster.getClusterSize(); |
|
|
|
int watermark = (int) Math.ceil(waterLine * w * questionTypeMap.get(QuestionTypeEnum.MULTIPLE_CHOICE.name())); |
|
|
|
int currentStock = questionKpMapper.countAvailableByCluster(cluster.getId()); |
|
|
|
int currentStock = clusterStockMap.getOrDefault(cluster.getId(), 0); |
|
|
|
boolean isEnough = currentStock >= watermark; |
|
|
|
|
|
|
|
sizeTotalMap.merge(w, 1, Integer::sum); |
|
|
|
|