sgj
2026-03-27 878b6958363308a7d07b7b8197dc19662f3e1198
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
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
package com.fzzy.group.manager;
 
import com.fzzy.common.manager.CommonManager;
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.constant.FoodVariety;
import com.fzzy.igds.constant.RespCodeEnum;
import com.fzzy.igds.data.*;
import com.fzzy.igds.domain.*;
import com.fzzy.igds.service.*;
import com.fzzy.igds.utils.ContextUtil;
import com.fzzy.igds.utils.DateUtil;
import com.fzzy.igds.utils.NumberUtil;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Description
 * @Author CZT
 * @Date 2025/12/11 15:48
 */
@Slf4j
@Component
public class GroupManager {
 
    @Resource
    private CommonManager commonManager;
    @Resource
    private DicAreaService dicAreaService;
    @Resource
    private CoreDeptService deptService;
    @Resource
    private DepotService depotService;
    @Resource
    private CoreCompanyService coreCompanyService;
    @Resource
    private InoutRecordService inoutRecordService;
    @Resource
    private EventInfoService eventInfoService;
    @Resource
    private SnapRecordService snapRecordService;
    @Resource
    private SecCameraService cameraService;
    @Resource
    private BankService bankService;
    @Resource
    private PledgeContractService pledgeContractService;
    @Resource
    private PledgeContractDepotService pledgeContractDepotService;
    @Resource
    private GatewaySerService gatewaySerService;
 
    /**
     * 获取省及下属市州集合
     *
     * @param areaCode
     * @return
     */
    public List<DicArea> getArea(String areaCode) {
 
        DicArea area = dicAreaService.listDicAreaByCode(areaCode);
        if (null == area) {
            return null;
        }
 
        List<DicArea> list = new ArrayList<>();
        list.add(area);
        if (Constant.AREA_TYPE_1.equals(area.getType())) {
            //市州级别,只查询伊犁
            List<DicArea> children = dicAreaService.listData(null, null, "654000");
            if (null != children && !children.isEmpty()) {
                for (DicArea child : children) {
                    if (Constant.AREA_TYPE_2.equals(child.getType())) {
                        //区县
                        List<DicArea> childrenItem = dicAreaService.listData(child.getCode(), null, null);
                        if (null != childrenItem && !childrenItem.isEmpty()) {
                            list.addAll(childrenItem);
                        }
                    }
                }
                list.addAll(children);
            }
        }
 
        return list;
    }
 
