1
zj
2025-04-30 9f804ae65d677a36f3c7330c5933bfa3229a2b10
1
2 files modified
56 ■■■■■ changed files
src/main/java/com/nq/controller/backend/AdminWithDrawController.java 25 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/controller/protol/UserWithdrawController.java 31 ●●●●● patch | view | raw | blame | history
src/main/java/com/nq/controller/backend/AdminWithDrawController.java
@@ -23,6 +23,8 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Controller
@RequestMapping({"/admin/withdraw/"})
@@ -72,14 +74,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
src/main/java/com/nq/controller/protol/UserWithdrawController.java
@@ -15,6 +15,9 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Controller
@RequestMapping({"/user/withdraw/"})
@@ -34,19 +37,36 @@
        return this.iUserWithdrawService.findUserWithList(withStatus, request, pageNum, pageSize);
    }
    private final Map<String, Long> requestTimestamps = new ConcurrentHashMap<>();
    private static final long REPEAT_REQUEST_THRESHOLD = 1000;  // 5秒内重复提交视为无效请求
    //用户提现
    @RequestMapping({"outMoney.do"})
    @ResponseBody
    public ServerResponse outMoney(@RequestParam(value = "amt") String amt,@RequestParam(value = "bankId") String bankId,
                                   @RequestParam(value = "assetsType") String accsetType,
                                   HttpServletRequest request) {
        ServerResponse serverResponse = null;
        User user = this.iUserService.getCurrentRefreshUser(request);
        String requestId = user.getId() + "_" + amt + "_" + bankId;
        // 检查是否在短时间内重复请求
        if (isDuplicateRequest(requestId)) {
            return ServerResponse.createByErrorMsg("重复提交,请稍后再试。!",request);
        }
        // 更新请求时间戳
        requestTimestamps.put(requestId, System.currentTimeMillis());
        try {
            if (!isIntegerGreaterThan100(amt)) {
                return ServerResponse.createByErrorMsg("请输入整数!",request);
            }
            serverResponse = this.iUserWithdrawService.outMoney(amt, user.getWithPwd(), accsetType,bankId,request);
            synchronized (user.getId()){
                serverResponse = this.iUserWithdrawService.outMoney(amt, user.getWithPwd(), accsetType,bankId,request);
            }
        } catch (Exception e) {
            log.error("出金异常 e = {}", e);
            serverResponse = ServerResponse.createByErrorMsg("提现异常,请稍后再试",request);
@@ -54,6 +74,15 @@
        return serverResponse;
    }
    private boolean isDuplicateRequest(String requestId) {
        Long lastRequestTime = requestTimestamps.get(requestId);
        if (lastRequestTime == null) {
            return false;  // 如果没有该请求记录,认为是首次请求
        }
        // 如果请求时间小于设定的时间窗口,则视为重复请求
        return System.currentTimeMillis() - lastRequestTime < REPEAT_REQUEST_THRESHOLD;
    }
    // 判断字符串是否是整数且大于100
    public static boolean isIntegerGreaterThan100(String str) {
        try {