liujie
16 小时以前 74f8b8074a2fb391b5363b4dca5f99bf31993430
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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
package com.stylefeng.guns.modular.system.controller.general;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.shiro.ShiroUser;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.DateUtil;
import com.stylefeng.guns.modular.system.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2020-06-17 20:51:18
 */
@Controller
@RequestMapping("/activity")
public class TActivityController extends BaseController {
 
    private String PREFIX = "/system/activity/";
 
    @Autowired
    private ITActivityService activityService;
    @Autowired
    private ITActivityAreaService activityAreaService;
    @Autowired
    private ITActivityCouponService activityCouponService;
    @Autowired
    private ITRegionService tRegionService;
    @Autowired
    private ITBranchOfficeAreaService branchOfficeAreaService;
    @Autowired
    private ITBranchOfficeService branchOfficeService;
    @Autowired
    private ITCouponService couponService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private ITUserToCouponService userToCouponService;
    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index(Model model) {
        // 查询当前帐号的省市区
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 1){
            List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>());
            if(CollectionUtils.isEmpty(branchOfficeAreaList)){
                model.addAttribute("branchOfficeAreaList",new ArrayList<>());
            }
            branchOfficeAreaList.forEach(item->{
                item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
            });
            model.addAttribute("branchOfficeAreaList",branchOfficeAreaList);
            model.addAttribute("roleType",roleType);
            return PREFIX + "activity.html";
        }else {
            TBranchOffice tBranchOffice = branchOfficeService.selectById(objectId);
            List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>()
                    .eq("branchOfficeId",tBranchOffice.getId()));
            if(CollectionUtils.isEmpty(branchOfficeAreaList)){
                model.addAttribute("branchOfficeAreaList",new ArrayList<>());
            }
            branchOfficeAreaList.forEach(item->{
                item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
            });
            model.addAttribute("roleType",roleType);
            model.addAttribute("branchOfficeAreaList",branchOfficeAreaList);
            return PREFIX + "activity_branchOffice.html";
        }
    }
 
    /**
     * 跳转到添加
     */
    @RequestMapping("/activity_add")
    public String activityAdd(Model model) {
        // 查询当前帐号的省市区
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 1){
            List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>());
            if(CollectionUtils.isEmpty(branchOfficeAreaList)){
                model.addAttribute("provinceList",new ArrayList<>());
            }
            branchOfficeAreaList.forEach(item->{
                item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
            });
            branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
                    new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
            model.addAttribute("provinceList",branchOfficeAreaList);
        }else {
            TBranchOffice tBranchOffice = branchOfficeService.selectById(objectId);
            List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>()
                    .eq("branchOfficeId",tBranchOffice.getId()));
            if(CollectionUtils.isEmpty(branchOfficeAreaList)){
                model.addAttribute("provinceList",new ArrayList<>());
            }
            branchOfficeAreaList.forEach(item->{
                item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
            });
            branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
                    new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
            model.addAttribute("provinceList",branchOfficeAreaList);
        }
        return PREFIX + "activity_add.html";
    }
    /**
     * 跳转到添加
     */
    @RequestMapping("/openAuditDetail/{id}")
    public String openAuditDetail(@PathVariable Integer id,Model model) {
        // 查询当前帐号的省市区
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 1){
            List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>());
            if(CollectionUtils.isEmpty(branchOfficeAreaList)){
                model.addAttribute("provinceList",new ArrayList<>());
            }
            branchOfficeAreaList.forEach(item->{
                item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
            });
            branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
                    new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
            model.addAttribute("provinceList",branchOfficeAreaList);
        }else {
            TBranchOffice tBranchOffice = branchOfficeService.selectById(objectId);
            List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>()
                    .eq("branchOfficeId",tBranchOffice.getId()));
            if(CollectionUtils.isEmpty(branchOfficeAreaList)){
                model.addAttribute("provinceList",new ArrayList<>());
            }
            branchOfficeAreaList.forEach(item->{
                item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
            });
            branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
                    new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
            model.addAttribute("provinceList",branchOfficeAreaList);
        }
        model.addAttribute("item",activityService.selectById(id));
        List<TActivityArea> branchOfficeAreaList = activityAreaService.selectList(new EntityWrapper<TActivityArea>().eq("activityId", id));
        model.addAttribute("scopeList",branchOfficeAreaList);
        // 查询优惠券信息
        List<TActivityCoupon> activityCoupons = activityCouponService.selectList(new EntityWrapper<TActivityCoupon>().eq("activityId", id));
        List<Integer> couponIds = activityCoupons.stream().map(TActivityCoupon::getCouponId).distinct().collect(Collectors.toList());
        if(!CollectionUtils.isEmpty(couponIds)){
            List<TCoupon> coupons = couponService.selectList(new EntityWrapper<TCoupon>().in("id", couponIds));
            for (TCoupon coupon : coupons) {
                TActivityCoupon tActivityCoupon = activityCoupons.stream().filter(e -> e.getCouponId().equals(coupon.getId())).findFirst().orElse(null);
                if(Objects.nonNull(tActivityCoupon) && Objects.nonNull(tActivityCoupon.getCreateTime())){
                    coupon.setCreateTimeStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tActivityCoupon.getCreateTime()));
                }
                switch (coupon.getCouponType()) {
                    case 1:
                        coupon.setCouponTypeStr("现金券");
                        break;
                    case 2:
                        coupon.setCouponTypeStr("新人券");
                        break;
                    case 3:
                        coupon.setCouponTypeStr("分享券");
                        break;
                    case 4:
                        coupon.setCouponTypeStr("消费优惠券");
                        break;
                    default:
                        coupon.setCouponTypeStr("充值优惠券");
                        break;
               }
                switch (coupon.getCouponServiceType()) {
                    case 1:
                        coupon.setCouponServiceTypeStr("通用型");
                        break;
                    default:
                        coupon.setCouponServiceTypeStr("通用型");
                        break;
                }
            }
            model.addAttribute("couponList",coupons);
        } else {
            model.addAttribute("couponList",new ArrayList<>());
        }
        return PREFIX + "audit_detail.html";
    }
    /**
     * 跳转到添加
     */
    @RequestMapping("/openDetail/{id}")
    public String openDetail(@PathVariable Integer id,Model model) {
        // 查询当前帐号的省市区
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 1){
            List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>());
            if(CollectionUtils.isEmpty(branchOfficeAreaList)){
                model.addAttribute("provinceList",new ArrayList<>());
            }
            branchOfficeAreaList.forEach(item->{
                item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
            });
            branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
                    new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
            model.addAttribute("provinceList",branchOfficeAreaList);
        }else {
            TBranchOffice tBranchOffice = branchOfficeService.selectById(objectId);
            List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>()
                    .eq("branchOfficeId",tBranchOffice.getId()));
            if(CollectionUtils.isEmpty(branchOfficeAreaList)){
                model.addAttribute("provinceList",new ArrayList<>());
            }
            branchOfficeAreaList.forEach(item->{
                item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
            });
            branchOfficeAreaList = branchOfficeAreaList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
                    new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getProvinceCode))),ArrayList::new));
            model.addAttribute("provinceList",branchOfficeAreaList);
        }
        TActivity tActivity = activityService.selectById(id);
 
        model.addAttribute("item",tActivity);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String temp = "";
        switch (tActivity.getStatus()){
            case 1:
                temp = "待审核";
                break;
            case 2:
                temp = "已审核";
                break;
            case 3:
                temp = "已驳回";
                break;
        }
        model.addAttribute("statusString",temp);
        model.addAttribute("auditTimeString",simpleDateFormat.format(tActivity.getAuditTime()));
        List<TActivityArea> branchOfficeAreaList = activityAreaService.selectList(new EntityWrapper<TActivityArea>().eq("activityId", id));
 
        StringBuilder sb = new StringBuilder();
        for (TActivityArea activityArea : branchOfficeAreaList) {
            sb.append(activityArea.getProvinceName()+"-"+activityArea.getCityName()+"-"+activityArea.getAreaName()+"、");
        }
        model.addAttribute("activityArea",sb.toString());
 
        model.addAttribute("scopeList",branchOfficeAreaList);
        // 查询优惠券信息
        List<TActivityCoupon> activityCoupons = activityCouponService.selectList(new EntityWrapper<TActivityCoupon>().eq("activityId", id));
        List<Integer> couponIds = activityCoupons.stream().map(TActivityCoupon::getCouponId).distinct().collect(Collectors.toList());
        if(!CollectionUtils.isEmpty(couponIds)){
            List<TCoupon> coupons = couponService.selectList(new EntityWrapper<TCoupon>().in("id", couponIds));
            for (TCoupon coupon : coupons) {
                TActivityCoupon tActivityCoupon = activityCoupons.stream().filter(e -> e.getCouponId().equals(coupon.getId())).findFirst().orElse(null);
                if(Objects.nonNull(tActivityCoupon) && Objects.nonNull(tActivityCoupon.getCreateTime())){
                    coupon.setCreateTimeStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tActivityCoupon.getCreateTime()));
                }
                switch (coupon.getCouponType()) {
                    case 1:
                        coupon.setCouponTypeStr("现金券");
                        break;
                    case 2:
                        coupon.setCouponTypeStr("新人券");
                        break;
                    case 3:
                        coupon.setCouponTypeStr("分享券");
                        break;
                    case 4:
                        coupon.setCouponTypeStr("消费优惠券");
                        break;
                    default:
                        coupon.setCouponTypeStr("充值优惠券");
                        break;
               }
                switch (coupon.getCouponServiceType()) {
                    case 1:
                        coupon.setCouponServiceTypeStr("通用型");
                        break;
                    default:
                        coupon.setCouponServiceTypeStr("通用型");
                        break;
                }
            }
            model.addAttribute("couponList",coupons);
 
            // 查询参与人数,总金额
            List<TUserToCoupon> userToCoupons = userToCouponService.selectList(new EntityWrapper<TUserToCoupon>().in("couponId", couponIds));
            int sum = userToCoupons.stream().mapToInt(TUserToCoupon::getCouponTotal).sum();
            model.addAttribute("joinCount",sum);
            if(CollectionUtils.isEmpty(userToCoupons)){
                model.addAttribute("couponMoney",0);
            }
            for (TUserToCoupon userToCoupon : userToCoupons) {
                TCoupon tCoupon = coupons.stream().filter(e -> e.getId().equals(userToCoupon.getCouponId())).findFirst().orElse(null);
                if(Objects.nonNull(tCoupon)){
                    model.addAttribute("couponMoney",new BigDecimal(userToCoupon.getCouponTotal()).multiply(tCoupon.getCouponPreferentialAmount()));
                }else {
                    model.addAttribute("couponMoney",0);
                }
            }
 
        } else {
            model.addAttribute("couponList",new ArrayList<>());
            model.addAttribute("joinCount",0);
            model.addAttribute("couponMoney",0);
        }
 
        // 查询优惠券点击量,参与人数,领取量
        String value = redisUtil.getValue("activity_view_count:" + id);
        if(StringUtils.hasLength(value)){
            model.addAttribute("readCount",Integer.parseInt(value));
        }else {
            model.addAttribute("readCount",0);
        }
 
 
 
 
        return PREFIX + "activity_detail.html";
    }
    /**
     * 跳转到选择优惠券页面
     */
    @RequestMapping("/changeCoupon")
    public String changeCoupon(Model model) {
        return PREFIX + "tCouponActivity.html";
    }
 
    /**
     * 跳转到修改
     */
    @RequestMapping("/activity_update/{id}")
    public String activityUpdate(@PathVariable("id") Integer id, Model model) {
        // 查询当前帐号的省市区
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 1){
            List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>());
            if(CollectionUtils.isEmpty(branchOfficeAreaList)){
                model.addAttribute("provinceList",new ArrayList<>());
            }
            branchOfficeAreaList.forEach(item->{
                item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
            });
            model.addAttribute("provinceList",branchOfficeAreaList);
        }else {
            TBranchOffice tBranchOffice = branchOfficeService.selectById(objectId);
            List<TBranchOfficeArea> branchOfficeAreaList = branchOfficeAreaService.selectList(new EntityWrapper<TBranchOfficeArea>()
                    .eq("branchOfficeId",tBranchOffice.getId()));
            if(CollectionUtils.isEmpty(branchOfficeAreaList)){
                model.addAttribute("provinceList",new ArrayList<>());
            }
            branchOfficeAreaList.forEach(item->{
                item.setActivityAreaCode(item.getProvinceCode()+"-"+item.getCityCode()+"-"+item.getAreaCode());
            });
            model.addAttribute("provinceList",branchOfficeAreaList);
        }
        TActivity tActivity = activityService.selectById(id);
 
        model.addAttribute("item",tActivity);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String temp = "";
        switch (tActivity.getStatus()){
            case 1:
                temp = "待审核";
                break;
            case 2:
                temp = "已审核";
                break;
            case 3:
                temp = "已驳回";
                break;
        }
        model.addAttribute("statusString",temp);
        model.addAttribute("auditTimeString",simpleDateFormat.format(tActivity.getAuditTime()));
        List<TActivityArea> branchOfficeAreaList = activityAreaService.selectList(new EntityWrapper<TActivityArea>().eq("activityId", id));
 
        StringBuilder sb = new StringBuilder();
        for (TActivityArea activityArea : branchOfficeAreaList) {
            sb.append(activityArea.getProvinceName()+"-"+activityArea.getCityName()+"-"+activityArea.getAreaName()+"、");
        }
        model.addAttribute("activityArea",sb.toString());
 
        model.addAttribute("scopeList",branchOfficeAreaList);
        // 查询优惠券信息
        List<TActivityCoupon> activityCoupons = activityCouponService.selectList(new EntityWrapper<TActivityCoupon>().eq("activityId", id));
        List<Integer> couponIds = activityCoupons.stream().map(TActivityCoupon::getCouponId).distinct().collect(Collectors.toList());
        if(!CollectionUtils.isEmpty(couponIds)){
            List<TCoupon> coupons = couponService.selectList(new EntityWrapper<TCoupon>().in("id", couponIds));
            for (TCoupon coupon : coupons) {
                TActivityCoupon tActivityCoupon = activityCoupons.stream().filter(e -> e.getCouponId().equals(coupon.getId())).findFirst().orElse(null);
                if(Objects.nonNull(tActivityCoupon) && Objects.nonNull(tActivityCoupon.getCreateTime())){
                    coupon.setCreateTimeStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tActivityCoupon.getCreateTime()));
                }
                switch (coupon.getCouponType()) {
                    case 1:
                        coupon.setCouponTypeStr("现金券");
                        break;
                    case 2:
                        coupon.setCouponTypeStr("新人券");
                        break;
                    case 3:
                        coupon.setCouponTypeStr("分享券");
                        break;
                    case 4:
                        coupon.setCouponTypeStr("消费优惠券");
                        break;
                    default:
                        coupon.setCouponTypeStr("充值优惠券");
                        break;
                }
                switch (coupon.getCouponServiceType()) {
                    case 1:
                        coupon.setCouponServiceTypeStr("通用型");
                        break;
                    default:
                        coupon.setCouponServiceTypeStr("通用型");
                        break;
                }
            }
            model.addAttribute("couponList",coupons);
        } else {
            model.addAttribute("couponList",new ArrayList<>());
        }
        return PREFIX + "activity_edit.html";
    }
 
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String createTime,String branchOfficeName,String activityName,
                       String activityAreaCode,Integer status) {
        ShiroUser user = ShiroKit.getUser();
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(createTime)){
            String[] timeArray = createTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
 
        String provinceCode = null;
        String cityCode = null;
        String areaCode = null;
        if(StringUtils.hasLength(activityAreaCode)){
            String[] split = activityAreaCode.split("-");
            provinceCode = split[0];
            cityCode = split[1];
            areaCode = split[2];
        }
        Page<TActivity> page = new PageFactory<TActivity>().defaultPage();
        List<TActivity> list = activityService.getList(page, beginTime, endTime, branchOfficeName, user.getRoleType(), user.getObjectId(), activityName, provinceCode, cityCode, areaCode, status);
        for (TActivity tActivity : list) {
            tActivity.setRoleType(user.getRoleType());
        }
 
        page.setRecords(list);
        return super.packForBT(page);
    }
 
    @RequestMapping(value = "/audit")
    @ResponseBody
    public Object audit(Integer id,Integer status, String auditRemark) {
        TActivity activity = activityService.selectById(id);
        activity.setStatus(status);
        activity.setAuditRemark(auditRemark);
        activity.setAuditPeople(ShiroKit.getUser().getName());
        activity.setAuditTime(new Date());
        activityService.updateById(activity);
        return SUCCESS_TIP;
    }
    @RequestMapping(value = "/change")
    @ResponseBody
    public Object change(@RequestParam Integer code) {
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        List<TBranchOfficeArea> list = new ArrayList<>();
        if (SinataUtil.isNotEmpty(code)){
            EntityWrapper<TBranchOfficeArea> wrapper = new EntityWrapper<>();
            wrapper.eq("provinceCode", code);
            if(roleType == 2){
                wrapper.eq("branchOfficeId", objectId);
            }
            list = branchOfficeAreaService.selectList(wrapper);
        }
        list = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
                new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getCityCode))),ArrayList::new));
        return list;
    }
    @RequestMapping(value = "/change1")
    @ResponseBody
    public Object change1(@RequestParam Integer code) {
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        List<TBranchOfficeArea> list = new ArrayList<>();
        if (SinataUtil.isNotEmpty(code)){
            EntityWrapper<TBranchOfficeArea> wrapper = new EntityWrapper<>();
            wrapper.eq("cityCode", code);
            if(roleType == 2){
                wrapper.eq("branchOfficeId", objectId);
            }
            list = branchOfficeAreaService.selectList(wrapper);
        }
        list = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
                new TreeSet<>(Comparator.comparing(TBranchOfficeArea::getAreaCode))),ArrayList::new));
        return list;
    }
 
    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TActivity activity,String subArr, String subArr1) {
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        activity.setCompanyId(objectId);
        activity.setCompanyType(roleType);
        activity.setCreateTime(new Date());
        activity.setCreateBy(ShiroKit.getUser().getName());
        activityService.insert(activity);
        addActivity(subArr1,activity.getId());
        addScope(subArr,activity.getId());
        return SUCCESS_TIP;
    }
 
    // 添加优惠券
    public void addActivity(String subArr,Integer id){
        JSONArray jsonArray = JSON.parseArray(subArr);
        activityCouponService.delete(new EntityWrapper<TActivityCoupon>().eq("activityId", id));
        int size = jsonArray.size();
        List<TActivityCoupon> activityCoupons = new ArrayList<>();
        for (int i = 0; i < size; i++){
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            if(Objects.isNull(jsonObject) || jsonObject.size() == 0){
                continue;
            }
            TActivityCoupon activityCoupon = new TActivityCoupon();
            activityCoupon.setActivityId(id);
            activityCoupon.setCouponId(jsonObject.getInteger("couponId"));
            activityCoupon.setCreateTime(new Date());
            activityCoupons.add(activityCoupon);
        }
        activityCouponService.insertBatch(activityCoupons);
    }
 
    //添加经营区域
    public void addScope(String subArr,Integer id){
        JSONArray jsonArray = JSON.parseArray(subArr);
        List<TRegion> tRegions = tRegionService.selectList(new EntityWrapper<TRegion>());
        activityAreaService.delete(new EntityWrapper<TActivityArea>().eq("activityId", id));
        int size = jsonArray.size();
        for (int i = 0; i < size; i++){
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            if(Objects.isNull(jsonObject) || jsonObject.size() == 0){
                continue;
            }
            TActivityArea activityArea = activityAreaService.selectOne(new EntityWrapper<TActivityArea>().eq("id", jsonObject.getInteger("recordId")).eq("activityId", id));
            String provinceCode = jsonObject.getString("provinceCode");
            String cityCode = jsonObject.getString("cityCode");
            String areaCode = jsonObject.getString("areaCode");
            TRegion province = tRegions.stream().filter(e -> e.getCode().equals(provinceCode)).findFirst().get();
            TRegion city = tRegions.stream().filter(e -> e.getCode().equals(cityCode)).findFirst().get();
            TRegion area = tRegions.stream().filter(e -> e.getCode().equals(areaCode)).findFirst().get();
            if (SinataUtil.isEmpty(activityArea)){
                activityArea = new TActivityArea();
                activityArea.setProvinceCode(provinceCode);
                activityArea.setCityCode(cityCode);
                activityArea.setAreaCode(areaCode);
                activityArea.setProvinceName(province.getName());
                activityArea.setCityName(city.getName());
                activityArea.setAreaName(area.getName());
                activityArea.setCreateTime(new Date());
                activityArea.setActivityId(id);
                activityAreaService.insert(activityArea);
            }else{
                activityArea.setProvinceCode(provinceCode);
                activityArea.setCityCode(cityCode);
                activityArea.setAreaCode(areaCode);
                activityArea.setProvinceName(province.getName());
                activityArea.setCityName(city.getName());
                activityArea.setAreaName(area.getName());
                activityArea.setCreateTime(new Date());
                activityAreaService.updateById(activityArea);
            }
        }
    }
 
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer activityId) {
        TActivity activity = activityService.selectById(activityId);
        activity.setIsDelete(1);
        activityService.updateById(activity);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TActivity activity,String subArr, String subArr1,Integer id) {
//        Integer objectId = ShiroKit.getUser().getObjectId();
//        Integer roleType = ShiroKit.getUser().getRoleType();
//        activity.setCompanyId(objectId);
//        activity.setCompanyType(roleType);
        activity.setStatus(1);
        activityService.updateById(activity);
        addActivity(subArr1,id);
        addScope(subArr,id);
        return SUCCESS_TIP;
    }
    @RequestMapping(value = "/updateStatus")
    @ResponseBody
    public Object updateStatus(TActivity activity, String subArr,String subArr1) {
        activityService.updateById(activity);
        addActivity(subArr1,activity.getId());
        addScope(subArr,activity.getId());
        return SUCCESS_TIP;
    }
 
    @RequestMapping("/activity_detail/{activityId}")
    public String activityDetail(@PathVariable Integer activityId, Model model) {
        TActivity activity = activityService.selectById(activityId);
        model.addAttribute("item",activity);
 
        LogObjectHolder.me().set(activity);
        return PREFIX + "activity_detail.html";
    }
 
    /**
     * 跳转到立即处理页面
     */
    @RequestMapping("/activity_immediately/{id}")
    public String activityImmediately(@PathVariable Integer id, Model model) {
        model.addAttribute("id",id);
        return PREFIX + "activity_immediately.html";
    }
    /**
     * 立即处理操作
     */
    @RequestMapping(value = "/immediately")
    @ResponseBody
    public Object immediately(@RequestParam Integer id,@RequestParam Integer state,@RequestParam String remark) {
        TActivity activity = activityService.selectById(id);
        if (SinataUtil.isNotEmpty(activity)){
            activity.setStatus(state);
            activityService.updateById(activity);
        }
        return SUCCESS_TIP;
    }
}