From ad4b0f392408a3a4b2282b24b4429ba94fb0b548 Mon Sep 17 00:00:00 2001 From: luoweijian <1329394916@qq.com> Date: Fri, 3 Jul 2026 15:13:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A5=97=E9=A2=98=E9=9B=86=E4=B8=8D=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...assicPaperQuestionCallbackServiceImpl.java | 3 +- .../RegenerateQuestionDomainServiceImpl.java | 54 ++++++++++--------- .../DraftReviewApplicationService.java | 3 +- .../DraftReviewApplicationServiceImpl.java | 19 ++++++- .../controller/InformationController.java | 7 +-- .../domain/dto/KnowledgePointDraftDTO.java | 32 +++++++++++ 6 files changed, 85 insertions(+), 33 deletions(-) create mode 100644 src/main/java/com/project/information/domain/dto/KnowledgePointDraftDTO.java diff --git a/src/main/java/com/project/classicpaper/domain/service/impl/ClassicPaperQuestionCallbackServiceImpl.java b/src/main/java/com/project/classicpaper/domain/service/impl/ClassicPaperQuestionCallbackServiceImpl.java index e603ca4..79ad048 100644 --- a/src/main/java/com/project/classicpaper/domain/service/impl/ClassicPaperQuestionCallbackServiceImpl.java +++ b/src/main/java/com/project/classicpaper/domain/service/impl/ClassicPaperQuestionCallbackServiceImpl.java @@ -122,7 +122,8 @@ public class ClassicPaperQuestionCallbackServiceImpl implements ClassicPaperQues com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper taskWrapper = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>(); taskWrapper.eq(RegenerateQuestionTaskEntity::getPaperQuestionId, paperQuestionId) - .eq(RegenerateQuestionTaskEntity::getStatus, 0); + .eq(RegenerateQuestionTaskEntity::getStatus, 0) + .last("LIMIT 1"); RegenerateQuestionTaskEntity regenTask = regenerateQuestionTaskBaseService.getOne(taskWrapper); if (regenTask != null) { regenTask.setStatus(1); diff --git a/src/main/java/com/project/classicpaper/domain/service/impl/RegenerateQuestionDomainServiceImpl.java b/src/main/java/com/project/classicpaper/domain/service/impl/RegenerateQuestionDomainServiceImpl.java index a844fb9..74a6894 100644 --- a/src/main/java/com/project/classicpaper/domain/service/impl/RegenerateQuestionDomainServiceImpl.java +++ b/src/main/java/com/project/classicpaper/domain/service/impl/RegenerateQuestionDomainServiceImpl.java @@ -186,7 +186,7 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo log.info(">>> [经典套题-重新生题-异步][备用池] 直接替换成功, paperQuestionId={}, newQuestionId={}", paperQuestionId, spareQuestion.getId()); } - return; // 直接返回,前端通过 getDetail 刷新 + return; } // 1. 前置校验(快速失败,不占用异步线程) @@ -218,7 +218,11 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo taskEntity.setStatus(0); // 进行中 regenerateQuestionTaskBaseService.save(taskEntity); - // 4. 异步执行重新生题逻辑 + // 4. 清空 questionId,让回调走提拔分支 + paperQuestion.setQuestionId(null); + classicPaperQuestionBaseService.updateById(paperQuestion); + + // 5. 异步执行重新生题逻辑(回调会提拔新题 + 更新 task 状态) CompletableFuture.runAsync(() -> doRegenerateAsync(taskId, paperQuestionId), regenerateExecutor); log.info(">>> [经典套题-重新生题-异步] 任务已提交, taskId={}, paperId={}, paperQuestionId={}", taskId, paperId, paperQuestionId); @@ -242,11 +246,7 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo throw new BusinessErrorException("关联知识点数据不存在"); } - // 3. 清空 questionId,让回调走提拔分支 - paperQuestion.setQuestionId(null); - classicPaperQuestionBaseService.updateById(paperQuestion); - - // 4. 异步提交生题任务(回调会提拔新题 + 更新 task 状态) + // 异步提交生题任务(回调会提拔新题 + 更新 task 状态) QuestionTypeEnum questionType = QuestionTypeEnum.findByValue(originalQuestion.getQuestionType()); Long clusterId = knowledgePoints.get(0).getClusterId(); classicPaperQuestionGenerator.generateAsync( @@ -256,31 +256,37 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo taskId, paperQuestionId, questionType); } catch (Exception e) { log.error(">>> [经典套题-重新生题-异步] 提交失败, taskId={}", taskId, e); - RegenerateQuestionTaskEntity taskEntity = regenerateQuestionTaskBaseService.getOne( - new LambdaQueryWrapper() - .eq(RegenerateQuestionTaskEntity::getTaskId, taskId)); - if (taskEntity != null) { - taskEntity.setStatus(2); - taskEntity.setErrorMessage(e.getMessage()); - regenerateQuestionTaskBaseService.updateById(taskEntity); + try { + RegenerateQuestionTaskEntity taskEntity = regenerateQuestionTaskBaseService.getOne( + new LambdaQueryWrapper() + .eq(RegenerateQuestionTaskEntity::getTaskId, taskId) + .last("LIMIT 1")); + if (taskEntity != null) { + taskEntity.setStatus(2); + taskEntity.setErrorMessage(e.getMessage()); + regenerateQuestionTaskBaseService.updateById(taskEntity); + } + } catch (Exception dbError) { + log.error(">>> [经典套题-重新生题-异步] 更新任务状态失败, taskId={}", taskId, dbError); } } } @Override public Map getTaskStatus(Long paperQuestionId) { - RegenerateQuestionTaskEntity taskEntity = regenerateQuestionTaskBaseService.getOne( - new LambdaQueryWrapper() - .eq(RegenerateQuestionTaskEntity::getPaperQuestionId, paperQuestionId) - .orderByDesc(RegenerateQuestionTaskEntity::getCreateTime) - .last("LIMIT 1")); - if (taskEntity == null) { + ClassicPaperQuestionEntity paperQuestion = classicPaperQuestionBaseService.getById(paperQuestionId); + if (paperQuestion == null) { return null; } Map result = new java.util.HashMap<>(); - result.put("status", taskEntity.getStatus()); - result.put("newQuestionId", taskEntity.getNewQuestionId()); - result.put("errorMessage", taskEntity.getErrorMessage()); + if (paperQuestion.getQuestionId() != null) { + result.put("status", 1); // 成功 + result.put("newQuestionId", paperQuestion.getQuestionId()); + } else { + result.put("status", 0); // 进行中 + result.put("newQuestionId", null); + } + result.put("errorMessage", null); return result; } @@ -372,7 +378,7 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo QuestionTypeEnum questionType = QuestionTypeEnum.findByValue(original.getQuestionType()); classicPaperQuestionGenerator.generateAsync( - paperQuestionId, kps, questionType, replenishCount, null); + paperQuestionId, kps, questionType, replenishCount, kps.get(0).getClusterId()); log.info(">>> [备用补充] 已提交补充任务, paperQuestionId={}, 数量={}", paperQuestionId, replenishCount); } catch (Exception e) { diff --git a/src/main/java/com/project/information/application/DraftReviewApplicationService.java b/src/main/java/com/project/information/application/DraftReviewApplicationService.java index fca0d87..3922b8d 100644 --- a/src/main/java/com/project/information/application/DraftReviewApplicationService.java +++ b/src/main/java/com/project/information/application/DraftReviewApplicationService.java @@ -2,6 +2,7 @@ package com.project.information.application; import com.project.base.domain.result.Result; import com.project.information.domain.dto.DraftSaveDTO; +import com.project.information.domain.dto.KnowledgePointDraftDTO; import com.project.information.domain.entity.KnowledgePointDraftEntity; import java.util.List; @@ -11,7 +12,7 @@ import java.util.List; */ public interface DraftReviewApplicationService { - Result> listDrafts(Long informationId); + Result> listDrafts(Long informationId); Result updateDraft(Long draftId, String content); diff --git a/src/main/java/com/project/information/application/impl/DraftReviewApplicationServiceImpl.java b/src/main/java/com/project/information/application/impl/DraftReviewApplicationServiceImpl.java index 432298d..762f605 100644 --- a/src/main/java/com/project/information/application/impl/DraftReviewApplicationServiceImpl.java +++ b/src/main/java/com/project/information/application/impl/DraftReviewApplicationServiceImpl.java @@ -7,6 +7,7 @@ import com.project.base.domain.result.Result; import com.project.information.application.DraftReviewApplicationService; import com.project.information.domain.dto.DraftSaveDTO; import com.project.information.domain.dto.KnowledgePointDTO; +import com.project.information.domain.dto.KnowledgePointDraftDTO; import com.project.information.domain.entity.InformationEntity; import com.project.information.domain.entity.KnowledgeClusterEntity; import com.project.information.domain.entity.KnowledgePointDraftEntity; @@ -61,8 +62,10 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication @Autowired private CustomIdGenerator customIdGenerator; + + @Override - public Result> listDrafts(Long informationId) { + public Result> listDrafts(Long informationId) { if (informationId == null) { throw new BusinessErrorException("资料ID不能为空"); } @@ -70,7 +73,19 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication new LambdaQueryWrapper() .eq(KnowledgePointDraftEntity::getInformationId, informationId) .orderByAsc(KnowledgePointDraftEntity::getId)); - return Result.success(drafts); + List res = drafts.stream() + .map(entity -> entity.toDTO(KnowledgePointDraftDTO::new)) + .toList(); + + Long infoId = drafts.stream() + .findAny() + .map(KnowledgePointDraftEntity::getInformationId) + .orElse(null); // 或者 .orElse(0L) 给个默认值 + if (Objects.nonNull(infoId)) { + InformationEntity one = informationBaseService.getById(infoId); + res.forEach(dto -> dto.setInformationName(one.getName())); + } + return Result.success(res); } @Override diff --git a/src/main/java/com/project/information/controller/InformationController.java b/src/main/java/com/project/information/controller/InformationController.java index 87e50c5..dabd71b 100644 --- a/src/main/java/com/project/information/controller/InformationController.java +++ b/src/main/java/com/project/information/controller/InformationController.java @@ -10,10 +10,7 @@ import com.project.information.application.InformationApplicationService; import com.project.information.application.KnowledgePointApplicationService; import com.project.information.application.ProductLineApplicationService; import com.project.information.application.UploadFilesApplicationService; -import com.project.information.domain.dto.UploadedFileDTO; -import com.project.information.domain.dto.DraftSaveDTO; -import com.project.information.domain.dto.InformationDTO; -import com.project.information.domain.dto.ProductLineDTO; +import com.project.information.domain.dto.*; import com.project.information.domain.entity.KnowledgePointDraftEntity; import com.project.information.domain.param.CheckDuplicatesParam; import com.project.information.domain.param.FileCheckItem; @@ -96,7 +93,7 @@ public class InformationController { * 查询草稿列表 */ @GetMapping("/draftList") - public Result> draftList(Long informationId) { + public Result> draftList(Long informationId) { return draftReviewApplicationService.listDrafts(informationId); } diff --git a/src/main/java/com/project/information/domain/dto/KnowledgePointDraftDTO.java b/src/main/java/com/project/information/domain/dto/KnowledgePointDraftDTO.java new file mode 100644 index 0000000..4824023 --- /dev/null +++ b/src/main/java/com/project/information/domain/dto/KnowledgePointDraftDTO.java @@ -0,0 +1,32 @@ +package com.project.information.domain.dto; + + +import com.project.base.domain.dto.BaseDTO; +import com.project.information.domain.enums.AuditStatusEnum; + +import lombok.Data; + +@Data +public class KnowledgePointDraftDTO extends BaseDTO { + + private Long id; + + + private Long informationId; + + private String informationName; + + private String content; + + + private String aiContent; + + + private Integer knowledgeType; + + + private String parseName; + + + private Integer auditStatus = AuditStatusEnum.PENDING.getValue(); +}