liujie
2025-08-08 f604df04d1f9fe90ee543a1772a3a8cdb50d3d66
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
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
package com.stylefeng.guns.modular.shunfeng.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.shunfeng.model.*;
import com.stylefeng.guns.modular.shunfeng.model.vo.ApiJson;
import com.stylefeng.guns.modular.shunfeng.model.vo.OrderRideInfoVo;
import com.stylefeng.guns.modular.shunfeng.model.vo.OrderRideVo;
import com.stylefeng.guns.modular.shunfeng.service.*;
import com.stylefeng.guns.modular.shunfeng.task.base.QuartzManager;
import com.stylefeng.guns.modular.shunfeng.task.base.TimeJobType;
import com.stylefeng.guns.modular.shunfeng.task.jobs.CourseExamineRide;
import com.stylefeng.guns.modular.shunfeng.util.OrdersUtil;
import com.stylefeng.guns.modular.shunfeng.util.SensitiveWordUtil;
import com.stylefeng.guns.modular.system.dao.SensitiveWordsMapper;
import com.stylefeng.guns.modular.system.model.SensitiveWords;
import com.stylefeng.guns.modular.system.model.TCarBrand;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.ISystemNoticeService;
import com.stylefeng.guns.modular.system.service.ITCarBrandService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.util.DateUtil;
import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil;
import com.stylefeng.guns.modular.system.util.PushUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.util.qianyuntong.UserUtil;
import io.swagger.annotations.*;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
import java.util.*;
 
/**
 * 顺风车相关接口
 */
@Api(tags = "顺风车相关接口")
@Controller
@RequestMapping("/api/rideComment")
public class rideCommentController {
        /*顺风车订单*/
        @Autowired
        private IOrderRideService orderRideService;
        /*顺风车行程*/
        @Autowired
        private IOrderTravelService orderTravelService;
        /*顺风车设置*/
        @Autowired
        private IParamRideService paramRideService;
        /*定时任务*/
        @Autowired
        private ITimeTaskService timeTaskService;
        /*顺风车司机*/
        @Autowired
        private IDriverRideService driverRideService;
        /*顺风车品牌*/
        @Autowired
        private ITCarBrandService carBrandService;
        /*评价*/
        @Autowired
        private IEvaluateService evaluateService;
        /*投诉*/
        @Autowired
        private IComplaintsService complaintsService;
        /*实名认证*/
        @Autowired
        private IUserApplyService applyService;
        @Autowired
        private GDMapElectricFenceUtil gdMapElectricFenceUtil;
        
        @Autowired
        private IUserInfoService userInfoService;
        
        @Autowired
        private PushUtil pushUtil;
        
        @Autowired
        private ISystemNoticeService systemNoticeService;
        
        @Resource
        private SensitiveWordsMapper sensitiveWordsMapper;
        
        @Autowired
        private IFinancialService financialService;
        
 
 
