题目返回创建人用户名

This commit is contained in:
Lqc 2025-09-23 11:49:07 +08:00
parent 4526e237a6
commit af808a80b7
2 changed files with 73 additions and 21 deletions

View File

@ -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<AiolRepo, IAiolRepoServi
@GetMapping("/questionList/{repoId}")
@Operation(summary = "查询题库下题目")
public Result<List<AiolQuestion>> questionList(@PathVariable String repoId) {
public Result<List<QuestionWithCreator>> questionList(@PathVariable String repoId) {
// 获取题库中的题目ID列表
List<String> repoQuestionIds = questionRepoService.questionList(repoId);
if (repoQuestionIds.isEmpty()) {
@ -429,6 +415,27 @@ public class AiolRepoController extends JeecgController<AiolRepo, IAiolRepoServi
if (questions.isEmpty()) {
return Result.error("题目不存在");
}
//获取所有创建人id
List<String> createIds = questions.stream()
.map(AiolQuestion::getCreateBy)
.collect(Collectors.toSet())
.stream()
.collect(Collectors.toList());
// 根据ID列表查询用户信息
Map<String, String> createIdToUsernameMap = new HashMap<>();
if (!createIds.isEmpty()) {
List<SysUser> users = sysUserService.list(
new LambdaQueryWrapper<SysUser>()
.in(SysUser::getUsername, createIds)
);
// 创建ID到用户名的映射
createIdToUsernameMap = users.stream()
.collect(Collectors.toMap(
SysUser::getUsername,
SysUser::getRealname,
(existing, replacement) -> existing
));
}
//获取复选题id
List<String> type5Ids = questions.stream()
.filter(question -> question.getType() == 5)
@ -446,15 +453,45 @@ public class AiolRepoController extends JeecgController<AiolRepo, IAiolRepoServi
Map<String, List<AiolQuestion>> parentToChildrenMap = type5Questions.stream()
.collect(Collectors.groupingBy(AiolQuestion::getParentId));
// 将子题目添加到原始列表中保持原有顺序
List<AiolQuestion> resultQuestions = new ArrayList<>();
// 构建结果列表
List<QuestionWithCreator> 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<AiolQuestion> 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);
}

View File

@ -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;
}
}