puzhibing
2023-06-30 f58cca364b731eac2d60a440ffaa804be3cd43fd
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
<?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="com.stylefeng.guns.modular.system.dao.TCompanyMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.TCompany">
        <id column="id" property="id" />
        <result column="isSpe" property="isSpe" />
        <result column="isTaxi" property="isTaxi" />
        <result column="isCross" property="isCross" />
        <result column="isCrossLogistics" property="isCrossLogistics" />
        <result column="isSameLogistics" property="isSameLogistics" />
        <result column="isCharter" property="isCharter" />
        <result column="isSpeFixedOrProportional" property="isSpeFixedOrProportional" />
        <result column="isTaxiFixedOrProportional" property="isTaxiFixedOrProportional" />
        <result column="isCrossLogisticsFixedOrProportional" property="isCrossLogisticsFixedOrProportional" />
        <result column="isSameLogisticsFixedOrProportional" property="isSameLogisticsFixedOrProportional" />
        <result column="speMoney" property="speMoney" />
        <result column="taxiMoney" property="taxiMoney" />
        <result column="crossLogisticsMoney" property="crossLogisticsMoney" />
        <result column="sameLogisticsMoney" property="sameLogisticsMoney" />
        <result column="isNeedFerry" property="isNeedFerry" />
        <result column="name" property="name" />
        <result column="type" property="type" />
        <result column="superiorId" property="superiorId" />
        <result column="principalName" property="principalName" />
        <result column="principalPhone" property="principalPhone" />
        <result column="adminName" property="adminName" />
        <result column="adminPhone" property="adminPhone" />
        <result column="urgentPhoen" property="urgentPhoen" />
        <result column="setupTime" property="setupTime" />
        <result column="identifier" property="identifier" />
        <result column="addressCode" property="addressCode" />
        <result column="businessScope" property="businessScope" />
        <result column="contactAddress" property="contactAddress" />
        <result column="documentAddress" property="documentAddress" />
        <result column="economicType" property="economicType" />
        <result column="regCapital" property="regCapital" />
        <result column="legalName" property="legalName" />
        <result column="legalId" property="legalId" />
        <result column="legalPhone" property="legalPhone" />
        <result column="legalPhotoUrl" property="legalPhotoUrl" />
        <result column="licensingAgency" property="licensingAgency" />
        <result column="licenseTime" property="licenseTime" />
        <result column="licenseStartTime" property="licenseStartTime" />
        <result column="licenseEndTime" property="licenseEndTime" />
        <result column="licenseNumber" property="licenseNumber" />
        <result column="carNum" property="carNum" />
        <result column="driverNum" property="driverNum" />
        <result column="mac" property="mac" />
        <result column="state" property="state" />
        <result column="flag" property="flag" />
        <result column="upload" property="upload" />
        <result column="insertTime" property="insertTime" />
        <result column="detailAddress" property="detailAddress" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, isSpe, isTaxi, isCross, isCrossLogistics, isSameLogistics, isCharter, isSpeFixedOrProportional, isTaxiFixedOrProportional, isCrossLogisticsFixedOrProportional, isSameLogisticsFixedOrProportional, speMoney, taxiMoney, crossLogisticsMoney, sameLogisticsMoney, isNeedFerry, name, type, superiorId, principalName, principalPhone, adminName, adminPhone, urgentPhoen, setupTime, identifier, addressCode, businessScope, contactAddress, documentAddress, economicType, regCapital, legalName, legalId, legalPhone, legalPhotoUrl, licensingAgency, licenseTime, licenseStartTime, licenseEndTime, licenseNumber, carNum, driverNum, mac, state, flag, upload, insertTime, detailAddress
    </sql>
 
 
    <!--根据条件查询分公司列表-->
    <select id="getCompanyList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT * FROM (SELECT ui.account,IFNULL(ci.num,0) as franchiseeNum,IFNULL(ca.num,0) as carNumber,IFNULL(di.num,0) as driverNumber,
        CONCAT(case when cc.isSpe = 1 then '专车,' else '' end,
        case when cc.isTaxi = 1 then '出租车,' else '' end,
        case when cc.isCross = 1 then '跨城出行,' else '' end,
        case when cc.isCrossLogistics = 1 then '跨城小件物流,' else '' end,
        case when cc.isSameLogistics = 1 then '同城小件物流,' else '' end,
        case when cc.isCharter = 1 then '包车,' else '' end) as serverStr,
        cc.* FROM t_company as cc
        LEFT JOIN (SELECT * FROM sys_user where roleType = 2) as ui on ui.objectId = cc.id
        LEFT JOIN (SELECT COUNT(id) as num,superiorId FROM t_company where type = 3 and flag != 3 GROUP BY superiorId) as ci on ci.superiorId = cc.id
        LEFT JOIN (SELECT COUNT(id) as num,companyId FROM t_car where state = 1 GROUP BY companyId) as ca on ca.companyId = cc.id
        LEFT JOIN (SELECT COUNT(id) as num,companyId FROM t_driver where flag != 3 GROUP BY companyId) as di on di.companyId = cc.id
        ) as o
        <where>
            o.type = 2 and o.flag != 3
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                AND (o.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
            </if>
            <if test="name != null and name != ''">
                and o.name  LIKE CONCAT('%',#{name},'%')
            </if>
            <if test="principalName != null and principalName != ''">
                and o.principalName  LIKE CONCAT('%',#{principalName},'%')
            </if>
            <if test="principalPhone != null and principalPhone != ''">
                and o.principalPhone  LIKE CONCAT('%',#{principalPhone},'%')
            </if>
            <if test="adminName != null and adminName != ''">
                and o.adminName  LIKE CONCAT('%',#{adminName},'%')
            </if>
            <if test="adminPhone != null and adminPhone != ''">
                and o.adminPhone  LIKE CONCAT('%',#{adminPhone},'%')
            </if>
            <if test="serviceStr != null and serviceStr != ''">
                and o.serverStr  LIKE CONCAT('%',#{serviceStr},'%')
            </if>
            <if test="state != null and state != '' and state == 1">
                and o.state  = 1
            </if>
            <if test="state != null and state != '' and state == 2">
                and o.state  = 0
            </if>
        </where>
        order by o.id desc
    </select>
 
    <!--根据公司ID获取公司经营区域-->
    <select id="getCompanyScopeById" resultType="map">
        SELECT CONCAT(case when r1.`name` is not null then r1.`name` else '' end,
        case when r2.`name` is not null then r2.`name` else '' end,
        case when r3.`name` is not null then r3.`name` else '' end) as value,cc.* FROM t_company_city as cc
        LEFT JOIN t_region as r1 on r1.code = cc.provinceCode
        LEFT JOIN t_region as r2 on r2.code = cc.cityCode
        LEFT JOIN t_region as r3 on r3.code = cc.areaCode
        where cc.companyId = #{id} and cc.state = 1 order by id asc
    </select>
 
    <!--根据条件查询加盟商列表-->
    <select id="getFranchiseeList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT * FROM (SELECT ui.account,ci.`name` as companyName,IFNULL(ca.num,0) as carNumber,IFNULL(di.num,0) as driverNumber,
        CONCAT(case when cc.isSpe = 1 then '专车,' else '' end,
        case when cc.isTaxi = 1 then '出租车,' else '' end,
        case when cc.isCross = 1 then '跨城出行,' else '' end,
        case when cc.isCrossLogistics = 1 then '跨城小件物流,' else '' end,
        case when cc.isSameLogistics = 1 then '同城小件物流,' else '' end,
        case when cc.isCharter = 1 then '包车,' else '' end) as serverStr,
        cc.* FROM t_company as cc
        LEFT JOIN (SELECT * FROM sys_user where roleType = 3) as ui on ui.objectId = cc.id
        LEFT JOIN (select * from t_company where type = 2 and flag != 3) as ci on ci.id = cc.superiorId
        LEFT JOIN (SELECT COUNT(id) as num,franchiseeId FROM t_car where state = 1 GROUP BY franchiseeId) as ca on ca.franchiseeId = cc.id
        LEFT JOIN (SELECT COUNT(id) as num,franchiseeId FROM t_driver where flag != 3 GROUP BY franchiseeId) as di on di.franchiseeId = cc.id) as o
        <where>
            o.type = 3 and o.flag != 3
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                AND (o.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
            </if>
            <if test="name != null and name != ''">
                and o.name  LIKE CONCAT('%',#{name},'%')
            </if>
            <if test="account != null and account != ''">
                and o.account  LIKE CONCAT('%',#{account},'%')
            </if>
            <if test="principalName != null and principalName != ''">
                and o.principalName  LIKE CONCAT('%',#{principalName},'%')
            </if>
            <if test="principalPhone != null and principalPhone != ''">
                and o.principalPhone  LIKE CONCAT('%',#{principalPhone},'%')
            </if>
            <if test="serviceStr != null and serviceStr != ''">
                and o.serverStr  LIKE CONCAT('%',#{serviceStr},'%')
            </if>
            <if test="state != null and state != '' and state == 1">
                and o.state  = 1
            </if>
            <if test="state != null and state != '' and state == 2">
                and o.state  = 0
            </if>
            <if test="roleType != null and roleType != '' and roleType == 2">
                and o.superiorId = #{nowUserId}
            </if>
        </where>
        order by o.id desc
    </select>
 
 
    <select id="queryOperationalData" resultType="map">
 
        select
        *,
        ROUND(if(orderNum != 0, cancelNum / orderNum, 0) * 100, 2) as cancelProportion,
        (onlinePay + offlinePay) as total,
        ROUND((onlinePay / (onlinePay + offlinePay)) * 100, 2) as payProportion
        from (
            select
            aa.time,
            sum(aa.register) as register,
            sum(aa.`online`) as `online`,
            sum(aa.orderNum) as orderNum,
            sum(aa.cancelNum) as cancelNum,
            sum(aa.onlinePay) as onlinePay,
            sum(aa.offlinePay) as offlinePay,
            sum(aa.money) as money,
            sum(aa.complaint) as complaint
            from (
            select DATE_FORMAT(insertTime, '%Y-%m-%d') as time, count(id) as register, 0 as `online`, 0 as orderNum, 0 as cancelNum, 0 as onlinePay, 0 as offlinePay, 0 as money, 0 as complaint
            from t_user
            where flag != 3 and state = 1
            <if test="null != companyId">
                and companyId = #{companyId}
            </if>
            <if test="null != start and '' != start and null != end and '' != end">
                and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{start} and #{end}
            </if>
            group by DATE_FORMAT(insertTime, '%Y-%m-%d')
            union all
            select DATE_FORMAT(a.insertTime, '%Y-%m-%d') as time, 0, count(a.id) as `online`, 0 as orderNum, 0 as cancelNum, 0 as onlinePay, 0 as offlinePay, 0 as money, 0 as complaint
            from t_driver_online a
            left join t_driver b on (a.driverId = b.id)
            where 1 = 1
            <if test="null != companyId">
                and if(b.franchiseeId is null or b.franchiseeId = 0, b.companyId = #{companyId}, b.franchiseeId = #{companyId})
            </if>
            <if test="null != start and '' != start and null != end and '' != end">
                and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
            </if>
            group by DATE_FORMAT(a.insertTime, '%Y-%m-%d')
            union all
            <if test="1 == type">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, count(id), 0, 0, 0, 0, 0 from t_order_private_car where isDelete = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="2 == type">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, count(id), 0, 0, 0, 0, 0 from t_order_taxi where isDelete = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="3 == type">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, count(id), 0, 0, 0, 0, 0 from t_order_cross_city where isDelete = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="4 == type">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, count(id), 0, 0, 0, 0, 0 from t_order_logistics where isDelete = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 1">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, count(id), 0, 0, 0, 0 from t_order_private_car where isDelete = 1 and state in (10, 12)
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 2">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, count(id), 0, 0, 0, 0 from t_order_taxi where isDelete = 1 and state in (10, 12)
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 3">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, count(id), 0, 0, 0, 0 from t_order_cross_city where isDelete = 1 and state in (10, 12)
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 4">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, count(id), 0, 0, 0, 0 from t_order_logistics where isDelete = 1 and state in (10, 12)
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 1">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, count(id), 0, sum(payMoney), 0 from t_order_private_car where isDelete = 1 and payManner = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 2">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, count(id), 0, sum(payMoney), 0 from t_order_taxi where isDelete = 1 and payManner = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 3">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, count(id), 0, sum(payMoney), 0 from t_order_cross_city where isDelete = 1 and payManner = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 4">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, count(id), 0, sum(payMoney), 0 from t_order_logistics where isDelete = 1 and payManner = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 1">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, 0, count(id), 0, 0 from t_order_private_car where isDelete = 1 and payManner = 2
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 2">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, 0, count(id), 0, 0 from t_order_taxi where isDelete = 1 and payManner = 2
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 3">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, 0, count(id), 0, 0 from t_order_cross_city where isDelete = 1 and payManner = 2
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 4">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, 0, count(id), 0, 0 from t_order_logistics where isDelete = 1 and payManner = 2
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            select DATE_FORMAT(a.insert_time, '%Y-%m-%d'), 0, 0, 0, 0, 0, 0, 0, count(a.id) from t_complaint a
            left join t_driver b on (a.driverId = b.id)
            where 1 = 1
            <if test="null != companyId">
                and if(b.franchiseeId is null or b.franchiseeId = 0, b.companyId = #{companyId}, b.franchiseeId = #{companyId})
            </if>
            <if test="null != start and '' != start and null != end and '' != end">
                and DATE_FORMAT(a.insert_time, '%Y-%m-%d') between #{start} and #{end}
            </if>
            group by DATE_FORMAT(a.insert_time, '%Y-%m-%d')
            ) as aa group by aa.time
        ) as da order by `time` desc
        <if test="null != offset and null != limit">
            limit #{offset}, #{limit}
        </if>
    </select>
 
 
 
    <select id="queryOperationalDataCount" resultType="int">
 
        select
        count(`time`)
        from (
            select
            aa.time,
            sum(aa.register) as register,
            sum(aa.`online`) as `online`,
            sum(aa.orderNum) as orderNum,
            sum(aa.cancelNum) as cancelNum,
            sum(aa.onlinePay) as onlinePay,
            sum(aa.offlinePay) as offlinePay,
            sum(aa.money) as money,
            sum(aa.complaint) as complaint
            from (
            select DATE_FORMAT(insertTime, '%Y-%m-%d') as time, count(id) as register, 0 as `online`, 0 as orderNum, 0 as cancelNum, 0 as onlinePay, 0 as offlinePay, 0 as money, 0 as complaint
            from t_user
            where flag != 3 and state = 1
            <if test="null != companyId">
                and companyId = #{companyId}
            </if>
            <if test="null != start and '' != start and null != end and '' != end">
                and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{start} and #{end}
            </if>
            group by DATE_FORMAT(insertTime, '%Y-%m-%d')
            union all
            select DATE_FORMAT(a.insertTime, '%Y-%m-%d') as time, 0, count(a.id) as `online`, 0 as orderNum, 0 as cancelNum, 0 as onlinePay, 0 as offlinePay, 0 as money, 0 as complaint from t_driver_online a
            left join t_driver b on (a.driverId = b.id)
            where 1 = 1
            <if test="null != companyId">
                and if(b.franchiseeId is null or b.franchiseeId = 0, b.companyId = #{companyId}, b.franchiseeId = #{companyId})
            </if>
            <if test="null != start and '' != start and null != end and '' != end">
                and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
            </if>
            group by DATE_FORMAT(a.insertTime, '%Y-%m-%d')
            union all
            <if test="1 == type">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, count(id), 0, 0, 0, 0, 0 from t_order_private_car where isDelete = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="2 == type">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, count(id), 0, 0, 0, 0, 0 from t_order_taxi where isDelete = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="3 == type">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, count(id), 0, 0, 0, 0, 0 from t_order_cross_city where isDelete = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="4 == type">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, count(id), 0, 0, 0, 0, 0 from t_order_logistics where isDelete = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 1">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, count(id), 0, 0, 0, 0 from t_order_private_car where isDelete = 1 and state in (10, 12)
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 2">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, count(id), 0, 0, 0, 0 from t_order_taxi where isDelete = 1 and state in (10, 12)
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 3">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, count(id), 0, 0, 0, 0 from t_order_cross_city where isDelete = 1 and state in (10, 12)
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 4">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, count(id), 0, 0, 0, 0 from t_order_logistics where isDelete = 1 and state in (10, 12)
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 1">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, count(id), 0, sum(payMoney), 0 from t_order_private_car where isDelete = 1 and payManner = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 2">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, count(id), 0, sum(payMoney), 0 from t_order_taxi where isDelete = 1 and payManner = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 3">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, count(id), 0, sum(payMoney), 0 from t_order_cross_city where isDelete = 1 and payManner = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 4">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, count(id), 0, sum(payMoney), 0 from t_order_logistics where isDelete = 1 and payManner = 1
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 1">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, 0, count(id), 0, 0 from t_order_private_car where isDelete = 1 and payManner = 2
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 2">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, 0, count(id), 0, 0 from t_order_taxi where isDelete = 1 and payManner = 2
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 3">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, 0, count(id), 0, 0 from t_order_cross_city where isDelete = 1 and payManner = 2
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            <if test="type == 4">
                select DATE_FORMAT(travelTime, '%Y-%m-%d'), 0, 0, 0, 0, 0, count(id), 0, 0 from t_order_logistics where isDelete = 1 and payManner = 2
                <if test="null != companyId">
                    and companyId = #{companyId}
                </if>
                <if test="null != start and '' != start and null != end and '' != end">
                    and DATE_FORMAT(travelTime, '%Y-%m-%d') between #{start} and #{end}
                </if>
                group by DATE_FORMAT(travelTime, '%Y-%m-%d')
                union all
            </if>
            select DATE_FORMAT(a.insert_time, '%Y-%m-%d'), 0, 0, 0, 0, 0, 0, 0, count(a.id) from t_complaint a
            left join t_driver b on (a.driverId = b.id)
            where 1 = 1
            <if test="null != companyId">
                and if(b.franchiseeId is null or b.franchiseeId = 0, b.companyId = #{companyId}, b.franchiseeId = #{companyId})
            </if>
            <if test="null != start and '' != start and null != end and '' != end">
                and DATE_FORMAT(a.insert_time, '%Y-%m-%d') between #{start} and #{end}
            </if>
            group by DATE_FORMAT(a.insert_time, '%Y-%m-%d')
            ) as aa group by aa.time
        ) as da order by `time` desc
    </select>
</mapper>