ReadyController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. package com.qxgmat.controller.admin;
  2. import com.github.pagehelper.Page;
  3. import com.nuliji.tools.PageMessage;
  4. import com.nuliji.tools.Response;
  5. import com.nuliji.tools.ResponseHelp;
  6. import com.nuliji.tools.Transform;
  7. import com.qxgmat.data.constants.enums.status.DirectionStatus;
  8. import com.qxgmat.data.dao.entity.*;
  9. import com.qxgmat.dto.admin.request.*;
  10. import com.qxgmat.help.ShiroHelp;
  11. import com.qxgmat.service.inline.*;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiOperation;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.http.MediaType;
  18. import org.springframework.validation.annotation.Validated;
  19. import org.springframework.web.bind.annotation.*;
  20. import javax.servlet.http.HttpSession;
  21. import java.util.List;
  22. @RestController("AdminReadyController")
  23. @RequestMapping("/admin/ready")
  24. @Api(tags = "GetReady接口", description = "ready相关", produces = MediaType.APPLICATION_JSON_VALUE)
  25. public class ReadyController {
  26. private static final Logger logger = LoggerFactory.getLogger(QuestionController.class);
  27. @Autowired
  28. private ShiroHelp shiroHelp;
  29. @Autowired
  30. private ReadyArticleService readyArticleService;
  31. @Autowired
  32. private ReadyArticleCategoryService readyArticleCategoryService;
  33. @Autowired
  34. private ReadyRoomService readyRoomService;
  35. @Autowired
  36. private ReadyRoomAreaService readyRoomAreaService;
  37. @Autowired
  38. private ReadyReadService readyReadService;
  39. @Autowired
  40. private ReadyDataService readyDataService;
  41. @RequestMapping(value = "/category/all", method = RequestMethod.GET)
  42. @ApiOperation(value = "所有分类层级", httpMethod = "GET")
  43. public Response<List<ReadyArticleCategory>> allCategory(HttpSession session) {
  44. List<ReadyArticleCategory> p = readyArticleCategoryService.all();
  45. return ResponseHelp.success(p);
  46. }
  47. @RequestMapping(value = "/category/edit", method = RequestMethod.PUT)
  48. @ApiOperation(value = "修改分类信息", httpMethod = "PUT")
  49. public Response<Boolean> editCategory(@RequestBody @Validated ReadyArticleCategoryDto dto, HttpSession session) {
  50. ReadyArticleCategory entity = Transform.dtoToEntity(dto);
  51. if (dto.getIndex() != null){
  52. // 排序操作
  53. readyArticleCategoryService.changeOrder(dto.getId(), dto.getIndex());
  54. }
  55. readyArticleCategoryService.edit(entity);
  56. return ResponseHelp.success(true);
  57. }
  58. @RequestMapping(value = "/category/delete", method = RequestMethod.DELETE)
  59. @ApiOperation(value = "删除分类信息", httpMethod = "DELETE")
  60. public Response<Boolean> deleteCategory(int id, HttpSession session) {
  61. ReadyArticleCategory category = readyArticleCategoryService.get(id);
  62. readyArticleService.deleteByCategory(category.getId());
  63. readyArticleCategoryService.delete(id);
  64. return ResponseHelp.success(true);
  65. }
  66. @RequestMapping(value = "/article/add", method = RequestMethod.POST)
  67. @ApiOperation(value = "添加文章", httpMethod = "POST")
  68. private Response<Boolean> addArticle(@RequestBody @Validated ReadyArticleDto dto){
  69. ReadyArticle entity = Transform.dtoToEntity(dto);
  70. if(entity.getCategoryId() == null || entity.getCategoryId() == 0){
  71. if (entity.getParentCategoryId() == null || entity.getParentCategoryId() == 0){
  72. // 添加一级标题
  73. ReadyArticleCategory category = readyArticleCategoryService.addCategory(dto.getParentCategory(), 0);
  74. entity.setParentCategoryId(category.getId());
  75. }
  76. // 添加二级标题
  77. ReadyArticleCategory category = readyArticleCategoryService.addCategory(dto.getCategory(), entity.getParentCategoryId());
  78. entity.setCategoryId(category.getId());
  79. }
  80. readyArticleService.add(entity);
  81. return ResponseHelp.success(true);
  82. }
  83. @RequestMapping(value = "/article/edit", method = RequestMethod.PUT)
  84. @ApiOperation(value = "修改文章", httpMethod = "PUT")
  85. private Response<Boolean> editArticle(@RequestBody @Validated ReadyArticleDto dto){
  86. ReadyArticle entity = Transform.dtoToEntity(dto);
  87. readyArticleService.edit(entity);
  88. return ResponseHelp.success(true);
  89. }
  90. @RequestMapping(value = "/article/delete", method = RequestMethod.DELETE)
  91. @ApiOperation(value = "删除文章", httpMethod = "DELETE")
  92. private Response<Boolean> deleteArticle(@RequestParam int id){
  93. readyArticleService.delete(id);
  94. return ResponseHelp.success(true);
  95. }
  96. @RequestMapping(value = "/article/detail", method = RequestMethod.GET)
  97. @ApiOperation(value = "文章详情", httpMethod = "GET")
  98. private Response<ReadyArticle> detailArticle(@RequestParam int id){
  99. ReadyArticle article = readyArticleService.get(id);
  100. return ResponseHelp.success(article);
  101. }
  102. @RequestMapping(value = "/article/list", method = RequestMethod.GET)
  103. @ApiOperation(value = "获取文章列表", httpMethod = "GET")
  104. private Response<PageMessage<ReadyArticle>> listArticle(
  105. @RequestParam(required = false, defaultValue = "1") int page,
  106. @RequestParam(required = false, defaultValue = "100") int size,
  107. @RequestParam(required = false) Integer parentCategoryId,
  108. @RequestParam(required = false) Integer categoryId,
  109. @RequestParam(required = false, defaultValue = "id") String order,
  110. @RequestParam(required = false, defaultValue = "desc") String direction
  111. ){
  112. Page<ReadyArticle> p = readyArticleService.listAdmin(page, size, parentCategoryId, categoryId, order, DirectionStatus.ValueOf(direction));
  113. return ResponseHelp.success(p, page, size, p.getTotal());
  114. }
  115. @RequestMapping(value = "/area/all", method = RequestMethod.GET)
  116. @ApiOperation(value = "所有区域层级", httpMethod = "GET")
  117. public Response<List<ReadyRoomArea>> allArea(HttpSession session) {
  118. List<ReadyRoomArea> p = readyRoomAreaService.all();
  119. return ResponseHelp.success(p);
  120. }
  121. @RequestMapping(value = "/room/add", method = RequestMethod.POST)
  122. @ApiOperation(value = "添加考场", httpMethod = "POST")
  123. private Response<Boolean> addRoom(@RequestBody @Validated ReadyRoomDto dto){
  124. ReadyRoom entity = Transform.dtoToEntity(dto);
  125. readyRoomService.add(entity);
  126. return ResponseHelp.success(true);
  127. }
  128. @RequestMapping(value = "/room/edit", method = RequestMethod.PUT)
  129. @ApiOperation(value = "修改考场", httpMethod = "PUT")
  130. private Response<Boolean> editRoom(@RequestBody @Validated ReadyRoomDto dto){
  131. ReadyRoom entity = Transform.dtoToEntity(dto);
  132. readyRoomService.edit(entity);
  133. return ResponseHelp.success(true);
  134. }
  135. @RequestMapping(value = "/room/delete", method = RequestMethod.DELETE)
  136. @ApiOperation(value = "删除考场", httpMethod = "DELETE")
  137. private Response<Boolean> deleteRoom(@RequestParam int id){
  138. readyRoomService.delete(id);
  139. return ResponseHelp.success(true);
  140. }
  141. @RequestMapping(value = "/room/detail", method = RequestMethod.GET)
  142. @ApiOperation(value = "考场详情", httpMethod = "GET")
  143. private Response<ReadyRoom> detailRoom(@RequestParam int id){
  144. ReadyRoom article = readyRoomService.get(id);
  145. return ResponseHelp.success(article);
  146. }
  147. @RequestMapping(value = "/room/list", method = RequestMethod.GET)
  148. @ApiOperation(value = "获取考场列表", httpMethod = "GET")
  149. private Response<PageMessage<ReadyRoom>> listRoom(
  150. @RequestParam(required = false, defaultValue = "1") int page,
  151. @RequestParam(required = false, defaultValue = "100") int size,
  152. @RequestParam(required = false) String position,
  153. @RequestParam(required = false) Integer areaId,
  154. @RequestParam(required = false, defaultValue = "id") String order,
  155. @RequestParam(required = false, defaultValue = "desc") String direction
  156. ){
  157. Page<ReadyRoom> p = readyRoomService.listAdmin(page, size, position, areaId, order, DirectionStatus.ValueOf(direction));
  158. return ResponseHelp.success(p, page, size, p.getTotal());
  159. }
  160. @RequestMapping(value = "/read/add", method = RequestMethod.POST)
  161. @ApiOperation(value = "添加文章", httpMethod = "POST")
  162. private Response<Boolean> addRead(@RequestBody @Validated ReadyReadDto dto){
  163. ReadyRead entity = Transform.dtoToEntity(dto);
  164. readyReadService.add(entity);
  165. return ResponseHelp.success(true);
  166. }
  167. @RequestMapping(value = "/read/edit", method = RequestMethod.PUT)
  168. @ApiOperation(value = "修改文章", httpMethod = "PUT")
  169. private Response<Boolean> editRead(@RequestBody @Validated ReadyReadDto dto){
  170. ReadyRead entity = Transform.dtoToEntity(dto);
  171. readyReadService.edit(entity);
  172. return ResponseHelp.success(true);
  173. }
  174. @RequestMapping(value = "/read/delete", method = RequestMethod.DELETE)
  175. @ApiOperation(value = "删除文章", httpMethod = "DELETE")
  176. private Response<Boolean> deleteRead(@RequestParam int id){
  177. readyReadService.delete(id);
  178. return ResponseHelp.success(true);
  179. }
  180. @RequestMapping(value = "/read/detail", method = RequestMethod.GET)
  181. @ApiOperation(value = "文章详情", httpMethod = "GET")
  182. private Response<ReadyRead> detailRead(@RequestParam int id){
  183. ReadyRead article = readyReadService.get(id);
  184. return ResponseHelp.success(article);
  185. }
  186. @RequestMapping(value = "/read/list", method = RequestMethod.GET)
  187. @ApiOperation(value = "获取文章列表", httpMethod = "GET")
  188. private Response<PageMessage<ReadyRead>> listRead(
  189. @RequestParam(required = false, defaultValue = "1") int page,
  190. @RequestParam(required = false, defaultValue = "100") int size,
  191. @RequestParam(required = false) String plate,
  192. @RequestParam(required = false, defaultValue = "id") String order,
  193. @RequestParam(required = false, defaultValue = "desc") String direction
  194. ){
  195. Page<ReadyRead> p = readyReadService.listAdmin(page, size, plate, order, DirectionStatus.ValueOf(direction));
  196. return ResponseHelp.success(p, page, size, p.getTotal());
  197. }
  198. @RequestMapping(value = "/data/add", method = RequestMethod.POST)
  199. @ApiOperation(value = "添加资料", httpMethod = "POST")
  200. private Response<Boolean> addData(@RequestBody @Validated ReadyDataDto dto){
  201. ReadyData entity = Transform.dtoToEntity(dto);
  202. readyDataService.add(entity);
  203. return ResponseHelp.success(true);
  204. }
  205. @RequestMapping(value = "/data/edit", method = RequestMethod.PUT)
  206. @ApiOperation(value = "修改文章", httpMethod = "PUT")
  207. private Response<Boolean> editData(@RequestBody @Validated ReadyDataDto dto){
  208. ReadyData entity = Transform.dtoToEntity(dto);
  209. readyDataService.edit(entity);
  210. return ResponseHelp.success(true);
  211. }
  212. @RequestMapping(value = "/data/delete", method = RequestMethod.DELETE)
  213. @ApiOperation(value = "删除文章", httpMethod = "DELETE")
  214. private Response<Boolean> deleteData(@RequestParam int id){
  215. readyDataService.delete(id);
  216. return ResponseHelp.success(true);
  217. }
  218. @RequestMapping(value = "/data/detail", method = RequestMethod.GET)
  219. @ApiOperation(value = "文章详情", httpMethod = "GET")
  220. private Response<ReadyData> detailData(@RequestParam int id){
  221. ReadyData entity = readyDataService.get(id);
  222. return ResponseHelp.success(entity);
  223. }
  224. @RequestMapping(value = "/data/list", method = RequestMethod.GET)
  225. @ApiOperation(value = "获取文章列表", httpMethod = "GET")
  226. private Response<PageMessage<ReadyData>> listData(
  227. @RequestParam(required = false, defaultValue = "1") int page,
  228. @RequestParam(required = false, defaultValue = "100") int size,
  229. @RequestParam(required = false) Boolean isOfficial,
  230. @RequestParam(required = false, defaultValue = "id") String order,
  231. @RequestParam(required = false, defaultValue = "desc") String direction
  232. ){
  233. Page<ReadyData> p = readyDataService.listAdmin(page, size, isOfficial, order, DirectionStatus.ValueOf(direction));
  234. return ResponseHelp.success(p, page, size, p.getTotal());
  235. }
  236. }