longz
2026-06-30 bcfeaf551a586ab6898bf6dc5c5995e2e03a4f11
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
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
package com.stylefeng.guns.modular.system.util;
 
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
 
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
 
/**
 * socket推单处理类
 */
@Component
public class PushUtil {
 
    @Autowired
    private IOrderTaxiService orderTaxiService;
 
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
 
    @Autowired
    private IOrderPrivateCarService orderPrivateCarService;
    
    @Autowired
    private IOrderCrossCityService orderCrossCityService;
    
    @Autowired
    private RedisTemplate redisTemplate;
    
    @Autowired
    private IOrderLogisticsService orderLogisticsService;
    
    private Map<String, Timer> taskMap = new HashMap<>();//存储定时推送的定时器
    
    @Value("${qyt.socket_uri}")
    private String socket_uri;
    
    
 
 
 
    // qyt 改派重新推单
    public void pushOrderState(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state, Integer time) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
        jsonObject.put("method", "ORDER_STATUS");
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        map.put("time", time);
        if (orderType == 1 && state == 100) {
            map.put("carpooling", 1);
            map.put("state", 2);
        } else {
            map.put("state", state);
        }
        jsonObject.put("data", map);
 
        //调用推送
        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        //将请求头部和参数合成一个请求
        Map<String, Object> params = new HashMap<>();
        params.put("msg", jsonObject.toJSONString());
        params.put("id", uid);
        params.put("type", type);
        params.put("bussinessType", "dache");
        post.form(params);
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            System.err.println("推送异常");
        } else {
            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
            if (jsonObject1.getIntValue("code") != 200) {
                System.err.println(jsonObject1.getString("msg"));
            }
        }
    }
 
 
    /**
     * 推单完成后,没有司机接单的推送提醒  qyt
     *
     * @param type
     * @param uid
     * @param orderId
     * @param orderType
     */
    public void pushEndPush(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
        jsonObject.put("method", "END_PUSH");
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        map.put("state", state);
        jsonObject.put("data", map);
 
        //调用推送
        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        //将请求头部和参数合成一个请求
        Map<String, Object> params = new HashMap<>();
        params.put("msg", jsonObject.toJSONString());
        params.put("id", uid);
        params.put("type", type);
        params.put("bussinessType", "dache");
        post.form(params);
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            System.err.println("推送异常");
        } else {
            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
            if (jsonObject1.getIntValue("code") != 200) {
                System.err.println(jsonObject1.getString("msg"));
            }
        }
    }
 
 
    /**
     * 改派推单结束
      * @param type
     * @param uid
     * @param orderId
     * @param orderType
     * @param state
     */
    public void pushReassignEndCancel(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
        jsonObject.put("method", "REASSIGN_END_CANCEL");
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        map.put("state", state);
        jsonObject.put("data", map);
 
        //调用推送
        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        //将请求头部和参数合成一个请求
        Map<String, Object> params = new HashMap<>();
        params.put("msg", jsonObject.toJSONString());
        params.put("id", uid);
        params.put("type", type);
        params.put("bussinessType", "dache");
        post.form(params);
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            System.err.println("推送异常");
        } else {
            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
            if (jsonObject1.getIntValue("code") != 200) {
                System.err.println(jsonObject1.getString("msg"));
            }
        }
 
    }
 
 
 
    /**
     * 推送订单状态
     *
     * @param type      1=用户,2=司机
     * @param uid       对象id
     * @param orderId   订单id
     * @param orderType 订单类型(1=专车,2=出租车,3=城际,4=小件物流-同城,5=小件物流-跨城,6=包车)
     * @param state     订单状态(1=待接单,2=待出发,3=待到达预约地点,4=待乘客上车,5=服务中,6=完成服务,7=待支付,8=待评价,9=已完成,10=已取消,11=改派中)
     */
    public void pushOrderState(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
        jsonObject.put("method", "ORDER_STATUS");
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        map.put("state", state);
        jsonObject.put("data", map);
        
        //调用推送
        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        //将请求头部和参数合成一个请求
        Map<String, Object> params = new HashMap<>();
        params.put("msg", jsonObject.toJSONString());
        params.put("id", uid);
        params.put("type", type);
        params.put("bussinessType", "dache");
        post.form(params);
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            System.err.println("推送异常");
        } else {
            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
            if (jsonObject1.getIntValue("code") != 200) {
                System.err.println(jsonObject1.getString("msg"));
            }
        }
        
    }
 
 
    /**
     * 改派完成后推送用户端提醒
     * @param uid
     * @param orderId
     * @param orderType
     */
    public void pushOrderReassign(Integer uid, Integer type, Integer orderId, Integer orderType){
        System.out.println("改派完成后推送用户端提醒");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
        jsonObject.put("method", "REASSIGN");
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        jsonObject.put("data", map);
    
        //调用推送
        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        //将请求头部和参数合成一个请求
        Map<String, Object> params = new HashMap<>();
        params.put("msg", jsonObject.toJSONString());
        params.put("id", uid);
        params.put("type", type);
        params.put("bussinessType", "dache");
        post.form(params);
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            System.err.println("推送异常");
        } else {
            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
            if (jsonObject1.getIntValue("code") != 200) {
                System.err.println(jsonObject1.getString("msg"));
            }
        }
    }
 
    /**
     * 推送改派确认请求给目标司机(Socket推送)
     * @param driverId 目标司机ID
     * @param reassignIds 改派记录ID列表(逗号分隔)
     * @param orderIds 订单ID列表(逗号分隔)
     * @param startSite 线路起点站点
     * @param endSite 线路终点站点
     * @param totalPeopleNumber 总人数
     * @param travelTime 出行时间
     * @param expireTime 超时时间
     */
    public void pushReassignConfirmRequest(Integer driverId, String reassignIds, String orderIds,
                                           String startSite, String endSite, Integer totalPeopleNumber,
                                           String travelTime, String expireTime) {
        System.out.println("推送改派确认请求给司机: driverId=" + driverId + ", reassignIds=" + reassignIds);
 
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
        jsonObject.put("method", "REASSIGN_CONFIRM_REQUEST");
 
        Map<String, Object> map = new HashMap<>();
        map.put("reassignIds", reassignIds); // 改派记录ID列表(逗号分隔)
        map.put("orderIds", orderIds);
        map.put("startSite", startSite);
        map.put("endSite", endSite);
        map.put("routeInfo", startSite + " → " + endSite);
        map.put("totalPeopleNumber", totalPeopleNumber);
        map.put("travelTime", travelTime);
        map.put("expireTime", expireTime);
 
        jsonObject.put("data", map);
 
        // 调用推送
        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
 
        // 将请求头部和参数合成一个请求
        Map<String, Object> params = new HashMap<>();
        params.put("msg", jsonObject.toJSONString());
        params.put("id", driverId);
        params.put("type", 2); // type=2 表示司机端
        params.put("bussinessType", "dache");
        post.form(params);
 
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            System.err.println("改派确认请求推送异常");
        } else {
            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
            if (jsonObject1.getIntValue("code") != 200) {
                System.err.println("改派确认请求推送失败: " + jsonObject1.getString("msg"));
            } else {
                System.out.println("改派确认请求推送成功: driverId=" + driverId);
            }
        }
    }
 
    /**
     * 通知原司机改派结果(Socket推送)
     * @param driverId 原司机ID
     * @param reassignId 改派记录ID
     * @param orderId 订单ID
     * @param orderType 订单类型
     * @param resultType 结果类型(1=成功,2=拒绝,3=超时)
     */
    public void pushReassignResult(Integer driverId, Integer reassignId, Integer orderId, Integer orderType, Integer resultType) {
        String resultName = resultType == 1 ? "成功" : (resultType == 2 ? "被拒绝" : "超时");
        System.out.println("推送改派" + resultName + "通知给原司机: driverId=" + driverId + ", reassignId=" + reassignId);
 
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
        jsonObject.put("method", "REASSIGN_RESULT");
 
        Map<String, Object> map = new HashMap<>();
        map.put("type", resultType); // 1=成功,2=拒绝,3=超时
        map.put("reassignId", reassignId);
        map.put("orderId", orderId);
        map.put("orderType", orderType);
 
        // 根据结果类型设置不同的提示消息
        String message;
        if (resultType == 1) {
            message = "您的改派申请已被接受";
        } else if (resultType == 2) {
            message = "对方拒绝了您的改派申请";
        } else {
            message = "改派申请已超时,请重新选择";
        }
        map.put("message", message);
 
        jsonObject.put("data", map);
 
        // 调用推送
        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
 
        Map<String, Object> params = new HashMap<>();
        params.put("msg", jsonObject.toJSONString());
        params.put("id", driverId);
        params.put("type", 2); // type=2 表示司机端
        params.put("bussinessType", "dache");
        post.form(params);
 
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            System.err.println("改派" + resultName + "通知推送异常");
        } else {
            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
            if (jsonObject1.getIntValue("code") != 200) {
                System.err.println("改派" + resultName + "通知推送失败: " + jsonObject1.getString("msg"));
            } else {
                System.out.println("改派" + resultName + "通知推送成功: driverId=" + driverId);
            }
        }
    }
 
    /**
     * 通知原司机改派成功(Socket推送)
     * @param driverId 原司机ID
     * @param reassignId 改派记录ID
     * @param orderId 订单ID
     * @param orderType 订单类型
     */
    public void pushReassignSuccess(Integer driverId, Integer reassignId, Integer orderId, Integer orderType) {
        pushReassignResult(driverId, reassignId, orderId, orderType, 1);
    }
 
    /**
     * 通知原司机改派被拒绝(Socket推送)
     * @param driverId 原司机ID
     * @param reassignId 改派记录ID
     * @param orderId 订单ID
     * @param orderType 订单类型
     */
    public void pushReassignRejected(Integer driverId, Integer reassignId, Integer orderId, Integer orderType) {
        pushReassignResult(driverId, reassignId, orderId, orderType, 2);
    }
 
    /**
     * 通知原司机改派超时(Socket推送)
     * @param driverId 原司机ID
     * @param reassignId 改派记录ID
     * @param orderId 订单ID
     * @param orderType 订单类型
     */
    public void pushReassignTimeout(Integer driverId, Integer reassignId, Integer orderId, Integer orderType) {
        pushReassignResult(driverId, reassignId, orderId, orderType, 3);
    }
 
 
    /**
     * 推送司机位置给乘客端
     */
    public void pushDriverPosition(Integer orderId, Integer orderType){
        Integer userId = null;
        switch (orderType){
            case 1:
                OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId);
                userId = orderPrivateCar.getUserId();
                break;
            case 2:
                OrderTaxi orderTaxi = orderTaxiService.selectById(orderId);
                userId = orderTaxi.getUserId();
                break;
            case 3:
                OrderCrossCity orderCrossCity = orderCrossCityService.selectById(orderId);
                userId = orderCrossCity.getUserId();
                break;
            case 4:
                OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId);
                userId = orderLogistics.getUserId();
                break;
            case 5:
                OrderLogistics orderLogistics1 = orderLogisticsService.selectById(orderId);
                userId = orderLogistics1.getUserId();
                break;
        }
        JSONObject data = new JSONObject();
        data.put("id", userId);
        data.put("type", 1);
        String value = (String) redisTemplate.opsForValue().get(orderId + "_" + orderType);
        if(ToolUtil.isEmpty(value)){
            redisTemplate.opsForValue().set(orderId + "_" + orderType, data.toJSONString());
            createTask(orderId, orderType);
        }
    }
 
 
    /**
     * 创建定时任务
     * @param orderId
     */
    public void createTask(Integer orderId, Integer orderType){
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                try {
                    PushUtil.this.pushPositon(orderId, orderType);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        Timer timer = new Timer();
        timer.schedule(task, 1000, 10000);//1秒后开始10秒钟一次的重复执行
        taskMap.put(orderId + "_" + orderType, timer);
    }
 
 
    /**
     * 推送处理方法
     * @param orderId
     * @param orderType
     * @throws Exception
     */
    public void pushPositon(Integer orderId, Integer orderType) throws Exception{
        Integer driverId = null;
        String startLonLat = null;
        String endLonLat = null;
        Integer state = 0;
        Integer oldState = 0;
        Long startServiceTime = null;
        Double servedMileage = null;
        switch (orderType){
            case 1:
                OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(orderId);
                if(orderPrivateCar == null){
                    this.removeTask(orderId, orderType);
                }else{
                    driverId = orderPrivateCar.getDriverId();
                    startLonLat = orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat();
                    state = orderPrivateCar.getState();
                    oldState = orderPrivateCar.getOldState();
                    startServiceTime = null != orderPrivateCar.getStartServiceTime() ? orderPrivateCar.getStartServiceTime().getTime() : null;
                    servedMileage = orderPrivateCar.getMileage();
                    endLonLat = orderPrivateCar.getEndLon() + "," + orderPrivateCar.getEndLat();
                }
                break;
            case 2:
                OrderTaxi orderTaxi = orderTaxiService.selectById(orderId);
                if(orderTaxi == null){
                    this.removeTask(orderId, orderType);
                }else{
                    driverId = orderTaxi.getDriverId();
                    startLonLat = orderTaxi.getStartLon() + "," + orderTaxi.getStartLat();
                    state = orderTaxi.getState();
                    oldState = orderTaxi.getOldState();
                    startServiceTime = null != orderTaxi.getStartServiceTime() ? orderTaxi.getStartServiceTime().getTime() : null;
                    servedMileage = orderTaxi.getMileage();
                    endLonLat = orderTaxi.getEndLon() + "," + orderTaxi.getEndLat();
                }
                break;
            case 3:
                OrderCrossCity orderCrossCity = orderCrossCityService.selectById(orderId);
                if(orderCrossCity == null){
                    this.removeTask(orderId, orderType);
                }else{
                    driverId = orderCrossCity.getDriverId();
                    startLonLat = orderCrossCity.getStartLon() + "," + orderCrossCity.getStartLat();
                    state = orderCrossCity.getState();
                    startServiceTime = null != orderCrossCity.getStartServiceTime() ? orderCrossCity.getStartServiceTime().getTime() : null;
                    servedMileage = orderCrossCity.getMileage();
                    endLonLat = orderCrossCity.getEndLon() + "," + orderCrossCity.getEndLat();
                }
                break;
            case 4:
                OrderLogistics orderLogistics = orderLogisticsService.selectById(orderId);
                if(orderLogistics == null){
                    this.removeTask(orderId, orderType);
                }else{
                    driverId = orderLogistics.getDriverId();
                    startLonLat = orderLogistics.getStartLon() + "," + orderLogistics.getStartLat();
                    state = orderLogistics.getState();
                    startServiceTime = null != orderLogistics.getStartServiceTime() ? orderLogistics.getStartServiceTime().getTime() : null;
                    servedMileage = orderLogistics.getMileage();
                    endLonLat = orderLogistics.getEndLon() + "," + orderLogistics.getEndLat();
                }
                break;
            case 5:
                OrderLogistics orderLogistics1 = orderLogisticsService.selectById(orderId);
                if(orderLogistics1 == null){
                    this.removeTask(orderId, orderType);
                }else{
                    driverId = orderLogistics1.getDriverId();
                    startLonLat = orderLogistics1.getStartLon() + "," + orderLogistics1.getStartLat();
                    state = orderLogistics1.getState();
                    startServiceTime = null != orderLogistics1.getStartServiceTime() ? orderLogistics1.getStartServiceTime().getTime() : null;
                    servedMileage = orderLogistics1.getMileage();
                    endLonLat = orderLogistics1.getEndLon() + "," + orderLogistics1.getEndLat();
                }
                break;
        }
        if(state == 7 || state == 8 || state == 9 || state == 10 || state == 12){//删除定时任务
            this.removeTask(orderId, orderType);
            return;
        }
        //计算预计距离和剩余时间
        String value = (String) redisTemplate.opsForValue().get("dache:DRIVER" + String.valueOf(driverId));
        if(null == value || "".equals(value)){
            return;
        }
        JSONObject msg = new JSONObject();
        msg.put("code", 200);
        msg.put("msg", "SUCCESS");
        msg.put("method", "DRIVER_POSITION");
        Map<String, String> map = new HashMap<>();
        map.put("orderId", String.valueOf(orderId));
        map.put("orderType", String.valueOf(orderType));
        map.put("lon", (null != value ? value.split(",")[0] : ""));
        map.put("lat", (null != value ? value.split(",")[1] : ""));
        if((state == 2 || state == 3 || state == 4) || (oldState != null && (oldState == 2 || oldState == 3 || oldState == 4))){//前往预约地
            // TODO: 2023/11/4  无法修改
            Map<String, String> distance = gdMapElectricFenceUtil.getDistance(value, startLonLat, 1);
            String d = "0";
            String t = "0";
            if(null == distance){
                System.err.println("查询距离出错了");
                return;
            }else{
                d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString();
                t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + "";
            }
            map.put("reservationMileage", d);//当前位置距离预约点的剩余里程
            map.put("reservationTime", t);//当前位置距离预约点的剩余分钟
            map.put("servedMileage", "0");//距离起点已经服务的里程
            map.put("servedTime", "0");//距离起点已经服务的时间
            map.put("laveMileage", "0");//距离终点剩余未服务的里程数
            map.put("laveTime", "0");//距离终端剩余未服务的预计时间
        }
 
        if((state == 5 || state == 6) || (oldState != null && (oldState == 5 || oldState == 6))){//服务中
            if(endLonLat.equals(",")){
                map.put("laveMileage", "0");//距离终点剩余未服务的里程数
                map.put("laveTime", "0");//距离终端剩余未服务的预计时间
            }else{
                map.put("reservationMileage", "0");//当前位置距离预约点的剩余里程
                map.put("reservationTime", "0");//当前位置距离预约点的剩余分钟
                map.put("servedMileage", String.valueOf((null == servedMileage ? 0 : servedMileage) / 1000));//距离起点已经服务的里程
                Integer servedTime = Long.valueOf((System.currentTimeMillis() - startServiceTime) / 60000).intValue();
                map.put("servedTime", servedTime + "");//距离起点已经服务的时间
                // TODO: 2023/11/4  无法修改
                Map<String, String> distance = gdMapElectricFenceUtil.getDistance(value, endLonLat, 1);
                String d = "0";
                String t = "0";
                if(null == distance){
                    System.err.println("查询距离出错了");
                }else{
                    d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).toString();
                    t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).intValue() + "";
                }
                map.put("laveMileage", d);//距离终点剩余未服务的里程数
                map.put("laveTime", t);//距离终端剩余未服务的预计时间
            }
    
        }
    
        msg.put("data", map);
    
        String value1 = (String) redisTemplate.opsForValue().get(orderId + "_" + orderType);
        if (ToolUtil.isEmpty(value1)) {
            this.removeTask(orderId, orderType);
            return;
        }
        JSONObject jsonObject = JSON.parseObject(value1);
    
        //调用推送
        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        //将请求头部和参数合成一个请求
        Map<String, Object> params = new HashMap<>();
        params.put("msg", msg.toJSONString());
        params.put("id", jsonObject.getIntValue("id"));
        params.put("type", jsonObject.getIntValue("type"));
        params.put("bussinessType", "dache");
        post.form(params);
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            System.err.println("推送异常");
        } else {
            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
            if (jsonObject1.getIntValue("code") != 200) {
                System.err.println(jsonObject1.getString("msg"));
            }
        }
    }
 
 
 
    /**
     * 推送强迫下线
     * @param id
     * @param type
     */
    public void pushOffline(Integer id, Integer type) {
        JSONObject msg = new JSONObject();
        msg.put("code", 200);
        msg.put("msg", "SUCCESS");
        msg.put("method", "OFFLINE");
        msg.put("data", new Object());
    
        //调用推送
        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        //将请求头部和参数合成一个请求
        Map<String, Object> params = new HashMap<>();
        params.put("msg", msg.toJSONString());
        params.put("id", id);
        params.put("type", type);
        params.put("bussinessType", "dache");
        post.form(params);
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            System.err.println("推送异常");
        } else {
            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
            if (jsonObject1.getIntValue("code") != 200) {
                System.err.println(jsonObject1.getString("msg"));
            }
        }
    }
 
 
 
 
    /**
     * 摆渡抢单成功后推单
     * @param type
     * @param uid
     * @param orderId
     * @param orderType
     * @param state
     */
    public void pushFerryOrderState(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
        jsonObject.put("method", "FERRY");
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        map.put("state", state);
        jsonObject.put("data", map);
    
        //调用推送
        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        //将请求头部和参数合成一个请求
        Map<String, Object> params = new HashMap<>();
        params.put("msg", jsonObject.toJSONString());
        params.put("id", uid);
        params.put("type", type);
        params.put("bussinessType", "dache");
        post.form(params);
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            System.err.println("推送异常");
        } else {
            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
            if (jsonObject1.getIntValue("code") != 200) {
                System.err.println(jsonObject1.getString("msg"));
            }
        }
    }
 
 
    /**
     * 小件物流差价支付的推送
     * @param type
     * @param uid
     * @param orderId
     * @param orderType
     * @param money
     */
    public void pushPayDifference(Integer type, Integer uid, Integer orderId, Integer orderType, Double money){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "SUCCESS");
        jsonObject.put("method", "DIFFERENCE");
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        map.put("orderType", orderType);
        map.put("money", money);
        jsonObject.put("data", map);
    
        //调用推送
        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        //将请求头部和参数合成一个请求
        Map<String, Object> params = new HashMap<>();
        params.put("msg", jsonObject.toJSONString());
        params.put("id", uid);
        params.put("type", type);
        params.put("bussinessType", "dache");
        post.form(params);
        HttpResponse execute = post.execute();
        if (200 != execute.getStatus()) {
            System.err.println("推送异常");
        } else {
            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
            if (jsonObject1.getIntValue("code") != 200) {
                System.err.println(jsonObject1.getString("msg"));
            }
        }
    }
 
 
    /**
     * 删除定时任务
     * @param orderId
     */
    public void removeTask(Integer orderId, Integer orderType){
        Timer timer = taskMap.get(orderId + "_" + orderType);
        if (null != timer){
            timer.cancel();
            taskMap.remove(orderId + "_" + orderType);
            redisTemplate.delete(orderId + "_" + orderType);
        }
    }
}