Pu Zhibing
2025-05-09 60c025ed5a9974a1a8ddb508ca76467da9d46361
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
package com.stylefeng.guns.modular.system.controller.taxi;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
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.util.DateUtil;
import com.stylefeng.guns.core.util.ExcelExportUtil;
import com.stylefeng.guns.core.util.SinataUtil;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * 出租车订单控制器
 *
 * @author fengshuonan
 * @Date 2020-06-08 10:25:55
 */
@Controller
@RequestMapping("/tOrderTaxi")
public class TOrderTaxiController extends BaseController {
 
    public static List<Integer> orderIds = new ArrayList<>();
    private String PREFIX = "/system/tOrderTaxi/";
    @Autowired
    private ITOrderTaxiService tOrderTaxiService;
    @Autowired
    private ITPubTransactionDetailsService pubTransactionDetailsService;
    @Autowired
    private ITOrderPositionService tOrderPositionService;
    @Autowired
    private ITDriverService tDriverService;
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
    @Autowired
    private GDMapGeocodingUtil gdMapGeocodingUtil;
    @Autowired
    private ITUserService itUserService;
    @Autowired
    private PushUtil pushUtil;
    @Autowired
    private ITCompanyCityService companyCityService;
    @Autowired
    private ITSysPushOrderService pushOrderService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private ITDriverService driverService;
    @Autowired
    private ITSystemNoticeService systemNoticeService;
    @Value("${filePath}")
    private String filePath;
    private ResultUtil resultUtil;
 
    /**
     * 跳转到出租车订单首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tOrderTaxi.html";
    }
 
    /**
     * 跳转到添加出租车订单
     */
    @RequestMapping("/tOrderTaxi_add")
    public String tOrderTaxiAdd() {
        return PREFIX + "tOrderTaxi_add.html";
    }
 
    /**
     * 跳转到修改出租车订单
     */
    @RequestMapping("/tOrderTaxi_update/{tOrderTaxiId}")
    public String tOrderTaxiUpdate(@PathVariable Integer tOrderTaxiId, Model model) throws IOException {
        Map<String, Object> tOrderTaxi = tOrderTaxiService.getTaxiOrderDetailById(tOrderTaxiId);
        model.addAttribute("item",tOrderTaxi);
        // 查询司机扣款
        List<TPubTransactionDetails> tPubTransactionDetails = pubTransactionDetailsService.selectList(new EntityWrapper<TPubTransactionDetails>()
                .eq("userId", tOrderTaxi.get("driverId"))
                .eq("orderId", tOrderTaxi.get("id"))
                .eq("type", 1)
                .eq("userType", 2));
        if(CollectionUtils.isEmpty(tPubTransactionDetails)){
            model.addAttribute("companyMoney","");
            model.addAttribute("driverMoney","");
        }else {
            TPubTransactionDetails pubTransactionDetailCompany = tPubTransactionDetails.stream().filter(e -> e.getOrderType().equals(6)).findFirst().orElse(null);
            if(Objects.nonNull(pubTransactionDetailCompany)){
                model.addAttribute("companyMoney",pubTransactionDetailCompany.getMoney());
            }else {
                model.addAttribute("companyMoney","");
            }
            TPubTransactionDetails pubTransactionDetailDriver = tPubTransactionDetails.stream().filter(e -> e.getOrderType().equals(2)).findFirst().orElse(null);
            if(Objects.nonNull(pubTransactionDetailDriver)){
                model.addAttribute("driverMoney",pubTransactionDetailDriver.getMoney());
            }else {
                model.addAttribute("driverMoney","");
            }
        }
        if(tOrderTaxi.get("payManner")!=null && Integer.parseInt(tOrderTaxi.get("payManner").toString()) == 1){
            model.addAttribute("payMannerStr","线上收款");
        }else {
            model.addAttribute("payMannerStr","计费打表");
        }
        LogObjectHolder.me().set(tOrderTaxi);
        try{
            //将数据存储到文件中
            File file = new File(filePath + tOrderTaxiId + "_2.txt");
 
            //读取文件(字符流)
            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
            //循环取出数据
            String str = null;
            StringBuffer sb = new StringBuffer();
            while ((str = in.readLine()) != null) {
                sb.append(str);
            }
            List<TOrderPosition> list = JSONArray.parseArray(sb.toString(), TOrderPosition.class);
            List<Map> maps = new ArrayList<>();
            for (TOrderPosition tOrderPosition : list) {
                Map<String, String> map = new HashMap<>();
                map.put("lon",tOrderPosition.getLon());
                map.put("lat",tOrderPosition.getLat());
                maps.add(map);
            }
            
//        resultUtil = ResultUtil.success(list);
            // 将maps转化为jsonArray字符串
            // 使用 Gson 转换为 JSON 字符串
//        Gson gson = new Gson();
//        String jsonString = gson.toJson(maps);
//        System.out.println(jsonString);
            model.addAttribute("guiji",maps);
        }catch (Exception e){
            e.printStackTrace();
            resultUtil = ResultUtil.runErr();
            model.addAttribute("guiji","");
        }
 
 
        return PREFIX + "tOrderTaxi_edit.html";
    }
 
