SettingController.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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.nuliji.tools.exception.ParameterException;
  6. import com.qxgmat.data.constants.enums.MessageCategory;
  7. import com.qxgmat.data.constants.enums.MessageMethod;
  8. import com.qxgmat.data.constants.enums.MessageType;
  9. import com.qxgmat.data.constants.enums.SettingKey;
  10. import com.qxgmat.data.constants.enums.status.AskStatus;
  11. import com.qxgmat.data.constants.enums.status.DirectionStatus;
  12. import com.qxgmat.data.constants.enums.user.MoneyRange;
  13. import com.qxgmat.data.dao.entity.*;
  14. import com.qxgmat.dto.admin.extend.InfoExtendDto;
  15. import com.qxgmat.dto.admin.extend.UserExtendDto;
  16. import com.qxgmat.dto.admin.request.*;
  17. import com.qxgmat.dto.admin.response.CommentInfoDto;
  18. import com.qxgmat.dto.admin.response.FaqInfoDto;
  19. import com.qxgmat.help.ShiroHelp;
  20. import com.qxgmat.service.UsersService;
  21. import com.qxgmat.service.extend.MessageExtendService;
  22. import com.qxgmat.service.inline.*;
  23. import io.swagger.annotations.Api;
  24. import io.swagger.annotations.ApiOperation;
  25. import org.apache.poi.hssf.usermodel.HSSFCell;
  26. import org.apache.poi.hssf.usermodel.HSSFRow;
  27. import org.apache.poi.hssf.usermodel.HSSFSheet;
  28. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  29. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  30. import org.slf4j.Logger;
  31. import org.slf4j.LoggerFactory;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.http.MediaType;
  34. import org.springframework.validation.annotation.Validated;
  35. import org.springframework.web.bind.annotation.*;
  36. import org.springframework.web.multipart.MultipartFile;
  37. import javax.servlet.http.HttpServletRequest;
  38. import javax.servlet.http.HttpSession;
  39. import java.io.FileInputStream;
  40. import java.io.IOException;
  41. import java.io.InputStream;
  42. import java.util.ArrayList;
  43. import java.util.Collection;
  44. import java.util.Date;
  45. import java.util.List;
  46. import java.util.stream.Collectors;
  47. @RestController("AdminSettingController")
  48. @RequestMapping("/admin/setting")
  49. @Api(tags = "配置信息接口", description = "全局独立配置设置", produces = MediaType.APPLICATION_JSON_VALUE)
  50. public class SettingController {
  51. private static final Logger logger = LoggerFactory.getLogger(SettingController.class);
  52. @Autowired
  53. private ShiroHelp shiroHelp;
  54. @Autowired
  55. private ManagerLogService managerLogService;
  56. @Autowired
  57. private AdService adService;
  58. @Autowired
  59. private SettingService settingService;
  60. @Autowired
  61. private RankService rankService;
  62. @Autowired
  63. private ContractService contractService;
  64. @Autowired
  65. private CommentService commentService;
  66. @Autowired
  67. private FaqService faqService;
  68. @Autowired
  69. private MessageTemplateService messageTemplateService;
  70. @Autowired
  71. private MessageExtendService messageExtendService;
  72. @Autowired
  73. private UsersService usersService;
  74. @Autowired
  75. private CourseService courseService;
  76. @Autowired
  77. private CourseDataService courseDataService;
  78. @RequestMapping(value = "/index", method = RequestMethod.PUT)
  79. @ApiOperation(value = "修改首页配置", httpMethod = "PUT")
  80. private Response<Boolean> editIndex(@RequestBody @Validated JSONObject dto){
  81. Setting entity = settingService.getByKey(SettingKey.INDEX);
  82. entity.setValue(dto);
  83. settingService.edit(entity);
  84. return ResponseHelp.success(true);
  85. }
  86. @RequestMapping(value = "/index", method = RequestMethod.GET)
  87. @ApiOperation(value = "获取首页配置", httpMethod = "GET")
  88. private Response<JSONObject> getIndex(){
  89. Setting entity = settingService.getByKey(SettingKey.INDEX);
  90. logger.debug("{}", entity);
  91. return ResponseHelp.success(entity.getValue());
  92. }
  93. @RequestMapping(value = "/place", method = RequestMethod.PUT)
  94. @ApiOperation(value = "修改考点设置", httpMethod = "PUT")
  95. private Response<Boolean> editPlace(@RequestBody @Validated JSONObject dto){
  96. Setting entity = settingService.getByKey(SettingKey.PLACE);
  97. entity.setValue(dto);
  98. settingService.edit(entity);
  99. return ResponseHelp.success(true);
  100. }
  101. @RequestMapping(value = "/place", method = RequestMethod.GET)
  102. @ApiOperation(value = "获取考点配置", httpMethod = "GET")
  103. private Response<JSONObject> getPlace(){
  104. Setting entity = settingService.getByKey(SettingKey.PLACE);
  105. return ResponseHelp.success(entity.getValue());
  106. }
  107. @RequestMapping(value = "/sentence", method = RequestMethod.PUT)
  108. @ApiOperation(value = "修改长难句设置", httpMethod = "PUT")
  109. private Response<Boolean> editSentence(@RequestBody @Validated JSONObject dto){
  110. Setting entity = settingService.getByKey(SettingKey.SENTENCE);
  111. entity.setValue(dto);
  112. settingService.edit(entity);
  113. return ResponseHelp.success(true);
  114. }
  115. @RequestMapping(value = "/sentence", method = RequestMethod.GET)
  116. @ApiOperation(value = "获取长难句配置", httpMethod = "GET")
  117. private Response<JSONObject> getSentence(){
  118. Setting entity = settingService.getByKey(SettingKey.SENTENCE);
  119. return ResponseHelp.success(entity.getValue());
  120. }
  121. @RequestMapping(value = "/exercise_time", method = RequestMethod.PUT)
  122. @ApiOperation(value = "修改做题时间设置", httpMethod = "PUT")
  123. private Response<Boolean> editExerciseTime(@RequestBody @Validated JSONObject dto){
  124. Setting entity = settingService.getByKey(SettingKey.EXERCISE_TIME);
  125. entity.setValue(dto);
  126. settingService.edit(entity);
  127. return ResponseHelp.success(true);
  128. }
  129. @RequestMapping(value = "/exercise_time", method = RequestMethod.GET)
  130. @ApiOperation(value = "获取做题时间配置", httpMethod = "GET")
  131. private Response<JSONObject> getExerciseTime(){
  132. Setting entity = settingService.getByKey(SettingKey.EXERCISE_TIME);
  133. return ResponseHelp.success(entity.getValue());
  134. }
  135. @RequestMapping(value = "/examination_time", method = RequestMethod.PUT)
  136. @ApiOperation(value = "修改做题时间设置", httpMethod = "PUT")
  137. private Response<Boolean> editExaminationTime(@RequestBody @Validated JSONObject dto){
  138. Setting entity = settingService.getByKey(SettingKey.EXAMINATION_TIME);
  139. entity.setValue(dto);
  140. settingService.edit(entity);
  141. return ResponseHelp.success(true);
  142. }
  143. @RequestMapping(value = "/examination_time", method = RequestMethod.GET)
  144. @ApiOperation(value = "获取做题时间配置", httpMethod = "GET")
  145. private Response<JSONObject> getExaminationTime(){
  146. Setting entity = settingService.getByKey(SettingKey.EXAMINATION_TIME);
  147. return ResponseHelp.success(entity.getValue());
  148. }
  149. @RequestMapping(value = "/filter_time", method = RequestMethod.PUT)
  150. @ApiOperation(value = "修改剔除时间设置", httpMethod = "PUT")
  151. private Response<Boolean> editFilterTime(@RequestBody @Validated JSONObject dto){
  152. Setting entity = settingService.getByKey(SettingKey.FILTER_TIME);
  153. entity.setValue(dto);
  154. settingService.edit(entity);
  155. return ResponseHelp.success(true);
  156. }
  157. @RequestMapping(value = "/filter_time", method = RequestMethod.GET)
  158. @ApiOperation(value = "获取剔除时间配置", httpMethod = "GET")
  159. private Response<JSONObject> getFilterTime(){
  160. Setting entity = settingService.getByKey(SettingKey.FILTER_TIME);
  161. return ResponseHelp.success(entity.getValue());
  162. }
  163. @RequestMapping(value = "/exercise_paper_auto", method = RequestMethod.PUT)
  164. @ApiOperation(value = "修改自动组卷时间设置", httpMethod = "PUT")
  165. private Response<Boolean> editExercisePaperAuto(@RequestBody @Validated JSONObject dto){
  166. Setting entity = settingService.getByKey(SettingKey.EXERCISE_PAPER_AUTO);
  167. entity.setValue(dto);
  168. settingService.edit(entity);
  169. return ResponseHelp.success(true);
  170. }
  171. @RequestMapping(value = "/exercise_paper_auto", method = RequestMethod.GET)
  172. @ApiOperation(value = "获取自动组卷时间配置", httpMethod = "GET")
  173. private Response<JSONObject> getExercisePaperAuto(){
  174. Setting entity = settingService.getByKey(SettingKey.EXERCISE_PAPER_AUTO);
  175. return ResponseHelp.success(entity.getValue());
  176. }
  177. @RequestMapping(value = "/sentence_time", method = RequestMethod.PUT)
  178. @ApiOperation(value = "修改长难句时间设置", httpMethod = "PUT")
  179. private Response<Boolean> editSentenceTime(@RequestBody @Validated JSONObject dto){
  180. Setting entity = settingService.getByKey(SettingKey.SENTENCE_TIME);
  181. entity.setValue(dto);
  182. settingService.edit(entity);
  183. return ResponseHelp.success(true);
  184. }
  185. @RequestMapping(value = "/sentence_time", method = RequestMethod.GET)
  186. @ApiOperation(value = "获取长难句时间配置", httpMethod = "GET")
  187. private Response<JSONObject> getSentenceTime(){
  188. Setting entity = settingService.getByKey(SettingKey.SENTENCE_TIME);
  189. return ResponseHelp.success(entity.getValue());
  190. }
  191. @RequestMapping(value = "/textbook_time", method = RequestMethod.PUT)
  192. @ApiOperation(value = "修改机经时间设置", httpMethod = "PUT")
  193. private Response<Boolean> editTextbookTime(@RequestBody @Validated JSONObject dto){
  194. Setting entity = settingService.getByKey(SettingKey.TEXTBOOK_TIME);
  195. entity.setValue(dto);
  196. settingService.edit(entity);
  197. return ResponseHelp.success(true);
  198. }
  199. @RequestMapping(value = "/textbook_time", method = RequestMethod.GET)
  200. @ApiOperation(value = "获取机经时间配置", httpMethod = "GET")
  201. private Response<JSONObject> getTextbookTime(){
  202. Setting entity = settingService.getByKey(SettingKey.TEXTBOOK_TIME);
  203. return ResponseHelp.success(entity.getValue());
  204. }
  205. @RequestMapping(value = "/score_switch", method = RequestMethod.PUT)
  206. @ApiOperation(value = "修改分数开关", httpMethod = "PUT")
  207. private Response<Boolean> editScoreSwitch(@RequestBody @Validated JSONObject dto){
  208. Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH);
  209. entity.setValue(dto);
  210. settingService.edit(entity);
  211. return ResponseHelp.success(true);
  212. }
  213. @RequestMapping(value = "/score_switch", method = RequestMethod.GET)
  214. @ApiOperation(value = "获取分数开关", httpMethod = "GET")
  215. private Response<JSONObject> getScoreSwitch(){
  216. Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH);
  217. return ResponseHelp.success(entity.getValue());
  218. }
  219. @RequestMapping(value = "/service_vip", method = RequestMethod.PUT)
  220. @ApiOperation(value = "修改Vip服务", httpMethod = "PUT")
  221. private Response<Boolean> editServiceVip(@RequestBody @Validated JSONObject dto){
  222. Setting entity = settingService.getByKey(SettingKey.SERVICE_VIP);
  223. entity.setValue(dto);
  224. settingService.edit(entity);
  225. return ResponseHelp.success(true);
  226. }
  227. @RequestMapping(value = "/service_vip", method = RequestMethod.GET)
  228. @ApiOperation(value = "获取Vip服务", httpMethod = "GET")
  229. private Response<JSONObject> getServiceVip(){
  230. Setting entity = settingService.getByKey(SettingKey.SERVICE_VIP);
  231. return ResponseHelp.success(entity.getValue());
  232. }
  233. @RequestMapping(value = "/service_textbook", method = RequestMethod.PUT)
  234. @ApiOperation(value = "修改千行CAT服务", httpMethod = "PUT")
  235. private Response<Boolean> editServiceTextbook(@RequestBody @Validated JSONObject dto){
  236. Setting entity = settingService.getByKey(SettingKey.SERVICE_TEXTBOOK);
  237. entity.setValue(dto);
  238. settingService.edit(entity);
  239. return ResponseHelp.success(true);
  240. }
  241. @RequestMapping(value = "/service_textbook", method = RequestMethod.GET)
  242. @ApiOperation(value = "获取千行CAT服务", httpMethod = "GET")
  243. private Response<JSONObject> getServiceTextbook(){
  244. Setting entity = settingService.getByKey(SettingKey.SERVICE_TEXTBOOK);
  245. return ResponseHelp.success(entity.getValue());
  246. }
  247. @RequestMapping(value = "/service_qx_cat", method = RequestMethod.PUT)
  248. @ApiOperation(value = "修改千行CAT服务", httpMethod = "PUT")
  249. private Response<Boolean> editServiceQXCat(@RequestBody @Validated JSONObject dto){
  250. Setting entity = settingService.getByKey(SettingKey.SERVICE_QX_CAT);
  251. entity.setValue(dto);
  252. settingService.edit(entity);
  253. return ResponseHelp.success(true);
  254. }
  255. @RequestMapping(value = "/service_qx_cat", method = RequestMethod.GET)
  256. @ApiOperation(value = "获取千行CAT服务", httpMethod = "GET")
  257. private Response<JSONObject> getServiceQXCat(){
  258. Setting entity = settingService.getByKey(SettingKey.SERVICE_QX_CAT);
  259. return ResponseHelp.success(entity.getValue());
  260. }
  261. @RequestMapping(value = "/course_index", method = RequestMethod.PUT)
  262. @ApiOperation(value = "修改课程首页", httpMethod = "PUT")
  263. private Response<Boolean> editCourseIndex(@RequestBody @Validated JSONObject dto){
  264. Setting entity = settingService.getByKey(SettingKey.COURSE_INDEX);
  265. entity.setValue(dto);
  266. settingService.edit(entity);
  267. return ResponseHelp.success(true);
  268. }
  269. @RequestMapping(value = "/course_index", method = RequestMethod.GET)
  270. @ApiOperation(value = "获取课程首页", httpMethod = "GET")
  271. private Response<JSONObject> getCourseIndex(){
  272. Setting entity = settingService.getByKey(SettingKey.COURSE_INDEX);
  273. return ResponseHelp.success(entity.getValue());
  274. }
  275. @RequestMapping(value = "/promote", method = RequestMethod.PUT)
  276. @ApiOperation(value = "修改促销", httpMethod = "PUT")
  277. private Response<Boolean> editPromote(@RequestBody @Validated JSONObject dto){
  278. Setting entity = settingService.getByKey(SettingKey.PROMOTE);
  279. entity.setValue(dto);
  280. settingService.edit(entity);
  281. return ResponseHelp.success(true);
  282. }
  283. @RequestMapping(value = "/promote", method = RequestMethod.GET)
  284. @ApiOperation(value = "获取课程促销", httpMethod = "GET")
  285. private Response<JSONObject> getPromote(){
  286. Setting entity = settingService.getByKey(SettingKey.PROMOTE);
  287. return ResponseHelp.success(entity.getValue());
  288. }
  289. @RequestMapping(value = "/prepare_info", method = RequestMethod.PUT)
  290. @ApiOperation(value = "修改备考信息", httpMethod = "PUT")
  291. private Response<Boolean> editPrepareInfo(@RequestBody @Validated JSONObject dto){
  292. Setting entity = settingService.getByKey(SettingKey.PREPARE_INFO);
  293. entity.setValue(dto);
  294. settingService.edit(entity);
  295. return ResponseHelp.success(true);
  296. }
  297. @RequestMapping(value = "/prepare_info", method = RequestMethod.GET)
  298. @ApiOperation(value = "获取备考信息", httpMethod = "GET")
  299. private Response<JSONObject> getPrepareInfo(){
  300. Setting entity = settingService.getByKey(SettingKey.PREPARE_INFO);
  301. return ResponseHelp.success(entity.getValue());
  302. }
  303. @RequestMapping(value = "/experience_info", method = RequestMethod.PUT)
  304. @ApiOperation(value = "修改心经信息", httpMethod = "PUT")
  305. private Response<Boolean> editExperienceInfo(@RequestBody @Validated JSONObject dto){
  306. Setting entity = settingService.getByKey(SettingKey.EXPERIENCE_INFO);
  307. entity.setValue(dto);
  308. settingService.edit(entity);
  309. return ResponseHelp.success(true);
  310. }
  311. @RequestMapping(value = "/experience_info", method = RequestMethod.GET)
  312. @ApiOperation(value = "获取心经信息", httpMethod = "GET")
  313. private Response<JSONObject> getExperienceInfo(){
  314. Setting entity = settingService.getByKey(SettingKey.EXPERIENCE_INFO);
  315. return ResponseHelp.success(entity.getValue());
  316. }
  317. @RequestMapping(value = "/sentence_info", method = RequestMethod.PUT)
  318. @ApiOperation(value = "修改长难句信息", httpMethod = "PUT")
  319. private Response<Boolean> editSentenceInfo(@RequestBody @Validated JSONObject dto){
  320. Setting entity = settingService.getByKey(SettingKey.SENTENCE_INFO);
  321. entity.setValue(dto);
  322. settingService.edit(entity);
  323. return ResponseHelp.success(true);
  324. }
  325. @RequestMapping(value = "/sentence_info", method = RequestMethod.GET)
  326. @ApiOperation(value = "获取长难句信息", httpMethod = "GET")
  327. private Response<JSONObject> getSentenceInfo(){
  328. Setting entity = settingService.getByKey(SettingKey.SENTENCE_INFO);
  329. return ResponseHelp.success(entity.getValue());
  330. }
  331. @RequestMapping(value = "/wechat_info", method = RequestMethod.PUT)
  332. @ApiOperation(value = "修改长难句信息", httpMethod = "PUT")
  333. private Response<Boolean> editWechatInfo(@RequestBody @Validated JSONObject dto){
  334. Setting entity = settingService.getByKey(SettingKey.WECHAT_INFO);
  335. entity.setValue(dto);
  336. settingService.edit(entity);
  337. return ResponseHelp.success(true);
  338. }
  339. @RequestMapping(value = "/wechat_info", method = RequestMethod.GET)
  340. @ApiOperation(value = "获取长难句信息", httpMethod = "GET")
  341. private Response<JSONObject> getWechatInfo(){
  342. Setting entity = settingService.getByKey(SettingKey.WECHAT_INFO);
  343. return ResponseHelp.success(entity.getValue());
  344. }
  345. @RequestMapping(value = "/tips", method = RequestMethod.PUT)
  346. @ApiOperation(value = "修改结构说明", httpMethod = "PUT")
  347. private Response<Boolean> editTips(@RequestBody @Validated JSONObject dto){
  348. Setting entity = settingService.getByKey(SettingKey.TIPS);
  349. entity.setValue(dto);
  350. settingService.edit(entity);
  351. return ResponseHelp.success(true);
  352. }
  353. @RequestMapping(value = "/tips", method = RequestMethod.GET)
  354. @ApiOperation(value = "获取结构说明", httpMethod = "GET")
  355. private Response<JSONObject> getTips(){
  356. Setting entity = settingService.getByKey(SettingKey.TIPS);
  357. return ResponseHelp.success(entity.getValue());
  358. }
  359. @RequestMapping(value = "/ready_read", method = RequestMethod.PUT)
  360. @ApiOperation(value = "修改推荐阅读设置", httpMethod = "PUT")
  361. private Response<Boolean> editReadyRead(@RequestBody @Validated JSONObject dto){
  362. Setting entity = settingService.getByKey(SettingKey.READY_READ);
  363. entity.setValue(dto);
  364. settingService.edit(entity);
  365. return ResponseHelp.success(true);
  366. }
  367. @RequestMapping(value = "/ready_read", method = RequestMethod.GET)
  368. @ApiOperation(value = "获取推荐阅读配置", httpMethod = "GET")
  369. private Response<JSONObject> getReadyRead(){
  370. Setting entity = settingService.getByKey(SettingKey.READY_READ);
  371. return ResponseHelp.success(entity.getValue());
  372. }
  373. @RequestMapping(value = "/comment/add", method = RequestMethod.POST)
  374. @ApiOperation(value = "添加评价", httpMethod = "POST")
  375. private Response<Boolean> addComment(@RequestBody @Validated CommentDto dto){
  376. Comment entity = Transform.dtoToEntity(dto);
  377. entity.setIsSystem(1);
  378. commentService.add(entity);
  379. return ResponseHelp.success(true);
  380. }
  381. @RequestMapping(value = "/comment/edit", method = RequestMethod.PUT)
  382. @ApiOperation(value = "修改评价", httpMethod = "PUT")
  383. private Response<Boolean> editComment(@RequestBody @Validated CommentDto dto){
  384. Comment entity = Transform.dtoToEntity(dto);
  385. commentService.edit(entity);
  386. return ResponseHelp.success(true);
  387. }
  388. @RequestMapping(value = "/comment/delete", method = RequestMethod.DELETE)
  389. @ApiOperation(value = "删除评价", httpMethod = "DELETE")
  390. private Response<Boolean> deleteComment(@RequestParam int id){
  391. commentService.delete(id);
  392. return ResponseHelp.success(true);
  393. }
  394. @RequestMapping(value = "/comment/order", method = RequestMethod.PUT)
  395. @ApiOperation(value = "修改评价排序", httpMethod = "PUT")
  396. private Response<Boolean> orderComment(@RequestBody @Validated CommentOrderDto dto){
  397. commentService.updateOrder(dto.getIds());
  398. return ResponseHelp.success(true);
  399. }
  400. @RequestMapping(value = "/comment/list", method = RequestMethod.GET)
  401. @ApiOperation(value = "获取评价列表", httpMethod = "GET")
  402. private Response<PageMessage<CommentInfoDto>> listComment(
  403. @RequestParam(required = false, defaultValue = "1") int page,
  404. @RequestParam(required = false, defaultValue = "100") int size,
  405. @RequestParam(required = false) Boolean user,
  406. @RequestParam(required = false) String channel,
  407. @RequestParam(required = false) String position,
  408. @RequestParam(required = false) Integer userId,
  409. @RequestParam(required = false) Boolean isSpecial,
  410. @RequestParam(required = false) Boolean isShow,
  411. @RequestParam(required = false) Integer moneyRang,
  412. @RequestParam(required = false, defaultValue = "id") String order,
  413. @RequestParam(required = false, defaultValue = "desc") String direction
  414. ){
  415. Page<Comment> p = commentService.listAdmin(page, size, user, channel, position, userId, isSpecial, isShow, MoneyRange.ValueOf(moneyRang), order, DirectionStatus.ValueOf(direction));
  416. List<CommentInfoDto> pr = Transform.convert(p, CommentInfoDto.class);
  417. // 绑定用户
  418. Collection userIds = Transform.getIds(p, Comment.class, "userId");
  419. List<User> userList = usersService.select(userIds);
  420. Transform.combine(pr, userList, CommentDto.class, "userId", "user", User.class, "id", UserExtendDto.class);
  421. // 绑定课程
  422. List<CommentInfoDto> prCourse = pr.stream().filter((row)-> row.getChannel().equals("course-video")).collect(Collectors.toList());
  423. Collection courseIds = Transform.getIds(prCourse, CommentInfoDto.class, "position");
  424. List<Course> courseList = courseService.select(courseIds);
  425. Transform.combine(prCourse, courseList, CommentInfoDto.class, "position", "positionDetail", Course.class, "id", InfoExtendDto.class);
  426. // 绑定资料
  427. List<CommentInfoDto> prData = pr.stream().filter((row)-> row.getChannel().equals("course_data")).collect(Collectors.toList());
  428. Collection dataIds = Transform.getIds(prData, CommentInfoDto.class, "position");
  429. List<CourseData> dataList = courseDataService.select(dataIds);
  430. Transform.combine(prData, dataList, CommentInfoDto.class, "position", "positionDetail", CourseData.class, "id", InfoExtendDto.class);
  431. return ResponseHelp.success(pr, page, size, p.getTotal());
  432. }
  433. @RequestMapping(value = "/faq/add", method = RequestMethod.POST)
  434. @ApiOperation(value = "添加faq", httpMethod = "POST")
  435. private Response<Boolean> addFaq(@RequestBody @Validated FaqDto dto){
  436. Faq entity = Transform.dtoToEntity(dto);
  437. entity.setIsSystem(1);
  438. if(!entity.getAnswer().isEmpty()){
  439. entity.setAnswerTime(new Date());
  440. entity.setAnswerStatus(AskStatus.ANSWER.index);
  441. Manager manager = shiroHelp.getLoginManager();
  442. entity.setManagerId(manager.getId());
  443. }
  444. faqService.add(entity);
  445. return ResponseHelp.success(true);
  446. }
  447. @RequestMapping(value = "/faq/edit", method = RequestMethod.PUT)
  448. @ApiOperation(value = "修改faq", httpMethod = "PUT")
  449. private Response<Boolean> editFaq(@RequestBody @Validated FaqDto dto){
  450. Faq entity = Transform.dtoToEntity(dto);
  451. Faq in = faqService.get(entity.getId());
  452. // 调整回答
  453. if(entity.getAnswer() != null && (!entity.getAnswer().isEmpty() || !in.getAnswer().equals(entity.getAnswer()))){
  454. entity.setAnswerTime(new Date());
  455. entity.setAnswerStatus(AskStatus.ANSWER.index);
  456. Manager manager = shiroHelp.getLoginManager();
  457. entity.setManagerId(manager.getId());
  458. User user = usersService.get(in.getUserId());
  459. if(in.getIsSystem() == 0){
  460. messageExtendService.sendFaqCallback(user, in);
  461. }
  462. }
  463. faqService.edit(entity);
  464. return ResponseHelp.success(true);
  465. }
  466. @RequestMapping(value = "/faq/order", method = RequestMethod.PUT)
  467. @ApiOperation(value = "修改faq排序", httpMethod = "PUT")
  468. private Response<Boolean> orderFaq(@RequestBody @Validated FaqOrderDto dto){
  469. faqService.updateOrder(dto.getIds());
  470. return ResponseHelp.success(true);
  471. }
  472. @RequestMapping(value = "/faq/delete", method = RequestMethod.DELETE)
  473. @ApiOperation(value = "删除评价", httpMethod = "DELETE")
  474. private Response<Boolean> deleteFaq(@RequestParam int id){
  475. faqService.delete(id);
  476. return ResponseHelp.success(true);
  477. }
  478. @RequestMapping(value = "/faq/list", method = RequestMethod.GET)
  479. @ApiOperation(value = "获取faq列表", httpMethod = "GET")
  480. private Response<PageMessage<FaqInfoDto>> listFaq(
  481. @RequestParam(required = false, defaultValue = "1") int page,
  482. @RequestParam(required = false, defaultValue = "100") int size,
  483. @RequestParam(required = false) Boolean user,
  484. @RequestParam(required = false) String channel,
  485. @RequestParam(required = false) String position,
  486. @RequestParam(required = false) Integer userId,
  487. @RequestParam(required = false) Integer answerStatus,
  488. @RequestParam(required = false) Boolean isShow,
  489. @RequestParam(required = false) Boolean isSpecial,
  490. @RequestParam(required = false) Integer moneyRang,
  491. @RequestParam(required = false, defaultValue = "id") String order,
  492. @RequestParam(required = false, defaultValue = "desc") String direction
  493. ){
  494. Page<Faq> p = faqService.listAdmin(page, size, user, channel, position, userId, answerStatus, isSpecial, isShow, MoneyRange.ValueOf(moneyRang), order, DirectionStatus.ValueOf(direction));
  495. List<FaqInfoDto> pr = Transform.convert(p, FaqInfoDto.class);
  496. // 绑定用户
  497. Collection userIds = Transform.getIds(p, Faq.class, "userId");
  498. List<User> userList = usersService.select(userIds);
  499. Transform.combine(pr, userList, CommentDto.class, "userId", "user", User.class, "id", UserExtendDto.class);
  500. // 绑定position
  501. // 绑定课程
  502. List<FaqInfoDto> prCourse = pr.stream().filter((row)-> row.getChannel().equals("course-video")).collect(Collectors.toList());
  503. Collection courseIds = Transform.getIds(prCourse, FaqInfoDto.class, "position");
  504. List<Course> courseList = courseService.select(courseIds);
  505. Transform.combine(prCourse, courseList, FaqInfoDto.class, "position", "positionDetail", Course.class, "id", InfoExtendDto.class);
  506. // 绑定资料
  507. List<FaqInfoDto> prData = pr.stream().filter((row)-> row.getChannel().equals("course_data")).collect(Collectors.toList());
  508. Collection dataIds = Transform.getIds(prData, FaqInfoDto.class, "position");
  509. List<CourseData> dataList = courseDataService.select(dataIds);
  510. Transform.combine(prData, dataList, FaqInfoDto.class, "position", "positionDetail", CourseData.class, "id", InfoExtendDto.class);
  511. return ResponseHelp.success(pr, page, size, p.getTotal());
  512. }
  513. @RequestMapping(value = "/message/add", method = RequestMethod.POST)
  514. @ApiOperation(value = "添加消息", httpMethod = "POST")
  515. private Response<Boolean> addMessage(@RequestBody @Validated MessageTemplateDto dto){
  516. MessageTemplate entity = Transform.dtoToEntity(dto);
  517. messageTemplateService.add(entity);
  518. return ResponseHelp.success(true);
  519. }
  520. @RequestMapping(value = "/message/edit", method = RequestMethod.PUT)
  521. @ApiOperation(value = "修改消息", httpMethod = "PUT")
  522. private Response<Boolean> editMessage(@RequestBody @Validated MessageTemplateDto dto){
  523. MessageTemplate entity = Transform.dtoToEntity(dto);
  524. messageTemplateService.edit(entity);
  525. return ResponseHelp.success(true);
  526. }
  527. @RequestMapping(value = "/message/delete", method = RequestMethod.DELETE)
  528. @ApiOperation(value = "删除消息", httpMethod = "DELETE")
  529. private Response<Boolean> deleteMessage(@RequestParam int id){
  530. MessageTemplate in = messageTemplateService.get(id);
  531. if(!in.getMessageCategory().equals(MessageCategory.CUSTOM.key)){
  532. throw new ParameterException("不允许删除非自定义消息模版");
  533. }
  534. messageTemplateService.delete(id);
  535. return ResponseHelp.success(true);
  536. }
  537. @RequestMapping(value = "/message/detail", method = RequestMethod.GET)
  538. @ApiOperation(value = "获取消息", httpMethod = "GET")
  539. public Response<MessageTemplate> detailMessage(@RequestParam int id, HttpSession session) {
  540. MessageTemplate entity = messageTemplateService.get(id);
  541. return ResponseHelp.success(entity);
  542. }
  543. @RequestMapping(value = "/message/list", method = RequestMethod.GET)
  544. @ApiOperation(value = "获取消息列表", httpMethod = "GET")
  545. private Response<PageMessage<MessageTemplate>> listMessage(
  546. @RequestParam(required = false, defaultValue = "1") int page,
  547. @RequestParam(required = false, defaultValue = "100") int size,
  548. @RequestParam(required = false) String messageCategory,
  549. @RequestParam(required = false) String messageMethod,
  550. @RequestParam(required = false) Boolean needCustom,
  551. @RequestParam(required = false, defaultValue = "id") String order,
  552. @RequestParam(required = false, defaultValue = "desc") String direction
  553. ){
  554. Page<MessageTemplate> p = messageTemplateService.listAdmin(page, size, MessageCategory.ValueOf(messageCategory), MessageMethod.ValueOf(messageMethod), needCustom,order, DirectionStatus.ValueOf(direction));
  555. return ResponseHelp.success(p, page, size, p.getTotal());
  556. }
  557. @RequestMapping(value = "/ad/add", method = RequestMethod.POST)
  558. @ApiOperation(value = "添加广告", httpMethod = "POST")
  559. public Response<Ad> addAd(@RequestBody @Validated AdDto dto, HttpServletRequest request) {
  560. Ad entity = Transform.dtoToEntity(dto);
  561. entity = adService.addAd(entity);
  562. managerLogService.log(request);
  563. return ResponseHelp.success(entity);
  564. }
  565. @RequestMapping(value = "/ad/edit", method = RequestMethod.PUT)
  566. @ApiOperation(value = "修改广告", httpMethod = "PUT")
  567. public Response<Boolean> editAd(@RequestBody @Validated AdDto dto, HttpServletRequest request) {
  568. Ad entity = Transform.dtoToEntity(dto);
  569. entity = adService.editAd(entity);
  570. managerLogService.log(request);
  571. return ResponseHelp.success(true);
  572. }
  573. @RequestMapping(value = "/ad/delete", method = RequestMethod.DELETE)
  574. @ApiOperation(value = "删除广告", httpMethod = "DELETE")
  575. public Response<Boolean> deleteAd(@RequestParam int id, HttpServletRequest request) {
  576. adService.delete(id);
  577. managerLogService.log(request);
  578. return ResponseHelp.success(true);
  579. }
  580. @RequestMapping(value = "/ad/detail", method = RequestMethod.GET)
  581. @ApiOperation(value = "获取广告", httpMethod = "GET")
  582. public Response<Ad> detailAd(@RequestParam int id, HttpSession session) {
  583. Ad entity = adService.get(id);
  584. return ResponseHelp.success(entity);
  585. }
  586. @RequestMapping(value = "/ad/list", method = RequestMethod.GET)
  587. @ApiOperation(value = "广告列表", httpMethod = "GET")
  588. public Response<PageMessage<Ad>> listAd(
  589. @RequestParam(required = false, defaultValue = "1") int page,
  590. @RequestParam(required = false, defaultValue = "100") int size,
  591. @RequestParam(required = false) String channel,
  592. @RequestParam(required = false) String position,
  593. @RequestParam(required = false, defaultValue = "id") String order,
  594. @RequestParam(required = false, defaultValue = "desc") String direction,
  595. HttpSession session) {
  596. Page<Ad> p = adService.listAdmin(page, size, channel, position, order, DirectionStatus.ValueOf(direction));
  597. return ResponseHelp.success(p, page, size, p.getTotal());
  598. }
  599. @RequestMapping(value = "/contract/edit", method = RequestMethod.PUT)
  600. @ApiOperation(value = "修改合同", httpMethod = "PUT")
  601. private Response<Boolean> editContract(@RequestBody @Validated ContractDto dto){
  602. Contract entity = Transform.dtoToEntity(dto);
  603. contractService.editContract(entity);
  604. return ResponseHelp.success(true);
  605. }
  606. @RequestMapping(value = "/contract/detail", method = RequestMethod.GET)
  607. @ApiOperation(value = "修改排行", httpMethod = "GET")
  608. private Response<Contract> getContract(String key){
  609. Contract in = contractService.getContract(key);
  610. return ResponseHelp.success(in);
  611. }
  612. @RequestMapping(value = "/contract/all", method = RequestMethod.GET)
  613. @ApiOperation(value = "获取排行设置", httpMethod = "GET")
  614. private Response<List<Contract>> allContract(){
  615. List<Contract> contractList = contractService.all();
  616. return ResponseHelp.success(contractList);
  617. }
  618. @RequestMapping(value = "/rank/add", method = RequestMethod.POST)
  619. @ApiOperation(value = "添加排行", httpMethod = "POST")
  620. private Response<Boolean> addRank(@RequestBody @Validated RankDto dto){
  621. Rank entity = Transform.dtoToEntity(dto);
  622. rankService.add(entity);
  623. return ResponseHelp.success(true);
  624. }
  625. @RequestMapping(value = "/rank/edit", method = RequestMethod.PUT)
  626. @ApiOperation(value = "修改排行", httpMethod = "PUT")
  627. private Response<Boolean> editRank(@RequestBody @Validated RankDto dto){
  628. Rank entity = Transform.dtoToEntity(dto);
  629. rankService.edit(entity);
  630. return ResponseHelp.success(true);
  631. }
  632. @RequestMapping(value = "/rank/delete", method = RequestMethod.DELETE)
  633. @ApiOperation(value = "删除排行", httpMethod = "DELETE")
  634. private Response<Boolean> deleteRank(@RequestParam int id){
  635. rankService.delete(id);
  636. return ResponseHelp.success(true);
  637. }
  638. @RequestMapping(value = "/rank/list", method = RequestMethod.GET)
  639. @ApiOperation(value = "获取排行设置", httpMethod = "GET")
  640. private Response<List<Rank>> getRank(){
  641. List<Rank> rankList = rankService.all();
  642. return ResponseHelp.success(rankList);
  643. }
  644. @RequestMapping(value = "/rank/import", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, method = RequestMethod.POST)
  645. @ApiOperation(value = "导入排行数据", httpMethod = "POST")
  646. private Response<Boolean> importRank(@RequestParam("file") MultipartFile multipartFile) throws IOException {
  647. // 删除所有排行数据, 并导入excel数据
  648. // 读取文件
  649. InputStream is = new FileInputStream("002.xls");
  650. // 将文件流解析成 POI 文档
  651. POIFSFileSystem fs = new POIFSFileSystem(is);
  652. // 再将 POI 文档解析成 Excel 工作簿
  653. HSSFWorkbook wb = new HSSFWorkbook(fs);
  654. HSSFRow row = null;
  655. HSSFCell cell = null;
  656. // 得到第 1 个工作簿
  657. HSSFSheet sheet = wb.getSheetAt(0);
  658. // 得到这一行一共有多少列
  659. int totalColumns = sheet.getRow(0).getPhysicalNumberOfCells();
  660. // 得到最后一行的坐标
  661. Integer lastRowNum = sheet.getLastRowNum();
  662. System.out.println("lastRowNum => " + lastRowNum);
  663. List<Rank> rankList = new ArrayList<>();
  664. Rank rank = null;
  665. String cellValue = null;
  666. // 从第 2 行开始读
  667. for(int i=1;i<=lastRowNum;i++){
  668. row = sheet.getRow(i);
  669. rank = new Rank();
  670. for(int j=0;j<totalColumns;j++){
  671. cell = row.getCell(j);
  672. if(cell!=null){
  673. cellValue = cell.getStringCellValue();
  674. }else {
  675. cellValue = "【没有数据】";
  676. }
  677. }
  678. rankList.add(rank);
  679. }
  680. rankService.replaceAll(rankList);
  681. return ResponseHelp.success(true);
  682. }
  683. }