From b97f397bb027a994ad4150512b91ae20c703979d Mon Sep 17 00:00:00 2001 From: luogw <3132758203@qq.com> Date: Mon, 16 Mar 2026 10:18:11 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ding/utils/ChineseNameEncryptUtil.java | 4 ++-- .../impl/AlgorithmApplicationServiceImpl.java | 4 +--- .../PostToGenerateQuestionDomainService.java | 2 +- ...stToGenerateQuestionDomainServiceImpl.java | 12 +++++------ .../impl/SaveClusterDomainServiceImpl.java | 21 +++++++++++++------ .../GenerateQuestionDomainService.java | 4 +--- .../GenerateQuestionDomainServiceImpl.java | 11 +++++----- .../QuestionInventoryDomainServiceImpl.java | 4 ++-- 8 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/project/ding/utils/ChineseNameEncryptUtil.java b/src/main/java/com/project/ding/utils/ChineseNameEncryptUtil.java index 195b80a..7727e12 100644 --- a/src/main/java/com/project/ding/utils/ChineseNameEncryptUtil.java +++ b/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); }; } } \ No newline at end of file diff --git a/src/main/java/com/project/interaction/application/impl/AlgorithmApplicationServiceImpl.java b/src/main/java/com/project/interaction/application/impl/AlgorithmApplicationServiceImpl.java index 8385b8f..6e1088f 100644 --- a/src/main/java/com/project/interaction/application/impl/AlgorithmApplicationServiceImpl.java +++ b/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 dtoList, QuestionTypeEnum questionType, int num) throws Exception { - postToGenerateQuestionDomainService.postToGenerateQuestion(dtoList , Collections.singletonList(questionType), num); + postToGenerateQuestionDomainService.postToGenerateQuestion(dtoList , questionType , num); } diff --git a/src/main/java/com/project/interaction/domain/service/PostToGenerateQuestionDomainService.java b/src/main/java/com/project/interaction/domain/service/PostToGenerateQuestionDomainService.java index 7030adb..385aaad 100644 --- a/src/main/java/com/project/interaction/domain/service/PostToGenerateQuestionDomainService.java +++ b/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 dtoList, List questionTypeEnumList, int num) throws Exception; + void postToGenerateQuestion(List dtoList, QuestionTypeEnum questionType, int num) throws Exception; } diff --git a/src/main/java/com/project/interaction/domain/service/impl/PostToGenerateQuestionDomainServiceImpl.java b/src/main/java/com/project/interaction/domain/service/impl/PostToGenerateQuestionDomainServiceImpl.java index b9e15ba..94a2264 100644 --- a/src/main/java/com/project/interaction/domain/service/impl/PostToGenerateQuestionDomainServiceImpl.java +++ b/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 dtoList, List questionTypeEnumList, int num) throws Exception { + public void postToGenerateQuestion(List 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 dtoList, List questionTypeEnumList, int num,String parseName){ - List questionTypeEnumStringList = questionTypeEnumList.stream().map(QuestionTypeEnum::getDescription).toList(); - + private GenerateQuestionResponseDTO callAlgorithmService(List dtoList, QuestionTypeEnum questionType, int num,String parseName){ // 获取知识点内容 List kpIds = dtoList.stream().map(TaskKnowledgePointDTO::getId).collect(Collectors.toList()); List 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(); // 调用算法服务 diff --git a/src/main/java/com/project/interaction/domain/service/impl/SaveClusterDomainServiceImpl.java b/src/main/java/com/project/interaction/domain/service/impl/SaveClusterDomainServiceImpl.java index 92231cb..6c3c93f 100644 --- a/src/main/java/com/project/interaction/domain/service/impl/SaveClusterDomainServiceImpl.java +++ b/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 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 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); } } } diff --git a/src/main/java/com/project/question/domain/service/GenerateQuestionDomainService.java b/src/main/java/com/project/question/domain/service/GenerateQuestionDomainService.java index 01c0dcd..6e8b3bc 100644 --- a/src/main/java/com/project/question/domain/service/GenerateQuestionDomainService.java +++ b/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 questionTypeEnumList , QuestionSourceTypeEnum sourceType, int needCount); + void produce(Long sourceId, QuestionTypeEnum questionType , QuestionSourceTypeEnum sourceType, int needCount); } diff --git a/src/main/java/com/project/question/domain/service/impl/GenerateQuestionDomainServiceImpl.java b/src/main/java/com/project/question/domain/service/impl/GenerateQuestionDomainServiceImpl.java index 3afb9d9..112c536 100644 --- a/src/main/java/com/project/question/domain/service/impl/GenerateQuestionDomainServiceImpl.java +++ b/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 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 questionTypeEnumList , QuestionSourceTypeEnum sourceType, int count) throws Exception{ + private void processBatch(Long sourceId, QuestionTypeEnum questionType , QuestionSourceTypeEnum sourceType, int count) throws Exception{ // 如果是簇复合题,执行随机采样 2-4 个知识点 List 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); } } } diff --git a/src/main/java/com/project/question/domain/service/impl/QuestionInventoryDomainServiceImpl.java b/src/main/java/com/project/question/domain/service/impl/QuestionInventoryDomainServiceImpl.java index c31e7ce..b57818c 100644 --- a/src/main/java/com/project/question/domain/service/impl/QuestionInventoryDomainServiceImpl.java +++ b/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); } }