diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java index 52ed7576..a182476e 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java @@ -1,12 +1,8 @@ package org.jeecg.modules.aiol.controller; -import java.io.ObjectOutputStream; import java.net.URLEncoder; 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; @@ -14,22 +10,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.StringUtils; -import com.jeecg.qywx.api.user.vo.User; import org.apache.poi.ss.usermodel.Workbook; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.system.api.ISysBaseAPI; import org.jeecg.common.system.query.QueryGenerator; -import org.jeecg.common.system.query.QueryRuleEnum; import org.jeecg.common.system.util.JwtUtil; import org.jeecg.common.system.vo.LoginUser; -import org.jeecg.common.util.UUIDGenerator; -import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.aiol.constant.EntityLinkConst; -import org.jeecg.modules.aiol.dto.CourseWithTeacherInfo; -import org.jeecg.modules.aiol.dto.QuestionAnswerDTO; -import org.jeecg.modules.aiol.dto.QuestionExcelDTO; -import org.jeecg.modules.aiol.dto.UserPermission; +import org.jeecg.modules.aiol.dto.*; import org.jeecg.modules.aiol.entity.*; import org.jeecg.modules.aiol.mapper.AiolRepoMapper; import org.jeecg.modules.aiol.service.*; @@ -43,18 +32,15 @@ import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.service.ISysUserService; import org.jeecgframework.poi.excel.ExcelExportUtil; 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.BeanUtils; 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; @@ -418,7 +404,7 @@ public class AiolRepoController extends JeecgController> questionList(@PathVariable String repoId) { + public Result> questionList(@PathVariable String repoId) { // 获取题库中的题目ID列表 List repoQuestionIds = questionRepoService.questionList(repoId); if (repoQuestionIds.isEmpty()) { @@ -429,6 +415,27 @@ public class AiolRepoController extends JeecgController createIds = questions.stream() + .map(AiolQuestion::getCreateBy) + .collect(Collectors.toSet()) + .stream() + .collect(Collectors.toList()); + // 根据ID列表查询用户信息 + Map createIdToUsernameMap = new HashMap<>(); + if (!createIds.isEmpty()) { + List users = sysUserService.list( + new LambdaQueryWrapper() + .in(SysUser::getUsername, createIds) + ); + // 创建ID到用户名的映射 + createIdToUsernameMap = users.stream() + .collect(Collectors.toMap( + SysUser::getUsername, + SysUser::getRealname, + (existing, replacement) -> existing + )); + } //获取复选题id List type5Ids = questions.stream() .filter(question -> question.getType() == 5) @@ -446,15 +453,45 @@ public class AiolRepoController extends JeecgController> parentToChildrenMap = type5Questions.stream() .collect(Collectors.groupingBy(AiolQuestion::getParentId)); - // 将子题目添加到原始列表中,保持原有顺序 - List resultQuestions = new ArrayList<>(); + + + // 构建结果列表 + List resultQuestions = new ArrayList<>(); for (AiolQuestion question : questions) { - resultQuestions.add(question); + // 创建扩展对象 + QuestionWithCreator questionWithCreator = new QuestionWithCreator(); + BeanUtils.copyProperties(question, questionWithCreator); + + // 设置创建人用户名 + String createBy = question.getCreateBy(); + if (StringUtils.isNotBlank(createBy)) { + questionWithCreator.setCreateByName(createIdToUsernameMap.getOrDefault(createBy, "")); + } else { + questionWithCreator.setCreateByName(""); + } + + resultQuestions.add(questionWithCreator); + if (question.getType() == 5) { List children = parentToChildrenMap.getOrDefault(question.getId(), Collections.emptyList()); - resultQuestions.addAll(children); + for (AiolQuestion child : children) { + // 创建子题目的扩展对象 + QuestionWithCreator childWithCreator = new QuestionWithCreator(); + BeanUtils.copyProperties(child, childWithCreator); + + // 设置子题目的创建人用户名 + String childCreateBy = child.getCreateBy(); + if (StringUtils.isNotBlank(childCreateBy)) { + childWithCreator.setCreateByName(createIdToUsernameMap.getOrDefault(childCreateBy, "")); + } else { + childWithCreator.setCreateByName(""); + } + + resultQuestions.add(childWithCreator); + } } } + return Result.ok(resultQuestions); } diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/dto/QuestionWithCreator.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/dto/QuestionWithCreator.java new file mode 100644 index 00000000..e1f53977 --- /dev/null +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/dto/QuestionWithCreator.java @@ -0,0 +1,15 @@ +package org.jeecg.modules.aiol.dto; + +import org.jeecg.modules.aiol.entity.AiolQuestion; + +public class QuestionWithCreator extends AiolQuestion { + private String createByName; + + public String getCreateByName() { + return createByName; + } + + public void setCreateByName(String createByName) { + this.createByName = createByName; + } +} \ No newline at end of file