QuestionController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. package com.qxgmat.controller.api;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.github.pagehelper.Page;
  4. import com.nuliji.tools.*;
  5. import com.qxgmat.data.constants.enums.logic.ExerciseLogic;
  6. import com.qxgmat.data.constants.enums.module.PaperModule;
  7. import com.qxgmat.data.constants.enums.module.PayModule;
  8. import com.qxgmat.data.dao.entity.*;
  9. import com.qxgmat.data.relation.entity.UserExercisePaperRelation;
  10. import com.qxgmat.data.relation.entity.UserHomeworkPreviewRelation;
  11. import com.qxgmat.dto.extend.UserExercisePaperExtendDto;
  12. import com.qxgmat.dto.extend.UserHomeworkPreviewExtendDto;
  13. import com.qxgmat.dto.request.*;
  14. import com.qxgmat.dto.response.*;
  15. import com.qxgmat.help.ShiroHelp;
  16. import com.qxgmat.service.ExercisePaperService;
  17. import com.qxgmat.service.HomeworkPreviewService;
  18. import com.qxgmat.service.UserQuestionService;
  19. import com.qxgmat.service.extend.QuestionFlowService;
  20. import com.qxgmat.service.inline.*;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiOperation;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.validation.annotation.Validated;
  25. import org.springframework.web.bind.annotation.*;
  26. import javax.servlet.http.HttpSession;
  27. import java.util.Collection;
  28. import java.util.HashMap;
  29. import java.util.List;
  30. import java.util.Map;
  31. @RestController
  32. @RequestMapping("/api/question")
  33. @Api(tags = "题目", description = "题目接口")
  34. public class QuestionController {
  35. @Autowired
  36. private ShiroHelp shiroHelp;
  37. @Autowired
  38. private HomeworkPreviewService homeworkPreviewService;
  39. @Autowired
  40. private ExercisePaperService exercisePaperService;
  41. @Autowired
  42. private QuestionNoService questionNoService;
  43. @Autowired
  44. private UserQuestionService userQuestionService;
  45. @Autowired
  46. private UserClassService userClassService;
  47. @Autowired
  48. private UserPayService userPayService;
  49. @Autowired
  50. private QuestionFlowService questionFlowService;
  51. @RequestMapping(value = "/class/process", method = RequestMethod.GET)
  52. @ApiOperation(value = "获取课程进度", notes = "获取所有课程及状态进度", httpMethod = "GET")
  53. public Response<List<UserClassDetailDto>> classProcess() {
  54. User user = (User) shiroHelp.getLoginUser();
  55. List<UserClass> userClassList = userClassService.getByUser(user.getId());
  56. List<UserClassDetailDto> dtos = Transform.convert(userClassList, UserClassDetailDto.class);
  57. // 获取每个科目的最后2次作业
  58. Map<Object, Collection<UserHomeworkPreviewRelation>> previewMap = homeworkPreviewService.groupByCategory(user.getId(), 3);
  59. Transform.combine(dtos, previewMap, UserClassDetailDto.class, "category", "previews", UserHomeworkPreviewExtendDto.class);
  60. // 获取课程状态:已购买未开通
  61. List<UserPay> pays = userPayService.listUnUse(user.getId(), PayModule.CLASS);
  62. Collection ids = Transform.getIds(userClassList, UserClass.class, "category");
  63. for(UserPay pay : pays){
  64. Integer category = Integer.valueOf(pay.getModuleExtend());
  65. if (!ids.contains(category)){
  66. UserClassDetailDto dto = new UserClassDetailDto();
  67. dto.setCategory(category);
  68. dto.setPayed(true);
  69. dtos.add(dto);
  70. }
  71. }
  72. return ResponseHelp.success(dtos);
  73. }
  74. @RequestMapping(value = "/preview/list", method = RequestMethod.GET)
  75. @ApiOperation(value = "获取预习作业列表", notes = "获取预习作业列表", httpMethod = "GET")
  76. public Response<PageMessage<UserHomeworkPreviewExtendDto>> listPreview(
  77. @RequestParam(required = false, defaultValue = "1") int page,
  78. @RequestParam(required = false, defaultValue = "100") int size,
  79. @RequestParam(required = false) Number category,
  80. @RequestParam(required = false) String endTime,
  81. @RequestParam(required = false) Boolean finish
  82. ) {
  83. User user = (User) shiroHelp.getLoginUser();
  84. PageResult<UserHomeworkPreviewRelation> p = homeworkPreviewService.list(page, size, category, user.getId(), endTime, finish);
  85. List<UserHomeworkPreviewExtendDto> pr = Transform.convert(p, UserHomeworkPreviewExtendDto.class);
  86. // 获取试卷统计信息
  87. Map map = Transform.getMap(p, UserHomeworkPreviewRelation.class, "id", "preview");
  88. Map<Integer, Integer[]> questionNoIdsMap = new HashMap<>();
  89. for(Object value : map.keySet()){
  90. Integer key = (Integer) value;
  91. HomeworkPreview preview = (HomeworkPreview) map.get(key);
  92. questionNoIdsMap.put(key, preview.getQuestionNoIds());
  93. }
  94. Map statMap = questionNoService.statPaperMap(questionNoIdsMap);
  95. Transform.combine(pr, statMap, UserHomeworkPreviewExtendDto.class, "id", "stat");
  96. return ResponseHelp.success(pr, page, size, p.getTotal());
  97. }
  98. @RequestMapping(value = "/exercise/process", method = RequestMethod.GET)
  99. @ApiOperation(value = "练习进度", httpMethod = "GET")
  100. public Response<List<UserExerciseGroupDto>> exerciseProcess(
  101. @RequestParam(required = true) Integer structId, // 第三层,查询第4层,以及第三层汇总
  102. HttpSession session) {
  103. Page<UserExerciseGroupDto> p=null;
  104. // todo 获取数据
  105. return ResponseHelp.success(p);
  106. }
  107. @RequestMapping(value = "/exercise/place", method = RequestMethod.GET)
  108. @ApiOperation(value = "练习组卷考点分组条件", httpMethod = "GET")
  109. public Response<List<String>> exercisePlace(HttpSession session) {
  110. return ResponseHelp.success(exercisePaperService.groupPlace());
  111. }
  112. @RequestMapping(value = "/exercise/paper", method = RequestMethod.GET)
  113. @ApiOperation(value = "练习组卷列表", httpMethod = "GET")
  114. public Response<PageMessage<UserExercisePaperExtendDto>> listExercisePaper(
  115. @RequestParam(required = false, defaultValue = "1") int page,
  116. @RequestParam(required = false, defaultValue = "100") int size,
  117. @RequestParam(required = true) Integer structId,
  118. @RequestParam(required = true) String logic,
  119. @RequestParam(required = false, name = "logic_extend") String logicExtend,
  120. @RequestParam(required = false) Integer times,
  121. HttpSession session) {
  122. User user = (User) shiroHelp.getLoginUser();
  123. PageResult<UserExercisePaperRelation> p = exercisePaperService.list(page, size, structId, user.getId(), ExerciseLogic.ValueOf(logic), logicExtend, times);
  124. List<UserExercisePaperExtendDto> pr = Transform.convert(p, UserExercisePaperExtendDto.class);
  125. // 获取试卷统计信息
  126. Map map = Transform.getMap(p, UserExercisePaperRelation.class, "id", "paper");
  127. Map<Integer, Integer[]> questionNoIdsMap = new HashMap<>();
  128. for(Object value : map.keySet()){
  129. Integer key = (Integer) value;
  130. ExercisePaper paper = (ExercisePaper) map.get(key);
  131. questionNoIdsMap.put(key, paper.getQuestionNoIds());
  132. }
  133. Map statMap = questionNoService.statPaperMap(questionNoIdsMap);
  134. Transform.combine(pr, statMap, UserHomeworkPreviewExtendDto.class, "id", "stat");
  135. return ResponseHelp.success(pr, page, size, p.getTotal());
  136. }
  137. @RequestMapping(value = "/examination/process", method = RequestMethod.GET)
  138. @ApiOperation(value = "模考进度", httpMethod = "GET")
  139. public Response<PageMessage<ExercisePaper>> examinationProcess(
  140. @RequestParam(required = false, defaultValue = "1") int page,
  141. @RequestParam(required = false, defaultValue = "100") int size,
  142. HttpSession session) {
  143. Page<ExercisePaper> p = null;
  144. return ResponseHelp.success(p, page, size, p.getTotal());
  145. }
  146. @RequestMapping(value = "/examination/paper", method = RequestMethod.GET)
  147. @ApiOperation(value = "模考组卷列表", httpMethod = "GET")
  148. public Response<PageMessage<ExercisePaper>> examinationPaperList(
  149. @RequestParam(required = false, defaultValue = "1") int page,
  150. @RequestParam(required = false, defaultValue = "100") int size,
  151. HttpSession session) {
  152. Page<ExercisePaper> p = null;
  153. return ResponseHelp.success(p, page, size, p.getTotal());
  154. }
  155. @RequestMapping(value = "/detail", method = RequestMethod.GET)
  156. @ApiOperation(value = "获取题目详情", notes = "获取题目详情", httpMethod = "GET")
  157. public Response<UserQuestionDetailDto> detail(
  158. @RequestParam(required = false) String userQuestionId
  159. ) {
  160. User user = (User) shiroHelp.getLoginUser();
  161. return ResponseHelp.success(null);
  162. }
  163. @RequestMapping(value = "/exercise/start", method = RequestMethod.POST)
  164. @ApiOperation(value = "开始: 练习", notes = "提交考试设置", httpMethod = "POST")
  165. public Response<UserReportDto> startExercise(@RequestBody @Validated ExerciseStartDto dto) {
  166. User user = (User) shiroHelp.getLoginUser();
  167. JSONObject setting = new JSONObject();
  168. setting.put("disorder", dto.getDisorder());
  169. UserReport report = questionFlowService.start(user.getId(), PaperModule.HOMEWORK_PREVIEW, dto.getPaperId(), setting);
  170. return ResponseHelp.success(Transform.convert(report, UserReportDto.class));
  171. }
  172. @RequestMapping(value = "/preview/start", method = RequestMethod.POST)
  173. @ApiOperation(value = "开始: 预习作业", notes = "提交考试设置", httpMethod = "POST")
  174. public Response<UserReportDto> startPreview(@RequestBody @Validated PreviewStartDto dto) {
  175. User user = (User) shiroHelp.getLoginUser();
  176. JSONObject setting = new JSONObject();
  177. setting.put("disorder", dto.getDisorder());
  178. UserReport report = questionFlowService.start(user.getId(), PaperModule.HOMEWORK_PREVIEW, dto.getPaperId(), setting);
  179. return ResponseHelp.success(Transform.convert(report, UserReportDto.class));
  180. }
  181. @RequestMapping(value = "/continue", method = RequestMethod.POST)
  182. @ApiOperation(value = "继续做题", notes = "获取报告信息", httpMethod = "POST")
  183. public Response<UserReportDto> continueReport(@RequestBody @Validated ReportContinueDto dto) {
  184. User user = (User) shiroHelp.getLoginUser();
  185. UserReport report = questionFlowService.continueReport(user.getId(), dto.getUserReportId());
  186. return ResponseHelp.success(Transform.convert(report, UserReportDto.class));
  187. }
  188. @RequestMapping(value = "/next", method = RequestMethod.POST)
  189. @ApiOperation(value = "获取下一题", notes = "获取下一题", httpMethod = "POST")
  190. public Response<UserQuestionBaseDto> next(@RequestBody @Validated ReportNextDto dto) {
  191. User user = (User) shiroHelp.getLoginUser();
  192. // 根据对应paper获取,以及设定的setting获取下一题
  193. UserQuestion userQuestion = questionFlowService.next(user.getId(), dto.getUserReportId());
  194. // 绑定questionNos
  195. // 绑定question
  196. // 绑定collect
  197. return ResponseHelp.success(null);
  198. }
  199. @RequestMapping(value = "/submit", method = RequestMethod.POST)
  200. @ApiOperation(value = "提交题目答案", notes = "提交题目", httpMethod = "POST")
  201. public Response<Boolean> submit(@RequestBody @Validated QuestionSubmitDto dto) {
  202. User user = (User) shiroHelp.getLoginUser();
  203. Boolean result = questionFlowService.submit(user.getId(), dto.getUserQuestionId(), dto.getTime(), dto.getAnswer());
  204. return ResponseHelp.success(result);
  205. }
  206. @RequestMapping(value = "/finish", method = RequestMethod.POST)
  207. @ApiOperation(value = "完成考试", notes = "完成考试", httpMethod = "POST")
  208. public Response<Boolean> finish(@RequestBody @Validated ReportFinishDto dto) {
  209. User user = (User) shiroHelp.getLoginUser();
  210. Boolean result = questionFlowService.finish(user.getId(), dto.getUserReportId());
  211. return ResponseHelp.success(result);
  212. }
  213. @RequestMapping(value = "/restart", method = RequestMethod.POST)
  214. @ApiOperation(value = "重置考试", notes = "重置考试", httpMethod = "POST")
  215. public Response<User> restart(@RequestBody @Validated PaperRestartDto dto) {
  216. User user = (User) shiroHelp.getLoginUser();
  217. questionFlowService.restart(dto.getUserPaperId(), user.getId());
  218. return ResponseHelp.success(null);
  219. }
  220. }