    /**
     * 获取对应省份及下属市州children
     *
     * @param areaCode
     * @return
     */
    public List<DicArea> getAreaAndChild(String areaCode) {
 
        DicArea area = dicAreaService.listDicAreaByCode(areaCode);
        if (null == area) {
            return null;
        }
 
        List<DicArea> list = new ArrayList<>();
        if (Constant.AREA_TYPE_1.equals(area.getType())) {
            //市州级别,只查询伊犁
            List<DicArea> children = dicAreaService.listData(null, null, "654000");
            if (null != children && !children.isEmpty()) {
                for (DicArea child : children) {
                    if (Constant.AREA_TYPE_2.equals(child.getType())) {
                        //区县
                        List<DicArea> childrenItem = dicAreaService.listData(child.getCode(), null, null);
                        if (null != childrenItem && !childrenItem.isEmpty()) {
                            child.setChildren(childrenItem);
                        }
                    }
                }
                area.setChildren(children);
            }
 
        }
        list.add(area);
        return list;
    }
 
 
    public List<DicArea> getBankAndChildDept(String areaCode) {
 
        DicArea area = dicAreaService.listDicAreaByCode(areaCode);
        if (null == area) {
            return null;
        }
        List<DicArea> areaChildren = new ArrayList<>();
 
        List<DicArea> list = new ArrayList<>();
        if (Constant.AREA_TYPE_1.equals(area.getType())) {
            //查询所有的质押合同
            List<PledgeContract> pledgeContractList = pledgeContractService.listAll(null);
            //查询所有的库区
            List<Dept> depotList = deptService.listDept(null, ContextUtil.getCompanyId(), null);
            //查询所有的银行
            List<Bank> bankList = bankService.listAll(null);
            DicArea defaultBank = new DicArea();
            defaultBank.setCode("-1");
            defaultBank.setName("无质押银行");
            defaultBank.setChildren(new ArrayList<>());
 
            for (Dept dept : depotList) {
                Boolean isPledge = false;
                for (PledgeContract pledgeContract : pledgeContractList) {
                    IgdsBaseParam param = new IgdsBaseParam();
                    param.setParentId(pledgeContract.getId());
                    List<PledgeContractDepot> pledgeContractDepots = pledgeContractDepotService.listAll(param);
                    if (null == pledgeContractDepots || pledgeContractDepots.isEmpty()) {
                        continue;
                    }
                    //找到pledgeContractDepots中的deptId集合,并去重
                    List<String> deptIdList = pledgeContractDepots.stream().map(PledgeContractDepot::getPledgeDept).distinct().collect(Collectors.toList());
                    if (deptIdList.contains(dept.getId())) {
                        //从list中找到当前质押银行的数据
                        DicArea pledgeBank = null;
                        int indexBank = -1;
                        for (DicArea item : areaChildren) {
                            if (pledgeContract.getPledgeBank().equals(item.getCode())) {
                                pledgeBank = item;
                                indexBank = areaChildren.indexOf(pledgeBank);
                                break;
                            }
                        }
                        if (null == pledgeBank) {
                            //未找到质押银行数据则新建
                            pledgeBank = new DicArea();
                            pledgeBank.setCode(pledgeContract.getPledgeBank());
                            pledgeBank.setName("质押银行_" + pledgeContract.getPledgeBank());
                            //从银行数据中找到质押银行的信息
                            for (Bank bank : bankList) {
                                if (pledgeContract.getPledgeBank().equals(bank.getId())) {
                                    pledgeBank.setName(bank.getName());
                                }
                            }
                            //添加质押银行下的库区数据
                            DicArea deptDic = new DicArea();
                            deptDic.setCode(dept.getId());
                            deptDic.setName(dept.getKqmc());
 
                            List<DicArea> children = pledgeBank.getChildren();
                            if (null == children) {
                                pledgeBank.setChildren(new ArrayList<>());
                            }
                            pledgeBank.getChildren().add(deptDic);
                            //新增质押银行数据到list中
                            areaChildren.add(pledgeBank);
                            isPledge = true;
                            break;
                        } else {
                            //添加质押银行下的库区数据
                            DicArea deptDic = new DicArea();
                            deptDic.setCode(dept.getId());
                            deptDic.setName(dept.getKqmc());
 
                            List<DicArea> children = pledgeBank.getChildren();
                            if (null == children) {
                                pledgeBank.setChildren(new ArrayList<>());
                            }
                            pledgeBank.getChildren().add(deptDic);
                            //更新list中的质押银行数据
                            areaChildren.set(indexBank, pledgeBank);
                            isPledge = true;
                            break;
                        }
                    }
 
                }
                if (!isPledge) {
                    DicArea deptDic = new DicArea();
                    deptDic.setCode(dept.getId());
                    deptDic.setName(dept.getKqmc());
 
                    List<DicArea> children = defaultBank.getChildren();
                    if (null == children) {
                        defaultBank.setChildren(new ArrayList<>());
                    }
                    defaultBank.getChildren().add(deptDic);
                }
            }
            List<DicArea> defaultBankChildren = defaultBank.getChildren();
            if (defaultBankChildren.size() > 0) {
                areaChildren.add(defaultBank);
            }
            area.setChildren(areaChildren);
        }
        list.add(area);
        return list;
    }
 
    /**
     * 获取用户下所有库区信息
     *
     * @return
     */
    public List<Dept> getDeptList() {
        return deptService.getDeptByUserType(null);
    }
 
