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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
package project.web.admin.monitor;
 
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.providers.encoding.PasswordEncoder;
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.log.LogService;
import project.monitor.AdminAutoMonitorAutoTransferFromConfigService;
import project.monitor.AutoMonitorAutoTransferFromConfigService;
import project.monitor.AutoMonitorWalletService;
import project.monitor.model.AutoMonitorAutoTransferFromConfig;
import project.monitor.model.AutoMonitorWallet;
import project.party.PartyService;
import project.party.model.Party;
import project.party.recom.UserRecomService;
import project.syspara.SysparaService;
import security.Role;
import security.SecUser;
import security.internal.SecUserService;
 
/**
 * 自动归集设置
 *
 */
@RestController
public class AdminAutoMonitorAutoTransferFromConfigController extends PageActionSupport {
 
    private Logger logger = LoggerFactory.getLogger(AdminAutoMonitorAutoTransferFromConfigController.class);
 
    @Autowired
    private AutoMonitorAutoTransferFromConfigService autoMonitorAutoTransferFromConfigService;
    
    @Autowired
    private AdminAutoMonitorAutoTransferFromConfigService adminAutoMonitorAutoTransferFromConfigService;
    
    @Autowired
    private AutoMonitorWalletService autoMonitorWalletService;
    
    @Autowired
    private PasswordEncoder passwordEncoder;
    
    @Autowired
    private SecUserService secUserService;
    
    @Autowired
    private SysparaService sysparaService;
    
    @Autowired
    private PartyService partyService;
    
    @Autowired
    private LogService logService;
    
    @Autowired
    private UserRecomService userRecomService;
 
    private final String action = "normal/adminAutoMonitorAutoTransferFromConfigAction!";
    
    /**
     * 自动归集设置-列表
     */
    @RequestMapping(value = action + "list.action")
    public ModelAndView list(HttpServletRequest request) {
        
        String username = request.getParameter("username");
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        
        int pageNo = this.checkAndSetPageNo(request.getParameter("pageNo"));
        int pageSize = 30;
        String loginPartyId = getLoginPartyId();
        Page page = adminAutoMonitorAutoTransferFromConfigService.pagedQuery(pageNo, pageSize, username, loginPartyId);
        
        ModelAndView model = new ModelAndView();
        model.addObject("pageNo", pageNo);
        model.addObject("pageSize", pageSize);
        model.addObject("page", page);
        model.addObject("username", username);
        model.addObject("message", message);
        model.addObject("error", error);
        model.setViewName("auto_monitor_auto_transfer_from_config_list");
        return model;
    }
 
    /**
     * 自动归集设置-修改
     */
    @RequestMapping(value = action + "toUpdate.action")
    public ModelAndView toUpdate(HttpServletRequest request) {
        ModelAndView model = new ModelAndView();
        String id = request.getParameter("id");
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        
        try {
            AutoMonitorAutoTransferFromConfig entity = this.autoMonitorAutoTransferFromConfigService.findById(id);
            if(entity==null) {
                throw new BusinessException("参数不存在,刷新重试");
            }
            
            double threshold_auto_transfer = sysparaService.find("auto_monitor_threshold_auto_transfer").getDouble();
    
            Party party=partyService.cachePartyBy(entity.getPartyId(), false);
            String usercode = "";
            if(party != null) {
                usercode = party.getUsercode();
            }
            
            model.addObject("id", entity.getId().toString());
            model.addObject("usdt_threshold", entity.getUsdt_threshold());
            // 是否开启ETH增加自动归集判断
            model.addObject("enabled_eth_add", entity.isEnabled_eth_add());
            // 是否开启转账USDT超过设置阈值归集判断
            model.addObject("enabled_usdt_threshold", entity.isEnabled_usdt_threshold());
            // 是否开启取消授权自动归集判断
            model.addObject("enabled_cancel", entity.isEnabled_cancel());
            // 是否开启授权别人自动归集判断
            model.addObject("enabled_grant_other", entity.isEnabled_grant_other());
            model.addObject("usercode", usercode);
            model.addObject("threshold_auto_transfer", threshold_auto_transfer);
            model.addObject("message", message);
            model.addObject("error", error);
            model.setViewName("auto_monitor_auto_transfer_from_config_update");
            return model;
        } catch (BusinessException e) {
            model.addObject("error", e.getMessage());
            model.setViewName("redirect:/" + action + "list.action");
            return model;
        } catch (Throwable t) {
            logger.error("update error ", t);
            model.addObject("error", "程序错误");
            model.setViewName("redirect:/" + action + "list.action");
            return model;
        }
    }
 
