ShowroomController.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. @PostMapping("/save")
  24. public Showroom save(@RequestBody Showroom record) {
  25. return showroomService.save(SecurityUtils.getAuthenticatedUser().getId(), record);
  26. }
  27. @PostMapping("/update")
  28. public Showroom update(@RequestBody Showroom record) {
  29. return showroomService.update(SecurityUtils.getAuthenticatedUser().getId(), record);
  30. }
  31. @PostMapping("/all")
  32. public Page<Showroom> all(@RequestBody PageQuery pageQuery) {
  33. return showroomService.all(pageQuery);
  34. }
  35. @GetMapping("/get/{id}")
  36. public Showroom get(@PathVariable Long id) {
  37. Showroom showroom = showroomRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  38. showroom.setCollections(showCollectionRepo.findAllByShowroomId(id));
  39. return showroom;
  40. }
  41. @PostMapping("/del/{id}")
  42. public void del(@PathVariable Long id) {
  43. showCollectionRepo.softDeleteByRoom(id);
  44. showroomRepo.softDelete(id);
  45. }
  46. @GetMapping("/excel")
  47. @ResponseBody
  48. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  49. List<Showroom> data = all(pageQuery).getContent();
  50. ExcelUtils.export(response, data);
  51. }
  52. @GetMapping("/{id}/share")
  53. public void addShare(@PathVariable Long id) {
  54. showroomRepo.addShare(id, 1);
  55. }
  56. }