CustomerPortraitMapper.xml
32.7 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
<?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.dj.customer.mapper.CustomerPortraitMapper" >
<resultMap id="BaseResultMap" type="cn.com.glsx.dj.customer.dto.CustomerPortraitDTO" >
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="sn" property="sn" jdbcType="VARCHAR" />
<result column="stand_no" jdbcType="VARCHAR" property="standNo" />
<result column="plate_number" property="plateNumber" jdbcType="VARCHAR" />
<result column="cus_name" property="cusName" jdbcType="VARCHAR" />
<result column="cus_mobile" property="cusMobile" jdbcType="VARCHAR" />
<result column="erp_mobile" property="erpMobile" jdbcType="VARCHAR" />
<result column="vehicle_buy_time" property="vehicleBuyTime" jdbcType="TIMESTAMP" />
<result column="last_back_time" property="lastBackTime" jdbcType="TIMESTAMP" />
<result column="curr_mileage" property="currMileage" jdbcType="DOUBLE" />
<result column="distance" property="distance" jdbcType="DOUBLE" />
<result column="last_time_mileage" property="lastTimeMileage" jdbcType="DOUBLE" />
<result column="ins_mileage_total" property="insMileageTotal" jdbcType="DOUBLE" />
<result column="continuity_unback_count" property="continuityUnbackCount" jdbcType="INTEGER" />
<result column="back_numbers_total" property="backNumbersTotal" jdbcType="INTEGER" />
<result column="last_year_back_count" property="lastYearBackCount" jdbcType="INTEGER" />
<result column="loss_numbers_total" property="lossNumbersTotal" jdbcType="INTEGER" />
<result column="last_year_loss_Count" property="lastYearLossCount" jdbcType="INTEGER" />
<result column="first_ins_to_cur_total_days" property="firstInsToCurTotalDays" jdbcType="INTEGER" />
<result column="merchant_id" jdbcType="INTEGER" property="merchantId" />
<result column="created_by" jdbcType="VARCHAR" property="createdBy" />
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate" />
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate" />
<result column="deleted_flag" jdbcType="CHAR" property="deletedFlag" />
<result column="last_back_time_str" property="lastBackTimeStr" jdbcType="VARCHAR" />
<result column="vehicle_buy_time_str" property="vehicleBuyTimeStr" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="BaseResultBaseMap" type="cn.com.glsx.dj.customer.model.CustomerPortrait" >
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="sn" property="sn" jdbcType="VARCHAR" />
<result column="stand_no" jdbcType="VARCHAR" property="standNo" />
<result column="plate_number" property="plateNumber" jdbcType="VARCHAR" />
<result column="cus_name" property="cusName" jdbcType="VARCHAR" />
<result column="cus_mobile" property="cusMobile" jdbcType="VARCHAR" />
<result column="erp_mobile" property="erpMobile" jdbcType="VARCHAR" />
<result column="vehicle_buy_time" property="vehicleBuyTime" jdbcType="TIMESTAMP" />
<result column="last_back_time" property="lastBackTime" jdbcType="TIMESTAMP" />
<result column="curr_mileage" property="currMileage" jdbcType="DOUBLE" />
<result column="distance" property="distance" jdbcType="DOUBLE" />
<result column="last_time_mileage" property="lastTimeMileage" jdbcType="DOUBLE" />
<result column="ins_mileage_total" property="insMileageTotal" jdbcType="DOUBLE" />
<result column="continuity_unback_count" property="continuityUnbackCount" jdbcType="INTEGER" />
<result column="back_numbers_total" property="backNumbersTotal" jdbcType="INTEGER" />
<result column="last_year_back_count" property="lastYearBackCount" jdbcType="INTEGER" />
<result column="loss_numbers_total" property="lossNumbersTotal" jdbcType="INTEGER" />
<result column="last_year_loss_Count" property="lastYearLossCount" jdbcType="INTEGER" />
<result column="first_ins_to_cur_total_days" property="firstInsToCurTotalDays" jdbcType="INTEGER" />
<result column="merchant_id" jdbcType="INTEGER" property="merchantId" />
<result column="created_by" jdbcType="VARCHAR" property="createdBy" />
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate" />
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate" />
<result column="deleted_flag" jdbcType="CHAR" property="deletedFlag" />
<result column="last_back_time_str" property="lastBackTimeStr" jdbcType="VARCHAR" />
<result column="vehicle_buy_time_str" property="vehicleBuyTimeStr" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="BaseResultMileageVOMap" type="cn.com.glsx.dj.customer.vo.CarDaysMileageVO" >
<result column="id" jdbcType="INTEGER" property="id" />
<result column="current_dates" property="currentDate" jdbcType="TIMESTAMP" />
<result column="total_mileage" property="totalMileage" jdbcType="DOUBLE" />
<result column="sn" jdbcType="VARCHAR" property="sn" />
</resultMap>
<resultMap id="BaseResultLossVOMap" type="cn.com.glsx.dj.customer.vo.CarLossWarningVO">
<result column="id" jdbcType="INTEGER" property="id" />
<result column="stand_no" jdbcType="VARCHAR" property="standNo" />
<result column="enter_time" jdbcType="TIMESTAMP" property="enterTime" />
<result column="last_year_loss" jdbcType="INTEGER" property="lastYearLoss" />
<result column="number_of_shops" jdbcType="INTEGER" property="lossTotalCount" />
<result column="sn" jdbcType="VARCHAR" property="sn" />
</resultMap>
<resultMap id="BaseResultShopVOMap" type="cn.com.glsx.dj.customer.vo.CarShopWarningVO">
<result column="id" jdbcType="INTEGER" property="id" />
<result column="stand_no" jdbcType="VARCHAR" property="standNo" />
<result column="enter_time" jdbcType="TIMESTAMP" property="enterTime" />
<result column="erp_mobile" jdbcType="VARCHAR" property="erpMobile" />
<result column="last_year_shops" jdbcType="INTEGER" property="lastYearShops" />
<result column="number_of_shops" jdbcType="INTEGER" property="backNumbersTotal" />
<result column="current_mileage" jdbcType="DOUBLE" property="currentMileage"/>
<result column="sn" jdbcType="VARCHAR" property="sn"/>
</resultMap>
<resultMap id="BaseResultInsureVOMap" type="cn.com.glsx.dj.customer.vo.InsureOrderVO" >
<result column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="phone" jdbcType="VARCHAR" property="phone"/>
<result column="stand_no" jdbcType="VARCHAR" property="standNo"/>
<result column="merchant_id" jdbcType="VARCHAR" property="merchantId"/>
<result column="merchant_name" jdbcType="VARCHAR" property="merchantName"/>
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
<result column="sub_device_sn" jdbcType="VARCHAR" property="subDeviceSn"/>
<result column="success_date" jdbcType="TIMESTAMP" property="successDate"/>
<result column="card_type" jdbcType="CHAR" property="cardType"/>
<result column="card_no" jdbcType="VARCHAR" property="cardNo" />
<result column="source" jdbcType="INTEGER" property="source" />
<result column="vehicle_id" jdbcType="INTEGER" property="vehicleId"/>
<result column="plate_number" jdbcType="VARCHAR" property="plateNumber" />
<result column="source" jdbcType="INTEGER" property="source"/>
</resultMap>
<resultMap id="BaseCustomerPortraitVOMap" type="cn.com.glsx.dj.customer.vo.CustomerPortraitVO" >
<result column="id" jdbcType="INTEGER" property="id" />
<result column="sn" jdbcType="VARCHAR" property="sn"/>
<result column="cus_name" jdbcType="VARCHAR" property="cusName"/>
<result column="cus_mobile" jdbcType="VARCHAR" property="cusMobile"/>
<result column="stand_no" jdbcType="VARCHAR" property="standNo"/>
</resultMap>
<sql id="Base_Column_List" >
c.id,
c.sn,
c.stand_no,
c.plate_number,
c.cus_name,
c.cus_mobile,
c.erp_mobile,
c.vehicle_buy_time,
c.last_back_time,
c.curr_mileage,
c.distance,
c.last_time_mileage,
c.continuity_unback_count,
c.back_numbers_total,
c.last_year_back_count,
c.loss_numbers_total,
c.last_year_loss_Count,
c.ins_mileage_total,
c.first_ins_to_cur_total_days,
c.merchant_id,
date_format(last_back_time,'%Y-%m-%d %H:%i:%s') as last_back_time_str,
date_format(vehicle_buy_time,'%Y-%m-%d %H:%i:%s') as vehicle_buy_time_str
</sql>
<select id="selectByStandNo" parameterType="java.lang.String" resultMap="BaseResultMap">
select <include refid="Base_Column_List"></include>
from dj_customer_portrait c
where c.stand_no=#{standNo}
</select>
<select id="selectBySnAndMerchantId" parameterType="cn.com.glsx.dj.customer.dto.CustomerPortraitDTO" resultMap="BaseResultMap">
SELECT
c.id,
c.sn,
c.stand_no,
c.plate_number,
c.cus_name,
c.cus_mobile,
c.erp_mobile,
c.vehicle_buy_time,
c.last_back_time,
c.curr_mileage,
c.distance,
c.last_time_mileage,
c.continuity_unback_count,
c.back_numbers_total,
c.last_year_back_count,
c.loss_numbers_total,
c.last_year_loss_Count,
c.ins_mileage_total,
c.first_ins_to_cur_total_days,
c.merchant_id,
date_format(last_back_time,'%Y-%m-%d %H:%i:%s') as last_back_time_str,
date_format(vehicle_buy_time,'%Y-%m-%d %H:%i:%s') as vehicle_buy_time_str
FROM
dj_customer_portrait c
WHERE 1=1
AND c.sn=#{sn}
AND c.merchant_id=#{merchantId}
LIMIT 0,1
</select>
<select id="listAllVO" parameterType="cn.com.glsx.dj.customer.dto.CustomerPortraitDTO" resultMap="BaseCustomerPortraitVOMap">
select
sn,
cus_name,
cus_mobile,
stand_no
from dj_customer_portrait c
where 1=1
and deleted_flag = 'N'
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
</select>
<select id="listBasic" parameterType="cn.com.glsx.dj.customer.dto.CustomerPortraitDTO" resultMap="BaseResultMap">
select <include refid="Base_Column_List"></include>
from dj_customer_portrait c
where 1=1
and c.deleted_flag = 'N'
<if test="record.merchantIds != null and record.merchantIds.size > 0 ">
and merchant_id in
<foreach item="merchantId" index="index" collection="record.merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
<if test="record.merchantId != null">
<![CDATA[and c.merchant_id = #{record.merchantId,jdbcType=INTEGER}]]>
</if>
<if test="record.sn != null">
<![CDATA[and c.sn = #{record.sn,jdbcType=VARCHAR}]]>
</if>
<if test="record.searchValue != null">
AND (c.stand_no LIKE CONCAT('%',#{record.searchValue,jdbcType=VARCHAR},'%')
or c.plate_number LIKE CONCAT('%',#{record.searchValue,jdbcType=VARCHAR},'%')
or c.cus_name LIKE CONCAT('%',#{record.searchValue,jdbcType=VARCHAR},'%')
or ((c.cus_mobile LIKE CONCAT('%',#{record.searchValue,jdbcType=VARCHAR},'%')) or (c.erp_mobile LIKE CONCAT('%',#{record.searchValue,jdbcType=VARCHAR},'%')))
)
</if>
<if test="record.mandinsmileFlag == 1">
<![CDATA[and ((c.first_ins_to_cur_total_days >= 85 and c.first_ins_to_cur_total_days <= 95) or (c.ins_mileage_total>=2800))]]>
<![CDATA[and c.ins_mileage_total<=3200]]>
</if>
<if test="record.mileageStart != null">
<![CDATA[and c.curr_mileage >= #{record.mileageStart,jdbcType=DOUBLE}]]>
</if>
<if test="record.mileageEnd != null">
<![CDATA[and c.curr_mileage <= #{record.mileageEnd,jdbcType=DOUBLE}]]>
</if>
<if test="record.lastYearBackTwoMoreCount != null">
<![CDATA[and c.last_year_back_count >= #{record.lastYearBackTwoMoreCount,jdbcType=INTEGER}]]>
</if>
<if test="record.continuityUnbackCount != null">
<![CDATA[and c.continuity_unback_count = #{record.continuityUnbackCount,jdbcType=INTEGER}]]>
</if>
<if test="record.unBackMonthCountStart != null">
<![CDATA[and c.continuity_unback_count = #{record.unBackMonthCountStart,jdbcType=INTEGER}]]>
</if>
<if test="record.unBackMonthCountEnd != null">
<![CDATA[and c.continuity_unback_count <= #{record.unBackMonthCountEnd,jdbcType=INTEGER}]]>
</if>
<if test="record.backTotalStart != null">
<![CDATA[and c.back_numbers_total >= #{record.backTotalStart,jdbcType=INTEGER}]]>
</if>
<if test="record.backTotalEnd != null">
<![CDATA[and c.back_numbers_total <= #{record.backTotalEnd,jdbcType=INTEGER}]]>
</if>
<if test="record.lossTotalStart != null">
<![CDATA[and c.loss_numbers_total >= #{record.lossTotalStart,jdbcType=INTEGER}]]>
</if>
<if test="record.lossTotalEnd != null">
<![CDATA[and c.loss_numbers_total <= #{record.lossTotalEnd,jdbcType=INTEGER}]]>
</if>
<if test="record.distanceStart != null">
<![CDATA[and c.distance >= #{record.distanceStart,jdbcType=DOUBLE}]]>
</if>
<if test="record.distanceEnd != null">
<![CDATA[and c.distance <= #{record.distanceEnd,jdbcType=DOUBLE}]]>
</if>
<if test="record.buyDateStart != null">
<![CDATA[and DATE_FORMAT(c.vehicle_buy_time, '%Y-%m-%d %H:%i:%S') >= DATE_FORMAT(#{record.buyDateStart}, '%Y-%m-%d %H:%i:%S') ]]>
</if>
<if test="record.buyDateEnd != null">
<![CDATA[and DATE_FORMAT(c.vehicle_buy_time, '%Y-%m-%d %H:%i:%S') <= DATE_FORMAT(#{record.buyDateEnd}, '%Y-%m-%d %H:%i:%S') ]]>
</if>
</select>
<select id="list" resultMap="BaseResultBaseMap">
select
c.id,
c.sn,
c.stand_no,
c.plate_number,
c.cus_name,
c.cus_mobile,
c.erp_mobile,
c.vehicle_buy_time,
c.last_back_time,
c.curr_mileage,
c.distance,
c.last_time_mileage,
c.continuity_unback_count,
c.back_numbers_total,
c.last_year_back_count,
c.loss_numbers_total,
c.last_year_loss_Count,
c.ins_mileage_total,
c.first_ins_to_cur_total_days,
c.merchant_id
from dj_customer_portrait c
<if test="merchantId != null">
and c.merchant_id = #{merchantId}
</if>
where c.deleted_flag = 'N'
</select>
<select id="listByPage" resultMap="BaseResultBaseMap">
select
c.id,
c.sn,
c.stand_no,
c.plate_number,
c.cus_name,
c.cus_mobile,
c.erp_mobile,
c.vehicle_buy_time,
c.last_back_time,
c.curr_mileage,
c.distance,
c.last_time_mileage,
c.continuity_unback_count,
c.back_numbers_total,
c.last_year_back_count,
c.loss_numbers_total,
c.last_year_loss_Count,
c.ins_mileage_total,
c.first_ins_to_cur_total_days,
c.merchant_id
from dj_customer_portrait c
where c.deleted_flag = 'N'
<if test="merchantId != null">
and c.merchant_id = #{merchantId}
</if>
and c.id > #{id}
limit #{pageSize}
</select>
<!-- 批量增加 -->
<insert id="batchInserts" parameterType="java.util.List" >
insert into dj_customer_portrait (
sn,
stand_no,
cus_name,
cus_mobile,
erp_mobile,
vehicle_buy_time,
curr_mileage,
distance,
back_numbers_total,
loss_numbers_total,
last_back_time,
continuity_unback_count,
last_year_back_count,
last_time_mileage,
last_year_loss_Count,
plate_number,
first_ins_to_cur_total_days,
ins_mileage_total,
merchant_id,
merchant_name,
created_by,
created_date,
updated_by,
updated_date,
deleted_flag
)
VALUES
<foreach collection="list" item="record" index="index" separator="," >
(
#{record.sn, jdbcType=VARCHAR},
#{record.standNo, jdbcType=VARCHAR},
#{record.cusName,jdbcType=VARCHAR},
#{record.cusMobile,jdbcType=VARCHAR},
#{record.erpMobile,jdbcType=VARCHAR},
#{record.vehicleBuyTime,jdbcType=TIMESTAMP},
#{record.currMileage,jdbcType=DOUBLE},
#{record.distance,jdbcType=DOUBLE},
#{record.backNumbersTotal,jdbcType=INTEGER},
#{record.lossNumbersTotal,jdbcType=INTEGER},
#{record.lastBackTime,jdbcType=TIMESTAMP},
#{record.continuityUnbackCount,jdbcType=INTEGER},
#{record.lastYearBackCount,jdbcType=INTEGER},
#{record.lastTimeMileage,jdbcType=DOUBLE},
#{record.lastYearLossCount,jdbcType=INTEGER},
#{record.plateNumber, jdbcType=VARCHAR},
#{record.firstInsToCurTotalDays,jdbcType=INTEGER},
#{record.insMileageTotal,jdbcType=DOUBLE},
#{record.merchantId,jdbcType=INTEGER},
#{record.merchantName, jdbcType=VARCHAR},
#{record.createdBy, jdbcType=VARCHAR},
#{record.createdDate,jdbcType=TIMESTAMP},
#{record.updatedBy, jdbcType=VARCHAR},
#{record.updatedDate,jdbcType=TIMESTAMP},
#{record.deletedFlag, jdbcType=VARCHAR}
)
</foreach>
ON DUPLICATE KEY UPDATE
sn = VALUES(sn)
</insert>
<update id="batchUpdateVin" parameterType="java.util.List">
<foreach collection="list" item="record" index="index" open="" close="" separator=";">
update dj_customer_portrait
set
cus_name = #{record.cusName, jdbcType=VARCHAR},
cus_mobile = #{record.cusMobile, jdbcType=VARCHAR},
erp_mobile = #{record.erpMobile, jdbcType=VARCHAR},
vehicle_buy_time = #{record.vehicleBuyTime, jdbcType=TIMESTAMP},
curr_mileage = #{record.currMileage, jdbcType=VARCHAR},
distance = #{record.distance, jdbcType=DOUBLE},
back_numbers_total = #{record.backNumbersTotal, jdbcType=INTEGER},
loss_numbers_total = #{record.lossNumbersTotal, jdbcType=INTEGER},
last_back_time = #{record.lastBackTime, jdbcType=TIMESTAMP},
continuity_unback_count = #{record.continuityUnbackCount, jdbcType=INTEGER},
last_year_back_count = #{record.lastYearBackCount, jdbcType=INTEGER},
last_time_mileage = #{record.lastTimeMileage, jdbcType=DOUBLE},
last_year_loss_Count = #{record.lastYearLossCount, jdbcType=INTEGER},
plate_number = #{record.plateNumber, jdbcType=VARCHAR},
first_ins_to_cur_total_days = #{record.firstInsToCurTotalDays, jdbcType=INTEGER},
ins_mileage_total = #{record.idnum, jdbcType=DOUBLE},
merchant_id = #{record.merchantId, jdbcType=INTEGER},
merchant_name = #{record.merchantName, jdbcType=VARCHAR},
updated_by = #{record.updatedBy, jdbcType=VARCHAR},
updated_date = #{record.updatedDate, jdbcType=TIMESTAMP},
deleted_flag = #{record.deletedFlag, jdbcType=VARCHAR}
where stand_no = #{record.standNo}
</foreach>
</update>
<!-- 批量增加或更新 -->
<insert id="batchInsertOrUpdates" parameterType="java.util.List" >
insert into dj_customer_portrait (
sn,
stand_no,
cus_name,
cus_mobile,
erp_mobile,
vehicle_buy_time,
curr_mileage,
distance,
back_numbers_total,
loss_numbers_total,
last_back_time,
continuity_unback_count,
last_year_back_count,
last_time_mileage,
last_year_loss_Count,
plate_number,
first_ins_to_cur_total_days,
ins_mileage_total,
merchant_id,
merchant_name,
created_by,
created_date,
updated_by,
updated_date,
deleted_flag
)
VALUES
<foreach collection="list" item="record" index="index" separator="," >
(
#{record.sn, jdbcType=VARCHAR},
#{record.standNo, jdbcType=VARCHAR},
#{record.cusName,jdbcType=VARCHAR},
#{record.cusMobile,jdbcType=VARCHAR},
#{record.erpMobile,jdbcType=VARCHAR},
#{record.vehicleBuyTime,jdbcType=TIMESTAMP},
#{record.currMileage,jdbcType=DOUBLE},
#{record.distance,jdbcType=DOUBLE},
#{record.backNumbersTotal,jdbcType=INTEGER},
#{record.lossNumbersTotal,jdbcType=INTEGER},
#{record.lastBackTime,jdbcType=TIMESTAMP},
#{record.continuityUnbackCount,jdbcType=INTEGER},
#{record.lastYearBackCount,jdbcType=INTEGER},
#{record.lastTimeMileage,jdbcType=DOUBLE},
#{record.lastYearLossCount,jdbcType=INTEGER},
#{record.plateNumber, jdbcType=VARCHAR},
#{record.firstInsToCurTotalDays,jdbcType=INTEGER},
#{record.insMileageTotal,jdbcType=DOUBLE},
#{record.merchantId,jdbcType=INTEGER},
#{record.merchantName, jdbcType=VARCHAR},
#{record.createdBy, jdbcType=VARCHAR},
#{record.createdDate,jdbcType=TIMESTAMP},
#{record.updatedBy, jdbcType=VARCHAR},
#{record.updatedDate,jdbcType=TIMESTAMP},
#{record.deletedFlag, jdbcType=VARCHAR}
)
</foreach>
ON DUPLICATE KEY UPDATE
stand_no = IFNULL(VALUES(stand_no), stand_no),
cus_name = IFNULL(VALUES(cus_name), cus_name),
cus_mobile = IFNULL(VALUES(cus_mobile), cus_mobile),
erp_mobile = IFNULL(VALUES(erp_mobile), erp_mobile),
vehicle_buy_time = IFNULL(VALUES(vehicle_buy_time), vehicle_buy_time),
curr_mileage = IFNULL(VALUES(curr_mileage), curr_mileage),
distance = IFNULL(VALUES(distance), distance),
back_numbers_total = IFNULL(VALUES(back_numbers_total), back_numbers_total),
loss_numbers_total = IFNULL(VALUES(loss_numbers_total), loss_numbers_total),
last_back_time = IFNULL(VALUES(last_back_time), last_back_time),
continuity_unback_count = IFNULL(VALUES(continuity_unback_count), continuity_unback_count),
last_year_back_count = IFNULL(VALUES(last_year_back_count), last_year_back_count),
last_time_mileage = IFNULL(VALUES(last_time_mileage), last_time_mileage),
last_year_loss_Count = IFNULL(VALUES(last_year_loss_Count), last_year_loss_Count),
plate_number = IFNULL(VALUES(plate_number), plate_number),
first_ins_to_cur_total_days = IFNULL(VALUES(first_ins_to_cur_total_days), first_ins_to_cur_total_days),
ins_mileage_total = IFNULL(VALUES(ins_mileage_total), ins_mileage_total),
merchant_name = IFNULL(VALUES(merchant_name), merchant_name),
updated_date = IFNULL(VALUES(updated_date), updated_date)
</insert>
<update id="updateByVin" parameterType="cn.com.glsx.dj.customer.model.CustomerPortrait">
update dj_customer_portrait
set
cus_name = #{record.cusName, jdbcType=VARCHAR},
cus_mobile = #{record.cusMobile, jdbcType=VARCHAR},
erp_mobile = #{record.erpMobile, jdbcType=VARCHAR},
vehicle_buy_time = #{record.vehicleBuyTime, jdbcType=TIMESTAMP},
curr_mileage = #{record.currMileage, jdbcType=VARCHAR},
distance = #{record.distance, jdbcType=DOUBLE},
back_numbers_total = #{record.backNumbersTotal, jdbcType=INTEGER},
loss_numbers_total = #{record.lossNumbersTotal, jdbcType=INTEGER},
last_back_time = #{record.lastBackTime, jdbcType=TIMESTAMP},
continuity_unback_count = #{record.continuityUnbackCount, jdbcType=INTEGER},
last_year_back_count = #{record.lastYearBackCount, jdbcType=INTEGER},
last_time_mileage = #{record.lastTimeMileage, jdbcType=DOUBLE},
last_year_loss_Count = #{record.lastYearLossCount, jdbcType=INTEGER},
plate_number = #{record.plateNumber, jdbcType=VARCHAR},
first_ins_to_cur_total_days = #{record.firstInsToCurTotalDays, jdbcType=INTEGER},
ins_mileage_total = #{record.idnum, jdbcType=DOUBLE},
merchant_id = #{record.merchantId, jdbcType=INTEGER},
merchant_name = #{record.merchantName, jdbcType=VARCHAR},
updated_by = #{record.updatedBy, jdbcType=VARCHAR},
updated_date = #{record.updatedDate, jdbcType=TIMESTAMP},
deleted_flag = #{record.deletedFlag, jdbcType=VARCHAR}
where stand_no = #{record.standNo}
</update>
<delete id="deleteByStandNo" parameterType="java.lang.String">
delete from dj_customer_portrait where stand_no = #{standNo}
</delete>
<delete id="deleteAllNotExIns">
DELETE FROM dj_customer_portrait WHERE id IN(
SELECT * FROM(
SELECT p.id FROM dj_customer_portrait p,dj_insure_order dio
WHERE p.stand_no=dio.stand_no
AND dio.insurance_status NOT IN('1','11')
) a
)
</delete>
<select id="selectMileageListBySn" parameterType="java.lang.String" resultMap="BaseResultMileageVOMap">
SELECT
cm.total_mileage,
cm.current_dates,
cm.sn
FROM
dj_car_days_mileage cm
WHERE cm.sn=#{sn}
AND cm.deleted_flag='N'
</select>
<select id="selectAllMileageListByPage" resultMap="BaseResultMileageVOMap">
SELECT
cm.id,
cm.total_mileage,
cm.current_dates,
cm.sn
FROM
dj_car_days_mileage cm
WHERE cm.id > #{id}
limit #{pageSize}
</select>
<select id="selectAllLossList" resultMap="BaseResultLossVOMap">
select
stand_no,
enter_time,
last_year_loss,
number_of_shops
from dj_car_loss_warning
where deleted_flag = 'N'
<if test="merchantId != null">
and merchant_id = #{merchantId}
</if>
</select>
<select id="selectAllLossListByPage" resultMap="BaseResultLossVOMap">
select
id,
stand_no,
enter_time,
last_year_loss,
number_of_shops,
sn
from dj_car_loss_warning
where deleted_flag = 'N'
<if test="merchantId != null">
and merchant_id = #{merchantId}
</if>
and id > #{id}
limit #{pageSize}
</select>
<select id="selectAllShopList" resultMap="BaseResultShopVOMap" >
select
stand_no,
last_year_shops,
number_of_shops,
enter_time,
erp_mobile,
current_mileage
FROM dj_car_shop_warning
where deleted_flag = 'N' and is_new = 1
<if test="merchantId != null">
and merchant_id = #{merchantId}
</if>
</select>
<select id="selectAllShopListByPage" resultMap="BaseResultShopVOMap" >
select
id,
stand_no,
sn,
last_year_shops,
number_of_shops,
enter_time,
erp_mobile,
current_mileage
FROM dj_car_shop_warning
where deleted_flag = 'N'
<if test="merchantId != null">
and merchant_id = #{merchantId}
</if>
and is_new = 1
and id > #{id}
limit #{pageSize}
</select>
<select id="selectAllInsureList" resultMap="BaseResultInsureVOMap">
SELECT
o.id,
o.name,
o.phone,
o.stand_no,
o.merchant_id,
o.vehicle_id,
iv.plate_num as plate_number,
m.merchant_name,
o.created_by,
IF(o.sub_device_sn is null or o.sub_device_sn = "",d.imei,o.sub_device_sn) as sub_device_sn,
o.success_date,
o.card_type,
o.card_no,
2 as source
FROM dj_insure_order o LEFT JOIN dj_system_merchant m ON o.merchant_id=m.merchant_id
left join dj_insure_vehicle iv on o.vehicle_id = iv.id
left join (select * from dj_customer_device GROUP BY phone,merchant_id)d on d.phone = o.phone and d.merchant_id = o.merchant_id
WHERE 1=1
AND m.deleted_flag= 'N'
AND o.deleted_flag = 'N'
AND (o.insurance_status = '1' OR o.insurance_status = '7' OR o.insurance_status = '11')
<if test="merchantId != null">
and o.merchant_id = #{merchantId}
</if>
</select>
<select id="selectAllEquityList" resultMap="BaseResultInsureVOMap">
SELECT
o.id,
o.name,
o.phone,
o.stand_no,
o.merchant_id,
o.vehicle_id,
iv.plate_num as plate_number,
m.merchant_name,
o.created_by,
IF(o.sub_device_sn is null or o.sub_device_sn = "",d.imei,o.sub_device_sn) as sub_device_sn,
o.success_date,
o.card_type,
o.card_no,
3 as source
FROM dj_insure_equity o LEFT JOIN dj_system_merchant m ON o.merchant_id=m.merchant_id
left join dj_insure_vehicle iv on o.vehicle_id = iv.id
left join (select * from dj_customer_device GROUP BY phone,merchant_id)d on d.phone = o.phone and d.merchant_id = o.merchant_id
WHERE 1=1
AND m.deleted_flag= 'N'
AND o.deleted_flag = 'N'
AND (o.equity_status = '1' OR o.equity_status = '7')
<if test="merchantId != null">
and o.merchant_id = #{merchantId}
</if>
</select>
<select id="selectAllInsureListByPage" resultMap="BaseResultInsureVOMap">
SELECT
o.id,
o.name,
o.phone,
o.stand_no,
o.merchant_id,
o.vehicle_id,
iv.plate_num as plate_number,
m.merchant_name,
o.created_by,
IF(o.sub_device_sn is null or o.sub_device_sn = "",d.imei,o.sub_device_sn) as sub_device_sn,
o.success_date,
o.card_type,
o.card_no,
2 as source
FROM dj_insure_order o LEFT JOIN dj_system_merchant m ON o.merchant_id=m.merchant_id
left join dj_insure_vehicle iv on o.vehicle_id = iv.id
left join (select * from dj_customer_device GROUP BY phone,merchant_id)d on d.phone = o.phone and d.merchant_id = o.merchant_id
WHERE 1=1
AND m.deleted_flag= 'N'
AND o.deleted_flag = 'N'
AND (o.insurance_status = '1' OR o.insurance_status = '7' OR o.insurance_status = '11')
AND o.id > #{id}
<if test="merchantId != null">
and o.merchant_id = #{merchantId}
</if>
order by o.id
limit #{pageSize}
</select>
<select id="selectAllEquityListByPage" resultMap="BaseResultInsureVOMap">
SELECT
o.id,
o.name,
o.phone,
o.stand_no,
o.merchant_id,
o.vehicle_id,
iv.plate_num as plate_number,
m.merchant_name,
o.created_by,
IF(o.sub_device_sn is null or o.sub_device_sn = "",d.imei,o.sub_device_sn) as sub_device_sn,
o.success_date,
o.card_type,
o.card_no,
3 as source
FROM dj_insure_equity o LEFT JOIN dj_system_merchant m ON o.merchant_id=m.merchant_id
left join dj_insure_vehicle iv on o.vehicle_id = iv.id
left join (select * from dj_customer_device GROUP BY phone,merchant_id)d on d.phone = o.phone and d.merchant_id = o.merchant_id
WHERE 1=1
AND m.deleted_flag= 'N'
AND o.deleted_flag = 'N'
AND (o.equity_status = '1' OR o.equity_status = '7')
<if test="merchantId != null">
and o.merchant_id = #{merchantId}
</if>
AND o.id > #{id}
order by o.id
limit #{pageSize}
</select>
<select id="selectAllInsureDevice" resultMap="BaseResultInsureVOMap">
SELECT
o.sub_device_sn,
o.merchant_id,
o.stand_no,
o.success_date,
(SELECT v.vehicle_childs_brand_id FROM dj_insure_vehicle v WHERE v.id=o.vehicle_id LIMIT 0,1) AS name,
(SELECT d.device_type FROM dj_insure_device d WHERE o.sub_device_sn=d.sn AND o.vehicle_id=d.vehicle_id LIMIT 0,1) AS phone,
(SELECT m.merchant_name FROM dj_system_merchant m WHERE o.merchant_id=m.merchant_id) AS merchant_name
FROM dj_insure_order o where o.insurance_status = 1
</select>
<select id="selectAllInsureDeviceByPage" resultMap="BaseResultInsureVOMap">
SELECT
o.sub_device_sn,
o.merchant_id,
o.stand_no,
o.success_date,
(SELECT v.vehicle_childs_brand_id FROM dj_insure_vehicle v WHERE v.id=o.vehicle_id LIMIT 0,1) AS name,
(SELECT d.device_type FROM dj_insure_device d WHERE o.sub_device_sn=d.sn AND o.vehicle_id=d.vehicle_id LIMIT 0,1) AS phone,
(SELECT m.merchant_name FROM dj_system_merchant m WHERE o.merchant_id=m.merchant_id) AS merchant_name
FROM dj_insure_order o where o.insurance_status = 1
and o.id > #{id}
limit #{pageSize}
</select>
<update id="updateInsureMileage" parameterType="java.lang.Integer">
UPDATE dj_insure_order o INNER JOIN dj_car_days_mileage m ON o.sub_device_sn=m.sn
SET o.mileage=m.total_mileage
WHERE o.insurance_status=#{status, jdbcType=INTEGER}
AND o.deleted_flag='N'
AND m.total_mileage >= 0
</update>
<select id="getCountMileage" parameterType="cn.com.glsx.dj.customer.vo.CustomerCountVO" resultType="java.lang.Integer">
SELECT COUNT(*)
FROM dj_customer_portrait a
WHERE a.deleted_flag = 'N'
<if test="merchantIds != null and merchantIds.size > 0 ">
and a.merchant_id in
<foreach item="merchantId" index="index" collection="merchantIds" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
<if test="minTotalMileage != null">
and IFNULL(a.curr_mileage,0) >= #{minTotalMileage}
</if>
<if test="maxTotalMileage != null">
<![CDATA[and IFNULL(a.curr_mileage,0) < #{maxTotalMileage}]]>
</if>
<if test="minLastYearBackCount != null">
<![CDATA[and a.last_year_back_count >= #{minLastYearBackCount}]]>
</if>
<if test="maxLastYearBackCount != null">
<![CDATA[and a.last_year_back_count < #{maxLastYearBackCount}]]>
</if>
<if test="lastYearBackCount != null">
and a.last_year_back_count = #{lastYearBackCount}
</if>
<if test="minMileage != null">
and IFNULL(a.last_time_mileage,0) >= #{minMileage}
</if>
<if test="maxMileage != null">
<![CDATA[and IFNULL(a.last_time_mileage,0) < #{maxMileage}]]>
</if>
<if test="backNumbersTotal != null">
and a.back_numbers_total = #{backNumbersTotal}
</if>
<if test = "unBackCurrentMonth != null">
and a.continuity_unback_count = #{unBackCurrentMonth}
</if>
<if test="unBackMaxMonth != null">
<![CDATA[and a.continuity_unback_count < #{unBackMaxMonth}]]>
</if>
<if test="unBackMinMonth != null">
<![CDATA[and a.continuity_unback_count >= #{unBackMinMonth}]]>
</if>
<if test="mandinsmileFlag !=null and mandinsmileFlag == 1">
<![CDATA[and ((a.first_ins_to_cur_total_days >= 85 and a.first_ins_to_cur_total_days <= 95) or (a.ins_mileage_total>=2800))]]>
<![CDATA[and a.ins_mileage_total<=3200]]>
</if>
<if test="distanceStart != null">
<![CDATA[and IFNULL(a.distance,0) >= #{distanceStart,jdbcType=DOUBLE}]]>
</if>
<if test="distanceEnd != null">
<![CDATA[and IFNULL(a.distance,0) < #{distanceEnd,jdbcType=DOUBLE}]]>
</if>
</select>
<select id="getCustomeListNotHasOrder" resultMap="BaseResultInsureVOMap">
SELECT
d.name as name,
d.phone as phone,
d.stand_no as stand_no,
d.plate_num as plate_number,
d.merchant_id as merchant_id,
d.merchant_name as merchant_name,
d.created_by as created_by,
d.imei as sub_device_sn,
d.created_date as success_date,
d.gender as gender,
1 as source
FROM dj_customer_device d
where
d.deleted_flag = 'N'
and d.phone is not NULL
<if test="merchantId != null">
and d.merchant_id = #{merchantId}
</if>
</select>
<select id="selectRepeatMerchantIdAndSn" resultMap="BaseResultMap">
SELECT
p.MERCHANT_ID,
p.sn
FROM dj_customer_portrait p
where
p.deleted_flag = 'N'
GROUP BY p.MERCHANT_ID,p.sn having count(1)>1
</select>
</mapper>