UserCouponController.java 1.9 KB

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