LearnTeacherController.java 18 KB

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