Browse Source

bug修复

master
luogw 1 month ago
parent
commit
b97f397bb0
  1. 4
      src/main/java/com/project/ding/utils/ChineseNameEncryptUtil.java
  2. 4
      src/main/java/com/project/interaction/application/impl/AlgorithmApplicationServiceImpl.java
  3. 2
      src/main/java/com/project/interaction/domain/service/PostToGenerateQuestionDomainService.java
  4. 12
      src/main/java/com/project/interaction/domain/service/impl/PostToGenerateQuestionDomainServiceImpl.java
  5. 21
      src/main/java/com/project/interaction/domain/service/impl/SaveClusterDomainServiceImpl.java
  6. 4
      src/main/java/com/project/question/domain/service/GenerateQuestionDomainService.java
  7. 11
      src/main/java/com/project/question/domain/service/impl/GenerateQuestionDomainServiceImpl.java
  8. 4
      src/main/java/com/project/question/domain/service/impl/QuestionInventoryDomainServiceImpl.java

4
src/main/java/com/project/ding/utils/ChineseNameEncryptUtil.java

@ -6,7 +6,7 @@ package com.project.ding.utils;
* 1. 二字名第二个字替换为**
* 2. 三字名中间字替换为**
* 3. 四字名中间两个字替换为***
* 4. 其他长度保留首尾中间全部替换为*****
* 4. 其他长度保留首尾中间全部替换为****
*/
public class ChineseNameEncryptUtil {
@ -31,7 +31,7 @@ public class ChineseNameEncryptUtil {
case 2 -> name.charAt(0) + "*"; // 二字名:首字符 + *
case 3 -> name.charAt(0) + "*" + name.charAt(2); // 三字名:首 + * + 尾
case 4 -> name.charAt(0) + "**" + name.charAt(3); // 四字名:首 + ** + 尾
default -> name.charAt(0) + "*".repeat(nameLength - 2) + name.charAt(nameLength - 1);
default -> name.charAt(0) + "**" + name.charAt(nameLength - 1);
};
}
}

4
src/main/java/com/project/interaction/application/impl/AlgorithmApplicationServiceImpl.java

@ -13,8 +13,6 @@ import com.project.question.domain.service.SaveQuestionDomainService;
import com.project.task.domain.enums.QuestionTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
@Service
@ -39,7 +37,7 @@ public class AlgorithmApplicationServiceImpl implements AlgorithmApplicationServ
@Override
public void postToGenerateQuestion(List<TaskKnowledgePointDTO> dtoList, QuestionTypeEnum questionType, int num) throws Exception {
postToGenerateQuestionDomainService.postToGenerateQuestion(dtoList , Collections.singletonList(questionType), num);
postToGenerateQuestionDomainService.postToGenerateQuestion(dtoList , questionType , num);
}

2
src/main/java/com/project/interaction/domain/service/PostToGenerateQuestionDomainService.java

@ -6,5 +6,5 @@ import com.project.task.domain.enums.QuestionTypeEnum;
import java.util.List;
public interface PostToGenerateQuestionDomainService {
void postToGenerateQuestion(List<TaskKnowledgePointDTO> dtoList, List<QuestionTypeEnum> questionTypeEnumList, int num) throws Exception;
void postToGenerateQuestion(List<TaskKnowledgePointDTO> dtoList, QuestionTypeEnum questionType, int num) throws Exception;
}

12
src/main/java/com/project/interaction/domain/service/impl/PostToGenerateQuestionDomainServiceImpl.java