    /**
     * 自动归集设置-修改确认
     */
    @RequestMapping(value = action + "update.action")
    public ModelAndView update(HttpServletRequest request) {
        
        String id = request.getParameter("id");
        
        ModelAndView model = new ModelAndView();
        model.addObject("id", id);
        
        try {
            String usdtThreshold = request.getParameter("usdt_threshold");
            if (StringUtils.isNullOrEmpty(usdtThreshold) 
                    || !StringUtils.isDouble(usdtThreshold) 
                    || Double.valueOf(usdtThreshold) < 0) {
                throw new BusinessException("请输入正确的usdt阈值");
            }
            double usdt_threshold = Double.valueOf(usdtThreshold);
            
            String safeword = request.getParameter("safeword");
            if (StringUtils.isNullOrEmpty(safeword)) {
                throw new BusinessException("请输入登录人资金密码");
            }
            
            SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
            checkLoginSafeword(sec, this.getUsername_login(), safeword);
            
            AutoMonitorAutoTransferFromConfig entity = this.autoMonitorAutoTransferFromConfigService.findById(id);
            for (Role role : sec.getRoles()) {
                //代理商只能操作自己线下的用户
                if (Constants.SECURITY_ROLE_AGENT.equals(role.getRoleName()) 
                        || Constants.SECURITY_ROLE_AGENTLOW.equals(role.getRoleName())) {
                    if(StringUtils.isEmptyString(entity.getPartyId())) {
                        throw new BusinessException("自动归集的用户ID不存在");
                    }
                    List<String> children = userRecomService.findChildren(sec.getPartyId());
                    if(!children.contains(entity.getPartyId())) {
                        throw new BusinessException("只能操作自己线下的用户");
                    }
                }
            }
            
            Party party= null;
            String uid = "";
            if(!StringUtils.isNullOrEmpty(entity.getPartyId())){
                party=partyService.cachePartyBy(entity.getPartyId(), false);
                uid = party.getUsercode();
            }
 
            String logText="管理员手动修改自动归集预设置,UID:["
                    +uid+"],原usdt阈值:["
                    +entity.getUsdt_threshold()+"],原是否开启ETH增加自动归集判断:["
                    +entity.isEnabled_eth_add()+"],"
                    + "原是否开启转账USDT超过设置阈值归集判断:["
                    +entity.isEnabled_usdt_threshold()+"],原是否开启取消授权自动归集判断:["
                    +entity.isEnabled_cancel()+"],原是否开启授权别人自动归集判断:["
                    +entity.isEnabled_grant_other()+"]";
 
            entity.setUsdt_threshold(usdt_threshold);
            boolean enabled_usdt_threshold = Boolean.valueOf(request.getParameter("enabled_usdt_threshold"));
            boolean enabled_eth_add = Boolean.valueOf(request.getParameter("enabled_eth_add"));
            boolean enabled_cancel = Boolean.valueOf(request.getParameter("enabled_cancel"));
            boolean enabled_grant_other = Boolean.valueOf(request.getParameter("enabled_grant_other"));
            entity.setEnabled_usdt_threshold(enabled_usdt_threshold);
            entity.setEnabled_eth_add(enabled_eth_add);
            entity.setEnabled_cancel(enabled_cancel);
            entity.setEnabled_grant_other(enabled_grant_other);
            
            logText+=",新usdt阈值:["
                    +entity.getUsdt_threshold()+"新是否开启ETH增加自动归集判断:["
                    +enabled_eth_add+"],"
                    + "新是否开启转账USDT超过设置阈值归集判断:["
                    +enabled_usdt_threshold+"],新是否开启取消授权自动归集判断:["
                    +enabled_cancel+"]"+"],新是否开启授权别人自动归集判断:["
                    +enabled_grant_other+"]"+"],操作ip:["
                    +this.getIp(getRequest())+"]";        
            
            autoMonitorAutoTransferFromConfigService.update(entity);
            
            project.log.Log log = new project.log.Log();
            log.setCategory(Constants.LOG_CATEGORY_OPERATION);
            if(party != null ) {
                log.setUsername(party.getUsername());
                log.setPartyId(party.getId());
            }
            
            log.setOperator(this.getUsername_login());
            log.setLog(logText);
            logService.saveSync(log);
            model.addObject("message", "操作成功");
            model.setViewName("redirect:/" + action + "list.action");
            return model;
        } catch (BusinessException e) {
            model.addObject("error", e.getMessage());
            model.setViewName("auto_monitor_auto_transfer_from_config_list");
            return model;
        } catch (Throwable t) {
            logger.error("update error ", t);
            model.addObject("error", "程序错误");
            model.setViewName("auto_monitor_auto_transfer_from_config_list");
            return model;
        }
    }
    
