SentenceController.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package com.qxgmat.controller.api;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.nuliji.tools.Response;
  4. import com.nuliji.tools.ResponseHelp;
  5. import com.nuliji.tools.Transform;
  6. import com.qxgmat.data.constants.enums.SettingKey;
  7. import com.qxgmat.data.dao.entity.*;
  8. import com.qxgmat.dto.request.UserSentenceCodeDto;
  9. import com.qxgmat.dto.request.UserSentenceProcessDto;
  10. import com.qxgmat.dto.response.UserSentenceArticleDto;
  11. import com.qxgmat.help.ShiroHelp;
  12. import com.qxgmat.service.SentencePaperService;
  13. import com.qxgmat.service.UserPaperService;
  14. import com.qxgmat.service.UsersService;
  15. import com.qxgmat.service.inline.*;
  16. import io.swagger.annotations.Api;
  17. import io.swagger.annotations.ApiOperation;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.validation.annotation.Validated;
  20. import org.springframework.web.bind.annotation.*;
  21. import javax.servlet.http.HttpSession;
  22. import java.util.List;
  23. import java.util.Map;
  24. @RestController
  25. @RequestMapping("/api/sentence")
  26. @Api(tags = "长难句", description = "长难句接口")
  27. public class SentenceController
  28. {
  29. @Autowired
  30. private ShiroHelp shiroHelp;
  31. @Autowired
  32. private UserPaperService userPaperService;
  33. @Autowired
  34. private UserReportService userReportService;
  35. @Autowired
  36. private UserQuestionService userQuestionService;
  37. @Autowired
  38. private SentenceArticleService sentenceArticleService;
  39. @Autowired
  40. private SentenceQuestionService sentenceQuestionService;
  41. @Autowired
  42. private SentencePaperService sentencePaperService;
  43. @Autowired
  44. private UserSentenceProcessService userSentenceProcessService;
  45. @Autowired
  46. private UsersService usersService;
  47. @Autowired
  48. private SentenceCodeService sentenceCodeService;
  49. @Autowired
  50. private SettingService settingService;
  51. @RequestMapping(value = "/info", method = RequestMethod.GET)
  52. @ApiOperation(value = "所有长难句信息", httpMethod = "GET")
  53. public Response<JSONObject> sentenceInfo(HttpSession session) {
  54. Setting entity = settingService.getByKey(SettingKey.SENTENCE);
  55. JSONObject value = entity.getValue();
  56. // 用户code状态
  57. User user = (User) shiroHelp.getLoginUser();
  58. SentenceCode code = sentenceCodeService.isActive(user.getId());
  59. if (code != null){
  60. value.put("code", code.getCode());
  61. }
  62. // 查询用户进度
  63. List<UserSentenceProcess> processList = userSentenceProcessService.listTotal(user.getId());
  64. Map process = Transform.getMap(processList,UserSentenceProcess.class, "chapter", "process");
  65. value.put("process", process);
  66. return ResponseHelp.success(value);
  67. }
  68. @RequestMapping(value = "/active", method = RequestMethod.PUT)
  69. @ApiOperation(value = "激活长难句", httpMethod = "PUT")
  70. public Response<Boolean> active(@RequestBody @Validated UserSentenceCodeDto dto) {
  71. UserSentenceProcess entity = Transform.dtoToEntity(dto);
  72. User user = (User) shiroHelp.getLoginUser();
  73. if (sentenceCodeService.isActive(user.getId()) == null){
  74. sentenceCodeService.active(user.getId(), dto.getCode());
  75. }
  76. return ResponseHelp.success(true);
  77. }
  78. @RequestMapping(value = "/article/list", method = RequestMethod.GET)
  79. @ApiOperation(value = "长难句文章列表", httpMethod = "GET")
  80. public Response<List<UserSentenceArticleDto>> listArticle(
  81. @RequestParam(required = true) Integer chapter,
  82. HttpSession session) {
  83. User user = (User) shiroHelp.getLoginUser();
  84. // 查询用户code
  85. if (sentenceCodeService.isActive(user.getId()) != null){
  86. List<SentenceArticle> p = sentenceArticleService.listByChapter(chapter);
  87. List<UserSentenceArticleDto> pr = Transform.convert(p, UserSentenceArticleDto.class);
  88. // 查询文章进度
  89. List<UserSentenceProcess> processList = userSentenceProcessService.listByChapter(user.getId(), chapter);
  90. Map process = Transform.getMap(processList,UserSentenceProcess.class, "part", "process");
  91. Transform.combine(pr, process, UserSentenceArticleDto.class, "part", "process");
  92. return ResponseHelp.success(pr);
  93. } else {
  94. List<SentenceArticle> p = sentenceArticleService.listByTrail();
  95. List<UserSentenceArticleDto> pr = Transform.convert(p, UserSentenceArticleDto.class);
  96. List<UserSentenceProcess> processList = userSentenceProcessService.listAllByTrail(user.getId());
  97. return ResponseHelp.success(pr);
  98. }
  99. }
  100. @RequestMapping(value = "/article/process", method = RequestMethod.PUT)
  101. @ApiOperation(value = "更新长难句文章进度", httpMethod = "PUT")
  102. public Response<Boolean> articleProcess(@RequestBody @Validated UserSentenceProcessDto dto) {
  103. UserSentenceProcess entity = Transform.dtoToEntity(dto);
  104. User user = (User) shiroHelp.getLoginUser();
  105. // 获取本章节的最大part数
  106. Integer max = sentenceArticleService.maxPart(dto.getChapter());
  107. userSentenceProcessService.updateProcess(user.getId(), dto.getChapter(), dto.getPart(), dto.getProcess(), max);
  108. return ResponseHelp.success(true);
  109. }
  110. @RequestMapping(value = "/paper/list", method = RequestMethod.GET)
  111. @ApiOperation(value = "长难句组卷列表", httpMethod = "GET")
  112. public Response<List<UserSentenceArticleDto>> listPaper(
  113. HttpSession session) {
  114. User user = (User) shiroHelp.getLoginUser();
  115. // 查询用户code
  116. if (sentenceCodeService.isActive(user.getId()) != null){
  117. } else {
  118. }
  119. return ResponseHelp.success(null);
  120. }
  121. @RequestMapping(value = "/question/detail", method = RequestMethod.GET)
  122. @ApiOperation(value = "获取题目详情", notes = "获取题目详情", httpMethod = "GET")
  123. public Response<User> detail(
  124. @RequestParam(required = false) String questionNoId
  125. ) {
  126. User user = (User) shiroHelp.getLoginUser();
  127. return ResponseHelp.success(null);
  128. }
  129. @RequestMapping(value = "/paper/start", method = RequestMethod.POST)
  130. @ApiOperation(value = "开始做题", notes = "提交考试设置", httpMethod = "POST")
  131. public Response<User> start(
  132. @RequestParam(required = false) String paperId
  133. ) {
  134. User user = (User) shiroHelp.getLoginUser();
  135. return ResponseHelp.success(null);
  136. }
  137. @RequestMapping(value = "/paper/next", method = RequestMethod.POST)
  138. @ApiOperation(value = "获取下一题", notes = "获取下一题", httpMethod = "POST")
  139. public Response<User> next(
  140. @RequestParam(required = false) String reportId
  141. ) {
  142. User user = (User) shiroHelp.getLoginUser();
  143. return ResponseHelp.success(null);
  144. }
  145. @RequestMapping(value = "/paper/submit", method = RequestMethod.POST)
  146. @ApiOperation(value = "提交题目答案", notes = "提交题目", httpMethod = "POST")
  147. public Response<User> submit(
  148. @RequestParam(required = false) String questionNoId
  149. ) {
  150. User user = (User) shiroHelp.getLoginUser();
  151. return ResponseHelp.success(null);
  152. }
  153. @RequestMapping(value = "/paper/finish", method = RequestMethod.POST)
  154. @ApiOperation(value = "完成考试", notes = "完成考试", httpMethod = "POST")
  155. public Response<User> finish(
  156. @RequestParam(required = false) String paperId
  157. ) {
  158. User user = (User) shiroHelp.getLoginUser();
  159. return ResponseHelp.success(null);
  160. }
  161. }