    /**
     * 发布顺风车行程实名认证
     * @param userId
     * @param type:1用户身份申请,2司机身份申请
     *
     * @param
     * @return
     */
    @ResponseBody
    @PostMapping("/authentication")
    @ApiOperation(value = "发布顺风车行程实名认证", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"),
            @ApiImplicitParam(name = "name", value = "姓名", dataType = "string"),
            @ApiImplicitParam(name = "identity", value = "身份证", dataType = "string"),
            @ApiImplicitParam(name = "type", value = "1用户,2司机", dataType = "int"),
    })
    public Object authentication(Integer userId,String name,String  identity,Integer type) {
        try {
            if (userId == null || userId == 0) {
                return ResultUtil.paranErr("userId不能为空");
            }
            /*发布顺风车行程实名认证*/
            UserApply apply=new UserApply();
            apply.setUserId(userId);
            apply.setApplyTime(new Date());
            apply.setApplyState(1);
            apply.setType(type);//司机申请
            apply.setApplyType(3);//3发布顺风车行程实名认证
            apply.setName(name);
            apply.setIdentity(identity);
            apply.setApplyState(1);
            Boolean aBoolean = UserUtil.idCardAuth(name, identity);
            if(aBoolean){
                apply.setApplyState(2);
                /*修改用户实名认证通过*/
                UserInfo userInfo=new UserInfo();
                userInfo.setId(userId);
                userInfo.setIsAuth(2);
                String sex = identity.substring(16, 17); //取指定位置的值(16位之后,17位结束;)
                int b = Integer.parseInt(sex);//强制类型转换
                if (b % 2 == 0) {
                    userInfo.setSex(2);
                } else {
                    userInfo.setSex(1);
                }
                userInfo.setName(name);
                userInfo.setIdCard(identity);
                userInfoService.updateById(userInfo);
            }else {
                apply.setApplyState(3);
            }
            applyService.insert(apply);
            Map<String,Object> reMap=new HashMap<>();
            reMap.put("auditState", aBoolean);
            return ResultUtil.success(reMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
 
    /**
     * 人脸识别
     * @param userId
     * @param headImg
     * @return
     */
    @ResponseBody
    @PostMapping("/faceAuthentication")
    @ApiOperation(value = "人脸识别", httpMethod = "POST")
    public Object authentication(Integer userId,String headImg) {
//        try {
//            if (userId == null || userId == 0) {
//                return ResultUtil.paranErr("userId不能为空");
//            }
//            /*查询实名认证信息*/
//            UserApply apply=applyService.selectOne(new EntityWrapper<UserApply>().eq("userId",userId)
//                    .eq("applyState",2)
//                    .eq("applyType",3));
//            /*是否验证成功*/
//            Integer auditState=0;
//            if(apply!=null){
//                String name=apply.getName();
//                String identity=apply.getIdentity();
//                apply.setHeadImg(headImg);
//                applyService.updateById(apply);
//                /*todo 第三方实名认证*/
//                String urlBase64=RealNameAuthenticationUtil.NetImageToBase64(headImg);
//                Map<String, String> bodys = new HashMap<String, String>();
//                bodys.put("base64Str", urlBase64);
//                bodys.put("liveChk", "0");
//                bodys.put("name", name);
//                bodys.put("number", identity);
//                Boolean result=RealNameAuthenticationUtil.faceAuthentication(bodys);
//                if(result){//认证通过
//                    auditState=1;
//                }
//                if(auditState==1){//审核通过
//                    UserInfo userInfo=new UserInfo();
//                    userInfo.setId(userId);
//                    userInfo.setIsFaceAuthenticationRide(1);
//                    userInfo.setCertificationImg(headImg);
//                    userInfoService.updateById(userInfo);
//                }
//            }
//            Map<String,Object> reMap=new HashMap<>();
//            reMap.put("auditState",auditState);
//            return ApiJson.returnOK(reMap);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        return ResultUtil.paranErr("异常");
    }
 
    /**
     * 获取车辆品牌列表
     * @return
     */
    @ResponseBody
    @GetMapping("/getBrandList")
    @ApiOperation(value = "获取车辆品牌列表", httpMethod = "GET")
    public Object getBrandList(){
        try {
            List<TCarBrand> tCarBrands = carBrandService.selectList(null);
            return ApiJson.returnOK(tCarBrands);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
 
    /**
     * 顺风车首页(待处理订单数)
     * @param userId  用户id
     * @param type 1= 用户,2顺风车司机
     * @return
     */
    @ResponseBody
    @GetMapping("/homeOrderCount")
    @ApiOperation(value = "顺风车首页(待处理订单数)", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"),
            @ApiImplicitParam(name = "type", value = "1用户,2司机", dataType = "int"),
    })
    public Object homeOrderCount(Integer userId,Integer type){
        try {
            if(ToolUtil.isEmpty(userId)){
                return ResultUtil.paranErr("userId不能为空");
            }
            if(ToolUtil.isEmpty(type)){
                return ResultUtil.paranErr("type不能为空");
            }
            Integer count=0;
 
            if(type==1){//用户待处理订单:进行中的订单
                EntityWrapper<OrderRide> entityWrapper=new EntityWrapper();
                entityWrapper.eq("userId",userId);
                entityWrapper.in("state","1,2,3,4");
                count=orderRideService.selectCount(entityWrapper);
            }else if(type==2){//司机待处理订单:进行中的订单
                EntityWrapper<OrderTravel> entityWrapper=new EntityWrapper();
                entityWrapper.eq("driverId",userId);
                entityWrapper.in("state","2,3,4");
                count=orderTravelService.selectCount(entityWrapper);
            }
            return ApiJson.returnOK(count);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("获取异常");
    }
 
    /**
     * 顺风车首页(待处理订单列表)
     * @param userId
     * @param type 1用户待处理订单:进行中的订单 2司机待处理订单:进行中的订单 3我的顺风车行程
     * @return
     */
    @ResponseBody
    @GetMapping("/homeOrderList")
    @ApiOperation(value = "顺风车首页(待处理订单列表)", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"),
            @ApiImplicitParam(name = "type", value = "1用户待处理订单:进行中的订单 2司机待处理订单:进行中的订单 3我的顺风车行程", dataType = "int"),
    })
    public Object homeOrderList(Integer userId,Integer type,Integer current,Integer size){
        try {
            if(ToolUtil.isEmpty(userId)){
                return ResultUtil.paranErr("userId不能为空");
            }
            if(ToolUtil.isEmpty(type)){
                return ResultUtil.paranErr("type不能为空");
            }
            List<OrderRideVo> rideVoList=new ArrayList<>();
            OrderRideVo orderRideVo=new OrderRideVo();
            orderRideVo.setCurrent(current > 0 ? (current - 1) * size : 0);
            orderRideVo.setSize(size);
            orderRideVo.setUserId(userId);
            orderRideVo.setDriverId(userId);
            if(type==1){//用户待处理订单:进行中的订单
                orderRideVo.setType(1);//待处理订单
                rideVoList=orderRideService.getOrderRide(orderRideVo);
            }else if(type==2){//司机待处理订单:进行中的订单
                orderRideVo.setType(1);//待处理订单
                rideVoList=orderTravelService.getOrderTravel(orderRideVo);
            }else if(type==3){//我的行程
                UserInfo userInfo=userInfoService.selectById(userId);
                orderRideVo.setDriverId(userInfo.getDriverId());
                rideVoList=orderRideService.getOrderRideAndTravel(orderRideVo);
            }
            return ApiJson.returnOK(rideVoList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("获取异常");
    }
 
    /**
     * 根据输入的开始结束经纬度和人数获取订单价格
     * @param num
     * @return
     */
    @ResponseBody
    @PostMapping("/orderPrice")
    @ApiOperation(value = "根据输入的开始结束经纬度和人数获取订单价格", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "num", value = "人数", dataType = "int"),
            @ApiImplicitParam(name = "startLat", value = "起点纬度", dataType = "double"),
            @ApiImplicitParam(name = "startLon", value = "起点经度", dataType = "double"),
            @ApiImplicitParam(name = "endLat", value = "终点纬度", dataType = "double"),
            @ApiImplicitParam(name = "endLon", value = "终点经度", dataType = "double"),
    })
    public Object orderPrice(Integer num,Double startLat,Double startLon,Double endLat,Double endLon){
        try {
            String locationS=startLon+","+startLat;
            String locationE=endLon+","+endLat;
            if(locationE==null){
                return ApiJson.returnOK(null);
            }
            /*计算两个地址的距离*/
            String strS=locationS;
            String strE=locationE;
            Map<String,String> map1= null;
            try {
                map1 = gdMapElectricFenceUtil.getDistance(strS,strE, 1);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            Double distance=Double.valueOf(map1.get("distance"))/1000;//距离公里
            Integer distanceType=1;
            //距离类型(1-100==1,100-200==2,200-500==3,500-800==4,800以上==5)
            if(distance<100){
                distanceType=1;
            }else if(distance>=100 && distance<200){
                distanceType=2;
            }else if(distance>=200 && distance<500){
                distanceType=3;
            }else if(distance>=500 && distance<800){
                distanceType=4;
            }else {
                distanceType=5;
            }
            ParamRide paramRide=paramRideService.selectOne(new EntityWrapper<ParamRide>().eq("type",1).eq("distanceType",distanceType));
            Double price=0d;
            if(paramRide!=null){
                JSONObject jsonObject =JSONObject.fromObject(paramRide.getContext());
                String priceStr=jsonObject.getString("person"+num+"");
                if(priceStr!=null){
                    price=Double.valueOf(priceStr)*distance;
                }
            }
            return ApiJson.returnOK(price);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("获取异常");
    }
 
    /**
     * 用户下单
     * @param userId
     * @param startTime
     * @param num
     * @param startName
     * @param endName
     * @param isDai
     * @param lxPhone
     * @return
     */
    @ResponseBody
    @PostMapping("/userAddOrder")
    @ApiOperation(value = "用户下单", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"),
            @ApiImplicitParam(name = "startTime", value = "出行时间", dataType = "string"),
            @ApiImplicitParam(name = "num", value = "出行人数", dataType = "int"),
            @ApiImplicitParam(name = "startName", value = "起点名称", dataType = "string"),
            @ApiImplicitParam(name = "startLat", value = "起点纬度", dataType = "double"),
            @ApiImplicitParam(name = "startLon", value = "起点经度", dataType = "double"),
            @ApiImplicitParam(name = "endName", value = "终点名称", dataType = "string"),
            @ApiImplicitParam(name = "endLat", value = "终点纬度", dataType = "double"),
            @ApiImplicitParam(name = "endLon", value = "终点经度", dataType = "double"),
            @ApiImplicitParam(name = "money", value = "金额", dataType = "double"),
            @ApiImplicitParam(name = "isDai  1=是 2=否", value = "是否代喊  1=是 2=否", dataType = "int"),
            @ApiImplicitParam(name = "lxPhone", value = "联系电话", dataType = "string"),
    })
    public Object addOrder(Integer userId,String startTime,Integer num,String startName,Double startLat,Double startLon,Double endLat,Double endLon,
                           String endName,Double money,Integer isDai,String lxPhone){
        try {
            if(ToolUtil.isEmpty(userId)){
                return ResultUtil.paranErr("userId不能为空");
            }
            if(ToolUtil.isEmpty(startTime)){
                return ResultUtil.paranErr("startTime不能为空");
            }
            if(ToolUtil.isEmpty(num)){
                return ResultUtil.paranErr("num不能为空");
            }
            if(ToolUtil.isEmpty(startName)){
                return ResultUtil.paranErr("startName不能为空");
            }
            if(ToolUtil.isEmpty(endName)){
                return ResultUtil.paranErr("endName不能为空");
            }
            if(ToolUtil.isEmpty(money)){
                return ResultUtil.paranErr("money不能为空");
            }
            /*用户只能发布一个进行中的行程*/
            /*EntityWrapper<OrderRide> entityWrapper=new EntityWrapper();
            entityWrapper.eq("userId",userId);
            entityWrapper.in("state","1,2,3,4");
            Integer count=orderRideService.selectCount(entityWrapper);
            if(count>0){
                return ResultUtil.paranErr("还有进行中的订单");
            }*/
            /*用户可以发布多个订单*/
            ParamRide paramRide=paramRideService.selectOne(new EntityWrapper<ParamRide>().eq("type",2));
            Double platformMoney=0d;
            if(paramRide!=null){
                JSONObject jsonObject =JSONObject.fromObject(paramRide.getContext());
                String priceStr=jsonObject.getString("commission"+num+"");
                if(priceStr!=null){
                    platformMoney=Double.valueOf(priceStr);
                }
            }
            OrderRide orderRide=new OrderRide();
            orderRide.setOrderNum(OrdersUtil.getOrderNoForPrefix("ride"));
            orderRide.setPlatformMoney(platformMoney);
            orderRide.setAddTime(new Date());
            orderRide.setUserId(userId);
            orderRide.setStartTime(DateUtil.getDate(startTime,"yyyy-MM-dd HH:mm"));
            orderRide.setNum(num);//乘车人数
            orderRide.setStartName(startName);//出发地
            orderRide.setStartLon(startLon);
            orderRide.setStartLat(startLat);
            orderRide.setEndName(endName);//目的地
            orderRide.setEndLon(endLon);
            orderRide.setEndLat(endLat);
            orderRide.setIsDai(isDai);
            orderRide.setLxPhone(lxPhone);
            orderRide.setMoney(money);
            orderRide.setState(1);//未支付状态
            orderRideService.insert(orderRide);
            //todo 定时人数  自动取消订单
            Integer time =10;
            Map<String,Object> reMap=new HashMap<>();
            reMap.put("djs",time);
            reMap.put("orderId",orderRide.getId());
            reMap.put("addTime",orderRide.getAddTime());
            // 添加定时任务信息
            TimeTask timeTask=new TimeTask();
            timeTask.setCreateDate(new Date());
            timeTask.setExcuteDate(DateUtil.getDate_strYMdHms(System.currentTimeMillis() + 1000*60*time));
            timeTask.setTaskName((CourseExamineRide.DSCE+orderRide.getId()).toUpperCase());
            timeTask.setTypeName(CourseExamineRide.DSCE);
            timeTask.setMap(orderRide.getId()+"");
            timeTaskService.insert(timeTask);
            //倒计时
            Map<String,Object> maps=new HashMap<>();
            maps.put("orderId",orderRide.getId());
            maps.put("timeTaskId",timeTask.getId());
            QuartzManager.addJob(CourseExamineRide.class,(CourseExamineRide.DSCE+orderRide.getId()).toUpperCase(), TimeJobType.UNLOCK, DateUtil.getDate_strYMdHms(System.currentTimeMillis() + 1000*60*time) , maps);
            return ResultUtil.success(orderRide.getId());
        } catch (Exception e) {
            e.printStackTrace();
        }
            return ResultUtil.error("异常");
        }
 
    /**
     * 司机创建行程
     * @param driverId
     * @param startTime
     * @param num
     * @param startName
     * @param endName
     * @return
     */
    @ResponseBody
    @PostMapping("/driverAddTravel")
    @ApiOperation(value = "司机创建行程", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "driverId", value = "司机id", dataType = "int"),
            @ApiImplicitParam(name = "startTime", value = "出行时间", dataType = "string"),
            @ApiImplicitParam(name = "num", value = "出行人数", dataType = "int"),
            @ApiImplicitParam(name = "startName", value = "起点名称", dataType = "string"),
            @ApiImplicitParam(name = "startLat", value = "起点纬度", dataType = "double"),
            @ApiImplicitParam(name = "startLon", value = "起点经度", dataType = "double"),
            @ApiImplicitParam(name = "endName", value = "终点名称", dataType = "string"),
            @ApiImplicitParam(name = "endLat", value = "终点纬度", dataType = "double"),
            @ApiImplicitParam(name = "endLon", value = "终点经度", dataType = "double"),
    })
    public Object driverAddTravel(Integer driverId,String startTime,Integer num,String startName,String endName,Double startLat,Double startLon,Double endLat,Double endLon){
        try {
            if(ToolUtil.isEmpty(driverId)){
                return ResultUtil.paranErr("driverId不能为空");
            }
            if(ToolUtil.isEmpty(startTime)){
                return ResultUtil.paranErr("startTime不能为空");
            }
            if(ToolUtil.isEmpty(num)){
                return ResultUtil.paranErr("num不能为空");
            }
            if(ToolUtil.isEmpty(startName)){
                return ResultUtil.paranErr("startName不能为空");
            }
            if(ToolUtil.isEmpty(endName)){
                return ResultUtil.paranErr("endName不能为空");
            }
            /*用户的资料过期了不可以发布行程*/
            DriverRide driverRide=driverRideService.selectById(driverId);
            if(driverRide!=null){
                if(driverRide!=null){
                    if(DateUtil.getDate(driverRide.getComInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                            || DateUtil.getDate(driverRide.getBusinessInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                            || DateUtil.getDate(driverRide.getDutyInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                            || DateUtil.getDate(driverRide.getAnnualInspectionTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                            ){
                        return ResultUtil.error("您的证件已过期,请重新上传资料");
                    }
                }
                /*1一个司机可以创建多个行程*/
                OrderTravel orderTravel=new OrderTravel();
                orderTravel.setOrderNum(OrdersUtil.getOrderNoForPrefix("travel"));
                orderTravel.setAddTime(new Date());
                orderTravel.setDriverId(driverId);
                orderTravel.setStartTime(DateUtil.getDate(startTime,"yyyy-MM-dd HH:mm"));
                orderTravel.setNum(num);//乘车人数
                orderTravel.setStartName(startName);//出发地
                orderTravel.setEndName(endName);//目的地
                orderTravel.setState(2);//待出行
                orderTravel.setStartLon(startLon);
                orderTravel.setStartLat(startLat);
                orderTravel.setEndLon(endLon);
                orderTravel.setEndLat(endLat);
 
                orderTravelService.insert(orderTravel);
                return ApiJson.returnOK(orderTravel.getId());
            }
            return ApiJson.returnOK("");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
 
 
    /**
     * 用户申请顺风车司机/修改司机资料
     * @param userId
     * @param carType
     * @param carNum
     * @param inviteCodeRide
     * @param license
     * @param licenseImg
     * @param comInsuranceTime
     * @param comInsuranceImg
     * @param businessInsuranceTime
     * @param businessInsuranceImg
     * @param dutyInsuranceTime
     * @param dutyInsuranceImg
     * @param annualInspectionTime
     * @param annualInspectionImg
     * @return
     */
    @ResponseBody
    @PostMapping("/driverAudit")
    @ApiOperation(value = "用户申请顺风车司机/修改司机资料", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"),
            @ApiImplicitParam(name = "brandId", value = "品牌id", dataType = "int"),
            @ApiImplicitParam(name = "driverId", value = "司机id", dataType = "int"),
            @ApiImplicitParam(name = "carType", value = "车辆品牌", dataType = "string"),
            @ApiImplicitParam(name = "carNum", value = "车牌", dataType = "string"),
            @ApiImplicitParam(name = "inviteCodeRide", value = "别人的邀请码", dataType = "string"),
            @ApiImplicitParam(name = "license", value = "驾驶证号", dataType = "string"),
            @ApiImplicitParam(name = "licenseImg", value = "驾驶证图片", dataType = "string"),
            @ApiImplicitParam(name = "comInsuranceTime", value = "交强险到期时间", dataType = "string"),
            @ApiImplicitParam(name = "comInsuranceImg", value = "交强险照片", dataType = "string"),
            @ApiImplicitParam(name = "businessInsuranceTime", value = "商业险到期时间", dataType = "string"),
            @ApiImplicitParam(name = "businessInsuranceImg", value = "商业险图片", dataType = "string"),
            @ApiImplicitParam(name = "dutyInsuranceTime", value = "驾乘人员责任险到期时间", dataType = "string"),
            @ApiImplicitParam(name = "dutyInsuranceImg", value = "驾乘人员责任险照片", dataType = "string"),
            @ApiImplicitParam(name = "annualInspectionTime", value = "年检到期时间", dataType = "string"),
            @ApiImplicitParam(name = "annualInspectionImg", value = "年检图片", dataType = "string"),
    })
    public Object driverAudit(Integer userId,Integer brandId,Integer driverId,String carType,String carNum,String inviteCodeRide,String license,String licenseImg,String comInsuranceTime,String comInsuranceImg,
                              String businessInsuranceTime,String businessInsuranceImg,String dutyInsuranceTime,String dutyInsuranceImg,String annualInspectionTime,String annualInspectionImg){
        try {
            if(ToolUtil.isEmpty(userId)){
                return ResultUtil.paranErr("userId不能为空");
            }
            if(ToolUtil.isEmpty(carType)){
                return ResultUtil.paranErr("carType不能为空");
            }
            if(ToolUtil.isEmpty(brandId)){
                return ResultUtil.paranErr("brandId不能为空");
            }
            if(ToolUtil.isEmpty(carNum)){
                return ResultUtil.paranErr("carNum不能为空");
            }
            if(ToolUtil.isEmpty(license)){
                return ResultUtil.paranErr("license不能为空");
            }
            if(ToolUtil.isEmpty(licenseImg)){
                return ResultUtil.paranErr("licenseImg不能为空");
            }
            if(ToolUtil.isEmpty(comInsuranceTime)){
                return ResultUtil.paranErr("comInsuranceTime不能为空");
            }
            if(ToolUtil.isEmpty(comInsuranceImg)){
                return ResultUtil.paranErr("comInsuranceImg不能为空");
            }
            if(ToolUtil.isEmpty(businessInsuranceTime)){
                return ResultUtil.paranErr("businessInsuranceTime不能为空");
            }
            if(ToolUtil.isEmpty(businessInsuranceImg)){
                return ResultUtil.paranErr("businessInsuranceImg不能为空");
            }
            if(ToolUtil.isEmpty(dutyInsuranceTime)){
                return ResultUtil.paranErr("dutyInsuranceTime不能为空");
            }
            if(ToolUtil.isEmpty(dutyInsuranceImg)){
                return ResultUtil.paranErr("dutyInsuranceImg不能为空");
            }
            if(ToolUtil.isEmpty(annualInspectionTime)){
                return ResultUtil.paranErr("annualInspectionTime不能为空");
            }
            if(ToolUtil.isEmpty(annualInspectionImg)){
                return ResultUtil.paranErr("annualInspectionImg不能为空");
            }
            DriverRide driverRide=new DriverRide();
            driverRide.setBrandId(brandId);
            driverRide.setUserId(userId);
            driverRide.setByInviteCode(inviteCodeRide);
            driverRide.setCarType(carType);
            driverRide.setCarNum(carNum);
            driverRide.setLicense(license);
            driverRide.setLicenseImg(licenseImg);
            if(ToolUtil.isNotEmpty(driverId)){
                driverRide.setId(driverId);
                driverRide.setState(1);//待审核状态
                if(ToolUtil.isNotEmpty(comInsuranceTime)){
                    driverRide.setComInsuranceTime(comInsuranceTime);
                }
                if(ToolUtil.isNotEmpty(comInsuranceImg)) {
                    driverRide.setComInsuranceImg(comInsuranceImg);
                }
                if(ToolUtil.isNotEmpty(businessInsuranceTime)) {
                    driverRide.setBusinessInsuranceTime(businessInsuranceTime);
                }
                if(ToolUtil.isNotEmpty(businessInsuranceImg)) {
                    driverRide.setBusinessInsuranceImg(businessInsuranceImg);
                }
                if(ToolUtil.isNotEmpty(dutyInsuranceTime)) {
                    driverRide.setDutyInsuranceTime(dutyInsuranceTime);
                }
                if(ToolUtil.isNotEmpty(dutyInsuranceImg)) {
                    driverRide.setDutyInsuranceImg(dutyInsuranceImg);
                }
                if(ToolUtil.isNotEmpty(annualInspectionTime)) {
                    driverRide.setAnnualInspectionTime(annualInspectionTime);
                }
                if(ToolUtil.isNotEmpty(annualInspectionImg)) {
                    driverRide.setAnnualInspectionImg(annualInspectionImg);
                }
                driverRideService.updateById(driverRide);
            }else {
                driverRide.setAddTime(new Date());
                /*获取司机品牌id*/
                /*Brand b=brandService.selectById(driverRide.getBrandId());
                if(b!=null){
                    driverRide.setCarType(b.getName());
                }*/
                driverRide.setComInsuranceTime(comInsuranceTime);
                driverRide.setComInsuranceImg(comInsuranceImg);
                driverRide.setBusinessInsuranceTime(businessInsuranceTime);
                driverRide.setBusinessInsuranceImg(businessInsuranceImg);
                driverRide.setDutyInsuranceTime(dutyInsuranceTime);
                driverRide.setDutyInsuranceImg(dutyInsuranceImg);
                driverRide.setAnnualInspectionTime(annualInspectionTime);
                driverRide.setAnnualInspectionImg(annualInspectionImg);
                driverRideService.insert(driverRide);
                /*绑定司机和用户的关系*/
                UserInfo userInfo_=new UserInfo();
                userInfo_.setId(userId);
                userInfo_.setDriverId(driverRide.getId());
                userInfoService.updateById(userInfo_);
            }
            return ApiJson.returnOK(driverRide);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
 
    /**
     * 获取司机资料
     * @param driverId
     * @return
     */
    @ResponseBody
    @GetMapping("/driverInfo")
    @ApiOperation(value = "获取司机资料", httpMethod = "GET")
    public Object driverInfo(Integer driverId){
        try {
            if(ToolUtil.isEmpty(driverId)){
                return ResultUtil.paranErr("driverId不能为空");
            }
            DriverRide driverRide=driverRideService.selectById(driverId);
            /*获取司机品牌id*/
            TCarBrand tCarBrand = carBrandService.selectById(driverRide.getBrandId());
            if(tCarBrand!=null){
                driverRide.setCarType(tCarBrand.getName());
            }
            return ApiJson.returnOK(driverRide);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
 
    /**
     * 司机用户获取取消的服务费(同时计算退款金额)
     * @param orderId 订单id
     * @param type 1用户,2司机
     * @return
     */
    @ResponseBody
    @GetMapping("/cancelServiceMoney")
    @ApiOperation(value = "司机用户获取取消的服务费(同时计算退款金额)", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"),
            @ApiImplicitParam(name = "type", value = "1用户,2司机", dataType = "int")
    })
    public Object cancelServiceMoney(Integer orderId,Integer type){
        try {
            if(ToolUtil.isEmpty(orderId)){
                return ResultUtil.paranErr("orderId不能为空");
            }
            if(ToolUtil.isEmpty(type)){
                return ResultUtil.paranErr("type不能为空");
            }
            Double serviceMoney=0d;
            if(type==1){//用户
                OrderRide orderRide=orderRideService.selectById(orderId);
                if(orderRide.getState()>=3){//待出行状态取消才会有服务费
                    EntityWrapper<ParamRide> rideEntityWrapper=new EntityWrapper<>();
                    rideEntityWrapper.eq("type",3);//用户
                    ParamRide paramRide=paramRideService.selectOne(rideEntityWrapper);//退单比例
                    serviceMoney=Double.valueOf(paramRide.getContext())*orderRide.getPlatformMoney();//退单金额:退单比例*平台抽成
                    orderRide.setServiceMoney(serviceMoney);//设置取消服务费
                    /*计算退款金额*/
                    if(orderRide.getState()==2){//已支付: 需要退款
                        orderRide.setTuiMoney(orderRide.getMoney());
                    }else if(orderRide.getState()>=3){//待出行,需要计算 然后 需要退款
                        if(serviceMoney>orderRide.getMoney()){//退款金额大于了取消服务费,就直接全部扣完
                            orderRide.setTuiMoney(0d);
                        }else {
                            orderRide.setTuiMoney(orderRide.getMoney()-serviceMoney);
                        }
                    }
                }else{
                    orderRide.setTuiMoney(orderRide.getMoney());
                }
                orderRideService.updateById(orderRide);//更新退款金额和取消服务器
            }else if(type==2){//司机
                OrderTravel orderTravel=orderTravelService.selectById(orderId);
                if(orderTravel.getState()>=3){//待出行的状态取消才有服务费
                    EntityWrapper<ParamRide> rideEntityWrapper=new EntityWrapper<>();
                    rideEntityWrapper.eq("type",4);//司机
                    ParamRide paramRide=paramRideService.selectOne(rideEntityWrapper);//司机退单比例
                    /*查询订单(现在订单和行程时一对一关系)*/
                    OrderRide orderRide=orderRideService.selectOne(new EntityWrapper<OrderRide>().eq("travelId",orderId));
                    if(orderRide!=null){
                        serviceMoney=Double.valueOf(paramRide.getContext())*orderRide.getPlatformMoney();
                        orderTravel.setServiceMoney(serviceMoney);//司机退单比例*订单提成比例
                        orderRide.setTuiMoney(orderRide.getMoney());
                        orderRideService.updateById(orderRide);
                    }
                }
                orderTravelService.updateById(orderTravel);//更新取消服务费
            }
            return ResultUtil.success(serviceMoney);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
 
    /**
     * 用户订单取消 待出行之前才可以取消
     * @param orderId
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/userCancel")
    @ApiOperation(value = "用户订单取消 待出行之前才可以取消", httpMethod = "POST")
    public Object userCancel(Integer orderId){
        try {
            if(ToolUtil.isEmpty(orderId)){
                return ResultUtil.paranErr("orderId不能为空");
            }
            /*查看这个订单是否在进行中*/
            OrderRide orderRide=orderRideService.selectById(orderId);
            if(orderRide!=null){
                /*查询该订单是否已经取消*/
                if(orderRide.getState()==6){
                    return ResultUtil.error("该订单已取消");
                }
                //用户取消给司机推送
                if(orderRide.getDriverId()!=null) {
                    UserInfo userInfo1=userInfoService.selectOne(new EntityWrapper<UserInfo>().eq("driverId",orderRide.getDriverId()));
                    pushUtil.pushOrderState(1, userInfo1.getDriverId(), orderRide.getId(), 8, 6, null);
                }
                //用户取消退款
                userCancelTuik(orderRide);
            }
            //取消司机行程
            if(orderRide.getTravelId()!=null){
                OrderTravel orderTravel=orderTravelService.selectById(orderRide.getTravelId());
                if(orderTravel.getState()!=6){
                    orderTravel.setState(6);
                    orderTravelService.updateById(orderTravel);
                }
            }
            return ResultUtil.success("");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
    //用户取消退款
    public void userCancelTuik(OrderRide orderRide){
        if(orderRide.getState()==2){//用户已经支付了订单但司机没有接单
            orderRide.setTuiMoney(orderRide.getMoney());
        }
        if(orderRide.getTuiMoney()>0){
            Financial financial= financialService.selectOne(new EntityWrapper<Financial>().eq("orderNum",orderRide.getOrderNum()));
            String finNum=OrdersUtil.getOrderNoForPrefix("fin");
            //todo 退款金额大于0需要退款
            if(orderRide.getPayType()==1){//余额
                UserInfo userInfo=userInfoService.selectById(orderRide.getUserId());
                userInfo.setBalance(userInfo.getBalance()+orderRide.getTuiMoney());
                userInfoService.updateById(userInfo);
            }else if(orderRide.getPayType()==2){
                //微信
                Integer money = new Double(orderRide.getMoney() * 100).intValue();
                Integer tMoney_ = new Double(orderRide.getTuiMoney()* 100).intValue();
                PayUtil.refundForWxpay(1, financial.getLsType(), orderRide.getOrderNum(), finNum, money,tMoney_ , "2");
            }else if(orderRide.getPayType()==3){
            
            }
            /*财务明细*/
            Financial f=new Financial();
            f.setAddTime(new Date());
            f.setType(2);//类型 1=收入 2=支出
            f.setMoney(orderRide.getTuiMoney());
            f.setPwType(9);//9=顺风车取消服务费
            f.setOrderNum(orderRide.getOrderNum());
            f.setLsType(finNum);
            f.setUserId(orderRide.getUserId());
            f.setOrderType(4);
            f.setLx(1);
            financialService.insert(f);
        }
        /*添加系统消息*/
        try {
            systemNoticeService.addSystemNotice(1, "您从"+orderRide.getStartName()+"到"+orderRide.getEndName()+"的顺风车订单已取消", orderRide.getUserId(), 1);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        orderRide.setState(6);//取消状态
        orderRideService.updateById(orderRide);
    }
    /**
     * 司机行程取消
     * @param orderId
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/driverCancel")
    @ApiOperation(value = "司机行程取消", httpMethod = "POST")
    public Object driverCancel(Integer orderId){
        try {
            if(ToolUtil.isEmpty(orderId)){
                return ResultUtil.paranErr("orderId不能为空");
            }
            OrderTravel orderTravel=orderTravelService.selectById(orderId);
            if(orderTravel!=null){
                if(orderTravel.getState()==6){
                    return ResultUtil.error("该订单已取消");
                }
                DriverRide driverRide=driverRideService.selectById(orderTravel.getDriverId());
                if(orderTravel.getServiceMoney()!=null && orderTravel.getServiceMoney()>0){
                    /*todo 更新司机余额*/
                    driverRide.setBalance(driverRide.getBalance()-orderTravel.getServiceMoney());
                    driverRideService.updateById(driverRide);
                    /* 更新司机用户余额(用户和司机用户一个账号余额)*/
                    UserInfo userInfo=userInfoService.selectOne(new EntityWrapper<UserInfo>().eq("driverId",orderTravel.getDriverId()));
                    if(userInfo!=null){
                        //用户余额可以为负数
                        userInfo.setBalance(userInfo.getBalance()-orderTravel.getServiceMoney());
                        userInfoService.updateById(userInfo);
                    }
                    /*财务明细*/
                    Financial f=new Financial();
                    f.setAddTime(new Date());
                    f.setType(1);//类型 1=收入 2=支出
                    f.setMoney(orderTravel.getServiceMoney());
                    f.setPwType(9);//9=顺风车取消服务费
                    f.setOrderNum(orderTravel.getOrderNum());
                    String finNum=OrdersUtil.getOrderNoForPrefix("fin");
                    f.setLsType(finNum);
                    f.setUserId(driverRide.getUserId());
                    f.setOrderType(4);
                    f.setLx(1);
                    financialService.insert(f);
                    //司机取消给用户推送
                }
                /*添加系统消息*/
                try {
                    systemNoticeService.addSystemNotice(1, "您从"+orderTravel.getStartName()+"到"+orderTravel.getEndName()+"的顺风车行程已取消", driverRide.getUserId(), 1);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                orderTravel.setState(6);//取消状态
                orderTravelService.updateById(orderTravel);
                //todo 推送
                /*司机接单给用户发送消息*/
                OrderRide orderRide=orderRideService.selectOne(new EntityWrapper<OrderRide>().eq("travelId",orderId));
                if(orderRide!=null) {
                    pushUtil.pushOrderState(1, orderRide.getUserId(), orderRide.getId(), 8, 6, null);
                }
                //取消乘客订单
                if(orderRide!=null && orderRide.getState()!=6){
                    orderRide.setTuiMoney(orderRide.getMoney());
                    orderRideService.updateById(orderRide);
                    userCancelTuik(orderRide);
                }
            }
 
            return ResultUtil.success("");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
 
    /**
     * 司机确认同行,接到乘客,送达乘客
     * @param driverOrderId
     * @param type 1确认同行 2接到乘客,3送达乘客
     * @return
     */
    @ResponseBody
    @PostMapping("/driverOperation")
    @ApiOperation(value = "司机确认同行,接到乘客,送达乘客", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userOrderId", value = "用户订单id", dataType = "int"),
            @ApiImplicitParam(name = "type", value = "1确认同行 2接到乘客,3送达乘客", dataType = "int"),
            @ApiImplicitParam(name = "driverOrderId", value = "司机订单id", dataType = "int")
    })
    @Transactional
    public Object driverOperation(Integer userOrderId,Integer type,Integer driverOrderId){
        try {
            if(ToolUtil.isEmpty(driverOrderId)){
                return ResultUtil.paranErr("driverOrderId不能为空");
            }
            if(ToolUtil.isEmpty(type)){
                return ResultUtil.paranErr("type不能为空");
            }
            OrderTravel orderTravel=orderTravelService.selectById(driverOrderId);//司机行程
            /*用户的资料过期了不可以发布行程*/
            DriverRide driverRide=driverRideService.selectById(orderTravel.getDriverId());
            if(driverRide!=null){
                if(DateUtil.getDate(driverRide.getComInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                        || DateUtil.getDate(driverRide.getBusinessInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                        || DateUtil.getDate(driverRide.getDutyInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                        || DateUtil.getDate(driverRide.getAnnualInspectionTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                        ){
                    return ResultUtil.error("您的证件已过期,请重新上传资料");
                }
            }
            OrderRide orderRide=orderRideService.selectById(userOrderId);
            if(orderRide!=null && orderRide.getState()==6){
                return  ResultUtil.error("用户已取消该行程");
            }
            if(orderTravel!=null){
                if(type==1){//1确认同行 一个行程只能匹配一个订单
                    if(orderTravel.getState()==3){
                        return ResultUtil.error("该行程已经绑定了用户订单");
                    }
                    orderTravel.setState(3);
                    //绑定司机行程、设置用户订单状态
                    orderRide.setTravelId(driverOrderId);
                    orderRide.setDriverId(orderTravel.getDriverId());
                    orderRide.setState(3);
                }else if(type==2){//2接到乘客
                    orderTravel.setState(4);
                    orderRide.setState(4);
                }else if(type==3){//3送达乘客
                    orderTravel.setState(5);
                    orderRide.setState(5);
                    /*修改司机的总接单数*/
                    driverRide.setTotalOrders(driverRide.getTotalOrders()+1);
                    driverRideService.updateById(driverRide);
                    /*修改用户接单数和司机提成*/
                    UserInfo userInfo=userInfoService.selectById(driverRide.getUserId());
                    userInfo.setBalance(userInfo.getBalance()+(orderRide.getMoney()-orderRide.getPlatformMoney()));
                    userInfoService.updateById(userInfo);
                    Financial f=new Financial();
                    f.setAddTime(new Date());
                    f.setType(2);
                    f.setPayType("1");//余额
                    f.setMoney(orderRide.getMoney()-orderRide.getPlatformMoney());//司机提成
                    f.setPwType(11);//顺风车司机提成
                    f.setLsType(OrdersUtil.getOrderNoForPrefix("finan"));
                    f.setUserId(userInfo.getId());
                    f.setOrderType(4);
                    f.setLx(1);
                    financialService.insert(f);
                    /*如果司机有推荐人就需要算用户的提成*/
                    if(ToolUtil.isNotEmpty(driverRide.getByInviteCode())){
                        /*计算推广用户的提成*/
                        UserInfo userInfo1=userInfoService.selectOne(new EntityWrapper<UserInfo>().eq("inviteCodeRide",driverRide.getByInviteCode()));
                        Double discount=100d;
                        Double money=orderRide.getMoney()*discount/100;//提成金额
                        userInfoService.updateById(userInfo1);
                        
                        f.setAddTime(new Date());
                        f.setType(2);
                        f.setPayType("1");//余额
                        f.setMoney(money);//邀请金额
                        f.setPwType(10);//分享收益
                        f.setLsType(OrdersUtil.getOrderNoForPrefix("finan"));
                        f.setUserId(userInfo1.getId());
                        f.setOrderType(4);
                        f.setLx(1);
                        financialService.insert(f);
                    }
                }
            }
            orderRideService.updateById(orderRide);
            orderTravelService.updateById(orderTravel);
 
            if(type==1){//确认同行
                String message="您发布的"+DateUtil.getDateToString(orderRide.getStartTime(),"MM月dd日")+"的行程有司机接单";
                /*添加系统消息*/
                try {
                    systemNoticeService.addSystemNotice(1, message, driverRide.getUserId(), 1);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            pushUtil.pushOrderState(1, orderRide.getUserId(), orderRide.getId(), 8, orderRide.getState(), null);
            return ResultUtil.success("");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
    /**
     * 用户评价
     * @param orderId
     * @param driverId
     * @param userId
     * @param score
     * @param content
     * @return
     */
    @ResponseBody
    @PostMapping("/evaluate")
    @ApiOperation(value = "用户评价", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"),
            @ApiImplicitParam(name = "driverId", value = "司机id", dataType = "int"),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"),
            @ApiImplicitParam(name = "score", value = "评分", dataType = "int"),
            @ApiImplicitParam(name = "content", value = "评价内容", dataType = "string")
    })
    public Object evaluate(Integer orderId,Integer driverId,Integer userId,Integer score,String  content){
        try {
            if(userId == null || userId == 0){
                return ResultUtil.paranErr("userId不能为空");
            }
            if(driverId == null || driverId == 0){
                return ResultUtil.paranErr("driverId不能为空");
            }
            if(orderId == null || orderId == 0){
                return ResultUtil.paranErr("orderId不能为空");
            }
            if(score == null || score == 0){
                return ResultUtil.paranErr("score不能为空");
            }
            Evaluate evaluate=new Evaluate();
            evaluate.setAddTime(new Date());
            evaluate.setType(8);
            evaluate.setOrderId(orderId);
            evaluate.setScore(score);
            evaluate.setUserId(userId);
            if(ToolUtil.isNotEmpty(content)){
                /*判断评价内容是否包含敏感词*/
                List<SensitiveWords> list = sensitiveWordsMapper.selectList(null);
                Set<String> sensitiveWordSet = new HashSet<>();
                for(SensitiveWords gs:list){
                    sensitiveWordSet.add(gs.getContent());
                }
                SensitiveWordUtil.init(sensitiveWordSet);
                boolean result = SensitiveWordUtil.contains(content);
                if(result){
                    return ResultUtil.error("评价内容包含敏感词");
                }
            }
            evaluate.setContent(content);
            evaluate.setDriverId(driverId);
            /*查询用户手机号*/
            UserInfo userInfo=userInfoService.selectById(userId);
            if(userInfo!=null){
                evaluate.setUserPhone(userInfo.getPhone());
            }
            /*查询司机电话*/
            DriverRide driverRide=driverRideService.selectById(driverId);
            if(driverRide!=null){
                /*计算司机的评分*/
                driverRide.setEvaluateNum(driverRide.getEvaluateNum()+1);
                driverRide.setEvaluateScore(driverRide.getEvaluateScore()+score);
                driverRideService.updateById(driverRide);
            }
            /*标记订单已评价*/
            OrderRide orderTaxi=new OrderRide();
            orderTaxi.setId(orderId);
            orderTaxi.setIsEvaluate(2);
            orderTaxi.setEvaluateScoreUser(score);
            orderTaxi.setContent(content);
            orderRideService.updateById(orderTaxi);
            evaluateService.insert(evaluate);
            /*需要反订单数据*/
            return ResultUtil.success(orderId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("");
    }
 
    /**
     * 投诉
     * @param  type 1:用户投诉司机,2司机投诉用户
     * @param driverId
     * @param userId
     * @param content
     * @param reMark
     * @return
     */
    @ResponseBody
    @PostMapping("/complaints")
    @ApiOperation(value = "投诉", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "driverId", value = "司机id", dataType = "int"),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"),
            @ApiImplicitParam(name = "content", value = "投诉内容", dataType = "string"),
            @ApiImplicitParam(name = "reMark", value = "备注", dataType = "string"),
            @ApiImplicitParam(name = "type", value = "1=顺风车用户,2=顺风车司机", dataType = "int"),
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int")
    })
    public Object complaints(Integer driverId,Integer userId,String  content,String reMark,Integer type,Integer orderId) {
        try {
            if (userId == null || userId == 0) {
                return ResultUtil.paranErr("userId不能为空");
            }
            if (driverId == null || driverId == 0) {
                return ResultUtil.paranErr("driverId不能为空");
            }
            if (orderId == null || orderId == 0) {
                return ResultUtil.paranErr("orderId不能为空");
            }
            Complaints complaints=new Complaints();
            complaints.setAddTime(new Date());
            complaints.setUserId(userId);
            complaints.setDriverId(driverId);
            /*判断投诉内容是否包含敏感词*/
            List<SensitiveWords> list = sensitiveWordsMapper.selectList(null);
            Set<String> sensitiveWordSet = new HashSet<>();
            for(SensitiveWords gs:list){
                sensitiveWordSet.add(gs.getContent());
            }
            SensitiveWordUtil.init(sensitiveWordSet);
            boolean result = SensitiveWordUtil.contains(content);
            if(result){
                return ResultUtil.error("投诉内容包含敏感词");
            }
            complaints.setContent(content);
            complaints.setReMark(reMark);
            if(type==1){
                complaints.setType(4);//顺风车用户
            }else if(type==2){
                complaints.setType(3);//顺风车司机
            }
            /*查询用户手机号*/
            UserInfo userInfo=userInfoService.selectById(userId);
            if(userInfo!=null){
                complaints.setPhone(userInfo.getPhone());
            }
            complaints.setState(1);
            complaintsService.insert(complaints);
            /*标记订单已投诉*/
            if(type==2){//司机投诉
                OrderRide orderTaxi=new OrderRide();
                orderTaxi.setId(orderId);
                orderTaxi.setIsComplaint(2);
                orderRideService.updateById(orderTaxi);
            }else{//用户投诉
                OrderTravel orderTravel=new OrderTravel();
                orderTravel.setId(orderId);
                orderTravel.setIsComplaint(2);
                orderTravelService.updateById(orderTravel);
            }
            return ResultUtil.success("投诉成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("");
    }
    /**
     *  用户邀请司机接单(需要发送消息)
     * @param orderId 司机订单
     * @param  userId
     * @return
     */
    @ResponseBody
    @PostMapping("/userInvite")
    @ApiOperation(value = "用户邀请司机接单(需要发送消息)", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "int"),
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int")
    })
    public Object myOrders(Integer orderId,Integer userId){
        try {
            if(ToolUtil.isEmpty(orderId)){
                return ResultUtil.paranErr("orderId不能为空");
            }
            if(ToolUtil.isEmpty(userId)){
                return ResultUtil.paranErr("userId不能为空");
            }
            OrderTravel orderTravel=orderTravelService.selectById(orderId);
            UserInfo userInfo_=userInfoService.selectOne(new EntityWrapper<UserInfo>().eq("driverId",orderTravel.getDriverId()));//司机用户
            OrderRide orderRide=orderRideService.selectOne(new EntityWrapper<OrderRide>().eq("userId",userId)
                    .eq("state",2));
            if(orderRide!=null){
                String message="您发布的"+DateUtil.getDateToString(orderTravel.getStartTime(),"MM月dd日")+"的行程有乘客邀请您同行";
                /*添加系统消息*/
                try {
                    systemNoticeService.addSystemNotice(1, message, userInfo_.getId(), 1);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            return ResultUtil.success("邀请成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
    /**
     * 用户订单匹配列表页面,用户订单去匹配司机的行程
     * @param  type  搜索条件:1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近
     * @param orderId
     * @param  lon 司机当前经度
     * @param  lat 司机当前纬度
     * @return
     */
    @ResponseBody
    @PostMapping("/userMatchingOrderList")
    @ApiOperation(value = "用户订单匹配列表页面,用户订单去匹配司机的行程", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"),
            @ApiImplicitParam(name = "type", value = "1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近", dataType = "int")
    })
    public Object userMatchingOrderList(Integer orderId,Integer current,Integer size,Integer type){
        try {
            if(ToolUtil.isEmpty(orderId)){
                return ResultUtil.paranErr("orderId不能为空");
            }
            if(ToolUtil.isEmpty(type)){
                return ResultUtil.paranErr("type不能为空");
            }
            OrderRide orderRide=orderRideService.selectById(orderId);
            current=current==null?1:current;
            size=size==null?10:size;
            size=current*size;
            current=(current-1)*size;
            OrderRideVo orderRideVo=new OrderRideVo();
            orderRideVo.setCurrent(current);
            orderRideVo.setSize(size);
            orderRideVo.setLon(orderRide.getStartLon());
            orderRideVo.setLat(orderRide.getStartLat());
            orderRideVo.setNum(orderRide.getNum());
            orderRideVo.setType(type+1);//搜索条件:1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近
            List<OrderRideVo> orderRides=orderTravelService.getOrderTravel(orderRideVo);
            return ResultUtil.success(orderRides);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
 
    /**
     * 司机订单匹配列表页面(司机的订单去匹配乘客订单)
     * @param orderId
     * @param current
     * @param size
     * @param type 搜索条件:1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近,4价格最低
     * @param lon
     * @param lat
     * @return
     */
    @ResponseBody
    @PostMapping("/driverMatchingOrderList")
    @ApiOperation(value = "司机订单匹配列表页面(司机的订单去匹配乘客订单)", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"),
            @ApiImplicitParam(name = "type", value = "1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近,4价格最低", dataType = "int")
    })
    public Object driverMatchingOrderList(Integer orderId,Integer current,Integer size,Integer type){
        try {
            try {
                if(ToolUtil.isEmpty(orderId)){
                    return ResultUtil.paranErr("orderId不能为空");
                }
                if(ToolUtil.isEmpty(type)){
                    return ResultUtil.paranErr("type不能为空");
                }
                OrderTravel orderTravel=orderTravelService.selectById(orderId);
                current=current==null?1:current;
                size=size==null?10:size;
                size=current*size;
                current=(current-1)*size;
                OrderRideVo orderRideVo=new OrderRideVo();
                orderRideVo.setCurrent(current);
                orderRideVo.setSize(size);
                orderRideVo.setNum(orderTravel.getNum());
                orderRideVo.setLon(orderTravel.getStartLon());
                orderRideVo.setLat(orderTravel.getStartLat());
                orderRideVo.setType(type+1);//搜索条件:1默认排序(根据线路、时间,人数综合匹配排序721),2时间最早,3距离最近,4价格最低
                List<OrderRideVo> orderRides=orderRideService.getOrderRide(orderRideVo);
                return ResultUtil.success(orderRides);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
 
    /**
     * 订单详情
     * @type 1用户订单,2司机端订单
     * @param orderId
     * @return
     */
    @ResponseBody
    @GetMapping("/orderInfo")
    @ApiOperation(value = "订单详情", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int"),
            @ApiImplicitParam(name = "type", value = "1=用户订单,2=司机订单", dataType = "int"),
            @ApiImplicitParam(name = "lon", value = "经度", dataType = "double"),
            @ApiImplicitParam(name = "lat", value = "纬度", dataType = "double"),
    })
    public Object orderInfo(Integer orderId,Integer type,Double lon,Double lat) {
        try {
            if(ToolUtil.isEmpty(orderId)){
                return ResultUtil.paranErr("orderId不能为空");
            }
            if(ToolUtil.isEmpty(type)){
                return ResultUtil.paranErr("type不能为空");
            }
            //取司机的经纬度
            OrderRideInfoVo orderRideInfoVo=new OrderRideInfoVo();
            orderRideInfoVo.setLon(lon);
            orderRideInfoVo.setLat(lat);
            if(type==1){//用户端订单详情 用户端看到的就是自己的订单信息
                orderRideInfoVo.setUserOrderId(orderId);
                orderRideInfoVo=orderRideService.getOrderInfo(orderRideInfoVo);
            }else if(type==2){//司机端订单详情 司机端看到的就是用户端的订单信息
                orderRideInfoVo.setDriverOrderId(orderId);
                orderRideInfoVo=orderTravelService.getOrderInfo(orderRideInfoVo);
            }
            /*获取顺风车订单支付倒计时*/
            Integer time =10;
            orderRideInfoVo.setDjs(time);
            return ResultUtil.success(orderRideInfoVo);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return ResultUtil.error("异常");
        }
 
    /**
     * 验证输入的邀请码是否正确
     * @param  type 1:普通邀请码,2顺风车邀请码
     * @param inviteCode
     * @return
     */
    @ResponseBody
    @PostMapping("/checkInviteCode")
    @ApiOperation(value = "验证输入的邀请码是否正确", httpMethod = "POST")
    public Object orderInfo(String inviteCode,Integer type) {
        try {
            if(ToolUtil.isEmpty(inviteCode)){
                return ResultUtil.paranErr("inviteCode不能为空");
            }
            if(ToolUtil.isEmpty(type)){
                return ResultUtil.paranErr("type不能为空");
            }
            Integer count=0;
            if(type==1){
                count=userInfoService.selectCount(new EntityWrapper<UserInfo>().eq("inviteCode",inviteCode));
            }else {
                count=userInfoService.selectCount(new EntityWrapper<UserInfo>().eq("inviteCodeRide",inviteCode));
            }
            return ResultUtil.success(count);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
 
    /**
     * 验证司机证件是否过期
     *
     * @param driverId
     * @return
     */
    @ResponseBody
    @PostMapping("/checkInsuranceTime")
    @ApiOperation(value = "验证司机证件是否过期", httpMethod = "POST")
    public Object orderInfo(Integer driverId) {
        try {
            if(ToolUtil.isEmpty(driverId)){
                return ResultUtil.paranErr("driverId不能为空");
            }
            DriverRide driverRide=driverRideService.selectById(driverId);
            Integer count=0;
            if(driverRide!=null){
                if(DateUtil.getDate(driverRide.getComInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                        || DateUtil.getDate(driverRide.getBusinessInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                        || DateUtil.getDate(driverRide.getDutyInsuranceTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                        || DateUtil.getDate(driverRide.getAnnualInspectionTime(), "yyyy-MM-dd").getTime()-new Date().getTime()<0
                        ){
                    count=1;
                }
            }
            return ResultUtil.success(count);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtil.error("异常");
    }
 
}