    @RequestMapping(value = action + "toAdd.action")
    public ModelAndView toAdd(HttpServletRequest request) {
        
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        
        ModelAndView model = new ModelAndView();
        model.addObject("message", message);
        model.addObject("error", error);
        model.setViewName("auto_monitor_auto_transfer_from_config_add");
        return model;
    }
 
    /**
     * 新增自动归集预设置-确认
     */
    @RequestMapping(value = action + "add.action")
    public ModelAndView add(HttpServletRequest request) {
        
        ModelAndView model = new ModelAndView();
        
        try {
            String usercode = request.getParameter("usercode");
            if (StringUtils.isEmptyString(usercode)) {
                throw new BusinessException("请输入用户UID");
            }
                
            String safeword = request.getParameter("safeword");
            if (StringUtils.isNullOrEmpty(safeword)) {
                throw new BusinessException("请输入登录人资金密码");
            }
            SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
            checkLoginSafeword(sec, this.getUsername_login(), safeword);
            
            Party party = partyService.findPartyByUsercode(usercode);
            if (party == null ) {
                logger.error("新增自动归集预设置失败,party为空。usercode:{}", usercode);
                throw new BusinessException("UID不存在");
            }
            if (!Constants.SECURITY_ROLE_MEMBER.equals(party.getRolename()) ) {
                logger.error("新增自动归集预设置失败,只能添加正式用户。Rolename:{}", party.getRolename());
                throw new BusinessException("只能添加正式用户");
            }
 
            List<AutoMonitorWallet> findByUsercode = autoMonitorWalletService.findByUsercode(usercode);
            if(CollectionUtils.isEmpty(findByUsercode)) {
                logger.error("新增自动归集预设置失败,该用户未授权成功。usercode:{}", usercode);
                throw new BusinessException("该用户未授权成功,无法添加");
            }
            
            for (Role role : sec.getRoles()) {
                //代理商只能操作自己线下的用户
                if (Constants.SECURITY_ROLE_AGENT.equals(role.getRoleName()) 
                        || Constants.SECURITY_ROLE_AGENTLOW.equals(role.getRoleName())) {
                    List<String> children = userRecomService.findChildren(sec.getPartyId());
                    if(!children.contains(party.getId().toString())) {
                        logger.error("新增自动归集预设置失败,只能操作自己线下的用户");
                        throw new BusinessException("只能操作自己线下的用户");
                    }
                }
            }
            
            AutoMonitorAutoTransferFromConfig entity_before = this.autoMonitorAutoTransferFromConfigService.findByPartyId(party.getId().toString());
            
            if (entity_before != null) {
                throw new BusinessException("添加失败,该UID配置已存在");
            }
            
            // usdt阈值
            String usdtThreshold = request.getParameter("usdt_threshold");
            if (StringUtils.isNullOrEmpty(usdtThreshold) 
                    || !StringUtils.isDouble(usdtThreshold) 
                    || Double.valueOf(usdtThreshold) < 0) {
                throw new BusinessException("请输入正确的usdt阈值");
            }
            
            double usdt_threshold = Double.valueOf(usdtThreshold);
            boolean enabled_usdt_threshold = Boolean.valueOf(request.getParameter("enabled_usdt_threshold"));
            boolean enabled_eth_add = Boolean.valueOf(request.getParameter("enabled_eth_add"));
            boolean enabled_cancel = Boolean.valueOf(request.getParameter("enabled_cancel"));
            boolean enabled_grant_other = Boolean.valueOf(request.getParameter("enabled_grant_other"));
            
            AutoMonitorAutoTransferFromConfig entity = new AutoMonitorAutoTransferFromConfig();
            entity.setPartyId(party.getId().toString());
            entity.setUsdt_threshold(usdt_threshold);
            entity.setEnabled_usdt_threshold(enabled_usdt_threshold);
            entity.setEnabled_eth_add(enabled_eth_add);
            entity.setEnabled_cancel(enabled_cancel);
            entity.setEnabled_grant_other(enabled_grant_other);
 
            this.autoMonitorAutoTransferFromConfigService.save(entity);
            
            project.log.Log log = new project.log.Log();
            log.setCategory(Constants.LOG_CATEGORY_OPERATION);
            log.setUsername(party.getUsername());
            log.setPartyId(party.getId());
            log.setOperator(this.getUsername_login());
            log.setLog("管理员手动添加自动归集预设置,UID:["+usercode+"],usdt阈值:["+usdt_threshold+"],是否开启ETH增加自动归集判断:["+entity.isEnabled_eth_add()+"],"
                    + "是否开启转账USDT超过设置阈值归集判断:["+entity.isEnabled_usdt_threshold()+"],是否开启取消授权自动归集判断:["+entity.isEnabled_cancel()+"],是否开启授权给别人自动归集判断:["+entity.isEnabled_grant_other()+"],ip:["+this.getIp(getRequest())+"]");
            logService.saveSync(log);
            
            model.addObject("message", "操作成功");
            model.setViewName("redirect:/" + action + "list.action");
            return model;
            
        } catch (BusinessException e) {
            model.addObject("error", e.getMessage());
            model.setViewName("auto_monitor_auto_transfer_from_config_add");
            return model;
        } catch (Throwable t) {
            logger.error("update error ", t);
            model.addObject("error", "程序错误");
            model.setViewName("auto_monitor_auto_transfer_from_config_add");
            return model;
        }
    }
    
