liujie
2023-08-31 8d7dbd6d2c0775d45043474c1525ad827b4cd3bd
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
package com.stylefeng.guns.modular.system.controller;
 
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.enums.FacilityCodeEnum;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.utils.PortUtil.FortyNineUtil;
import com.stylefeng.guns.modular.system.utils.PortUtil.SCACEnum;
import com.stylefeng.guns.modular.system.utils.PortUtil.TerminalInterfaceAcquisitionUtil;
import com.stylefeng.guns.modular.system.utils.tips.ErrorTip;
import com.stylefeng.guns.modular.system.utils.tips.SuccessTip;
import com.stylefeng.guns.modular.system.warpper.TerminaleDataWarpper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.net.FileNameMap;
import java.net.URLConnection;
import java.util.*;
 
@Controller
@Api(tags = "订单")
@RequestMapping("/api/order")
public class OrderController {
 
    @Autowired
    private ITOrderService orderService;
 
    @Autowired
    private ITDriverService driverService;
 
    @Autowired
    private ITExamSiteService examSiteService;
 
    @Autowired
    private ITUserFeeSettingService feeSettingService;
 
    @Autowired
    private ITGroupService groupService;
 
    @Autowired
    private  ITUserService itUserService;
 
    @Autowired
    private ITPriceService priceService;
 
    @Autowired
    private IUserService service;
 
    @Autowired
    private ITOrderLogService orderLogService;
 
    @Autowired
    private ITOrderFileService fileService;
 
    @Autowired
    private ITUserAddressService addressService;
 
    @Autowired
    private ITPortService portService;
 
    @Resource
    private ITGoodsService goodsService;
 
    @Resource
    private TUserBankService bankService;
 
    /**
     * company 订单
     * @param dto
     * @return
     */
    @ApiOperation(value = "用户端-订单列表",notes="用户端-订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/getOrderList")
    @ResponseBody
    public Object getOrderList(@RequestBody OrderListDto dto) {
        Page<OrderListVo> orderListVoPage = new Page<>(dto.getPageNumber(), dto.getPageSize());
        List<OrderListVo> list =  orderService.getOrderList(orderListVoPage,dto);
        orderListVoPage.setRecords(list);
        return new SuccessTip(orderListVoPage);
    }
 
