From 9022a1683dee2eb8bf113abf301b36556b5fa873 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Mon, 25 Aug 2025 18:09:05 +0800
Subject: [PATCH] 代理新增充值

---
 src/main/java/com/nq/controller/backend/AdminWithDrawController.java |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/nq/controller/backend/AdminWithDrawController.java b/src/main/java/com/nq/controller/backend/AdminWithDrawController.java
index ca9655c..6a8d39a 100644
--- a/src/main/java/com/nq/controller/backend/AdminWithDrawController.java
+++ b/src/main/java/com/nq/controller/backend/AdminWithDrawController.java
@@ -4,7 +4,6 @@
 import cn.afterturn.easypoi.excel.entity.ExportParams;
 import com.github.pagehelper.PageInfo;
 import com.nq.common.ServerResponse;
-import com.nq.pojo.TradeResultVO;
 import com.nq.pojo.UserWithdraw;
 import com.nq.service.IUserWithdrawService;
 
@@ -23,6 +22,8 @@
 
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 @Controller
 @RequestMapping({"/admin/withdraw/"})
@@ -72,14 +73,33 @@
                                       HttpServletRequest request, HttpServletResponse response) {
         ServerResponse serverResponse = null;
         try {
-            serverResponse = this.iUserWithdrawService.updateState(withId, state, authMsg,request,response);
+            String requestId = withId + "_" + state;
+            // 检查是否在短时间内重复请求
+            if (isDuplicateRequest(requestId)) {
+                return ServerResponse.createByErrorMsg("重复提交,请稍后再试。");
+            }
+
+            // 更新请求时间戳
+            requestTimestamps.put(requestId, System.currentTimeMillis());
+            synchronized (withId){
+                serverResponse = this.iUserWithdrawService.updateState(withId, state, authMsg,request,response);
+            }
         } catch (Exception e) {
             log.error("admin修改充值订单状态出错 ,异常 = {}", e);
             return ServerResponse.createByErrorMsg("操作失败");
         }
         return serverResponse;
     }
-
+    private final Map<String, Long> requestTimestamps = new ConcurrentHashMap<>();
+    private static final long REPEAT_REQUEST_THRESHOLD = 1000;  // 5秒内重复提交视为无效请求
+    private boolean isDuplicateRequest(String requestId) {
+        Long lastRequestTime = requestTimestamps.get(requestId);
+        if (lastRequestTime == null) {
+            return false;  // 如果没有该请求记录,认为是首次请求
+        }
+        // 如果请求时间小于设定的时间窗口,则视为重复请求
+        return System.currentTimeMillis() - lastRequestTime < REPEAT_REQUEST_THRESHOLD;
+    }
 
     @RequestMapping({"deleteWithdraw.do"})
     @ResponseBody

--
Gitblit v1.9.3