SettingController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. package com.qxgmat.controller.admin;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.github.pagehelper.Page;
  4. import com.nuliji.tools.*;
  5. import com.qxgmat.data.constants.enums.SettingKey;
  6. import com.qxgmat.data.constants.enums.module.ChannelModule;
  7. import com.qxgmat.data.dao.entity.*;
  8. import com.qxgmat.dto.admin.request.CommentDto;
  9. import com.qxgmat.dto.admin.request.FaqDto;
  10. import com.qxgmat.dto.admin.request.RankDto;
  11. import com.qxgmat.service.inline.*;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiOperation;
  14. import org.apache.poi.hssf.usermodel.HSSFCell;
  15. import org.apache.poi.hssf.usermodel.HSSFRow;
  16. import org.apache.poi.hssf.usermodel.HSSFSheet;
  17. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  18. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.http.MediaType;
  23. import org.springframework.validation.annotation.Validated;
  24. import org.springframework.web.bind.annotation.*;
  25. import org.springframework.web.multipart.MultipartFile;
  26. import java.io.FileInputStream;
  27. import java.io.IOException;
  28. import java.io.InputStream;
  29. import java.util.ArrayList;
  30. import java.util.List;
  31. @RestController("AdminSettingController")
  32. @RequestMapping("/admin/setting")
  33. @Api(tags = "配置信息接口", description = "全局独立配置设置", produces = MediaType.APPLICATION_JSON_VALUE)
  34. public class SettingController {
  35. private static final Logger logger = LoggerFactory.getLogger(SettingController.class);
  36. @Autowired
  37. private SettingService settingService;
  38. @Autowired
  39. private RankService rankService;
  40. @Autowired
  41. private CommentService commentService;
  42. @Autowired
  43. private FaqService faqService;
  44. @Autowired
  45. private MessageService messageService;
  46. @RequestMapping(value = "/index", method = RequestMethod.PUT)
  47. @ApiOperation(value = "修改首页配置", httpMethod = "PUT")
  48. private Response<Boolean> editIndex(@RequestBody @Validated JSONObject dto){
  49. Setting entity = settingService.getByKey(SettingKey.INDEX);
  50. entity.setValue(dto);
  51. settingService.edit(entity);
  52. return ResponseHelp.success(true);
  53. }
  54. @RequestMapping(value = "/index", method = RequestMethod.GET)
  55. @ApiOperation(value = "获取首页配置", httpMethod = "GET")
  56. private Response<JSONObject> getIndex(){
  57. Setting entity = settingService.getByKey(SettingKey.INDEX);
  58. logger.debug("{}", entity);
  59. return ResponseHelp.success(entity.getValue());
  60. }
  61. @RequestMapping(value = "/place", method = RequestMethod.PUT)
  62. @ApiOperation(value = "修改考点设置", httpMethod = "PUT")
  63. private Response<Boolean> editPlace(@RequestBody @Validated JSONObject dto){
  64. Setting entity = settingService.getByKey(SettingKey.PLACE);
  65. entity.setValue(dto);
  66. settingService.edit(entity);
  67. return ResponseHelp.success(true);
  68. }
  69. @RequestMapping(value = "/place", method = RequestMethod.GET)
  70. @ApiOperation(value = "获取考点配置", httpMethod = "GET")
  71. private Response<JSONObject> getPlace(){
  72. Setting entity = settingService.getByKey(SettingKey.PLACE);
  73. return ResponseHelp.success(entity.getValue());
  74. }
  75. @RequestMapping(value = "/message_template", method = RequestMethod.PUT)
  76. @ApiOperation(value = "修改消息模版", httpMethod = "PUT")
  77. private Response<Boolean> editMessageTemplate(@RequestBody @Validated JSONObject dto){
  78. Setting entity = settingService.getByKey(SettingKey.MESSAGE_TEMPLATE);
  79. entity.setValue(dto);
  80. settingService.edit(entity);
  81. return ResponseHelp.success(true);
  82. }
  83. @RequestMapping(value = "/message_template", method = RequestMethod.GET)
  84. @ApiOperation(value = "获取消息模版", httpMethod = "GET")
  85. private Response<JSONObject> getMessageTemplate(){
  86. Setting entity = settingService.getByKey(SettingKey.MESSAGE_TEMPLATE);
  87. return ResponseHelp.success(entity.getValue());
  88. }
  89. @RequestMapping(value = "/sentence", method = RequestMethod.PUT)
  90. @ApiOperation(value = "修改长难句设置", httpMethod = "PUT")
  91. private Response<Boolean> editSentence(@RequestBody @Validated JSONObject dto){
  92. Setting entity = settingService.getByKey(SettingKey.SENTENCE);
  93. entity.setValue(dto);
  94. settingService.edit(entity);
  95. return ResponseHelp.success(true);
  96. }
  97. @RequestMapping(value = "/sentence", method = RequestMethod.GET)
  98. @ApiOperation(value = "获取长难句配置", httpMethod = "GET")
  99. private Response<JSONObject> getSentence(){
  100. Setting entity = settingService.getByKey(SettingKey.SENTENCE);
  101. return ResponseHelp.success(entity.getValue());
  102. }
  103. @RequestMapping(value = "/exercise_time", method = RequestMethod.PUT)
  104. @ApiOperation(value = "修改做题时间设置", httpMethod = "PUT")
  105. private Response<Boolean> editExerciseTime(@RequestBody @Validated JSONObject dto){
  106. Setting entity = settingService.getByKey(SettingKey.EXERCISE_TIME);
  107. entity.setValue(dto);
  108. settingService.edit(entity);
  109. return ResponseHelp.success(true);
  110. }
  111. @RequestMapping(value = "/exercise_time", method = RequestMethod.GET)
  112. @ApiOperation(value = "获取做题时间配置", httpMethod = "GET")
  113. private Response<JSONObject> getExerciseTime(){
  114. Setting entity = settingService.getByKey(SettingKey.EXERCISE_TIME);
  115. return ResponseHelp.success(entity.getValue());
  116. }
  117. @RequestMapping(value = "/examination_time", method = RequestMethod.PUT)
  118. @ApiOperation(value = "修改做题时间设置", httpMethod = "PUT")
  119. private Response<Boolean> editExaminationTime(@RequestBody @Validated JSONObject dto){
  120. Setting entity = settingService.getByKey(SettingKey.EXAMINATION_TIME);
  121. entity.setValue(dto);
  122. settingService.edit(entity);
  123. return ResponseHelp.success(true);
  124. }
  125. @RequestMapping(value = "/examination_time", method = RequestMethod.GET)
  126. @ApiOperation(value = "获取做题时间配置", httpMethod = "GET")
  127. private Response<JSONObject> getExaminationTime(){
  128. Setting entity = settingService.getByKey(SettingKey.EXAMINATION_TIME);
  129. return ResponseHelp.success(entity.getValue());
  130. }
  131. @RequestMapping(value = "/filter_time", method = RequestMethod.PUT)
  132. @ApiOperation(value = "修改剔除时间设置", httpMethod = "PUT")
  133. private Response<Boolean> editFilterTime(@RequestBody @Validated JSONObject dto){
  134. Setting entity = settingService.getByKey(SettingKey.FILTER_TIME);
  135. entity.setValue(dto);
  136. settingService.edit(entity);
  137. return ResponseHelp.success(true);
  138. }
  139. @RequestMapping(value = "/filter_time", method = RequestMethod.GET)
  140. @ApiOperation(value = "获取剔除时间配置", httpMethod = "GET")
  141. private Response<JSONObject> getFilterTime(){
  142. Setting entity = settingService.getByKey(SettingKey.FILTER_TIME);
  143. return ResponseHelp.success(entity.getValue());
  144. }
  145. @RequestMapping(value = "/sentence_time", method = RequestMethod.PUT)
  146. @ApiOperation(value = "修改长难句时间设置", httpMethod = "PUT")
  147. private Response<Boolean> editSentenceTime(@RequestBody @Validated JSONObject dto){
  148. Setting entity = settingService.getByKey(SettingKey.SENTENCE_TIME);
  149. entity.setValue(dto);
  150. settingService.edit(entity);
  151. return ResponseHelp.success(true);
  152. }
  153. @RequestMapping(value = "/sentence_time", method = RequestMethod.GET)
  154. @ApiOperation(value = "获取长难句时间配置", httpMethod = "GET")
  155. private Response<JSONObject> getSentenceTime(){
  156. Setting entity = settingService.getByKey(SettingKey.SENTENCE_TIME);
  157. return ResponseHelp.success(entity.getValue());
  158. }
  159. @RequestMapping(value = "/textbook_time", method = RequestMethod.PUT)
  160. @ApiOperation(value = "修改机经时间设置", httpMethod = "PUT")
  161. private Response<Boolean> editTextbookTime(@RequestBody @Validated JSONObject dto){
  162. Setting entity = settingService.getByKey(SettingKey.TEXTBOOK_TIME);
  163. entity.setValue(dto);
  164. settingService.edit(entity);
  165. return ResponseHelp.success(true);
  166. }
  167. @RequestMapping(value = "/textbook_time", method = RequestMethod.GET)
  168. @ApiOperation(value = "获取机经时间配置", httpMethod = "GET")
  169. private Response<JSONObject> getTextbookTime(){
  170. Setting entity = settingService.getByKey(SettingKey.TEXTBOOK_TIME);
  171. return ResponseHelp.success(entity.getValue());
  172. }
  173. @RequestMapping(value = "/score_switch", method = RequestMethod.PUT)
  174. @ApiOperation(value = "修改分数开关", httpMethod = "PUT")
  175. private Response<Boolean> editScoreSwitch(@RequestBody @Validated JSONObject dto){
  176. Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH);
  177. entity.setValue(dto);
  178. settingService.edit(entity);
  179. return ResponseHelp.success(true);
  180. }
  181. @RequestMapping(value = "/score_switch", method = RequestMethod.GET)
  182. @ApiOperation(value = "获取分数开关", httpMethod = "GET")
  183. private Response<JSONObject> getScoreSwitch(){
  184. Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH);
  185. return ResponseHelp.success(entity.getValue());
  186. }
  187. @RequestMapping(value = "/service_vip", method = RequestMethod.PUT)
  188. @ApiOperation(value = "修改Vip服务", httpMethod = "PUT")
  189. private Response<Boolean> editServiceVip(@RequestBody @Validated JSONObject dto){
  190. Setting entity = settingService.getByKey(SettingKey.SERVICE_VIP);
  191. entity.setValue(dto);
  192. settingService.edit(entity);
  193. return ResponseHelp.success(true);
  194. }
  195. @RequestMapping(value = "/service_vip", method = RequestMethod.GET)
  196. @ApiOperation(value = "获取Vip服务", httpMethod = "GET")
  197. private Response<JSONObject> getServiceVip(){
  198. Setting entity = settingService.getByKey(SettingKey.SERVICE_VIP);
  199. return ResponseHelp.success(entity.getValue());
  200. }
  201. @RequestMapping(value = "/service_textbook", method = RequestMethod.PUT)
  202. @ApiOperation(value = "修改千行CAT服务", httpMethod = "PUT")
  203. private Response<Boolean> editServiceTextbook(@RequestBody @Validated JSONObject dto){
  204. Setting entity = settingService.getByKey(SettingKey.SERVICE_TEXTBOOK);
  205. entity.setValue(dto);
  206. settingService.edit(entity);
  207. return ResponseHelp.success(true);
  208. }
  209. @RequestMapping(value = "/service_textbook", method = RequestMethod.GET)
  210. @ApiOperation(value = "获取千行CAT服务", httpMethod = "GET")
  211. private Response<JSONObject> getServiceTextbook(){
  212. Setting entity = settingService.getByKey(SettingKey.SERVICE_TEXTBOOK);
  213. return ResponseHelp.success(entity.getValue());
  214. }
  215. @RequestMapping(value = "/service_qx_cat", method = RequestMethod.PUT)
  216. @ApiOperation(value = "修改千行CAT服务", httpMethod = "PUT")
  217. private Response<Boolean> editServiceQXCat(@RequestBody @Validated JSONObject dto){
  218. Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH);
  219. entity.setValue(dto);
  220. settingService.edit(entity);
  221. return ResponseHelp.success(true);
  222. }
  223. @RequestMapping(value = "/service_qx_cat", method = RequestMethod.GET)
  224. @ApiOperation(value = "获取千行CAT服务", httpMethod = "GET")
  225. private Response<JSONObject> getServiceQXCat(){
  226. Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH);
  227. return ResponseHelp.success(entity.getValue());
  228. }
  229. @RequestMapping(value = "/course_index", method = RequestMethod.PUT)
  230. @ApiOperation(value = "修改课程首页", httpMethod = "PUT")
  231. private Response<Boolean> editCourseIndex(@RequestBody @Validated JSONObject dto){
  232. Setting entity = settingService.getByKey(SettingKey.COURSE_INDEX);
  233. entity.setValue(dto);
  234. settingService.edit(entity);
  235. return ResponseHelp.success(true);
  236. }
  237. @RequestMapping(value = "/course_index", method = RequestMethod.GET)
  238. @ApiOperation(value = "获取课程首页", httpMethod = "GET")
  239. private Response<JSONObject> getCourseIndex(){
  240. Setting entity = settingService.getByKey(SettingKey.COURSE_INDEX);
  241. return ResponseHelp.success(entity.getValue());
  242. }
  243. @RequestMapping(value = "/tips", method = RequestMethod.PUT)
  244. @ApiOperation(value = "修改结构说明", httpMethod = "PUT")
  245. private Response<Boolean> editTips(@RequestBody @Validated JSONObject dto){
  246. Setting entity = settingService.getByKey(SettingKey.TIPS);
  247. entity.setValue(dto);
  248. settingService.edit(entity);
  249. return ResponseHelp.success(true);
  250. }
  251. @RequestMapping(value = "/tips", method = RequestMethod.GET)
  252. @ApiOperation(value = "获取结构说明", httpMethod = "GET")
  253. private Response<JSONObject> getTips(){
  254. Setting entity = settingService.getByKey(SettingKey.TIPS);
  255. return ResponseHelp.success(entity.getValue());
  256. }
  257. @RequestMapping(value = "/comment/add", method = RequestMethod.POST)
  258. @ApiOperation(value = "添加评价", httpMethod = "POST")
  259. private Response<Boolean> addComment(@RequestBody @Validated CommentDto dto){
  260. Comment entity = Transform.dtoToEntity(dto);
  261. commentService.add(entity);
  262. return ResponseHelp.success(true);
  263. }
  264. @RequestMapping(value = "/comment/edit", method = RequestMethod.PUT)
  265. @ApiOperation(value = "修改评价", httpMethod = "PUT")
  266. private Response<Boolean> editComment(@RequestBody @Validated CommentDto dto){
  267. Comment entity = Transform.dtoToEntity(dto);
  268. commentService.edit(entity);
  269. return ResponseHelp.success(true);
  270. }
  271. @RequestMapping(value = "/comment/delete", method = RequestMethod.DELETE)
  272. @ApiOperation(value = "删除评价", httpMethod = "DELETE")
  273. private Response<Boolean> deleteComment(@RequestParam int id){
  274. commentService.delete(id);
  275. return ResponseHelp.success(true);
  276. }
  277. @RequestMapping(value = "/comment/list", method = RequestMethod.GET)
  278. @ApiOperation(value = "获取评价列表", httpMethod = "GET")
  279. private Response<PageMessage<Comment>> listComment(
  280. @RequestParam(required = false, defaultValue = "1") int page,
  281. @RequestParam(required = false, defaultValue = "100") int size,
  282. @RequestParam(required = false) String channel,
  283. @RequestParam(required = false) String position,
  284. @RequestParam(required = false) Integer userId,
  285. @RequestParam(required = false) Boolean isSpecial
  286. ){
  287. Page<Comment> p = commentService.listAdmin(page, size, ChannelModule.ValueOf(channel), position, userId, isSpecial);
  288. return ResponseHelp.success(p, page, size, p.getTotal());
  289. }
  290. @RequestMapping(value = "/faq/add", method = RequestMethod.POST)
  291. @ApiOperation(value = "添加faq", httpMethod = "POST")
  292. private Response<Boolean> addFaq(@RequestBody @Validated FaqDto dto){
  293. Faq entity = Transform.dtoToEntity(dto);
  294. faqService.add(entity);
  295. return ResponseHelp.success(true);
  296. }
  297. @RequestMapping(value = "/faq/edit", method = RequestMethod.PUT)
  298. @ApiOperation(value = "修改faq", httpMethod = "PUT")
  299. private Response<Boolean> editFaq(@RequestBody @Validated FaqDto dto){
  300. Faq entity = Transform.dtoToEntity(dto);
  301. faqService.edit(entity);
  302. return ResponseHelp.success(true);
  303. }
  304. @RequestMapping(value = "/faq/delete", method = RequestMethod.DELETE)
  305. @ApiOperation(value = "删除评价", httpMethod = "DELETE")
  306. private Response<Boolean> deleteFaq(@RequestParam int id){
  307. faqService.delete(id);
  308. return ResponseHelp.success(true);
  309. }
  310. @RequestMapping(value = "/faq/list", method = RequestMethod.GET)
  311. @ApiOperation(value = "获取faq列表", httpMethod = "GET")
  312. private Response<PageMessage<Faq>> listFaq(
  313. @RequestParam(required = false, defaultValue = "1") int page,
  314. @RequestParam(required = false, defaultValue = "100") int size,
  315. @RequestParam(required = false) String channel,
  316. @RequestParam(required = false) String position,
  317. @RequestParam(required = false) Integer status,
  318. @RequestParam(required = false) Boolean isSpecial
  319. ){
  320. Page<Faq> p = faqService.listAdmin(page, size, ChannelModule.ValueOf(channel), position, status, isSpecial);
  321. return ResponseHelp.success(p, page, size, p.getTotal());
  322. }
  323. @RequestMapping(value = "/message/add", method = RequestMethod.POST)
  324. @ApiOperation(value = "添加消息", httpMethod = "POST")
  325. private Response<Boolean> addMessage(@RequestBody @Validated FaqDto dto){
  326. Faq entity = Transform.dtoToEntity(dto);
  327. faqService.add(entity);
  328. return ResponseHelp.success(true);
  329. }
  330. @RequestMapping(value = "/message/edit", method = RequestMethod.PUT)
  331. @ApiOperation(value = "修改消息", httpMethod = "PUT")
  332. private Response<Boolean> editMessage(@RequestBody @Validated FaqDto dto){
  333. Faq entity = Transform.dtoToEntity(dto);
  334. faqService.edit(entity);
  335. return ResponseHelp.success(true);
  336. }
  337. @RequestMapping(value = "/message/delete", method = RequestMethod.DELETE)
  338. @ApiOperation(value = "删除消息", httpMethod = "DELETE")
  339. private Response<Boolean> deleteMessage(@RequestParam int id){
  340. faqService.delete(id);
  341. return ResponseHelp.success(true);
  342. }
  343. @RequestMapping(value = "/message/list", method = RequestMethod.GET)
  344. @ApiOperation(value = "获取消息列表", httpMethod = "GET")
  345. private Response<PageMessage<Message>> listMessage(
  346. @RequestParam(required = false, defaultValue = "1") int page,
  347. @RequestParam(required = false, defaultValue = "100") int size
  348. ){
  349. Page<Message> p = messageService.select(page, size);
  350. return ResponseHelp.success(p, page, size, p.getTotal());
  351. }
  352. @RequestMapping(value = "/rank/add", method = RequestMethod.POST)
  353. @ApiOperation(value = "添加排行", httpMethod = "POST")
  354. private Response<Boolean> addRank(@RequestBody @Validated RankDto dto){
  355. Rank entity = Transform.dtoToEntity(dto);
  356. rankService.add(entity);
  357. return ResponseHelp.success(true);
  358. }
  359. @RequestMapping(value = "/rank/edit", method = RequestMethod.PUT)
  360. @ApiOperation(value = "修改排行", httpMethod = "PUT")
  361. private Response<Boolean> editRank(@RequestBody @Validated RankDto dto){
  362. Rank entity = Transform.dtoToEntity(dto);
  363. rankService.edit(entity);
  364. return ResponseHelp.success(true);
  365. }
  366. @RequestMapping(value = "/rank/delete", method = RequestMethod.DELETE)
  367. @ApiOperation(value = "删除排行", httpMethod = "DELETE")
  368. private Response<Boolean> deleteRank(@RequestParam int id){
  369. rankService.delete(id);
  370. return ResponseHelp.success(true);
  371. }
  372. @RequestMapping(value = "/rank/list", method = RequestMethod.GET)
  373. @ApiOperation(value = "获取排行设置", httpMethod = "GET")
  374. private Response<List<Rank>> getRank(){
  375. List<Rank> rankList = rankService.all();
  376. return ResponseHelp.success(rankList);
  377. }
  378. @RequestMapping(value = "/rank/import", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, method = RequestMethod.POST)
  379. @ApiOperation(value = "导入排行数据", httpMethod = "POST")
  380. private Response<Boolean> importRank(@RequestParam("file") MultipartFile multipartFile) throws IOException {
  381. // 删除所有排行数据, 并导入excel数据
  382. // 读取文件
  383. InputStream is = new FileInputStream("002.xls");
  384. // 将文件流解析成 POI 文档
  385. POIFSFileSystem fs = new POIFSFileSystem(is);
  386. // 再将 POI 文档解析成 Excel 工作簿
  387. HSSFWorkbook wb = new HSSFWorkbook(fs);
  388. HSSFRow row = null;
  389. HSSFCell cell = null;
  390. // 得到第 1 个工作簿
  391. HSSFSheet sheet = wb.getSheetAt(0);
  392. // 得到这一行一共有多少列
  393. int totalColumns = sheet.getRow(0).getPhysicalNumberOfCells();
  394. // 得到最后一行的坐标
  395. Integer lastRowNum = sheet.getLastRowNum();
  396. System.out.println("lastRowNum => " + lastRowNum);
  397. List<Rank> rankList = new ArrayList<>();
  398. Rank rank = null;
  399. String cellValue = null;
  400. // 从第 2 行开始读
  401. for(int i=1;i<=lastRowNum;i++){
  402. row = sheet.getRow(i);
  403. rank = new Rank();
  404. for(int j=0;j<totalColumns;j++){
  405. cell = row.getCell(j);
  406. if(cell!=null){
  407. cellValue = cell.getStringCellValue();
  408. }else {
  409. cellValue = "【没有数据】";
  410. }
  411. }
  412. rankList.add(rank);
  413. }
  414. rankService.replaceAll(rankList);
  415. return ResponseHelp.success(true);
  416. }
  417. }