QuestionController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. package com.qxgmat.controller.api;
  2. import com.github.pagehelper.Page;
  3. import com.nuliji.tools.*;
  4. import com.qxgmat.data.constants.enums.logic.ExerciseLogic;
  5. import com.qxgmat.data.constants.enums.module.PayModule;
  6. import com.qxgmat.data.dao.entity.*;
  7. import com.qxgmat.data.relation.entity.UserExercisePaperRelation;
  8. import com.qxgmat.data.relation.entity.UserHomeworkPreviewRelation;
  9. import com.qxgmat.dto.extend.UserExercisePaperExtendDto;
  10. import com.qxgmat.dto.extend.UserHomeworkPreviewExtendDto;
  11. import com.qxgmat.dto.request.*;
  12. import com.qxgmat.dto.response.UserClassDetailDto;
  13. import com.qxgmat.dto.response.UserExerciseGroupDto;
  14. import com.qxgmat.dto.response.UserQuestionDetailDto;
  15. import com.qxgmat.help.ShiroHelp;
  16. import com.qxgmat.service.ExercisePaperService;
  17. import com.qxgmat.service.HomeworkPreviewService;
  18. import com.qxgmat.service.UserPaperService;
  19. import com.qxgmat.service.inline.*;
  20. import io.swagger.annotations.Api;
  21. import io.swagger.annotations.ApiOperation;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.validation.annotation.Validated;
  24. import org.springframework.web.bind.annotation.*;
  25. import javax.servlet.http.HttpSession;
  26. import java.util.Collection;
  27. import java.util.HashMap;
  28. import java.util.List;
  29. import java.util.Map;
  30. @RestController
  31. @RequestMapping("/api/question")
  32. @Api(tags = "题目", description = "题目接口")
  33. public class QuestionController {
  34. @Autowired
  35. private ShiroHelp shiroHelp;
  36. @Autowired
  37. private QuestionNoService questionNoService;
  38. @Autowired
  39. private UserPaperService userPaperService;
  40. @Autowired
  41. private UserReportService userReportService;
  42. @Autowired
  43. private UserQuestionService userQuestionService;
  44. @Autowired
  45. private HomeworkPreviewService homeworkPreviewService;
  46. @Autowired
  47. private ExercisePaperService exercisePaperService;
  48. @Autowired
  49. private UserClassService userClassService;
  50. @Autowired
  51. private UserPayService userPayService;
  52. @RequestMapping(value = "/class/process", method = RequestMethod.GET)
  53. @ApiOperation(value = "获取课程进度", notes = "获取所有课程及状态进度", httpMethod = "GET")
  54. public Response<List<UserClassDetailDto>> classProcess() {
  55. User user = (User) shiroHelp.getLoginUser();
  56. List<UserClass> userClassList = userClassService.getByUser(user.getId());
  57. List<UserClassDetailDto> dtos = Transform.convert(userClassList, UserClassDetailDto.class);
  58. // 获取每个科目的最后3次作业
  59. Map<Object, Collection<UserHomeworkPreviewRelation>> previewMap = homeworkPreviewService.groupByCategory(user.getId(), 3);
  60. Transform.combine(dtos, previewMap, UserClassDetailDto.class, "category", "previews", UserHomeworkPreviewExtendDto.class);
  61. // 获取课程状态
  62. List<UserPay> pays = userPayService.listUnUse(user.getId(), PayModule.CLASS);
  63. Collection ids = Transform.getIds(userClassList, UserClass.class, "category");
  64. for(UserPay pay : pays){
  65. Integer category = Integer.valueOf(pay.getModuleExtend());
  66. if (!ids.contains(category)){
  67. UserClassDetailDto dto = new UserClassDetailDto();
  68. dto.setCategory(category);
  69. dto.setPayed(true);
  70. dtos.add(dto);
  71. }
  72. }
  73. return ResponseHelp.success(dtos);
  74. }
  75. @RequestMapping(value = "/preview/list", method = RequestMethod.GET)
  76. @ApiOperation(value = "获取预习作业列表", notes = "获取预习作业列表", httpMethod = "GET")
  77. public Response<PageMessage<UserHomeworkPreviewExtendDto>> listPreview(
  78. @RequestParam(required = false, defaultValue = "1") int page,
  79. @RequestParam(required = false, defaultValue = "100") int size,
  80. @RequestParam(required = false) Number category,
  81. @RequestParam(required = false) String endTime,
  82. @RequestParam(required = false) Boolean finish
  83. ) {
  84. User user = (User) shiroHelp.getLoginUser();
  85. PageResult<UserHomeworkPreviewRelation> p = homeworkPreviewService.list(page, size, category, user.getId(), endTime, finish);
  86. List<UserHomeworkPreviewExtendDto> pr = Transform.convert(p, UserHomeworkPreviewExtendDto.class);
  87. // 获取试卷统计信息
  88. Map map = Transform.getMap(p, UserHomeworkPreviewRelation.class, "id", "preview");
  89. Map<Integer, Integer[]> questionNoIdsMap = new HashMap<>();
  90. for(Object value : map.keySet()){
  91. Integer key = (Integer) value;
  92. HomeworkPreview preview = (HomeworkPreview) map.get(key);
  93. questionNoIdsMap.put(key, preview.getQuestionNoIds());
  94. }
  95. Map statMap = questionNoService.statPaperMap(questionNoIdsMap);
  96. Transform.combine(pr, statMap, UserHomeworkPreviewExtendDto.class, "id", "stat");
  97. return ResponseHelp.success(pr, page, size, p.getTotal());
  98. }
  99. @RequestMapping(value = "/exercise/process", method = RequestMethod.GET)
  100. @ApiOperation(value = "练习进度", httpMethod = "GET")
  101. public Response<List<UserExerciseGroupDto>> exerciseProcess(
  102. @RequestParam(required = true) Integer structId, // 第三层,查询第4层,以及第三层汇总
  103. HttpSession session) {
  104. Page<UserExerciseGroupDto> p=null;
  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<Boolean> start(@RequestBody @Validated ExerciseStartDto dto) {
  166. User user = (User) shiroHelp.getLoginUser();
  167. return ResponseHelp.success(null);
  168. }
  169. @RequestMapping(value = "/preview/start", method = RequestMethod.POST)
  170. @ApiOperation(value = "开始: 预习作业", notes = "提交考试设置", httpMethod = "POST")
  171. public Response<User> start(@RequestBody @Validated PreviewStartDto dto) {
  172. User user = (User) shiroHelp.getLoginUser();
  173. return ResponseHelp.success(null);
  174. }
  175. @RequestMapping(value = "/next", method = RequestMethod.POST)
  176. @ApiOperation(value = "获取下一题", notes = "获取下一题", httpMethod = "POST")
  177. public Response<User> next(@RequestBody @Validated QuestionNextDto dto) {
  178. User user = (User) shiroHelp.getLoginUser();
  179. return ResponseHelp.success(null);
  180. }
  181. @RequestMapping(value = "/submit", method = RequestMethod.POST)
  182. @ApiOperation(value = "提交题目答案", notes = "提交题目", httpMethod = "POST")
  183. public Response<User> submit(@RequestBody @Validated QuestionSubmitDto dto) {
  184. User user = (User) shiroHelp.getLoginUser();
  185. return ResponseHelp.success(null);
  186. }
  187. @RequestMapping(value = "/finish", method = RequestMethod.POST)
  188. @ApiOperation(value = "完成考试", notes = "完成考试", httpMethod = "POST")
  189. public Response<User> finish(@RequestBody @Validated QuestionFinishDto dto) {
  190. User user = (User) shiroHelp.getLoginUser();
  191. return ResponseHelp.success(null);
  192. }
  193. }