WithdrawApplyController.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package com.izouma.nineth.web;
  2. import com.izouma.nineth.domain.WithdrawApply;
  3. import com.izouma.nineth.service.WithdrawApplyService;
  4. import com.izouma.nineth.dto.PageQuery;
  5. import com.izouma.nineth.exception.BusinessException;
  6. import com.izouma.nineth.repo.WithdrawApplyRepo;
  7. import com.izouma.nineth.utils.SecurityUtils;
  8. import com.izouma.nineth.utils.excel.ExcelUtils;
  9. import lombok.AllArgsConstructor;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.data.domain.Page;
  12. import org.springframework.security.access.prepost.PreAuthorize;
  13. import org.springframework.web.bind.annotation.*;
  14. import javax.servlet.http.HttpServletResponse;
  15. import java.io.IOException;
  16. import java.math.BigDecimal;
  17. import java.util.List;
  18. import java.util.concurrent.ExecutionException;
  19. @RestController
  20. @RequestMapping("/withdrawApply")
  21. @AllArgsConstructor
  22. @Slf4j
  23. public class WithdrawApplyController extends BaseController {
  24. private WithdrawApplyService withdrawApplyService;
  25. private WithdrawApplyRepo withdrawApplyRepo;
  26. @PreAuthorize("hasRole('ADMIN')")
  27. @PostMapping("/all")
  28. public Page<WithdrawApply> all(@RequestBody PageQuery pageQuery) {
  29. return withdrawApplyService.all(pageQuery);
  30. }
  31. @PreAuthorize("hasRole('ADMIN')")
  32. @GetMapping("/get/{id}")
  33. public WithdrawApply get(@PathVariable Long id) {
  34. return withdrawApplyRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  35. }
  36. @GetMapping("/excel")
  37. @ResponseBody
  38. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  39. List<WithdrawApply> data = all(pageQuery).getContent();
  40. ExcelUtils.export(response, data);
  41. }
  42. @PostMapping("/apply")
  43. public WithdrawApply apply(@RequestParam BigDecimal amount) {
  44. return withdrawApplyService.apply(SecurityUtils.getAuthenticatedUser().getId(), amount);
  45. }
  46. @PreAuthorize("hasRole('ADMIN')")
  47. @PostMapping("/finish")
  48. public WithdrawApply finish(@RequestParam Long id, @RequestParam boolean approve, String reason) {
  49. return withdrawApplyService.finishWithdrawApply(id, approve, reason);
  50. }
  51. @PreAuthorize("hasRole('ADMIN')")
  52. @PostMapping("/approveAll")
  53. public void approveAll() throws ExecutionException, InterruptedException {
  54. withdrawApplyService.approveAllAsync();
  55. }
  56. @PreAuthorize("hasRole('ADMIN')")
  57. @PostMapping("/fixCharge")
  58. public void fixCharge() throws ExecutionException, InterruptedException {
  59. withdrawApplyService.fixCharge();
  60. }
  61. @PreAuthorize("hasRole('ADMIN')")
  62. @PostMapping("/applyAll")
  63. public void applyAll() throws ExecutionException, InterruptedException {
  64. withdrawApplyService.applyAll();
  65. }
  66. }