puzhibing
2023-05-31 0a6f905b50a88993da05b9b3114394fb91dbc7d0
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
package com.stylefeng.guns.modular.system.controller.general;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.GunsApplication;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.state.Order;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.controller.resp.TOrderServerResp;
import com.stylefeng.guns.modular.system.controller.util.HttpUtils;
import com.stylefeng.guns.modular.system.enums.OrderStateEnum;
import com.stylefeng.guns.modular.system.enums.StatusEnum;
import com.stylefeng.guns.modular.system.model.TAgent;
import com.stylefeng.guns.modular.system.model.TDriver;
import com.stylefeng.guns.modular.system.model.TDriverWork;
import com.stylefeng.guns.modular.system.model.TOrder;
import com.stylefeng.guns.modular.system.pojo.GaoDePoJo;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDate;
import java.time.Period;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2023-03-14 15:15:19
 */
@Controller
@RequestMapping("/tHomePage")
public class THomePageController extends BaseController {
 
    private final static Logger log = LoggerFactory.getLogger(THomePageController.class);
 
    @Autowired
    private IUserService userService;
    @Autowired
    private ITAgentService tAgentService;
    @Autowired
    private ITDriverService tDriverService;
    @Autowired
    private ITOrderService tOrderService;
    @Autowired
    private ITRevenueService tRevenueService;
    @Autowired
    private ITDriverWorkService tDriverWorkService;
    @Autowired
    private GaoDePoJo gaoDePoJo;
    @Autowired
    private HttpUtils httpUtils;
    @Autowired
    private RedisUtil redisUtil;
 
    private String PREFIX = "/system/tHomePage/";
 
    /**
     * 跳转到地图
     */
    @RequestMapping("/map")
    public String map(Integer agentId,Integer type,Model model) {
 
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 3 && Objects.nonNull(objectId)){
            agentId = objectId;
        }
 
