Browse Source

套题集不分页查询

master
luoweijian 2 months ago
parent
commit
ad4b0f3924
  1. 3
      src/main/java/com/project/classicpaper/domain/service/impl/ClassicPaperQuestionCallbackServiceImpl.java
  2. 54
      src/main/java/com/project/classicpaper/domain/service/impl/RegenerateQuestionDomainServiceImpl.java
  3. 3
      src/main/java/com/project/information/application/DraftReviewApplicationService.java
  4. 19
      src/main/java/com/project/information/application/impl/DraftReviewApplicationServiceImpl.java
  5. 7
      src/main/java/com/project/information/controller/InformationController.java
  6. 32
      src/main/java/com/project/information/domain/dto/KnowledgePointDraftDTO.java

3
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<RegenerateQuestionTaskEntity> taskWrapper = com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<RegenerateQuestionTaskEntity> taskWrapper =
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>(); new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<>();
taskWrapper.eq(RegenerateQuestionTaskEntity::getPaperQuestionId, paperQuestionId) taskWrapper.eq(RegenerateQuestionTaskEntity::getPaperQuestionId, paperQuestionId)
.eq(RegenerateQuestionTaskEntity::getStatus, 0); .eq(RegenerateQuestionTaskEntity::getStatus, 0)
.last("LIMIT 1");
RegenerateQuestionTaskEntity regenTask = regenerateQuestionTaskBaseService.getOne(taskWrapper); RegenerateQuestionTaskEntity regenTask = regenerateQuestionTaskBaseService.getOne(taskWrapper);
if (regenTask != null) { if (regenTask != null) {
regenTask.setStatus(1); regenTask.setStatus(1);

54
src/main/java/com/project/classicpaper/domain/service/impl/RegenerateQuestionDomainServiceImpl.java

@ -186,7 +186,7 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo
log.info(">>> [经典套题-重新生题-异步][备用池] 直接替换成功, paperQuestionId={}, newQuestionId={}", log.info(">>> [经典套题-重新生题-异步][备用池] 直接替换成功, paperQuestionId={}, newQuestionId={}",
paperQuestionId, spareQuestion.getId()); paperQuestionId, spareQuestion.getId());
} }
return; // 直接返回,前端通过 getDetail 刷新 return;
} }
// 1. 前置校验(快速失败,不占用异步线程) // 1. 前置校验(快速失败,不占用异步线程)
@ -218,7 +218,11 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo
taskEntity.setStatus(0); // 进行中 taskEntity.setStatus(0); // 进行中
regenerateQuestionTaskBaseService.save(taskEntity); regenerateQuestionTaskBaseService.save(taskEntity);
// 4. 异步执行重新生题逻辑 // 4. 清空 questionId,让回调走提拔分支
paperQuestion.setQuestionId(null);
classicPaperQuestionBaseService.updateById(paperQuestion);
// 5. 异步执行重新生题逻辑(回调会提拔新题 + 更新 task 状态)
CompletableFuture.runAsync(() -> doRegenerateAsync(taskId, paperQuestionId), regenerateExecutor); CompletableFuture.runAsync(() -> doRegenerateAsync(taskId, paperQuestionId), regenerateExecutor);
log.info(">>> [经典套题-重新生题-异步] 任务已提交, taskId={}, paperId={}, paperQuestionId={}", taskId, paperId, paperQuestionId); log.info(">>> [经典套题-重新生题-异步] 任务已提交, taskId={}, paperId={}, paperQuestionId={}", taskId, paperId, paperQuestionId);
@ -242,11 +246,7 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo
throw new BusinessErrorException("关联知识点数据不存在"); throw new BusinessErrorException("关联知识点数据不存在");
} }
// 3. 清空 questionId,让回调走提拔分支 // 异步提交生题任务(回调会提拔新题 + 更新 task 状态)
paperQuestion.setQuestionId(null);
classicPaperQuestionBaseService.updateById(paperQuestion);
// 4. 异步提交生题任务(回调会提拔新题 + 更新 task 状态)
QuestionTypeEnum questionType = QuestionTypeEnum.findByValue(originalQuestion.getQuestionType()); QuestionTypeEnum questionType = QuestionTypeEnum.findByValue(originalQuestion.getQuestionType());
Long clusterId = knowledgePoints.get(0).getClusterId(); Long clusterId = knowledgePoints.get(0).getClusterId();
classicPaperQuestionGenerator.generateAsync( classicPaperQuestionGenerator.generateAsync(
@ -256,31 +256,37 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo
taskId, paperQuestionId, questionType); taskId, paperQuestionId, questionType);
} catch (Exception e) { } catch (Exception e) {
log.error(">>> [经典套题-重新生题-异步] 提交失败, taskId={}", taskId, e); log.error(">>> [经典套题-重新生题-异步] 提交失败, taskId={}", taskId, e);
RegenerateQuestionTaskEntity taskEntity = regenerateQuestionTaskBaseService.getOne( try {
new LambdaQueryWrapper<RegenerateQuestionTaskEntity>() RegenerateQuestionTaskEntity taskEntity = regenerateQuestionTaskBaseService.getOne(
.eq(RegenerateQuestionTaskEntity::getTaskId, taskId)); new LambdaQueryWrapper<RegenerateQuestionTaskEntity>()
if (taskEntity != null) { .eq(RegenerateQuestionTaskEntity::getTaskId, taskId)
taskEntity.setStatus(2); .last("LIMIT 1"));
taskEntity.setErrorMessage(e.getMessage()); if (taskEntity != null) {
regenerateQuestionTaskBaseService.updateById(taskEntity); taskEntity.setStatus(2);
taskEntity.setErrorMessage(e.getMessage());
regenerateQuestionTaskBaseService.updateById(taskEntity);
}
} catch (Exception dbError) {
log.error(">>> [经典套题-重新生题-异步] 更新任务状态失败, taskId={}", taskId, dbError);
} }
} }
} }
@Override @Override
public Map<String, Object> getTaskStatus(Long paperQuestionId) { public Map<String, Object> getTaskStatus(Long paperQuestionId) {
RegenerateQuestionTaskEntity taskEntity = regenerateQuestionTaskBaseService.getOne( ClassicPaperQuestionEntity paperQuestion = classicPaperQuestionBaseService.getById(paperQuestionId);
new LambdaQueryWrapper<RegenerateQuestionTaskEntity>() if (paperQuestion == null) {
.eq(RegenerateQuestionTaskEntity::getPaperQuestionId, paperQuestionId)
.orderByDesc(RegenerateQuestionTaskEntity::getCreateTime)
.last("LIMIT 1"));
if (taskEntity == null) {
return null; return null;
} }
Map<String, Object> result = new java.util.HashMap<>(); Map<String, Object> result = new java.util.HashMap<>();
result.put("status", taskEntity.getStatus()); if (paperQuestion.getQuestionId() != null) {
result.put("newQuestionId", taskEntity.getNewQuestionId()); result.put("status", 1); // 成功
result.put("errorMessage", taskEntity.getErrorMessage()); result.put("newQuestionId", paperQuestion.getQuestionId());
} else {
result.put("status", 0); // 进行中
result.put("newQuestionId", null);
}
result.put("errorMessage", null);
return result; return result;
} }
@ -372,7 +378,7 @@ public class RegenerateQuestionDomainServiceImpl implements RegenerateQuestionDo
QuestionTypeEnum questionType = QuestionTypeEnum.findByValue(original.getQuestionType()); QuestionTypeEnum questionType = QuestionTypeEnum.findByValue(original.getQuestionType());
classicPaperQuestionGenerator.generateAsync( classicPaperQuestionGenerator.generateAsync(
paperQuestionId, kps, questionType, replenishCount, null); paperQuestionId, kps, questionType, replenishCount, kps.get(0).getClusterId());
log.info(">>> [备用补充] 已提交补充任务, paperQuestionId={}, 数量={}", log.info(">>> [备用补充] 已提交补充任务, paperQuestionId={}, 数量={}",
paperQuestionId, replenishCount); paperQuestionId, replenishCount);
} catch (Exception e) { } catch (Exception e) {

3
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.base.domain.result.Result;
import com.project.information.domain.dto.DraftSaveDTO; import com.project.information.domain.dto.DraftSaveDTO;
import com.project.information.domain.dto.KnowledgePointDraftDTO;
import com.project.information.domain.entity.KnowledgePointDraftEntity; import com.project.information.domain.entity.KnowledgePointDraftEntity;
import java.util.List; import java.util.List;
@ -11,7 +12,7 @@ import java.util.List;
*/ */
public interface DraftReviewApplicationService { public interface DraftReviewApplicationService {
Result<List<KnowledgePointDraftEntity>> listDrafts(Long informationId); Result<List<KnowledgePointDraftDTO>> listDrafts(Long informationId);
Result<String> updateDraft(Long draftId, String content); Result<String> updateDraft(Long draftId, String content);

19
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.application.DraftReviewApplicationService;
import com.project.information.domain.dto.DraftSaveDTO; import com.project.information.domain.dto.DraftSaveDTO;
import com.project.information.domain.dto.KnowledgePointDTO; 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.InformationEntity;
import com.project.information.domain.entity.KnowledgeClusterEntity; import com.project.information.domain.entity.KnowledgeClusterEntity;
import com.project.information.domain.entity.KnowledgePointDraftEntity; import com.project.information.domain.entity.KnowledgePointDraftEntity;
@ -61,8 +62,10 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication
@Autowired @Autowired
private CustomIdGenerator customIdGenerator; private CustomIdGenerator customIdGenerator;
@Override @Override
public Result<List<KnowledgePointDraftEntity>> listDrafts(Long informationId) { public Result<List<KnowledgePointDraftDTO>> listDrafts(Long informationId) {
if (informationId == null) { if (informationId == null) {
throw new BusinessErrorException("资料ID不能为空"); throw new BusinessErrorException("资料ID不能为空");
} }
@ -70,7 +73,19 @@ public class DraftReviewApplicationServiceImpl implements DraftReviewApplication
new LambdaQueryWrapper<KnowledgePointDraftEntity>() new LambdaQueryWrapper<KnowledgePointDraftEntity>()
.eq(KnowledgePointDraftEntity::getInformationId, informationId) .eq(KnowledgePointDraftEntity::getInformationId, informationId)
.orderByAsc(KnowledgePointDraftEntity::getId)); .orderByAsc(KnowledgePointDraftEntity::getId));
return Result.success(drafts); List<KnowledgePointDraftDTO> 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 @Override

7
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.KnowledgePointApplicationService;
import com.project.information.application.ProductLineApplicationService; import com.project.information.application.ProductLineApplicationService;
import com.project.information.application.UploadFilesApplicationService; import com.project.information.application.UploadFilesApplicationService;
import com.project.information.domain.dto.UploadedFileDTO; import com.project.information.domain.dto.*;
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.entity.KnowledgePointDraftEntity; import com.project.information.domain.entity.KnowledgePointDraftEntity;
import com.project.information.domain.param.CheckDuplicatesParam; import com.project.information.domain.param.CheckDuplicatesParam;
import com.project.information.domain.param.FileCheckItem; import com.project.information.domain.param.FileCheckItem;
@ -96,7 +93,7 @@ public class InformationController {
* 查询草稿列表 * 查询草稿列表
*/ */
@GetMapping("/draftList") @GetMapping("/draftList")
public Result<List<KnowledgePointDraftEntity>> draftList(Long informationId) { public Result<List<KnowledgePointDraftDTO>> draftList(Long informationId) {
return draftReviewApplicationService.listDrafts(informationId); return draftReviewApplicationService.listDrafts(informationId);
} }

32
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();
}
Loading…
Cancel
Save