SentenceController.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package com.qxgmat.controller.admin;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.github.pagehelper.Page;
  4. import com.nuliji.tools.PageMessage;
  5. import com.nuliji.tools.Response;
  6. import com.nuliji.tools.ResponseHelp;
  7. import com.nuliji.tools.Transform;
  8. import com.nuliji.tools.exception.ParameterException;
  9. import com.qxgmat.data.constants.enums.SettingKey;
  10. import com.qxgmat.data.dao.entity.SentenceArticle;
  11. import com.qxgmat.data.dao.entity.SentenceQuestion;
  12. import com.qxgmat.data.dao.entity.Setting;
  13. import com.qxgmat.data.relation.entity.SentenceQuestionRelation;
  14. import com.qxgmat.dto.admin.request.ExerciseStructDto;
  15. import com.qxgmat.dto.admin.request.SentenceQuestionDto;
  16. import com.qxgmat.dto.admin.response.SentenceQuestionListDto;
  17. import com.qxgmat.service.inline.SentencePaperService;
  18. import com.qxgmat.service.extend.SentenceService;
  19. import com.qxgmat.service.inline.*;
  20. import com.qxgmat.task.AsyncTask;
  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.HttpServletRequest;
  26. import javax.servlet.http.HttpSession;
  27. import java.util.List;
  28. @RestController("AdminSentenceController")
  29. @RequestMapping("/admin/sentence")
  30. public class SentenceController {
  31. @Autowired
  32. private ManagerLogService managerLogService;
  33. @Autowired
  34. private SentenceQuestionService sentenceQuestionService;
  35. @Autowired
  36. private SentencePaperService sentencePaperService;
  37. @Autowired
  38. private SentenceArticleService sentenceArticleService;
  39. @Autowired
  40. private SentenceService sentenceService;
  41. @Autowired
  42. private QuestionService questionService;
  43. @Autowired
  44. private SettingService settingService;
  45. @Autowired
  46. private AsyncTask asyncTask;
  47. @RequestMapping(value = "/article/add", method = RequestMethod.POST)
  48. @ApiOperation(value = "添加长难句文章", httpMethod = "POST")
  49. public Response<SentenceArticle> addArticle(@RequestBody @Validated SentenceArticle dto, HttpServletRequest request) {
  50. SentenceArticle entity = Transform.convert(dto, SentenceArticle.class);
  51. entity = sentenceArticleService.add(entity);
  52. managerLogService.log(request);
  53. return ResponseHelp.success(Transform.convert(entity, SentenceArticle.class));
  54. }
  55. @RequestMapping(value = "/article/edit", method = RequestMethod.PUT)
  56. @ApiOperation(value = "编辑长难句文章", httpMethod = "PUT")
  57. public Response<Boolean> editArticle(@RequestBody @Validated SentenceArticle dto, HttpServletRequest request) {
  58. SentenceArticle entity = Transform.convert(dto, SentenceArticle.class);
  59. entity = sentenceArticleService.edit(entity);
  60. managerLogService.log(request);
  61. return ResponseHelp.success(true);
  62. }
  63. @RequestMapping(value = "/article/delete", method = RequestMethod.DELETE)
  64. @ApiOperation(value = "删除长难句文章", httpMethod = "DELETE")
  65. public Response<Boolean> deleteArticle(@RequestParam int id, HttpServletRequest request) {
  66. sentenceArticleService.delete(id);
  67. managerLogService.log(request);
  68. return ResponseHelp.success(sentenceArticleService.delete(id));
  69. }
  70. @RequestMapping(value = "/article/detail", method = RequestMethod.GET)
  71. @ApiOperation(value = "获取长难句文章", httpMethod = "GET")
  72. public Response<SentenceArticle> detailArticle(@RequestParam int id,HttpSession session) {
  73. SentenceArticle entity = sentenceArticleService.get(id);
  74. return ResponseHelp.success(Transform.convert(entity, SentenceArticle.class));
  75. }
  76. @RequestMapping(value = "/article/list", method = RequestMethod.GET)
  77. @ApiOperation(value = "长难句文章列表", httpMethod = "GET")
  78. public Response<PageMessage<SentenceArticle>> listArticle(
  79. @RequestParam(required = false, defaultValue = "1") int page,
  80. @RequestParam(required = false, defaultValue = "100") int size,
  81. @RequestParam(required = false) Number chapter,
  82. @RequestParam(required = false) Number part,
  83. HttpSession session) {
  84. Page<SentenceArticle> p = sentenceArticleService.select(page, size, chapter, part);
  85. List<SentenceArticle> pr = Transform.convert(p, SentenceArticle.class);
  86. return ResponseHelp.success(pr, page, size, p.getTotal());
  87. }
  88. @RequestMapping(value = "/question/add", method = RequestMethod.POST)
  89. @ApiOperation(value = "添加长难句题目", httpMethod = "POST")
  90. public Response<SentenceQuestion> addQuestion(@RequestBody @Validated SentenceQuestionDto dto, HttpServletRequest request) {
  91. SentenceQuestionRelation entity = Transform.dtoToEntity(dto);
  92. SentenceQuestion entityNew = sentenceService.addQuestion(entity);
  93. managerLogService.log(request);
  94. return ResponseHelp.success(entityNew);
  95. }
  96. @RequestMapping(value = "/question/edit", method = RequestMethod.PUT)
  97. @ApiOperation(value = "修改长难句题目", httpMethod = "PUT")
  98. public Response<Boolean> editQuestion(@RequestBody @Validated SentenceQuestionDto dto, HttpServletRequest request) {
  99. SentenceQuestionRelation entity = Transform.dtoToEntity(dto);
  100. sentenceService.editQuestion(entity);
  101. managerLogService.log(request);
  102. return ResponseHelp.success(true);
  103. }
  104. // @RequestMapping(value = "/question/delete", method = RequestMethod.DELETE)
  105. // @ApiOperation(value = "删除长难句题目", httpMethod = "DELETE")
  106. // public Response<Boolean> deleteQuestion(@RequestParam int id, HttpServletRequest request) {
  107. // managerLogService.log(request);
  108. // return ResponseHelp.success(sentenceQuestionService.delete(id));
  109. // }
  110. @RequestMapping(value = "/question/detail", method = RequestMethod.GET)
  111. @ApiOperation(value = "获取长难句题目", httpMethod = "GET")
  112. public Response<SentenceQuestionRelation> detailQuestion(@RequestParam int id, HttpSession session) {
  113. SentenceQuestion entity = sentenceQuestionService.get(id);
  114. SentenceQuestionRelation relation = sentenceQuestionService.relation(entity);
  115. return ResponseHelp.success(relation);
  116. }
  117. @RequestMapping(value = "/question/list", method = RequestMethod.GET)
  118. @ApiOperation(value = "长难句题目列表", httpMethod = "GET")
  119. public Response<PageMessage<SentenceQuestionListDto>> listQuestion(
  120. @RequestParam(required = false, defaultValue = "1") int page,
  121. @RequestParam(required = false, defaultValue = "100") int size,
  122. HttpSession session) {
  123. Page<SentenceQuestion> p = sentenceQuestionService.select(page, size);
  124. List<SentenceQuestionListDto> pr = Transform.convert(p, SentenceQuestionListDto.class);
  125. return ResponseHelp.success(pr, page, size, p.getTotal());
  126. }
  127. @RequestMapping(value = "/question/search", method = RequestMethod.GET)
  128. @ApiOperation(value = "搜索长难句题目列表", httpMethod = "GET")
  129. public Response<PageMessage<SentenceQuestionListDto>> listQuestion(
  130. @RequestParam(required = false, defaultValue = "1") int page,
  131. @RequestParam(required = false, defaultValue = "100") int size,
  132. @RequestParam(required = false) String keyword,
  133. @RequestParam(required = false) Integer[] ids,
  134. HttpSession session) {
  135. Page<SentenceQuestion> p;
  136. if (ids != null && ids.length > 0){
  137. p = sentenceQuestionService.select(ids);
  138. }else{
  139. p = sentenceQuestionService.searchAdmin(page, size, keyword);
  140. }
  141. List<SentenceQuestionListDto> pr = Transform.convert(p, SentenceQuestionListDto.class);
  142. return ResponseHelp.success(pr, page, size, p.getTotal());
  143. }
  144. @RequestMapping(value = "/paper/auto", method = RequestMethod.POST)
  145. @ApiOperation(value = "自动组卷", httpMethod = "POST")
  146. public Response<Boolean> autoPaper(@RequestBody @Validated ExerciseStructDto dto, HttpServletRequest request) {
  147. // 判断当前组卷状态
  148. Setting setting = settingService.getByKey(SettingKey.SENTENCE_PAPER_STATUS);
  149. JSONObject status = setting.getValue();
  150. if (status.getInteger("progress")<100){
  151. throw new ParameterException("组卷进行中,请稍后再试");
  152. }
  153. asyncTask.autoSentencePaper();
  154. return ResponseHelp.success(true);
  155. }
  156. @RequestMapping(value = "/paper/auto", method = RequestMethod.GET)
  157. @ApiOperation(value = "自动组卷状态", httpMethod = "GET")
  158. public Response<JSONObject> autoPaperStatus(HttpServletRequest request) {
  159. // 判断当前组卷状态
  160. Setting setting = settingService.getByKey(SettingKey.SENTENCE_PAPER_STATUS);
  161. JSONObject status = setting.getValue();
  162. return ResponseHelp.success(status);
  163. }
  164. }