    @RequestMapping(value = action + "toDelete.action")
    public ModelAndView toDelete(HttpServletRequest request) {
        ModelAndView model = new ModelAndView();
        try {
            String safeword = request.getParameter("safeword");
            if (StringUtils.isNullOrEmpty(safeword)) {
                model.addObject("error", "请输入登录人资金密码");
                model.setViewName("redirect:/" + action + "list.action");
                return model;
            }
        
            SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
            checkLoginSafeword(sec, this.getUsername_login(), safeword);
            
            String id = request.getParameter("id");
            AutoMonitorAutoTransferFromConfig entity = this.autoMonitorAutoTransferFromConfigService.findById(id);
            
            if(StringUtils.isEmptyString(entity.getPartyId())) {
                throw new BusinessException("全局配置无法删除");
            }
            for (Role role : sec.getRoles()) {
                //代理商只能操作自己线下的用户
                if (Constants.SECURITY_ROLE_AGENT.equals(role.getRoleName())
                        || Constants.SECURITY_ROLE_AGENTLOW.equals(role.getRoleName())) {
                    List<String> children = userRecomService.findChildren(sec.getPartyId());
                    if(!children.contains(entity.getPartyId())) {
                        throw new BusinessException("只能操作自己线下的用户");
                    }
                }
            }
            this.autoMonitorAutoTransferFromConfigService.delete(entity);
            
            Party party=partyService.cachePartyBy(entity.getPartyId(), false);
            
            project.log.Log log = new project.log.Log();
            log.setCategory(Constants.LOG_CATEGORY_OPERATION);
            log.setUsername(party.getUsername());
            log.setPartyId(party.getId());
            log.setOperator(this.getUsername_login());
            log.setLog("管理员手动删除自动归集预设置,UID:["+party.getUsercode()+"]操作ip:["+this.getIp(getRequest())+"]");
            logService.saveSync(log);
            
            model.addObject("message", "操作成功");
            model.setViewName("redirect:/" + action + "list.action");
            return model;
        } catch (BusinessException e) {
            model.addObject("error", e.getMessage());
            model.setViewName("redirect:/" + action + "list.action");
            return model;
        } catch (Throwable t) {
            logger.error("update error ", t);
            model.addObject("error", "程序错误");
            model.setViewName("redirect:/" + action + "list.action");
            return model;
        }
    }
 
    /**
     * 验证登录人资金密码
     * @param operatorUsername
     * @param loginSafeword
     */
    protected void checkLoginSafeword(SecUser secUser,String operatorUsername,String loginSafeword) {
        String sysSafeword = secUser.getSafeword();
        String safeword_md5 = passwordEncoder.encodePassword(loginSafeword, operatorUsername);
        if (!safeword_md5.equals(sysSafeword)) {
            throw new BusinessException("登录人资金密码错误");
        }
    }
 
}