BaseController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. package com.qxgmat.controller.api;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.github.pagehelper.Page;
  5. import com.nuliji.tools.PageMessage;
  6. import com.nuliji.tools.Response;
  7. import com.nuliji.tools.ResponseHelp;
  8. import com.nuliji.tools.Transform;
  9. import com.nuliji.tools.exception.ParameterException;
  10. import com.qxgmat.data.constants.enums.ServiceKey;
  11. import com.qxgmat.data.constants.enums.SettingKey;
  12. import com.qxgmat.data.constants.enums.status.DirectionStatus;
  13. import com.qxgmat.data.dao.entity.*;
  14. import com.qxgmat.dto.extend.UserExtendDto;
  15. import com.qxgmat.dto.response.CommentDto;
  16. import com.qxgmat.dto.response.FaqDto;
  17. import com.qxgmat.service.UsersService;
  18. import com.qxgmat.service.inline.*;
  19. import io.swagger.annotations.Api;
  20. import io.swagger.annotations.ApiOperation;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.http.MediaType;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.RequestMethod;
  25. import org.springframework.web.bind.annotation.RequestParam;
  26. import org.springframework.web.bind.annotation.RestController;
  27. import javax.servlet.http.HttpSession;
  28. import java.util.Collection;
  29. import java.util.HashMap;
  30. import java.util.List;
  31. import java.util.Map;
  32. @RestController
  33. @RequestMapping("/api/base")
  34. @Api(tags = "基本接口", description = "全站基本数据接口", produces = MediaType.APPLICATION_JSON_VALUE)
  35. public class BaseController {
  36. @Autowired
  37. private SettingService settingService;
  38. @Autowired
  39. private AdService adService;
  40. @Autowired
  41. private RankService rankService;
  42. @Autowired
  43. private ContractService contractService;
  44. @Autowired
  45. private ExerciseStructService exerciseStructService;
  46. @Autowired
  47. private ExaminationStructService examinationStructService;
  48. @Autowired
  49. private FaqService faqService;
  50. @Autowired
  51. private CommentService commentService;
  52. @Autowired
  53. private ReadyReadService readyReadService;
  54. @Autowired
  55. private ReadyDataService readyDataService;
  56. @Autowired
  57. private ReadyRoomService readyRoomService;
  58. @Autowired
  59. private ReadyArticleCategoryService readyArticleCategoryService;
  60. @Autowired
  61. private ReadyArticleService readyArticleService;
  62. @Autowired
  63. private ReadyRoomAreaService readyRoomAreaService;
  64. @Autowired
  65. private UsersService usersService;
  66. @RequestMapping(value = "/index", method = RequestMethod.GET)
  67. @ApiOperation(value = "获取首页配置", httpMethod = "GET")
  68. private Response<JSONObject> index(){
  69. Setting entity = settingService.getByKey(SettingKey.INDEX);
  70. return ResponseHelp.success(entity.getValue());
  71. }
  72. @RequestMapping(value = "/base", method = RequestMethod.GET)
  73. @ApiOperation(value = "获取基础配置", httpMethod = "GET")
  74. private Response<JSONObject> base(){
  75. Setting entity = settingService.getByKey(SettingKey.BASE);
  76. return ResponseHelp.success(entity.getValue());
  77. }
  78. @RequestMapping(value = "/ad", method = RequestMethod.GET)
  79. @ApiOperation(value = "获取广告", notes = "获取广告列表", httpMethod = "GET")
  80. public Response<List<Ad>> ad(
  81. @RequestParam(required = true) String channel
  82. ) {
  83. List<Ad> adList = adService.all(channel);
  84. return ResponseHelp.success(adList);
  85. }
  86. @RequestMapping(value = "/promote", method = RequestMethod.GET)
  87. @ApiOperation(value = "获取课程促销", httpMethod = "GET")
  88. private Response<JSONObject> getPromote(){
  89. Setting entity = settingService.getByKey(SettingKey.PROMOTE);
  90. return ResponseHelp.success(entity.getValue());
  91. }
  92. @RequestMapping(value = "/tips", method = RequestMethod.GET)
  93. @ApiOperation(value = "获取提示信息", notes = "获取提示信息", httpMethod = "GET")
  94. public Response<Map<String, String>> tips(@RequestParam(required = true) String[] position) {
  95. Setting entity = settingService.getByKey(SettingKey.TIPS);
  96. JSONObject value = entity.getValue();
  97. Map<String, String> map = new HashMap<>();
  98. for (String p: position) {
  99. map.put(p, value.getString(p));
  100. }
  101. return ResponseHelp.success(map);
  102. }
  103. @RequestMapping(value = "/sentence", method = RequestMethod.GET)
  104. @ApiOperation(value = "获取长难句信息", notes = "获取长难句信息", httpMethod = "GET")
  105. public Response<JSONObject> sentence() {
  106. Setting entity = settingService.getByKey(SettingKey.SENTENCE_INFO);
  107. return ResponseHelp.success(entity.getValue());
  108. }
  109. @RequestMapping(value = "/experience", method = RequestMethod.GET)
  110. @ApiOperation(value = "获取心经信息", notes = "获取心经信息", httpMethod = "GET")
  111. public Response<JSONObject> experience() {
  112. Setting entity = settingService.getByKey(SettingKey.EXPERIENCE_INFO);
  113. return ResponseHelp.success(entity.getValue());
  114. }
  115. @RequestMapping(value = "/wechat", method = RequestMethod.GET)
  116. @ApiOperation(value = "获取心经信息", notes = "获取心经信息", httpMethod = "GET")
  117. public Response<JSONObject> wechat() {
  118. Setting entity = settingService.getByKey(SettingKey.WECHAT_INFO);
  119. return ResponseHelp.success(entity.getValue());
  120. }
  121. @RequestMapping(value = "/score", method = RequestMethod.GET)
  122. @ApiOperation(value = "考分计算", notes = "获取考分排行信息", httpMethod = "GET")
  123. public Response<Rank> score(
  124. @RequestParam(required = true) Number total,
  125. @RequestParam(required = true) Number quant
  126. ) {
  127. Rank rank = rankService.compute(total, quant);
  128. if (rank == null){
  129. throw new ParameterException("排名信息为空");
  130. }
  131. return ResponseHelp.success(rank);
  132. }
  133. @RequestMapping(value = "/course_index", method = RequestMethod.GET)
  134. @ApiOperation(value = "获取课程首页", notes = "获取课程首页", httpMethod = "GET")
  135. public Response<JSONObject> courseIndex() {
  136. Setting entity = settingService.getByKey(SettingKey.COURSE_INDEX);
  137. return ResponseHelp.success(entity.getValue());
  138. }
  139. @RequestMapping(value = "/exercise/main", method = RequestMethod.GET)
  140. @ApiOperation(value = "所有练习头2层", httpMethod = "GET")
  141. public Response<List<ExerciseStruct>> exerciseMain(HttpSession session) {
  142. List<ExerciseStruct> p = exerciseStructService.main();
  143. return ResponseHelp.success(p);
  144. }
  145. @RequestMapping(value = "/exercise/children", method = RequestMethod.GET)
  146. @ApiOperation(value = "所有练习层级", httpMethod = "GET")
  147. public Response<List<ExerciseStruct>> exerciseChildren(
  148. @RequestParam(required = true) Integer id,
  149. @RequestParam(required = false, defaultValue = "false") boolean children,
  150. HttpSession session) {
  151. List<ExerciseStruct> p = exerciseStructService.children(id, children? 1 : 0);
  152. return ResponseHelp.success(p);
  153. }
  154. @RequestMapping(value = "/exercise/parent", method = RequestMethod.GET)
  155. @ApiOperation(value = "练习层级父级", httpMethod = "GET")
  156. public Response<List<ExerciseStruct>> exerciseParent(
  157. @RequestParam(required = true) Integer id,
  158. HttpSession session) {
  159. List<ExerciseStruct> p = exerciseStructService.parent(id);
  160. return ResponseHelp.success(p);
  161. }
  162. @RequestMapping(value = "/exercise/all", method = RequestMethod.GET)
  163. @ApiOperation(value = "练习层级范围", httpMethod = "GET")
  164. public Response<List<ExerciseStruct>> exerciseRange(HttpSession session) {
  165. List<ExerciseStruct> p = exerciseStructService.all();
  166. return ResponseHelp.success(p);
  167. }
  168. @RequestMapping(value = "/examination/main", method = RequestMethod.GET)
  169. @ApiOperation(value = "所有模考头2层", httpMethod = "GET")
  170. public Response<List<ExaminationStruct>> examinationMain(HttpSession session) {
  171. List<ExaminationStruct> p = examinationStructService.main();
  172. return ResponseHelp.success(p);
  173. }
  174. @RequestMapping(value = "/examination/children", method = RequestMethod.GET)
  175. @ApiOperation(value = "所有模考层级", httpMethod = "GET")
  176. public Response<List<ExaminationStruct>> examinationChildren(
  177. @RequestParam(required = true) Integer id,
  178. @RequestParam(required = false, defaultValue = "false") boolean children,
  179. HttpSession session) {
  180. List<ExaminationStruct> p = examinationStructService.children(id, children ? 1 :0);
  181. return ResponseHelp.success(p);
  182. }
  183. @RequestMapping(value = "/examination/parent", method = RequestMethod.GET)
  184. @ApiOperation(value = "模考层级父级", httpMethod = "GET")
  185. public Response<List<ExaminationStruct>> examinationParent(
  186. @RequestParam(required = true) Integer id,
  187. HttpSession session) {
  188. List<ExaminationStruct> p = examinationStructService.parent(id);
  189. return ResponseHelp.success(p);
  190. }
  191. @RequestMapping(value = "/examination/number", method = RequestMethod.GET)
  192. @ApiOperation(value = "模考题目数", notes = "获取模考题目数", httpMethod = "GET")
  193. public Response<JSONObject> examinationNumber() {
  194. Setting entity = settingService.getByKey(SettingKey.EXAMINATION_TIME);
  195. return ResponseHelp.success(entity.getValue());
  196. }
  197. @RequestMapping(value = "/service", method = RequestMethod.GET)
  198. @ApiOperation(value = "获取服务信息", notes = "获取服务信息", httpMethod = "GET")
  199. public Response<JSONObject> service(@RequestParam(required = true) String service) {
  200. SettingKey key;
  201. switch(ServiceKey.ValueOf(service)){
  202. case TEXTBOOK:
  203. key = SettingKey.SERVICE_TEXTBOOK;
  204. break;
  205. case VIP:
  206. key = SettingKey.SERVICE_VIP;
  207. break;
  208. case QX_CAT:
  209. key = SettingKey.SERVICE_QX_CAT;
  210. break;
  211. default:
  212. throw new ParameterException("服务信息错误");
  213. }
  214. Setting setting = settingService.getByKey(key);
  215. return ResponseHelp.success(setting.getValue());
  216. }
  217. @RequestMapping(value = "/contract", method = RequestMethod.GET)
  218. @ApiOperation(value = "获取合同信息", notes = "获取合同信息", httpMethod = "GET")
  219. public Response<Contract> contract(@RequestParam(required = true) String key) {
  220. Contract contract = contractService.getContract(key);
  221. return ResponseHelp.success(contract);
  222. }
  223. @RequestMapping(value = "/faq/list", method = RequestMethod.GET)
  224. @ApiOperation(value = "faq列表", httpMethod = "GET")
  225. public Response<PageMessage<FaqDto>> listFaq(
  226. @RequestParam(required = false, defaultValue = "1") int page,
  227. @RequestParam(required = false, defaultValue = "100") int size,
  228. @RequestParam(required = true) String channel,
  229. @RequestParam(required = false) String position,
  230. @RequestParam(required = false, defaultValue = "id") String order,
  231. @RequestParam(required = false, defaultValue = "desc") String direction,
  232. HttpSession session) {
  233. Page<Faq> p = faqService.list(page, size, channel, position);
  234. List<FaqDto> pr = Transform.convert(p, FaqDto.class);
  235. Collection userIds = Transform.getIds(p, Faq.class, "userId");
  236. List<User> userList = usersService.select(userIds);
  237. Transform.combine(pr, userList, FaqDto.class, "userId", "user", User.class, "id", UserExtendDto.class);
  238. return ResponseHelp.success(pr, page, size, p.getTotal());
  239. }
  240. @RequestMapping(value = "/comment/list", method = RequestMethod.GET)
  241. @ApiOperation(value = "评论列表", httpMethod = "GET")
  242. public Response<PageMessage<CommentDto>> listComment(
  243. @RequestParam(required = false, defaultValue = "1") int page,
  244. @RequestParam(required = false, defaultValue = "100") int size,
  245. @RequestParam(required = true) String channel,
  246. @RequestParam(required = false) String position,
  247. @RequestParam(required = false, defaultValue = "id") String order,
  248. @RequestParam(required = false, defaultValue = "desc") String direction,
  249. HttpSession session) {
  250. Page<Comment> p = commentService.list(page, size, channel, position);
  251. Collection userIds = Transform.getIds(p, Comment.class, "userId");
  252. List<User> userList = usersService.select(userIds);
  253. commentService.replaceUser(p, userList);
  254. List<CommentDto> pr = Transform.convert(p, CommentDto.class);
  255. return ResponseHelp.success(pr, page, size, p.getTotal());
  256. }
  257. @RequestMapping(value = "/ready_info", method = RequestMethod.GET)
  258. @ApiOperation(value = "获取GetReady信息", notes = "获取GetReady信息", httpMethod = "GET")
  259. public Response<JSONObject> readyRead() {
  260. Setting entity = settingService.getByKey(SettingKey.READY_READ);
  261. JSONObject info = entity.getValue();
  262. List<ReadyArticleCategory> articleCategoryList = readyArticleCategoryService.all();
  263. List<ReadyRoomArea> roomAreaList = readyRoomAreaService.all();
  264. JSONObject dto = new JSONObject();
  265. dto.put("read", info);
  266. dto.put("category", articleCategoryList);
  267. dto.put("area", roomAreaList);
  268. return ResponseHelp.success(dto);
  269. }
  270. @RequestMapping(value = "/article/list", method = RequestMethod.GET)
  271. @ApiOperation(value = "获取文章信息", notes = "获取文章信息", httpMethod = "GET")
  272. public Response<List<ReadyArticle>> listArticle(
  273. @RequestParam(required = true) Integer categoryId
  274. ) {
  275. List<ReadyArticle> list = readyArticleService.list(categoryId);
  276. return ResponseHelp.success(list);
  277. }
  278. @RequestMapping(value = "/read/list", method = RequestMethod.GET)
  279. @ApiOperation(value = "推荐阅读", httpMethod = "GET")
  280. public Response<PageMessage<ReadyRead>> listRead(
  281. @RequestParam(required = false, defaultValue = "1") int page,
  282. @RequestParam(required = false, defaultValue = "100") int size,
  283. @RequestParam(required = true) String plate,
  284. @RequestParam(required = false, defaultValue = "id") String order,
  285. @RequestParam(required = false, defaultValue = "desc") String direction,
  286. HttpSession session) {
  287. Page<ReadyRead> p = readyReadService.list(page, size, plate, order, DirectionStatus.ValueOf(direction));
  288. return ResponseHelp.success(p, page, size, p.getTotal());
  289. }
  290. @RequestMapping(value = "/room/list", method = RequestMethod.GET)
  291. @ApiOperation(value = "考场查询", httpMethod = "GET")
  292. public Response<PageMessage<ReadyRoom>> listRoom(
  293. @RequestParam(required = false, defaultValue = "1") int page,
  294. @RequestParam(required = false, defaultValue = "100") int size,
  295. @RequestParam(required = false) String keyword,
  296. @RequestParam(required = false) Integer areaId,
  297. @RequestParam(required = false) Boolean isOverseas,
  298. @RequestParam(required = false, defaultValue = "id") String order,
  299. @RequestParam(required = false, defaultValue = "desc") String direction,
  300. HttpSession session) {
  301. Page<ReadyRoom> p = readyRoomService.list(page, size, keyword, areaId, isOverseas, order, DirectionStatus.ValueOf(direction));
  302. return ResponseHelp.success(p, page, size, p.getTotal());
  303. }
  304. @RequestMapping(value = "/data/all", method = RequestMethod.GET)
  305. @ApiOperation(value = "资料", httpMethod = "GET")
  306. public Response<List<ReadyData>> allData(
  307. @RequestParam(required = false) Boolean isOfficial,
  308. HttpSession session) {
  309. List<ReadyData> p = readyDataService.all(isOfficial);
  310. return ResponseHelp.success(p);
  311. }
  312. }