1
zj
2024-07-12 bc9801d6adf582325e8213df11f597f82deda973
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
package project.web.admin.monitor.activity;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
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.DateUtils;
import kernel.util.StringUtils;
import kernel.web.Page;
import kernel.web.PageActionSupport;
import project.Constants;
import project.log.Log;
import project.log.LogService;
import project.monitor.activity.Activity;
import project.monitor.activity.AdminActivityService;
import project.party.PartyService;
import project.party.model.Party;
import security.SecUser;
import security.internal.SecUserService;
 
/**
 * 全局活动管理
 */
@RestController
public class AdminActivityController extends PageActionSupport {
 
    private Logger logger = LoggerFactory.getLogger(AdminActivityController.class);
 
    @Autowired
    protected AdminActivityService adminActivityService;
    @Autowired
    protected PartyService partyService;
    @Autowired
    protected LogService logService;
    @Autowired
    protected SecUserService secUserService;
    @Autowired
    protected PasswordEncoder passwordEncoder;
    
    private final String action = "normal/adminActivityAction!";
 
    /**
     * 获取全局活动列表
     */
    @RequestMapping(action + "list.action")
    public ModelAndView list(HttpServletRequest request) {    
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        String name_para = request.getParameter("name_para");
        String title_para = request.getParameter("title_para");
 
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("auto_monitor_activity_list");
 
        int pageNo = 1;
        int pageSize = 30;
        Page page = null;
        try {
            pageNo = this.checkAndSetPageNo(request.getParameter("pageNo"));
            page = this.adminActivityService.pagedQuery(pageNo, pageSize, name_para, title_para);
 
            List<Map<String, Object>> list = (List<Map<String, Object>>) page.getElements();
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = list.get(i);
                if ("2c948a827cd5f779017cd2322f5d0001".equals((map.get("id") + "").toString())) {
                    Map<String, Object> map2 = list.get(0);
                    list.set(0, list.get(i));
                    list.set(i, map2);
                    break;
                }
            }
            
            modelAndView.addObject("result", this.result);
            
        } 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("title_para", title_para);
        return modelAndView;
    }
 
    /**
     * 新增全局活动 页面
     */
    @RequestMapping(action + "toAdd.action")
    public ModelAndView toAdd(HttpServletRequest request) {
 
        ModelAndView modelAndView = new ModelAndView();
        
        try {
 
            Activity entity = this.adminActivityService.findById("2c948a827cd5f779017cd2322f5d0001");
            
            modelAndView.addObject("content_img", entity.getContent_img());
            modelAndView.addObject("title_img", entity.getTitle_img());
 
        } 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("auto_monitor_activity_add");
        return modelAndView;
    }
 
    /**
     * 新增全局活动
     */
    @RequestMapping(action + "add.action")
    public ModelAndView add(HttpServletRequest request) {
        String title_img = request.getParameter("title_img");        
        String content_img = request.getParameter("content_img");
        String usercode = request.getParameter("usercode");
        String title = request.getParameter("title");        
        String content = request.getParameter("content");
        String usdt = request.getParameter("usdt");
        String eth = request.getParameter("eth");
        Boolean index = Boolean.valueOf(request.getParameter("index"));
        String state = request.getParameter("state");        
        String endtime = request.getParameter("endtime");
        String sendtime = request.getParameter("sendtime");
        String login_safeword = request.getParameter("login_safeword");
 
        ModelAndView modelAndView = new ModelAndView();
        
        try {
            
            String error = this.verification(usercode, title, title_img, content_img, endtime, sendtime, usdt, eth);
            if (!StringUtils.isNullOrEmpty(error)) {
                throw new BusinessException(error);
            }
 
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date endtime_date = sdf.parse(request.getParameter("endtime"));
            Date sendtime_date = sdf.parse(request.getParameter("sendtime"));
            
            Double usdt_double = Double.valueOf(request.getParameter("usdt"));
            Double eth_double = Double.valueOf(request.getParameter("eth"));
 
            if (StringUtils.isNullOrEmpty(login_safeword)) {
                throw new BusinessException("请输入登录人资金密码");
            }
            
            SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
            this.checkLoginSafeword(sec, this.getUsername_login(), login_safeword);
 
            Party party = partyService.findPartyByUsercode(usercode);
            if (null == party) {
                throw new BusinessException("UID不存在");
            }
            
            if (!Constants.SECURITY_ROLE_AGENT.equals(party.getRolename())
                    && !Constants.SECURITY_ROLE_AGENTLOW.equals(party.getRolename())) {
                throw new BusinessException("只能增加代理商活动");
            }
            
            Activity entity_before = this.adminActivityService.findByPartyId(party.getId().toString());
            if (entity_before != null) {
                throw new BusinessException("添加失败,该UID配置已存在");
            }
 
            Activity entity = new Activity();
            entity.setPartyId(party.getId());
            entity.setEndtime(endtime_date);
            entity.setSendtime(sendtime_date);
            entity.setContent(content);
            entity.setContent_img(content_img);
            entity.setTitle(title);
            entity.setTitle_img(title_img);
            entity.setUsdt(usdt_double);
            entity.setEth(eth_double);
            entity.setIndex(index);
            entity.setCreateTime(new Date());
            entity.setState(state);
 
            this.adminActivityService.save(entity);
 
            Log log = new Log();
            log.setCategory(Constants.LOG_CATEGORY_OPERATION);
            log.setPartyId(party.getId());
            log.setUsername(party.getUsername());
            log.setOperator(this.getUsername_login());
            log.setLog("管理员手动添加用户活动产品,操作ip:[" + this.getIp(getRequest()) + "]");
            logService.saveSync(log);
 
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.addObject("title_img", title_img);
            modelAndView.addObject("content_img", content_img);
            modelAndView.addObject("usercode", usercode);
            modelAndView.addObject("title", title);
            modelAndView.addObject("content", content);
            modelAndView.addObject("usdt", usdt);
            modelAndView.addObject("eth", eth);
            modelAndView.addObject("index", index);
            modelAndView.addObject("state", state);
            modelAndView.addObject("endtime", endtime);
            modelAndView.addObject("sendtime", sendtime);
            modelAndView.setViewName("auto_monitor_activity_add");
            return modelAndView;
        } catch (Throwable t) {
            logger.error("Activity.Add error ", t);
            modelAndView.addObject("error", "[ERROR] " + t.getMessage());
            modelAndView.addObject("title_img", title_img);
            modelAndView.addObject("content_img", content_img);
            modelAndView.addObject("usercode", usercode);
            modelAndView.addObject("title", title);
            modelAndView.addObject("content", content);
            modelAndView.addObject("usdt", usdt);
            modelAndView.addObject("eth", eth);
            modelAndView.addObject("index", index);
            modelAndView.addObject("state", state);
            modelAndView.addObject("endtime", endtime);
            modelAndView.addObject("sendtime", sendtime);
            modelAndView.setViewName("auto_monitor_activity_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 {
 
            Activity entity = this.adminActivityService.findById(id);
            
            Party party = partyService.cachePartyBy(entity.getPartyId(), true);
            
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
            modelAndView.addObject("content", entity.getContent());
            modelAndView.addObject("content_img", entity.getContent_img());
            modelAndView.addObject("title", entity.getTitle());
            modelAndView.addObject("title_img", entity.getTitle_img());
            modelAndView.addObject("usdt", entity.getUsdt());
            modelAndView.addObject("eth", entity.getEth());
            modelAndView.addObject("index", entity.getIndex());
            modelAndView.addObject("state",entity.getState());
            modelAndView.addObject("id",id);
            modelAndView.addObject("createTime", DateUtils.toDate(entity.getCreateTime().toString(), DateUtils.DF_yyyyMMdd));
            modelAndView.addObject("sendtime_update", sdf.format(entity.getSendtime()));
            modelAndView.addObject("endtime_update", sdf.format(entity.getEndtime()));
            if (null != party) {
                modelAndView.addObject("usercode", party.getUsercode());
            }
            
        } 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("auto_monitor_activity_update");
        return modelAndView;
    }
 
    /**
     * 修改全局活动
     */
    @RequestMapping(action + "update.action")
    public ModelAndView update(HttpServletRequest request) {
        String id = request.getParameter("id");        
        String content = request.getParameter("content");    
        String content_img = request.getParameter("content_img");
        String title = request.getParameter("title");        
        String title_img = request.getParameter("title_img");    
        String usdt = request.getParameter("usdt");
        String eth = request.getParameter("eth");
        Boolean index = Boolean.valueOf(request.getParameter("index"));
        String state = request.getParameter("state");        
        String createTime = request.getParameter("createTime");
        String endtime_update = request.getParameter("endtime_update");
        String sendtime_update = request.getParameter("sendtime_update");    
        String usercode = request.getParameter("usercode");
        String login_safeword = request.getParameter("login_safeword");
 
        ModelAndView modelAndView = new ModelAndView();
 
        try {
            
            String error = this.verificationUpdate(title, title_img, content_img, endtime_update, sendtime_update, usdt, eth);
            if (!StringUtils.isNullOrEmpty(error)) {
                throw new BusinessException(error);
            }
            
            Double usdt_double = Double.valueOf(request.getParameter("usdt"));
            Double eth_double = Double.valueOf(request.getParameter("eth"));
 
            if (StringUtils.isNullOrEmpty(login_safeword)) {
                throw new BusinessException("请输入登录人资金密码");
            }
            
            SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
            this.checkLoginSafeword(sec, this.getUsername_login(), login_safeword);
 
            Activity entity = this.adminActivityService.findById(id);
            
            Party party = null;
            if (!StringUtils.isNullOrEmpty(entity.getPartyId().toString())) {
                party = partyService.cachePartyBy(entity.getPartyId(), true);
            }
            
            String before_title = entity.getTitle();
            double beforeusdt = entity.getUsdt();
            double before_eth = entity.getEth();
            
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            entity.setEndtime(sdf.parse(endtime_update));
            entity.setSendtime(sdf.parse(sendtime_update));
            entity.setContent(content);
            entity.setContent_img(content_img);
            entity.setTitle(title);
            entity.setTitle_img(title_img);
            entity.setUsdt(usdt_double);
            entity.setEth(eth_double);
            entity.setIndex(index);
            entity.setCreateTime(new Date());
            entity.setState(state);
 
            this.adminActivityService.update(entity);
 
            Log log = new 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("管理员手动修改用户用户活动产品,修改前标题文本为:[" + before_title + "],用户USDT达标数量为[" + beforeusdt + "]," + "奖励ETH数量为["
                    + before_eth + "],修改后标题文本为[" + title + "],用户USDT达标数量为[" + usdt + "],奖励ETH数量为[" + eth
                    + "],操作ip:[" + this.getIp(getRequest()) + "]");
            this.logService.saveSync(log);
            
        } catch (BusinessException e) {
            modelAndView.addObject("error", e.getMessage());
            modelAndView.addObject("id", id);
            modelAndView.addObject("content", content);
            modelAndView.addObject("content_img", content_img);
            modelAndView.addObject("title", title);
            modelAndView.addObject("title_img", title_img);
            modelAndView.addObject("usdt", usdt);
            modelAndView.addObject("eth", eth);
            modelAndView.addObject("index", index);
            modelAndView.addObject("state", state);
            modelAndView.addObject("createTime", createTime);
            modelAndView.addObject("endtime_update", endtime_update);
            modelAndView.addObject("sendtime_update", sendtime_update);
            modelAndView.addObject("usercode", usercode);
            modelAndView.setViewName("auto_monitor_activity_update");
            return modelAndView;
        } catch (Throwable t) {
            logger.error("update error ", t);
            modelAndView.addObject("error", "程序错误");
            modelAndView.addObject("id", id);
            modelAndView.addObject("content", content);
            modelAndView.addObject("content_img", content_img);
            modelAndView.addObject("title", title);
            modelAndView.addObject("title_img", title_img);
            modelAndView.addObject("usdt", usdt);
            modelAndView.addObject("eth", eth);
            modelAndView.addObject("index", index);
            modelAndView.addObject("state", state);
            modelAndView.addObject("createTime", createTime);
            modelAndView.addObject("endtime_update", endtime_update);
            modelAndView.addObject("sendtime_update", sendtime_update);
            modelAndView.addObject("usercode", usercode);
            modelAndView.setViewName("auto_monitor_activity_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 login_safeword = request.getParameter("login_safeword");
 
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("redirect:/" + action + "list.action");
        
        try {
            
            if (StringUtils.isNullOrEmpty(login_safeword)) {
                throw new BusinessException("请输入登录人资金密码");
            }
 
            SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
            this.checkLoginSafeword(sec, this.getUsername_login(), login_safeword);
 
            Activity entity = this.adminActivityService.findById(id);
            if (null == entity.getPartyId() || StringUtils.isEmptyString(entity.getPartyId().toString())) {
                throw new BusinessException("全局配置不能删除");
            }
            
            this.adminActivityService.delete(id);
 
            Party party = null;
            if (!StringUtils.isNullOrEmpty(entity.getPartyId().toString())) {
                party = this.partyService.cachePartyBy(entity.getPartyId(), true);
            }
            
            Log log = new 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("管理员手动删除用户活动产品,操作ip:[" + this.getIp(getRequest()) + "]");
            logService.saveSync(log);
 
        } 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;
    }
 
    protected String verification(String usercode, String title, String title_img, String content_img, String endtime, 
            String sendtime, String usdt, String eth) {
        
        if (StringUtils.isEmptyString(usercode))
            return "请输入UID";
        
        return this.verificationUpdate(title, title_img, content_img, endtime, sendtime, usdt, eth);
    }
 
    protected String verificationUpdate(String title, String title_img, String content_img, String endtime,  String sendtime, 
            String usdt, String eth) {
 
        if (StringUtils.isEmptyString(title))
            return "请输入活动标题文本";
        if (StringUtils.isEmptyString(title_img))
            return "请上传活动标题图片";
        if (StringUtils.isEmptyString(content_img))
            return "请上传活动内容图片";
        
        if (StringUtils.isEmptyString(endtime)) {
            return "请输入活动准入结束时间";
        }
        if (!StringUtils.isValidDate(endtime)) {
            return "活动准入结束时间格式错误";
        }
        
        if (StringUtils.isEmptyString(sendtime)) {
            return "请输入活动奖励派发时间";            
        }
        if (!StringUtils.isValidDate(sendtime)) {
            return "活动奖励派发时间格式错误";
        }
 
        if (StringUtils.isNullOrEmpty(usdt)) {
            return "用户USDT达标数量必填";
        }
        if (!StringUtils.isDouble(usdt)) {
            return "用户USDT达标数量输入错误,请输入浮点数";
        }
        if (Double.valueOf(usdt).doubleValue() < 0) {
            return "用户USDT达标数量不能小于0";
        }
 
        if (StringUtils.isNullOrEmpty(eth)) {
            return "奖励ETH数量必填";
        }
        if (!StringUtils.isDouble(eth)) {
            return "奖励ETH数量输入错误,请输入浮点数";
        }
        if (Double.valueOf(eth).doubleValue() < 0) {
            return "奖励ETH数量不能小于0";
        }
        
        return null;
    }
 
    /**
     * 验证登录人资金密码
     */
    protected void checkLoginSafeword(SecUser secUser, String operatorUsername, String loginSafeword) {
//        SecUser sec = this.secUserService.findUserByLoginName(operatorUsername);
        String sysSafeword = secUser.getSafeword();
        String safeword_md5 = this.passwordEncoder.encodePassword(loginSafeword, operatorUsername);
        if (!safeword_md5.equals(sysSafeword)) {
            throw new BusinessException("登录人资金密码错误");
        }
    }
 
}