@ -61,7 +61,7 @@ public class PostToGenerateQuestionDomainServiceImpl implements PostToGenerateQu
* 2. 如果算法服务失败使用熔断降级方案生成默认题目
*/
@Override
public void postToGenerateQuestion(List<TaskKnowledgePointDTO> dtoList, List<QuestionTypeEnum> questionTypeEnumList, int num) throws Exception {
public void postToGenerateQuestion(List<TaskKnowledgePointDTO> dtoList, QuestionTypeEnum questionType, int num) throws Exception {
Long taskId = Optional.of(dtoList.stream().findFirst())
.get().orElse(new TaskKnowledgePointDTO()).getTaskId();
Long clusterId = Optional.of(dtoList.stream().findFirst())
@ -71,7 +71,7 @@ public class PostToGenerateQuestionDomainServiceImpl implements PostToGenerateQu
.get().orElse(new TaskKnowledgePointDTO()).getAtomId());
log.info(">>> [题目生成] 开始生成题目, TaskId: {}, ClusterId: {}, 题型: {}, 数量: {}",
taskId, clusterId, questionTypeEnumList, num);
taskId, clusterId, questionType, num);
try {
// 应用限流:获取令牌,超过限流速率则等待
@ -83,7 +83,7 @@ public class PostToGenerateQuestionDomainServiceImpl implements PostToGenerateQu
}
//尝试调用算法服务生成题目
GenerateQuestionResponseDTO response = callAlgorithmService(dtoList, questionTypeEnumList, num, knowledgePoint.getParseName());
GenerateQuestionResponseDTO response = callAlgorithmService(dtoList, questionType, num, knowledgePoint.getParseName());
if (response != null && StringUtils.isNotBlank(response.getMessage()) && response.getMessage().contains("success")) {
log.info(">>> [题目生成] 算法服务接受任务成功, 任务: {}, 状态: {}, 信息:{}",
@ -106,9 +106,7 @@ public class PostToGenerateQuestionDomainServiceImpl implements PostToGenerateQu
/**
* 调用算法服务生成题目
*/
private GenerateQuestionResponseDTO callAlgorithmService(List<TaskKnowledgePointDTO> dtoList, List<QuestionTypeEnum> questionTypeEnumList, int num,String parseName){
List<String> questionTypeEnumStringList = questionTypeEnumList.stream().map(QuestionTypeEnum::getDescription).toList();
private GenerateQuestionResponseDTO callAlgorithmService(List<TaskKnowledgePointDTO> dtoList, QuestionTypeEnum questionType, int num,String parseName){
// 获取知识点内容
List<Long> kpIds = dtoList.stream().map(TaskKnowledgePointDTO::getId).collect(Collectors.toList());
List<String> sourceTexts = dtoList.stream().map(TaskKnowledgePointDTO::getContent).collect(Collectors.toList());
@ -126,7 +124,7 @@ public class PostToGenerateQuestionDomainServiceImpl implements PostToGenerateQu
.sourceId(kpIds)
.build())
.numQuestions(num)
.questionTypes(questionTypeEnumStringList)
.questionTypes(Collections.singletonList(questionType.name().toLowerCase()))
.build();
// 调用算法服务

21
src/main/java/com/project/interaction/domain/service/impl/SaveClusterDomainServiceImpl.java

@ -19,9 +19,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service
@ -77,15 +77,24 @@ public class SaveClusterDomainServiceImpl implements SaveClusterDomainService {
taskKnowledgePointBaseService.saveBatch(taskKpList);
// 生成目标量
int targetNum = (int) Math.ceil(1.2 * u);
//题目总数
Integer totalNum = taskEntity.getMultipleChoiceNum() + taskEntity.getSingleChoiceNum() + taskEntity.getTrueFalseNum();
//题目占比系数
Map<String,Double> questionTypeMap = new HashMap<>();
questionTypeMap.put(QuestionTypeEnum.SINGLE_CHOICE.name(), taskEntity.getSingleChoiceNum() * 1.0/totalNum);
questionTypeMap.put(QuestionTypeEnum.MULTIPLE_CHOICE.name(), taskEntity.getMultipleChoiceNum() * 1.0/totalNum);
questionTypeMap.put(QuestionTypeEnum.TRUE_FALSE.name(), taskEntity.getTrueFalseNum() * 1.0/totalNum);
for (TaskKnowledgePointEntity kp : taskKpList) {
List<QuestionTypeEnum> questionTypeEnumList = Arrays.stream(QuestionTypeEnum.values()).toList();
// 调用题目生成方法
generateQuestionDomainService.produce(kp.getId(), questionTypeEnumList , QuestionSourceTypeEnum.Single_Concept , targetNum);
for (QuestionTypeEnum value : QuestionTypeEnum.values()) {
generateQuestionDomainService.produce(kp.getId(), value , QuestionSourceTypeEnum.Single_Concept , (int) Math.ceil(targetNum * questionTypeMap.get(value.name())));
}
}
if (clusterEntity.getClusterSize() > 1) {
// 簇生成目标量
int clusterTargetNum = (int) Math.ceil(1.2 * u * clusterEntity.getClusterSize());
generateQuestionDomainService.produce(clusterEntity.getId(), Collections.singletonList(QuestionTypeEnum.MULTIPLE_CHOICE) , QuestionSourceTypeEnum.Multi_Concept , clusterTargetNum);
int clusterTargetNum = (int) Math.ceil(1.2 * u * clusterEntity.getClusterSize() * questionTypeMap.get(QuestionTypeEnum.MULTIPLE_CHOICE.name()));
generateQuestionDomainService.produce(clusterEntity.getId(), QuestionTypeEnum.MULTIPLE_CHOICE , QuestionSourceTypeEnum.Multi_Concept , clusterTargetNum);
}
}
}

4
src/main/java/com/project/question/domain/service/GenerateQuestionDomainService.java

@ -3,9 +3,7 @@ package com.project.question.domain.service;
import com.project.question.domain.enums.QuestionSourceTypeEnum;
import com.project.task.domain.enums.QuestionTypeEnum;
import java.util.List;
public interface GenerateQuestionDomainService {
void produce(Long sourceId, List<QuestionTypeEnum> questionTypeEnumList , QuestionSourceTypeEnum sourceType, int needCount);
void produce(Long sourceId, QuestionTypeEnum questionType , QuestionSourceTypeEnum sourceType, int needCount);
}

11
src/main/java/com/project/question/domain/service/impl/GenerateQuestionDomainServiceImpl.java

@ -1,6 +1,5 @@
package com.project.question.domain.service.impl;
import com.project.interaction.application.AlgorithmApplicationService;
import com.project.interaction.domain.service.PostToGenerateQuestionDomainService;
import com.project.question.domain.dto.TaskKnowledgePointDTO;
import com.project.question.domain.enums.QuestionSourceTypeEnum;
@ -36,32 +35,32 @@ public class GenerateQuestionDomainServiceImpl implements GenerateQuestionDomain
private PostToGenerateQuestionDomainService postToGenerateQuestionDomainService;
@Override
public void produce(Long sourceId, List<QuestionTypeEnum> questionTypeEnumList, QuestionSourceTypeEnum sourceType, int needCount) {
public void produce(Long sourceId, QuestionTypeEnum questionType , QuestionSourceTypeEnum sourceType, int needCount) {
if (needCount <= 0) {
return;
}
CompletableFuture.runAsync(() -> {
log.info(">>> [题库预生成] 准备生产任务: SourceID={}, Type={}, Count={}", sourceId, sourceType, needCount);
Try.run(() -> processBatch(sourceId,questionTypeEnumList , sourceType , needCount));
Try.run(() -> processBatch(sourceId,questionType , sourceType , needCount));
}, questionGenExecutor);
}
private void processBatch(Long sourceId, List<QuestionTypeEnum> questionTypeEnumList , QuestionSourceTypeEnum sourceType, int count) throws Exception{
private void processBatch(Long sourceId, QuestionTypeEnum questionType , QuestionSourceTypeEnum sourceType, int count) throws Exception{
// 如果是簇复合题,执行随机采样 2-4 个知识点
List<TaskKnowledgePointDTO> kpList;
if (QuestionSourceTypeEnum.Multi_Concept.equals(sourceType)) {
for (int i = 0; i < count; i++) {
kpList = samplingStrategy.sample(sourceId); // 获取随机组合的 KPs
postToGenerateQuestionDomainService.postToGenerateQuestion(kpList , questionTypeEnumList , 1);
postToGenerateQuestionDomainService.postToGenerateQuestion(kpList , questionType , 1);
}
} else {
// 单 KP 逻辑:直接查出对应 KP 的内容
kpList = Collections.singletonList(taskKnowledgePointBaseService.getById(sourceId)
.toDTO(TaskKnowledgePointDTO::new));
postToGenerateQuestionDomainService.postToGenerateQuestion(kpList , questionTypeEnumList , count);
postToGenerateQuestionDomainService.postToGenerateQuestion(kpList , questionType , count);
}
}
}

4
src/main/java/com/project/question/domain/service/impl/QuestionInventoryDomainServiceImpl.java

@ -85,7 +85,7 @@ public class QuestionInventoryDomainServiceImpl implements QuestionInventoryDoma
int gap = targetLine - currentStock;
log.info(">>> [自动补库] KP: {}, 题型: {}, 当前库存: {}, 需补货: {}", kpId, type.getDescription(), currentStock, gap);
// 触发异步生产逻辑 (内部带 30 分钟冷却锁)
generateQuestionDomainService.produce(kpId , Collections.singletonList(type) , QuestionSourceTypeEnum.Single_Concept , gap);
generateQuestionDomainService.produce(kpId , type , QuestionSourceTypeEnum.Single_Concept , gap);
}
}
@ -99,7 +99,7 @@ public class QuestionInventoryDomainServiceImpl implements QuestionInventoryDoma
int gap = targetLine - currentStock;
log.info(">>> [自动补库] 簇: {}, 类型: 复合多选, 当前库存: {}, 需补货: {}", clusterId, currentStock, gap);
// 簇维度触发,触发异步生产逻辑
generateQuestionDomainService.produce(clusterId , Collections.singletonList(QuestionTypeEnum.MULTIPLE_CHOICE) , QuestionSourceTypeEnum.Multi_Concept , gap);
generateQuestionDomainService.produce(clusterId , QuestionTypeEnum.MULTIPLE_CHOICE , QuestionSourceTypeEnum.Multi_Concept , gap);
}
}

Loading…
Cancel
Save