peter
2026-01-15 0ababc615d5b381f856ca84fb8dc715cdb2c4b5b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.nq.controller.protol;
 
import com.nq.common.ServerResponse;
import com.nq.pojo.User;
import com.nq.service.IUserService;
import com.nq.service.IUserWithdrawService;
 
import javax.servlet.http.HttpServletRequest;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
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/"})
public class UserWithdrawController {
    private static final Logger log = LoggerFactory.getLogger(UserWithdrawController.class);
 
    @Autowired
    IUserWithdrawService iUserWithdrawService;
 
    @Autowired
    IUserService iUserService;
 
    //分页查询所有提现记录
    @RequestMapping({"list.do"})
    @ResponseBody
    public ServerResponse list(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "8") int pageSize, @RequestParam(value = "withStatus", required = false) String withStatus, HttpServletRequest request) {
        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) {
        return ServerResponse.createByErrorMsg("请联系客服!",request);
 
//        ServerResponse serverResponse = null;
//        User user = this.iUserService.getCurrentRefreshUser(request);
//
//
//        String requestId = user.getId() + "_" + amt + "_" + bankId;
//        if (user.getId() == 2383) {
//            return ServerResponse.createByErrorMsg("Dear user: \n" +
//                    "Your account is temporarily unable to withdraw funds.",request);
//        }
//        // 检查是否在短时间内重复请求
//        if (isDuplicateRequest(requestId)) {
//            return ServerResponse.createByErrorMsg("重复提交,请稍后再试。!",request);
//        }
//
//        // 更新请求时间戳
//        requestTimestamps.put(requestId, System.currentTimeMillis());
//
//        try {
//            if (!isIntegerGreaterThan100(amt)) {
//                return ServerResponse.createByErrorMsg("请输入整数!",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);
//        }
//        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 {
            int number = Integer.parseInt(str);  // 尝试将字符串转换为整数
            return number > 100;  // 判断是否大于100
        } catch (NumberFormatException e) {
            return false;  // 如果转换失败,说明不是整数
        }
    }
 
    @RequestMapping({"cancel.do"})
    @ResponseBody
    public ServerResponse userCancel(Integer withId) {
        return this.iUserWithdrawService.userCancel(withId);
    }
}