    /**
     * 跳转到改派出租车订单
     */
    @RequestMapping("/tOrderTaxi_changeOrder/{tOrderTaxiId}")
    public String tOrderTaxi_changeOrder(@PathVariable Integer tOrderTaxiId, Model model) {
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(tOrderTaxiId);
        model.addAttribute("item",tOrderTaxi);
        LogObjectHolder.me().set(tOrderTaxi);
        return PREFIX + "tOrderTaxi_changeOrder.html";
    }
 
    /**
     * 跳转到出租车订单轨迹页面
     */
    @RequestMapping("/tOrderTaxi_trajectory/{tOrderTaxiId}")
    public String tOrderTaxi_trajectory(@PathVariable Integer tOrderTaxiId, Model model) throws IOException {
        model.addAttribute("tOrderTaxiId",tOrderTaxiId);
        try{
            //将数据存储到文件中
            File file = new File(filePath + tOrderTaxiId + "_2.txt");
 
            //读取文件(字符流)
            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
            //循环取出数据
            String str = null;
            StringBuffer sb = new StringBuffer();
            while ((str = in.readLine()) != null) {
                sb.append(str);
            }
            List<TOrderPosition> list = JSONArray.parseArray(sb.toString(), TOrderPosition.class);
            List<Map> maps = new ArrayList<>();
            for (TOrderPosition tOrderPosition : list) {
                Map<String, String> map = new HashMap<>();
                map.put("lon",tOrderPosition.getLon());
                map.put("lat",tOrderPosition.getLat());
                maps.add(map);
            }
//        resultUtil = ResultUtil.success(list);
            // 将maps转化为jsonArray字符串
            // 使用 Gson 转换为 JSON 字符串
//        Gson gson = new Gson();
//        String jsonString = gson.toJson(maps);
//        System.out.println(jsonString);
            model.addAttribute("guiji",maps);
        }catch (Exception e){
            e.printStackTrace();
            resultUtil = ResultUtil.runErr();
            model.addAttribute("guiji","");
        }
        return PREFIX + "tOrderTaxi_trajectory.html";
    }
    
