Pu Zhibing
6 天以前 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
package com.stylefeng.guns.modular.system.controller.specialTrain;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.shiro.ShiroUser;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.controller.util.PushUtil;
import com.stylefeng.guns.modular.system.dao.LineShiftDriverMapper;
import com.stylefeng.guns.modular.system.dao.OrderCancelMapper;
import com.stylefeng.guns.modular.system.dao.TCarModelMapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.GoogleMap.DistancematrixVo;
import com.stylefeng.guns.modular.system.util.GoogleMap.FleetEngineUtil;
import com.stylefeng.guns.modular.system.util.GoogleMap.GoogleMapUtil;
import com.stylefeng.guns.modular.system.util.*;
import com.stylefeng.guns.modular.system.util.quartz.QuartzUtil;
import com.stylefeng.guns.modular.system.util.quartz.jobs.OrderTimeOutJob;
import org.apache.shiro.util.StringUtils;
import org.quartz.JobDataMap;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * 专车改派管理控制器
 *
 * @author fengshuonan
 * @Date 2020-09-03 14:20:27
 */
@Controller
@RequestMapping("/tReassign")
public class TReassignController extends BaseController {
 
    private String PREFIX = "/system/tReassign/";
 
    @Autowired
    private ITReassignService tReassignService;
    
    @Autowired
    private PushUtil pushUtil;
 
    @Autowired
    private ITOrderPrivateCarService itOrderPrivateCarService;
 
    @Autowired
    private ITOrderCrossCityService itOrderCrossCityService;
 
    @Autowired
    private ITDriverService itDriverService;
 
    @Resource
    private LineShiftDriverMapper lineShiftDriverMapper;
 
    @Autowired
    private  ITDispatchService dispatchService;
 
    @Resource
    private OrderCancelMapper orderCancelMapper;
 
   /* @Autowired
    private ICBCPayUtil icbcPayUtil;*/
 
    @Autowired
    private ITUserService userService;
 
    @Autowired
    private ITransactionDetailsService transactionDetailsService;
 
    @Autowired
    private IPaymentRecordService paymentRecordService;
 
    @Autowired
    private IIncomeService incomeService;
 
    @Autowired
    private ITOrderLogisticsService orderLogisticsService;
    @Autowired
    private ITPubTransactionDetailsService itPubTransactionDetailsService;
    
    @Resource
    private QuartzUtil quartzUtil;
    
    @Resource
    private FleetEngineUtil fleetEngineUtil;
    
    @Resource
    private TCarModelMapper carModelMapper;
    
    @Resource
    private ITCarService carService;
    
    @Resource
    private RedisUtil redisUtil;
    
    @Resource
    private ITSysOverTimeService sysOvertimeService;
    
    @Resource
    private ITSysCancleOrderService cancleOrderService;
    
    @Resource
    private ITSystemNoticeService systemNoticeService;
    
    
 
    /**
     * 跳转到专车改派管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tReassign.html";
    }
 
    /**
     * 跳转到跨城出行改派管理首页
     */
    @RequestMapping("/cross")
    public String corse() {
        return PREFIX + "cross.html";
    }
 
    /**
     * 跳转到小件物流改派管理首页
     */
    @RequestMapping("/smallPieceLogistics")
    public String smallPieceLogistics() {
        return PREFIX + "smallPieceLogistics.html";
    }
 
    /**
     * 跳转到添加专车改派管理
     */
    @RequestMapping("/tReassign_add")
    public String tReassignAdd() {
        return PREFIX + "tReassign_add.html";
    }
 
    /**
     * 跳转到修改专车改派管理
     */
    @RequestMapping("/tReassign_update/{tReassignId}")
    public String tReassignUpdate(@PathVariable Integer tReassignId, Model model) {
        TReassign tReassign = tReassignService.selectById(tReassignId);
        model.addAttribute("item",tReassign);
        LogObjectHolder.me().set(tReassign);
        return PREFIX + "tReassign_edit.html";
    }
 
    /**
     * 跳转到修改专车改派管理
     */
    @RequestMapping("/tReassign_reassignment/{tReassignId}")
    public String tReassign_reassignment(@PathVariable Integer tReassignId, Model model) {
        model.addAttribute("tReassignId",tReassignId);
        return PREFIX + "tReassign_reassignment.html";
    }
 
    /**
     * 跳转到修改跨城改派管理
     */
    @RequestMapping("/tReassign_reassignmentCross/{tReassignId}")
    public String tReassign_reassignmentCross(@PathVariable Integer tReassignId, Model model) {
        model.addAttribute("tReassignId",tReassignId);
        return PREFIX + "tReassign_reassignmentCross.html";
    }
    
    /**
     * 跳转到修改跨城改派管理
     */
    @RequestMapping("/tReassign_reassignmentSmall/{tReassignId}")
    public String tReassign_reassignmentSmall(@PathVariable Integer tReassignId, Model model) {
        model.addAttribute("tReassignId",tReassignId);
        return PREFIX + "tReassign_reassignmentSmall.html";
    }
    
    @RequestMapping("/lookDetail/{id}")
    public String lookDetail(@PathVariable Integer id, Model model) {
        TReassign tReassign = tReassignService.selectById(id);
        String str = tReassign.getReason();
        model.addAttribute("str",str);
        return "/system/tComplaint/lookDetail.html";
    }
 
