LearnTeacherController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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));
  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("/getPaperStudentRecords")
  174. @ApiOperation("班级详情")
  175. public AjaxResult getPaperStudentRecords(TestPaperVO.TestPaperBuildReq req)
  176. {
  177. List<JSONObject> list = learnTeacherService.getPaperStudentRecords(req);
  178. list.stream().forEach(o -> {
  179. Integer state = o.getInteger("state");
  180. o.put("state", PaperBuildStatus.of(state).getTitle());
  181. });
  182. return AjaxResult.success(list);
  183. }
  184. @GetMapping("/getPaperStudentDetail")
  185. @ApiOperation("学生详情")
  186. public AjaxResult getPaperStudentDetail(@ApiParam("考卷ID") Long examineeId)
  187. {
  188. return AjaxResult.success(learnTeacherService.getPaperStudentDetail(examineeId));
  189. }
  190. @PostMapping("/postUnfinishAlarm")
  191. @ApiOperation("学生提醒")
  192. public AjaxResult postUnfinishAlarm(@ApiParam("组卷类型") String buildType, @ApiParam("批次") Long batchId, @ApiParam("班级") Long classId)
  193. {
  194. return AjaxResult.success();
  195. }
  196. @GetMapping("/questionTypes")
  197. @ApiOperation("题型列表")
  198. public AjaxResult questionTypes(@ApiParam("科目ID") Long subjectId, @RequestParam(required = false) @ApiParam("知识点") Collection<Long> knowledgeIds)
  199. {
  200. List<Dict> dictList = learnTeacherService.getQuestionTypes(subjectId, knowledgeIds).stream().map(t -> {
  201. QuestionType qt = QuestionType.of(t.getQtpye());
  202. return Dict.create().set("dictLabel", qt.getTitle()).set("dictValue", qt.getVal());
  203. }).sorted(new Comparator<Dict>() {
  204. @Override
  205. public int compare(Dict o1, Dict o2) {
  206. return o1.getInt("dictValue").compareTo(o2.getInt("dictValue"));
  207. }
  208. }).collect(Collectors.toList());
  209. return AjaxResult.success(dictList);
  210. }
  211. @PreAuthorize("@ss.hasPermi('learn:test_paper:add')")
  212. @PostMapping("/build/exactIntelligent")
  213. @ApiOperation("定向智能")
  214. public AjaxResult buildExactIntelligent(@RequestBody TestPaperVO.TestPaperBuildReq req)
  215. {
  216. req.setBuildType("ExactIntelligent");
  217. req.setDirectType(true);
  218. req.setSubjectId(11L);
  219. req.setTeacherId(getTeacherId());
  220. return AjaxResult.success(learnTeacherService.buildPapersDirect(req));
  221. }
  222. private Long getTeacherId() {
  223. return SecurityUtils.getLoginUser().getUser().getUserTypeId();
  224. }
  225. @PreAuthorize("@ss.hasPermi('learn:test_paper:add')")
  226. @PostMapping("/build/fullIntelligent")
  227. @ApiOperation("全量智能")
  228. public AjaxResult buildFullIntelligent(@RequestBody TestPaperVO.TestPaperBuildReq req)
  229. {
  230. req.setBuildType("FullIntelligent");
  231. req.setDirectType(false);
  232. if(null == req.getSubjectId()) {
  233. AjaxResult.error("未选择科目");
  234. }
  235. req.setTeacherId(getTeacherId());
  236. return AjaxResult.success(learnTeacherService.buildPapersFull(req));
  237. }
  238. @PreAuthorize("@ss.hasPermi('learn:test_paper:add')")
  239. @PostMapping("/build/exactHand")
  240. @ApiOperation("定向手动")
  241. public AjaxResult buildExactHand(@RequestBody TestPaperVO.TestPaperBuildReq req)
  242. {
  243. req.setBuildType("ExactHand");
  244. req.setDirectType(true);
  245. req.setSubjectId(11L);
  246. if(null == req.getMajorPlanId()) {
  247. AjaxResult.error("未选择计划");
  248. }
  249. req.setTeacherId(getTeacherId());
  250. return AjaxResult.success(learnTeacherService.buildPapersDirect(req));
  251. }
  252. @PreAuthorize("@ss.hasPermi('learn:test_paper:add')")
  253. @PostMapping("/build/fullHand")
  254. @ApiOperation("全量手动")
  255. public AjaxResult buildFullHand(@RequestBody TestPaperVO.TestPaperBuildReq req)
  256. {
  257. req.setBuildType("FullHand");
  258. req.setDirectType(false);
  259. if(null == req.getSubjectId()) {
  260. AjaxResult.error("未选择科目");
  261. }
  262. req.setTeacherId(getTeacherId());
  263. return AjaxResult.success(learnTeacherService.buildPapersFull(req));
  264. }
  265. @GetMapping("/universities")
  266. @ApiOperation("院校列表")
  267. public AjaxResult universities(@ApiParam("批次ID") Long batchId, @RequestParam @ApiParam("考生类型") ExamType examType)
  268. {
  269. SysUser sysUser = VistorContextHolder.getContext();
  270. return AjaxResult.success(learnTeacherService.selectUniversityList(getTeacherId(), batchId, null == examType ? sysUser.getExamType().name() : examType.name()));
  271. }
  272. @GetMapping("/majors")
  273. @ApiOperation("专业列表")
  274. public AjaxResult majors(@ApiParam("批次ID") Long batchId, @RequestParam @ApiParam("院校列表") Long universityId, @RequestParam @ApiParam("考生类型") ExamType examType)
  275. {
  276. SysUser sysUser = SecurityUtils.getLoginUser().getUser();
  277. DzControl control = dzControlService.selectDzControl(sysUser.getLocation(), examType);
  278. return AjaxResult.success(learnTeacherService.selectMajorList(sysUser.getUserTypeId(), universityId, control.getPlanYear(), batchId, examType.name()));
  279. }
  280. /**
  281. -- 1. 查询考试批次(假设每个老师自已控制)
  282. -- 2. 查询班老师班级列表
  283. -- 3. 查询定向院校列表
  284. -- 5. 查询定向院校专业组
  285. -- 6. 查询科目(分是否定向)
  286. -- 7. 查询知识点(分是否定向)
  287. -- 8. 查询单个定向时知识点树
  288. -- 9. 设置题型数量(预置题型要求,或人工指定,不指定时平均分配, 题型是针对院校的)
  289. */
  290. @GetMapping(value = "provinces")
  291. @Anonymous
  292. @ApiOperation("省份列表")
  293. public AjaxResult provinces()
  294. {
  295. DzControl cond = new DzControl();
  296. cond.setIsValid(1);
  297. return AjaxResult.success(dzControlService.selectDzControlList(cond).stream().map(t -> {
  298. JSONObject o = new JSONObject();
  299. o.put("dictValue", t.getLocation());
  300. o.put("dictLabel", t.getLocation());
  301. return o;
  302. }).collect(Collectors.toList()));
  303. }
  304. @GetMapping("/classes")
  305. @ApiOperation("2. 班级列表")
  306. public AjaxResult classes()
  307. {
  308. return AjaxResult.success(learnTeacherService.getClasses(getTeacherId()));
  309. }
  310. @GetMapping("/students")
  311. @ApiOperation("学生列表")
  312. public AjaxResult students(@ApiParam("批次ID") Long batchId, @ApiParam("班级ID") Long classId)
  313. {
  314. return AjaxResult.success(learnTeacherService.getStudents(batchId, classId));
  315. }
  316. @ApiOperation("04 取试卷列表")
  317. @GetMapping(value = "papers")
  318. public AjaxResult papers(@ApiParam("批次") @RequestParam(required = false) Integer batchId) {
  319. LearnTestPaper tpCond = new LearnTestPaper();
  320. tpCond.setCreatorId(getTeacherId());
  321. tpCond.setBatchId(batchId);
  322. List<LearnTestPaper> testPaperList = testPaperService.selectLearnTestPaperList(tpCond);
  323. List<LearnPaper> paperList = Lists.newArrayList();
  324. for(LearnTestPaper tp : testPaperList) {
  325. paperList.add(learnPaperService.selectLearnPaperById(tp.getPaperId()));
  326. }
  327. return AjaxResult.success(paperList);
  328. }
  329. }