fix
Helius
2021-09-15 7ab7943de217a9e5d4a489c22c7ae27a29692d55
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
package com.xzx.gc.system.service;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.xzx.gc.common.constant.CommonEnum;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.constant.OrderEnum;
import com.xzx.gc.common.utils.BusinessUtil;
import com.xzx.gc.common.utils.DateUtils;
import com.xzx.gc.common.utils.SpringUtil;
import com.xzx.gc.entity.*;
import com.xzx.gc.system.mapper.PlatformReportMapper;
import com.xzx.gc.util.CollUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
 
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
 
/**
 * 平台报表
 */
@Service
@Transactional
@Slf4j
public class PlatformReportService {
 
    @Autowired
    private PlatformReportMapper platformReportMapper;
 
    @Autowired
    private UserService userService;
 
    @Autowired
    private OrderService orderService;
 
    @Autowired
    private AccountService accountService;
 
    @Autowired
    private OrderComplaintService orderComplaintService;
 
    @Autowired
    private OrderStorageService orderStorageService;
 
    @Autowired
    private CityPartnerService cityPartnerService;
 
    @Autowired
    private BusinessUtil businessUtil;
 
    @Autowired
    private OtherUserService otherUserService;
 
    @Autowired
    private AccountLogService accountLogService;
 
 
 
 
 
