ShowroomController.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package com.izouma.nineth.web;
  2. import com.izouma.nineth.domain.Showroom;
  3. import com.izouma.nineth.dto.PageQuery;
  4. import com.izouma.nineth.exception.BusinessException;
  5. import com.izouma.nineth.repo.ShowCollectionRepo;
  6. import com.izouma.nineth.repo.ShowroomRepo;
  7. import com.izouma.nineth.service.ShowroomService;
  8. import com.izouma.nineth.utils.SecurityUtils;
  9. import com.izouma.nineth.utils.excel.ExcelUtils;
  10. import lombok.AllArgsConstructor;
  11. import org.springframework.data.domain.Page;
  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("/showroom")
  18. @AllArgsConstructor
  19. public class ShowroomController extends BaseController {
  20. private ShowroomService showroomService;
  21. private ShowroomRepo showroomRepo;
  22. private ShowCollectionRepo showCollectionRepo;
  23. //@PreAuthorize("hasRole('ADMIN')")
  24. @PostMapping("/save")
  25. public Showroom save(@RequestBody Showroom record) {
  26. // if (record.getId() != null) {
  27. // Showroom orig = showroomRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
  28. // ObjUtils.merge(orig, record);
  29. // return showroomRepo.save(orig);
  30. // }
  31. // return showroomRepo.save(record);
  32. return showroomService.save(SecurityUtils.getAuthenticatedUser().getId(), record);
  33. }
  34. @PostMapping("/update")
  35. public Showroom update(@RequestBody Showroom record) {
  36. return showroomService.update(SecurityUtils.getAuthenticatedUser().getId(), record);
  37. }
  38. //@PreAuthorize("hasRole('ADMIN')")
  39. @PostMapping("/all")
  40. public Page<Showroom> all(@RequestBody PageQuery pageQuery) {
  41. return showroomService.all(pageQuery);
  42. }
  43. @GetMapping("/get/{id}")
  44. public Showroom get(@PathVariable Long id) {
  45. return showroomRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  46. }
  47. @PostMapping("/del/{id}")
  48. public void del(@PathVariable Long id) {
  49. showCollectionRepo.softDeleteByRoom(id);
  50. showroomRepo.softDelete(id);
  51. }
  52. @GetMapping("/excel")
  53. @ResponseBody
  54. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  55. List<Showroom> data = all(pageQuery).getContent();
  56. ExcelUtils.export(response, data);
  57. }
  58. }