LearnTeacherController.java 15 KB

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