From 678b9eeb6e791286df33cfe03f427f84c9ad9b63 Mon Sep 17 00:00:00 2001 From: Lqc Date: Sat, 20 Sep 2025 05:48:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E6=89=80=E6=9C=89=E9=A2=98=E7=9B=AE=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AiolPaperQuestionController.java | 159 ++++++++++++++---- 1 file changed, 125 insertions(+), 34 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperQuestionController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperQuestionController.java index 53167aa7..f5f38129 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperQuestionController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperQuestionController.java @@ -4,45 +4,39 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import org.jeecg.common.api.vo.Result; -import org.jeecg.common.system.query.QueryGenerator; -import org.jeecg.common.system.query.QueryRuleEnum; -import org.jeecg.common.util.oConvertUtils; -import org.jeecg.modules.aiol.entity.AiolPaperQuestion; -import org.jeecg.modules.aiol.entity.AiolQuestion; -import org.jeecg.modules.aiol.service.IAiolPaperQuestionService; - import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.aspect.annotation.AutoLog; +import org.jeecg.common.system.query.QueryGenerator; +import org.jeecg.modules.aiol.dto.QuestionAnswerDTO; +import org.jeecg.modules.aiol.entity.AiolPaperQuestion; +import org.jeecg.modules.aiol.entity.AiolQuestion; +import org.jeecg.modules.aiol.entity.AiolQuestionAnswer; +import org.jeecg.modules.aiol.entity.AiolQuestionOption; +import org.jeecg.modules.aiol.service.IAiolPaperQuestionService; + import lombok.extern.slf4j.Slf4j; +import org.jeecg.modules.aiol.service.IAiolQuestionAnswerService; +import org.jeecg.modules.aiol.service.IAiolQuestionOptionService; import org.jeecg.modules.aiol.service.IAiolQuestionService; -import org.jeecgframework.poi.excel.ExcelImportUtil; -import org.jeecgframework.poi.excel.def.NormalExcelConstants; -import org.jeecgframework.poi.excel.entity.ExportParams; -import org.jeecgframework.poi.excel.entity.ImportParams; -import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecg.common.system.base.controller.JeecgController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.multipart.MultipartHttpServletRequest; -import org.springframework.web.servlet.ModelAndView; -import com.alibaba.fastjson.JSON; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; -import org.jeecg.common.aspect.annotation.AutoLog; -import org.apache.shiro.authz.annotation.RequiresPermissions; - /** +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** * @Description: 试卷试题 * @Author: jeecg-boot * @Date: 2025-08-31 @@ -57,6 +51,10 @@ public class AiolPaperQuestionController extends JeecgController> queryPageList(AiolPaperQuestion aiolPaperQuestion, - @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, - @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, - HttpServletRequest req) { + @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, + @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, + HttpServletRequest req) { QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(aiolPaperQuestion, req.getParameterMap()); @@ -81,7 +79,7 @@ public class AiolPaperQuestionController extends JeecgController pageList = aiolPaperQuestionService.page(page, queryWrapper); return Result.OK(pageList); } - + /** * 添加 * @@ -129,7 +127,7 @@ public class AiolPaperQuestionController extends JeecgController paperDetail(@PathVariable String paperId) { + List list = aiolPaperQuestionService.list(new LambdaQueryWrapper().eq(AiolPaperQuestion::getPaperId, paperId)); + // 收集所有需要的 questionId + List questionIds = list.stream() + .map(AiolPaperQuestion::getQuestionId) + .collect(Collectors.toList()); + return Result.OK(convertToQuestionAnswerDTO(questionIds,aiolQuestionService,optionService,answerService)); + } + + /** + * 将题目列表转换为题目答案DTO映射 + * + * @param questionIds 题目id列表 + * @param aiolQuestionService 题目服务 + * @param optionService 选项服务 + * @param answerService 答案服务 + * @return 题目答案DTO映射,key为题目ID + */ + public static Collection convertToQuestionAnswerDTO( + List questionIds, + IAiolQuestionService aiolQuestionService, + IAiolQuestionOptionService optionService, + IAiolQuestionAnswerService answerService) { + + // 批量查询所有题目 + List questions = aiolQuestionService.listByIds(questionIds); + + // 分离选项和答案的ID + List optionIds = new ArrayList<>(); + List answerIds = new ArrayList<>(); + for (AiolQuestion question : questions) { + if (question.getType() >= 0 && question.getType() <= 2) { + optionIds.add(question.getId()); + } else if (question.getType() == 3 || question.getType() == 4) { + answerIds.add(question.getId()); + } + } + + // 批量查询选项和答案 + List questionOptions = Collections.emptyList(); + List questionAnswers = Collections.emptyList(); + + if (!optionIds.isEmpty()) { + questionOptions = optionService.list(new LambdaQueryWrapper().in(AiolQuestionOption::getQuestionId, optionIds)); + } + if (!answerIds.isEmpty()) { + questionAnswers = answerService.list(new LambdaQueryWrapper().in(AiolQuestionAnswer::getQuestionId, answerIds)); + } + + // 构建题目id的映射 + Map> optionMap = questionOptions.stream() + .collect(Collectors.groupingBy(AiolQuestionOption::getQuestionId)); + Map> answerMap = questionAnswers.stream() + .collect(Collectors.groupingBy(AiolQuestionAnswer::getQuestionId)); + + // 构建结果列表 + Map result = new HashMap<>(); + Map> children = new HashMap<>(); + + for (AiolQuestion question : questions) { + QuestionAnswerDTO questionAnswerDTO = new QuestionAnswerDTO(); + questionAnswerDTO.setQuestion(question); + + // 设置对应的选项或答案 + if (question.getType() >= 0 && question.getType() <= 2) { + questionAnswerDTO.setAnswer(optionMap.get(question.getId())); + } else if (question.getType() == 3 || question.getType() == 4) { + questionAnswerDTO.setAnswer(answerMap.get(question.getId())); + } + + // 处理父子关系 + if (question.getParentId() == null || question.getParentId().isEmpty()) { + result.put(question.getId(), questionAnswerDTO); + } else { + children.computeIfAbsent(question.getParentId(), k -> new ArrayList<>()) + .add(questionAnswerDTO); + } + } + + // 将子问题列表添加到对应的父问题中 + children.forEach((parentId, childList) -> { + if (result.containsKey(parentId)) { + result.get(parentId).setChildren(childList); + } + }); + + return result.values(); + } + + + } From 65e8179e14e383fdd0e273d7ce8cb44afcfff10c Mon Sep 17 00:00:00 2001 From: Lqc Date: Sat, 20 Sep 2025 06:07:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=AF=95=E5=8D=B7=EF=BC=8C=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E4=BA=BA=E5=90=8D=E4=B8=80=E8=B5=B7=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aiol/controller/AiolPaperController.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperController.java index 8c81b8d4..322b4ae4 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperController.java @@ -61,22 +61,24 @@ public class AiolPaperController extends JeecgController> queryPageList(AiolPaper aiolPaper, - @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, - @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, - HttpServletRequest req) { + public Result>> queryPageList(AiolPaper aiolPaper, + @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, + @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, + HttpServletRequest req) { + QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(aiolPaper, req.getParameterMap()); + Page> page = new Page<>(pageNo, pageSize); - QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(aiolPaper, req.getParameterMap()); - Page page = new Page(pageNo, pageSize); - IPage pageList = aiolPaperService.page(page, queryWrapper); + queryWrapper.select("aiol_paper.*", "(SELECT realname FROM sys_user WHERE username = aiol_paper.create_by) as createByName"); + + IPage> pageList = aiolPaperService.pageMaps(page, queryWrapper); return Result.OK(pageList); } - - /** + + + /** * 添加 * * @param aiolPaper