package com.qxgmat.controller.admin; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.Page; import com.nuliji.tools.*; import com.nuliji.tools.exception.ParameterException; import com.qxgmat.data.constants.enums.MessageCategory; import com.qxgmat.data.constants.enums.MessageMethod; import com.qxgmat.data.constants.enums.MessageType; import com.qxgmat.data.constants.enums.SettingKey; import com.qxgmat.data.constants.enums.status.AskStatus; import com.qxgmat.data.constants.enums.status.DirectionStatus; import com.qxgmat.data.constants.enums.user.MoneyRange; import com.qxgmat.data.dao.entity.*; import com.qxgmat.dto.admin.extend.InfoExtendDto; import com.qxgmat.dto.admin.extend.UserExtendDto; import com.qxgmat.dto.admin.request.*; import com.qxgmat.dto.admin.response.CommentInfoDto; import com.qxgmat.dto.admin.response.FaqInfoDto; import com.qxgmat.help.ShiroHelp; import com.qxgmat.service.UsersService; import com.qxgmat.service.extend.MessageExtendService; import com.qxgmat.service.inline.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @RestController("AdminSettingController") @RequestMapping("/admin/setting") @Api(tags = "配置信息接口", description = "全局独立配置设置", produces = MediaType.APPLICATION_JSON_VALUE) public class SettingController { private static final Logger logger = LoggerFactory.getLogger(SettingController.class); @Autowired private ShiroHelp shiroHelp; @Autowired private ManagerLogService managerLogService; @Autowired private AdService adService; @Autowired private SettingService settingService; @Autowired private RankService rankService; @Autowired private ContractService contractService; @Autowired private CommentService commentService; @Autowired private FaqService faqService; @Autowired private MessageTemplateService messageTemplateService; @Autowired private MessageExtendService messageExtendService; @Autowired private UsersService usersService; @Autowired private CourseService courseService; @Autowired private CourseDataService courseDataService; @RequestMapping(value = "/index", method = RequestMethod.PUT) @ApiOperation(value = "修改首页配置", httpMethod = "PUT") private Response editIndex(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.INDEX); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/index", method = RequestMethod.GET) @ApiOperation(value = "获取首页配置", httpMethod = "GET") private Response getIndex(){ Setting entity = settingService.getByKey(SettingKey.INDEX); logger.debug("{}", entity); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/place", method = RequestMethod.PUT) @ApiOperation(value = "修改考点设置", httpMethod = "PUT") private Response editPlace(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.PLACE); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/place", method = RequestMethod.GET) @ApiOperation(value = "获取考点配置", httpMethod = "GET") private Response getPlace(){ Setting entity = settingService.getByKey(SettingKey.PLACE); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/sentence", method = RequestMethod.PUT) @ApiOperation(value = "修改长难句设置", httpMethod = "PUT") private Response editSentence(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.SENTENCE); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/sentence", method = RequestMethod.GET) @ApiOperation(value = "获取长难句配置", httpMethod = "GET") private Response getSentence(){ Setting entity = settingService.getByKey(SettingKey.SENTENCE); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/exercise_time", method = RequestMethod.PUT) @ApiOperation(value = "修改做题时间设置", httpMethod = "PUT") private Response editExerciseTime(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.EXERCISE_TIME); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/exercise_time", method = RequestMethod.GET) @ApiOperation(value = "获取做题时间配置", httpMethod = "GET") private Response getExerciseTime(){ Setting entity = settingService.getByKey(SettingKey.EXERCISE_TIME); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/examination_time", method = RequestMethod.PUT) @ApiOperation(value = "修改做题时间设置", httpMethod = "PUT") private Response editExaminationTime(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.EXAMINATION_TIME); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/examination_time", method = RequestMethod.GET) @ApiOperation(value = "获取做题时间配置", httpMethod = "GET") private Response getExaminationTime(){ Setting entity = settingService.getByKey(SettingKey.EXAMINATION_TIME); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/filter_time", method = RequestMethod.PUT) @ApiOperation(value = "修改剔除时间设置", httpMethod = "PUT") private Response editFilterTime(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.FILTER_TIME); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/filter_time", method = RequestMethod.GET) @ApiOperation(value = "获取剔除时间配置", httpMethod = "GET") private Response getFilterTime(){ Setting entity = settingService.getByKey(SettingKey.FILTER_TIME); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/exercise_paper_auto", method = RequestMethod.PUT) @ApiOperation(value = "修改自动组卷时间设置", httpMethod = "PUT") private Response editExercisePaperAuto(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.EXERCISE_PAPER_AUTO); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/exercise_paper_auto", method = RequestMethod.GET) @ApiOperation(value = "获取自动组卷时间配置", httpMethod = "GET") private Response getExercisePaperAuto(){ Setting entity = settingService.getByKey(SettingKey.EXERCISE_PAPER_AUTO); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/sentence_time", method = RequestMethod.PUT) @ApiOperation(value = "修改长难句时间设置", httpMethod = "PUT") private Response editSentenceTime(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.SENTENCE_TIME); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/sentence_time", method = RequestMethod.GET) @ApiOperation(value = "获取长难句时间配置", httpMethod = "GET") private Response getSentenceTime(){ Setting entity = settingService.getByKey(SettingKey.SENTENCE_TIME); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/textbook_time", method = RequestMethod.PUT) @ApiOperation(value = "修改机经时间设置", httpMethod = "PUT") private Response editTextbookTime(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.TEXTBOOK_TIME); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/textbook_time", method = RequestMethod.GET) @ApiOperation(value = "获取机经时间配置", httpMethod = "GET") private Response getTextbookTime(){ Setting entity = settingService.getByKey(SettingKey.TEXTBOOK_TIME); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/score_switch", method = RequestMethod.PUT) @ApiOperation(value = "修改分数开关", httpMethod = "PUT") private Response editScoreSwitch(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/score_switch", method = RequestMethod.GET) @ApiOperation(value = "获取分数开关", httpMethod = "GET") private Response getScoreSwitch(){ Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/service_vip", method = RequestMethod.PUT) @ApiOperation(value = "修改Vip服务", httpMethod = "PUT") private Response editServiceVip(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.SERVICE_VIP); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/service_vip", method = RequestMethod.GET) @ApiOperation(value = "获取Vip服务", httpMethod = "GET") private Response getServiceVip(){ Setting entity = settingService.getByKey(SettingKey.SERVICE_VIP); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/service_textbook", method = RequestMethod.PUT) @ApiOperation(value = "修改千行CAT服务", httpMethod = "PUT") private Response editServiceTextbook(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.SERVICE_TEXTBOOK); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/service_textbook", method = RequestMethod.GET) @ApiOperation(value = "获取千行CAT服务", httpMethod = "GET") private Response getServiceTextbook(){ Setting entity = settingService.getByKey(SettingKey.SERVICE_TEXTBOOK); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/service_qx_cat", method = RequestMethod.PUT) @ApiOperation(value = "修改千行CAT服务", httpMethod = "PUT") private Response editServiceQXCat(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/service_qx_cat", method = RequestMethod.GET) @ApiOperation(value = "获取千行CAT服务", httpMethod = "GET") private Response getServiceQXCat(){ Setting entity = settingService.getByKey(SettingKey.SCORE_SWITCH); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/course_index", method = RequestMethod.PUT) @ApiOperation(value = "修改课程首页", httpMethod = "PUT") private Response editCourseIndex(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.COURSE_INDEX); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/course_index", method = RequestMethod.GET) @ApiOperation(value = "获取课程首页", httpMethod = "GET") private Response getCourseIndex(){ Setting entity = settingService.getByKey(SettingKey.COURSE_INDEX); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/promote", method = RequestMethod.PUT) @ApiOperation(value = "修改促销", httpMethod = "PUT") private Response editPromote(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.PROMOTE); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/promote", method = RequestMethod.GET) @ApiOperation(value = "获取课程促销", httpMethod = "GET") private Response getPromote(){ Setting entity = settingService.getByKey(SettingKey.PROMOTE); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/experience_info", method = RequestMethod.PUT) @ApiOperation(value = "修改心经信息", httpMethod = "PUT") private Response editExperienceInfo(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.EXPERIENCE_INFO); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/experience_info", method = RequestMethod.GET) @ApiOperation(value = "获取心经信息", httpMethod = "GET") private Response getExperienceInfo(){ Setting entity = settingService.getByKey(SettingKey.EXPERIENCE_INFO); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/sentence_info", method = RequestMethod.PUT) @ApiOperation(value = "修改长难句信息", httpMethod = "PUT") private Response editSentenceInfo(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.SENTENCE_INFO); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/sentence_info", method = RequestMethod.GET) @ApiOperation(value = "获取长难句信息", httpMethod = "GET") private Response getSentenceInfo(){ Setting entity = settingService.getByKey(SettingKey.SENTENCE_INFO); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/wechat_info", method = RequestMethod.PUT) @ApiOperation(value = "修改长难句信息", httpMethod = "PUT") private Response editWechatInfo(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.WECHAT_INFO); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/wechat_info", method = RequestMethod.GET) @ApiOperation(value = "获取长难句信息", httpMethod = "GET") private Response getWechatInfo(){ Setting entity = settingService.getByKey(SettingKey.WECHAT_INFO); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/tips", method = RequestMethod.PUT) @ApiOperation(value = "修改结构说明", httpMethod = "PUT") private Response editTips(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.TIPS); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/tips", method = RequestMethod.GET) @ApiOperation(value = "获取结构说明", httpMethod = "GET") private Response getTips(){ Setting entity = settingService.getByKey(SettingKey.TIPS); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/ready_read", method = RequestMethod.PUT) @ApiOperation(value = "修改推荐阅读设置", httpMethod = "PUT") private Response editReadyRead(@RequestBody @Validated JSONObject dto){ Setting entity = settingService.getByKey(SettingKey.READY_READ); entity.setValue(dto); settingService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/ready_read", method = RequestMethod.GET) @ApiOperation(value = "获取推荐阅读配置", httpMethod = "GET") private Response getReadyRead(){ Setting entity = settingService.getByKey(SettingKey.READY_READ); return ResponseHelp.success(entity.getValue()); } @RequestMapping(value = "/comment/add", method = RequestMethod.POST) @ApiOperation(value = "添加评价", httpMethod = "POST") private Response addComment(@RequestBody @Validated CommentDto dto){ Comment entity = Transform.dtoToEntity(dto); entity.setIsSystem(1); commentService.add(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/comment/edit", method = RequestMethod.PUT) @ApiOperation(value = "修改评价", httpMethod = "PUT") private Response editComment(@RequestBody @Validated CommentDto dto){ Comment entity = Transform.dtoToEntity(dto); commentService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/comment/delete", method = RequestMethod.DELETE) @ApiOperation(value = "删除评价", httpMethod = "DELETE") private Response deleteComment(@RequestParam int id){ commentService.delete(id); return ResponseHelp.success(true); } @RequestMapping(value = "/comment/order", method = RequestMethod.PUT) @ApiOperation(value = "修改评价排序", httpMethod = "PUT") private Response orderComment(@RequestBody @Validated CommentOrderDto dto){ commentService.updateOrder(dto.getIds()); return ResponseHelp.success(true); } @RequestMapping(value = "/comment/list", method = RequestMethod.GET) @ApiOperation(value = "获取评价列表", httpMethod = "GET") private Response> listComment( @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "100") int size, @RequestParam(required = false) Boolean user, @RequestParam(required = false) String channel, @RequestParam(required = false) String position, @RequestParam(required = false) Integer userId, @RequestParam(required = false) Boolean isSpecial, @RequestParam(required = false) Boolean isShow, @RequestParam(required = false) Integer moneyRang, @RequestParam(required = false, defaultValue = "id") String order, @RequestParam(required = false, defaultValue = "desc") String direction ){ Page p = commentService.listAdmin(page, size, user, channel, position, userId, isSpecial, isShow, MoneyRange.ValueOf(moneyRang), order, DirectionStatus.ValueOf(direction)); List pr = Transform.convert(p, CommentInfoDto.class); // 绑定用户 Collection userIds = Transform.getIds(p, Comment.class, "userId"); List userList = usersService.select(userIds); Transform.combine(pr, userList, CommentDto.class, "userId", "user", User.class, "id", UserExtendDto.class); // 绑定课程 List prCourse = pr.stream().filter((row)-> row.getChannel().equals("course-video")).collect(Collectors.toList()); Collection courseIds = Transform.getIds(prCourse, CommentInfoDto.class, "position"); List courseList = courseService.select(courseIds); Transform.combine(prCourse, courseList, CommentInfoDto.class, "position", "positionDetail", Course.class, "id", InfoExtendDto.class); // 绑定资料 List prData = pr.stream().filter((row)-> row.getChannel().equals("course_data")).collect(Collectors.toList()); Collection dataIds = Transform.getIds(prData, CommentInfoDto.class, "position"); List dataList = courseDataService.select(dataIds); Transform.combine(prData, dataList, CommentInfoDto.class, "position", "positionDetail", CourseData.class, "id", InfoExtendDto.class); return ResponseHelp.success(pr, page, size, p.getTotal()); } @RequestMapping(value = "/faq/add", method = RequestMethod.POST) @ApiOperation(value = "添加faq", httpMethod = "POST") private Response addFaq(@RequestBody @Validated FaqDto dto){ Faq entity = Transform.dtoToEntity(dto); entity.setIsSystem(1); if(!entity.getAnswer().isEmpty()){ entity.setAnswerTime(new Date()); entity.setAnswerStatus(AskStatus.ANSWER.index); Manager manager = shiroHelp.getLoginManager(); entity.setManagerId(manager.getId()); } faqService.add(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/faq/edit", method = RequestMethod.PUT) @ApiOperation(value = "修改faq", httpMethod = "PUT") private Response editFaq(@RequestBody @Validated FaqDto dto){ Faq entity = Transform.dtoToEntity(dto); Faq in = faqService.get(entity.getId()); // 调整回答 if(entity.getAnswer() != null && (!entity.getAnswer().isEmpty() || !in.getAnswer().equals(entity.getAnswer()))){ entity.setAnswerTime(new Date()); entity.setAnswerStatus(AskStatus.ANSWER.index); Manager manager = shiroHelp.getLoginManager(); entity.setManagerId(manager.getId()); User user = usersService.get(in.getUserId()); if(in.getIsSystem() == 0){ messageExtendService.sendFaqCallback(user, in); } } faqService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/faq/order", method = RequestMethod.PUT) @ApiOperation(value = "修改faq排序", httpMethod = "PUT") private Response orderFaq(@RequestBody @Validated FaqOrderDto dto){ faqService.updateOrder(dto.getIds()); return ResponseHelp.success(true); } @RequestMapping(value = "/faq/delete", method = RequestMethod.DELETE) @ApiOperation(value = "删除评价", httpMethod = "DELETE") private Response deleteFaq(@RequestParam int id){ faqService.delete(id); return ResponseHelp.success(true); } @RequestMapping(value = "/faq/list", method = RequestMethod.GET) @ApiOperation(value = "获取faq列表", httpMethod = "GET") private Response> listFaq( @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "100") int size, @RequestParam(required = false) Boolean user, @RequestParam(required = false) String channel, @RequestParam(required = false) String position, @RequestParam(required = false) Integer userId, @RequestParam(required = false) Integer answerStatus, @RequestParam(required = false) Boolean isShow, @RequestParam(required = false) Boolean isSpecial, @RequestParam(required = false) Integer moneyRang, @RequestParam(required = false, defaultValue = "id") String order, @RequestParam(required = false, defaultValue = "desc") String direction ){ Page p = faqService.listAdmin(page, size, user, channel, position, userId, answerStatus, isSpecial, isShow, MoneyRange.ValueOf(moneyRang), order, DirectionStatus.ValueOf(direction)); List pr = Transform.convert(p, FaqInfoDto.class); // 绑定用户 Collection userIds = Transform.getIds(p, Faq.class, "userId"); List userList = usersService.select(userIds); Transform.combine(pr, userList, CommentDto.class, "userId", "user", User.class, "id", UserExtendDto.class); // 绑定position // 绑定课程 List prCourse = pr.stream().filter((row)-> row.getChannel().equals("course-video")).collect(Collectors.toList()); Collection courseIds = Transform.getIds(prCourse, FaqInfoDto.class, "position"); List courseList = courseService.select(courseIds); Transform.combine(prCourse, courseList, FaqInfoDto.class, "position", "positionDetail", Course.class, "id", InfoExtendDto.class); // 绑定资料 List prData = pr.stream().filter((row)-> row.getChannel().equals("course_data")).collect(Collectors.toList()); Collection dataIds = Transform.getIds(prData, FaqInfoDto.class, "position"); List dataList = courseDataService.select(dataIds); Transform.combine(prData, dataList, FaqInfoDto.class, "position", "positionDetail", CourseData.class, "id", InfoExtendDto.class); return ResponseHelp.success(pr, page, size, p.getTotal()); } @RequestMapping(value = "/message/add", method = RequestMethod.POST) @ApiOperation(value = "添加消息", httpMethod = "POST") private Response addMessage(@RequestBody @Validated MessageTemplateDto dto){ MessageTemplate entity = Transform.dtoToEntity(dto); messageTemplateService.add(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/message/edit", method = RequestMethod.PUT) @ApiOperation(value = "修改消息", httpMethod = "PUT") private Response editMessage(@RequestBody @Validated MessageTemplateDto dto){ MessageTemplate entity = Transform.dtoToEntity(dto); messageTemplateService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/message/delete", method = RequestMethod.DELETE) @ApiOperation(value = "删除消息", httpMethod = "DELETE") private Response deleteMessage(@RequestParam int id){ MessageTemplate in = messageTemplateService.get(id); if(!in.getMessageCategory().equals(MessageCategory.CUSTOM.key)){ throw new ParameterException("不允许删除非自定义消息模版"); } messageTemplateService.delete(id); return ResponseHelp.success(true); } @RequestMapping(value = "/message/detail", method = RequestMethod.GET) @ApiOperation(value = "获取消息", httpMethod = "GET") public Response detailMessage(@RequestParam int id, HttpSession session) { MessageTemplate entity = messageTemplateService.get(id); return ResponseHelp.success(entity); } @RequestMapping(value = "/message/list", method = RequestMethod.GET) @ApiOperation(value = "获取消息列表", httpMethod = "GET") private Response> listMessage( @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "100") int size, @RequestParam(required = false) String messageCategory, @RequestParam(required = false) String messageMethod, @RequestParam(required = false) Boolean needCustom, @RequestParam(required = false, defaultValue = "id") String order, @RequestParam(required = false, defaultValue = "desc") String direction ){ Page p = messageTemplateService.listAdmin(page, size, MessageCategory.ValueOf(messageCategory), MessageMethod.ValueOf(messageMethod), needCustom,order, DirectionStatus.ValueOf(direction)); return ResponseHelp.success(p, page, size, p.getTotal()); } @RequestMapping(value = "/ad/add", method = RequestMethod.POST) @ApiOperation(value = "添加广告", httpMethod = "POST") public Response addAd(@RequestBody @Validated AdDto dto, HttpServletRequest request) { Ad entity = Transform.dtoToEntity(dto); entity = adService.addAd(entity); managerLogService.log(request); return ResponseHelp.success(entity); } @RequestMapping(value = "/ad/edit", method = RequestMethod.PUT) @ApiOperation(value = "修改广告", httpMethod = "PUT") public Response editAd(@RequestBody @Validated AdDto dto, HttpServletRequest request) { Ad entity = Transform.dtoToEntity(dto); entity = adService.editAd(entity); managerLogService.log(request); return ResponseHelp.success(true); } @RequestMapping(value = "/ad/delete", method = RequestMethod.DELETE) @ApiOperation(value = "删除广告", httpMethod = "DELETE") public Response deleteAd(@RequestParam int id, HttpServletRequest request) { adService.delete(id); managerLogService.log(request); return ResponseHelp.success(true); } @RequestMapping(value = "/ad/detail", method = RequestMethod.GET) @ApiOperation(value = "获取广告", httpMethod = "GET") public Response detailAd(@RequestParam int id, HttpSession session) { Ad entity = adService.get(id); return ResponseHelp.success(entity); } @RequestMapping(value = "/ad/list", method = RequestMethod.GET) @ApiOperation(value = "广告列表", httpMethod = "GET") public Response> listAd( @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "100") int size, @RequestParam(required = false) String channel, @RequestParam(required = false) String position, @RequestParam(required = false, defaultValue = "id") String order, @RequestParam(required = false, defaultValue = "desc") String direction, HttpSession session) { Page p = adService.listAdmin(page, size, channel, position, order, DirectionStatus.ValueOf(direction)); return ResponseHelp.success(p, page, size, p.getTotal()); } @RequestMapping(value = "/contract/edit", method = RequestMethod.PUT) @ApiOperation(value = "修改合同", httpMethod = "PUT") private Response editContract(@RequestBody @Validated ContractDto dto){ Contract entity = Transform.dtoToEntity(dto); contractService.editContract(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/contract/detail", method = RequestMethod.GET) @ApiOperation(value = "修改排行", httpMethod = "GET") private Response getContract(String key){ Contract in = contractService.getContract(key); return ResponseHelp.success(in); } @RequestMapping(value = "/contract/all", method = RequestMethod.GET) @ApiOperation(value = "获取排行设置", httpMethod = "GET") private Response> allContract(){ List contractList = contractService.all(); return ResponseHelp.success(contractList); } @RequestMapping(value = "/rank/add", method = RequestMethod.POST) @ApiOperation(value = "添加排行", httpMethod = "POST") private Response addRank(@RequestBody @Validated RankDto dto){ Rank entity = Transform.dtoToEntity(dto); rankService.add(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/rank/edit", method = RequestMethod.PUT) @ApiOperation(value = "修改排行", httpMethod = "PUT") private Response editRank(@RequestBody @Validated RankDto dto){ Rank entity = Transform.dtoToEntity(dto); rankService.edit(entity); return ResponseHelp.success(true); } @RequestMapping(value = "/rank/delete", method = RequestMethod.DELETE) @ApiOperation(value = "删除排行", httpMethod = "DELETE") private Response deleteRank(@RequestParam int id){ rankService.delete(id); return ResponseHelp.success(true); } @RequestMapping(value = "/rank/list", method = RequestMethod.GET) @ApiOperation(value = "获取排行设置", httpMethod = "GET") private Response> getRank(){ List rankList = rankService.all(); return ResponseHelp.success(rankList); } @RequestMapping(value = "/rank/import", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, method = RequestMethod.POST) @ApiOperation(value = "导入排行数据", httpMethod = "POST") private Response importRank(@RequestParam("file") MultipartFile multipartFile) throws IOException { // 删除所有排行数据, 并导入excel数据 // 读取文件 InputStream is = new FileInputStream("002.xls"); // 将文件流解析成 POI 文档 POIFSFileSystem fs = new POIFSFileSystem(is); // 再将 POI 文档解析成 Excel 工作簿 HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFRow row = null; HSSFCell cell = null; // 得到第 1 个工作簿 HSSFSheet sheet = wb.getSheetAt(0); // 得到这一行一共有多少列 int totalColumns = sheet.getRow(0).getPhysicalNumberOfCells(); // 得到最后一行的坐标 Integer lastRowNum = sheet.getLastRowNum(); System.out.println("lastRowNum => " + lastRowNum); List rankList = new ArrayList<>(); Rank rank = null; String cellValue = null; // 从第 2 行开始读 for(int i=1;i<=lastRowNum;i++){ row = sheet.getRow(i); rank = new Rank(); for(int j=0;j