From 7aa094b397bc46e11084fcc67cff9183dad6216b Mon Sep 17 00:00:00 2001 From: luogw <3132758203@qq.com> Date: Fri, 3 Jul 2026 16:42:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A5=97=E9=A2=98=E6=A0=91=E5=BD=A2=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Impl/SearchAppealDomainServiceImpl.java | 3 ++ .../ClassicCategoryApplicationService.java | 2 +- ...ClassicCategoryApplicationServiceImpl.java | 44 +++++++++++++++---- .../controller/ClassicCategoryController.java | 8 ++-- .../controller/ClassicPaperController.java | 2 - .../controller/ClassicPaperSetController.java | 3 -- .../domain/dto/ClassicCategoryDTO.java | 3 ++ 7 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/project/appeal/domain/service/Impl/SearchAppealDomainServiceImpl.java b/src/main/java/com/project/appeal/domain/service/Impl/SearchAppealDomainServiceImpl.java index 9cf23bb..9069f2a 100644 --- a/src/main/java/com/project/appeal/domain/service/Impl/SearchAppealDomainServiceImpl.java +++ b/src/main/java/com/project/appeal/domain/service/Impl/SearchAppealDomainServiceImpl.java @@ -153,6 +153,9 @@ public class SearchAppealDomainServiceImpl implements SearchAppealDomainService }); //查询知识点,构建知识点字段 + if (kpIdSet.isEmpty()) { + return appealDTOList; + } Map kpIdToEntityMap = taskKnowledgePointBaseService.listByIds(kpIdSet).stream() .collect(Collectors.toMap( TaskKnowledgePointEntity::getId, diff --git a/src/main/java/com/project/classicpaper/application/ClassicCategoryApplicationService.java b/src/main/java/com/project/classicpaper/application/ClassicCategoryApplicationService.java index 96d1dad..93345ce 100644 --- a/src/main/java/com/project/classicpaper/application/ClassicCategoryApplicationService.java +++ b/src/main/java/com/project/classicpaper/application/ClassicCategoryApplicationService.java @@ -7,7 +7,7 @@ import java.util.List; public interface ClassicCategoryApplicationService { - Result> treeList(); + Result> treeList(Boolean withPaperSet); Result save(ClassicCategoryDTO dto) throws Exception; diff --git a/src/main/java/com/project/classicpaper/application/impl/ClassicCategoryApplicationServiceImpl.java b/src/main/java/com/project/classicpaper/application/impl/ClassicCategoryApplicationServiceImpl.java index 94109b0..c851ab1 100644 --- a/src/main/java/com/project/classicpaper/application/impl/ClassicCategoryApplicationServiceImpl.java +++ b/src/main/java/com/project/classicpaper/application/impl/ClassicCategoryApplicationServiceImpl.java @@ -7,6 +7,7 @@ import com.project.base.domain.result.Result; import com.project.base.domain.utils.TreeUtils; import com.project.classicpaper.application.ClassicCategoryApplicationService; import com.project.classicpaper.domain.dto.ClassicCategoryDTO; +import com.project.classicpaper.domain.dto.ClassicPaperSetDTO; import com.project.classicpaper.domain.entity.ClassicCategoryEntity; import com.project.classicpaper.domain.entity.ClassicPaperSetEntity; import com.project.classicpaper.domain.service.ClassicCategoryBaseService; @@ -14,10 +15,7 @@ import com.project.classicpaper.domain.service.ClassicPaperSetBaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; @Service @@ -30,7 +28,7 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp private ClassicPaperSetBaseService classicPaperSetBaseService; @Override - public Result> treeList() { + public Result> treeList(Boolean withPaperSet) { // 1. 查所有分类 → DTO List list = classicCategoryBaseService.list( new LambdaQueryWrapper().orderByAsc(ClassicCategoryEntity::getSort) @@ -43,12 +41,13 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp ClassicCategoryDTO::getParentId, ClassicCategoryDTO::setChildrenList); - // 3. 统计各分类下的套题组数量 - List allSets = classicPaperSetBaseService.lambdaQuery() - .select(ClassicPaperSetEntity::getClassicCategoryId) + // 3. 查询所有套题组(只查必要字段),同时用于统计数量和填充列表 + List allPaperSets = classicPaperSetBaseService.lambdaQuery() + .select(ClassicPaperSetEntity::getClassicCategoryId,ClassicPaperSetEntity::getId, ClassicPaperSetEntity::getName) + .orderByDesc(ClassicPaperSetEntity::getId) .list(); Map countMap = new HashMap<>(); - for (ClassicPaperSetEntity set : allSets) { + for (ClassicPaperSetEntity set : allPaperSets) { Long catId = set.getClassicCategoryId(); if (catId != null) { countMap.merge(catId, 1, Integer::sum); @@ -58,6 +57,17 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp // 4. 注入 paperSetCount 到树节点 injectPaperSetCount(tree, countMap); + if (Boolean.TRUE.equals(withPaperSet)) { + // 5. 按分类ID分组套题组 + Map> paperSetMap = allPaperSets.stream() + .filter(s -> s.getClassicCategoryId() != null) + .map(s -> s.toDTO(ClassicPaperSetDTO::new)) + .collect(Collectors.groupingBy(ClassicPaperSetDTO::getClassicCategoryId)); + + // 6. 注入套题组到二级分类 + injectPaperList(tree, paperSetMap); + } + return Result.success(tree); } @@ -81,6 +91,22 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp } } + /** + * 递归注入套题组列表: + * 仅二级分类(level == 2)填充 childrenClassicPaperList + */ + private void injectPaperList(List nodes, Map> paperSetMap) { + for (ClassicCategoryDTO node : nodes) { + if (node.getChildrenList() != null && !node.getChildrenList().isEmpty()) { + // 一级分类:递归处理子节点 + injectPaperList(node.getChildrenList(), paperSetMap); + } else if (node.getLevel() != null && node.getLevel() == 2) { + // 二级分类:填充套题组列表 + node.setClassicPaperSetList(paperSetMap.getOrDefault(node.getId(), new ArrayList<>())); + } + } + } + @Override public Result save(ClassicCategoryDTO dto) throws Exception { if (StrUtil.isBlank(dto.getName())) { diff --git a/src/main/java/com/project/classicpaper/controller/ClassicCategoryController.java b/src/main/java/com/project/classicpaper/controller/ClassicCategoryController.java index db27fb5..0f15e19 100644 --- a/src/main/java/com/project/classicpaper/controller/ClassicCategoryController.java +++ b/src/main/java/com/project/classicpaper/controller/ClassicCategoryController.java @@ -3,12 +3,12 @@ package com.project.classicpaper.controller; import com.project.base.domain.result.Result; import com.project.classicpaper.application.ClassicCategoryApplicationService; import com.project.classicpaper.domain.dto.ClassicCategoryDTO; -import com.project.operation.annotation.OperationLog; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -22,18 +22,16 @@ public class ClassicCategoryController { private ClassicCategoryApplicationService classicCategoryApplicationService; @GetMapping("/treeList") - public Result> treeList() { - return classicCategoryApplicationService.treeList(); + public Result> treeList(@RequestParam(required = false, defaultValue = "false") Boolean withPaperSet) { + return classicCategoryApplicationService.treeList(withPaperSet); } @PostMapping("/save") - @OperationLog(module = "经典分类") public Result save(ClassicCategoryDTO dto) throws Exception { return classicCategoryApplicationService.save(dto); } @PostMapping("/delete") - @OperationLog(module = "经典分类") public Result delete(Long id) throws Exception { return classicCategoryApplicationService.delete(id); } diff --git a/src/main/java/com/project/classicpaper/controller/ClassicPaperController.java b/src/main/java/com/project/classicpaper/controller/ClassicPaperController.java index 9529384..ffed3ac 100644 --- a/src/main/java/com/project/classicpaper/controller/ClassicPaperController.java +++ b/src/main/java/com/project/classicpaper/controller/ClassicPaperController.java @@ -23,7 +23,6 @@ public class ClassicPaperController { * 单题重新生题(同步):等待算法返回结果,适合响应快的场景 */ @PostMapping("/regenerateQuestion") - @OperationLog(module = "经典套题") public Result regenerateQuestion(Long paperId, Long paperQuestionId) throws Exception { return classicPaperApplicationService.regenerateQuestion(paperId, paperQuestionId); } @@ -32,7 +31,6 @@ public class ClassicPaperController { * 单题重新生题(异步):立即返回,前端通过轮询状态接口获取结果 */ @PostMapping("/regenerateQuestion/async") - @OperationLog(module = "经典套题") public Result regenerateQuestionAsync(Long paperQuestionId) throws Exception { classicPaperApplicationService.regenerateQuestionAsync(paperQuestionId); return Result.success("接收成功"); diff --git a/src/main/java/com/project/classicpaper/controller/ClassicPaperSetController.java b/src/main/java/com/project/classicpaper/controller/ClassicPaperSetController.java index 2e6c6e9..0ddd55b 100644 --- a/src/main/java/com/project/classicpaper/controller/ClassicPaperSetController.java +++ b/src/main/java/com/project/classicpaper/controller/ClassicPaperSetController.java @@ -22,7 +22,6 @@ public class ClassicPaperSetController { private ClassicPaperSetApplicationService classicPaperSetApplicationService; @PostMapping("/generate") - @OperationLog(module = "经典套题") public Result generate(ClassicPaperSetDTO request) throws Exception { return classicPaperSetApplicationService.generate(request); } @@ -46,7 +45,6 @@ public class ClassicPaperSetController { * @param paperName 套卷名称(可选,为空时取 Word 文档标题) */ @PostMapping("/importWord") - @OperationLog(module = "经典套题") public Result importFromWord(@RequestParam("file") MultipartFile file, @RequestParam("classicCategoryId") Long classicCategoryId, @RequestParam(value = "paperName", required = false) String paperName) throws Exception { @@ -54,7 +52,6 @@ public class ClassicPaperSetController { } @PostMapping("/delete") - @OperationLog(module = "经典套题") public Result delete(List ids) throws Exception { return classicPaperSetApplicationService.delete(ids); } diff --git a/src/main/java/com/project/classicpaper/domain/dto/ClassicCategoryDTO.java b/src/main/java/com/project/classicpaper/domain/dto/ClassicCategoryDTO.java index 3ac90bc..9f56405 100644 --- a/src/main/java/com/project/classicpaper/domain/dto/ClassicCategoryDTO.java +++ b/src/main/java/com/project/classicpaper/domain/dto/ClassicCategoryDTO.java @@ -25,4 +25,7 @@ public class ClassicCategoryDTO extends BaseDTO { private Integer paperSetCount = 0; private List childrenList = new ArrayList<>(); + + /** 二级分类下的套题组 */ + private List ClassicPaperSetList = new ArrayList<>(); }