    /**
     * 获取库区封装信息
     *
     * @param companyId
     * @return
     */
    public List<GroupDeptData> getDeptData(String companyId) {
 
        List<GroupDeptData> list = new ArrayList<>();
        GroupDeptData deptData;
        List<Dept> deptList = deptService.getDeptByUserType(null);
        if (null != deptList && !deptList.isEmpty()) {
            List<Depot> depotList;
            for (Dept dept : deptList) {
                deptData = new GroupDeptData();
                deptData.setDeptId(dept.getId());
                deptData.setDeptName(dept.getKqmc());
                deptData.setCode(dept.getXzqhdm());
                deptData.setCounty(dept.getXzqhmc());
                deptData.setJd(dept.getJd());
                deptData.setWd(dept.getWd());
 
                //统计仓库数
                depotList = depotService.getCacheDepotList(dept.getCompanyId(), dept.getId());
                if (null != depotList && !depotList.isEmpty()) {
                    for (Depot depot : depotList) {
                        deptData.setDepotNumber(deptData.getDepotNumber() + 1);
 
                        if (StringUtils.isNotBlank(depot.getPledgeBank())) {
                            deptData.setDepotBankNumber(deptData.getDepotBankNumber() + 1);
                        }
 
                        if (null == depot.getStorageReal()) {
                            depot.setStorageReal(0.0);
                        }
                        deptData.setStorageNum(deptData.getStorageNum() + depot.getStorageReal() / 1000);
                    }
                }
 
                //统计出入库数量
                InoutParam inoutParam = new InoutParam();
                inoutParam.setDeptId(dept.getId());
                inoutParam.setCompanyId(companyId);
                inoutParam.setStart(DateUtil.getCurZero(new Date()));
                inoutParam.setEnd(DateUtil.getNextZero(new Date()));
                List<InoutRecord> inoutRecords = inoutRecordService.listInout(inoutParam);
                if (null != inoutRecords && !inoutRecords.isEmpty()) {
                    for (InoutRecord inoutRecord : inoutRecords) {
                        if (Constant.TYPE_IN.equals(inoutRecord.getType())) {
                            deptData.setInNum(deptData.getInNum() + 1);
                        }
                        if (Constant.TYPE_OUT.equals(inoutRecord.getType())) {
                            deptData.setOutNum(deptData.getOutNum() + 1);
 
                        }
                    }
                }
 
                list.add(deptData);
            }
        }
 
        return list;
    }
 
 
    /**
     * 获取库区封装信息
     *
     * @param companyId
     * @return
     */
    public List<GroupDepotData> getDepotData(String companyId) {
 
        List<GroupDepotData> list = new ArrayList<>();
        GroupDepotData depotData;
        List<Dept> deptList = deptService.getDeptByUserType(null);
        if (null != deptList && !deptList.isEmpty()) {
            List<Depot> depotList;
            for (Dept dept : deptList) {
                //统计仓库数
                depotList = depotService.getCacheDepotList(dept.getCompanyId(), dept.getId());
                if (null != depotList && !depotList.isEmpty()) {
                    for (Depot depot : depotList) {
                        depotData = new GroupDepotData();
                        depotData.setDeptId(dept.getId());
                        depotData.setDeptName(dept.getKqmc());
                        depotData.setCode(dept.getXzqhdm());
                        depotData.setCounty(dept.getXzqhmc());
                        depotData.setDepotId(depot.getId());
                        depotData.setDepotName(depot.getName());
                        if (null == depot.getStorageReal()) {
                            depot.setStorageReal(0.0);
                        }
                        depotData.setStorageNum(depot.getStorageReal() / 1000);
                        list.add(depotData);
                    }
                }
            }
        }
        return list;
    }
 
