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.

157 lines
5.9 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. package com.example.demo.controller.coin;
  2. import com.example.demo.Util.JWTUtil;
  3. import com.example.demo.config.interfac.Log;
  4. import com.example.demo.domain.entity.Admin;
  5. import com.example.demo.service.coin.RefundService;
  6. import jakarta.servlet.http.HttpServletRequest;
  7. import lombok.RequiredArgsConstructor;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.apache.commons.lang3.StringUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.util.ObjectUtils;
  12. import org.springframework.web.bind.annotation.*;
  13. import org.springframework.web.context.request.RequestContextHolder;
  14. import org.springframework.web.context.request.ServletRequestAttributes;
  15. import com.example.demo.domain.vo.coin.*;
  16. import java.util.Arrays;
  17. import java.util.List;
  18. /**
  19. * @program: gold-java
  20. * @ClassName RefundMapper.xml
  21. * @description:
  22. * @author: Double
  23. * @create: 202506-26 11:28
  24. * @Version 1.0
  25. **/
  26. @RestController
  27. @RequestMapping("/refund")
  28. @RequiredArgsConstructor
  29. @Slf4j
  30. @CrossOrigin
  31. public class RefundController {
  32. @Autowired
  33. private RefundService refundService;
  34. //退款明细
  35. @Log("获取全部退款明细")
  36. @PostMapping("/selectAll")
  37. public Result selcetAll(@RequestBody Page page) {
  38. try {
  39. if (ObjectUtils.isEmpty(page.getPageNum())) {
  40. return Result.error("页码数为空!");
  41. }
  42. if (ObjectUtils.isEmpty(page.getPageSize())) {
  43. return Result.error("页大小为空!");
  44. } else {
  45. //解token权限
  46. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  47. String token = request.getHeader("token");
  48. Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
  49. if (admin != null) {
  50. List<String> list = Arrays.asList(admin.getMarkets().split(","));
  51. page.getRefundUser().setMarkets(list);
  52. } else {
  53. return Result.error("角色为空");
  54. }
  55. return Result.success(refundService.selectAll(page.getPageNum(), page.getPageSize(), page.getRefundUser()));
  56. }
  57. } catch (Exception e) {
  58. return Result.error("请检查筛选数据的格式");
  59. }
  60. }
  61. //退款筛选
  62. @Log("退款明细筛选")
  63. @PostMapping("/selectBy")
  64. public Result selcetBy(@RequestBody Page page) {
  65. try {
  66. if (ObjectUtils.isEmpty(page.getPageNum())) {
  67. return Result.error("页码数为空!");
  68. }
  69. if (ObjectUtils.isEmpty(page.getPageSize())) {
  70. return Result.error("页大小为空!");
  71. } else {
  72. //解token权限
  73. if(page.getRefundUser().getMarkets()==null||page.getRefundUser().getMarkets().isEmpty()) {
  74. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  75. String token = request.getHeader("token");
  76. Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
  77. List<String> markets = Arrays.asList(StringUtils.split(admin.getMarkets(), ","));
  78. page.getRefundUser().setMarkets(markets);
  79. }
  80. return Result.success(refundService.selectBy(page.getPageNum(), page.getPageSize(), page.getRefundUser()));
  81. }
  82. } catch (Exception e) {
  83. return Result.error("请检查筛选数据的格式");
  84. }
  85. }
  86. //退款金币统计
  87. @Log("退款金币合计数统计")
  88. @PostMapping("/statsGold")
  89. public Result statsGold(@RequestBody RefundUser refundUser) {
  90. try {
  91. //解token权限
  92. if(refundUser.getMarkets()==null||refundUser.getMarkets().isEmpty()) {
  93. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  94. String token = request.getHeader("token");
  95. Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
  96. List<String> markets = Arrays.asList(StringUtils.split(admin.getMarkets(), ","));
  97. refundUser.setMarkets(markets);
  98. }
  99. Gold gold = refundService.statsGold(refundUser);
  100. return Result.success(gold);
  101. } catch (Exception e) {
  102. return Result.error("请检查数据的格式");
  103. }
  104. }
  105. //获取退款类型
  106. @Log("获取退款类型")
  107. @PostMapping("/refundType")
  108. public Result getRefundType() {
  109. List<String> list = refundService.getRefundType();
  110. return Result.success(list);
  111. }
  112. //筛选产品
  113. // @Log("筛选商品")
  114. @PostMapping("/selectGoods")
  115. public Result getSelectGoods(@RequestBody RefundUser refundUser) {
  116. List<RefundUser> list = refundService.selectGoods(refundUser);
  117. return Result.success(list);
  118. }
  119. //消耗金币增加
  120. @Log("新增金币消耗")
  121. @PostMapping("/add")
  122. public Result add(@RequestBody RefundUser refundUser) {
  123. try {
  124. return refundService.add(refundUser);
  125. } catch (Exception e) {
  126. return Result.error("请检查数据的格式");
  127. }
  128. }
  129. public Result selcet(@RequestBody Page page) {
  130. try {
  131. if (ObjectUtils.isEmpty(page.getPageNum())) {
  132. return Result.error("页码数为空!");
  133. }
  134. if (ObjectUtils.isEmpty(page.getPageSize())) {
  135. return Result.error("页大小为空!");
  136. } else {
  137. return Result.success(refundService.selectBy(page.getPageNum(), page.getPageSize(), page.getRefundUser()));
  138. }
  139. } catch (Exception e) {
  140. return Result.error("请检查筛选数据的格式");
  141. }
  142. }
  143. }