LearnTeacherController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. package com.ruoyi.web.controller.learn;
  2. import cn.hutool.core.lang.Dict;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import com.google.common.collect.Lists;
  5. import com.ruoyi.common.annotation.Anonymous;
  6. import com.ruoyi.common.core.controller.BaseController;
  7. import com.ruoyi.common.core.domain.AjaxResult;
  8. import com.ruoyi.common.core.domain.AjaxResult2;
  9. import com.ruoyi.common.core.domain.entity.SysUser;
  10. import com.ruoyi.common.core.page.TableDataInfo;
  11. import com.ruoyi.common.enums.ExamType;
  12. import com.ruoyi.common.utils.SecurityUtils;
  13. import com.ruoyi.dz.domain.DzControl;
  14. import com.ruoyi.dz.domain.DzSubject;
  15. import com.ruoyi.dz.service.IDzControlService;
  16. import com.ruoyi.dz.service.IDzSubjectService;
  17. import com.ruoyi.enums.PaperBuildStatus;
  18. import com.ruoyi.enums.QuestionType;
  19. import com.ruoyi.learn.domain.*;
  20. import com.ruoyi.learn.service.ILearnPaperQuestionService;
  21. import com.ruoyi.learn.service.ILearnPaperService;
  22. import com.ruoyi.learn.service.ILearnTestPaperService;
  23. import com.ruoyi.web.service.LearnTeacherService;
  24. import com.ruoyi.web.service.PaperService;
  25. import io.swagger.annotations.Api;
  26. import io.swagger.annotations.ApiOperation;
  27. import io.swagger.annotations.ApiParam;
  28. import org.apache.commons.lang3.StringUtils;
  29. import org.springframework.security.access.prepost.PreAuthorize;
  30. import org.springframework.util.CollectionUtils;
  31. import org.springframework.web.bind.annotation.*;
  32. import java.util.*;
  33. import java.util.stream.Collectors;
  34. @RestController
  35. @RequestMapping("/learn/teaching")
  36. @Api(tags = "后台-学习 - 老师业务")
  37. public class LearnTeacherController extends BaseController {
  38. private final IDzControlService dzControlService;
  39. private final IDzSubjectService dzSubjectService;
  40. private final LearnTeacherService learnTeacherService;
  41. private final PaperService paperService;
  42. private final ILearnPaperService learnPaperService;
  43. private final ILearnTestPaperService testPaperService;
  44. public LearnTeacherController(IDzControlService dzControlService, IDzSubjectService dzSubjectService, LearnTeacherService learnTeacherService, PaperService paperService, ILearnPaperService learnPaperService, ILearnTestPaperService testPaperService) {
  45. this.dzControlService = dzControlService;
  46. this.dzSubjectService = dzSubjectService;
  47. this.learnTeacherService = learnTeacherService;
  48. this.paperService = paperService;
  49. this.learnPaperService = learnPaperService;
  50. this.testPaperService = testPaperService;
  51. }
  52. @GetMapping(value = "examTypes")
  53. @Anonymous
  54. @ApiOperation("考生类型列表")
  55. public AjaxResult examTypes(@RequestParam String location)
  56. {
  57. DzControl cond = new DzControl();
  58. cond.setIsValid(1);
  59. cond.setLocation(location);
  60. List<DzControl> list = dzControlService.selectDzControlList(cond);
  61. String examTypes;
  62. if(CollectionUtils.isEmpty(list) || StringUtils.isBlank(examTypes = list.get(0).getExamTypes())) {
  63. return AjaxResult.success(Collections.emptyList());
  64. }
  65. return AjaxResult.success(Arrays.stream(examTypes.split(",")).map(t -> {
  66. JSONObject o = new JSONObject();
  67. o.put("dictValue", t);
  68. o.put("dictLabel", ExamType.valueOf(t).title());
  69. return o;
  70. }).collect(Collectors.toList()));
  71. }
  72. @GetMapping("/subjects")
  73. @ApiOperation("科目列表")
  74. public AjaxResult2<List<DzSubject>> subjects(@RequestParam @ApiParam("考生类型") ExamType examType)
  75. {
  76. DzSubject sCond = new DzSubject();
  77. sCond.setExamTypes(examType.name());
  78. List<DzSubject> list = dzSubjectService.selectDzSubjectList(sCond);
  79. return AjaxResult2.success(list);
  80. }
  81. @GetMapping("/knowledges")
  82. @ApiOperation("知识点列表")
  83. public AjaxResult knowledges(@ApiParam("类型 ExactIntelligent/FullIntelligent/ExactHand/FullHand") @RequestParam String buildType,
  84. @ApiParam("科目ID") @RequestParam(required = false) Long subjectId,
  85. @ApiParam("专业计划ID") @RequestParam(required = false) Long majorPlanId)
  86. {
  87. Set<Long> knowledgeIdSet = null;
  88. if("ExactHand".equals(buildType)) {
  89. knowledgeIdSet = learnTeacherService.getKnowledgeIdSet(majorPlanId);
  90. }
  91. return AjaxResult.success(learnTeacherService.getKnowledgeTree(null, subjectId, knowledgeIdSet, null));
  92. }
  93. @GetMapping(value = "classStatistic")
  94. @ApiOperation("班级生成统计")
  95. public AjaxResult classStatistic(TestPaperVO.TestPaperBuildReq req)
  96. {
  97. return AjaxResult.success(learnTeacherService.getClassesBuildStats(req, SecurityUtils.getLoginUser().getUser().getUserTypeId()));
  98. }
  99. @PreAuthorize("@ss.hasPermi('learn:test_paper:add')")
  100. @GetMapping("build/getBuiltPaper")
  101. @ApiOperation("获取已组卷详情")
  102. public AjaxResult getBuiltPaper(TestPaperVO.TestPaperBuildReq req) {
  103. List<LearnTestPaper> testPaperList = learnTeacherService.getBuiltTestPaper(req);
  104. if (CollectionUtils.isEmpty(testPaperList)) {
  105. return AjaxResult.success(Collections.emptyList());
  106. }
  107. List<JSONObject> resultList = new ArrayList<>();
  108. for(LearnTestPaper learnTestPaper : testPaperList) {
  109. PaperVO paperVO = paperService.loadPaper(learnTestPaper.getPaperId());
  110. JSONObject root = JSONObject.from(paperVO);
  111. root.remove("id");
  112. root.put("paperId", learnTestPaper.getPaperId());
  113. resultList.add(root);
  114. }
  115. return AjaxResult.success(resultList);
  116. }
  117. @GetMapping("/getPaperClassRecords")
  118. @ApiOperation("组卷记录")
  119. public TableDataInfo getPaperClassRecords(TestPaperVO.TestPaperBuildReq req)
  120. {
  121. startPage();
  122. List<JSONObject> list = learnTeacherService.getPaperClassRecords(req, SecurityUtils.getUserId());
  123. list.stream().forEach(o -> {
  124. o.put("buildType", req.getBuildType());
  125. });
  126. return getDataTable(list);
  127. }
  128. @GetMapping("/getPaperStudentRecords")
  129. @ApiOperation("班级详情")
  130. public AjaxResult getPaperStudentRecords(TestPaperVO.TestPaperBuildReq req)
  131. {
  132. List<JSONObject> list = learnTeacherService.getPaperStudentRecords(req);
  133. list.stream().forEach(o -> {
  134. Integer state = o.getInteger("state");
  135. o.put("state", PaperBuildStatus.of(state).getTitle());
  136. });
  137. return AjaxResult.success(list);
  138. }
  139. @GetMapping("/getPaperStudentDetail")
  140. @ApiOperation("学生详情")
  141. public AjaxResult getPaperStudentDetail(@ApiParam("考卷ID") Long examineeId)
  142. {
  143. return AjaxResult.success(learnTeacherService.getPaperStudentDetail(examineeId));
  144. }
  145. @PostMapping("/postUnfinishAlarm")
  146. @ApiOperation("学生提醒")
  147. public AjaxResult postUnfinishAlarm(@ApiParam("组卷类型") String buildType, @ApiParam("批次") Long batchId, @ApiParam("班级") Long classId)
  148. {
  149. return AjaxResult.success();
  150. }
  151. @GetMapping("/questionTypes")
  152. @ApiOperation("题型列表")
  153. public AjaxResult questionTypes(@ApiParam("科目ID") Long subjectId, @RequestParam(required = false) @ApiParam("知识点") Collection<Long> knowledgeIds)
  154. {
  155. List<Dict> dictList = learnTeacherService.getQuestionTypes(subjectId, knowledgeIds).stream().map(t -> {
  156. QuestionType qt = QuestionType.of(t.getQtpye());
  157. return Dict.create().set("dictLabel", qt.getTitle()).set("dictValue", qt.getVal());
  158. }).sorted(new Comparator<Dict>() {
  159. @Override
  160. public int compare(Dict o1, Dict o2) {
  161. return o1.getInt("dictValue").compareTo(o2.getInt("dictValue"));
  162. }
  163. }).collect(Collectors.toList());
  164. return AjaxResult.success(dictList);
  165. }
  166. @PreAuthorize("@ss.hasPermi('learn:test_paper:add')")
  167. @PostMapping("/build/exactIntelligent")
  168. @ApiOperation("定向智能")
  169. public AjaxResult buildExactIntelligent(@RequestBody TestPaperVO.TestPaperBuildReq req)
  170. {
  171. req.setBuildType("ExactIntelligent");
  172. req.setDirectType(true);
  173. req.setSubjectId(11L);
  174. return AjaxResult.success(learnTeacherService.buildPapersDirect(req));
  175. }
  176. @PreAuthorize("@ss.hasPermi('learn:test_paper:add')")
  177. @PostMapping("/build/fullIntelligent")
  178. @ApiOperation("全量智能")
  179. public AjaxResult buildFullIntelligent(@RequestBody TestPaperVO.TestPaperBuildReq req)
  180. {
  181. req.setBuildType("FullIntelligent");
  182. req.setDirectType(false);
  183. if(null == req.getSubjectId()) {
  184. AjaxResult.error("未选择科目");
  185. }
  186. return AjaxResult.success(learnTeacherService.buildPapersFull(req));
  187. }
  188. @PreAuthorize("@ss.hasPermi('learn:test_paper:add')")
  189. @PostMapping("/build/exactHand")
  190. @ApiOperation("定向手动")
  191. public AjaxResult buildExactHand(@RequestBody TestPaperVO.TestPaperBuildReq req)
  192. {
  193. req.setBuildType("ExactHand");
  194. req.setDirectType(true);
  195. req.setSubjectId(11L);
  196. if(null == req.getMajorPlanId()) {
  197. AjaxResult.error("未选择计划");
  198. }
  199. return AjaxResult.success(learnTeacherService.buildPapersDirect(req));
  200. }
  201. @PreAuthorize("@ss.hasPermi('learn:test_paper:add')")
  202. @PostMapping("/build/fullHand")
  203. @ApiOperation("全量手动")
  204. public AjaxResult buildFullHand(@RequestBody TestPaperVO.TestPaperBuildReq req)
  205. {
  206. req.setBuildType("FullHand");
  207. req.setDirectType(false);
  208. if(null == req.getSubjectId()) {
  209. AjaxResult.error("未选择科目");
  210. }
  211. return AjaxResult.success(learnTeacherService.buildPapersFull(req));
  212. }
  213. @GetMapping("/universities")
  214. @ApiOperation("院校列表")
  215. public AjaxResult universities(@ApiParam("批次ID") Long batchId)
  216. {
  217. return AjaxResult.success(learnTeacherService.selectUniversityList(getUserId(), batchId));
  218. }
  219. @GetMapping("/majors")
  220. @ApiOperation("专业列表")
  221. public AjaxResult majors(@ApiParam("批次ID") Long batchId, @RequestParam @ApiParam("院校列表") Long universityId, @RequestParam @ApiParam("考生类型") ExamType examType)
  222. {
  223. SysUser sysUser = SecurityUtils.getLoginUser().getUser();
  224. DzControl control = dzControlService.selectDzControl(sysUser.getLocation(), examType);
  225. return AjaxResult.success(learnTeacherService.selectMajorList(universityId, control.getPlanYear(), batchId, examType.name()));
  226. }
  227. /**
  228. -- 1. 查询考试批次(假设每个老师自已控制)
  229. -- 2. 查询班老师班级列表
  230. -- 3. 查询定向院校列表
  231. -- 5. 查询定向院校专业组
  232. -- 6. 查询科目(分是否定向)
  233. -- 7. 查询知识点(分是否定向)
  234. -- 8. 查询单个定向时知识点树
  235. -- 9. 设置题型数量(预置题型要求,或人工指定,不指定时平均分配, 题型是针对院校的)
  236. */
  237. @GetMapping(value = "provinces")
  238. @Anonymous
  239. @ApiOperation("省份列表")
  240. public AjaxResult provinces()
  241. {
  242. DzControl cond = new DzControl();
  243. cond.setIsValid(1);
  244. return AjaxResult.success(dzControlService.selectDzControlList(cond).stream().map(t -> {
  245. JSONObject o = new JSONObject();
  246. o.put("dictValue", t.getLocation());
  247. o.put("dictLabel", t.getLocation());
  248. return o;
  249. }).collect(Collectors.toList()));
  250. }
  251. @GetMapping("/classes")
  252. @ApiOperation("2. 班级列表")
  253. public AjaxResult classes()
  254. {
  255. return AjaxResult.success(learnTeacherService.getClasses(getUserId()));
  256. }
  257. @GetMapping("/students")
  258. @ApiOperation("学生列表")
  259. public AjaxResult students(@ApiParam("批次ID") Long batchId)
  260. {
  261. return AjaxResult.success(learnTeacherService.getStudents(batchId, getUserId()));
  262. }
  263. @ApiOperation("04 取试卷列表")
  264. @GetMapping(value = "papers")
  265. public AjaxResult papers(@ApiParam("批次") @RequestParam(required = false) Integer batchId) {
  266. LearnTestPaper tpCond = new LearnTestPaper();
  267. tpCond.setCreatorId(SecurityUtils.getUserId());
  268. tpCond.setBatchId(batchId);
  269. List<LearnTestPaper> testPaperList = testPaperService.selectLearnTestPaperList(tpCond);
  270. List<LearnPaper> paperList = Lists.newArrayList();
  271. for(LearnTestPaper tp : testPaperList) {
  272. JSONObject root = JSONObject.from(tp);
  273. paperList.add(learnPaperService.selectLearnPaperById(tp.getPaperId()));
  274. }
  275. return AjaxResult.success(paperList);
  276. }
  277. }