FrontPaperController.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package com.ruoyi.web.controller.front;
  2. import com.alibaba.fastjson2.JSONObject;
  3. import com.ruoyi.common.core.content.VistorContextHolder;
  4. import com.ruoyi.common.core.domain.AjaxResult;
  5. import com.ruoyi.common.core.domain.AjaxResult2;
  6. import com.ruoyi.common.core.domain.entity.SysUser;
  7. import com.ruoyi.common.utils.NumberUtils;
  8. import com.ruoyi.common.utils.SecurityUtils;
  9. import com.ruoyi.dz.domain.DzControl;
  10. import com.ruoyi.dz.domain.DzSubject;
  11. import com.ruoyi.dz.service.IDzControlService;
  12. import com.ruoyi.dz.service.IDzSubjectService;
  13. import com.ruoyi.enums.PaperType;
  14. import com.ruoyi.learn.domain.LearnPaper;
  15. import com.ruoyi.learn.domain.LearnStudent;
  16. import com.ruoyi.learn.domain.LearnTest;
  17. import com.ruoyi.learn.service.ILearnPaperService;
  18. import com.ruoyi.learn.service.ILearnStudentService;
  19. import com.ruoyi.learn.service.ILearnTestService;
  20. import com.ruoyi.web.service.LearnTeacherService;
  21. import com.ruoyi.web.service.PaperService;
  22. import com.ruoyi.web.service.StudentService;
  23. import io.swagger.annotations.Api;
  24. import io.swagger.annotations.ApiOperation;
  25. import io.swagger.annotations.ApiParam;
  26. import org.apache.commons.compress.utils.Lists;
  27. import org.apache.commons.lang3.StringUtils;
  28. import org.springframework.util.CollectionUtils;
  29. import org.springframework.web.bind.annotation.GetMapping;
  30. import org.springframework.web.bind.annotation.RequestMapping;
  31. import org.springframework.web.bind.annotation.RequestParam;
  32. import org.springframework.web.bind.annotation.RestController;
  33. import java.util.List;
  34. import java.util.Map;
  35. import java.util.Set;
  36. import java.util.stream.Collectors;
  37. @RestController
  38. @RequestMapping("/front/paper")
  39. @Api(tags = "前台-学习-试卷")
  40. public class FrontPaperController {
  41. private final IDzControlService dzControlService;
  42. private final IDzSubjectService dzSubjectService;
  43. private final PaperService paperService;
  44. private final ILearnPaperService learnPaperService;
  45. private final ILearnTestService testService;
  46. private final ILearnStudentService learnStudentService;
  47. private final LearnTeacherService learnTeacherService;
  48. private final StudentService studentService;
  49. public FrontPaperController(IDzControlService dzControlService, IDzSubjectService dzSubjectService, PaperService paperService, ILearnPaperService learnPaperService, ILearnTestService testService, ILearnStudentService learnStudentService, LearnTeacherService learnTeacherService, StudentService studentService) {
  50. this.dzControlService = dzControlService;
  51. this.dzSubjectService = dzSubjectService;
  52. this.paperService = paperService;
  53. this.learnPaperService = learnPaperService;
  54. this.testService = testService;
  55. this.learnStudentService = learnStudentService;
  56. this.learnTeacherService = learnTeacherService;
  57. this.studentService = studentService;
  58. }
  59. @ApiOperation("01 考试批次")
  60. @GetMapping(value = "batch")
  61. public List<LearnTest> getBatch() {
  62. DzControl dzControl = dzControlService.selectDzControl(VistorContextHolder.getContext());
  63. LearnTest cond = new LearnTest();
  64. cond.setYear(dzControl.getPlanYear());
  65. return testService.selectLearnTestList(cond);
  66. }
  67. @ApiOperation("02 考试科目")
  68. @GetMapping(value = "subject")
  69. public AjaxResult2<List<DzSubject>> getSubject(@ApiParam("定向") @RequestParam(defaultValue = "false") boolean directed) {
  70. return AjaxResult2.success(studentService.getSubjectList(directed));
  71. }
  72. @ApiOperation("03 知识点树")
  73. @GetMapping(value = "knowledge")
  74. public AjaxResult getKnowledge(@ApiParam("定向") @RequestParam(defaultValue = "false") boolean directed, @ApiParam("科目ID") Long subjectId,
  75. @ApiParam("考卷题类别0普通2必刷") @RequestParam(required = false) Integer questionType) {
  76. SysUser sysUser = SecurityUtils.getLoginUser().getUser();
  77. Set<Long> knowledgeIdSet = null;
  78. if(directed) {
  79. LearnStudent learnStudent = learnStudentService.selectLearnStudentByStudentId(sysUser.getUserId());
  80. if(null != learnStudent) {
  81. knowledgeIdSet = learnTeacherService.getKnowledgeIdSet(learnStudent.getMajorPlanId(), sysUser.getExamType().name());
  82. }
  83. }
  84. List<LearnTeacherService.TreeNode> nodeList = learnTeacherService.getKnowledgeTree(sysUser.getExamType().title(), subjectId, knowledgeIdSet, sysUser.getUserId(), questionType);
  85. if(CollectionUtils.isEmpty(knowledgeIdSet)) {
  86. return AjaxResult.success(nodeList);
  87. }
  88. List<LearnTeacherService.TreeNode> finalList = Lists.newArrayList();
  89. for(LearnTeacherService.TreeNode parent : nodeList) {
  90. if(CollectionUtils.isEmpty(parent.getChildren())) {
  91. if(parent.getQuestionCount() > 0 && parent.getStatus().equals(1)) {
  92. finalList.add(parent);
  93. }
  94. continue;
  95. }
  96. parent.setQuestionCount(0);
  97. parent.setFinishedCount(0);
  98. parent.setRightCount(0);
  99. List<LearnTeacherService.TreeNode> childList = Lists.newArrayList();
  100. for(LearnTeacherService.TreeNode child : parent.getChildren()) {
  101. if(child.getStatus().equals(1)) { // TODO 暂不过滤无题的 && child.getQuestionCount() > 0
  102. childList.add(child);
  103. parent.setQuestionCount(parent.getQuestionCount() + child.getQuestionCount());
  104. parent.setFinishedCount(parent.getFinishedCount() + child.getFinishedCount());
  105. parent.setRightCount(parent.getRightCount() + child.getRightCount());
  106. }
  107. }
  108. parent.calcRatio();
  109. if(childList.size() > 0) {
  110. parent.setChildren(childList);
  111. finalList.add(parent);
  112. }
  113. }
  114. return AjaxResult.success(finalList);
  115. }
  116. @ApiOperation("03 课程同步知识点树")
  117. @GetMapping(value = "courseKnowledge")
  118. public AjaxResult getCourseKnowledge() {
  119. SysUser sysUser = SecurityUtils.getLoginUser().getUser();
  120. List<LearnTeacherService.TreeNode> nodeList = learnTeacherService.getCourseKnowledgeTree(sysUser.getUserId());
  121. return AjaxResult.success(nodeList);
  122. }
  123. @ApiOperation("04 取试卷")
  124. @GetMapping(value = "paper")
  125. public AjaxResult loadPaper(@ApiParam("考卷类型PaperType") PaperType type, @ApiParam("考卷标识") Long id) {
  126. return AjaxResult.success(paperService.loadPaper(id));
  127. }
  128. @ApiOperation("05 取模拟卷列表")
  129. @GetMapping("/list")
  130. public AjaxResult2<List<JSONObject>> list(LearnPaper learnPaper) {
  131. SysUser sysUser = SecurityUtils.getLoginUser().getUser();
  132. learnPaper.setPaperType(PaperType.Simulated.name());
  133. String subjectKey = NumberUtils.isPositive(learnPaper.getSubjectId()) ? String.valueOf(sysUser.getExamMajor()) : "0";
  134. learnPaper.setLocations(sysUser.getLocation());
  135. learnPaper.setDirectKey(sysUser.getExamType().name() + "_" + subjectKey);
  136. learnPaper.setSubjectId(null);
  137. learnPaper.setStatus(1);
  138. learnPaper.setExamineeId(sysUser.getUserId());
  139. List<LearnPaper> list = learnPaperService.selectLearnPaperForExam(learnPaper);
  140. Map<Long, String> subjectMap = dzSubjectService.selectDzSubjectList(new DzSubject()).stream().collect(Collectors.toMap(DzSubject::getSubjectId, DzSubject::getSubjectName));
  141. List<JSONObject> jsonList = list.stream().map(t -> {
  142. JSONObject o = JSONObject.from(t);
  143. o.put("subjectName", subjectMap.get(t.getSubjectId()));
  144. return o;
  145. }).collect(Collectors.toList());
  146. return AjaxResult2.success(jsonList);
  147. }
  148. }