    /**
     * 按报表类型和指标类型查询
     * @param reportType
     * @param indicatorType
     * @return
     */
    public List<PlatformReport> findByType(String reportType,String indicatorType){
        Example example=new Example(PlatformReport.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("reportType",reportType);
        criteria.andEqualTo("indicatorType",indicatorType);
        return platformReportMapper.selectByExample(example);
    }
 
 
    /**
     * 根据报表类型 及小于入参时间查询
     * @param reportType
     * @param time
     * @return
     */
    public List<PlatformReport> findByReportTypeLessThanTime(String reportType,String time){
        Example example=new Example(PlatformReport.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("reportType",reportType);
        criteria.andLessThan("createTime",time);
        return platformReportMapper.selectByExample(example);
    }
 
 
    /**
     * 根据类型和时间筛选
     * @param reportType
     * @param indicatorType
     * @param timeType
     * @return
     */
    public List<PlatformReport> findByTypeAndTimeType(String reportType,String indicatorType,String timeType){
        Example example=new Example(PlatformReport.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("reportType",reportType);
        criteria.andEqualTo("indicatorType",indicatorType);
        //1:近3天 2 近1个星期 3:近一个月 4:近3个月 5:近6个月
        if("1".equals(timeType)){
            criteria.andCondition("DATE_FORMAT(create_time,'%Y-%m-%d')>=date_sub(CURRENT_DATE(), interval 3 day)");
        } else if ("2".equals(timeType)) {
            criteria.andCondition("DATE_FORMAT(create_time,'%Y-%m-%d')>=date_sub(CURRENT_DATE(), interval 7 day)");
        }else if ("3".equals(timeType)) {
            criteria.andCondition("DATE_FORMAT(create_time,'%Y-%m-%d')>=date_sub(CURRENT_DATE(), interval 1 month)");
        }else if ("4".equals(timeType)) {
            criteria.andCondition("DATE_FORMAT(create_time,'%Y-%m-%d')>=date_sub(CURRENT_DATE(), interval 3 month)");
        }else if ("5".equals(timeType)) {
            criteria.andCondition("DATE_FORMAT(create_time,'%Y-%m-%d')>=date_sub(CURRENT_DATE(), interval 6 month)");
        }
        example.setOrderByClause("create_time asc");
        return platformReportMapper.selectByExample(example);
    }
 
    /**
     * 根据指标类型查找
     * @param indicatorType
     * @return
     */
    public List<PlatformReport> findByIndicatorType(String indicatorType){
        Example example=new Example(PlatformReport.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("indicatorType",indicatorType);
        example.setOrderByClause("create_time desc");
        return platformReportMapper.selectByExample(example);
    }
 
    /**
     * 根据统计时间查找
     * @param time
     * @return
     */
    public int findByTime(String time){
        Example example=new Example(PlatformReport.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("createTime",time);
        return platformReportMapper.selectCountByExample(example);
    }
 
    /**
     * 获取 日环比
     * @param moneys
     * @return
     */
    public String  getRatio(List<PlatformReport> moneys ){
        List<PlatformReport> collect = moneys.stream().filter(x -> DateUtil.offsetDay(new Date(),-2).toDateStr().equals(x.getCreateTime())).collect(Collectors.toList());
        double yesterday = collect.stream().mapToDouble(x -> Convert.toDouble(x.getIndicator())).sum();
        collect = moneys.stream().filter(x -> DateUtil.offsetDay(new Date(),-1).toDateStr().equals(x.getCreateTime())).collect(Collectors.toList());
        double today = collect.stream().mapToDouble(x -> Convert.toDouble(x.getIndicator())).sum();
        return businessUtil.getRatio(Convert.toBigDecimal(yesterday), Convert.toBigDecimal(today));
    }
 
 
    /**
     * 删除所有报表数据
     */
    public void deleteAll(){
        platformReportMapper.delete(new PlatformReport());
    }
 
    /**
     * 批量添加
     * @param list
     */
    public void batchAdd(List<PlatformReport> list){
        platformReportMapper.insertList(list);
    }
 
 
    /**
     * 初始化所有数据生成报表
     */
    public void init(){
        List<UserInfo> userInfos = userService.findForBidden();
        List<OrderInfo> orderInfos =orderService.findPartnerId();
        List<OrderStorageInfo> storageInfos = orderStorageService.findByStorageType(Convert.toShort(OrderEnum.打包站.getValue()));
        List<OrderComplaint> complaints = orderComplaintService.findPartner();
        List<AccountInfo> accountInfos = accountService.findThanZero();
        List<AccountLog> withdraws = accountLogService.findByChannelType(Convert.toShort(CommonEnum.提现操作.getValue()));
        init(userInfos,orderInfos,storageInfos,complaints,accountInfos,withdraws,DateUtil.today());
    }
 
    /**
     * 同步数据
     */
    @Scheduled(cron = "${order.report.cron}")
    @Async
    public void sysnc(){
        log.trace("********定时执行平台报表统计任务开始【凌晨12点半执行】*********");
        if(!SpringUtil.isCloud()) {
            List<UserInfo> userInfos = userService.findForBiddenByTime();
            List<OrderInfo> orderInfos = orderService.findPartnerIdByTime();
            List<OrderStorageInfo> storageInfos = orderStorageService.findByStorageTypeByTime(Convert.toShort(OrderEnum.打包站.getValue()));
            List<OrderComplaint> complaints = orderComplaintService.findPartnerByTime();
            List<AccountInfo> accountInfos = accountService.findThanZero();
            List<AccountLog> withdraws = accountLogService.findByChannelTypeAndTime(Convert.toShort(CommonEnum.提现操作.getValue()));
            init(userInfos, orderInfos, storageInfos, complaints, accountInfos,withdraws, DateUtil.yesterday().toDateStr());
        }
        log.trace("********定时执行平台报表统计任务结束【凌晨12点半执行】*********");
    }
 
 
    private void init(List<UserInfo> userInfos,List<OrderInfo> orderInfos,List<OrderStorageInfo> storageInfos,List<OrderComplaint> complaints,List<AccountInfo> accountInfos,List<AccountLog> withdraws,String time){
 
        log.debug(businessUtil.repeatService("平台报表统计任务开始"));
 
        if(findByTime(DateUtil.yesterday().toDateStr())>0||findByTime(DateUtil.today())>0){
            log.debug("统计已执行");
            return;
        }
 
        List<PlatformReport> list=CollUtil.newArrayList();
        /**
         *总用户量
         */
        //按时间统计
        List<List<UserInfo>> userByTime = CollUtils.groupByField(userInfos, "registTime");
 
        if(CollUtil.isNotEmpty(userByTime)) {
            for (List<UserInfo> userInfoList : userByTime) {
                PlatformReport platformReport = new PlatformReport();
                platformReport.setCreateTime(DateUtils.formatDate(userInfoList.get(0).getRegistTime()));
                platformReport.setReportType(Convert.toShort(OrderEnum.用户量.getValue()));
                platformReport.setIndicator(Convert.toStr(userInfoList.size()));
                platformReport.setIndicatorType(Convert.toShort(OrderEnum.按时间统计.getValue()));
                platformReport.setUserId(Constants.DEFAULT_ID);
                list.add(platformReport);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.用户量.getValue(),OrderEnum.按时间统计.getValue());
        }
        platformReportMapper.insertList(list);
        log.debug("已完成总用户量按时间统计,统计数目:{}",list.size());
 
        //按合伙人统计
        list.clear();
 
        //用户根据合伙人拆分成多个集合
        if(CollUtil.isNotEmpty(userInfos)){
            Dict dict =groupPartner(userInfos);
            for (String s : dict.keySet()) {
                List<UserInfo> dictList = (List<UserInfo>) dict.get(s);
                staticUser(dictList,list,time);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.用户量.getValue(),OrderEnum.按合伙人统计.getValue());
        }
 
        platformReportMapper.insertList(list);
        log.debug("已完成总用户量按合伙人统计,统计数目:{}",list.size());
 
 
        /*
         *总订单量
         */
        //按时间统计
        list.clear();
        List<List<OrderInfo>> orderByTime = CollUtils.groupByField(orderInfos, "createTime");
        if(CollUtil.isNotEmpty(orderByTime)) {
            for (List<OrderInfo> orderInfoList : orderByTime) {
                PlatformReport platformReport = new PlatformReport();
                platformReport.setCreateTime(DateUtils.formatDate(orderInfoList.get(0).getCreateTime()));
                platformReport.setReportType(Convert.toShort(OrderEnum.总下单量.getValue()));
                platformReport.setIndicator(Convert.toStr(orderInfoList.size()));
                platformReport.setIndicatorType(Convert.toShort(OrderEnum.按时间统计.getValue()));
                platformReport.setUserId(Constants.DEFAULT_ID);
                list.add(platformReport);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.总下单量.getValue(),OrderEnum.按时间统计.getValue());
        }
        platformReportMapper.insertList(list);
        log.debug("已完成总订单量按时间统计,统计数目:{}",list.size());
 
        //按合伙人统计
        list.clear();
        List<List<OrderInfo>> orderByPartner = CollUtil.groupByField(orderInfos, "partnerId");
        if(CollUtil.isNotEmpty(orderByPartner)) {
            for (List<OrderInfo> orderInfoList : orderByPartner) {
                PlatformReport platformReport = new PlatformReport();
                platformReport.setCreateTime(time);
                platformReport.setReportType(Convert.toShort(OrderEnum.总下单量.getValue()));
                platformReport.setIndicator(Convert.toStr(orderInfoList.size()));
                platformReport.setIndicatorType(Convert.toShort(OrderEnum.按合伙人统计.getValue()));
                String partnterId = StrUtil.isBlank(orderInfoList.get(0).getPartnerId()) ? Constants.DEFAULT_ID : orderInfoList.get(0).getPartnerId();
                platformReport.setUserId(partnterId);
                list.add(platformReport);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.总下单量.getValue(),OrderEnum.按合伙人统计.getValue());
        }
        platformReportMapper.insertList(list);
        log.debug("已完成总订单量按合伙人统计,统计数目:{}",list.size());
 
 
        /*
         *总交易金额
         */
        //按时间统计
        list.clear();
        //删除金额为0(订单状态为已取消等)
        orderInfos.removeIf(x->StrUtil.isBlank(x.getMoney())||Convert.toBigDecimal(x.getMoney()).compareTo(BigDecimal.ZERO)==0);
        orderByTime = CollUtils.groupByField(orderInfos, "createTime");
        if(CollUtil.isNotEmpty(orderByTime)) {
            for (List<OrderInfo> orderInfoList : orderByTime) {
                PlatformReport platformReport = new PlatformReport();
                platformReport.setCreateTime(DateUtils.formatDate(orderInfoList.get(0).getCreateTime()));
                platformReport.setReportType(Convert.toShort(OrderEnum.总交易金额.getValue()));
                platformReport.setIndicator(businessUtil.changeMoney(Convert.toStr(orderInfoList.stream().mapToDouble(x -> Convert.toDouble(x.getMoney())).sum())));
                platformReport.setIndicatorType(Convert.toShort(OrderEnum.按时间统计.getValue()));
                platformReport.setUserId(Constants.DEFAULT_ID);
                list.add(platformReport);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.总交易金额.getValue(),OrderEnum.按时间统计.getValue());
        }
        platformReportMapper.insertList(list);
        log.debug("已完成总交易额按时间统计,统计数目:{}",list.size());
 
        //按合伙人统计
        list.clear();
        orderByPartner = CollUtil.groupByField(orderInfos, "partnerId");
        if(CollUtil.isNotEmpty(orderByPartner)) {
            for (List<OrderInfo> orderInfoList : orderByPartner) {
                PlatformReport platformReport = new PlatformReport();
                platformReport.setCreateTime(time);
                platformReport.setReportType(Convert.toShort(OrderEnum.总交易金额.getValue()));
                platformReport.setIndicator(businessUtil.changeMoney(Convert.toStr(orderInfoList.stream().mapToDouble(x -> Convert.toDouble(x.getMoney())).sum())));
                platformReport.setIndicatorType(Convert.toShort(OrderEnum.按合伙人统计.getValue()));
                String partnterId = StrUtil.isBlank(orderInfoList.get(0).getPartnerId()) ? Constants.DEFAULT_ID : orderInfoList.get(0).getPartnerId();
                platformReport.setUserId(partnterId);
                list.add(platformReport);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.总交易金额.getValue(),OrderEnum.按合伙人统计.getValue());
        }
        platformReportMapper.insertList(list);
        log.debug("已完成总交易额按合伙人统计,统计数目:{}",list.size());
 
 
        /*
          打包站回收金额
         */
        //按时间统计
        list.clear();
        List<List<OrderStorageInfo>> storageByTime = CollUtils.groupByField(storageInfos, "storageTime");
        if(CollUtil.isNotEmpty(storageByTime)) {
            for (List<OrderStorageInfo> storageInfoList : storageByTime) {
                PlatformReport platformReport = new PlatformReport();
                platformReport.setCreateTime(DateUtils.formatDate(storageInfoList.get(0).getStorageTime()));
                platformReport.setReportType(Convert.toShort(OrderEnum.打包站回收金额.getValue()));
                platformReport.setIndicator(businessUtil.changeMoney(Convert.toStr(storageInfoList.stream().mapToDouble(x -> Convert.toDouble(x.getStorageMoney(),Convert.toDouble(BigDecimal.ZERO))).sum())));
                platformReport.setIndicatorType(Convert.toShort(OrderEnum.按时间统计.getValue()));
                platformReport.setUserId(Constants.DEFAULT_ID);
                list.add(platformReport);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.打包站回收金额.getValue(),OrderEnum.按时间统计.getValue());
        }
        platformReportMapper.insertList(list);
        log.debug("已完成打包站回收金额按时间统计,统计数目:{}",list.size());
 
 
        //按打包站统计
        list.clear();
        List<List<OrderStorageInfo>> storageByPartner = CollUtil.groupByField(storageInfos, "sysStorageId");
        if(CollUtil.isNotEmpty(storageByPartner)) {
            for (List<OrderStorageInfo> storageInfoList : storageByPartner) {
                PlatformReport platformReport = new PlatformReport();
                platformReport.setCreateTime(time);
                platformReport.setReportType(Convert.toShort(OrderEnum.打包站回收金额.getValue()));
                platformReport.setIndicator(businessUtil.changeMoney(Convert.toStr(storageInfoList.stream().mapToDouble(x -> Convert.toDouble(x.getStorageMoney(),Convert.toDouble(BigDecimal.ZERO))).sum())));
                platformReport.setIndicatorType(Convert.toShort(OrderEnum.按打包站统计.getValue()));
                platformReport.setUserId(Convert.toStr(storageInfoList.get(0).getSysStorageId()));
                list.add(platformReport);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.打包站回收金额.getValue(),OrderEnum.按打包站统计.getValue());
        }
        platformReportMapper.insertList(list);
        log.debug("已完成打包站回收金额按打包站统计,统计数目:{}",list.size());
 
 
        /*
         * 投诉总量
         */
        //按时间统计
        list.clear();
        List<List<OrderComplaint>> complaintByTime = CollUtils.groupByField(complaints, "createTime");
        if(CollUtil.isNotEmpty(complaintByTime)) {
            for (List<OrderComplaint> complaintList : complaintByTime) {
                PlatformReport platformReport = new PlatformReport();
                platformReport.setCreateTime(DateUtils.formatDate(complaintList.get(0).getCreateTime()));
                platformReport.setReportType(Convert.toShort(OrderEnum.投诉总量.getValue()));
                platformReport.setIndicator(Convert.toStr(complaintList.size()));
                platformReport.setIndicatorType(Convert.toShort(OrderEnum.按时间统计.getValue()));
                platformReport.setUserId(Constants.DEFAULT_ID);
                list.add(platformReport);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.投诉总量.getValue(),OrderEnum.按时间统计.getValue());
        }
        platformReportMapper.insertList(list);
        log.debug("已完成投诉总量按时间统计,统计数目:{}",list.size());
 
        //按合伙人统计
        list.clear();
        List<List<OrderComplaint>> complaintByPartner = CollUtil.groupByField(complaints, "partnerId");
        if(CollUtil.isNotEmpty(complaintByPartner)) {
            for (List<OrderComplaint> complaintList : complaintByPartner) {
                PlatformReport platformReport = new PlatformReport();
                platformReport.setCreateTime(time);
                platformReport.setReportType(Convert.toShort(OrderEnum.投诉总量.getValue()));
                platformReport.setIndicator(Convert.toStr(complaintList.size()));
                platformReport.setIndicatorType(Convert.toShort(OrderEnum.按合伙人统计.getValue()));
                String partnterId = StrUtil.isBlank(complaintList.get(0).getPartnerId()) ? Constants.DEFAULT_ID : complaintList.get(0).getPartnerId();
                platformReport.setUserId(partnterId);
                list.add(platformReport);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.投诉总量.getValue(),OrderEnum.按合伙人统计.getValue());
        }
        platformReportMapper.insertList(list);
        log.debug("已完成投诉总量按打合伙人统计,统计数目:{}",list.size());
 
        /*
         * 未提现金额
         */
        //按时间统计
        if(CollUtil.isNotEmpty(accountInfos)) {
            PlatformReport platformReport = new PlatformReport();
            platformReport.setCreateTime(time);
            platformReport.setReportType(Convert.toShort(OrderEnum.未提现总额.getValue()));
            platformReport.setIndicator(businessUtil.changeMoney(Convert.toStr(accountInfos.stream().mapToDouble(x -> Convert.toDouble(x.getMoney())).sum())));
            platformReport.setIndicatorType(Convert.toShort(OrderEnum.按时间统计.getValue()));
            platformReport.setUserId(Constants.DEFAULT_ID);
            platformReportMapper.insertSelective(platformReport);
        }
        log.debug("已完成未提现金额按时间统计,统计数目:{}",CollUtil.isNotEmpty(accountInfos)?1:0);
        //按合伙人统计
        list.clear();
 
        //查询当前账户所属合伙人 打包站的账户归为合伙人
        for (AccountInfo accountInfo : accountInfos) {
            String partnerId = getPartnerIdByUserId(accountInfo.getUserId());
            accountInfo.setPartnerId(partnerId);
        }
 
 
        //账户根据合伙人拆分成多个集合
        if(CollUtil.isNotEmpty(accountInfos)){
            Dict dict =groupPartner(accountInfos);
            for (String s : dict.keySet()) {
                List<AccountInfo> dictList = (List<AccountInfo>) dict.get(s);
                staticAccount(dictList,list,time);
            }
        }
 
 
        if(CollUtil.isNotEmpty(list)) {
            platformReportMapper.insertList(list);
        }
        log.debug("已完成未提现金额按合伙人统计,统计数目:{}",list.size());
 
        /*
         *已提现金额
         */
        //按时间统计
        list.clear();
        List<List<AccountLog>> withdrawByTime = CollUtils.groupByField(withdraws, "createTime");
        if(CollUtil.isNotEmpty(withdrawByTime)) {
            for (List<AccountLog> withdrawList : withdrawByTime) {
                PlatformReport platformReport = new PlatformReport();
                platformReport.setCreateTime(DateUtils.formatDate(withdrawList.get(0).getCreateTime()));
                platformReport.setReportType(Convert.toShort(OrderEnum.已提现总额.getValue()));
                platformReport.setIndicator(businessUtil.changeMoney(Convert.toStr(withdrawList.stream().mapToDouble(x -> Convert.toDouble(x.getMoney())).sum())));
                platformReport.setIndicatorType(Convert.toShort(OrderEnum.按时间统计.getValue()));
                platformReport.setUserId(Constants.DEFAULT_ID);
                list.add(platformReport);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.已提现总额.getValue(),OrderEnum.按时间统计.getValue());
        }
        platformReportMapper.insertList(list);
        log.debug("已完成已提现总额按时间统计,统计数目:{}",list.size());
 
        //按合伙人统计
        list.clear();
        //查询当前账户所属合伙人 打包站的账户归为合伙人
        for (AccountLog withdraw : withdraws) {
            String partnerId = getPartnerIdByUserId(withdraw.getUserId());
            withdraw.setPartnerId(partnerId);
        }
 
 
        //账户根据合伙人拆分成多个集合
        if(CollUtil.isNotEmpty(withdraws)){
            Dict dict =groupPartner(withdraws);
            for (String s : dict.keySet()) {
                List<AccountLog> dictList = (List<AccountLog>) dict.get(s);
                staticAccountLog(dictList,list,time);
            }
        }else {
            initForEmptyList(list,time,OrderEnum.已提现总额.getValue(),OrderEnum.按合伙人统计.getValue());
        }
 
        platformReportMapper.insertList(list);
        log.debug("已完成已提现总额按合伙人统计,统计数目:{}",list.size());
 
 
        log.debug(businessUtil.repeatService("平台报表统计任务结束"));
    }
 
 
    /**
     * 根据用户ID查找合伙人ID
     * @param userId
     * @return
     */
    private String getPartnerIdByUserId(String userId) {
        String partnerId;
        OtherUserInfo byId = otherUserService.findById(userId);
        if(byId!=null){
            if(CommonEnum.打包员.getValue().equals(byId.getUserType())||CommonEnum.打包站运营员.getValue().equals(byId.getUserType())){
                //打包站id转换成合伙人id
                partnerId = cityPartnerService.queryById(Convert.toLong(byId.getPartnerId())).getPackingStation();
            }else {
                partnerId=byId.getPartnerId();
            }
        }else {
            UserInfo byId1 = userService.findById(userId);
            if(byId1==null){
                partnerId=Constants.DEFAULT_PARTNER_ID;
            }else {
                partnerId = byId1.getPartnerId();
            }
        }
        return partnerId;
    }
 
 
    /**
     * 按合伙人分组
     */
    private <T> Dict groupPartner(List<T> list) {
        Dict dict = Dict.create();
        for (T t : list) {
            String partnerIds= (String) ReflectUtil.getFieldValue(t,"partnerId");
            if(StrUtil.isNotBlank(partnerIds)){
                String[] split = partnerIds.split(",");
                if(split.length>1) {
                    for (String partnerId : split) {
                        Object o = BeanUtil.copyProperties(t, t.getClass());
                        ReflectUtil.setFieldValue(o, "singlePartnerId", partnerId);
                        groupDict(dict, o, partnerId);
                    }
                }else {
                    ReflectUtil.setFieldValue(t, "singlePartnerId", partnerIds);
                    groupDict(dict, t, partnerIds);
                }
            }else {
                String partnerId=Constants.DEFAULT_ID;
                ReflectUtil.setFieldValue(t,"singlePartnerId",partnerId);
                groupDict(dict,  t, partnerId);
            }
        }
        return dict;
    }
 
    private <T> void groupDict(Dict dict, T t, String s) {
        if(dict.containsKey(s)){
            List<T> dictList = (List<T>) dict.get(s);
            dictList.add(t);
            dict.put(s,dictList);
        }else {
            dict.put(s,CollUtil.newArrayList(t));
        }
    }
 
 
    /**
     * 用户按合伙人统计
     * @param userInfos
     * @param list
     * @param time
     */
    private void staticUser(List<UserInfo> userInfos,List<PlatformReport> list,String time){
        List<List<UserInfo>> userByPartner = CollUtil.groupByField(userInfos, "singlePartnerId");
        for (List<UserInfo> userInfoList : userByPartner) {
            PlatformReport platformReport=new PlatformReport();
            platformReport.setCreateTime(time);
            platformReport.setReportType(Convert.toShort(OrderEnum.用户量.getValue()));
            platformReport.setIndicator(Convert.toStr(userInfoList.size()));
            platformReport.setIndicatorType(Convert.toShort(OrderEnum.按合伙人统计.getValue()));
            String partnterId = StrUtil.isBlank(userInfoList.get(0).getPartnerId()) ? Constants.DEFAULT_ID : userInfoList.get(0).getSinglePartnerId();
            platformReport.setUserId(partnterId);
            list.add(platformReport);
        }
    }
 
 
    /**
     * 账户按合伙人统计
     * @param list
     * @param time
     */
    private void staticAccount(List<AccountInfo> accountInfos,List<PlatformReport> list,String time){
        List<List<AccountInfo>> accountByPartner = CollUtil.groupByField(accountInfos, "singlePartnerId");
        for (List<AccountInfo> accountInfoList : accountByPartner) {
            PlatformReport platformReport=new PlatformReport();
            platformReport.setCreateTime(time);
            platformReport.setReportType(Convert.toShort(OrderEnum.未提现总额.getValue()));
            platformReport.setIndicator(businessUtil.changeMoney(Convert.toStr(accountInfoList.stream().mapToDouble(x->Convert.toDouble(x.getMoney())).sum())));
            platformReport.setIndicatorType(Convert.toShort(OrderEnum.按合伙人统计.getValue()));
            String partnterId = StrUtil.isBlank(accountInfoList.get(0).getPartnerId()) ? Constants.DEFAULT_ID : accountInfoList.get(0).getSinglePartnerId();
            platformReport.setUserId(partnterId);
            list.add(platformReport);
        }
    }
 
 
    /**
     * 已提现按合伙人统计
     * @param list
     * @param time
     */
    private void staticAccountLog(List<AccountLog> accountInfos,List<PlatformReport> list,String time){
        List<List<AccountLog>> accountByPartner = CollUtil.groupByField(accountInfos, "singlePartnerId");
        for (List<AccountLog> accountInfoList : accountByPartner) {
            PlatformReport platformReport=new PlatformReport();
            platformReport.setCreateTime(time);
            platformReport.setReportType(Convert.toShort(OrderEnum.已提现总额.getValue()));
            platformReport.setIndicator(businessUtil.changeMoney(Convert.toStr(accountInfoList.stream().mapToDouble(x->Convert.toDouble(x.getMoney())).sum())));
            platformReport.setIndicatorType(Convert.toShort(OrderEnum.按合伙人统计.getValue()));
            String partnterId = StrUtil.isBlank(accountInfoList.get(0).getPartnerId()) ? Constants.DEFAULT_ID : accountInfoList.get(0).getSinglePartnerId();
            platformReport.setUserId(partnterId);
            list.add(platformReport);
        }
    }
 
    /**
     * 当查询数据为空的时候初始化
     */
    private void initForEmptyList( List<PlatformReport> list,String time,String reportType,String indicatorType){
        PlatformReport platformReport=new PlatformReport();
        platformReport.setCreateTime(time);
        platformReport.setReportType(Convert.toShort(reportType));
        platformReport.setIndicator(Convert.toStr(0));
        platformReport.setIndicatorType(Convert.toShort(indicatorType));
        platformReport.setUserId(Constants.DEFAULT_ID);
        list.add(platformReport);
    }
}