LearnTeacherController.java 17 KB

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