    /**
     * company 订单
     * @param orderId 订单id
     * @return
     */
    @ApiOperation(value = "用户端-确认收货",notes="用户端-确认收货")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
    })
    @PostMapping(value = "/affirm")
    @ResponseBody
    public Object affirm( Long orderId) {
        TOrder tOrder = orderService.selectById(orderId);
        tOrder.setStatus("1");
        orderService.updateById(tOrder);
        return new SuccessTip();
    }
 
    /**
     * company 订单
     * @param orderId 订单id
     * @return
     */
    @ApiOperation(value = "用户端-检查站可取货",notes="用户端-检查站可取货")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
    })
    @PostMapping(value = "/affirmOne")
    @ResponseBody
    public Object affirmOne( Long orderId) {
        TOrder tOrder = orderService.selectById(orderId);
 
        if(tOrder.getStatus().equals("13")){
            tOrder.setStatus("14");
        }else {
            return new ErrorTip(5010,"The current status cannot be modified");
        }
        orderService.updateById(tOrder);
        return new SuccessTip();
    }
 
 
 
    @ApiOperation(value = "支付",notes="支付")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "type", value = "1信用支付 2卡支付 ", required = true, dataType = "int"),
            @ApiImplicitParam(name = "cardId", value = "卡id", required = true, dataType = "int"),
    })
    @GetMapping(value = "/pay")
    @ResponseBody
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public Object pay(Long orderId,int type,int cardId){
        TOrder tOrder = orderService.selectById(orderId);
        BigDecimal allTotal = tOrder.getAllTotal();
        if(type==1){
            Integer userId = tOrder.getUserId();
            TUser tUser = itUserService.selectById(userId);
            // 剩余额度
            String reditLimit = tUser.getResidueLimit();
            // 信用额度
            BigDecimal bigDecimal = new BigDecimal(reditLimit);
 
            if(bigDecimal.doubleValue()<allTotal.doubleValue()){
                // 扣完额度
                tUser.setResidueLimit("0");
                // 还需支付
                BigDecimal subtract = allTotal.subtract(bigDecimal);
                TUserBank tUserBank = bankService.selectById(cardId);
                // TODO 支付
            }else {
                // 剩下额度
                BigDecimal subtract = bigDecimal.subtract(allTotal);
                tUser.setResidueLimit(subtract.toString());
                tOrder.setStatus("0");
            }
            orderService.updateById(tOrder);
            itUserService.updateById(tUser);
            return new SuccessTip();
        }else {
            TUserBank tUserBank = bankService.selectById(cardId);
            // TODO 用卡支付
            try {
                tOrder.setStatus("0");
                return new SuccessTip();
            }catch (Exception e){
                e.printStackTrace();
                return new ErrorTip(5007,"ERROR");
            }
        }
    }
 
    @ApiOperation(value = "卡车公司-订单取消",notes="卡车公司-订单取消")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
    })
    @GetMapping(value = "/cancelOrderList")
    @ResponseBody
    public Object cancelOrderList(Long orderId) {
        TOrder tOrder = orderService.selectById(orderId);
        tOrder.setStatus("16");
        orderService.updateById(tOrder);
        return new SuccessTip();
    }
 
 
    @ApiOperation(value = "用户端-安排检查站",notes="用户端-安排检查站")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "examId", value = "examId", required = true, dataType = "int"),
    })
    @GetMapping(value = "/examAdd")
    @ResponseBody
    public Object examAdd(Long orderId,int examId) {
        TOrder tOrder = orderService.selectById(orderId);
        tOrder.setExamSite(examId);
        orderService.updateById(tOrder);
        return new SuccessTip();
    }
 
 
 
 
    @ApiOperation(value = "商品详情",notes="商品详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
    })
    @GetMapping(value = "/getGoodsInfo")
    @ResponseBody
    public Object getGoodsInfo( Long orderId) {
        List<GoodsInfoVo> list = orderService.getGoodsInfo(orderId);
        return new SuccessTip(list);
    }
 
    @ApiOperation(value = "卡车公司-删除订单",notes="卡车公司-删除订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
    })
    @GetMapping(value = "/deleteOrder")
    @ResponseBody
    public Object deleteOrder( Long orderId) {
        TOrder tOrder = orderService.selectById(orderId);
        if(tOrder.getStatus().equals("16")){
            orderService.deleteById(tOrder);
            return new SuccessTip();
        }else {
            return new ErrorTip(5006,"The order status cannot be deleted");
        }
    }
 
    @ApiOperation(value = "订单详情",notes="订单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
    })
    @GetMapping(value = "/getOrderInfo")
    @ResponseBody
    public Object getOrderInfo( Long orderId) {
        HashMap<String, Object> orderInfo = orderService.getOrderInfo(orderId);
        return new SuccessTip(orderInfo);
    }
    @ApiOperation(value = "根据zipcode获取用户地址",notes="根据zipcode获取用户地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "zipcode", value = "zipcode", required = true, dataType = "String"),
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer"),
    })
    @GetMapping(value = "/getAddressByCode")
    @ResponseBody
    public Object getAddressByCode( String  zipcode,Integer id) {
        List<TUserAddress> addresses = addressService.selectList(new EntityWrapper<TUserAddress>().eq("user_id", id).eq("zip_code", zipcode).eq("remove",0));
        return new SuccessTip(addresses);
    }
    @ApiOperation(value = "订单详情--修改reference numbers",notes="订单详情--修改reference numbers")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/updateReference")
    @ResponseBody
    public Object updateReference( TGoods tGoods) {
        boolean b = goodsService.updateById(tGoods);
        return new SuccessTip();
    }
    @Resource
    private TTransportationService tTransportationService;
 
    @Resource
    private TPowerUnitsService powerUnitsService;
 
    @ApiOperation(value = "获取运输安排",notes="卡车公司-获取运输安排")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
    })
    @GetMapping(value = "/getTransportInfo")
    @ResponseBody
    public Object getTransportInfo(@RequestParam Long orderId) {
        TransportInfo transportInfo = new TransportInfo();
        ArrayList<OrderDriverInfo> orderDriverInfos = new ArrayList<>();
        ArrayList<Integer> driverIds = new ArrayList<>();
        TOrder tOrder = orderService.selectById(orderId);
        TPort tPort = portService.selectById(tOrder.getPort());
        // 第一个开始司机id
        Integer sDriverid = tOrder.getsDriverid();
        if(sDriverid!=null){
            driverIds.add(sDriverid);
        }
        // 第2个开始司机id
        Integer sDriverIdOne = tOrder.getsDriverIdOne();
        if(sDriverIdOne!=null){
            driverIds.add(sDriverIdOne);
        }
        Integer driverid = tOrder.geteDriverid();
        if(driverid!=null){
            driverIds.add(driverid);
        }
        Integer driverIdOne = tOrder.geteDriverIdOne();
        if(driverIdOne!=null){
            driverIds.add(driverIdOne);
        }
        TGoods tGoods = goodsService.selectOne(new EntityWrapper<TGoods>().eq("order_id", tOrder.getId()));
        List<TTransportation> tTransportations = tTransportationService.selectList(new EntityWrapper<TTransportation>().eq("order_id", orderId).in("driver_id", driverIds).orderBy("type"));
        TerminaleDataWarpper terminalStatus=new TerminaleDataWarpper();
        try {
            if("LBCT".equals(tPort.getName()) || "APM".equals(tPort.getName())){
                terminalStatus  = TerminalInterfaceAcquisitionUtil.getTerminalStatus(tPort.getName(),tGoods.getContainerNumber(), FacilityCodeEnum.USLAX.getMsg());
            }else {
                // 去查是否存了containerid
                if(ToolUtil.isNotEmpty(tGoods.getShipmentId()) && !"0".equals(tGoods.getShipmentId())){
                    terminalStatus = FortyNineUtil.getContainerNo(tGoods.getShipmentId(), tGoods.getContainerNumber());
                }else {
 
                    String shippingLine = tGoods.getShippingLine();
                    SCACEnum scacEnum = SCACEnum.fromCode(shippingLine);
                    String s;
                    if(ToolUtil.isEmpty(tGoods.getTrackingId()) || "0".equals(tGoods.getTrackingId())){
                        s = FortyNineUtil.trackingRequest(tGoods.getBillNumber(), scacEnum.getDesc());
                        if(ToolUtil.isEmpty(s)){
                            s = FortyNineUtil.trackingList(tGoods.getBillNumber());
                        }
                        tGoods.setTrackingId(s);
                        goodsService.updateById(tGoods);
                    }else {
                        s = tGoods.getTrackingId();
                    }
                    String shipmentId = FortyNineUtil.getShipmentId(s);
                    if(ToolUtil.isNotEmpty(shipmentId)){
                        tGoods.setShipmentId(shipmentId);
                        goodsService.updateById(tGoods);
                    }else {
                        tGoods.setShipmentId("0");
                        tGoods.setTrackingId("0");
                        goodsService.updateById(tGoods);
                    }
                    terminalStatus = FortyNineUtil.getContainerNo(shipmentId, tGoods.getContainerNumber());
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            terminalStatus =new TerminaleDataWarpper();
        }
        for (TTransportation tDriver : tTransportations) {
            OrderDriverInfo orderDriverInfo = new OrderDriverInfo();
            orderDriverInfo.setId(tDriver.getId());
            orderDriverInfo.setDriverId(tDriver.getDriverId());
            if(tDriver.getDriverId().equals(sDriverIdOne)&&tDriver.getType()==1){
                orderDriverInfo.setPickUp(tDriver.getPickDate());
            }
            if(tDriver.getDriverId().equals(sDriverIdOne)&&tDriver.getType()==2){
                orderDriverInfo.setPickUp(tDriver.getPickDate());
            }
            if(tDriver.getDriverId().equals(driverid) &&tDriver.getType()==3){
                orderDriverInfo.setEmptyDate(tDriver.getEmptyDate());
            }
            if(tDriver.getDriverId().equals(driverIdOne) &&tDriver.getType()==4){
                orderDriverInfo.setReturnDate(tDriver.getReturnDate());
            }
            orderDriverInfo.setContactEmail(tDriver.getEmail());
            orderDriverInfo.setContactName(tDriver.getName());
            orderDriverInfo.setContactPhone(tDriver.getPhone());
            orderDriverInfo.setTPowerUnits(powerUnitsService.selectById(tDriver.getPowerUnit()));
            orderDriverInfo.setChassiess(powerUnitsService.selectById(tDriver.getChassises()));
 
            // TODO 第三方  目前不知道对接那个
            orderDriverInfo.setAppointmentNumber(terminalStatus.getAppointmentNumber());
 
            orderDriverInfos.add(orderDriverInfo);
 
        }
        transportInfo.setTruckCompany(tOrder.getTruckCompany());
        transportInfo.setPickupTime(tOrder.getPickupTimeTruck());
        transportInfo.setStreetTurn(tOrder.getStreetTurn());
 
 
        transportInfo.setLineHold(terminalStatus.getLineHold());
        transportInfo.setCustomHold(terminalStatus.getCustomHold());
        transportInfo.setPierpass(terminalStatus.getPierpass());
        transportInfo.setCTF(terminalStatus.getCtf());
        transportInfo.setClosedArea(terminalStatus.getClosedArea());
        transportInfo.setLFD(terminalStatus.getLfd());
        transportInfo.setAvailable(terminalStatus.getAvailability());
 
        transportInfo.setList(orderDriverInfos);
        Integer examSite = tOrder.getExamSite();
        if(Objects.nonNull(examSite)){
            TExamSite tExamSite = examSiteService.selectById(examSite);
            transportInfo.setAddress(tExamSite.getAddress());
            transportInfo.setContactEmail(tExamSite.getContactEmail());
            transportInfo.setContactName(tExamSite.getContactName());
            transportInfo.setExamSiteName(tExamSite.getExamSiteName());
            transportInfo.setZipCode(tExamSite.getZipCode());
        }
        return new SuccessTip(transportInfo);
    }
 
 
    @ApiOperation(value = "获取订单司机位置",notes="获取订单司机位置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "lon", value = "lon", required = true, dataType = "String"),
            @ApiImplicitParam(name = "lat", value = "lat", required = true, dataType = "String"),
    })
    @GetMapping(value = "/getLonLat")
    @ResponseBody
    public Object getLonLat(Long orderId){
        //  通过司机id获取订单
        List<Map<String,Object>> orders = orderService.getLonLat(orderId);
        return new SuccessTip(orders);
    }
 
 
    @ApiOperation(value = "获取费用明细",notes="获取费用明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
    })
    @GetMapping(value = "/getPriceInfo")
    @ResponseBody
    public Object getPriceInfo(Long orderId){
 
        TOrder tOrder = orderService.selectById(orderId);
        Integer userId = tOrder.getUserId();
        // 获取用户所i在分组
        TUser tUser = itUserService.selectById(userId);
        List<TPrice> prices = priceService.selectList(new EntityWrapper<TPrice>().eq("order_id", tOrder.getId()));
        ArrayList<PriceInfo> priceInfos = new ArrayList<>();
        if(tUser.getGroupId()!=null){
            TGroup tGroup = groupService.selectById(tUser.getGroupId());
            User user = service.selectById(tGroup.getSalesId());
 
            // 提成
            Double commission = user.getCommission();
 
            // 获取分组sale
            List<TUserFeeSetting> tUserFeeSettings = feeSettingService.selectList(new EntityWrapper<TUserFeeSetting>().eq("user_id", tGroup.getSalesId()));
 
            // 提成一个  根据价格判断
            for (TPrice price : prices) {
                for (TUserFeeSetting tUserFeeSetting : tUserFeeSettings) {
                    if(price.getType().equals(tUserFeeSetting.getName())){
                        PriceInfo priceInfo = new PriceInfo();
                        priceInfo.setName(price.getType());
                        priceInfo.setCustomerCost(price.getPrice());
                        if(tUserFeeSetting.getFee()!=null && tUserFeeSetting.getFee()!=0) {
                            double v = ((double) tUserFeeSetting.getFee()) / 100;
                            BigDecimal multiply = price.getPrice().multiply(new BigDecimal(v));
                            BigDecimal subtract = price.getPrice().subtract(multiply);
                        }else {
                        }
                        priceInfos.add(priceInfo);
                        break;
                    }
                }
            }
        }else {
            for (TPrice price : prices) {
                PriceInfo priceInfo = new PriceInfo();
                priceInfo.setCustomerCost(price.getPrice());
                priceInfo.setName(price.getType());
                priceInfos.add(priceInfo);
            }
        }
        return new SuccessTip(priceInfos);
 
    }
 
    @ApiOperation(value = "获取订单日志",notes="获取订单日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int"),
    })
    @GetMapping(value = "/getOrderLog")
    @ResponseBody
    public Object getOrderLog(Long orderId,int pageNumber,int pageSize){
        Page<TOrderLog> tOrderLogPage = new Page<>(pageNumber, pageSize);
        Page<TOrderLog> page = orderLogService.selectPage(tOrderLogPage, new EntityWrapper<TOrderLog>().eq("order_id", orderId).orderBy("create_time",false));
        return new SuccessTip(page);
    }
 
 
 
    @ApiOperation(value = "卡车公司--安排司机",notes="卡车公司--安排司机")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/selectDriver")
    @ResponseBody
    public Object selectDriver(@RequestBody CompanySelectDriverDto companySelectDriverDto){
        try {
 
            Long orderId = companySelectDriverDto.getOrderId();
            // 找出这个订单
            TOrder tOrder = orderService.selectById(orderId);
            List<TTransportation> list = companySelectDriverDto.getList();
            tOrder.setsDriverid(list.get(0).getDriverId());
            tOrder.setsDriverIdOne(list.get(1).getDriverId());
            tOrder.seteDriverid(list.get(2).getDriverId());
            tOrder.seteDriverIdOne(list.get(3).getDriverId());
            tOrder.setTruckCompany(companySelectDriverDto.getTruckCompany());
            tOrder.setPickupTimeTruck(companySelectDriverDto.getPickupTime());
            tOrder.setStreetTurn(companySelectDriverDto.getStreetTurn());
 
            // 添加司机信息
            tTransportationService.insertBatch(companySelectDriverDto.getList());
            // 更改订单信息
            orderService.updateById(tOrder);
            return new SuccessTip();
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ErrorTip(500,"ERROR");
    }
 
 
    @ApiOperation(value = "卡车公司--修改安排司机(多个)",notes="卡车公司--修改安排司机(多个)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/updateDriver")
    @ResponseBody
    public Object updateDriver(@RequestBody CompanySelectDriverDto companySelectDriverDto){
        try {
 
            Long orderId = companySelectDriverDto.getOrderId();
            // 找出这个订单
            TOrder tOrder = orderService.selectById(orderId);
            List<TTransportation> list = companySelectDriverDto.getList();
            tOrder.setsDriverid(list.get(0).getDriverId());
            tOrder.setsDriverIdOne(list.get(1).getDriverId());
            tOrder.seteDriverid(list.get(2).getDriverId());
            tOrder.seteDriverIdOne(list.get(3).getDriverId());
            tOrder.setTruckCompany(companySelectDriverDto.getTruckCompany());
            tOrder.setPickupTimeTruck(companySelectDriverDto.getPickupTime());
            tOrder.setStreetTurn(companySelectDriverDto.getStreetTurn());
            // 删除原来的司机信息
            tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId));
            // 添加新司机信息
            tTransportationService.insertBatch(companySelectDriverDto.getList());
            // 更改订单信息
            orderService.updateById(tOrder);
            return new SuccessTip();
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ErrorTip(500,"ERROR");
    }
 
    @ApiOperation(value = "卡车公司--修改安排司机(单个)",notes="卡车公司--修改安排司机(单个)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/updateDriverSingle")
    @ResponseBody
    public Object updateDriverSingle(@RequestBody CompanySelectDriverSingleDto companySelectDriverSingleDto){
        try {
 
            Long orderId = companySelectDriverSingleDto.getOrderId();
            // 找出这个订单
            TOrder tOrder = orderService.selectById(orderId);
            TTransportation list = companySelectDriverSingleDto.getList();
            list.setOrderId(companySelectDriverSingleDto.getOrderId());
            Integer type = companySelectDriverSingleDto.getList().getType();
            if(type==1){
                tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.getsDriverid()).eq("type",1));
                tOrder.setsDriverid(list.getDriverId());
            }else if(type==2){
                tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.getsDriverIdOne()).eq("type",2));
                tOrder.setsDriverIdOne(list.getDriverId());
            }else if(type==3){
                tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.geteDriverid()).eq("type",3));
                tOrder.seteDriverid(list.getDriverId());
            }else {
                tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.geteDriverIdOne()).eq("type",4));
                tOrder.seteDriverIdOne(list.getDriverId());
            }
            tTransportationService.insert(list);
            // 删除原来的司机信息
            // 更改订单信息
            orderService.updateById(tOrder);
            return new SuccessTip();
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ErrorTip(500,"ERROR");
    }
 
    @Resource
    private TYardService yardService;
 
 
    @ApiOperation(value = "卡车公司--点击定位(场地/码头)",notes="卡车公司--点击定位(场地/码头)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/getLocation")
    @ResponseBody
    public Object getLocation(@RequestBody CompanyLocationDto companyLocationDto){
        try {
 
            Long orderId = companyLocationDto.getOrderId();
            // 找出这个订单
            TOrder tOrder = orderService.selectById(orderId);
            Integer type = companyLocationDto.getType();
            if(type==1){
                TTransportation tTransportation = tTransportationService.selectOne(new EntityWrapper<TTransportation>().eq("order_id", orderId).eq("driver_id", tOrder.getsDriverIdOne()));
                if(tTransportation!=null){
                    Integer yardId = tTransportation.getYardId();
                    TYard tYard = yardService.selectById(yardId);
                    return new SuccessTip(tYard);
                }
            }else if(type==2){
                TTransportation tTransportation = tTransportationService.selectOne(new EntityWrapper<TTransportation>().eq("order_id", orderId).eq("driver_id", tOrder.geteDriverid()));
                if(tTransportation!=null) {
                    Integer yardId = tTransportation.getYardId();
                    TYard tYard = yardService.selectById(yardId);
                    return new SuccessTip(tYard);
                }
            }else if(type==3){
                TTransportation tTransportation = tTransportationService.selectOne(new EntityWrapper<TTransportation>().eq("order_id", orderId).eq("driver_id", tOrder.geteDriverIdOne()));
                if(tTransportation!=null) {
                    Integer portId = tTransportation.getPortId();
                    TPort tPort = portService.selectById(portId);
                    return new SuccessTip(tPort);
                }
            }
            return new ErrorTip(5001,"not found");
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ErrorTip(500,"ERROR");
    }
 
 
 
    @ApiOperation(value = "运输安排---选择公司司机",notes="运输安排---选择公司司机")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int"),
            @ApiImplicitParam(name = "id", value = "当前公司id", required = true, dataType = "int"),
    })
    @GetMapping(value = "/getDriverSelect")
    @ResponseBody
    public Object getDriverSelect(int pageNumber,int pageSize,int id){
        Page<TDriver> tDriverPage = new Page<>(pageNumber, pageSize);
        Page<TDriver> tDriverPage1 = driverService.selectPage(tDriverPage, new EntityWrapper<TDriver>().eq("is_carriers", 1).eq("company_id", id).eq("remove", 0));
        ArrayList<TDriverSelectVo> tDriverSelectVos = new ArrayList<>();
        List<TDriver> records = tDriverPage1.getRecords();
        records.forEach(e->{
            TDriverSelectVo tDriverSelectVo = new TDriverSelectVo();
            BeanUtil.copyProperties(e,tDriverSelectVo);
            tDriverSelectVos.add(tDriverSelectVo);
        });
        Page<TDriverSelectVo> page = new Page<>();
        BeanUtil.copyProperties(tDriverPage1,page);
        page.setRecords(tDriverSelectVos);
        return new SuccessTip(page);
    }
 
 
 
    @ApiOperation(value = "运输安排---承运商选择司机",notes="运输安排---承运商选择司机")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int"),
            @ApiImplicitParam(name = "id", value = "承运商ud", required = true, dataType = "int"),
    })
    @GetMapping(value = "/getDriverSelectFromCarriers")
    @ResponseBody
    public Object getDriverSelectFromCarriers(int pageNumber,int pageSize,int id){
        Page<TDriver> tDriverPage = new Page<>(pageNumber, pageSize);
        Page<TDriver> tDriverPage1 = driverService.selectPage(tDriverPage, new EntityWrapper<TDriver>().eq("is_carriers", 2).eq("carriers_id", id).eq("remove", 0));
        ArrayList<TDriverSelectVo> tDriverSelectVos = new ArrayList<>();
        List<TDriver> records = tDriverPage1.getRecords();
        records.forEach(e->{
            TDriverSelectVo tDriverSelectVo = new TDriverSelectVo();
            BeanUtil.copyProperties(e,tDriverSelectVo);
            tDriverSelectVos.add(tDriverSelectVo);
        });
        Page<TDriverSelectVo> page = new Page<>();
        BeanUtil.copyProperties(tDriverPage1,page);
        page.setRecords(tDriverSelectVos);
        return new SuccessTip(page);
    }
 
 
 
 
    @ApiOperation(value = "获取订单文件",notes="获取订单文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int"),
    })
    @GetMapping(value = "/getOrderFile")
    @ResponseBody
    public Object getOrderFile(Long orderId,int pageNumber,int pageSize){
        Page<TOrderFile> tOrderFilePage = new Page<>(pageNumber, pageSize);
        Page<TOrderFile> orderFilePage = fileService.selectPage(tOrderFilePage, new EntityWrapper<TOrderFile>().eq("order_id", orderId).orderBy("create_time",false));
        List<TOrderFile> records = orderFilePage.getRecords();
        for (TOrderFile record : records) {
            FileNameMap fileNameMap = URLConnection.getFileNameMap();
            String contentTypeFor = fileNameMap.getContentTypeFor(record.getFile());
            String type=null;
            if(contentTypeFor==null){
                type="video";
            }else {
                type="img";
            }
            record.setType(type);
        }
        TOrder tOrder = orderService.selectById(orderId);
        if("9".equals(tOrder.getStatus()) || "18".equals(tOrder.getStatus())){
            ArrayList<TOrderFile> tOrderFiles = new ArrayList<>();
            TOrderFile tOrderFile = new TOrderFile();
            tOrderFile.setName("Bill of lading.pdf");
            tOrderFile.setId(0);
            tOrderFile.setType("file");
            tOrderFiles.add(tOrderFile);
            tOrderFiles.addAll(records);
            orderFilePage.setRecords(tOrderFiles);
        }else {
 
            orderFilePage.setRecords(records);
        }
        return new SuccessTip(orderFilePage);
    }
 
    @ApiOperation(value = "添加订单文件",notes="添加订单文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "url", value = "文件链接", required = true, dataType = "String"),
            @ApiImplicitParam(name = "name", value = "文件名称", required = true, dataType = "String"),
    })
    @PostMapping(value = "/addOrderFile")
    @ResponseBody
    public Object addOrderFile(@RequestBody AddOrderFile addOrderFile){
        Long orderId = addOrderFile.getOrderId();
        List<TOrderFileDto> file = addOrderFile.getFile();
        Boolean b =false;
        for (TOrderFileDto tOrderFileDto : file) {
            b = orderService.addOrderFile(orderId, tOrderFileDto.getUrl(), tOrderFileDto.getDeleteUrl());
        }
 
        if(b){
            return new SuccessTip();
        }
        return new ErrorTip(500,"ERROR");
    }
 
 
    @ApiOperation(value = "订单详情-提货单",notes="订单详情-提货单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType     = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
    })
    @GetMapping(value = "/getOrderLading")
    @ResponseBody
    public Object getOrderLading(Long orderId){
        try {
            OrderLading orderLading = new OrderLading();
            TOrder tOrder = orderService.selectById(orderId);
            // 找出用户
            TUser tUser = itUserService.selectById(tOrder.getUserId());
            orderLading.setCustomerName(tUser.getCompanyName());
            // 找出默认地址
            List<TUserAddress> addresses = addressService.selectList(new EntityWrapper<TUserAddress>().eq("user_id", tUser.getId()));
            if(addresses.size()>0){
                for (TUserAddress address : addresses) {
                    if(address.getIsDefault()==1){
                        orderLading.setCustomerAddress(address.getAddress());
                    }
                }
                if(orderLading.getCustomerAddress()==null){
                    orderLading.setCustomerAddress(addresses.get(0).getAddress());
                }
            }
            orderLading.setCustomerPhone(tUser.getPhone());
            // 码头信息
            TPort tPort = portService.selectById(tOrder.getPort());
            orderLading.setPortAddress(tPort.getAddress());
            orderLading.setOrderCreateTime(tOrder.getCreateTime());
            orderLading.setShipmentDate(tOrder.getShipmentDate());
            // 货物信息
            TGoods tGoods = goodsService.selectList(new EntityWrapper<TGoods>().eq("order_id", orderId)).get(0);
            orderLading.setOurRef(tGoods.getOurRef());
            orderLading.setSb(tGoods.getSb());
            orderLading.setPo(tGoods.getPo());
            orderLading.setCustRef(tGoods.getCustRef());
            orderLading.setEntry(tGoods.getEntry());
            // 获取收货信息
            orderLading.setEndCompanyName(tOrder.geteCompanyName());
            orderLading.setEndCompanyAddress(tOrder.geteAddress());
            orderLading.setEndContactName(tOrder.geteName());
            orderLading.setEndContactPhone(tOrder.getePhone());
            return new SuccessTip(orderLading);
        }catch (Exception e){
            e.printStackTrace();
            return new ErrorTip(500,"ERROR");
        }
    }
 
 
 
 
    @ApiOperation(value = "平台给用户报价/平台给卡车公司价格",notes="平台给用户报价/平台给卡车公司价格")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "orderId", value = "orderId", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "type", value = "1平台给用户报价 2平台给卡车公司价格", required = true, dataType = "int"),
    })
    @GetMapping(value = "/getPriceFromPlatform")
    @ResponseBody
    public Object getPriceFromPlatform(Long orderId,int type){
        HashMap<String, Object> map = new HashMap<>();
 
        TOrder tOrder = orderService.selectById(orderId);
        // 根据订单获取报价
 
        map.put("invoice",tOrder.getInvoiceNumber());
        map.put("pickUpDate",tOrder.getShipmentDate());
        map.put("returnDate",tOrder.getOrderOkTime());
        List<TPrice> prices = priceService.selectList(new EntityWrapper<TPrice>().eq("order_id", orderId));
        if(type==1){
            map.put("price",prices);
        }else{
            // 找出订单用户 --> 获取销售--> 获取提成 --> 计算应给卡车公司金额
            Integer userId = tOrder.getUserId();
            TUser tUser = itUserService.selectById(userId);
            if(tUser.getGroupId()==null){
                map.put("price",prices);
            }else {
                TGroup tGroup = groupService.selectById(tUser.getGroupId());
                User user = service.selectById(tGroup.getSalesId());
                List<TUserFeeSetting> tUserFeeSettings = feeSettingService.selectList(new EntityWrapper<TUserFeeSetting>().eq("user_id", user.getId()));
 
                for (TPrice price : prices) {
                    for (TUserFeeSetting tUserFeeSetting : tUserFeeSettings) {
                        if(price.getType().equals(tUserFeeSetting.getName())){
                            if(tUserFeeSetting.getFee()!=null && tUserFeeSetting.getFee()!=0) {
                                double v = ((double) tUserFeeSetting.getFee()) / 100;
                                BigDecimal multiply = price.getPrice().multiply(new BigDecimal(v));
                                BigDecimal subtract = price.getPrice().subtract(multiply);
                                price.setPrice(subtract);
                            }else {
                                price.setPrice(price.getPrice());
                            }
                            break;
                        }
                    }
                }
                map.put("price",prices);
            }
        }
        return new SuccessTip(map);
    }
 
 
 
    
 
 
 
}