zj
2025-02-17 76bc979b654c23be393c9c46c9e3099cdd3785ec
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
package project.web.admin;
 
import javax.servlet.http.HttpServletRequest;
 
import kernel.web.ResultObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
 
import kernel.exception.BusinessException;
import kernel.util.StringUtils;
import kernel.web.Page;
import kernel.web.PageActionSupport;
import project.Constants;
import project.blockchain.AdminChannelBlockchainService;
import project.blockchain.ChannelBlockchain;
import project.blockchain.ChannelBlockchainService;
import project.blockchain.QRProducerService;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * 区块链充值地址维护
 */
@RestController
public class AdminChannelBlockchainController extends PageActionSupport {
 
    @Autowired
    private QRProducerService qRProducerService;
 
    @Autowired
    private ChannelBlockchainService channelBlockchainService;
 
    @Autowired
    private AdminChannelBlockchainService adminChannelBlockchainService;
 
    private final String action = "normal/adminChannelBlockchainAction!";
 
    private Logger logger = LoggerFactory.getLogger(AdminChannelBlockchainController.class);
 
    /**
     * 获取 区块链充值地址 列表
     *
     * name_para 链名称
     * coin_para 币种名称
     */
    @RequestMapping(action + "list.action")
    public ModelAndView list(HttpServletRequest request) {
        String pageNoStr = request.getParameter("pageNo");
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        String name_para = request.getParameter("name_para");
        String coin_para = request.getParameter("coin_para");
 
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("channel_blockchain_list");
 
        int pageNo=1;
        Page page=null;
        int pageSize=300;
        try {
            pageNo=checkAndSetPageNo(pageNoStr);
            page = this.adminChannelBlockchainService.pagedQuery(pageNo, pageSize, name_para, coin_para);
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            return modelAndView;
        }
 
        modelAndView.addObject("pageNo", pageNo);
        modelAndView.addObject("pageSize", pageSize);
        modelAndView.addObject("page", page);
        modelAndView.addObject("message", message);
        modelAndView.addObject("error", error);
        modelAndView.addObject("name_para", name_para);
        modelAndView.addObject("coin_para", coin_para);
        return modelAndView;
    }
 
    @RequestMapping(action + "appList")
    public Object apiList(HttpServletRequest request) {
        String pageNoStr = request.getParameter("pageNo");
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        String name_para = request.getParameter("name_para");
        String coin_para = request.getParameter("coin_para");
 
        ResultObject resultObject = new ResultObject();
 
        int pageNo=1;
        Page page=null;
        int pageSize=300;
        try {
            pageNo=checkAndSetPageNo(pageNoStr);
            page = this.adminChannelBlockchainService.pagedQuery(pageNo, pageSize, name_para, coin_para);
        } catch (BusinessException e) {
            logger.error(" error ", e);
            resultObject.setCode("1");
            resultObject.setMsg(e.getMessage());
            return resultObject;
        } catch (Throwable t) {
            logger.error(" error ", t);
            resultObject.setCode("1");
            resultObject.setMsg( t.getMessage());
            return resultObject;
        }
        Map<String,Object> map = new HashMap<>();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("page", page);
        map.put("message", message);
        map.put("error", error);
        map.put("name_para", name_para);
        map.put("coin_para", coin_para);
        resultObject.setData(map);
        return resultObject;
    }
 
    /**
     * 新增 区块链充值地址 页面
     */
    @RequestMapping(action + "toAdd.action")
    public ModelAndView toAdd(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("coins_map", Constants.BLOCKCHAIN_COINS);
        modelAndView.addObject("blockchain_name_map", Constants.BLOCKCHAIN_COINS_NAME);
        modelAndView.setViewName("channel_blockchain_add");
        return modelAndView;
    }
 
    /**
     * 新增 区块链充值地址
     *
     * blockchain_name 链名称
     * coin 币种 BTC USDT ETH
     * address 充值地址
     * img 充值地址二维码
     */
    //@RequestMapping(action + "add.action")
    public ModelAndView add(HttpServletRequest request) {
        String blockchain_name = request.getParameter("blockchain_name");
        String coin = request.getParameter("coin");
        String address = request.getParameter("address");
        String img = request.getParameter("img");
        String safeword = request.getParameter("safeword");
        String email_code = request.getParameter("email_code");
        String super_google_auth_code = request.getParameter("super_google_auth_code");
 
        ModelAndView modelAndView = new ModelAndView();
 
        try {
            String error = this.verif(blockchain_name, coin, address, img);
            if (!StringUtils.isNullOrEmpty(error)) {
                throw new BusinessException(error);
            }
 
            ChannelBlockchain channelBlockchain = new ChannelBlockchain();
            channelBlockchain.setBlockchain_name(blockchain_name);
            channelBlockchain.setCoin(coin);
            channelBlockchain.setAddress(address);
            img = this.qRProducerService.generate(address);
            channelBlockchain.setImg(img);
 
            this.channelBlockchainService.save(channelBlockchain, this.getUsername_login(), safeword,
                    this.getIp(getRequest()), email_code, super_google_auth_code);
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.addObject("coins_map", Constants.BLOCKCHAIN_COINS);
            modelAndView.addObject("blockchain_name_map", Constants.BLOCKCHAIN_COINS_NAME);
            modelAndView.addObject("blockchain_name", blockchain_name);
            modelAndView.addObject("coin", coin);
            modelAndView.addObject("address", address);
            modelAndView.addObject("img", img);
            modelAndView.setViewName("channel_blockchain_add");
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            modelAndView.addObject("coins_map", Constants.BLOCKCHAIN_COINS);
            modelAndView.addObject("blockchain_name_map", Constants.BLOCKCHAIN_COINS_NAME);
            modelAndView.addObject("blockchain_name", blockchain_name);
            modelAndView.addObject("coin", coin);
            modelAndView.addObject("address", address);
            modelAndView.addObject("img", img);
            modelAndView.setViewName("channel_blockchain_add");
            return modelAndView;
        }
 
        modelAndView.addObject("message", "操作成功");
        modelAndView.setViewName("redirect:/" + action + "list.action");
        return modelAndView;
    }
 