    /**
     * 获取出租车订单列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String insertTime,
                       String orderNum,
                       Integer orderSource,
                       String userName,
                       String userPhone,
                       String passengers,
                       String passengersPhone,
                       String driver,
                       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(tOrderTaxiService.getTaxiOrderList(page,beginTime,endTime,ShiroKit.getUser().getRoleType(),ShiroKit.getUser().getObjectId(),orderNum,orderSource,userName,userPhone,passengers,passengersPhone,driver,state));
        return super.packForBT(page);
    }
    
    /**
     * 导出订单
     * @param insertTime
     * @param orderNum
     * @param orderSource
     * @param userName
     * @param userPhone
     * @param passengers
     * @param passengersPhone
     * @param driver
     * @param state
     * @param request
     * @param response
     */
    @GetMapping("/export")
    public void export(String insertTime,
                       String orderNum,
                       Integer orderSource,
                       String userName,
                       String userPhone,
                       String passengers,
                       String passengersPhone,
                       String driver,
                       Integer state, HttpServletRequest request, HttpServletResponse response){
        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 Page(1, 99999);
        List<Map<String, Object>> taxiOrderList = tOrderTaxiService.getTaxiOrderList(page, beginTime, endTime, ShiroKit.getUser().getRoleType(), ShiroKit.getUser().getObjectId(), orderNum, orderSource, userName, userPhone, passengers, passengersPhone, driver, state);
    
        // 表格数据【封装】
        List<List<String>> dataList = new ArrayList<>();
    
        // 列【封装】
        List<String> shellList = new ArrayList<String>();
        shellList.add("下单时间");
        shellList.add("订单编号");
        shellList.add("订单来源");
        shellList.add("乘车时间");
        shellList.add("下单用户昵称");
        shellList.add("下单用户手机");
        shellList.add("乘车用户姓名");
        shellList.add("乘车用户手机");
        shellList.add("起点");
        shellList.add("终点");
        shellList.add("接单司机");
        shellList.add("司机手机号");
        shellList.add("车辆所属机构");
        shellList.add("接单车辆");
        shellList.add("订单金额");
        shellList.add("司机抽成");
        shellList.add("状态");
        dataList.add(shellList);
    
        for (Map<String,Object> object : taxiOrderList){
            // 详细数据列【封装】
            shellList = new ArrayList<String>();
            if(SinataUtil.isNotEmpty(object.get("insertTime"))){
                shellList.add(DateUtil.formatDate(DateUtil.parse(object.get("insertTime").toString(),"YYYY-MM-dd HH:mm:ss.S"), "YYYY-MM-dd HH:mm"));
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("orderNum"))){
                shellList.add(object.get("orderNum").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("orderSource"))){
                switch (object.get("orderSource").toString()){
                    case "1":
                        shellList.add("APP下单");
                        break;
                    case "2":
                        shellList.add("扫码下单");
                        break;
                    case "3":
                        shellList.add("小程序下单");
                        break;
                    case "4":
                        shellList.add("司机下单");
                        break;
                    case "5":
                        shellList.add("调度下单");
                        break;
                    case "6":
                        shellList.add("电话下单");
                        break;
                    case "7":
                        shellList.add("95128电召");
                        break;
                }
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("travelTime"))){
                shellList.add(DateUtil.formatDate(DateUtil.parse(object.get("travelTime").toString(),"YYYY-MM-dd HH:mm:ss.S"), "YYYY-MM-dd HH:mm"));
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("userName"))){
                shellList.add(object.get("userName").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("userPhone"))){
                shellList.add(object.get("userPhone").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("passengers"))){
                shellList.add(object.get("passengers").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("passengersPhone"))){
                shellList.add(object.get("passengersPhone").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("startAddress"))){
                shellList.add(object.get("startAddress").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("endAddress"))){
                shellList.add(object.get("endAddress").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("driver"))){
                shellList.add(object.get("driver").toString().split("-")[0]);
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("driver"))){
                shellList.add(object.get("driver").toString().split("-")[1]);
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("company"))){
                shellList.add(object.get("company").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("car"))){
                shellList.add(object.get("car").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("payMoney"))){
                shellList.add(object.get("payMoney").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("commission"))){
                shellList.add(object.get("commission").toString());
            }else{
                shellList.add("-");
            }
            if(SinataUtil.isNotEmpty(object.get("state"))){
                switch (object.get("state").toString()){
                    case "1":
                        shellList.add("待接单");
                        break;
                    case "2":
                        shellList.add("待出发");
                        break;
                    case "3":
                        shellList.add("待到达预约地点");
                        break;
                    case "4":
                        shellList.add("待乘客上车");
                        break;
                    case "5":
                        shellList.add("服务中");
                        break;
                    case "6":
                        shellList.add("完成服务");
                        break;
                    case "7":
                        shellList.add("待支付");
                        break;
                    case "8":
                        shellList.add("待评价");
                        break;
                    case "9":
                        shellList.add("已完成");
                        break;
                    case "10":
                        shellList.add("已取消");
                        break;
                    case "11":
                        shellList.add("改派中");
                        break;
                    case "12":
                        shellList.add("取消待支付");
                        break;
                }
            }else{
                shellList.add("-");
            }
            dataList.add(shellList);
        }
        try {
            // 调用工具类进行导出
            ExcelExportUtil.easySheet("出租车订单"+DateUtil.formatDate(new Date(), "YYYYMMddHHmmss"), "出租车订单", dataList,request, response);
        
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 选择司机列表
     */
    @RequestMapping(value = "/selectDriver/{orderId}")
    @ResponseBody
    public Object selectDriver(@PathVariable Integer orderId,
                               String name,
                               String phone) {
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(orderId);
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage();
        page.setRecords(tOrderTaxiService.getCanSelectTaxiDriverList(page,tOrderTaxi.getCompanyId(),name,phone));
        return super.packForBT(page);
    }
 
    /**
     * 获取订单轨迹
     * @param orderDetailId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getOrderTrack", method = RequestMethod.POST)
    public ResultUtil getOrderTrack(String orderDetailId){
        if(ToolUtil.isNotEmpty(orderDetailId)){
            try {
//                List<TOrderPosition> list = tOrderPositionService.selectList(new EntityWrapper<TOrderPosition>().eq("orderType", 2).eq("orderId", orderDetailId).orderBy("insertTime"));
                /*if(list.size() == 0){
                    return ResultUtil.error("该订单没有运行轨迹");
                }*/
                //将数据存储到文件中
                File file = new File(filePath + orderDetailId + "_2.txt");
                if(!file.exists()){
                    return ResultUtil.success(new ArrayList<>());
                }
                //读取文件(字符流)
                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
                //循环取出数据
                String str = null;
                StringBuffer sb = new StringBuffer();
                while ((str = in.readLine()) != null) {
                    sb.append(str);
                }
                List<TOrderPosition> list = JSONArray.parseArray(sb.toString(), TOrderPosition.class);
                resultUtil = ResultUtil.success(list);
            }catch (Exception e){
                e.printStackTrace();
                resultUtil = ResultUtil.runErr();
            }
        }else {
            resultUtil = ResultUtil.paranErr();
        }
        return resultUtil;
    }
 
    /**
     * 删除出租车订单
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tOrderTaxiId) {
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(tOrderTaxiId);
        tOrderTaxi.setIsDelete(2);
        tOrderTaxiService.updateById(tOrderTaxi);
        return SUCCESS_TIP;
    }
 
    /**
     * 出租车订单改派司机
     */
    @RequestMapping(value = "/selectDriver")
    @ResponseBody
    public Object selectDriver(@RequestParam Integer orderId,@RequestParam Integer driverId) {
        //修改订单
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(orderId);
        
        //修改之前司机状态 -- 空闲
        TDriver oldDriver = tDriverService.selectById(tOrderTaxi.getDriverId());
        oldDriver.setState(2);
        tDriverService.updateById(oldDriver);
 
        //查找司机对象
        TDriver nowDriver = tDriverService.selectById(driverId);
        nowDriver.setState(3);
        tDriverService.updateById(nowDriver);
 
        //修改出租车订单
        tOrderTaxi.setState(tOrderTaxi.getOldState());
        tOrderTaxi.setDriverId(driverId);
        tOrderTaxi.setCarId(nowDriver.getCarId());
        tOrderTaxiService.updateById(tOrderTaxi);
 
        //增加推送
        Map<String,String> map = new HashMap<>();
        map.put("orderId", tOrderTaxi.getId().toString());
        map.put("orderType", "2");
        String result = HttpRequestUtil.postRequest(PushURL.order_push_url, map);
        System.out.println("出租车改派:【orderId="+tOrderTaxi.getId().toString()+"】,调用接口:"+result);
        return SUCCESS_TIP;
    }
 
    /**
     * 取消出租车订单
     */
    @RequestMapping(value = "/cancel")
    @ResponseBody
    public Object cancel(@RequestParam Integer tOrderTaxiId) {
        TOrderTaxi tOrderTaxi = tOrderTaxiService.selectById(tOrderTaxiId);
 
        //修改之前司机状态 -- 空闲
        if(null != tOrderTaxi.getDriverId()){
            TDriver driver = tDriverService.selectById(tOrderTaxi.getDriverId());
            driver.setState(2);
            tDriverService.updateById(driver);
        }
 
        tOrderTaxi.setState(10);
        tOrderTaxiService.updateById(tOrderTaxi);
 
        //增加推送
        Map<String,String> map = new HashMap<>();
        map.put("id", tOrderTaxi.getId().toString());
        map.put("orderType", "2");
        String result = HttpRequestUtil.postRequest(PushURL.cancel_order_url, map);
        System.out.println("出租车取消:【orderId="+tOrderTaxi.getId().toString()+"】,调用接口:"+result);
 
        return SUCCESS_TIP;
    }
 
    /**
     * 修改出租车订单
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TOrderTaxi tOrderTaxi) {
        tOrderTaxiService.updateById(tOrderTaxi);
        return SUCCESS_TIP;
    }
 
    /**
     * 出租车订单详情
     */
    @RequestMapping(value = "/detail/{tOrderTaxiId}")
    @ResponseBody
    public Object detail(@PathVariable("tOrderTaxiId") Integer tOrderTaxiId) {
        return tOrderTaxiService.selectById(tOrderTaxiId);
    }
 
    @ResponseBody
    @PostMapping("/add")
    public ResultUtil add(String passengers, String passengersPhone, String startAddress, String endAddress, Integer orderType, String travelTime, String remark){
        try {
            startAddress = startAddress.replaceAll("& #40;", "\\(");//特殊字符转义
            startAddress = startAddress.replaceAll("& #41;", "\\)");
            TOrderTaxi tOrderTaxi = new TOrderTaxi();
            tOrderTaxi.setStartAddress(startAddress);
            endAddress = endAddress.replaceAll("& #40;", "\\(");//特殊字符转义
            endAddress = endAddress.replaceAll("& #41;", "\\)");
            tOrderTaxi.setEndAddress(endAddress);
            tOrderTaxi.setPassengers(passengers);
            tOrderTaxi.setPassengersPhone(passengersPhone);
            tOrderTaxi.setOrderType(orderType);
            if(orderType == 1){
                tOrderTaxi.setTravelTime(new Date());
            }else if(ToolUtil.isNotEmpty(travelTime)){
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                tOrderTaxi.setTravelTime(sdf.parse(travelTime));
            }
 
            Map<String, Object> geocoding_s = gdMapGeocodingUtil.geocoding(null, null, null, tOrderTaxi.getStartAddress());
            if(Integer.valueOf(geocoding_s.get("status").toString()) != 0){
                return ResultUtil.error("无效的起点");
            }
            Map<String, Object> geocoding_e = gdMapGeocodingUtil.geocoding(null, null, null, tOrderTaxi.getEndAddress());
            if(Integer.valueOf(geocoding_e.get("status").toString()) != 0){
                return ResultUtil.error("无效的终点");
            }
            List<String> s = (List<String>)geocoding_s.get("data");
            List<String> e = (List<String>)geocoding_e.get("data");
            if(s.size() == 0){
                return ResultUtil.error("未查询到有效的起点");
            }
            if(e.size() == 0){
                return ResultUtil.error("未查询到有效的终点");
            }
 
            tOrderTaxi.setType(1);
            TUser tUser = itUserService.selectOne(new EntityWrapper<TUser>().eq("phone", tOrderTaxi.getPassengersPhone()).eq("state", 1).ne("flag", 3));
            if(null == tUser){
                tUser = new TUser();
                tUser.setState(1);
                tUser.setFlag("1");
                tUser.setInsertTime(new Date());
                tUser.setPhone(tOrderTaxi.getPassengersPhone());
                tUser.setName(tOrderTaxi.getPassengers());
                tUser.setIsAuth(1);
                itUserService.insert(tUser);
            }
            tOrderTaxi.setUserId(tUser.getId());
            tOrderTaxi.setOrderNum(this.getOrderNum());
            tOrderTaxi.setPlacementAddress(tOrderTaxi.getStartAddress());
            tOrderTaxi.setPlacementLon(Double.valueOf(s.get(0).split(",")[1]));
            tOrderTaxi.setPlacementLat(Double.valueOf(s.get(0).split(",")[0]));
            tOrderTaxi.setStartLon(Double.valueOf(s.get(0).split(",")[1]));
            tOrderTaxi.setStartLat(Double.valueOf(s.get(0).split(",")[0]));
            tOrderTaxi.setEndLon(Double.valueOf(e.get(0).split(",")[1]));
            tOrderTaxi.setEndLat(Double.valueOf(e.get(0).split(",")[0]));
            tOrderTaxi.setMileage(0D);
            tOrderTaxi.setOrderMoney(new BigDecimal(0));
            tOrderTaxi.setTravelMoney(new BigDecimal(0));
            tOrderTaxi.setParkMoney(new BigDecimal(0));
            tOrderTaxi.setRoadTollMoney(new BigDecimal(0));
            tOrderTaxi.setRedPacketMoney(new BigDecimal(0));
            tOrderTaxi.setCouponMoney(new BigDecimal(0));
            tOrderTaxi.setInsertTime(new Date());
            tOrderTaxi.setIsReassign(1);
            tOrderTaxi.setState(1);//待接单
            tOrderTaxi.setSubstitute(0);
            tOrderTaxi.setOrderSource(5);
            tOrderTaxi.setIsDelete(1);
            tOrderTaxi.setPayManner(3);
            tOrderTaxiService.insert(tOrderTaxi);
            if(tOrderTaxi.getState() == 1){
                //推送司机抢单
                this.pushOrder(tOrderTaxi);
            }
            //添加消息
            systemNoticeService.addSystemNotice(1, "您的出租车订单已下单成功,我们正在为您指派司机,请稍后!", tOrderTaxi.getUserId(), 1);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
        return ResultUtil.success();
    }
 
 
    public synchronized String getOrderNum() throws Exception{
        int size = tOrderTaxiService.selectCount(null);
        return "TAXI" + String.valueOf(1000000 + size + 1).substring(1);
    }
 
 
    /**
     * 推送订单给司机抢单
     * @param orderTaxi
     * @throws Exception
     */
    public void pushOrder(TOrderTaxi orderTaxi) throws Exception{
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    orderIds.add(orderTaxi.getId());//添加记录,防止调用接口重复提醒无人接单
                    String vehicle = redisUtil.getValue("VEHICLE");
                    List<Integer> integers = new ArrayList<>();
                    if(ToolUtil.isNotEmpty(vehicle)){
                        integers = JSON.parseArray(vehicle).toJavaList(Integer.class);
                    }
                    TCompany query = companyCityService.query(String.valueOf(orderTaxi.getStartLon()), String.valueOf(orderTaxi.getStartLat()));//获取起点所属分公司
                    List<TSysPushOrder> querys = pushOrderService.querys(null, 2, query.getId());//获取需要推送的次数
                    for(int i = 1; i <= querys.size(); i++){
                        TSysPushOrder pushOrder = pushOrderService.querys(i, 2, query.getId()).get(0);
                        //获取空闲司机
                        List<TDriver> list = driverService.queryIdleDriver(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机
                        System.out.println("空闲司机1"+list);
                        if(list.size() > 0){
                            double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数
                            System.out.println("空闲司机2"+driverProportion);
 
                            int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取)
                            System.out.println("空闲司机3"+lastIndex);
                            lastIndex = lastIndex == 0 ? list.size() : lastIndex;
                            list = list.subList(0, lastIndex);//获取空闲司机中占比数据
                            System.out.println("空闲司机4"+list);
                            for(TDriver driver : list){//开始进行推送
                                //查询是否在限制推单范围内
                                boolean bo = false;
                                System.out.println("integers"+integers);
                                for(Integer integer : integers){
                                    System.out.println("距离"+integer);
                                    if(integer.compareTo(driver.getId()) == 0){
                                        bo = true;
                                        break;
                                    }
                                }
                                if(bo){
                                    continue;
                                }
                                System.out.println("推送1");
                                pushUtil.pushOrderState(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime());
                                System.out.println("推送2");
                            }
                        }
                        Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间
                        Integer state = tOrderTaxiService.selectById(orderTaxi.getId()).getState();
                        if(state > 1){
                            break;
                        }
                        if(i == querys.size() && state == 1){
                            pushUtil.pushEndPush(1, orderTaxi.getUserId(), orderTaxi.getId(), 2);
                            orderIds.remove(orderTaxi.getId());
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}