    /**
     * 获取库区下监控信息
     *
     * @param param
     * @return
     */
    public PageResponse<List<Camera>> cameraList(IgdsBaseParam param) {
 
        if (StringUtils.isBlank(param.getDeptId())) {
            return new PageResponse<>(RespCodeEnum.CODE_2000, null);
        }
 
        if (StringUtils.isBlank(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
 
        List<Camera> listCamera = cameraService.getCameraByDeptId(param.getCompanyId(), param.getDeptId());
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, listCamera);
    }
 
    /**
     * 大屏首页统计信息:企业数、库区数、仓库数、质押仓数、散粮及成品粮数、分品种库存数
     *
     * @param param
     * @return
     */
    public PageResponse<GroupIndexData> getGroupIndexData(IgdsBaseParam param) {
 
        GroupIndexData indexData = new GroupIndexData();
 
        //企业数
        Integer companyNum = coreCompanyService.getCompanyNum(param.getCompanyId());
        indexData.setCompanyNum(companyNum);
 
        //库区数
        List<Dept> deptList = deptService.getDeptByUserType(null);
        if (null != deptList) {
            indexData.setDeptNum(deptList.size());
        }
 
        ///仓库数及质押仓库数
        List<Depot> depotList = depotService.getCacheDepotList(param.getCompanyId());
        if (null != depotList) {
            Double foodSum = 0.0;
            Double packFoodSum = 0.0;
            indexData.setDepotNum(depotList.size());
 
            //用于统计分品种库存
            LinkedHashMap<String, Double> varietyMap = new LinkedHashMap<>();
            for (Depot depot : depotList) {
                if (StringUtils.isNotBlank(depot.getPledgeBank())) {
                    indexData.setDepotBankNum(indexData.getDepotBankNum() + 1);
                }
                if (null == depot.getStorageReal()) {
                    depot.setStorageReal(0.0);
                }
                if (StringUtils.isNotBlank(depot.getStoreType()) && "2".equals(depot.getStoreType())) {
                    packFoodSum += depot.getStorageReal() / 1000;
                } else {
                    foodSum += depot.getStorageReal() / 1000;
                }
 
                if (depot.getStorageReal() > 0) {
                    if (StringUtils.isBlank(depot.getFoodVariety())) {
                        //设置为其他品类
                        depot.setFoodVariety("9999000");
                    }
 
                    varietyMap.putIfAbsent(depot.getFoodVariety(), 0.000);
                    varietyMap.put(depot.getFoodVariety(), varietyMap.get(depot.getFoodVariety()) + NumberUtil.keepPrecision(depot.getStorageReal() / 1000, 3));
                }
            }
 
            for (String mapKey : varietyMap.keySet()) {
                if (varietyMap.get(mapKey) <= 0) {
                    continue;
                }
                indexData.getXaxis().add(FoodVariety.getMsg(mapKey));
                indexData.getSeriesData().add(new DecimalFormat("0.000").format(varietyMap.get(mapKey)));
            }
            indexData.setFoodSum(new DecimalFormat("0.000").format(foodSum));
            indexData.setPackFoodSum(new DecimalFormat("0.000").format(packFoodSum));
        }
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, indexData);
    }
 