    /**
     * 修改 区块链充值地址 页面
     */
    @RequestMapping(action + "toUpdate.action")
    public ModelAndView toUpdate(HttpServletRequest request) {
        String id = request.getParameter("id");
        ModelAndView modelAndView = new ModelAndView();
 
        try {
            ChannelBlockchain channelBlockchain = this.channelBlockchainService.findById(id);
            modelAndView.addObject("id", id);
            modelAndView.addObject("address", channelBlockchain.getAddress());
            modelAndView.addObject("coin", channelBlockchain.getCoin());
            modelAndView.addObject("blockchain_name", channelBlockchain.getBlockchain_name());
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            modelAndView.setViewName("redirect:/" + action + "list.action");
            return modelAndView;
        }
 
        modelAndView.setViewName("channel_blockchain_update");
        return modelAndView;
    }
 
    /**
     * 修改 区块链充值地址
     *
     * blockchain_name 链名称
     * coin 币种 BTC USDT ETH
     * address 充值地址
     * img 充值地址二维码
     */
    @RequestMapping(action + "update.action")
    public ModelAndView update(HttpServletRequest request) {
        String id = request.getParameter("id");
        String blockchain_name = request.getParameter("blockchain_name");
        String coin = request.getParameter("coin");
        String address = request.getParameter("address");
        String img = request.getParameter("img");
        String safeword = request.getParameter("safeword");
        String email_code = request.getParameter("email_code");
        String super_google_auth_code = request.getParameter("super_google_auth_code");
 
        ModelAndView modelAndView = new ModelAndView();
 
        try {
            ChannelBlockchain channelBlockchain = this.channelBlockchainService.findById(id);
            ChannelBlockchain old = new ChannelBlockchain();
            BeanUtils.copyProperties(channelBlockchain, old);
 
            String error = this.verif(blockchain_name, coin, address, img);
            if (!StringUtils.isNullOrEmpty(error)) {
                throw new BusinessException(error);
            }
 
            channelBlockchain.setBlockchain_name(blockchain_name);
            channelBlockchain.setCoin(coin);
            if (!address.equals(channelBlockchain.getAddress())) {
                channelBlockchain.setAddress(address);
                img = this.qRProducerService.generate(address);
                channelBlockchain.setImg(img);
            }
 
            this.channelBlockchainService.update(old, channelBlockchain, this.getUsername_login(),
                    this.getLoginPartyId(), safeword, this.getIp(getRequest()), email_code, super_google_auth_code);
 
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.addObject("id", id);
            modelAndView.addObject("blockchain_name", blockchain_name);
            modelAndView.addObject("coin", coin);
            modelAndView.addObject("address", address);
            modelAndView.addObject("img", img);
            modelAndView.setViewName("channel_blockchain_update");
            return modelAndView;
        } catch (Throwable t) {
            logger.error(" error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            modelAndView.addObject("id", id);
            modelAndView.addObject("blockchain_name", blockchain_name);
            modelAndView.addObject("coin", coin);
            modelAndView.addObject("address", address);
            modelAndView.addObject("img", img);
            modelAndView.setViewName("channel_blockchain_update");
            return modelAndView;
        }
 
        modelAndView.addObject("message", "操作成功");
        modelAndView.setViewName("redirect:/" + action + "list.action");
        return modelAndView;
    }
 
    /**
     * 删除 区块链充值地址
     */
    //@RequestMapping(action + "toDelete.action")
    public ModelAndView toDelete(HttpServletRequest request) {
        String id = request.getParameter("id");
        String safeword = request.getParameter("safeword");
        String email_code = request.getParameter("email_code");
        String super_google_auth_code = request.getParameter("super_google_auth_code");
 
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("redirect:/" + action + "list.action");
 
        try {
 
            this.channelBlockchainService.delete(id, safeword, this.getUsername_login(), this.getIp(), email_code, super_google_auth_code);
 
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            return modelAndView;
        } catch (Throwable t) {
            logger.error("update error ", t);
            modelAndView.addObject("error", "程序错误");
            return modelAndView;
        }
 
        modelAndView.addObject("message", "操作成功");
        return modelAndView;
    }
 
    private String verif(String blockchain_name, String coin, String address, String img) {
        if (StringUtils.isEmptyString(blockchain_name))
            return "请输入链名称";
        if (StringUtils.isEmptyString(coin))
            return "请输入币种";
        if (StringUtils.isEmptyString(address))
            return "请输入地址";
        return null;
    }
 
}