SettingController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. package com.qxgmat.controller.admin;
  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.Rank;
  8. import com.qxgmat.data.dao.entity.Setting;
  9. import com.qxgmat.dto.admin.request.RankDto;
  10. import com.qxgmat.service.inline.RankService;
  11. import com.qxgmat.service.inline.SettingService;
  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.FileNotFoundException;
  28. import java.io.IOException;
  29. import java.io.InputStream;
  30. import java.util.ArrayList;
  31. import java.util.List;
  32. @RestController("AdminSettingController")
  33. @RequestMapping("/admin/setting")
  34. @Api(tags = "配置信息接口", description = "全局独立配置设置", produces = MediaType.APPLICATION_JSON_VALUE)
  35. public class SettingController {
  36. private static final Logger logger = LoggerFactory.getLogger(SettingController.class);
  37. @Autowired
  38. private SettingService settingService;
  39. @Autowired
  40. private RankService rankService;
  41. @RequestMapping(value = "/index", method = RequestMethod.PUT)
  42. @ApiOperation(value = "修改首页配置", httpMethod = "PUT")
  43. private Response<Boolean> editIndex(@RequestBody @Validated JSONObject dto){
  44. Setting entity = settingService.getByKey(SettingKey.INDEX);
  45. entity.setValue(dto);
  46. settingService.edit(entity);
  47. return ResponseHelp.success(true);
  48. }
  49. @RequestMapping(value = "/index", method = RequestMethod.GET)
  50. @ApiOperation(value = "获取首页配置", httpMethod = "GET")
  51. private Response<JSONObject> getIndex(){
  52. Setting entity = settingService.getByKey(SettingKey.INDEX);
  53. logger.debug("{}", entity);
  54. return ResponseHelp.success(entity.getValue());
  55. }
  56. @RequestMapping(value = "/place", method = RequestMethod.PUT)
  57. @ApiOperation(value = "修改考点设置", httpMethod = "PUT")
  58. private Response<Boolean> editPlace(@RequestBody @Validated JSONObject dto){
  59. Setting entity = settingService.getByKey(SettingKey.PLACE);
  60. entity.setValue(dto);
  61. settingService.edit(entity);
  62. return ResponseHelp.success(true);
  63. }
  64. @RequestMapping(value = "/place", method = RequestMethod.GET)
  65. @ApiOperation(value = "获取考点配置", httpMethod = "GET")
  66. private Response<JSONObject> getPlace(){
  67. Setting entity = settingService.getByKey(SettingKey.PLACE);
  68. return ResponseHelp.success(entity.getValue());
  69. }
  70. @RequestMapping(value = "/sentence", method = RequestMethod.PUT)
  71. @ApiOperation(value = "修改长难句设置", httpMethod = "PUT")
  72. private Response<Boolean> editSentence(@RequestBody @Validated JSONObject dto){
  73. Setting entity = settingService.getByKey(SettingKey.SENTENCE);
  74. entity.setValue(dto);
  75. settingService.edit(entity);
  76. return ResponseHelp.success(true);
  77. }
  78. @RequestMapping(value = "/sentence", method = RequestMethod.GET)
  79. @ApiOperation(value = "获取长难句配置", httpMethod = "GET")
  80. private Response<JSONObject> getSentence(){
  81. Setting entity = settingService.getByKey(SettingKey.SENTENCE);
  82. return ResponseHelp.success(entity.getValue());
  83. }
  84. @RequestMapping(value = "/exercise_time", method = RequestMethod.PUT)
  85. @ApiOperation(value = "修改做题时间设置", httpMethod = "PUT")
  86. private Response<Boolean> editExerciseTime(@RequestBody @Validated JSONObject dto){
  87. Setting entity = settingService.getByKey(SettingKey.EXERCISE_TIME);
  88. entity.setValue(dto);
  89. settingService.edit(entity);
  90. return ResponseHelp.success(true);
  91. }
  92. @RequestMapping(value = "/exercise_time", method = RequestMethod.GET)
  93. @ApiOperation(value = "获取做题时间配置", httpMethod = "GET")
  94. private Response<JSONObject> getExerciseTime(){
  95. Setting entity = settingService.getByKey(SettingKey.EXERCISE_TIME);
  96. return ResponseHelp.success(entity.getValue());
  97. }
  98. @RequestMapping(value = "/examination_time", method = RequestMethod.PUT)
  99. @ApiOperation(value = "修改做题时间设置", httpMethod = "PUT")
  100. private Response<Boolean> editExaminationTime(@RequestBody @Validated JSONObject dto){
  101. Setting entity = settingService.getByKey(SettingKey.EXAMINATION_TIME);
  102. entity.setValue(dto);
  103. settingService.edit(entity);
  104. return ResponseHelp.success(true);
  105. }
  106. @RequestMapping(value = "/examination_time", method = RequestMethod.GET)
  107. @ApiOperation(value = "获取做题时间配置", httpMethod = "GET")
  108. private Response<JSONObject> getExaminationTime(){
  109. Setting entity = settingService.getByKey(SettingKey.EXAMINATION_TIME);
  110. return ResponseHelp.success(entity.getValue());
  111. }
  112. @RequestMapping(value = "/filter_time", method = RequestMethod.PUT)
  113. @ApiOperation(value = "修改剔除时间设置", httpMethod = "PUT")
  114. private Response<Boolean> editFilterTime(@RequestBody @Validated JSONObject dto){
  115. Setting entity = settingService.getByKey(SettingKey.FILTER_TIME);
  116. entity.setValue(dto);
  117. settingService.edit(entity);
  118. return ResponseHelp.success(true);
  119. }
  120. @RequestMapping(value = "/filter_time", method = RequestMethod.GET)
  121. @ApiOperation(value = "获取剔除时间配置", httpMethod = "GET")
  122. private Response<JSONObject> getFilterTime(){
  123. Setting entity = settingService.getByKey(SettingKey.FILTER_TIME);
  124. return ResponseHelp.success(entity.getValue());
  125. }
  126. @RequestMapping(value = "/sentence_time", method = RequestMethod.PUT)
  127. @ApiOperation(value = "修改长难句时间设置", httpMethod = "PUT")
  128. private Response<Boolean> editSentenceTime(@RequestBody @Validated JSONObject dto){
  129. Setting entity = settingService.getByKey(SettingKey.SENTENCE_TIME);
  130. entity.setValue(dto);
  131. settingService.edit(entity);
  132. return ResponseHelp.success(true);
  133. }
  134. @RequestMapping(value = "/sentence_time", method = RequestMethod.GET)
  135. @ApiOperation(value = "获取长难句时间配置", httpMethod = "GET")
  136. private Response<JSONObject> getSentenceTime(){
  137. Setting entity = settingService.getByKey(SettingKey.SENTENCE_TIME);
  138. return ResponseHelp.success(entity.getValue());
  139. }
  140. @RequestMapping(value = "/textbook_time", method = RequestMethod.PUT)
  141. @ApiOperation(value = "修改机经时间设置", httpMethod = "PUT")
  142. private Response<Boolean> editTextbookTime(@RequestBody @Validated JSONObject dto){
  143. Setting entity = settingService.getByKey(SettingKey.TEXTBOOK_TIME);
  144. entity.setValue(dto);
  145. settingService.edit(entity);
  146. return ResponseHelp.success(true);
  147. }
  148. @RequestMapping(value = "/textbook_time", method = RequestMethod.GET)
  149. @ApiOperation(value = "获取机经时间配置", httpMethod = "GET")
  150. private Response<JSONObject> getTextbookTime(){
  151. Setting entity = settingService.getByKey(SettingKey.TEXTBOOK_TIME);
  152. return ResponseHelp.success(entity.getValue());
  153. }
  154. @RequestMapping(value = "/score_switch", method = RequestMethod.PUT)
  155. @ApiOperation(value = "修改分数开关", httpMethod = "PUT")
  156. private Response<Boolean> editScoreSwitch(@RequestBody @Validated JSONObject dto){
  157. Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH);
  158. entity.setValue(dto);
  159. settingService.edit(entity);
  160. return ResponseHelp.success(true);
  161. }
  162. @RequestMapping(value = "/score_switch", method = RequestMethod.GET)
  163. @ApiOperation(value = "获取分数开关", httpMethod = "GET")
  164. private Response<JSONObject> getScoreSwitch(){
  165. Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH);
  166. return ResponseHelp.success(entity.getValue());
  167. }
  168. @RequestMapping(value = "/service_vip", method = RequestMethod.PUT)
  169. @ApiOperation(value = "修改Vip服务", httpMethod = "PUT")
  170. private Response<Boolean> editServiceVip(@RequestBody @Validated JSONObject dto){
  171. Setting entity = settingService.getByKey(SettingKey.SERVICE_VIP);
  172. entity.setValue(dto);
  173. settingService.edit(entity);
  174. return ResponseHelp.success(true);
  175. }
  176. @RequestMapping(value = "/service_vip", method = RequestMethod.GET)
  177. @ApiOperation(value = "获取Vip服务", httpMethod = "GET")
  178. private Response<JSONObject> getServiceVip(){
  179. Setting entity = settingService.getByKey(SettingKey.SERVICE_VIP);
  180. return ResponseHelp.success(entity.getValue());
  181. }
  182. @RequestMapping(value = "/service_textbook", method = RequestMethod.PUT)
  183. @ApiOperation(value = "修改千行CAT服务", httpMethod = "PUT")
  184. private Response<Boolean> editServiceTextbook(@RequestBody @Validated JSONObject dto){
  185. Setting entity = settingService.getByKey(SettingKey.SERVICE_TEXTBOOK);
  186. entity.setValue(dto);
  187. settingService.edit(entity);
  188. return ResponseHelp.success(true);
  189. }
  190. @RequestMapping(value = "/service_textbook", method = RequestMethod.GET)
  191. @ApiOperation(value = "获取千行CAT服务", httpMethod = "GET")
  192. private Response<JSONObject> getServiceTextbook(){
  193. Setting entity = settingService.getByKey(SettingKey.SERVICE_TEXTBOOK);
  194. return ResponseHelp.success(entity.getValue());
  195. }
  196. @RequestMapping(value = "/service_qx_cat", method = RequestMethod.PUT)
  197. @ApiOperation(value = "修改千行CAT服务", httpMethod = "PUT")
  198. private Response<Boolean> editServiceQXCat(@RequestBody @Validated JSONObject dto){
  199. Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH);
  200. entity.setValue(dto);
  201. settingService.edit(entity);
  202. return ResponseHelp.success(true);
  203. }
  204. @RequestMapping(value = "/service_qx_cat", method = RequestMethod.GET)
  205. @ApiOperation(value = "获取千行CAT服务", httpMethod = "GET")
  206. private Response<JSONObject> getServiceQXCat(){
  207. Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH);
  208. return ResponseHelp.success(entity.getValue());
  209. }
  210. @RequestMapping(value = "/tips", method = RequestMethod.PUT)
  211. @ApiOperation(value = "修改结构说明", httpMethod = "PUT")
  212. private Response<Boolean> editTips(@RequestBody @Validated JSONObject dto){
  213. Setting entity = settingService.getByKey(SettingKey.TIPS);
  214. entity.setValue(dto);
  215. settingService.edit(entity);
  216. return ResponseHelp.success(true);
  217. }
  218. @RequestMapping(value = "/tips", method = RequestMethod.GET)
  219. @ApiOperation(value = "获取结构说明", httpMethod = "GET")
  220. private Response<JSONObject> getTips(){
  221. Setting entity = settingService.getByKey(SettingKey.TIPS);
  222. return ResponseHelp.success(entity.getValue());
  223. }
  224. @RequestMapping(value = "/rank/add", method = RequestMethod.POST)
  225. @ApiOperation(value = "添加排行", httpMethod = "POST")
  226. private Response<Boolean> addRank(@RequestBody @Validated RankDto dto){
  227. Rank entity = Transform.dtoToEntity(dto);
  228. rankService.add(entity);
  229. return ResponseHelp.success(true);
  230. }
  231. @RequestMapping(value = "/rank/edit", method = RequestMethod.PUT)
  232. @ApiOperation(value = "修改排行", httpMethod = "PUT")
  233. private Response<Boolean> editRank(@RequestBody @Validated RankDto dto){
  234. Rank entity = Transform.dtoToEntity(dto);
  235. rankService.edit(entity);
  236. return ResponseHelp.success(true);
  237. }
  238. @RequestMapping(value = "/rank/delete", method = RequestMethod.DELETE)
  239. @ApiOperation(value = "删除排行", httpMethod = "DELETE")
  240. private Response<Boolean> deleteRank(@RequestParam int id){
  241. rankService.delete(id);
  242. return ResponseHelp.success(true);
  243. }
  244. @RequestMapping(value = "/rank/list", method = RequestMethod.GET)
  245. @ApiOperation(value = "获取排行设置", httpMethod = "GET")
  246. private Response<List<Rank>> getRank(){
  247. List<Rank> rankList = rankService.all();
  248. return ResponseHelp.success(rankList);
  249. }
  250. @RequestMapping(value = "/rank/import", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, method = RequestMethod.POST)
  251. @ApiOperation(value = "导入排行数据", httpMethod = "POST")
  252. private Response<Boolean> importRank(@RequestParam("file") MultipartFile multipartFile) throws IOException {
  253. // 删除所有排行数据, 并导入excel数据
  254. // 读取文件
  255. InputStream is = new FileInputStream("002.xls");
  256. // 将文件流解析成 POI 文档
  257. POIFSFileSystem fs = new POIFSFileSystem(is);
  258. // 再将 POI 文档解析成 Excel 工作簿
  259. HSSFWorkbook wb = new HSSFWorkbook(fs);
  260. HSSFRow row = null;
  261. HSSFCell cell = null;
  262. // 得到第 1 个工作簿
  263. HSSFSheet sheet = wb.getSheetAt(0);
  264. // 得到这一行一共有多少列
  265. int totalColumns = sheet.getRow(0).getPhysicalNumberOfCells();
  266. // 得到最后一行的坐标
  267. Integer lastRowNum = sheet.getLastRowNum();
  268. System.out.println("lastRowNum => " + lastRowNum);
  269. List<Rank> rankList = new ArrayList<>();
  270. Rank rank = null;
  271. String cellValue = null;
  272. // 从第 2 行开始读
  273. for(int i=1;i<=lastRowNum;i++){
  274. row = sheet.getRow(i);
  275. rank = new Rank();
  276. for(int j=0;j<totalColumns;j++){
  277. cell = row.getCell(j);
  278. if(cell!=null){
  279. cellValue = cell.getStringCellValue();
  280. }else {
  281. cellValue = "【没有数据】";
  282. }
  283. }
  284. rankList.add(rank);
  285. }
  286. rankService.replaceAll(rankList);
  287. return ResponseHelp.success(true);
  288. }
  289. }