Browse Source

套题树形结构修改

master
luogw 2 months ago
parent
commit
7aa094b397
  1. 3
      src/main/java/com/project/appeal/domain/service/Impl/SearchAppealDomainServiceImpl.java
  2. 2
      src/main/java/com/project/classicpaper/application/ClassicCategoryApplicationService.java
  3. 44
      src/main/java/com/project/classicpaper/application/impl/ClassicCategoryApplicationServiceImpl.java
  4. 8
      src/main/java/com/project/classicpaper/controller/ClassicCategoryController.java
  5. 2
      src/main/java/com/project/classicpaper/controller/ClassicPaperController.java
  6. 3
      src/main/java/com/project/classicpaper/controller/ClassicPaperSetController.java
  7. 3
      src/main/java/com/project/classicpaper/domain/dto/ClassicCategoryDTO.java

3
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<Long, TaskKnowledgePointEntity> kpIdToEntityMap = taskKnowledgePointBaseService.listByIds(kpIdSet).stream() Map<Long, TaskKnowledgePointEntity> kpIdToEntityMap = taskKnowledgePointBaseService.listByIds(kpIdSet).stream()
.collect(Collectors.toMap( .collect(Collectors.toMap(
TaskKnowledgePointEntity::getId, TaskKnowledgePointEntity::getId,

2
src/main/java/com/project/classicpaper/application/ClassicCategoryApplicationService.java

@ -7,7 +7,7 @@ import java.util.List;
public interface ClassicCategoryApplicationService { public interface ClassicCategoryApplicationService {
Result<List<ClassicCategoryDTO>> treeList(); Result<List<ClassicCategoryDTO>> treeList(Boolean withPaperSet);
Result<ClassicCategoryDTO> save(ClassicCategoryDTO dto) throws Exception; Result<ClassicCategoryDTO> save(ClassicCategoryDTO dto) throws Exception;

44
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.base.domain.utils.TreeUtils;
import com.project.classicpaper.application.ClassicCategoryApplicationService; import com.project.classicpaper.application.ClassicCategoryApplicationService;
import com.project.classicpaper.domain.dto.ClassicCategoryDTO; 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.ClassicCategoryEntity;
import com.project.classicpaper.domain.entity.ClassicPaperSetEntity; import com.project.classicpaper.domain.entity.ClassicPaperSetEntity;
import com.project.classicpaper.domain.service.ClassicCategoryBaseService; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@ -30,7 +28,7 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp
private ClassicPaperSetBaseService classicPaperSetBaseService; private ClassicPaperSetBaseService classicPaperSetBaseService;
@Override @Override
public Result<List<ClassicCategoryDTO>> treeList() { public Result<List<ClassicCategoryDTO>> treeList(Boolean withPaperSet) {
// 1. 查所有分类 → DTO // 1. 查所有分类 → DTO
List<ClassicCategoryDTO> list = classicCategoryBaseService.list( List<ClassicCategoryDTO> list = classicCategoryBaseService.list(
new LambdaQueryWrapper<ClassicCategoryEntity>().orderByAsc(ClassicCategoryEntity::getSort) new LambdaQueryWrapper<ClassicCategoryEntity>().orderByAsc(ClassicCategoryEntity::getSort)
@ -43,12 +41,13 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp
ClassicCategoryDTO::getParentId, ClassicCategoryDTO::getParentId,
ClassicCategoryDTO::setChildrenList); ClassicCategoryDTO::setChildrenList);
// 3. 统计各分类下的套题组数量 // 3. 查询所有套题组(只查必要字段),同时用于统计数量和填充列表
List<ClassicPaperSetEntity> allSets = classicPaperSetBaseService.lambdaQuery() List<ClassicPaperSetEntity> allPaperSets = classicPaperSetBaseService.lambdaQuery()
.select(ClassicPaperSetEntity::getClassicCategoryId) .select(ClassicPaperSetEntity::getClassicCategoryId,ClassicPaperSetEntity::getId, ClassicPaperSetEntity::getName)
.orderByDesc(ClassicPaperSetEntity::getId)
.list(); .list();
Map<Long, Integer> countMap = new HashMap<>(); Map<Long, Integer> countMap = new HashMap<>();
for (ClassicPaperSetEntity set : allSets) { for (ClassicPaperSetEntity set : allPaperSets) {
Long catId = set.getClassicCategoryId(); Long catId = set.getClassicCategoryId();
if (catId != null) { if (catId != null) {
countMap.merge(catId, 1, Integer::sum); countMap.merge(catId, 1, Integer::sum);
@ -58,6 +57,17 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp
// 4. 注入 paperSetCount 到树节点 // 4. 注入 paperSetCount 到树节点
injectPaperSetCount(tree, countMap); injectPaperSetCount(tree, countMap);
if (Boolean.TRUE.equals(withPaperSet)) {
// 5. 按分类ID分组套题组
Map<Long, List<ClassicPaperSetDTO>> 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); return Result.success(tree);
} }
@ -81,6 +91,22 @@ public class ClassicCategoryApplicationServiceImpl implements ClassicCategoryApp
} }
} }
/**
* 递归注入套题组列表
* 仅二级分类level == 2填充 childrenClassicPaperList
*/
private void injectPaperList(List<ClassicCategoryDTO> nodes, Map<Long, List<ClassicPaperSetDTO>> 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 @Override
public Result<ClassicCategoryDTO> save(ClassicCategoryDTO dto) throws Exception { public Result<ClassicCategoryDTO> save(ClassicCategoryDTO dto) throws Exception {
if (StrUtil.isBlank(dto.getName())) { if (StrUtil.isBlank(dto.getName())) {

8
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.base.domain.result.Result;
import com.project.classicpaper.application.ClassicCategoryApplicationService; import com.project.classicpaper.application.ClassicCategoryApplicationService;
import com.project.classicpaper.domain.dto.ClassicCategoryDTO; import com.project.classicpaper.domain.dto.ClassicCategoryDTO;
import com.project.operation.annotation.OperationLog;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@ -22,18 +22,16 @@ public class ClassicCategoryController {
private ClassicCategoryApplicationService classicCategoryApplicationService; private ClassicCategoryApplicationService classicCategoryApplicationService;
@GetMapping("/treeList") @GetMapping("/treeList")
public Result<List<ClassicCategoryDTO>> treeList() { public Result<List<ClassicCategoryDTO>> treeList(@RequestParam(required = false, defaultValue = "false") Boolean withPaperSet) {
return classicCategoryApplicationService.treeList(); return classicCategoryApplicationService.treeList(withPaperSet);
} }
@PostMapping("/save") @PostMapping("/save")
@OperationLog(module = "经典分类")
public Result<ClassicCategoryDTO> save(ClassicCategoryDTO dto) throws Exception { public Result<ClassicCategoryDTO> save(ClassicCategoryDTO dto) throws Exception {
return classicCategoryApplicationService.save(dto); return classicCategoryApplicationService.save(dto);
} }
@PostMapping("/delete") @PostMapping("/delete")
@OperationLog(module = "经典分类")
public Result<String> delete(Long id) throws Exception { public Result<String> delete(Long id) throws Exception {
return classicCategoryApplicationService.delete(id); return classicCategoryApplicationService.delete(id);
} }

2
src/main/java/com/project/classicpaper/controller/ClassicPaperController.java

@ -23,7 +23,6 @@ public class ClassicPaperController {
* 单题重新生题同步等待算法返回结果适合响应快的场景 * 单题重新生题同步等待算法返回结果适合响应快的场景
*/ */
@PostMapping("/regenerateQuestion") @PostMapping("/regenerateQuestion")
@OperationLog(module = "经典套题")
public Result<ClassicPaperQuestionDTO> regenerateQuestion(Long paperId, Long paperQuestionId) throws Exception { public Result<ClassicPaperQuestionDTO> regenerateQuestion(Long paperId, Long paperQuestionId) throws Exception {
return classicPaperApplicationService.regenerateQuestion(paperId, paperQuestionId); return classicPaperApplicationService.regenerateQuestion(paperId, paperQuestionId);
} }
@ -32,7 +31,6 @@ public class ClassicPaperController {
* 单题重新生题异步立即返回前端通过轮询状态接口获取结果 * 单题重新生题异步立即返回前端通过轮询状态接口获取结果
*/ */
@PostMapping("/regenerateQuestion/async") @PostMapping("/regenerateQuestion/async")
@OperationLog(module = "经典套题")
public Result<String> regenerateQuestionAsync(Long paperQuestionId) throws Exception { public Result<String> regenerateQuestionAsync(Long paperQuestionId) throws Exception {
classicPaperApplicationService.regenerateQuestionAsync(paperQuestionId); classicPaperApplicationService.regenerateQuestionAsync(paperQuestionId);
return Result.success("接收成功"); return Result.success("接收成功");

3
src/main/java/com/project/classicpaper/controller/ClassicPaperSetController.java

@ -22,7 +22,6 @@ public class ClassicPaperSetController {
private ClassicPaperSetApplicationService classicPaperSetApplicationService; private ClassicPaperSetApplicationService classicPaperSetApplicationService;
@PostMapping("/generate") @PostMapping("/generate")
@OperationLog(module = "经典套题")
public Result<ClassicPaperSetDTO> generate(ClassicPaperSetDTO request) throws Exception { public Result<ClassicPaperSetDTO> generate(ClassicPaperSetDTO request) throws Exception {
return classicPaperSetApplicationService.generate(request); return classicPaperSetApplicationService.generate(request);
} }
@ -46,7 +45,6 @@ public class ClassicPaperSetController {
* @param paperName 套卷名称可选为空时取 Word 文档标题 * @param paperName 套卷名称可选为空时取 Word 文档标题
*/ */
@PostMapping("/importWord") @PostMapping("/importWord")
@OperationLog(module = "经典套题")
public Result<ClassicPaperSetDTO> importFromWord(@RequestParam("file") MultipartFile file, public Result<ClassicPaperSetDTO> importFromWord(@RequestParam("file") MultipartFile file,
@RequestParam("classicCategoryId") Long classicCategoryId, @RequestParam("classicCategoryId") Long classicCategoryId,
@RequestParam(value = "paperName", required = false) String paperName) throws Exception { @RequestParam(value = "paperName", required = false) String paperName) throws Exception {
@ -54,7 +52,6 @@ public class ClassicPaperSetController {
} }
@PostMapping("/delete") @PostMapping("/delete")
@OperationLog(module = "经典套题")
public Result<String> delete(List<Long> ids) throws Exception { public Result<String> delete(List<Long> ids) throws Exception {
return classicPaperSetApplicationService.delete(ids); return classicPaperSetApplicationService.delete(ids);
} }

3
src/main/java/com/project/classicpaper/domain/dto/ClassicCategoryDTO.java

@ -25,4 +25,7 @@ public class ClassicCategoryDTO extends BaseDTO {
private Integer paperSetCount = 0; private Integer paperSetCount = 0;
private List<ClassicCategoryDTO> childrenList = new ArrayList<>(); private List<ClassicCategoryDTO> childrenList = new ArrayList<>();
/** 二级分类下的套题组 */
private List<ClassicPaperSetDTO> ClassicPaperSetList = new ArrayList<>();
} }

Loading…
Cancel
Save