Merge branch 'dev2' of http://110.42.96.64:19890/GoCo/OL-LearnPlatform-Backend into dev2
merge
This commit is contained in:
commit
5da9d2135a
@ -61,21 +61,23 @@ public class AiolPaperController extends JeecgController<AiolPaper, IAiolPaperSe
|
|||||||
* @param req
|
* @param req
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
//@AutoLog(value = "试卷-分页列表查询")
|
|
||||||
@Operation(summary="试卷-分页列表查询")
|
@Operation(summary="试卷-分页列表查询")
|
||||||
@GetMapping(value = "/list")
|
@GetMapping(value = "/list")
|
||||||
public Result<IPage<AiolPaper>> queryPageList(AiolPaper aiolPaper,
|
public Result<IPage<Map<String, Object>>> queryPageList(AiolPaper aiolPaper,
|
||||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||||
HttpServletRequest req) {
|
HttpServletRequest req) {
|
||||||
|
|
||||||
|
|
||||||
QueryWrapper<AiolPaper> queryWrapper = QueryGenerator.initQueryWrapper(aiolPaper, req.getParameterMap());
|
QueryWrapper<AiolPaper> queryWrapper = QueryGenerator.initQueryWrapper(aiolPaper, req.getParameterMap());
|
||||||
Page<AiolPaper> page = new Page<AiolPaper>(pageNo, pageSize);
|
Page<Map<String, Object>> page = new Page<>(pageNo, pageSize);
|
||||||
IPage<AiolPaper> pageList = aiolPaperService.page(page, queryWrapper);
|
|
||||||
|
queryWrapper.select("aiol_paper.*", "(SELECT realname FROM sys_user WHERE username = aiol_paper.create_by) as createByName");
|
||||||
|
|
||||||
|
IPage<Map<String, Object>> pageList = aiolPaperService.pageMaps(page, queryWrapper);
|
||||||
return Result.OK(pageList);
|
return Result.OK(pageList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加
|
* 添加
|
||||||
*
|
*
|
||||||
|
@ -4,44 +4,38 @@ import java.math.BigDecimal;
|
|||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
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 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.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
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 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.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.jeecg.common.system.base.controller.JeecgController;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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.tags.Tag;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 试卷试题
|
* @Description: 试卷试题
|
||||||
* @Author: jeecg-boot
|
* @Author: jeecg-boot
|
||||||
@ -57,6 +51,10 @@ public class AiolPaperQuestionController extends JeecgController<AiolPaperQuesti
|
|||||||
private IAiolPaperQuestionService aiolPaperQuestionService;
|
private IAiolPaperQuestionService aiolPaperQuestionService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IAiolQuestionService aiolQuestionService;
|
private IAiolQuestionService aiolQuestionService;
|
||||||
|
@Autowired
|
||||||
|
private IAiolQuestionAnswerService answerService;
|
||||||
|
@Autowired
|
||||||
|
private IAiolQuestionOptionService optionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页列表查询
|
* 分页列表查询
|
||||||
@ -231,4 +229,97 @@ public class AiolPaperQuestionController extends JeecgController<AiolPaperQuesti
|
|||||||
return super.importExcel(request, response, AiolPaperQuestion.class);
|
return super.importExcel(request, response, AiolPaperQuestion.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/paperDetail/{paperId}")
|
||||||
|
@Operation(summary = "查询试卷所有题目详情")
|
||||||
|
public Result<?> paperDetail(@PathVariable String paperId) {
|
||||||
|
List<AiolPaperQuestion> list = aiolPaperQuestionService.list(new LambdaQueryWrapper<AiolPaperQuestion>().eq(AiolPaperQuestion::getPaperId, paperId));
|
||||||
|
// 收集所有需要的 questionId
|
||||||
|
List<String> 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<QuestionAnswerDTO> convertToQuestionAnswerDTO(
|
||||||
|
List<String> questionIds,
|
||||||
|
IAiolQuestionService aiolQuestionService,
|
||||||
|
IAiolQuestionOptionService optionService,
|
||||||
|
IAiolQuestionAnswerService answerService) {
|
||||||
|
|
||||||
|
// 批量查询所有题目
|
||||||
|
List<AiolQuestion> questions = aiolQuestionService.listByIds(questionIds);
|
||||||
|
|
||||||
|
// 分离选项和答案的ID
|
||||||
|
List<String> optionIds = new ArrayList<>();
|
||||||
|
List<String> 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<AiolQuestionOption> questionOptions = Collections.emptyList();
|
||||||
|
List<AiolQuestionAnswer> questionAnswers = Collections.emptyList();
|
||||||
|
|
||||||
|
if (!optionIds.isEmpty()) {
|
||||||
|
questionOptions = optionService.list(new LambdaQueryWrapper<AiolQuestionOption>().in(AiolQuestionOption::getQuestionId, optionIds));
|
||||||
|
}
|
||||||
|
if (!answerIds.isEmpty()) {
|
||||||
|
questionAnswers = answerService.list(new LambdaQueryWrapper<AiolQuestionAnswer>().in(AiolQuestionAnswer::getQuestionId, answerIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建题目id的映射
|
||||||
|
Map<String, List<AiolQuestionOption>> optionMap = questionOptions.stream()
|
||||||
|
.collect(Collectors.groupingBy(AiolQuestionOption::getQuestionId));
|
||||||
|
Map<String, List<AiolQuestionAnswer>> answerMap = questionAnswers.stream()
|
||||||
|
.collect(Collectors.groupingBy(AiolQuestionAnswer::getQuestionId));
|
||||||
|
|
||||||
|
// 构建结果列表
|
||||||
|
Map<String, QuestionAnswerDTO> result = new HashMap<>();
|
||||||
|
Map<String, List<QuestionAnswerDTO>> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user