    /**
     * 大屏首页-库区信息统计
     *
     * @param param
     * @return
     */
    public PageResponse<List<GroupDeptData>> indexDeptList(IgdsBaseParam param) {
 
        List<GroupDeptData> list = new ArrayList<>();
        GroupDeptData deptData;
        List<Dept> deptList = deptService.getDeptByUserType(null);
        if (null != deptList && !deptList.isEmpty()) {
            List<Depot> depotList;
            for (Dept dept : deptList) {
                deptData = new GroupDeptData();
                deptData.setDeptId(dept.getId());
                deptData.setDeptName(dept.getKqmc());
                deptData.setCode(dept.getXzqhdm());
                deptData.setCounty(dept.getXzqhmc());
                deptData.setJd(dept.getJd());
                deptData.setWd(dept.getWd());
 
                //统计仓库数
                depotList = depotService.getCacheDepotList(dept.getCompanyId(), dept.getId());
                if (null != depotList && !depotList.isEmpty()) {
                    for (Depot depot : depotList) {
                        deptData.setDepotNumber(deptData.getDepotNumber() + 1);
 
                        if (StringUtils.isNotBlank(depot.getPledgeBank())) {
                            deptData.setDepotBankNumber(deptData.getDepotBankNumber() + 1);
                        }
 
                        if (null == depot.getStorageReal()) {
                            depot.setStorageReal(0.0);
                        }
                        deptData.setStorageNum(deptData.getStorageNum() + depot.getStorageReal() / 1000);
                    }
                }
 
                //统计出入库数量
                InoutParam inoutParam = new InoutParam();
                inoutParam.setDeptId(dept.getId());
                inoutParam.setCompanyId(param.getCompanyId());
                inoutParam.setStart(DateUtil.getCurZero(new Date()));
                inoutParam.setEnd(DateUtil.getNextZero(new Date()));
                List<InoutRecord> inoutRecords = inoutRecordService.listInout(inoutParam);
                if (null != inoutRecords && !inoutRecords.isEmpty()) {
                    for (InoutRecord inoutRecord : inoutRecords) {
                        if (Constant.TYPE_IN.equals(inoutRecord.getType())) {
                            deptData.setInNum(deptData.getInNum() + 1);
                        }
                        if (Constant.TYPE_OUT.equals(inoutRecord.getType())) {
                            deptData.setOutNum(deptData.getOutNum() + 1);
 
                        }
                    }
                }
 
                //统计AI事件数量
                IgdsBaseParam igdsParam = new IgdsBaseParam();
                igdsParam.setDeptId(dept.getId());
                igdsParam.setCompanyId(param.getCompanyId());
                igdsParam.setStart(DateUtil.getNewByDay(new Date(), -6));
                igdsParam.setEnd(DateUtil.getNextZero(new Date()));
                List<EventInfo> enevtList = eventInfoService.getListByParam(igdsParam);
                List<EventInfo> resultEnevtList = new ArrayList<>();
                for (EventInfo info : enevtList) {
                    //当标签包含 卡车, 或者包含大写的英文字母(代表有车牌)时,添加进result
                    if (StringUtils.isNotBlank(info.getTags())) {
                        if (info.getTags().contains("卡车") || info.getTags().matches(".*[A-Z].*")) {
                            resultEnevtList.add(info);
                        }
                    }
                }
                if (null != resultEnevtList && !resultEnevtList.isEmpty()) {
                    deptData.setWarnNum7(resultEnevtList.size());
                    for (EventInfo eventInfo : resultEnevtList) {
                        if (DateFormatUtils.format(new Date(), "yyyyMMdd").equals(DateFormatUtils.format(eventInfo.getTime(), "yyyyMMdd"))) {
                            deptData.setDailyTotal(deptData.getDailyTotal() + 1);
                        }
                    }
                }
                //判断网关是否在线
                GatewaySer cacheSerByDeptId = gatewaySerService.getCacheSerByDeptId(dept.getId());
                if (null == cacheSerByDeptId || (null != cacheSerByDeptId && StringUtils.isNotBlank(cacheSerByDeptId.getStatus()) && cacheSerByDeptId.getStatus().equals(Constant.YN_N))) {
                    deptData.setDailyTotal(-1);
                }
                list.add(deptData);
            }
        }
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, list);
    }
 
    /**
     * 统计gis数据,只统计登录人下属的数据统计
     *
     * @return
     */
    public GroupGisData getGisData() {
 
        GroupGisData groupGisData = new GroupGisData();
 
        //查询伊犁下属区县
        //区县
        List<DicArea> dicAreaList = dicAreaService.listData("654000", null, null);
 
        //统计区县下库区数
        LinkedHashMap<String, Integer> valuePieChart = new LinkedHashMap<>();
        LinkedHashMap<String, String> namePieChart = new LinkedHashMap<>();
        if (null != dicAreaList && !dicAreaList.isEmpty()) {
            for (DicArea dicArea : dicAreaList) {
                valuePieChart.put(dicArea.getCode(), 0);
                namePieChart.put(dicArea.getCode(), dicArea.getName());
            }
        }
        List<Dept> deptList = deptService.getDeptByUserType(null);
        if (null != deptList && !deptList.isEmpty()) {
            //库区总数
            groupGisData.setDeptNum(deptList.size());
            for (Dept dept : deptList) {
                if (StringUtils.isBlank(dept.getXzqhdm()) || null == valuePieChart.get(dept.getXzqhdm())) {
                    if (null == valuePieChart.get("999999")) {
                        valuePieChart.put("999999", 0);
                        namePieChart.put("999999", "其他区县");
                    }
                    dept.setXzqhdm("999999");
                }
                valuePieChart.put(dept.getXzqhdm(), valuePieChart.get(dept.getXzqhdm()) + 1);
            }
        }
 
        if (groupGisData.getDeptNum() > 0) {
            for (String mapKey : valuePieChart.keySet()) {
                groupGisData.getDeptList().add(new ChartPie(valuePieChart.get(mapKey) + "", namePieChart.get(mapKey), new DecimalFormat("0.0").format((double) valuePieChart.get(mapKey) / groupGisData.getDeptNum() * 100)));
            }
        }
 
        //统计重量
        List<Depot> depotList = depotService.getData(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), false);
        if (null != depotList && !depotList.isEmpty()) {
            for (Depot depot : depotList) {
                if (null == depot.getStorageReal()) {
                    depot.setStorageReal(0.0);
                }
                groupGisData.setSum(groupGisData.getSum() + depot.getStorageReal());
                if (StringUtils.isNotBlank(depot.getPledgeBank())) {
                    groupGisData.setBankSum(groupGisData.getBankSum() + depot.getStorageReal());
                } else {
                    groupGisData.setNormalSum(groupGisData.getNormalSum() + depot.getStorageReal());
                }
            }
        }
        if (groupGisData.getSum() > 0) {
            groupGisData.setSumPer(new DecimalFormat("0.00").format(groupGisData.getSum() / groupGisData.getSum() * 100L));
            groupGisData.setBankSumPer(new DecimalFormat("0.00").format(groupGisData.getBankSum() / groupGisData.getSum() * 100L));
            groupGisData.setNormalSumPer(new DecimalFormat("0.00").format(groupGisData.getNormalSum() / groupGisData.getSum() * 100L));
        }
 
        return groupGisData;
    }
 
 
    public GroupGisData getGisDataByCompanyId() {
 
        GroupGisData groupGisData = new GroupGisData();
 
        //查询伊犁下属区县
        //区县
        List<DicArea> dicAreaList = dicAreaService.listData("654000", null, null);
 
        //统计区县下库区数
        LinkedHashMap<String, Integer> valuePieChart = new LinkedHashMap<>();
        LinkedHashMap<String, String> namePieChart = new LinkedHashMap<>();
        if (null != dicAreaList && !dicAreaList.isEmpty()) {
            for (DicArea dicArea : dicAreaList) {
                valuePieChart.put(dicArea.getCode(), 0);
                namePieChart.put(dicArea.getCode(), dicArea.getName());
            }
        }
        List<Dept> deptList = deptService.getDeptByUserType(null);
        if (null != deptList && !deptList.isEmpty()) {
            //库区总数
            groupGisData.setDeptNum(deptList.size());
            for (Dept dept : deptList) {
                if (StringUtils.isBlank(dept.getXzqhdm()) || null == valuePieChart.get(dept.getXzqhdm())) {
                    if (null == valuePieChart.get("999999")) {
                        valuePieChart.put("999999", 0);
                        namePieChart.put("999999", "其他区县");
                    }
                    dept.setXzqhdm("999999");
                }
                valuePieChart.put(dept.getXzqhdm(), valuePieChart.get(dept.getXzqhdm()) + 1);
            }
        }
 
        if (groupGisData.getDeptNum() > 0) {
            for (String mapKey : valuePieChart.keySet()) {
                groupGisData.getDeptList().add(new ChartPie(valuePieChart.get(mapKey) + "", namePieChart.get(mapKey), new DecimalFormat("0.0").format((double) valuePieChart.get(mapKey) / groupGisData.getDeptNum() * 100)));
            }
        }
 
        //统计重量
        List<Depot> depotList = depotService.getCacheDepotList(ContextUtil.getCompanyId());
        if (null != depotList && !depotList.isEmpty()) {
            for (Depot depot : depotList) {
                if (null == depot.getStorageReal()) {
                    depot.setStorageReal(0.0);
                }
                groupGisData.setSum(groupGisData.getSum() + depot.getStorageReal());
                if (StringUtils.isNotBlank(depot.getPledgeBank())) {
                    groupGisData.setBankSum(groupGisData.getBankSum() + depot.getStorageReal());
                } else {
                    groupGisData.setNormalSum(groupGisData.getNormalSum() + depot.getStorageReal());
                }
            }
        }
        if (groupGisData.getSum() > 0) {
            groupGisData.setSumPer(new DecimalFormat("0.00").format(groupGisData.getSum() / groupGisData.getSum() * 100L));
            groupGisData.setBankSumPer(new DecimalFormat("0.00").format(groupGisData.getBankSum() / groupGisData.getSum() * 100L));
            groupGisData.setNormalSumPer(new DecimalFormat("0.00").format(groupGisData.getNormalSum() / groupGisData.getSum() * 100L));
        }
 
        return groupGisData;
    }
 
    /**
     * 大屏首页-抓拍跟踪信息
     *
     * @param param
     * @return
     */
    public PageResponse<List<SnapRecord>> indexSnapList(IgdsBaseParam param) {
 
        param.setStart(DateUtil.getNewByDay(new Date(), -10));
        param.setEnd(new Date());
        List<SnapRecord> listSnap = snapRecordService.getListByParam(param);
 
        List<SnapRecord> resultListSnap = new ArrayList<>();
        for (SnapRecord info : listSnap) {
            //当标签包含 卡车, 或者包含大写的英文字母(代表有车牌)时,添加进result
            if (StringUtils.isNotBlank(info.getTags())) {
                if (info.getTags().contains("卡车") || info.getTags().matches(".*[A-Z].*")) {
                    resultListSnap.add(info);
                }
            }
        }
        if (null != resultListSnap && !resultListSnap.isEmpty()) {
            //判断文件是否存在
            for (SnapRecord record : resultListSnap) {
                record.setImgName(commonManager.isImgExit(record.getImgName(), null));
            }
        }
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, resultListSnap);
    }
 
 
    /**
     * 大屏首页-抓拍跟踪信息-展示AI时间图片
     * 展示图片的业务逻辑:每个库区展示一张,图片为当天十点以后最新的一张
     * @param param
     * @return
     */
    public PageResponse<List<EventInfo>> indexEventInfoList(IgdsBaseParam param) {
//        Date start =DateUtils.setHours(DateUtil.getNewByDay(new Date(), -3), 10);
        //param.setStart(start);
//        param.setEnd(DateUtil.getNewByDay(new Date(), -3));
        Date start =DateUtils.setHours(new Date(), 10);
        param.setStart(start);
        param.setEnd(new Date());
        //获取当日的抓拍信息
        List<EventInfo> listByParam = eventInfoService.getListByParam(param);
        if (null == listByParam || listByParam.isEmpty()) {
            return new PageResponse<>(RespCodeEnum.CODE_0000, new ArrayList<>());
        }
        //筛选time大于Start时间的数据
        listByParam = listByParam.stream().filter(info -> info.getTime().after(start)).collect(Collectors.toList());
 
        //获取所有的库区信息
        List<Dept> deptList = deptService.getDeptByUserType(null);
        //根据库区从listByParam来获取每一个库区下,最新的一张抓拍图片
        List<EventInfo> resultList = new ArrayList<>();
 
        for (Dept dept : deptList) {
            EventInfo latestEvent = null;
                //从listByParam中筛选出与当前id匹配的数据
            List<EventInfo> collect = listByParam.stream().filter(info -> info.getDeptId().equals(dept.getId())).collect(Collectors.toList());
            if (!collect.isEmpty()) {
                //根据时间排序并找到最新一条数据
                latestEvent = collect.stream().sorted(Comparator.comparing(EventInfo::getTime).reversed()).findFirst().get();
            }
            if (latestEvent != null) {
                resultList.add(latestEvent);
            }
        }
        if (null != resultList && !resultList.isEmpty()) {
            //判断文件是否存在
            for (EventInfo record : resultList) {
                record.setImgName(commonManager.isImgExit(record.getImgName(), null));
            }
        }
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, resultList);
    }
}