You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.7 KiB

2 months ago
  1. package com.example.demo.controller.cash;
  2. import com.example.demo.Util.JWTUtil;
  3. import com.example.demo.domain.entity.Admin;
  4. import com.example.demo.domain.vo.cash.CashCollection;
  5. import com.example.demo.domain.vo.coin.Page;
  6. import com.example.demo.domain.vo.coin.Result;
  7. import com.example.demo.service.coin.MarketService;
  8. import com.example.demo.serviceImpl.cash.CashRefundServiceImpl;
  9. import com.github.pagehelper.PageInfo;
  10. import jakarta.servlet.http.HttpServletRequest;
  11. import lombok.RequiredArgsConstructor;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.util.ObjectUtils;
  16. import org.springframework.web.bind.annotation.*;
  17. import org.springframework.web.context.request.RequestContextHolder;
  18. import org.springframework.web.context.request.ServletRequestAttributes;
  19. import java.util.Arrays;
  20. import java.util.List;
  21. /**
  22. * @program: GOLD
  23. * @ClassName RefundController
  24. * @description:
  25. * @author: huangqizhen
  26. * @create: 202509-26 14:15
  27. * @Version 1.0
  28. **/
  29. @RestController
  30. @RequestMapping("/Money")
  31. @RequiredArgsConstructor
  32. @Slf4j
  33. @CrossOrigin
  34. public class CashRefundController {
  35. @Autowired
  36. private CashRefundServiceImpl cashRefundServiceImpl;
  37. @Autowired
  38. MarketService marketService;
  39. @PostMapping("/select")
  40. public Result select(@RequestBody Page page) throws Exception {
  41. // 获取当前请求对象
  42. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  43. String token = request.getHeader("token");
  44. // 解析 token 获取用户信息
  45. Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
  46. List<String> userMarkets = Arrays.asList(StringUtils.split(admin.getMarkets(), ","));
  47. List<String> markets = marketService.getMarketIds(userMarkets);
  48. // 校验分页参数
  49. if (ObjectUtils.isEmpty(page.getPageNum())) {
  50. return Result.error("页码数为空!");
  51. }
  52. if (ObjectUtils.isEmpty(page.getPageSize())) {
  53. return Result.error("页大小为空!");
  54. }
  55. // 获取传入的市场列表
  56. List<String> requestedMarkets = page.getGoldDetail() != null ? page.getGoldDetail().getMarkets() : null;
  57. // 权限校验逻辑
  58. if (markets.contains("9") || markets.contains("9999")) {
  59. // 特权市场:9 或 9999,跳过权限校验,直接放行传入的 markets
  60. // 如果业务需要,也可以在这里做空值处理
  61. if (page.getGoldDetail() != null) {
  62. // 保持 requestedMarkets 不变,原样接受
  63. // 可选:如果 requestedMarkets 为 null,可设为默认值或保持 null
  64. }
  65. } else {
  66. // 普通用户:必须校验权限
  67. if (requestedMarkets == null || requestedMarkets.isEmpty()) {
  68. page.getGoldDetail().setMarkets(requestedMarkets);
  69. }
  70. if (!markets.containsAll(requestedMarkets)) {
  71. return Result.error("无权限!请求的市场不在授权范围内。");
  72. }
  73. // 校验通过,保持 requestedMarkets 不变
  74. }
  75. return Result.success(cashRefundServiceImpl.select(page.getPageNum(),page.getPageSize(),page.getCashCollection()));
  76. }
  77. @PostMapping("/add")
  78. public Result add(@RequestBody CashCollection cashCollection){
  79. return Result.success(cashRefundServiceImpl.add(cashCollection));
  80. }
  81. @PostMapping("/update")
  82. public Result update(@RequestBody CashCollection cashCollection){
  83. return Result.success(cashRefundServiceImpl.update(cashCollection));
  84. }
  85. }