ShowCollectionController.java 2.1 KB

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