|
|
@ -1,6 +1,5 @@ |
|
|
package com.project.question.domain.service.impl; |
|
|
package com.project.question.domain.service.impl; |
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.project.base.domain.result.Result; |
|
|
import com.project.base.domain.result.Result; |
|
|
import com.project.question.domain.entity.TaskKnowledgeClusterEntity; |
|
|
import com.project.question.domain.entity.TaskKnowledgeClusterEntity; |
|
|
@ -18,7 +17,6 @@ import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
import java.util.Date; |
|
|
import java.util.Date; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
@ -46,14 +44,8 @@ public class QuestionInventoryDomainServiceImpl implements QuestionInventoryDoma |
|
|
if (task == null || task.getEndTime().before(new Date())) { |
|
|
if (task == null || task.getEndTime().before(new Date())) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
int u = (task.getParticipantNum() == null ? 0 : task.getParticipantNum()) |
|
|
int watermark = getWatermark(task); |
|
|
- (task.getPassNum() == null ? 0 : task.getPassNum()); |
|
|
int targetLine = (int) Math.ceil(1.2 * getUnpassedCount(task)); |
|
|
if (u <= 0) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
int watermark = (int) Math.ceil(1.0 * u); |
|
|
|
|
|
int targetLine = (int) Math.ceil(1.2 * u); |
|
|
|
|
|
// 针对每个知识点遍历每种题型
|
|
|
|
|
|
List<TaskKnowledgePointEntity> kpList = taskKpMapper.selectList( |
|
|
List<TaskKnowledgePointEntity> kpList = taskKpMapper.selectList( |
|
|
new LambdaQueryWrapper<TaskKnowledgePointEntity>().eq(TaskKnowledgePointEntity::getTaskId , taskId)); |
|
|
new LambdaQueryWrapper<TaskKnowledgePointEntity>().eq(TaskKnowledgePointEntity::getTaskId , taskId)); |
|
|
for (TaskKnowledgePointEntity kp : kpList) { |
|
|
for (TaskKnowledgePointEntity kp : kpList) { |
|
|
@ -85,59 +77,33 @@ public class QuestionInventoryDomainServiceImpl implements QuestionInventoryDoma |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Result<String> checkAndReplenishBoolean(Long taskId) { |
|
|
public Result<String> checkAndReplenishBoolean(Long taskId) { |
|
|
//标记是否生成完成
|
|
|
|
|
|
Boolean flage = true; |
|
|
|
|
|
|
|
|
|
|
|
TaskEntity task = taskMapper.selectById(taskId); |
|
|
TaskEntity task = taskMapper.selectById(taskId); |
|
|
if (task == null || task.getEndTime().before(new Date())) { |
|
|
if (task == null || task.getEndTime().before(new Date())) { |
|
|
return Result.success("题目生成完成"); |
|
|
return Result.success("题目生成完成"); |
|
|
} |
|
|
} |
|
|
int u = (task.getParticipantNum() == null ? 0 : task.getParticipantNum()) |
|
|
int unpassed = getUnpassedCount(task); |
|
|
- (task.getPassNum() == null ? 0 : task.getPassNum()); |
|
|
if (unpassed <= 0) { |
|
|
if (u <= 0) { |
|
|
|
|
|
return Result.success("题目生成完成"); |
|
|
return Result.success("题目生成完成"); |
|
|
} |
|
|
} |
|
|
int watermark = (int) Math.ceil(1.0 * u); |
|
|
|
|
|
int targetLine = (int) Math.ceil(1.2 * u); |
|
|
|
|
|
// 针对每个知识点遍历每种题型
|
|
|
|
|
|
List<TaskKnowledgePointEntity> kpList = taskKpMapper.selectList( |
|
|
List<TaskKnowledgePointEntity> kpList = taskKpMapper.selectList( |
|
|
new LambdaQueryWrapper<TaskKnowledgePointEntity>().eq(TaskKnowledgePointEntity::getTaskId , taskId)); |
|
|
new LambdaQueryWrapper<TaskKnowledgePointEntity>().eq(TaskKnowledgePointEntity::getTaskId , taskId)); |
|
|
for (TaskKnowledgePointEntity kp : kpList) { |
|
|
for (TaskKnowledgePointEntity kp : kpList) { |
|
|
for (QuestionTypeEnum questionType : QuestionTypeEnum.values()) { |
|
|
if(!checkKp(task,kp.getId())){ |
|
|
if (QuestionTypeEnum.MULTIPLE_CHOICE.equals(questionType)) { |
|
|
return Result.success("题目未生成完成"); |
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
int currentStock = questionKpMapper.countAvailableByKp(kp.getId(), questionType.getValue()); |
|
|
|
|
|
if (currentStock < watermark){ |
|
|
|
|
|
flage = false; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
// 针对每一个簇
|
|
|
// 针对每一个簇
|
|
|
List<TaskKnowledgeClusterEntity> clusterList = clusterMapper.selectList( |
|
|
List<TaskKnowledgeClusterEntity> clusterList = clusterMapper.selectList( |
|
|
new LambdaQueryWrapper<TaskKnowledgeClusterEntity>().eq(TaskKnowledgeClusterEntity::getTaskId, taskId)); |
|
|
new LambdaQueryWrapper<TaskKnowledgeClusterEntity>().eq(TaskKnowledgeClusterEntity::getTaskId, taskId)); |
|
|
|
|
|
|
|
|
for (TaskKnowledgeClusterEntity cluster : clusterList) { |
|
|
for (TaskKnowledgeClusterEntity cluster : clusterList) { |
|
|
if (cluster.getClusterSize() < 2) { |
|
|
if (cluster.getClusterSize() < 2) { |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
int w = cluster.getClusterSize(); |
|
|
if (!checkCluster(task, cluster)) { |
|
|
// 簇水位线: 1.0 * U * W
|
|
|
return Result.success("题目未生成完成"); |
|
|
int clusterWatermark = watermark * w; |
|
|
|
|
|
|
|
|
|
|
|
int currentStock = questionKpMapper.countAvailableByCluster(cluster.getId()); |
|
|
|
|
|
if (currentStock < clusterWatermark){ |
|
|
|
|
|
flage = false; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (flage){ |
|
|
|
|
|
return Result.success("题目生成完成"); |
|
|
return Result.success("题目生成完成"); |
|
|
}else{ |
|
|
|
|
|
return Result.success("题目未生成完成"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -168,4 +134,56 @@ public class QuestionInventoryDomainServiceImpl implements QuestionInventoryDoma |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 校验知识点是否库存充足 |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean checkKpInventory(Long kpId, QuestionTypeEnum type, int watermark) { |
|
|
|
|
|
int currentStock = questionKpMapper.countAvailableByKp(kpId, type.getValue()); |
|
|
|
|
|
return currentStock >= watermark; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 校验知识点簇是否库存充足 |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean checkClusterInventory(Long clusterId, int clusterWatermark) { |
|
|
|
|
|
int currentStock = questionKpMapper.countAvailableByCluster(clusterId); |
|
|
|
|
|
return currentStock >= clusterWatermark; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 计算未通过人数 |
|
|
|
|
|
*/ |
|
|
|
|
|
private int getUnpassedCount(TaskEntity task) { |
|
|
|
|
|
return (task.getParticipantNum() == null ? 0 : task.getParticipantNum()) |
|
|
|
|
|
- (task.getPassNum() == null ? 0 : task.getPassNum()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 计算水位线 (watermark = ceil(1.0 * u)) |
|
|
|
|
|
*/ |
|
|
|
|
|
private int getWatermark(TaskEntity task) { |
|
|
|
|
|
return (int) Math.ceil(1.0 * getUnpassedCount(task)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Boolean checkKp(TaskEntity task, Long kpId){ |
|
|
|
|
|
int watermark = getWatermark(task); |
|
|
|
|
|
for (QuestionTypeEnum questionType : QuestionTypeEnum.values()) { |
|
|
|
|
|
if (QuestionTypeEnum.MULTIPLE_CHOICE.equals(questionType)) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (!checkKpInventory(kpId, questionType, watermark)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Boolean checkCluster(TaskEntity task, TaskKnowledgeClusterEntity cluster) { |
|
|
|
|
|
int watermark = getWatermark(task); |
|
|
|
|
|
int clusterWatermark = watermark * cluster.getClusterSize(); |
|
|
|
|
|
return checkClusterInventory(cluster.getId(), clusterWatermark); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|