mitao
2024-09-04 ecca9ab70a9a87bcb60977c92fbf81053b8fc1bb
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
<?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.ruoyi.order.mapper.OrderMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.order.entity.Order">
        <id column="id" property="id"/>
        <result column="site_id" property="siteId"/>
        <result column="accept_time" property="acceptTime"/>
        <result column="order_number" property="orderNumber"/>
        <result column="order_money" property="orderMoney"/>
        <result column="site_name" property="siteName"/>
        <result column="serve_id" property="serveId"/>
        <result column="print_count" property="printCount"/>
        <result column="serve_name" property="serveName"/>
        <result column="serve_price" property="servePrice"/>
        <result column="reservation_name" property="reservationName"/>
        <result column="reservation_phone" property="reservationPhone"/>
        <result column="reservation_address" property="reservationAddress"/>
        <result column="time" property="time"/>
        <result column="server_id" property="serverId"/>
        <result column="server_name" property="serverName"/>
        <result column="server_phone" property="serverPhone"/>
        <result column="reservation_remark" property="reservationRemark"/>
        <result column="state" property="state"/>
        <result column="createBy" property="createBy"/>
        <result column="updateBy" property="updateBy"/>
        <result column="createTime" property="createTime"/>
        <result column="updateTime" property="updateTime"/>
        <result column="is_delete" property="isDelete"/>
        <result column="fake" property="fake"/>
        <result column="apply_reason" property="applyReason"/>
    </resultMap>
 
 
    <select id="orderCountByYear" resultType="com.ruoyi.order.vo.OrderQueryVO">
        SELECT DATE_FORMAT(createTime, '%Y-%m') AS dateTime,
               COUNT(*)                         AS number,
               sum(IFNULL(order_money, 0))      as totalPrice,
        COUNT(CASE WHEN fake = 1 THEN 1 END) AS fakeCount
        FROM t_order
        <where>
            is_delete = 0
              and YEAR(createTime) = YEAR(NOW())
            <if test="cityList != null and cityList.size() != 0">
                and city_code in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="orderState != null">
                and state = #{orderState}
            </if>
        </where>
        GROUP BY dateTime
        order by dateTime
    </select>
 
    <select id="orderCountByWeek" resultType="com.ruoyi.order.vo.OrderQueryVO">
        SELECT DATE_FORMAT(createTime, '%Y-%m-%d') AS dateTime,
               COUNT(*)                            AS number,
               sum(IFNULL(order_money, 0))         as totalPrice,
        COUNT(CASE WHEN fake = 1 THEN 1 END) AS fakeCount
        FROM t_order
        <where>
            is_delete = 0
              and YEARWEEK(DATE_FORMAT(createTime, '%Y-%m-%d'), 1) = YEARWEEK(NOW(), 1)
            <if test="cityList != null and cityList.size() != 0">
                and city_code in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="orderState != null">
                and state = #{orderState}
            </if>
        </where>
        GROUP BY dateTime
        order by dateTime
    </select>
 
    <select id="orderCountByMonth" resultType="com.ruoyi.order.vo.OrderQueryVO">
        SELECT DATE_FORMAT(createTime, '%Y-%m-%d') AS dateTime,
               COUNT(*)                            AS number,
               sum(IFNULL(order_money, 0))         as totalPrice,
        COUNT(CASE WHEN fake = 1 THEN 1 END) AS fakeCount
        FROM t_order
        <where>
            is_delete = 0
              and MONTH(createTime) = MONTH(NOW())
              AND YEAR(createTime) = YEAR(NOW())
            <if test="cityList != null and cityList.size() != 0">
                and city_code in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="orderState != null">
                and state = #{orderState}
            </if>
        </where>
        GROUP BY dateTime
        order by dateTime
    </select>
 
    <select id="orderCountByToday" resultType="com.ruoyi.order.vo.OrderQueryVO">
        SELECT DATE_FORMAT(createTime, '%Y-%m-%d') AS dateTime,
               COUNT(*)                            AS number,
               sum(IFNULL(order_money, 0))         as totalPrice,
        COUNT(CASE WHEN fake = 1 THEN 1 END) AS fakeCount
        FROM t_order
        <where>
            is_delete = 0
              and DATE(createTime) = CURDATE()
            <if test="cityList != null and cityList.size() != 0">
                and city_code in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="orderState != null">
                and state = #{orderState}
            </if>
        </where>
        GROUP BY dateTime
        order by dateTime
    </select>
 
    <select id="totalMoneyByQuarter" resultType="java.math.BigDecimal">
        select sum(order_money)
        from t_order
        <where>
            is_delete = 0
              and state = 3
            <if test="cityList != null and cityList.size() != 0">
                and city_code in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
        #{id}
                </foreach>
            </if>
            <if test="start != null and start != ''">
                and createTime <![CDATA[ >= ]]> #{start}
            </if>
            <if test="end != null and end != ''">
                and createTime <![CDATA[ <= ]]> #{end}
            </if>
        </where>
    </select>
 
    <select id="totalMoneyByYear" resultType="java.math.BigDecimal">
        SELECT sum(order_money) as totalPrice
        FROM t_order
        where YEAR(createTime) = YEAR(NOW())
          and is_delete = 0
          and state = 3
        <if test="cityList != null and cityList.size() != 0">
            and city_code in
            <foreach collection="cityList" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>
 
    <select id="totalMoneyByMonth" resultType="java.math.BigDecimal">
        SELECT sum(order_money) as totalPrice
        FROM t_order
        where MONTH(createTime) = MONTH(NOW())
          AND YEAR(createTime) = YEAR(NOW())
          and is_delete = 0
          and state = 3
        <if test="cityList != null and cityList.size() != 0">
            and city_code in
            <foreach collection="cityList" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>
 
    <select id="orderCount" resultType="com.ruoyi.order.vo.OrderCountVO">
        SELECT o.server_id                                        as workerId,
               SUM(CASE WHEN o.state in (1, 2) THEN 1 ELSE 0 END) AS toBeCompletedNumber,
               SUM(CASE WHEN o.state = 3 THEN 1 ELSE 0 END)       AS completedNumber,
               SUM(CASE WHEN o.state = 6 THEN 1 ELSE 0 END)       AS reInvestment
        FROM t_order o
        WHERE o.is_delete = 0 and  DATE(o.time) = DATE(NOW())
          and o.server_id is not null
        <if test="cityList != null and cityList.size() != 0">
            and o.city_code in
            <foreach collection="cityList" item="city" open="(" separator="," close=")">
                #{city}
            </foreach>
        </if>
        <if test="phone != null and phone != ''">
            and o.server_phone like concat('%', #{phone}, '%')
        </if>
        <if test="name != null and name != ''">
            and o.server_name like concat('%', #{name}, '%')
        </if>
        GROUP BY o.server_id
    </select>
 
    <select id="queryPage" resultMap="BaseResultMap">
        select *
        from t_order o
        <where>
            o.is_delete = 0
            <if test="data.fake != null ">
                and o.fake = #{data.fake}
            </if>
            <if test="data.address != null and data.address != ''">
                and o.reservation_address like concat('%', #{data.address}, '%')
            </if>
            <if test="data.orderNumber != null and data.orderNumber != ''">
                and o.order_number like concat('%', #{data.orderNumber}, '%')
            </if>
            <if test="data.cityName != null and data.cityName != ''">
                and o.city like concat('%', #{data.cityName}, '%')
            </if>
            <if test="data.cityList != null and data.cityList.size() != 0">
                and o.city_code in
                <foreach collection="data.cityList" item="c" open="(" separator="," close=")">
                    #{c}
                </foreach>
            </if>
            <if test="data.servIds != null and data.servIds.size() != 0">
                and o.serve_id in
                <foreach collection="data.servIds" item="c" open="(" separator="," close=")">
                    #{c}
                </foreach>
            </if>
 
            <if test="data.reservationName != null and data.reservationName != ''">
                and o.reservation_name like concat('%', #{data.reservationName}, '%')
            </if>
            <if test="data.reservationPhone != null and data.reservationPhone != ''">
                and o.reservation_phone like concat('%', #{data.reservationPhone}, '%')
            </if>
            <if test="data.state != null">
                and o.state = #{data.state}
            </if>
            <if test="data.type != null">
                and o.type = #{data.type}
            </if>
            <if test="data.workerName != null and data.workerName != ''">
                and o.server_name like concat('%', #{data.workerName}, '%')
            </if>
            <if test="data.workerPhone != null and data.workerPhone != ''">
                and o.server_phone like concat('%', #{data.workerPhone}, '%')
            </if>
            <if test="data.serveName != null and data.serveName != ''">
                and o.site_name like concat('%', #{data.serveName}, '%')
            </if>
            <if test="data.orderTimeStart != null and data.orderTimeStart != ''">
                and DATE(o.createTime) <![CDATA[ >= ]]> #{data.orderTimeStart}
            </if>
            <if test="data.orderTimeEnd != null and data.orderTimeEnd != ''">
                and DATE(o.createTime) <![CDATA[ <= ]]> #{data.orderTimeEnd}
            </if>
            <if test="data.startTime != null and data.startTime != ''">
                and STR_TO_DATE(SUBSTRING_INDEX(time, ' - ', 1), '%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{data.startTime}
            </if>
            <if test="data.endTime != null and data.endTime != ''">
                AND STR_TO_DATE(SUBSTRING_INDEX(time, ' - ', -1), '%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{data.endTime}
            </if>
            <if test="data.completeTimeStart != null and data.completeTimeStart != ''">
                and DATE(o.complete_time) <![CDATA[ >= ]]> #{data.completeTimeStart}
            </if>
            <if test="data.completeTimeEnd != null and data.completeTimeEnd != ''">
                and DATE(o.complete_time) <![CDATA[ <= ]]> #{data.completeTimeEnd}
            </if>
        </where>
        order by o.createTime desc
    </select>
 
    <select id="orderPageCount" resultMap="BaseResultMap">
        select o.*
        from t_order o
        <where>
            o.is_delete = 0
            <if test="data.cityList != null and data.cityList.size() != 0">
                and o.city_code in
                <foreach collection="data.cityList" item="city" open="(" separator="," close=")">
                    #{city}
                </foreach>
            </if>
 
            <if test="data.servIds != null and data.servIds.size() != 0">
                and o.serve_id in
                <foreach collection="data.servIds" item="c" open="(" separator="," close=")">
                    #{c}
                </foreach>
            </if>
 
           <if test="data.type !=null">
               and o.type = #{data.type}
           </if>
            <if test="data.fake !=null">
                and o.fake = #{data.fake}
            </if>
            <if test="data.address != null and data.address != ''">
                and o.reservation_address like concat('%', #{data.address}, '%')
            </if>
            <if test="data.orderNumber != null and data.orderNumber != ''">
                and o.order_number like concat('%', #{data.orderNumber}, '%')
            </if>
            <if test="data.cityName != null and data.cityName != ''">
                and o.city like concat('%', #{data.cityName}, '%')
            </if>
            <if test="data.reservationName != null and data.reservationName != ''">
                and o.reservation_name like concat('%', #{data.reservationName}, '%')
            </if>
            <if test="data.reservationPhone != null and data.reservationPhone != ''">
                and o.reservation_phone like concat('%', #{data.reservationPhone}, '%')
            </if>
            <if test="data.workerName != null and data.workerName != ''">
                and o.server_name like concat('%', #{data.workerName}, '%')
            </if>
            <if test="data.workerPhone != null and data.workerPhone != ''">
                and o.server_phone like concat('%', #{data.workerPhone}, '%')
            </if>
            <if test="data.serveName != null and data.serveName != ''">
                and o.site_name like concat('%', #{data.serveName}, '%')
            </if>
            <if test="data.orderTimeStart != null and data.orderTimeStart != ''">
                and DATE(o.createTime) <![CDATA[ >= ]]> #{data.orderTimeStart}
            </if>
            <if test="data.orderTimeEnd != null and data.orderTimeEnd != ''">
                and DATE(o.createTime) <![CDATA[ <= ]]> #{data.orderTimeEnd}
            </if>
            <if test="data.startTime != null and data.startTime != ''">
                and STR_TO_DATE(SUBSTRING_INDEX(time, ' - ', 1), '%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{data.startTime}
            </if>
            <if test="data.endTime != null and data.endTime != ''">
                AND STR_TO_DATE(SUBSTRING_INDEX(time, ' - ', -1), '%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{data.endTime}
            </if>
        </where>
    </select>
 
    <select id="exportByIdList" resultMap="BaseResultMap">
        select reservation_name,
               reservation_phone,
               reservation_address,
               time,
               serve_name,
               server_name,
               server_phone,site_name
        from t_order
        <where>
            id in
            <foreach collection="list" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </where>
    </select>
 
    <select id="exportList" resultMap="BaseResultMap">
        select *
        from t_order o
        <where>
            o.is_delete = 0
            <if test="data.fake != null ">
                and o.fake = #{data.fake}
            </if>
            <if test="data.address != null and data.address != ''">
                and o.reservation_address like concat('%', #{data.address}, '%')
            </if>
            <if test="data.servIds != null and data.servIds.size() != 0">
                and o.serve_id in
                <foreach collection="data.servIds" item="c" open="(" separator="," close=")">
                    #{c}
                </foreach>
            </if>
            <if test="data.type != null">
                and o.type = #{data.type}
            </if>
            <if test="data.orderNumber != null and data.orderNumber != ''">
                and o.order_number like concat('%', #{data.orderNumber}, '%')
            </if>
            <if test="data.cityName != null and data.cityName != ''">
                and o.city like concat('%', #{data.cityName}, '%')
            </if>
            <if test="data.reservationName != null and data.reservationName != ''">
                and o.reservation_name like concat('%', #{data.reservationName}, '%')
            </if>
            <if test="data.reservationPhone != null and data.reservationPhone != ''">
                and o.reservation_phone like concat('%', #{data.reservationPhone}, '%')
            </if>
            <if test="data.state != null">
                and o.state = #{data.state}
            </if>
            <if test="data.workerName != null and data.workerName != ''">
                and o.server_name like concat('%', #{data.workerName}, '%')
            </if>
            <if test="data.workerPhone != null and data.workerPhone != ''">
                and o.server_phone like concat('%', #{data.workerPhone}, '%')
            </if>
            <if test="data.serveName != null and data.serveName != ''">
                and o.site_name like concat('%', #{data.serveName}, '%')
            </if>
            <if test="data.orderTimeStart != null and data.orderTimeStart != ''">
                and DATE(o.createTime) <![CDATA[ >= ]]> #{data.orderTimeStart}
            </if>
            <if test="data.orderTimeEnd != null and data.orderTimeEnd != ''">
                and DATE(o.createTime) <![CDATA[ <= ]]> #{data.orderTimeEnd}
            </if>
            <if test="data.startTime != null and data.startTime != ''">
                and STR_TO_DATE(SUBSTRING_INDEX(time, ' - ', 1), '%Y-%m-%d %H:%i') <![CDATA[ >= ]]> #{data.startTime}
            </if>
            <if test="data.endTime != null and data.endTime != ''">
                AND STR_TO_DATE(SUBSTRING_INDEX(time, ' - ', -1), '%Y-%m-%d %H:%i') <![CDATA[ <= ]]> #{data.endTime}
            </if>
        </where>
        order by o.createTime desc
    </select>
 
    <select id="orderListWorker" resultMap="BaseResultMap">
        select o.*
        from t_order o
        <where>
            o.is_delete = 0
              and o.server_id = #{userId}
            <choose>
                <when test="state == 1">
                    and o.state in (1, 2)
                </when>
                <when test="state == 2">
                    and o.state = 3
                </when>
                <otherwise>
                    and o.state in (1, 2, 3)
                </otherwise>
            </choose>
        </where>
        order by o.createTime desc
    </select>
 
    <select id="workerOrderRank" resultType="com.ruoyi.order.vo.WorkerOrderRankVO">
        select server_id as workerId, COUNT(server_id) as orderNumber
        from t_order
        <where>
            is_delete = 0
            <if test="ids != null and ids.size() != 0">
                and server_id in
                <foreach collection="ids" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </where>
        GROUP BY server_id
        ORDER BY orderNumber desc
    </select>
 
    <select id="orderStateCount" resultType="com.ruoyi.order.vo.WorkerOrderCountVO">
        SELECT COALESCE(SUM(CASE WHEN o.state IN (1, 2, 3) THEN 1 ELSE 0 END), 0) AS total,
               COALESCE(SUM(CASE WHEN o.state in (1, 2) THEN 1 ELSE 0 END), 0)    AS waitVisit,
               COALESCE(SUM(CASE WHEN o.state = 3 THEN 1 ELSE 0 END), 0)          AS completed
        FROM t_order o
        where o.server_id = #{workerId}
          and o.is_delete = 0
    </select>
 
    <select id="orderCountByTimeRange" resultType="com.ruoyi.order.vo.OrderQueryVO">
        SELECT DATE_FORMAT(createTime, '%Y-%m-%d') AS dateTime,
               COUNT(*)                            AS number,
               sum(IFNULL(order_money, 0))         as totalPrice,
        COUNT(CASE WHEN fake = 1 THEN 1 END) AS fakeCount
        FROM t_order
        <where>
            is_delete = 0
            <if test="cityList != null and cityList.size() != 0">
                and city_code in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="orderState != null">
                and state = #{orderState}
            </if>
            <if test="startTime != null and startTime != ''">
                and createTime <![CDATA[ >= ]]> #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and createTime <![CDATA[ <= ]]> #{endTime}
            </if>
        </where>
        GROUP BY dateTime
        order by dateTime
    </select>
 
    <select id="orderCountByTimeRangeYear" resultType="com.ruoyi.order.vo.OrderQueryVO">
        SELECT DATE_FORMAT(createTime, '%Y') AS dateTime, COUNT(*) AS number, sum(IFNULL(order_money, 0)) as totalPrice,
        COUNT(CASE WHEN fake = 1 THEN 1 END) AS fakeCount
        FROM t_order
        <where>
            is_delete = 0
            <if test="cityList != null and cityList.size() != 0">
                and city_code in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="orderState != null">
                and state = #{orderState}
            </if>
            <if test="startTime != null and startTime != ''">
                and createTime <![CDATA[ >= ]]> #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and createTime <![CDATA[ <= ]]> #{endTime}
            </if>
        </where>
        GROUP BY dateTime
        order by dateTime
    </select>
 
    <select id="orderCountByTimeRangeMonth" resultType="com.ruoyi.order.vo.OrderQueryVO">
        SELECT DATE_FORMAT(createTime, '%Y-%m') AS dateTime,
               COUNT(*)                         AS number,
               sum(IFNULL(order_money, 0))      as totalPrice,
        COUNT(CASE WHEN fake = 1 THEN 1 END) AS fakeCount
        FROM t_order
        <where>
            is_delete = 0
            <if test="cityList != null and cityList.size() != 0">
                and city_code in
                <foreach collection="cityList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="orderState != null">
                and state = #{orderState}
            </if>
            <if test="startTime != null and startTime != ''">
                and createTime <![CDATA[ >= ]]> #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and createTime <![CDATA[ <= ]]> #{endTime}
            </if>
        </where>
        GROUP BY dateTime
        order by dateTime
    </select>
    <select id="papercout" resultType="com.ruoyi.common.core.vo.PaperInVo">
        select count(*) as count, serve_id as serveId from t_order
                                                      where is_delete = 0 and state = 3
                                                        and server_id = #{workId}
                                                        and `time` = #{date}
        group by serve_id
 
    </select>
 
</mapper>