        // 查询所有代理商
        List<TAgent> agentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                .ne("status", StatusEnum.DELETE.getCode())
                .ne("principal",""));
        model.addAttribute("agentList",agentList);
        // 查询广东省广州市的地址解析
        Map<String, String> map = geocode("广东省广州市");
        model.addAttribute("addressLon",map.get("addressLon"));
        model.addAttribute("addressLat",map.get("addressLat"));
        // 查询广东全区域数据 查询广东所有的代理商
        List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                .eq("provinceCode", "440000"));
        List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList());
        // 查询统计在线司机,待接单,服务中,已完成,已取消
        List<TDriver> onLineDriver = tDriverService.selectList(new EntityWrapper<TDriver>()
                .in("agentId", ids));
        List<TAgent> tAgentAllList = tAgentService.selectList(new EntityWrapper<TAgent>());
        List<Integer> allIds = tAgentAllList.stream().map(TAgent::getId).collect(Collectors.toList());
        tOrderService.getDataStatisticsCountByIds(allIds,model);
 
        // 查询服务中的订单列表
        List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerListByIds(allIds);
        List<TOrder> orderList = tOrderService.selectList(new EntityWrapper<TOrder>());
        // 查询司机
        for (TOrderServerResp tOrderServerResp : orderServerRespList) {
            TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId());
            tOrderServerResp.setAvatar(tDriver.getAvatar());
            tOrderServerResp.setDriverName(tDriver.getName());
            List<TOrder> collect = orderList.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) &&
                    (order.getState().equals(OrderStateEnum.WAIT_PAY.getCode())
                            || order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode())
                            || order.getState().equals(OrderStateEnum.FINISH.getCode()))).collect(Collectors.toList());
            // 驾龄
            Period period = Period.between(LocalDate.now(), DateUtil.dateToLocalDate(tDriver.getFirstCertificateTime()));
            tOrderServerResp.setDrivingExperience(Math.max(Math.abs(period.getYears()), 1));
            // 代驾次数
            tOrderServerResp.setValetDrivingCount(collect.size());
            // 行驶时间
            long goTime = 0;
            for (TOrder tOrder : collect) {
                // 下车时间
                Date getoffTime = tOrder.getGetoffTime();
                // 上车时间
                Date boardingTime = tOrder.getBoardingTime();
                long minutes = Duration.between(DateUtil.dateToLocalDate(getoffTime), DateUtil.dateToLocalDate(boardingTime)).toMinutes();
                goTime += Math.abs(minutes);
            }
            tOrderServerResp.setGoTime(Long.valueOf(goTime).intValue());
            // 行驶里程
            int sum = collect.stream().mapToInt(TOrder::getActualMileage).sum();
            tOrderServerResp.setMileageTraveled(sum/1000);
        }
        model.addAttribute("serverList",orderServerRespList);
        // 查询今天所有订单
        List<TOrder> allList = tOrderService.getDataStatisticsAllListByIds(ids,type);
        List<List<String>> list = new ArrayList<>(allList.size());
        for (TOrder tOrder : allList) {
            List<String> obj = new ArrayList<>(3);
            obj.add(tOrder.getStartLng());
            obj.add(tOrder.getStartLat());
            obj.add(String.valueOf(tOrder.getState()));
            list.add(obj);
        }
        model.addAttribute("allList",list);
        List<List<String>> list1 = new ArrayList<>();
        AtomicInteger count = new AtomicInteger(0);
        for (TDriver tDriver : onLineDriver) {
 
            String value1 = redisUtil.getValue("DRIVER_" + tDriver.getPhone());
            String value2 = redisUtil.getValue(value1);
            if(ToolUtil.isNotEmpty(value2)){
                count.addAndGet(1);
            }
 
            List<String> obj = new ArrayList<>(3);
            String value = redisUtil.getValue("DRIVER" + tDriver.getId());
            if(ToolUtil.isEmpty(value)){
                continue;
            }
            obj.add(value.split(",")[0]);// 经度
            obj.add(value.split(",")[1]);// 纬度
            obj.add(String.valueOf(tDriver.getServerStatus()));// 服务状态
            list1.add(obj);
        }
        model.addAttribute("onLineDriverCount",count.get());
        // 拿到所有在线司机地址
        model.addAttribute("onLineDriver",list1);
        return PREFIX + "tHomePageMap.html";
    }
 
    @RequestMapping("/getMap")
    @ResponseBody
    public Object getMap(Integer agentId,Integer type,Model model) {
        Integer objectId = Objects.requireNonNull(ShiroKit.getUser()).getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 3 && Objects.nonNull(objectId)){
            agentId = objectId;
        }
        HashMap<String, Object> map = new HashMap<>();
        // 查询所有代理商
        List<TAgent> agentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                .ne("status", StatusEnum.DELETE.getCode())
                .ne("principal",""));
 
        map.put("agentList",agentList);
        if(Objects.nonNull(agentId)){
            // 查询当前代理商
            TAgent tAgent = tAgentService.selectById(agentId);
            Map<String, String> mapAddress = geocode(tAgent.getProvinceName()+tAgent.getCityName());
            map.put("addressLon",mapAddress.get("addressLon"));
            map.put("addressLat",mapAddress.get("addressLat"));
            // 查询统计在线司机,待接单,服务中,已完成,已取消
            List<TDriver> onLineDriver = tDriverService.selectList(new EntityWrapper<TDriver>()
                    .eq("agentId", agentId));
            List<TAgent> tAgentAllList = tAgentService.selectList(new EntityWrapper<TAgent>());
            List<Integer> allIds = tAgentAllList.stream().map(TAgent::getId).collect(Collectors.toList());
            tOrderService.getDataStatisticsCountByIdsGetMap(allIds,map);
 
            // 查询服务中的订单列表
            List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerListByIds(allIds);
            List<TOrder> orderList = tOrderService.selectList(new EntityWrapper<TOrder>());
            // 查询司机
            for (TOrderServerResp tOrderServerResp : orderServerRespList) {
                TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId());
                tOrderServerResp.setAvatar(tDriver.getAvatar());
                tOrderServerResp.setDriverName(tDriver.getName());
                List<TOrder> collect = orderList.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) &&
                        (order.getState().equals(OrderStateEnum.WAIT_PAY.getCode())
                                || order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode())
                                || order.getState().equals(OrderStateEnum.FINISH.getCode()))).collect(Collectors.toList());
                // 驾龄
                if(Objects.nonNull(tDriver.getFirstCertificateTime())){
                    Period period = Period.between(LocalDate.now(), DateUtil.dateToLocalDate(tDriver.getFirstCertificateTime()));
                    tOrderServerResp.setDrivingExperience(Math.max(Math.abs(period.getYears()), 1));
                }else {
                    tOrderServerResp.setDrivingExperience(0);
                }
                // 代驾次数
                tOrderServerResp.setValetDrivingCount(collect.size());
                // 行驶时间
                long goTime = 0;
                for (TOrder tOrder : collect) {
                    // 下车时间
                    Date getoffTime = tOrder.getGetoffTime();
                    // 上车时间
                    Date boardingTime = tOrder.getBoardingTime();
                    long minutes = Duration.between(DateUtil.dateToLocalDateTime(getoffTime), DateUtil.dateToLocalDateTime(boardingTime)).toMinutes();
                    goTime += Math.abs(minutes);
                }
                tOrderServerResp.setGoTime(Long.valueOf(goTime).intValue());
                // 行驶里程
                if(CollectionUtils.isEmpty(collect)){
                    tOrderServerResp.setMileageTraveled(0);
                }else {
                    int sum = collect.stream().mapToInt(TOrder::getActualMileage).sum();
                    tOrderServerResp.setMileageTraveled(sum/1000);
                }
            }
            map.put("serverList",orderServerRespList);
            // 查询今天所有订单
            List<TOrder> allList = tOrderService.getDataStatisticsAllList(agentId,type);
            List<List<String>> list = new ArrayList<>(allList.size());
            for (TOrder tOrder : allList) {
                List<String> obj = new ArrayList<>(3);
                obj.add(tOrder.getStartLng());
                obj.add(tOrder.getStartLat());
                obj.add(String.valueOf(tOrder.getState()));
                list.add(obj);
            }
            map.put("allList",list);
            List<List<String>> list1 = new ArrayList<>();
            for (TDriver tDriver : onLineDriver) {
                List<String> obj = new ArrayList<>(3);
                String value = redisUtil.getValue("DRIVER" + tDriver.getId());
                if(ToolUtil.isEmpty(value)){
                    continue;
                }
                obj.add(value.split(",")[0]);// 经度
                obj.add(value.split(",")[1]);// 纬度
                obj.add(String.valueOf(tDriver.getServerStatus()));// 服务状态
                list1.add(obj);
            }
            map.put("onLineDriverCount",list1.size());
            // 拿到所有在线司机地址
            map.put("onLineDriver",list1);
        }else {
            List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                    .eq("provinceCode", "440000"));
            List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList());
            // 查询统计在线司机,待接单,服务中,已完成,已取消
            List<TDriver> onLineDriver = tDriverService.selectList(new EntityWrapper<TDriver>()
                    .in("agentId", ids));
 
            Map<String, String> mapAddress = geocode("广东省广州市");
            map.put("addressLon",mapAddress.get("addressLon"));
            map.put("addressLat",mapAddress.get("addressLat"));
 
            List<TAgent> tAgentAllList = tAgentService.selectList(new EntityWrapper<TAgent>());
            List<Integer> allIds = tAgentAllList.stream().map(TAgent::getId).collect(Collectors.toList());
            tOrderService.getDataStatisticsCountByIdsGetMap(allIds,map);
 
            // 查询服务中的订单列表
            List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerListByIds(allIds);
            List<TOrder> orderList = tOrderService.selectList(new EntityWrapper<TOrder>());
            // 查询司机
            for (TOrderServerResp tOrderServerResp : orderServerRespList) {
                TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId());
                tOrderServerResp.setAvatar(tDriver.getAvatar());
                tOrderServerResp.setDriverName(tDriver.getName());
                List<TOrder> collect = orderList.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) &&
                        (order.getState().equals(OrderStateEnum.WAIT_PAY.getCode())
                                || order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode())
                                || order.getState().equals(OrderStateEnum.FINISH.getCode()))).collect(Collectors.toList());
                // 驾龄
                if(Objects.nonNull(tDriver.getFirstCertificateTime())){
                    Period period = Period.between(LocalDate.now(), DateUtil.dateToLocalDate(tDriver.getFirstCertificateTime()));
                    tOrderServerResp.setDrivingExperience(Math.max(Math.abs(period.getYears()), 1));
                }else {
                    tOrderServerResp.setDrivingExperience(0);
                }
                // 代驾次数
                tOrderServerResp.setValetDrivingCount(collect.size());
                // 行驶时间
                long goTime = 0;
                for (TOrder tOrder : collect) {
                    // 下车时间
                    Date getoffTime = tOrder.getGetoffTime();
                    // 上车时间
                    Date boardingTime = tOrder.getBoardingTime();
                    long minutes = Duration.between(DateUtil.dateToLocalDateTime(getoffTime), DateUtil.dateToLocalDateTime(boardingTime)).toMinutes();
                    goTime += Math.abs(minutes);
                }
                tOrderServerResp.setGoTime(Long.valueOf(goTime).intValue());
                // 行驶里程
                if(CollectionUtils.isEmpty(collect)){
                    tOrderServerResp.setMileageTraveled(0);
                }else {
                    int sum = collect.stream().mapToInt(TOrder::getActualMileage).sum();
                    tOrderServerResp.setMileageTraveled(sum/1000);
                }
            }
            map.put("serverList",orderServerRespList);
 
            // 查询今天所有订单
            List<TOrder> allList = tOrderService.getDataStatisticsAllListByIds(allIds,type);
            List<List<String>> list = new ArrayList<>(allList.size());
            for (TOrder tOrder : allList) {
                List<String> obj = new ArrayList<>(3);
                obj.add(tOrder.getStartLng());
                obj.add(tOrder.getStartLat());
                obj.add(String.valueOf(tOrder.getState()));
                list.add(obj);
            }
            map.put("allList",list);
            List<List<String>> list1 = new ArrayList<>();
            for (TDriver tDriver : onLineDriver) {
                List<String> obj = new ArrayList<>(3);
                String value = redisUtil.getValue("DRIVER" + tDriver.getId());
                if(ToolUtil.isEmpty(value)){
                    continue;
                }
                obj.add(value.split(",")[0]);// 经度
                obj.add(value.split(",")[1]);// 纬度
                obj.add(String.valueOf(tDriver.getServerStatus()));// 服务状态
                list1.add(obj);
            }
            map.put("onLineDriverCount",list1.size());
            // 拿到所有在线司机地址
            map.put("onLineDriver",list1);
        }
        return map;
    }
 
    @RequestMapping("/getServerOrder")
    @ResponseBody
    public Object getServerOrder(Integer agentId,Model model) {
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 3 && Objects.nonNull(objectId)){
            agentId = objectId;
        }
        HashMap<String, Object> map = new HashMap<>();
        if(Objects.nonNull(agentId)){
            List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>());
            List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList());
            // 查询服务中的订单列表
            List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerListByIds(ids);
            List<TOrder> orderList = tOrderService.selectList(new EntityWrapper<TOrder>());
            // 查询司机
            for (TOrderServerResp tOrderServerResp : orderServerRespList) {
                TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId());
                tOrderServerResp.setAvatar(tDriver.getAvatar());
                tOrderServerResp.setDriverName(tDriver.getName());
                List<TOrder> collect = orderList.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) &&
                        (order.getState().equals(OrderStateEnum.WAIT_PAY.getCode())
                                || order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode())
                                || order.getState().equals(OrderStateEnum.FINISH.getCode()))).collect(Collectors.toList());
                // 驾龄
                if(Objects.nonNull(tDriver.getFirstCertificateTime())){
                    Period period = Period.between(LocalDate.now(), DateUtil.dateToLocalDate(tDriver.getFirstCertificateTime()));
                    tOrderServerResp.setDrivingExperience(Math.max(Math.abs(period.getYears()), 1));
                }else {
                    tOrderServerResp.setDrivingExperience(0);
                }
                // 代驾次数
                tOrderServerResp.setValetDrivingCount(collect.size());
                // 行驶时间
                long goTime = 0;
                for (TOrder tOrder : collect) {
                    // 下车时间
                    Date getoffTime = tOrder.getGetoffTime();
                    // 上车时间
                    Date boardingTime = tOrder.getBoardingTime();
                    long minutes = Duration.between(DateUtil.dateToLocalDateTime(getoffTime), DateUtil.dateToLocalDateTime(boardingTime)).toMinutes();
                    goTime += Math.abs(minutes);
                }
                tOrderServerResp.setGoTime(Long.valueOf(goTime).intValue());
                // 行驶里程
                if(CollectionUtils.isEmpty(collect)){
                    tOrderServerResp.setMileageTraveled(0);
                }else {
                    int sum = collect.stream().mapToInt(TOrder::getActualMileage).sum();
                    tOrderServerResp.setMileageTraveled(sum/1000);
                }
            }
            map.put("serverList",orderServerRespList);
        }else {
            List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>());
            List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList());
            // 查询服务中的订单列表
            List<TOrderServerResp> orderServerRespList = tOrderService.getDataStatisticsServerListByIds(ids);
            List<TOrder> orderList = tOrderService.selectList(new EntityWrapper<TOrder>());
            // 查询司机
            for (TOrderServerResp tOrderServerResp : orderServerRespList) {
                TDriver tDriver = tDriverService.selectById(tOrderServerResp.getDriverId());
                tOrderServerResp.setAvatar(tDriver.getAvatar());
                tOrderServerResp.setDriverName(tDriver.getName());
                List<TOrder> collect = orderList.stream().filter(order -> tDriver.getId().equals(order.getDriverId()) &&
                        (order.getState().equals(OrderStateEnum.WAIT_PAY.getCode())
                                || order.getState().equals(OrderStateEnum.WAIT_EVALUATED.getCode())
                                || order.getState().equals(OrderStateEnum.FINISH.getCode()))).collect(Collectors.toList());
                // 驾龄
                if(Objects.nonNull(tDriver.getFirstCertificateTime())){
                    Period period = Period.between(LocalDate.now(), DateUtil.dateToLocalDate(tDriver.getFirstCertificateTime()));
                    tOrderServerResp.setDrivingExperience(Math.max(Math.abs(period.getYears()), 1));
                }else {
                    tOrderServerResp.setDrivingExperience(0);
                }
                // 代驾次数
                tOrderServerResp.setValetDrivingCount(collect.size());
                // 行驶时间
                long goTime = 0;
                for (TOrder tOrder : collect) {
                    // 下车时间
                    Date getoffTime = tOrder.getGetoffTime();
                    // 上车时间
                    Date boardingTime = tOrder.getBoardingTime();
                    long minutes = Duration.between(DateUtil.dateToLocalDateTime(getoffTime), DateUtil.dateToLocalDateTime(boardingTime)).toMinutes();
                    goTime += Math.abs(minutes);
                }
                tOrderServerResp.setGoTime(Long.valueOf(goTime).intValue());
                // 行驶里程
                if(CollectionUtils.isEmpty(collect)){
                    tOrderServerResp.setMileageTraveled(0);
                }else {
                    int sum = collect.stream().mapToInt(TOrder::getActualMileage).sum();
                    tOrderServerResp.setMileageTraveled(sum/1000);
                }
            }
            map.put("serverList",orderServerRespList);
        }
        return map;
    }
 
    /**
     * 跳转到首页统计
     */
    @RequestMapping("/statistics")
    public String statistics(Integer agentId,String dayDate,String yearDate,String monthDate,Integer type,Model model) {
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 3 && Objects.nonNull(objectId)){
            agentId = objectId;
        }
        if(Objects.isNull(type)){
            type = 1;
        }
        model.addAttribute("txt",new SimpleDateFormat("yyyy年MM月dd日").format(new Date()) + DateUtil.getWeekDay(new Date()) + ",欢迎" +
                Objects.requireNonNull(ShiroKit.getUser()).getName() + "登录");
        // 查询所有代理商
        List<TAgent> agentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                .ne("status", StatusEnum.DELETE.getCode())
                .ne("principal",""));
        model.addAttribute("agentList",agentList);
        Map<String, Object> map = new HashMap<>();
        if(Objects.nonNull(agentId)){
            // 统计代理商
            tAgentService.getDataStatistics(agentId,model,map);
 
            // 统计司机数
            tDriverService.getDataStatistics(agentId,model,map);
 
            // 订单统计本月
            tOrderService.getStatisticsOrderByMonth(agentId,dayDate,model,map);
 
            // 订单统计,每年按月份
            tOrderService.getDataStatisticsByYear(agentId,yearDate,model,map);
 
            // 业绩排名 performanceTable
            if (1 == type){
                // 单量
                tOrderService.getDataStatisticsOrderCount(agentId,monthDate,model,map);
            }else {
                // 收入、佣金
                tRevenueService.getDataStatisticsIncomeOrCommission(agentId,monthDate,type,model,map);
            }
 
        }else {
            // 查询广东全区域数据 查询广东所有的代理商
            List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                    .eq("provinceCode", "440000"));
            List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList());
            // 统计代理商
            tAgentService.getDataStatisticsByIds(ids,model,map);
 
            // 统计司机数
            tDriverService.getDataStatisticsByIds(ids,model,map);
 
            // 订单统计本月
            tOrderService.getStatisticsOrderByMonthIds(ids,dayDate,model,map);
 
            // 订单统计,每年按月份
            tOrderService.getDataStatisticsByYearByIds(ids,yearDate,model,map);
 
            // 业绩排名 performanceTable
            if (1 == type){
                // 单量
                tOrderService.getDataStatisticsOrderCountByIds(ids,monthDate,model,map);
            }else {
                // 收入、佣金
                tRevenueService.getDataStatisticsIncomeOrCommissionByIds(ids,monthDate,type,model,map);
            }
        }
        return PREFIX + "tHomePageStatistics.html";
    }
 
 
    /**
     * 首页统计通过代理商查询
     */
    @RequestMapping("/statisticsByAgentId")
    @ResponseBody
    public Map<String, Object> statisticsByAgentId(Integer agentId, String dayDate, String yearDate, String monthDate, Integer type, Model model) {
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 3 && Objects.nonNull(objectId)){
            agentId = objectId;
        }
        Map<String, Object> map = new HashMap<>();
        if(Objects.nonNull(agentId)){
            // 统计代理商
            tAgentService.getDataStatistics(agentId,model,map);
 
            // 统计司机数
            tDriverService.getDataStatistics(agentId,model,map);
 
            // 订单统计本月
            tOrderService.getStatisticsOrderByMonth(agentId,dayDate,model,map);
 
            // 订单统计,每年按月份
            tOrderService.getDataStatisticsByYear(agentId,yearDate,model,map);
 
            // 业绩排名 performanceTable
            if (1 == type){
                // 单量
                tOrderService.getDataStatisticsOrderCount(agentId,monthDate,model,map);
            }else {
                // 收入、佣金
                tRevenueService.getDataStatisticsIncomeOrCommission(agentId,monthDate,type,model,map);
            }
 
        }
        return map;
    }
 
    /**
     * 首页统计通过代理商查询订单量 今天,昨天,本周,本月
     */
    @RequestMapping("/statisticsMonthByAgentId")
    @ResponseBody
    public Map<String, Object> statisticsMonthByAgentId(Integer agentId, String dayDate,Model model) {
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 3 && Objects.nonNull(objectId)){
            agentId = objectId;
        }
        dayDate = new SimpleDateFormat("yyyy-MM").format(new Date());
        Map<String, Object> map = new HashMap<>();
        if(Objects.nonNull(agentId)){
            // 订单统计本月
            tOrderService.getStatisticsOrderByMonth(agentId,dayDate,model,map);
        }else {
            // 查询广东全区域数据 查询广东所有的代理商
            List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                    .eq("provinceCode", "440000"));
            List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList());
            // 订单统计本月
            tOrderService.getStatisticsOrderByMonthIds(ids,dayDate,model,map);
        }
        return map;
    }
 
    /**
     * 首页统计通过代理商查询订单量 按年
     */
    @RequestMapping("/statisticsYearByAgentId")
    @ResponseBody
    public Map<String, Object> statisticsYearByAgentId(Integer agentId, String yearDate,Model model) {
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 3 && Objects.nonNull(objectId)){
            agentId = objectId;
        }
        if(!StringUtils.hasLength(yearDate)){
            yearDate = new SimpleDateFormat("yyyy").format(new Date());
        }
        Map<String, Object> map = new HashMap<>();
        if(Objects.nonNull(agentId)){
            // 订单统计,每年按月份
            tOrderService.getDataStatisticsByYear(agentId,yearDate,model,map);
        }else {
            // 查询广东全区域数据 查询广东所有的代理商
            List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                    .eq("provinceCode", "440000"));
            List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList());
            tOrderService.getDataStatisticsByYearByIds(ids,yearDate,model,map);
        }
        return map;
    }
 
    /**
     * 首页统计通过代理商查询订单量,收入,佣金 按年
     */
    @RequestMapping("/statisticsOrderByAgentId")
    @ResponseBody
    public Map<String, Object> statisticsOrderByAgentId(Integer agentId, String monthDate,Integer type,Model model) {
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 3 && Objects.nonNull(objectId)){
            agentId = objectId;
        }
        if(Objects.isNull(type)){
            type = 1;
        }
        if(!StringUtils.hasLength(monthDate)){
            monthDate = new SimpleDateFormat("yyyy-MM").format(new Date());
        }
        Map<String, Object> map = new HashMap<>();
        if(Objects.nonNull(agentId)){
            // 业绩排名 performanceTable
            if (1 == type){
                // 单量
                tOrderService.getDataStatisticsOrderCount(agentId,monthDate,model,map);
            }else {
                // 收入、佣金
                tRevenueService.getDataStatisticsIncomeOrCommission(agentId,monthDate,type,model,map);
            }
        }else {
            // 业绩排名 performanceTable
            List<TAgent> tAgentList = tAgentService.selectList(null);
            List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList());
            if (1 == type){
                // 单量
                tOrderService.getDataStatisticsOrderCountByIds(ids,monthDate,model,map);
            }else {
                // 收入、佣金
                tRevenueService.getDataStatisticsIncomeOrCommissionByIds(ids,monthDate,type,model,map);
            }
        }
        return map;
    }
 
    /**
     * 首页统计通过代理商查询司机数量
     */
    @RequestMapping("/statisticsDriverByAgentId")
    @ResponseBody
    public Map<String, Object> statisticsDriverByAgentId(Integer agentId,Model model) {
        Integer objectId = ShiroKit.getUser().getObjectId();
        Integer roleType = ShiroKit.getUser().getRoleType();
        if(roleType == 3 && Objects.nonNull(objectId)){
            agentId = objectId;
        }
        Map<String, Object> map = new HashMap<>();
        if(Objects.nonNull(agentId)){
            // 统计司机数
            tDriverService.getDataStatistics(agentId,model,map);
            tAgentService.getDataStatistics(agentId,model,map);
        }else {
            // 统计司机数
            // 查询广东全区域数据 查询广东所有的代理商
            List<TAgent> tAgentList = tAgentService.selectList(new EntityWrapper<TAgent>()
                    .eq("provinceCode", "440000"));
            List<Integer> ids = tAgentList.stream().map(TAgent::getId).collect(Collectors.toList());
            tDriverService.getDataStatisticsByIds(ids,model,map);
            tAgentService.getDataStatisticsByIds(ids,model,map);
        }
        return map;
    }
 
    private Map<String,String> geocode(String address){
        Map<String,String> map = new HashMap<>(2);
        try {
            String url = "https://restapi.amap.com/v3/geocode/geo?address=" + address + "&key=" + gaoDePoJo.getKey();
            url = url.trim().replace("#", "").replace(" ", "");
            String result = httpUtils.get(url);
            log.info("地址解析结果:{}", result);
            JSONObject jsonObject = JSONObject.parseObject(result);
            if (jsonObject.getString("status").equals("1")) {
                String geocodes = jsonObject.getString("geocodes");
                JSONArray objects = JSONObject.parseArray(geocodes);
                String string = objects.getString(0);
                JSONObject geocodesObject = JSONObject.parseObject(string);
                log.info("地址数据:{}", geocodesObject);
                String location = geocodesObject.getString("location");
                String[] split = location.split(",");
                map.put("addressLon",split[0]);
                map.put("addressLat",split[1]);
            }
        } catch (Exception e) {
            log.error("解析地址失败============:{}", e.getMessage());
            e.printStackTrace();
        }
        return map;
    }
 
}