    /**
     * 获取专车改派管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String insertTime,
                       String originalDriverName,
                       String originalDriverPhone,
                       String orderNum,
                       String nowDriverName,
                       String nowDriverPhone,
                       Integer orderState,
                       Integer state) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(insertTime)){
            String[] timeArray = insertTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tReassignService.getPrivateCarReassignOrderList(page,ShiroKit.getUser().getRoleType(),ShiroKit.getUser().getObjectId(),beginTime,endTime,originalDriverName,originalDriverPhone,orderNum,nowDriverName,nowDriverPhone,orderState,state));
        return super.packForBT(page);
    }
 
    /**
     * 获取跨城改派管理列表
     */
    @RequestMapping(value = "/listCross")
    @ResponseBody
    public Object listCross(String insertTime,
                       String originalDriverName,
                       String originalDriverPhone,
                       String orderNum,
                       String nowDriverName,
                       String nowDriverPhone,
                       Integer orderState,
                       Integer state) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(insertTime)){
            String[] timeArray = insertTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tReassignService.getCrossReassignOrderList(page,ShiroKit.getUser().getRoleType(),ShiroKit.getUser().getObjectId(),beginTime,endTime,originalDriverName,originalDriverPhone,orderNum,nowDriverName,nowDriverPhone,orderState,state));
        return super.packForBT(page);
    }
 
    /**
     * 获取跨城改派管理列表
     */
    @RequestMapping(value = "/listSmallPieceLogistics")
    @ResponseBody
    public Object listSmallPieceLogistics(String insertTime,
                            String originalDriverName,
                            String originalDriverPhone,
                            String orderNum,
                            String nowDriverName,
                            String nowDriverPhone,
                            Integer orderState,
                            Integer state) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(insertTime)){
            String[] timeArray = insertTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tReassignService.getSmallPieceLogisticsList(page,ShiroKit.getUser().getRoleType(),ShiroKit.getUser().getObjectId(),beginTime,endTime,originalDriverName,originalDriverPhone,orderNum,nowDriverName,nowDriverPhone,orderState,state));
        return super.packForBT(page);
    }
 
    /**
     * 选择司机列表
     */
    @RequestMapping(value = "/selectDriver/{orderId}")
    @ResponseBody
    public Object selectDriver(@PathVariable Integer orderId,
                               String name,
                               String phone) {
        TReassign reassign = tReassignService.selectById(orderId);
        TOrderPrivateCar privateCar = itOrderPrivateCarService.selectById(reassign.getOrderId());
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tReassignService.getCanSelectPrivateCarDriverList(page,privateCar.getServerCarModelId(),privateCar.getDriverId(),name,phone));
        return super.packForBT(page);
    }
 
    /**
     * 选择司机列表
     */
    @RequestMapping(value = "/selectCrossDriver/{orderId}")
    @ResponseBody
    public Object selectCrossDriver(@PathVariable Integer orderId,
                                    String name,
                                    String phone) {
        TReassign reassign = tReassignService.selectById(orderId);
        TOrderCrossCity tOrderCrossCity = itOrderCrossCityService.selectById(reassign.getOrderId());
        LineShiftDriver lineShiftDriver = lineShiftDriverMapper.selectById(tOrderCrossCity.getLineShiftDriverId());
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tReassignService.getCanSelectCrossDriverList(page, tOrderCrossCity.getCompanyId(), tOrderCrossCity.getServerCarModelId(),
                tOrderCrossCity.getLineId(), lineShiftDriver.getLineShiftId(), tOrderCrossCity.getTravelTime(), tOrderCrossCity.getPeopleNumber(), name, phone, tOrderCrossCity.getDriverId()));
        return super.packForBT(page);
    }
 
    /**
     * 选择司机列表
     */
    @RequestMapping(value = "/selectSmallDriver/{orderId}")
    @ResponseBody
    public Object selectSmallDriver(@PathVariable Integer orderId,
                               String name,
                               String phone) {
        TReassign reassign = tReassignService.selectById(orderId);
        TOrderLogistics tOrderLogistics = orderLogisticsService.selectById(reassign.getOrderId());
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tReassignService.getCanSelectSmallDriverList(page,tOrderLogistics.getServerCarModelId(), tOrderLogistics.getDriverId(), tOrderLogistics.getType(),name,phone));
        return super.packForBT(page);
    }
 
    /**
     * 操作专车改派管理
     * optType 1=拒绝 2=取消
     */
    @RequestMapping(value = "/opt")
    @ResponseBody
    public Object opt(@RequestParam Integer tReassignId,@RequestParam Integer optType) {
        ShiroUser user = ShiroKit.getUser();
        TReassign tReassign = tReassignService.selectById(tReassignId);
        if (1 == optType){
            tReassign.setState(5);
            tReassignService.updateById(tReassign);
 
            //还原订单状态
            TOrderPrivateCar tOrderPrivateCar = itOrderPrivateCarService.selectById(tReassign.getOrderId());
            tOrderPrivateCar.setState(tOrderPrivateCar.getOldState());
            itOrderPrivateCarService.updateById(tOrderPrivateCar);
        }else if (2 == optType){
            tReassign.setState(4);
            tReassignService.updateById(tReassign);
 
            //修改订单状态"已取消"
            TOrderPrivateCar tOrderPrivateCar = itOrderPrivateCarService.selectById(tReassign.getOrderId());
            tOrderPrivateCar.setState(10);
            itOrderPrivateCarService.updateById(tOrderPrivateCar);
 
            //修改司机状态"空闲"
            TDriver driver = itDriverService.selectById(tReassign.getOriginalDriverId());
            driver.setState(2);
            itDriverService.updateById(driver);
 
            //添加取消记录
            OrderCancel orderCancel = new OrderCancel();
            orderCancel.setOrderId(tReassign.getOrderId());
            orderCancel.setOrderType(tReassign.getOrderType());
            orderCancel.setReason("The platform cancels the order");
            orderCancel.setRemark("The platform cancels the order");
            orderCancel.setState(2);
            orderCancel.setInsertTime(new Date());
            orderCancel.setUserType(3);
            orderCancel.setUserId(user.getId());
            orderCancelMapper.insert(orderCancel);
 
            //调用推送
            Map<String,String> map = new HashMap<>();
            map.put("id", tOrderPrivateCar.getId().toString());
            map.put("orderType", "1");
            map.put("from", "admin");
            String result = HttpRequestUtil.postRequest(PushURL.cancel_order_url, map);
            System.out.println("专车取消:【orderId="+tOrderPrivateCar.getId().toString()+"】,调用接口:"+result);
        }
 
        //返回驾驶员处罚金
//        TDriver originalDriver = itDriverService.selectById(tReassign.getOriginalDriverId());
//        originalDriver.setBalance(originalDriver.getBalance().add(new BigDecimal(tReassign.getMoney())));
//        itDriverService.updateById(originalDriver);
 
        //增加交易明细
//        TPubTransactionDetails details = new TPubTransactionDetails();
//        details.setUserId(originalDriver.getId());
//        details.setInsertTime(new Date());
//        details.setRemark("【专车改派】:改派失败或订单取消");
//        details.setMoney(new BigDecimal(tReassign.getMoney()));
//        details.setState(1);
//        details.setType(1);
//        details.setUserType(2);
//        details.setOrderType(3);
//        details.setOrderId(tReassign.getOrderId());
//        itPubTransactionDetailsService.insert(details);
        return SUCCESS_TIP;
    }
 
    /**
     * 操作跨城改派管理
     * optType 1=拒绝 2=取消
     */
    @RequestMapping(value = "/optCross")
    @ResponseBody
    public Object optCross(@RequestParam Integer tReassignId,@RequestParam Integer optType) {
        try {
            TReassign tReassign = tReassignService.selectById(tReassignId);
            ShiroUser user = ShiroKit.getUser();
            if (1 == optType){
                tReassign.setState(5);
                tReassign.setReviewer(user.getId());
                tReassign.setReviewerType(2);
                tReassignService.updateById(tReassign);
 
                //还原订单状态
                TOrderCrossCity tOrderCrossCity = itOrderCrossCityService.selectById(tReassign.getOrderId());
                tOrderCrossCity.setState(tOrderCrossCity.getOldState());
                itOrderCrossCityService.updateById(tOrderCrossCity);
            }else if (2 == optType){
                tReassign.setState(4);
                tReassign.setReviewer(user.getId());
                tReassign.setReviewerType(2);
                tReassignService.updateById(tReassign);
 
                TOrderCrossCity orderCrossCity = itOrderCrossCityService.selectById(tReassign.getOrderId());
                if(orderCrossCity.getState() > 5 && orderCrossCity.getState() != 11){
                    return ResultUtil.error("订单状态不在可取消范围内");
                }
                orderCrossCity.setState(10);
                itOrderCrossCityService.updateById(orderCrossCity);
 
                //修改司机信息
                LineShiftDriver lineShiftDriver = lineShiftDriverMapper.selectById(orderCrossCity.getLineShiftDriverId());
                lineShiftDriver.setLaveSeat(lineShiftDriver.getLaveSeat() + orderCrossCity.getPeopleNumber() > lineShiftDriver.getTotalSeat() ?
                        lineShiftDriver.getTotalSeat() : lineShiftDriver.getLaveSeat() + orderCrossCity.getPeopleNumber());
                String seat = "";
                String[] split = orderCrossCity.getSeatNumber().split(",");
                for(String s : split){
                    seat += s + ",";
                }
                seat = lineShiftDriver.getLaveSeatNumber() + "," + seat.substring(0, seat.length() - 1);
 
                //总和大于总座位数的情况
                if(lineShiftDriver.getLaveSeat() + orderCrossCity.getPeopleNumber() > lineShiftDriver.getTotalSeat()){
                    seat = "";
                    for(int i = 1; i <= lineShiftDriver.getTotalSeat(); i++){
                        seat += i + ",";
                    }
                    seat = seat.substring(0, seat.length() - 1);
                }
                lineShiftDriver.setLaveSeatNumber(seat);
                lineShiftDriverMapper.updateById(lineShiftDriver);
                if(lineShiftDriver.getLaveSeat() >= lineShiftDriver.getTotalSeat()){
                    TDriver driver = itDriverService.selectById(tReassign.getOriginalDriverId());
                    driver.setState(2);
                    itDriverService.updateById(driver);
                }
 
                //调用推送
                Map<String,String> map = new HashMap<>();
                map.put("id", orderCrossCity.getId().toString());
                map.put("orderType", "3");
                map.put("from", "admin");
                String result = HttpRequestUtil.postRequest(PushURL.cancel_order_url, map);
                System.out.println("跨城出行取消:【orderId="+orderCrossCity.getId().toString()+"】,调用接口:"+result);
 
 
                //已支付的情况下进行退款操作
                if(null != orderCrossCity.getPayType() && null != orderCrossCity.getPayMoney()){
                    if(orderCrossCity.getPayType() == 3){//余额支付
                        TUser tUser = userService.selectById(orderCrossCity.getUserId());
                        tUser.setBalance(tUser.getBalance().add(orderCrossCity.getPayMoney()));
                        userService.updateById(tUser);
                        //添加交易明细
                        transactionDetailsService.saveData(orderCrossCity.getUserId(), "跨城订单取消退款", orderCrossCity.getPayMoney().doubleValue(), 1, 1, 1, 3, tReassign.getOrderId());
                    }else{
                        PaymentRecord query = paymentRecordService.query(1, null, null, tReassign.getOrderId(), 3, null, 2);
                        if(null == query){
                            return ResultUtil.error("订单还未进行支付");
                        }
                        /*Map<String, Object> merrefund = icbcPayUtil.merrefund(query.getCode(), "", query.getAmount(), tReassign.getOrderId() + "_3", orderCrossCity.getOrderNum());
                        if(Integer.valueOf(merrefund.get("code").toString()) == 0){
                            boolean b = true;
                            while (b){
                                Map<String, Object> refundqry = icbcPayUtil.refundqry("", query.getCode(), orderCrossCity.getOrderNum());
                                if(Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 0){//成功
                                    //添加交易明细
                                    transactionDetailsService.saveData(orderCrossCity.getUserId(), "跨城订单取消退款", query.getAmount(), 1, 1, 1, 3, tReassign.getOrderId());
                                }
                                if(Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 1){//失败
                                    return ResultUtil.error("订单取消失败(退款不成功)");
                                }
                                if(Integer.valueOf(refundqry.get("code").toString()) == 0 && Integer.valueOf(refundqry.get("pay_status").toString()) == 2){//未知
                                    return ResultUtil.error("退款返回未知异常");
                                }
                            }
                        }*/
                    }
 
                    //添加负的收入明细
                    List<Income> incomes = incomeService.selectList(new EntityWrapper<Income>().eq("type", 2).eq("incomeId", tReassign.getOrderId()).eq("orderType", 3));
                    for(Income income : incomes){
                        if(income.getUserType() == 2){//处理司机的收入
                            TDriver driver = itDriverService.selectById(income.getObjectId());
                            driver.setBalance(driver.getBalance().subtract(new BigDecimal(income.getMoney())));
                            driver.setLaveBusinessMoney(new BigDecimal(driver.getLaveBusinessMoney()).subtract(new BigDecimal(income.getMoney())).doubleValue());
                            driver.setBusinessMoney(new BigDecimal(driver.getBusinessMoney()).subtract(new BigDecimal(income.getMoney())).doubleValue());
                            itDriverService.updateById(driver);
                        }
                        Income income1 = new Income();
                        BeanUtils.copyProperties(income, income1);
                        income1.setMoney(income.getMoney() * -1);
                        income1.setId(null);
                        income1.setInsertTime(new Date());
                        incomeService.insert(income1);
                    }
                }
 
                //添加取消记录
                OrderCancel orderCancel = new OrderCancel();
                orderCancel.setOrderId(tReassign.getOrderId());
                orderCancel.setOrderType(tReassign.getOrderType());
                orderCancel.setReason("The platform cancels the order");
                orderCancel.setRemark("The platform cancels the order");
                orderCancel.setState(2);
                orderCancel.setInsertTime(new Date());
                orderCancel.setUserType(3);
                orderCancel.setUserId(user.getId());
                orderCancelMapper.insert(orderCancel);
            }
 
            //返回驾驶员处罚金
            TDriver originalDriver = itDriverService.selectById(tReassign.getOriginalDriverId());
            originalDriver.setBalance(originalDriver.getBalance().add(new BigDecimal(tReassign.getMoney())));
            itDriverService.updateById(originalDriver);
 
            //增加交易明细
            TPubTransactionDetails details = new TPubTransactionDetails();
            details.setUserId(originalDriver.getId());
            details.setInsertTime(new Date());
            details.setRemark("【跨城改派】:改派失败或订单取消");
            details.setMoney(new BigDecimal(tReassign.getMoney()));
            details.setState(1);
            details.setType(1);
            details.setUserType(2);
            details.setOrderType(3);
            details.setOrderId(tReassign.getOrderId());
            itPubTransactionDetailsService.insert(details);
        }catch (Exception e){
            e.printStackTrace();
        }
        return SUCCESS_TIP;
    }
 
 
 
    /**
     * 操作专车改派管理
     * optType 1=拒绝 2=取消
     */
    @RequestMapping(value = "/optSmall")
    @ResponseBody
    public Object optSmall(@RequestParam Integer tReassignId,@RequestParam Integer optType) {
        ShiroUser user = ShiroKit.getUser();
        TReassign tReassign = tReassignService.selectById(tReassignId);
        if (1 == optType){
            tReassign.setState(5);
            tReassignService.updateById(tReassign);
 
            //还原订单状态
            TOrderLogistics tOrderLogistics = orderLogisticsService.selectById(tReassign.getOrderId());
            tOrderLogistics.setState(tOrderLogistics.getOldState());
            orderLogisticsService.updateById(tOrderLogistics);
        }else if (2 == optType){
            tReassign.setState(4);
            tReassignService.updateById(tReassign);
 
            //修改订单状态"已取消"
            TOrderLogistics tOrderLogistics = orderLogisticsService.selectById(tReassign.getOrderId());
            tOrderLogistics.setState(10);
            orderLogisticsService.updateById(tOrderLogistics);
 
            //添加取消记录
            OrderCancel orderCancel = new OrderCancel();
            orderCancel.setOrderId(tReassign.getOrderId());
            orderCancel.setOrderType(tReassign.getOrderType());
            orderCancel.setReason("The platform cancels the order");
            orderCancel.setRemark("The platform cancels the order");
            orderCancel.setState(2);
            orderCancel.setInsertTime(new Date());
            orderCancel.setUserType(3);
            orderCancel.setUserId(user.getId());
            orderCancelMapper.insert(orderCancel);
 
            //调用推送
            Map<String,String> map = new HashMap<>();
            map.put("id", tOrderLogistics.getId().toString());
            map.put("orderType", tOrderLogistics.getType().toString());
            map.put("from", "admin");
            String result = HttpRequestUtil.postRequest(PushURL.cancel_order_url, map);
            System.out.println("小件物流取消:【orderId="+tOrderLogistics.getId().toString()+"】,调用接口:"+result);
        }
 
//        //返回驾驶员处罚金
//        TDriver originalDriver = itDriverService.selectById(tReassign.getOriginalDriverId());
//        originalDriver.setBalance(originalDriver.getBalance().add(new BigDecimal(tReassign.getMoney())));
//        itDriverService.updateById(originalDriver);
//
//        //增加交易明细
//        TPubTransactionDetails details = new TPubTransactionDetails();
//        details.setUserId(originalDriver.getId());
//        details.setInsertTime(new Date());
//        details.setRemark("【小件物流】:改派失败或订单取消");
//        details.setMoney(new BigDecimal(tReassign.getMoney()));
//        details.setState(1);
//        details.setType(1);
//        details.setUserType(2);
//        details.setOrderType(tReassign.getOrderType());
//        details.setOrderId(tReassign.getOrderId());
//        itPubTransactionDetailsService.insert(details);
        return SUCCESS_TIP;
    }
 
 
    /**
     * 专车订单改派司机
     */
    @RequestMapping(value = "/selectDriver")
    @ResponseBody
    public Object selectDriver(@RequestParam Integer orderId,@RequestParam Integer driverId) {
        try {
            //修改订单
            TReassign tReassign = tReassignService.selectById(orderId);
            TOrderPrivateCar orderPrivateCar = itOrderPrivateCarService.selectById(tReassign.getOrderId());
            String tripId = redisUtil.getValue("trip" + orderPrivateCar.getUserId());
            TDriver driver = itDriverService.selectById(orderPrivateCar.getDriverId());
            TDriver driver1 = itDriverService.selectById(driverId);
            
            String text = "";
            tReassign.setState(3);
            tReassign.setNowDriverId(driver1.getId());
            tReassign.setNowCarId(driver1.getCarId());
            tReassign.setCompleteTime(new Date());
            tReassignService.updateById(tReassign);
    
    
            Integer language1 = driver1.getLanguage();
            switch (language1){
                case 1:
                    text = "收到新的打车订单,从" + orderPrivateCar.getStartAddress() + "出发,全程约" + orderPrivateCar.getEstimatedMileage() + "公里";
                    break;
                case 2:
                    text = "Received a new ride order, starting from " + orderPrivateCar.getStartAddress() + ", the whole journey is about " + orderPrivateCar.getEstimatedMileage() + "kilometre";
                    break;
                case 3:
                    text = "Reçu une nouvelle commande de course, à partir de " + orderPrivateCar.getStartAddress() + ", le trajet complet est d’environ " + orderPrivateCar.getEstimatedMileage();
                    break;
        
            }
            String audioUrl = "";
            String fileName = "pushOrder" + orderPrivateCar.getDriverId() + UUIDUtil.getRandomCode(5) + ".mp3";
            try {
                audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, fileName);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            //定时任务删除语音文件
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    try {
                        // 使用Runtime执行命令
                        Process process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + fileName);
                        // 读取命令的输出
                        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                        String line;
                        while ((line = reader.readLine()) != null) {
                            System.out.println(line);
                        }
                        // 等待命令执行完成
                        process.waitFor();
                        // 关闭流
                        reader.close();
                    } catch (IOException | InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }, 30000);
    
            orderPrivateCar.setDriverId(driver1.getId());
            orderPrivateCar.setCarId(driver1.getCarId());
            orderPrivateCar.setCompanyId(driver1.getFranchiseeId() != null && driver1.getFranchiseeId() != 0 ? driver1.getFranchiseeId() : (
                    driver1.getCompanyId() != null && driver1.getCompanyId() != 0 ? driver1.getCompanyId() : 1));
            orderPrivateCar.setSnatchOrderTime(new Date());
            orderPrivateCar.setState(orderPrivateCar.getOldState());
            orderPrivateCar.setOldState(null);
            if(!StringUtils.hasLength(orderPrivateCar.getTripId())){
                orderPrivateCar.setTripId(UUIDUtil.getRandomCode());
            }
    
            if(orderPrivateCar.getOrderType() == 1){
                String value = redisUtil.getValue("DRIVER" + driver1.getId());
                if(ToolUtil.isNotEmpty(value)) {
                    String[] split = value.split(",");
                    DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderPrivateCar.getStartLat(), orderPrivateCar.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0]), tripId);
                    //超时时间
                    long timeOut = System.currentTimeMillis() + (distancematrix.getDuration() * 1000);
                    orderPrivateCar.setEstimateArriveTime(new Date(timeOut));
                    orderPrivateCar.setEstimateArriveMileage(distancematrix.getDistance());
                }
            }
            itOrderPrivateCarService.updateAllColumnById(orderPrivateCar);
            driver1.setState(3);
            itDriverService.updateById(driver1);
    
            driver.setState(2);
            itDriverService.updateById(driver);
    
            //检查google车辆信息或者添加新的车辆信息
            TCar car = carService.selectById(orderPrivateCar.getCarId());
            if(ToolUtil.isEmpty(car.getVehicleId())){
                car.setVehicleId(UUIDUtil.getRandomCode());
                carService.updateById(car);
            }
            String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId());
            if(ToolUtil.isEmpty(vehicles)){
                TCarModel carModel = carModelMapper.selectById(car.getCarModelId());
                boolean createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
                if(!createVehicles){
                    for (int i = 0; i < 5; i++) {
                        createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
                        if(createVehicles){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
    
            //修改google订单信息或者创建新的行程
            String trip = fleetEngineUtil.getTrip(orderPrivateCar.getTripId());
            if(ToolUtil.isEmpty(trip)){
                JSONObject createTrip = fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderPrivateCar.getTripId(),
                        orderPrivateCar.getStartLat().toString(), orderPrivateCar.getStartLon().toString(),  orderPrivateCar.getEndLat().toString(), orderPrivateCar.getEndLon().toString());
                JSONObject error = createTrip.getJSONObject("error");
                if(null != error){
                    for (int i = 0; i < 5; i++) {
                        createTrip = fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderPrivateCar.getTripId(),
                                orderPrivateCar.getStartLat().toString(), orderPrivateCar.getStartLon().toString(),  orderPrivateCar.getEndLat().toString(), orderPrivateCar.getEndLon().toString());
                        error = createTrip.getJSONObject("error");
                        String tripStatus = createTrip.getString("tripStatus");
                        if(null == error && "NEW".equals(tripStatus)){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }else{
                //开始修改行程数据
                boolean updateTrip = fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderPrivateCar.getTripId(), null, null, null, null, orderPrivateCar.getId(), 1);
                if(!updateTrip){
                    for (int i = 0; i < 5; i++) {
                        updateTrip = fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderPrivateCar.getTripId(), null, null, null, null, orderPrivateCar.getId(), 1);
                        if(updateTrip){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
    
    
    
            //删除定时任务
            quartzUtil.deleteQuartzTask("1_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("2_1_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("2_2_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("3_" + orderPrivateCar.getId() + "_1","ORDER_TIME_OUT");
    
            /**
             * 超时用户取消不收费的提醒
             *   预约单:行程时间 + 配置不收费的时间 > 当前时间 (只弹一次)
             *   即时单:预估到达预约点时间 + 配置不收费的时间 > 当前时间 (只弹一次)
             *
             * 超时用户取消订单后需要弹给司机提醒弹框,超时时间 = 当前时间 - 行程时间 - 配置不收费的时间
             *
             * 定时提醒弹框
             *   司机只要开始超时且还未到达预约点,则需要定时提醒
             *
             * 预约单需要提前xx分钟提醒司机需要接乘客,过后每隔xx分钟提醒一次。超时后停止提醒
             */
    
            //添加定时任务(普通任务)
            TSysOverTime reminderRules = sysOvertimeService.selectOne(new EntityWrapper<TSysOverTime>().eq("companyId", driver1.getCompanyId()));
            if(null != reminderRules){
                TSysCancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<TSysCancleOrder>().eq("companyId", driver1.getCompanyId()));
                Integer driverTimeout = JSON.parseObject(cancleOrder.getContent()).getInteger("driverTimeout");
        
                //即时单
                if(orderPrivateCar.getOrderType() == 1){
                    //超时时间
                    long timeOut = orderPrivateCar.getEstimateArriveTime().getTime() + (driverTimeout * 60 * 1000);
                    //乘客取消不收费提醒
                    JobDataMap jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 1);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", timeOut);
                    jobDataMap.put("driverTimeout", driverTimeout);
                    jobDataMap.put("describe", language1 == 1 ? "您已超时" + driverTimeout + "分钟,用户可免费取消订单" : language1 == 2 ? "Reminder You are overdue for " + driverTimeout + " minutes The subscriber could cancel the order for free Confirm" : "Rappel Vous êtes en retard de " + driverTimeout + " minutes L’abonné peut annuler la commande gratuitement Confirmer");
                    quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "1_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , new Date(timeOut), timeOut, 0);
            
                    //超时循环提醒
                    jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 3);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", orderPrivateCar.getEstimateArriveTime().getTime());
                    jobDataMap.put("driverTimeout", 0);
                    jobDataMap.put("describe", "");
                    quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "3_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , orderPrivateCar.getEstimateArriveTime(), reminderRules.getCar() * 60000, -1);
                }else{
                    //超时时间
                    long timeOut = orderPrivateCar.getTravelTime().getTime() + (driverTimeout * 60000);
                    //乘客取消不收费提醒
                    JobDataMap jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 1);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", timeOut);
                    jobDataMap.put("driverTimeout", driverTimeout);
                    jobDataMap.put("describe", language1 == 1 ? "您已超时" + driverTimeout + "分钟,用户可免费取消订单" : language1 == 2 ? "Reminder You are overdue for " + driverTimeout + " minutes The subscriber could cancel the order for free Confirm" : "Rappel Vous êtes en retard de " + driverTimeout + " minutes L’abonné peut annuler la commande gratuitement Confirmer");
                    quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "1_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , new Date(timeOut), timeOut, 0);
            
            
                    TUser userInfo = userService.selectById(orderPrivateCar.getUserId());
            
                    //预约单出发首次提醒
                    long travelTime = orderPrivateCar.getTravelTime().getTime() - reminderRules.getReserveTime() * 60000;
                    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
                    jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 2);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", timeOut);
                    jobDataMap.put("driverTimeout", 0);
                    jobDataMap.put("describe", language1 == 1 ? "您将于" + sdf.format(orderPrivateCar.getTravelTime()) + "去接" + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName())  + ",请准时!" :
                            language1 == 2 ? "You are going to pick up " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " at " + sdf.format(orderPrivateCar.getTravelTime()) + ", please be on time. " :
                                    "Vous allez chercher " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " à " + sdf.format(orderPrivateCar.getTravelTime()) + ", s’il vous plaît soyez à l’heure.");
                    quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "2_1_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , new Date(travelTime), travelTime, 0);
            
                    //预约单出发循环提醒
                    jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 2);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", orderPrivateCar.getTravelTime().getTime());
                    jobDataMap.put("driverTimeout", 0);
                    jobDataMap.put("describe", language1 == 1 ? "您将于" + sdf.format(orderPrivateCar.getTravelTime()) + "去接" + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName())  + ",请准时!" :
                            language1 == 2 ? "You are going to pick up " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " at " + sdf.format(orderPrivateCar.getTravelTime()) + ", please be on time. " :
                                    "Vous allez chercher " + (ToolUtil.isEmpty(userInfo.getFirstName()) ? userInfo.getNickName() : userInfo.getFirstName() + " " + userInfo.getLastName()) + " à " + sdf.format(orderPrivateCar.getTravelTime()) + ", s’il vous plaît soyez à l’heure.");
                    quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "2_2_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , new Date(travelTime + reminderRules.getReserveNext() * 60000), reminderRules.getReserveNext() * 60000, -1);
            
                    //超时循环提醒
                    jobDataMap = new JobDataMap();
                    jobDataMap.put("driverId", driver1.getId());
                    jobDataMap.put("timeOutType", 3);
                    jobDataMap.put("orderId", orderPrivateCar.getId());
                    jobDataMap.put("orderType", 1);
                    jobDataMap.put("language", language1);
                    jobDataMap.put("timeOut", orderPrivateCar.getTravelTime().getTime());
                    jobDataMap.put("driverTimeout", 0);
                    jobDataMap.put("describe", "");
                    quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "3_" + orderPrivateCar.getId() + "_1", "ORDER_TIME_OUT", jobDataMap
                            , orderPrivateCar.getTravelTime(), reminderRules.getCar() * 60000, -1);
                }
            }
    
            //推送相关代码------------------start----------------
            String finalAudioUrl = audioUrl;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    pushUtil.pushOrderReassign(orderPrivateCar.getUserId(), 1, orderPrivateCar.getId(), 1, "");
                    pushUtil.pushOrderReassign(orderPrivateCar.getDriverId(), 2, orderPrivateCar.getId(), 1, finalAudioUrl);
                }
            }).start();
    
            Integer language2 = userService.selectById(orderPrivateCar.getUserId()).getLanguage();
            systemNoticeService.addSystemNotice(2, language1 == 1 ? "您已成功抢得打车订单,请及时联系客户!" :
                    language1 == 2 ? "You have grabbed the ride order, please contact the client timely."
                            : "Vous avez saisi la commande de course, veuillez contacter le client en temps opportun.", orderPrivateCar.getDriverId());
            systemNoticeService.addSystemNotice(1, language2 == 1 ? "您的订单已指派给" + driver1.getFirstName() + "师傅,请保持电话畅通!" :
                    language2 == 2 ? "Your order has been assigned to the driver- " + driver1.getFirstName() + ", please keep your line on."
                            : "Votre commande a été attribuée au chauffeur- " + driver1.getFirstName() + ", S'il vous plaît, restez en ligne.", orderPrivateCar.getUserId());
            return SUCCESS_TIP;
        }catch (Exception e){
            e.printStackTrace();
        }
        return ERROR;
    }
 
    /**
     * 跨城出行订单改派司机
     */
    @RequestMapping(value = "/selectCrossDriver")
    @ResponseBody
    public Object selectCrossDriver(@RequestParam Integer orderId,@RequestParam Integer driverId) {
        //修改原司机信息
        //修改订单
        TReassign tReassign = tReassignService.selectById(orderId);
        TOrderCrossCity tOrderCrossCity = itOrderCrossCityService.selectById(tReassign.getOrderId());
        TDriver oldDriver = itDriverService.selectById(tReassign.getOriginalDriverId());
        LineShiftDriver lineShiftDriver = lineShiftDriverMapper.selectById(tOrderCrossCity.getLineShiftDriverId());
        lineShiftDriver.setLaveSeat(lineShiftDriver.getLaveSeat() + tOrderCrossCity.getPeopleNumber() > lineShiftDriver.getTotalSeat() ?
                lineShiftDriver.getTotalSeat() : lineShiftDriver.getLaveSeat() + tOrderCrossCity.getPeopleNumber());
        String seat = "";
        String[] split = tOrderCrossCity.getSeatNumber().split(",");
        for(String s : split){
            seat += s + ",";
        }
        seat = lineShiftDriver.getLaveSeatNumber() + "," + seat.substring(0, seat.length() - 1);
 
        //总和大于总座位数的情况
        if(lineShiftDriver.getLaveSeat() + tOrderCrossCity.getPeopleNumber() > lineShiftDriver.getTotalSeat()){
            seat = "";
            for(int i = 1; i <= lineShiftDriver.getTotalSeat(); i++){
                seat += i + ",";
            }
            seat = seat.substring(0, seat.length() - 1);
        }
        lineShiftDriver.setLaveSeatNumber(seat);
        lineShiftDriverMapper.updateById(lineShiftDriver);
        if(lineShiftDriver.getLaveSeat() >= lineShiftDriver.getTotalSeat()){
            oldDriver.setState(2);
            itDriverService.updateById(oldDriver);
        }
 
        //修改新司机数据
        List<LineShiftDriver> query = lineShiftDriverMapper.query(lineShiftDriver.getLineShiftId(), driverId, tOrderCrossCity.getTravelTime());
        if(query.size() == 0){
            return ResultUtil.error("司机没有预约班次");
        }
        LineShiftDriver lineShiftDriver1 = query.get(0);
        if(lineShiftDriver1.getLaveSeat() < tOrderCrossCity.getPeopleNumber()){
            return ResultUtil.runErr("司机车辆剩余座位数不足");
        }
        lineShiftDriver1.setLaveSeat(lineShiftDriver1.getLaveSeat() - tOrderCrossCity.getPeopleNumber());
        String[] split1 = lineShiftDriver1.getLaveSeatNumber().split(",");
        String seat1 = "";//使用
        String seat2 = "";//未使用
        for(int i = 0; i < tOrderCrossCity.getPeopleNumber(); i++){
            seat1 += split1[i] + ",";
        }
        for(int i = tOrderCrossCity.getPeopleNumber(); i < split.length; i++){
            seat2 += split1[i] + ",";
        }
        lineShiftDriver1.setLaveSeatNumber(seat2);
        lineShiftDriverMapper.updateById(lineShiftDriver1);
        TDriver driver = itDriverService.selectById(driverId);
        if(driver.getState() == 1){
            return ResultUtil.error("司机还未上班呢");
        }
        if(driver.getState() == 2){
            driver.setState(3);
        }
 
        //修改订单数据
        tOrderCrossCity.setDriverId(driverId);
        tOrderCrossCity.setCarId(driver.getCarId());
        tOrderCrossCity.setSeatNumber(seat1);
        tOrderCrossCity.setState(tOrderCrossCity.getOldState());
        tOrderCrossCity.setLineShiftDriverId(lineShiftDriver1.getId());
        tOrderCrossCity.setOldState(null);
        tOrderCrossCity.setIsReassign(2);
        try {
            tOrderCrossCity.setOrderNum(itOrderCrossCityService.getOrderNum(driverId, tOrderCrossCity.getLineShiftDriverId()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        itOrderCrossCityService.updateAllColumnById(tOrderCrossCity);
 
        //修改专车改派订单
        tReassign.setNowDriverId(driverId);
        tReassign.setNowCarId(driver.getCarId());
        tReassign.setState(3);
        tReassign.setCompleteTime(new Date());
        tReassignService.updateById(tReassign);
 
        //修改收入明细,转给新司机(因为是先支付金额)
        List<Income> incomes = incomeService.selectList(new EntityWrapper<Income>().eq("userType", 2).eq("objectId", oldDriver.getId()).eq("type", 2).eq("incomeId", tReassign.getOrderId()).eq("orderType", 3));
        if(incomes.size() > 0){
            Income income = incomes.get(0);
            income.setObjectId(driverId);
            incomeService.updateById(income);
 
            oldDriver.setBusinessMoney(oldDriver.getBusinessMoney() - income.getMoney());
            oldDriver.setLaveBusinessMoney(oldDriver.getLaveBusinessMoney() - income.getMoney());
            oldDriver.setBalance(oldDriver.getBalance().subtract(new BigDecimal(income.getMoney())));
 
            driver.setBusinessMoney(driver.getBusinessMoney() + income.getMoney());
            driver.setLaveBusinessMoney(driver.getLaveBusinessMoney() + income.getMoney());
            driver.setBalance(driver.getBalance().add(new BigDecimal(income.getMoney())));
 
        }
        itDriverService.updateById(oldDriver);
        itDriverService.updateById(driver);
        //增加推送
        Map<String,String> map = new HashMap<>();
        map.put("orderId", tOrderCrossCity.getId().toString());
        map.put("orderType", "3");
        map.put("from", "admin");
        String result = HttpRequestUtil.postRequest(PushURL.order_push_url, map);
        System.out.println("跨城出行改派:【orderId="+tOrderCrossCity.getId().toString()+"】,调用接口:"+result);
        return SUCCESS_TIP;
    }
 
 
    /**
     * 专车订单改派司机
     */
    @RequestMapping(value = "/selectSmallDriver")
    @ResponseBody
    public Object selectSmallDriver(@RequestParam Integer orderId,@RequestParam Integer driverId) {
        //修改订单
        try {
            TReassign tReassign = tReassignService.selectById(orderId);
            TOrderLogistics orderLogistics = orderLogisticsService.selectById(tReassign.getOrderId());
            String tripId = redisUtil.getValue("trip" + orderLogistics.getUserId());
            TDriver driver = itDriverService.selectById(orderLogistics.getDriverId());
    
            TDriver driver1 = itDriverService.selectById(driverId);
            tReassign.setState(3);
            tReassign.setNowDriverId(driver1.getId());
            tReassign.setNowCarId(driver1.getCarId());
            tReassign.setCompleteTime(new Date());
            tReassignService.updateById(tReassign);
    
            String text = "";
            Integer language1 = driver1.getLanguage();
            switch (language1){
                case 1:
                    text = "收到新的包裹订单,从" + orderLogistics.getStartAddress() + "出发,全程约" + orderLogistics.getEstimatedMileage() + "公里";
                    break;
                case 2:
                    text = "Received a new delivery order, starting from " + orderLogistics.getStartAddress() + ", the whole journey is about " + orderLogistics.getEstimatedMileage() + "kilometre";
                    break;
                case 3:
                    text = "Reçu une nouvelle commande de livraison, à partir de " + orderLogistics.getStartAddress() + ", le trajet complet est d’environ " + orderLogistics.getEstimatedMileage();
                    break;
        
            }
            String audioUrl = "";
            String fileName = null;
            try {
                fileName = "pushOrder" + driver1.getId() + UUIDUtil.getRandomCode(5) + ".mp3";
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            try {
                audioUrl = TextToSpeechUtil.create(language1 == 1 ? "cmn-CN" : language1 == 2 ? "en-US" : "fr-FR", text, fileName);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            //定时任务删除语音文件
            String finalFileName = fileName;
            new Timer().schedule(new TimerTask() {
                @Override
                public void run() {
                    try {
                        // 使用Runtime执行命令
                        Process process = Runtime.getRuntime().exec("sudo rm -rf /home/igotechgh/nginx/html/files/audio/" + finalFileName);
                        // 读取命令的输出
                        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                        String line;
                        while ((line = reader.readLine()) != null) {
                            System.out.println(line);
                        }
                        // 等待命令执行完成
                        process.waitFor();
                        // 关闭流
                        reader.close();
                    } catch (IOException | InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }, 30000);
    
    
            orderLogistics.setDriverId(driver1.getId());
            orderLogistics.setCarId(driver1.getCarId());
            orderLogistics.setCompanyId(driver1.getFranchiseeId() != null && driver1.getFranchiseeId() != 0 ? driver1.getFranchiseeId() : (
                    driver1.getCompanyId() != null && driver1.getCompanyId() != 0 ? driver1.getCompanyId() : 1));
            orderLogistics.setState(orderLogistics.getOldState());
            orderLogistics.setOldState(null);
            orderLogistics.setSnatchOrderTime(new Date());
            if(!StringUtils.hasLength(orderLogistics.getTripId())){
                orderLogistics.setTripId(UUIDUtil.getRandomCode());
            }
            String value = redisUtil.getValue("DRIVER" + driver1.getId());
            if(ToolUtil.isNotEmpty(value)) {
                String[] split = value.split(",");
                DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(orderLogistics.getStartLat(), orderLogistics.getStartLon(), Double.valueOf(split[1]), Double.valueOf(split[0]), tripId);
                //超时时间
                long timeOut = System.currentTimeMillis() + (distancematrix.getDuration() * 1000);
                orderLogistics.setEstimateArriveTime(new Date(timeOut));
                orderLogistics.setEstimateArriveMileage(distancematrix.getDistance());
            }
            orderLogisticsService.updateAllColumnById(orderLogistics);
            //修改司机为服务中
            driver1.setState(3);
            itDriverService.updateById(driver1);
    
            driver.setState(2);
            itDriverService.updateById(driver);
    
            //检查google车辆信息或者添加新的车辆信息
            TCar car = carService.selectById(orderLogistics.getCarId());
            if(ToolUtil.isEmpty(car.getVehicleId())){
                car.setVehicleId(UUIDUtil.getRandomCode());
                carService.updateById(car);
            }
            String vehicles = fleetEngineUtil.getVehicles(car.getVehicleId());
            if(ToolUtil.isEmpty(vehicles)){
                TCarModel carModel = carModelMapper.selectById(car.getCarModelId());
                boolean createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
                if(!createVehicles){
                    for (int i = 0; i < 5; i++) {
                        createVehicles = fleetEngineUtil.createVehicles(carModel.getSeat() - 1, car.getCarLicensePlate(), car.getVehicleId());
                        if(createVehicles){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
    
            //修改google订单信息或者创建新的行程
            String trip = fleetEngineUtil.getTrip(orderLogistics.getTripId());
            if(ToolUtil.isEmpty(trip)){
                JSONObject createTrip = fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderLogistics.getTripId(),
                        orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(), orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
                JSONObject error = createTrip.getJSONObject("error");
                if(null != error){
                    for (int i = 0; i < 5; i++) {
                        createTrip = fleetEngineUtil.createTrip(car.getVehicleId(), 1, orderLogistics.getTripId(),
                                orderLogistics.getStartLat().toString(), orderLogistics.getStartLon().toString(), orderLogistics.getEndLat().toString(), orderLogistics.getEndLon().toString());
                        error = createTrip.getJSONObject("error");
                        String tripStatus = createTrip.getString("tripStatus");
                        if(null == error && "NEW".equals(tripStatus)){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }else{
                //开始修改行程数据
                boolean updateTrip = fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null, orderLogistics.getId(), 4);
                if(!updateTrip){
                    for (int i = 0; i < 5; i++) {
                        updateTrip = fleetEngineUtil.updateTrip(null, car.getVehicleId(), null, orderLogistics.getTripId(), null, null, null, null, orderLogistics.getId(), 4);
                        if(updateTrip){
                            break;
                        }
                        try {
                            Thread.sleep(3000L);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
    
    
            //删除定时任务
            quartzUtil.deleteQuartzTask("1_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("2_1_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("2_2_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
            quartzUtil.deleteQuartzTask("3_" + orderLogistics.getId() + "_4","ORDER_TIME_OUT");
    
            /**
             * 超时用户取消不收费的提醒
             *   即时单:预估到达预约点时间 + 配置不收费的时间 > 当前时间 (只弹一次)
             *
             * 超时用户取消订单后需要弹给司机提醒弹框,超时时间 = 当前时间 - 行程时间 - 配置不收费的时间
             *
             * 定时提醒弹框
             *   司机只要开始超时且还未到达预约点,则需要定时提醒
             */
    
            //添加定时任务(普通任务)
            TSysOverTime reminderRules = sysOvertimeService.selectOne(new EntityWrapper<TSysOverTime>().eq("companyId", driver1.getCompanyId()));
            if(null != reminderRules){
                TSysCancleOrder cancleOrder = cancleOrderService.selectOne(new EntityWrapper<TSysCancleOrder>().eq("companyId", driver1.getCompanyId()));
                Integer driverTimeout = JSON.parseObject(cancleOrder.getContent()).getInteger("driverTimeout");
                //超时时间
                long timeOut = orderLogistics.getEstimateArriveTime().getTime() + (driverTimeout * 60 * 1000);
                //乘客取消不收费提醒
                JobDataMap jobDataMap = new JobDataMap();
                jobDataMap.put("driverId", driver1.getId());
                jobDataMap.put("timeOutType", 1);
                jobDataMap.put("orderId", orderLogistics.getId());
                jobDataMap.put("orderType", 4);
                jobDataMap.put("language", language1);
                jobDataMap.put("timeOut", timeOut);
                jobDataMap.put("driverTimeout", driverTimeout);
                jobDataMap.put("describe", language1 == 1 ? "您已超时" + driverTimeout + "分钟,用户可免费取消订单" : language1 == 2 ? "Reminder You are overdue for " + driverTimeout + " minutes The subscriber could cancel the order for free Confirm" : "Rappel Vous êtes en retard de " + driverTimeout + " minutes L’abonné peut annuler la commande gratuitement Confirmer");
                quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "1_" + orderLogistics.getId() + "_4", "ORDER_TIME_OUT", jobDataMap
                        , new Date(timeOut), timeOut, 0);
        
                //超时循环提醒
                jobDataMap = new JobDataMap();
                jobDataMap.put("driverId", driver1.getId());
                jobDataMap.put("timeOutType", 3);
                jobDataMap.put("orderId", orderLogistics.getId());
                jobDataMap.put("orderType", 4);
                jobDataMap.put("language", language1);
                jobDataMap.put("timeOut", orderLogistics.getEstimateArriveTime().getTime());
                jobDataMap.put("driverTimeout", driverTimeout);
                jobDataMap.put("describe", "");
                quartzUtil.addSimpleQuartzTask(OrderTimeOutJob.class, "3_" + orderLogistics.getId() + "_4", "ORDER_TIME_OUT", jobDataMap
                        , orderLogistics.getEstimateArriveTime(), reminderRules.getCar() * 60000, -1);
            }
    
    
            //推送相关代码------------------start----------------
            String finalAudioUrl = audioUrl;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    pushUtil.pushOrderReassign(orderLogistics.getUserId(), 1, orderLogistics.getId(), 4, "");
                    pushUtil.pushOrderReassign(orderLogistics.getDriverId(), 2, orderLogistics.getId(), 4, finalAudioUrl);
                }
            }).start();
            Integer language2 = userService.selectById(orderLogistics.getUserId()).getLanguage();
            systemNoticeService.addSystemNotice(2, language1 == 1 ? "您已成功抢得包裹订单,请及时联系客户!" :
                    language1 == 2 ? "You have grabbed the delivery order, please contact the client timely."
                            : "Vous avez saisi la commande du livraison. Veuillez contacter le client en temps opportun.", orderLogistics.getDriverId());
            systemNoticeService.addSystemNotice(1, language2 == 1 ? "您的订单已指派给" + driver1.getFirstName() + "师傅,请保持电话畅通!" :
                    language2 == 2 ? "Your order has been assigned to the driver- " + driver1.getFirstName() + ", please keep your line on."
                            : "Votre commande a été attribuée au chauffeur- " + driver1.getFirstName() + ", S'il vous plaît, restez en ligne.", orderLogistics.getUserId());
    
    
            return SUCCESS_TIP;
        }catch (Exception e){
            e.printStackTrace();
        }
        return ERROR;
    }
}