1
zj
2025-07-31 071c1c1f0b58ad266bd1cb016f9daf94c0b6367f
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
106
107
108
109
110
package com.nq.controller.backend;
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
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;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.poi.ss.usermodel.Workbook;
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.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
 
@Controller
@RequestMapping({"/admin/withdraw/"})
public class AdminWithDrawController {
    private static final Logger log = LoggerFactory.getLogger(AdminWithDrawController.class);
 
    @Autowired
    IUserWithdrawService iUserWithdrawService;
 
    //分页查询资金管理 提现列表信息及模糊查询
    @RequestMapping({"list.do"})
    @ResponseBody
    public ServerResponse<PageInfo> list(@RequestParam(value = "agentId", required = false) Integer agentId, @RequestParam(value = "userId", required = false) Integer userId, @RequestParam(value = "realName", required = false) String realName, @RequestParam(value = "state", required = false) Integer state, @RequestParam(value = "beginTime", required = false) String beginTime, @RequestParam(value = "endTime", required = false) String endTime, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, HttpServletRequest request) {
        return this.iUserWithdrawService.listByAdmin(agentId, userId, realName, state, beginTime, endTime, request, pageNum, pageSize);
    }
 
    //导出提现记录
    @RequestMapping({"export.do"})
    @ResponseBody
    public void export( @RequestParam(value = "agentId", required = false) Integer agentId, @RequestParam(value = "userId", required = false) Integer userId, @RequestParam(value = "realName", required = false) String realName, @RequestParam(value = "state", required = false) Integer state, @RequestParam(value = "beginTime", required = false) String beginTime, @RequestParam(value = "endTime", required = false) String endTime, HttpServletRequest request, HttpServletResponse response) {
        List<UserWithdraw> userRechargeList = this.iUserWithdrawService.exportByAdmin(agentId, userId, realName, state, beginTime, endTime, request);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("提现导出","提现数据"),
                UserWithdraw.class, userRechargeList);
        try {
            ServletOutputStream outputStream = response.getOutputStream();
            workbook.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {
            log.error("导出提现数据失败",e);
        }
    }
 
    /**
     *
     * @param withId
     * @param state 1.审核通过(走代付) 2.审核(不走代付) 3.驳回
     * @param authMsg
     * @return
     */
    //修改资金管理 提现列表 提现状态
    @RequestMapping({"updateState.do"})
    @ResponseBody
    public ServerResponse updateState(@RequestParam(value = "withId", required = false) Integer withId,
                                      @RequestParam(value = "state", required = false) Integer state,
                                      @RequestParam(value = "authMsg", required = false) String authMsg,
                                      HttpServletRequest request, HttpServletResponse response) {
        ServerResponse serverResponse = null;
        try {
            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
    public ServerResponse deleteWithdraw(Integer withdrawId) {
        return this.iUserWithdrawService.deleteWithdraw(withdrawId);
    }
}