NeteaseMessageController.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.izouma.nineth.web.netease;
  2. import com.izouma.nineth.web.BaseController;
  3. import com.izouma.nineth.domain.netease.NeteaseMessage;
  4. import com.izouma.nineth.service.netease.NeteaseMessageService;
  5. import com.izouma.nineth.dto.PageQuery;
  6. import com.izouma.nineth.exception.BusinessException;
  7. import com.izouma.nineth.repo.netease.NeteaseMessageRepo;
  8. import com.izouma.nineth.utils.ObjUtils;
  9. import com.izouma.nineth.utils.excel.ExcelUtils;
  10. import lombok.AllArgsConstructor;
  11. import org.apache.commons.validator.Msg;
  12. import org.springframework.data.domain.Page;
  13. import org.springframework.security.access.prepost.PreAuthorize;
  14. import org.springframework.web.bind.annotation.*;
  15. import javax.servlet.http.HttpServletResponse;
  16. import java.io.IOException;
  17. import java.util.List;
  18. @RestController
  19. @RequestMapping("/neteaseMessage")
  20. @AllArgsConstructor
  21. public class NeteaseMessageController extends BaseController {
  22. private NeteaseMessageService neteaseMessageService;
  23. private NeteaseMessageRepo neteaseMessageRepo;
  24. //@PreAuthorize("hasRole('ADMIN')")
  25. @PostMapping("/save")
  26. public NeteaseMessage save(@RequestBody NeteaseMessage record) {
  27. if (record.getId() != null) {
  28. NeteaseMessage orig = neteaseMessageRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
  29. ObjUtils.merge(orig, record);
  30. return neteaseMessageRepo.save(orig);
  31. }
  32. return neteaseMessageRepo.save(record);
  33. }
  34. //@PreAuthorize("hasRole('ADMIN')")
  35. @PostMapping("/all")
  36. public Page<NeteaseMessage> all(@RequestBody PageQuery pageQuery) {
  37. return neteaseMessageService.all(pageQuery);
  38. }
  39. @GetMapping("/get/{id}")
  40. public NeteaseMessage get(@PathVariable Long id) {
  41. return neteaseMessageRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  42. }
  43. @PostMapping("/del/{id}")
  44. public void del(@PathVariable Long id) {
  45. neteaseMessageRepo.softDelete(id);
  46. }
  47. @GetMapping("/excel")
  48. @ResponseBody
  49. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  50. List<NeteaseMessage> data = all(pageQuery).getContent();
  51. ExcelUtils.export(response, data);
  52. }
  53. @PostMapping("/sendMsg")
  54. public NeteaseMessage sendMsg(@RequestBody NeteaseMessage msg) {
  55. return neteaseMessageService.sendMessage(msg);
  56. }
  57. }