VehicleMapper.xml
58.6 KB
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.admin.modules.mapper.VehicleMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.admin.modules.entity.Vehicle">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="workorder_id" jdbcType="INTEGER" property="workOrderId"/>
<result column="owner_name" jdbcType="VARCHAR" property="ownerName"/>
<result column="vin" jdbcType="VARCHAR" property="vin"/>
<result column="owner_sex" jdbcType="VARCHAR" property="ownerSex"/>
<result column="owner_tel" jdbcType="VARCHAR" property="ownerTel"/>
<result column="brand_id" jdbcType="INTEGER" property="brandId"/>
<result column="brand_name" jdbcType="VARCHAR" property="brandName"/>
<result column="sub_brand_id" jdbcType="INTEGER" property="subBrandId"/>
<result column="sub_brand_name" jdbcType="VARCHAR" property="subBrandName"/>
<result column="series_id" jdbcType="INTEGER" property="seriesId"/>
<result column="series_name" jdbcType="VARCHAR" property="seriesName"/>
<result column="type_id" jdbcType="INTEGER" property="typeId"/>
<result column="type_name" jdbcType="VARCHAR" property="typeName"/>
<result column="model_id" jdbcType="INTEGER" property="modelId"/>
<result column="model_name" jdbcType="VARCHAR" property="modelName"/>
<result column="config_id" jdbcType="INTEGER" property="configId"/>
<result column="config_desc" jdbcType="VARCHAR" property="configDesc"/>
<result column="color" jdbcType="VARCHAR" property="color"/>
<result column="inner_color" jdbcType="VARCHAR" property="innerColor"/>
<result column="license_plate" jdbcType="VARCHAR" property="licensePlate"/>
<result column="vehicle_type" jdbcType="TINYINT" property="vehicleType"/>
<result column="engine" jdbcType="VARCHAR" property="engine"/>
<result column="displacement" jdbcType="VARCHAR" property="displacement"/>
<result column="mileage" jdbcType="VARCHAR" property="mileage"/>
<result column="buy_date" jdbcType="DATE" property="buyDate"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="serve_type" jdbcType="TINYINT" property="serveType"/>
<result column="validate_status" jdbcType="TINYINT" property="validateStatus"/>
<result column="vehicle_usages" jdbcType="TINYINT" property="vehicleUsages"/>
<result column="validate_info" jdbcType="VARCHAR" property="validateInfo"/>
<result column="settle_flag" jdbcType="TINYINT" property="settleFlag"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
<result column="registration_date" jdbcType="TIMESTAMP" property="registrationDate"/>
<result column="sale_manager" jdbcType="VARCHAR" property="saleManager"/>
<result column="sale_manager_phone" jdbcType="VARCHAR" property="saleManagerPhone"/>
<result column="buy_type" jdbcType="DATE" property="buyType"/>
</resultMap>
<resultMap id="TearDownAlarmMap" type="cn.com.glsx.admin.modules.model.export.TearDownModelExport">
<result column="area" jdbcType="VARCHAR" property="area"/>
<result column="province" jdbcType="VARCHAR" property="province"/>
<result column="city" jdbcType="VARCHAR" property="city"/>
<result column="username" jdbcType="VARCHAR" property="shopName"/>
<result column="account" jdbcType="VARCHAR" property="shopCode"/>
<result column="shop_level" jdbcType="INTEGER" property="shopLevel"/>
<result column="type_name" jdbcType="VARCHAR" property="typeName"/>
<result column="model_name" jdbcType="VARCHAR" property="modelName"/>
<result column="config_desc" jdbcType="INTEGER" property="configDesc"/>
<result column="vin" jdbcType="VARCHAR" property="vin"/>
<result column="sn" jdbcType="INTEGER" property="sn"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
</resultMap>
<resultMap id="VehicleInfoMap" type="cn.com.glsx.admin.modules.model.VehicleInfoPageDTO">
<result column="id" jdbcType="BIGINT" property="id"/>
<result column="workorder_id" jdbcType="INTEGER" property="workOrderId"/>
<result column="owner_name" jdbcType="VARCHAR" property="ownerName"/>
<result column="vin" jdbcType="VARCHAR" property="vin"/>
<result column="sn" jdbcType="VARCHAR" property="sn"/>
<result column="source" jdbcType="INTEGER" property="deviceType"/>
<result column="model_name" jdbcType="VARCHAR" property="modelName"/>
<result column="vehicle_type" jdbcType="INTEGER" property="vehicleType"/>
<result column="vehicle_usages" jdbcType="INTEGER" property="vehicleUsages"/>
<result column="created_date" jdbcType="TIMESTAMP" property="activateTime"/>
<result column="freqStatus" jdbcType="INTEGER" property="freqStatus"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, workorder_id, owner_name, vin, owner_sex, owner_tel, brand_id, brand_name, sub_brand_id,sub_brand_name,
series_id,series_name, type_id,type_name,model_id, model_name, config_id, config_desc, color, inner_color,
license_plate,vehicle_type, engine, displacement, mileage, buy_date, description, remark, serve_type, settle_flag,
vehicle_usages, validate_status, validate_info, buy_type, del_flag, created_date, created_by, updated_date,updated_by
</sql>
<sql id="search_sql_condition">
<if test="searchKey != null and searchKey != '' ">
and (
tu.account like concat('%',#{searchKey},'%')
or tu.username like concat('%',#{searchKey},'%')
or tv.vin like concat('%',#{searchKey},'%')
or tvd.sn like concat('%',#{searchKey},'%')
or tv.model_name like concat('%',#{searchKey},'%')
or tv.series_name like concat('%',#{searchKey},'%')
)
</if>
</sql>
<select id="linkSnsSearch" resultType="cn.com.glsx.admin.modules.model.VehicleLinkSnsDTO">
select tv.id,tvd.id vdId,tv.owner_name name, tv.vin, tv.owner_tel userTel, tvd.sn sns,tv.created_date
from t_vehicle tv
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
left join t_workorder tw on tw.id = tv.workorder_id
left join t_device td on tvd.sn = td.sn
where tv.del_flag = 0 and tvd.del_flag = 0
and tvd.bind_status = 1
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="term != null and term != ''">
<choose>
<when test="termType == 1">
and tvd.sn like concat('%',#{term},'%')
</when>
<when test="termType == 2">
and tv.vin like concat('%',#{term},'%')
</when>
<when test="termType == 3">
and tv.owner_name like concat('%',#{term},'%')
</when>
<when test="termType == 4">
and tw.partner_order_no like concat('%',#{term},'%')
</when>
</choose>
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
and DATE_FORMAT(tv.created_date,'%Y-%m-%d') between #{startTime} and #{endTime}
</if>
<if test="shopId != null">
and tv.created_by = #{shopId}
</if>
<if test="deviceSource != null">
and td.source = #{deviceSource}
</if>
<if test="trialType != null">
and tvd.trial_type = #{trialType}
</if>
order by tv.created_date desc,tv.id desc
</select>
<select id="selectVehicleLinkSnsByUserId" resultType="cn.com.glsx.admin.modules.model.VehicleLinkSnsDTO">
select tvd.id vdId,tv.owner_name name, tv.vin, tv.owner_tel userTel, tvd.sn sns
from t_vehicle tv
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
left join t_device td on tvd.sn = td.sn
where tv.del_flag = 0 and tvd.del_flag = 0
and tvd.bind_status = 1
and tv.created_by = #{userId}
<if test="trialType != null">
and tvd.trial_type = #{trialType}
</if>
order by tv.id,tvd.sn
</select>
<select id="searchTrialDrive" resultType="cn.com.glsx.admin.modules.model.TrialDriveVehiclePageDTO">
select tv.id tempId,
tw.partner_order_no bizOrderNo,
tvd.id vdId,
tv.vin,
case when tv.type_id is null then tv.model_name else concat(tv.sub_brand_name, '/', series_name) end seriesName,
case when tv.type_id is null then tv.config_desc else tv.type_name end typeName,
tv.license_plate licensePlate,
tv.created_by createdBy,
tu.username shopName,
tu.account shopCode,
ttds.shop_level shopLevel,
tvd.sn sns,
tvd.created_date installedTime
from t_vehicle tv
inner join t_trial_drive_vehicle ttdv on ttdv.vehicle_id = tv.id
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id and tvd.bind_status = 1 and tvd.del_flag = 0 and
tvd.trial_type = 1
left join t_user tu on tv.created_by = tu.id and tu.del_flag = 0
left join t_trial_drive_shop ttds on tu.id = ttds.created_by and ttds.del_flag = 0
left join t_workorder tw on tw.id = tv.workorder_id
where tv.del_flag = 0
and ttdv.del_flag = 0
and tvd.trial_type = 1
<include refid="search_sql_condition"/>
order by tv.created_date desc
</select>
<select id="exportDriveVehicle" resultType="cn.com.glsx.admin.modules.model.export.TrialDriveVehicleExport">
select tv.vin,
case when tv.type_id is null then tv.model_name else concat(tv.sub_brand_name, '/', series_name) end seriesName,
case when tv.type_id is null then tv.config_desc else tv.type_name end typeName,
tv.license_plate licensePlate,
tv.model_name modelName,
tv.color,
tv.inner_color innerColor,
tv.serve_type serveType,
tu.username shopName,
tu.account shopCode,
tvd.sn sns ,
tv.created_by as createdBy
from t_vehicle tv
inner join t_trial_drive_vehicle ttdv on ttdv.vehicle_id = tv.id
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id and tvd.bind_status = 1 and tvd.del_flag = 0 and
tvd.trial_type = 1
left join t_user tu on tv.created_by = tu.id and tu.del_flag = 0
left join t_trial_drive_shop ttds on tu.id = ttds.created_by and ttds.del_flag = 0
where tv.del_flag = 0
and ttdv.del_flag = 0
and tvd.trial_type = 1
<include refid="search_sql_condition"/>
order by tv.created_date desc
</select>
<select id="searchTearDownAlarmList" resultMap="TearDownAlarmMap">
SELECT distinct
ttds.area,
ttds.province,
ttds.city,
tu.username,
tu.account,
ttds.shop_level,
tv.model_name,
tv.config_desc,
tv.vin,
tvd.sn,
tv.created_by
FROM t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_electric_fence_sns tefs on tefs.sn = tvd.sn
left join t_trial_drive_shop ttds on ttds.fence_id = tefs.fence_id
left join t_user tu on tu.id = tv.created_by
where tv.del_flag = 0 and tvd.del_flag = 0 and tvd.bind_status = 1 and tu.del_flag = 0
and tvd.trial_type = 1
<if test="keywords != null and keywords !=''">
and (
tu.username like '%${keywords}%'
or tu.account like '%${keywords}%'
or tvd.sn like '%${keywords}%'
or tv.model_name like '%${keywords}%'
or tv.series_name like '%${keywords}%'
)
</if>
</select>
<select id="findVehicleInfoBySn" resultMap="BaseResultMap">
select
tv.*
from t_vehicle tv
inner join t_vehicle_device tvd on tvd.vehicle_id = tv.id
where tv.del_flag = 0 and tvd.bind_status = 1 and tvd.del_flag = 0
<if test="sn != null and sn != ''">
and tvd.sn = #{sn}
</if>
</select>
<select id="selectOrgVehicle" resultType="cn.com.glsx.admin.modules.model.OrgVehicleModel">
select tv.id,
tv.id vid,
tv.vin,
tv.owner_name ownerName,
group_concat(tvd.sn) sns,
tv.created_by creatorId
from t_vehicle tv
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
left join t_device td on td.sn = tvd.sn
where tv.del_flag = 0 and tvd.del_flag = 0
and tvd.bind_status = 1
and tv.created_by is not null
<if test="userIds != null and userIds.size() > 0">
and tv.created_by in
<foreach collection="userIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</if>
<if test="term != null and term != ''">
<choose>
<when test="termType == 1">
and tvd.sn like concat('%',#{term},'%')
</when>
<when test="termType == 2">
and tv.vin like concat('%',#{term},'%')
</when>
<when test="termType == 3">
and tv.owner_name like concat('%',#{term},'%')
</when>
</choose>
</if>
group by tv.id
order by tv.id desc
</select>
<select id="selectOrgVehicleSns" resultType="cn.com.glsx.admin.modules.model.OrgVehicleModel">
select tvd.id,
tv.id vid,
tv.vin,
tv.owner_name ownerName,
tvd.sn sns,
tv.created_by creatorId,
td.source,
td.device_type deviceType
from t_vehicle tv
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
left join t_device td on td.sn = tvd.sn
where tv.del_flag = 0 and tvd.del_flag = 0
and tvd.bind_status = 1
and tv.created_by is not null
<if test="userIds != null and userIds.size() > 0">
and tv.created_by in
<foreach collection="userIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</if>
<if test="term != null and term != ''">
<choose>
<when test="termType == 1">
and tvd.sn like concat('%',#{term},'%')
</when>
<when test="termType == 2">
and tv.vin like concat('%',#{term},'%')
</when>
<when test="termType == 3">
and tv.owner_name like concat('%',#{term},'%')
</when>
</choose>
</if>
order by tv.id desc
<if test="threshold != null and threshold gt 0">
limit #{threshold}
</if>
</select>
<select id="selectAbsolutelyVehicleSns" resultType="cn.com.glsx.admin.modules.model.OrgVehicleModel">
select tvd.id,
tv.id vid,
tv.vin,
tv.owner_name ownerName,
tvd.sn sns,
tvp.receiver_id creatorId,
td.source,
td.device_type deviceType
from t_vehicle tv
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
left join t_device td on td.sn = tvd.sn
left join t_vehicle_permit tvp on tvp.content_id = tv.id
where tv.del_flag = 0 and tvd.del_flag = 0 and tvp.del_flag = 0
and tvd.bind_status = 1
and tvp.receiver_id = #{loginUserId}
<if test="term != null and term != ''">
<choose>
<when test="termType == 1">
and tvd.sn like concat('%',#{term},'%')
</when>
<when test="termType == 2">
and tv.vin like concat('%',#{term},'%')
</when>
<when test="termType == 3">
and tv.owner_name like concat('%',#{term},'%')
</when>
</choose>
</if>
order by tv.id desc
<if test="threshold != null and threshold gt 0">
limit #{threshold}
</if>
</select>
<select id="selectUserAllVehicleSns" resultType="cn.com.glsx.admin.modules.model.OrgVehicleModel">
select tvd.id,
tv.id vid,
tv.vin,
tv.owner_name ownerName,
tvd.sn sns,
tv.created_by creatorId,
td.source,
td.device_type deviceType
from t_vehicle tv
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
left join t_device td on td.sn = tvd.sn
where tv.del_flag = 0 and tvd.del_flag = 0
and tvd.bind_status = 1
and tv.created_by is not null
and tv.created_by in
<foreach collection="userIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
<if test="term != null and term != ''">
<choose>
<when test="termType == 1">
and tvd.sn like concat('%',#{term},'%')
</when>
<when test="termType == 2">
and tv.vin like concat('%',#{term},'%')
</when>
<when test="termType == 3">
and tv.owner_name like concat('%',#{term},'%')
</when>
</choose>
</if>
UNION
select tvd.id,
tv.id vid,
tv.vin,
tv.owner_name ownerName,
tvd.sn sns,
tvp.receiver_id creatorId,
td.source,
td.device_type deviceType
from t_vehicle tv
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
left join t_device td on td.sn = tvd.sn
left join t_vehicle_permit tvp on tvp.content_id = tv.id
where tv.del_flag = 0 and tvd.del_flag = 0 and tvp.del_flag = 0
and tvd.bind_status = 1
and tvp.receiver_id = #{loginUserId}
<if test="term != null and term != ''">
<choose>
<when test="termType == 1">
and tvd.sn like concat('%',#{term},'%')
</when>
<when test="termType == 2">
and tv.vin like concat('%',#{term},'%')
</when>
<when test="termType == 3">
and tv.owner_name like concat('%',#{term},'%')
</when>
</choose>
</if>
order by id desc
</select>
<select id="selectById" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle
where id = #{id}
and del_flag = 0
</select>
<select id="selectByIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle
where del_flag = 0
and id in
<foreach collection="ids" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</select>
<select id="getVehicleByVin" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle tv where tv.vin = #{vin} and del_flag = 0
</select>
<select id="searchVehicleInfo" parameterType="cn.com.glsx.admin.modules.model.param.VehicleInfoSearch"
resultType="cn.com.glsx.admin.modules.model.VehicleInfoPageDTO">
select tv.id ,
tvd.id vdId ,
tv.workorder_id workOrderId,
tw.partner_order_no bizOrderNo,
tv.owner_name ownerName,
tv.vin ,
tvd.sn ,
td.source deviceType,
case when td.source = 1 then '有线' when td.source = 0 then '无线' else '--' end as deviceTypeStr,
case when tv.type_id is null then tv.model_name else
concat(tv.sub_brand_name,'/',tv.series_name,'/',tv.type_name) end modelName,
tv.vehicle_type vehicleType,
tv.vehicle_usages vehicleUsages,
tv.settle_flag settleFlag,
tv.created_date activateTime,
ddf.`status` AS freqStatus,
tv.created_by createdBy
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_workorder tw on tw.id = tv.workorder_id
left join t_device td on td.sn = tvd.sn
left join t_device_location tdl on tdl.sn = tvd.sn
left join t_user tu on tu.id = tv.created_by
left join (select vehicle_id, sn, status from (SELECT * FROM t_device_freq order by created_date desc) temp GROUP BY temp.sn) ddf on ddf.vehicle_id = tv.id and ddf.sn =
td.sn
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
${settleCondition}
<if test="keywords != null and keywords !=''">
and(
tv.owner_name like '%${keywords}%'
or tv.vin like '%${keywords}%'
or tvd.sn like '%${keywords}%'
or tv.type_name like '%${keywords}%'
or tv.model_name like '%${keywords}%'
)
</if>
<if test="activateTimeStart != null and activateTimeStart !=''">
and left(tv.created_date,10) >= #{activateTimeStart}
</if>
<if test="activateTimeEnd != null and activateTimeEnd !=''">
and left(tv.created_date,10) <= #{activateTimeEnd}
</if>
<if test="deviceType != null">
and td.source = #{deviceType}
</if>
<if test="vehicleType != null">
and tv.vehicle_type = #{vehicleType}
</if>
<if test="vehicleUsages != null">
and tv.vehicle_usages = #{vehicleUsages}
</if>
<if test="settleFlag != null">
and tv.settle_flag = #{settleFlag}
</if>
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="deviceState != null">
<choose>
<when test="deviceState == 0"> <!-- 行驶中-->
and (td.source=1) and ((timestampdiff(SECOND,tdl.last_gps_time,now())) <![CDATA[<]]> 360 or (timestampdiff(SECOND,tdl.last_bs_time,now())) <![CDATA[<]]> 360)
and tdl.stay_status = 2
</when>
<when test="deviceState == 1"> <!-- 静止-->
and (td.source=1) and ((timestampdiff(SECOND,tdl.last_gps_time,now())) <![CDATA[<]]> 360 or (timestampdiff(SECOND,tdl.last_bs_time,now())) <![CDATA[<]]> 360)
and (tdl.stay_status is null or tdl.stay_status = 1)
</when>
<when test="deviceState == 2"> <!-- 离线-->
and ((timestampdiff(SECOND, tdl.last_gps_time, now()) > #{offlineTime} and timestampdiff(SECOND, tdl.last_bs_time, now()) > #{offlineTime})
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and timestampdiff(SECOND, tdl.last_bs_time, now()) > #{offlineTime})
or (timestampdiff(SECOND, tdl.last_gps_time, now()) > #{offlineTime} and tdl.last_bs_time is null)
)
</when>
<when test="deviceState == 3"> <!-- 在线-->
and (timestampdiff(SECOND,tdl.last_gps_time,now()) < #{offlineTime} or timestampdiff(SECOND,tdl.last_bs_time,now()) < #{offlineTime})
</when>
</choose>
</if>
order by tv.created_date desc,tv.id,vdId
</select>
<select id="exportVehicleInfo" parameterType="cn.com.glsx.admin.modules.model.param.VehicleInfoSearch"
resultType="cn.com.glsx.admin.modules.model.export.VehicleInfoExport">
select tv.id ,
tvd.id vdId ,
tv.workorder_id workOrderId,
tw.partner_order_no bizOrderNo,
tw.shop_name shopName,
tv.owner_name ownerName,
tv.vin ,
tvd.sn ,
td.source deviceType,
case when td.source = 1 then '有线' when td.source = 0 then '无线' else '--' end as deviceTypeStr,
case when tv.type_id is null then tv.model_name else concat(tv.sub_brand_name,'/',tv.series_name,'/',tv.type_name) end as modelName,
tv.vehicle_type vehicleType,
tv.vehicle_usages vehicleUsages,
tv.created_date activateTime,
tv.settle_flag settleFlag,
ddf.`status` AS freqStatus,
LEFT(ddf.created_date, 19) AS freqTime,
ddf.freq_type AS freqType,
TIMESTAMPDIFF(DAY, ddf.created_date, ddf.updated_date) AS diffDayTime,
TIMESTAMPDIFF(MINUTE, ddf.created_date, ddf.updated_date) AS diffMinuteTime,
tdp.soc AS batteryLevel,
ddf.catching_timer AS catchingTimer,
ddf.timer AS timer,
ddf.`week` AS `week`,
ddf.week_timer AS weekTimer,
tv.created_by createdBy,
tu2.username,
tu.account operation
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_workorder tw on tw.id = tv.workorder_id
left join t_device td on td.sn = tvd.sn
left join t_device_location tdl on tdl.sn = tvd.sn
left join t_device_power tdp on tdp.sn = tvd.sn and tvd.id = tdp.vd_id
left join (select * from (SELECT * FROM t_device_freq order by created_date desc) temp GROUP BY temp.sn) ddf on ddf.vehicle_id = tv.id and ddf.sn = td.sn
left join t_user tu on tu.id = ddf.created_by
left join t_user tu2 on tu2.id = tv.created_by
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
${settleCondition}
<if test="keywords != null and keywords !=''">
and(
tv.owner_name like '%${keywords}%'
or tv.vin like '%${keywords}%'
or td.sn like '%${keywords}%'
or tv.type_name like '%${keywords}%'
or tv.model_name like '%${keywords}%'
)
</if>
<if test="activateTimeStart != null and activateTimeStart !=''">
and left(tv.created_date,10) >= #{activateTimeStart}
</if>
<if test="activateTimeEnd != null and activateTimeEnd !=''">
and left(tv.created_date,10) <= #{activateTimeEnd}
</if>
<if test="deviceType != null">
and td.source = #{deviceType}
</if>
<if test="vehicleType != null">
and tv.vehicle_type = #{vehicleType}
</if>
<if test="vehicleUsages != null">
and tv.vehicle_usages = #{vehicleUsages}
</if>
<if test="settleFlag != null">
and tv.settle_flag = #{settleFlag}
</if>
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="deviceState != null">
<choose>
<when test="deviceState == 0"> <!-- 行驶中-->
and (td.source=1) and ((timestampdiff(SECOND,tdl.last_gps_time,now())) <![CDATA[<]]> 360 or (timestampdiff(SECOND,tdl.last_bs_time,now())) <![CDATA[<]]> 360)
and tdl.stay_status = 2
</when>
<when test="deviceState == 1"> <!-- 静止-->
and (td.source=1) and ((timestampdiff(SECOND,tdl.last_gps_time,now())) <![CDATA[<]]> 360 or (timestampdiff(SECOND,tdl.last_bs_time,now())) <![CDATA[<]]> 360)
and (tdl.stay_status is null or tdl.stay_status = 1)
</when>
<when test="deviceState == 2"> <!-- 离线-->
and ((timestampdiff(SECOND, tdl.last_gps_time, now()) > #{offlineTime} and timestampdiff(SECOND, tdl.last_bs_time, now()) > #{offlineTime})
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and timestampdiff(SECOND, tdl.last_bs_time, now()) > #{offlineTime})
or (timestampdiff(SECOND, tdl.last_gps_time, now()) > #{offlineTime} and tdl.last_bs_time is null)
)
</when>
<when test="deviceState == 3"> <!-- 在线-->
and (timestampdiff(SECOND,tdl.last_gps_time,now()) < #{offlineTime} or timestampdiff(SECOND,tdl.last_bs_time,now()) < #{offlineTime})
</when>
</choose>
</if>
order by tv.created_date desc,tv.id,vdId
</select>
<select id="listTestDriveVehicle" resultType="cn.com.glsx.admin.modules.model.TestVehicleDTO">
select
tv.id ,
tvd.id as vdId,
tv.vin ,
tv.owner_name as ownerName,
td.sn as sns
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_user tu on tu.id = tv.created_by and tu.del_flag = 0
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.trial_type = 0
and tvd.del_flag = 0
and td.del_flag = 0
<if test="sn != null and sn !=''">
and td.sn like concat('%',#{sn},'%')
</if>
<if test="ownerName != null and ownerName !=''">
and tv.owner_name like concat('%',#{ownerName},'%')
</if>
<if test="vin != null and vin !=''">
and tv.vin like concat('%',#{vin},'%')
</if>
<if test="buyDateStart != null and buyDateStart !=''">
and tv.created_date >= #{buyDateStart}
</if>
<if test="buyDateEnd != null and buyDateEnd !=''">
and tv.created_date <= #{buyDateEnd}
</if>
<if test="shopId != null and shopId !=''">
and tu.id = #{shopId}
</if>
order by tv.created_date desc,tv.id
</select>
<select id="getVehicleBindNumWithAuth" resultType="cn.com.glsx.admin.modules.model.stat.StatCountModel">
select count(temp.id) as cnt,
count(case when TO_DAYS(temp.created_date) = TO_DAYS(NOW()) then 1 end) as cnt1
from (select tv.id,
max(tvd.created_date) as created_date,
tv.created_by
from t_vehicle tv
left join t_vehicle_device tvd
on tv.id = tvd.vehicle_id
where tvd.bind_status = 1
and tvd.del_flag = 0
and tv.del_flag = 0
group by tv.id) temp
</select>
<select id="getAllDeviceSnByAuth" resultType="String">
select tvd.sn
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
where tv.del_flag = 0
and tvd.del_flag = 0
and tvd.bind_status = 1
</select>
<select id="getBaseDeviceActiveListWithAuth" resultType="cn.com.glsx.admin.modules.model.export.DeviceActiveExprot">
select tvd.id,
tw.partner_order_no workOrderNo,
tv.owner_name as ownerName,
tv.vin as vin,
tvd.sn as sn,
td.device_type as deviceType,
td.source as `source`,
case
when (timestampdiff(SECOND, tdl.last_gps_time, now())) > 259200
and (timestampdiff(SECOND, tdl.last_bs_time, now())) > 259200 then 2
when (tdl.last_gps_time is null and tdl.last_bs_time is null) then 2
when (timestampdiff(SECOND, tdl.last_gps_time, now())) > 259200 and tdl.last_bs_time is null then 2
when tdl.last_gps_time is null and (timestampdiff(SECOND, tdl.last_bs_time, now())) > 259200 then 2
else 1 end as isOnline,
tv.created_by as createdBy,
tvd.created_date as activeDate,
tvd.active_location_lng as lng,
tvd.active_location_lat as lat,
tvd.active_location_address as activeAddress
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
left join t_user tu on tu.id = tv.created_by and tu.del_flag = 0
left join t_device_location tdl on tdl.sn = tvd.sn
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="isOnLine != null">
<choose>
<when test="isOnLine == 2">
and ( timestampdiff(SECOND,tdl.last_gps_time,now())>259200
and timestampdiff(SECOND,tdl.last_bs_time,now())>259200
or (tdl.last_gps_time is null and tdl.last_bs_time is null )
or (timestampdiff(SECOND,tdl.last_gps_time,now())>259200 and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and timestampdiff(SECOND,tdl.last_bs_time,now())>259200)
)
</when>
<when test="isOnLine == 1">
and (timestampdiff(SECOND,tdl.last_gps_time,now()) <![CDATA[<]]> 259200
or timestampdiff(SECOND,tdl.last_bs_time,now()) <![CDATA[<]]> 259200)
</when>
</choose>
</if>
<if test="startTime != null and startTime != ''">
and tvd.created_date >= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
and tvd.created_date <= #{endTime}
</if>
<if test="keywords != null and keywords !=''">
and(
td.sn like '%${keywords}%'
or tw.partner_order_no like '%${keywords}%'
or tv.vin like '%${keywords}%'
or tv.owner_name like '%${keywords}%'
)
</if>
order by tvd.id desc
</select>
<select id="findFinalPositioningList" resultType="cn.com.glsx.admin.modules.model.export.FinalPositioningExport">
select tvd.id,
tw.partner_order_no workOrderNo,
tw.`shop_name` AS shopName,
tv.owner_name as ownerName,
tv.vin as vin,
tvd.sn as sn,
tvd.created_date as activeDate,
tdl.last_gps_time as finalGpsTime,
tdl.last_bs_time as finalBsTime,
td.source as `source`,
td.device_type as deviceType
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
left join t_device_location tdl on tdl.sn = td.sn
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
<if test="activeDateStart != null and activeDateStart != ''">
and tvd.created_date >= #{activeDateStart}
</if>
<if test="activeDateEnd != null and activeDateEnd != ''">
and tvd.created_date <= #{activeDateEnd}
</if>
<if test="finalGpsTimeStart != null and finalGpsTimeStart != ''">
and tdl.last_gps_time >= #{finalGpsTimeStart}
</if>
<if test="finalGpsTimeEnd != null and finalGpsTimeEnd != ''">
and tdl.last_gps_time <= #{finalGpsTimeEnd}
</if>
<if test="finalBsTimeStart != null and finalBsTimeStart != ''">
and tdl.last_bs_time >= #{finalBsTimeStart}
</if>
<if test="finalBsTimeEnd != null and finalBsTimeEnd != ''">
and tdl.last_bs_time <= #{finalBsTimeEnd}
</if>
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="deviceType != null ">
and td.device_type = #{deviceType}
</if>
<if test="source != null ">
and td.source = #{source}
</if>
<if test="keywords != null and keywords !=''">
and(
tw.partner_order_no like '%${keywords}%'
or td.sn like '%${keywords}%'
or tv.vin like '%${keywords}%'
or tv.owner_name like '%${keywords}%'
)
</if>
order by tvd.id desc
</select>
<select id="findJudgmentList" resultType="cn.com.glsx.admin.modules.model.export.JudgmentExport">
select tvd.id, tw.partner_order_no as workOrderNo,
tv.owner_name as ownerName,
tv.vin as vin,
case when tv.type_id is null then tv.model_name
else concat(tv.series_name, '/', tv.type_name) end modelName,
tvd.sn as sn,
td.source as `source`
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="keywords != null and keywords !=''">
and(
tw.partner_order_no like '%${keywords}%'
or tv.vin like '%${keywords}%'
or tv.owner_name like '%${keywords}%'
or tvd.sn like '%${keywords}%'
)
</if>
</select>
<select id="findJourneyList" resultType="cn.com.glsx.admin.modules.model.export.JourneyExport">
select tvd.id, tw.partner_order_no as workOrderNo,
tv.owner_name as ownerName,
tvd.sn as sn,
tv.vin as vin, tv.created_date,
tdjo.total_journey_count as tripCount,
tdjo.distance as distance
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device_journey_overview tdjo on tvd.id = tdjo.vd_id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
and td.source = 1
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="keywords != null and keywords !=''">
and(
tw.partner_order_no like '%${keywords}%'
or tv.vin like '%${keywords}%'
or tv.owner_name like '%${keywords}%'
or tvd.sn like '%${keywords}%'
)
</if>
order by tv.created_date desc
</select>
<select id="countJourneyList" resultType="java.lang.Integer">
select count(1)
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device_journey_overview tdjo on tvd.id = tdjo.vd_id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
and td.source = 1
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="keywords != null and keywords !=''">
and(
tw.partner_order_no like '%${keywords}%'
or tv.vin like '%${keywords}%'
or tv.owner_name like '%${keywords}%'
or tvd.sn like '%${keywords}%'
)
</if>
</select>
<select id="findOfflineList" resultType="cn.com.glsx.admin.modules.model.export.OfflineExport">
select tvd.id, tw.partner_order_no as workOrderNo,
tv.owner_name as ownerName,
tvd.sn as sn,
tv.vin as vin,
td.device_type as deviceType,
tu.username as shopName,
tvd.created_date as activeDate,
tdl.last_gps_time as lastGpsTime,
tdl.last_bs_time as lastBsTime,
td.source as `source`
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
left join t_user tu on tu.id = tv.created_by and tu.del_flag = 0
left join t_device_location tdl on tdl.sn = td.sn
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
<if test="offlineStartTime != null and offlineStartTime != ''">
and ((tdl.last_gps_time < #{offlineStartTime} and tdl.last_bs_time < #{offlineStartTime})
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and tdl.last_bs_time < #{offlineStartTime})
or (tdl.last_gps_time < #{offlineStartTime} and tdl.last_bs_time is null)
)
</if>
<if test="activeStartTime != null and activeStartTime != ''">
and tvd.created_date >= #{activeStartTime}
</if>
<if test="activeEndTime != null and activeEndTime != ''">
and tvd.created_date <= #{activeEndTime}
</if>
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="deviceType != null ">
and td.device_type = #{deviceType}
</if>
<if test="source != null ">
and td.source = #{source}
</if>
<if test="keywords != null and keywords !=''">
and(
tw.partner_order_no like '%${keywords}%'
or tv.vin like '%${keywords}%'
or tv.owner_name like '%${keywords}%'
or tvd.sn like '%${keywords}%'
)
</if>
order by tvd.id desc
</select>
<select id="searchCommonTearDownAlarmList" resultType="cn.com.glsx.admin.modules.model.export.CommonTearDownModelExport">
select tvd.id, tw.partner_order_no as workOrderNo,
tu.username as shopName,
tv.owner_name as ownerName,
tv.vin as vin,
tvd.sn as sn,
td.source as source
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
left join t_user tu on tu.id = tv.created_by and tu.del_flag = 0
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="keywords != null and keywords !=''">
and(
tw.partner_order_no like '%${keywords}%'
or tv.vin like '%${keywords}%'
or tv.owner_name like '%${keywords}%'
or tvd.sn like '%${keywords}%'
)
</if>
</select>
<select id="findJourneyDetailList" resultType="cn.com.glsx.admin.modules.model.export.JourneyDetailExport">
select tvd.id,
tw.partner_order_no as workOrderNo,
tv.owner_name as ownerName,
tvd.sn as sn,
tv.vin as vin, tv.created_date,
tdj.begin_time as journeyStartTime,
tdj.end_time as journeyEndTime,
tdj.mileage as distance
from t_device_journey tdj
left join t_vehicle_device tvd on tvd.id = tdj.vd_id
left join t_vehicle tv on tv.id = tvd.vehicle_id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
and td.source = 1
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="sn != null and sn !=''">
and tvd.sn = #{sn}
</if>
<if test="journeyStartTime != null and journeyStartTime !=''">
and tdj.begin_time <![CDATA[ >= ]]> #{journeyStartTime}
</if>
<if test="journeyEndTime != null and journeyEndTime !=''">
and tdj.end_time <![CDATA[ <= ]]> #{journeyEndTime}
</if>
order by tdj.begin_time desc
</select>
<select id="countJourneyDetailList" resultType="java.lang.Integer">
select count(1)
from t_device_journey tdj
left join t_vehicle_device tvd on tvd.id = tdj.vd_id
left join t_vehicle tv on tv.id = tvd.vehicle_id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
and td.source = 1
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="sn != null and sn !=''">
and tvd.sn = #{sn}
</if>
</select>
<select id="getActiveDeviceInfoWithAuth" resultType="cn.com.glsx.admin.modules.model.ActiveDeviceVo">
SELECT count(temp.id) AS activeNumber,
<choose>
<when test="period == 1 || period == 2">
DATE_FORMAT(temp.created_date,'%H') as activeDate
from (
select tvd.id,
tvd.created_date,
tv.created_by
FROM t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
WHERE tvd.bind_status = 1 and tv.del_flag = 0 and tvd.del_flag = 0
${appendSql}
) temp
GROUP BY DATE_FORMAT(temp.created_date,'%H')
</when>
<otherwise>
DATE_FORMAT(temp.created_date,'%Y-%m-%d') as activeDate
from (
select tvd.id,
tvd.created_date,
tv.created_by
FROM t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
WHERE tvd.bind_status = 1 and tv.del_flag = 0 and tvd.del_flag = 0
${appendSql}
)temp
GROUP BY DATE_FORMAT(temp.created_date,'%Y-%m-%d')
</otherwise>
</choose>
</select>
<select id="getBindDeviceInfoWithAuth" resultType="cn.com.glsx.admin.modules.model.DeviceBindVo">
SELECT count(temp.id) AS bindDeviceNumber,
DATE_FORMAT(temp.created_date, '%Y-%m-%d') as bindDate
FROM (SELECT distinct tv.id,
tvd.created_date,
tv.created_by
FROM t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
WHERE tvd.bind_status = 1
and tv.del_flag = 0
and tvd.del_flag = 0
${appendSql}) temp
GROUP BY DATE_FORMAT(temp.created_date, '%Y-%m-%d')
</select>
<select id="getOfflineNumber" resultType="cn.com.glsx.admin.modules.model.stat.StatCountModel">
select COUNT(1) cnt
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_device_location tdl on tdl.sn = td.sn
WHERE tvd.del_flag = 0 and tv.del_flag = 0 and tvd.bind_status = 1
and ((timestampdiff(SECOND, tdl.last_gps_time, now()) > #{offlineTime} and timestampdiff(SECOND, tdl.last_bs_time, now()) > #{offlineTime})
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and timestampdiff(SECOND, tdl.last_bs_time, now()) > #{offlineTime})
or (timestampdiff(SECOND, tdl.last_gps_time, now()) > #{offlineTime} and tdl.last_bs_time is null)
)
<if test="offlineSnStr != null and offlineSnStr != ''">
and tvd.sn not in (${offlineSnStr})
</if>
</select>
<select id="findJourneyDailyList" resultType="cn.com.glsx.admin.modules.model.export.JourneyDailyExport">
select tvd.sn as sn,
tv.vin as vin, tv.created_date,
ifnull(sum(tdj.mileage), 0) as journeyMileage,
date_format(tdj.begin_time, '%Y-%m-%d') as journeyTime
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
left join t_device_journey tdj on tvd.id = tdj.vd_id and tdj.begin_time <![CDATA[ >= ]]> #{journeyStartTime} and tdj.begin_time <![CDATA[ <= ]]> #{journeyEndTime}
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
and td.source = 1
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="keywords != null and keywords !=''">
and(
tw.partner_order_no like '%${keywords}%'
or tv.vin like '%${keywords}%'
or tv.owner_name like '%${keywords}%'
or tvd.sn like '%${keywords}%'
)
</if>
group by tvd.sn, date_format(tdj.begin_time, '%Y-%m-%d')
order by tv.created_date desc
</select>
<select id="getOffLineAlarmCount" resultType="cn.com.glsx.admin.modules.model.stat.StatCountModel">
SELECT count(1) cnt
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device_location tdl on tdl.sn = tvd.sn
left join t_device td on td.sn = tvd.sn
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
and td.del_flag = 0
and tvd.created_date > '2013-01-01 00:00:00.0'
<!--离线时间-->
<if test="lostBegin != null">
and ((tdl.last_gps_time < #{lostBegin} and tdl.last_bs_time < #{lostBegin})
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and tdl.last_bs_time < #{lostBegin})
or (tdl.last_gps_time < #{lostBegin} and tdl.last_bs_time is null)
)
</if>
</select>
<select id="selectByOrderId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle
where del_flag = 0
and workorder_id = #{workOrderId}
</select>
<select id="selectAnyByOrderId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle
where workorder_id = #{workOrderId}
</select>
<select id="selectByOrderIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle
where del_flag = 0
and workorder_id in
<foreach collection="orderIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</select>
<select id="getVehicleAndDeviceMap" resultType="cn.com.glsx.admin.modules.model.VehicleDeviceMapDto">
SELECT tv.vin,
GROUP_CONCAT(tvd.sn) as sns
FROM t_vehicle tv
LEFT JOIN t_vehicle_device tvd ON tvd.vehicle_id = tv.id
WHERE tv.del_flag = 0
GROUP BY tv.vin;
</select>
<select id="getVehicleByPermission" resultType="java.lang.String">
select distinct vin
from t_vehicle
where del_flag = 0;
</select>
<select id="selectBizWorkNoAndVin" resultMap="BaseResultMap">
select tv.*
from t_vehicle tv
left join t_workorder tw on tw.id = tv.workorder_id
where tv.del_flag = 0
and tw.partner_order_no = #{bizOrderNo}
and tv.vin = #{vin} limit 1
</select>
<select id="selectAllShared" resultMap="BaseResultMap">
select tv.*
from t_vehicle tv
where tv.del_flag = 0
</select>
<select id="searchWithoutPermit" resultType="cn.com.glsx.admin.modules.model.view.SimpleVehicleDTO">
select tv.id,
tw.partner_order_no orderNo,
tv.owner_name as ownerName,
tv.vin as vin,
group_concat(tvd.sn) as sns,
group_concat(td.device_type) as deviceTypes,
group_concat(td.source) as sources
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_workorder tw on tw.id = tv.workorder_id and tw.del_flag = 0
where tv.del_flag = 0
and tvd.del_flag = 0
and tvd.bind_status = 1
<choose>
<when test="termType == 1">
and tv.id in (select vehicle_id from t_vehicle_device where del_flag = 0 and bind_status = 1 and sn = #{term})
</when>
<when test="termType == 2">
and tv.vin = #{term}
</when>
<when test="termType == 3">
and tv.owner_name = #{term}
</when>
<when test="termType == 4">
and tw.partner_order_no = #{term}
</when>
<otherwise>
and tv.id = 0
</otherwise>
</choose>
group by tv.id
</select>
<select id="selectVehicleUnique" resultMap="BaseResultMap">
select tv.*
from t_vehicle tv
where tv.vin=#{vin}
<choose>
<when test="workOrderId!=null">
and tv.workorder_id=#{workOrderId}
</when>
<otherwise>
and tv.workorder_id is null
</otherwise>
</choose>
and tv.del_flag = #{delFlag}
limit 1
</select>
<select id="searchReportVehicle" resultType="cn.com.glsx.admin.modules.model.ReportVehicleDTO">
select tv.id,
tv.workorder_id workOrderId,
tw.partner_order_no bizOrderNo,
tv.owner_name ownerName,
tv.vin,
twv.device_compose deviceCompose,
group_concat(td.sn order by td.id) sns,
group_concat(td.device_type order by td.id) deviceTypes,
group_concat(td.source order by td.id) deviceSources,
tv.license_plate licensePlate,
case when tv.type_id is null then tv.model_name else concat(tv.sub_brand_name,'/',tv.series_name,'/',tv.type_name) end as modelName,
tv.created_date activateTime,
tw.created_date createdDate,
ifnull(tw.mechanic_name,tu.username) activator,
tv.created_by createdBy
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_workorder tw on tw.id = tv.workorder_id
left join t_workorder_vehicle twv on twv.workorder_id = tw.id
left join t_device td on td.sn = tvd.sn
left join t_user tu on tu.id = tv.created_by
where tv.del_flag = 0
and tvd.del_flag = 0
and tvd.bind_status = 1
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="activateBeginDate != null and activateBeginDate != '' and activateEndDate != null and activateEndDate != ''">
and DATE_FORMAT(tv.created_date,'%Y-%m-%d') between #{activateBeginDate} and #{activateEndDate}
</if>
<if test="orderBeginDate != null and orderBeginDate != '' and orderEndDate != null and orderEndDate != ''">
and DATE_FORMAT(tw.created_date,'%Y-%m-%d') between #{orderBeginDate} and #{orderEndDate}
</if>
<if test="term != null and term !=''">
and(
tv.owner_name like '%${term}%'
or tv.vin like '%${term}%'
or tw.partner_order_no like '%${term}%'
or tv.id in (select vehicle_id from t_vehicle_device where del_flag = 0 and bind_status = 1 and sn like '%${term}%')
)
</if>
group by tv.id
order by tv.created_date desc
</select>
<select id="exportReportVehicle" resultType="cn.com.glsx.admin.modules.model.export.ReportVehicleExport">
select tv.id,
tv.workorder_id workOrderId,
tw.partner_order_no bizOrderNo,
tv.owner_name ownerName,
tv.vin,
twv.device_compose deviceCompose,
group_concat(td.sn order by td.id) sns,
group_concat(td.device_type order by td.id) deviceTypes,
group_concat(td.source order by td.id) deviceSources,
tv.license_plate licensePlate,
case when tv.type_id is null then tv.model_name else concat(tv.sub_brand_name,'/',tv.series_name,'/',tv.type_name) end as modelName,
tv.created_date activateTime,
tv.remark,
tw.shop_name shopName,
tw.service_address serviceAddress,
'--' as leaseTerm,
'--' as leaseWay,
'--' as purchaseWay,
tw.created_date createdDate,
ifnull(tw.mechanic_name,tu.username) activator,
tv.created_by createdBy
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_workorder tw on tw.id = tv.workorder_id
left join t_workorder_vehicle twv on twv.workorder_id = tw.id
left join t_device td on td.sn = tvd.sn
left join t_user tu on tu.id = tv.created_by
where tv.del_flag = 0
and tvd.del_flag = 0
and tvd.bind_status = 1
<if test="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<if test="activateBeginDate != null and activateBeginDate != '' and activateEndDate != null and activateEndDate != ''">
and DATE_FORMAT(tv.created_date,'%Y-%m-%d') between #{activateBeginDate} and #{activateEndDate}
</if>
<if test="orderBeginDate != null and orderBeginDate != '' and orderEndDate != null and orderEndDate != ''">
and DATE_FORMAT(tw.created_date,'%Y-%m-%d') between #{orderBeginDate} and #{orderEndDate}
</if>
<if test="term != null and term !=''">
and(
tv.owner_name like '%${term}%'
or tv.vin like '%${term}%'
or tw.partner_order_no like '%${term}%'
or tv.id in (select vehicle_id from t_vehicle_device where del_flag = 0 and bind_status = 1 and sn like '%${term}%')
)
</if>
group by tv.id
order by tv.created_date desc
</select>
<update id="updateSettleFlagById">
update t_vehicle
set settle_flag = #{settleFlag}
where id = #{id}
</update>
</mapper>