liujie
2 天以前 f73e9c5419c82b9ff685b8e67d839fd942100073
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
<?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.system.mapper.TErpProcurementMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.model.TErpProcurement">
        <id column="id" property="id" />
        <result column="clinic_id" property="clinicId" />
        <result column="procurement_code" property="procurementCode" />
        <result column="pay_money" property="payMoney" />
        <result column="pay_number" property="payNumber" />
        <result column="pay_transaction_id" property="payTransactionId" />
        <result column="status" property="status" />
        <result column="supplier_money" property="supplierMoney" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="create_by" property="createBy" />
        <result column="update_by" property="updateBy" />
        <result column="disabled" property="disabled" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, clinic_id, procurement_code, pay_money, pay_number, pay_transaction_id, status, create_time, update_time, create_by, update_by, disabled
    </sql>
    <sql id="Base_Column_List1">
        t1.id, t1.supplier_clinic_id, t1.goods_source, t1.goods_name, t1.goods_id_code, t1.quasi_number, t1.manufacturer, t1.formulation_spec, t1.packing_spec, t1.type_id, t1.goods_yards, t1.maintenance_interval, t1.low_purchase_quantity, t1.low_unit_id, t1.is_prescription_drug, t1.goods_spec, t1.warning_inventory, t1.sales_amount, t1.packing_unit_id, t1.instructions_use, t1.side_effect, t1.clinic_purchase_price, t1.platform_commission_price, t1.create_time, t1.update_time, t1.create_by,t1.`state`, t1.update_by, t1.disabled,
    </sql>
 
    <select id="pageList" resultType="com.ruoyi.system.vo.TErpProcurementVo">
        select t1.id,
        t1.procurement_code,
        t1.clinic_id,
        t3.supplier_name,
        sum(t2.total_price) as totalPrice,
        t1.create_time,
        t2.id tErpProcurementGoodsId,
        t1.create_by as userName,
        t1.status,
        t1.supplier_money,
        t1.money as platformMoney,
        t5.clinic_name
        from t_erp_procurement t1
        left JOIN t_erp_procurement_goods t2 on t1.id = t2.procurement_id
        LEFT JOIN t_crm_supplier t3 on t1.supplier_id = t3.id
        left JOIN sys_user t4 on t1.create_id = t4.user_id
        left join t_crm_clinic t5 on t1.clinic_id = t5.id
        where t1.disabled = 0 and t1.status !=1
        <if test="user.roleType !=null and user.roleType==4">
            and t2.supplier_id =#{supplierClinicId} and t1.status in(3,4,5)
        </if>
        <if test="user.roleType !=null and user.roleType==5">
            and t1.clinic_id =#{supplierClinicId}
        </if>
        <if test="query.procurementCode != null and query.procurementCode != ''">
            and t1.procurement_code = #{query.procurementCode}
        </if>
        <if test="query.clinicName != null and query.clinicName != ''">
            and t3.supplier_name like concat('%',#{query.clinicName},'%')
        </if>
        <if test="query.userName != null and query.userName != ''">
            and t1.create_by like concat('%',#{query.userName},'%')
        </if>
        <if test="query.status != null">
            and t1.status = #{query.status}
        </if>
        <if test="sTime != null">
            and t1.create_time between #{sTime} and #{eTime}
        </if>
        group by t1.id
        order by t1.create_time desc
 
    </select>
    <select id="inventoryNotEnoughList" resultType="com.ruoyi.system.vo.TErpGoodsVO">
        select * from (
        select <include refid="Base_Column_List1"/>
        COALESCE(sum(t2.goods_count), 0) - COALESCE(sum(t3.outbound_count), 0) as allNum,
        SUM(t2.unit_amount * (t2.goods_count - COALESCE(t3.outbound_count, 0))) as allTotalPrice,
 
        COALESCE(sum(t3.outbound_count), 0) as outNum
        from t_erp_goods t1  left join  t_erp_supplier_warehousing t2  on t1.id = t2.goods_id
        left join  t_erp_supplier_outbound_goods t3 on t2.id = t3.warehousing_id
        where t1.disabled = 0 and t2.id is not null and t1.goods_source =1 and t1.clinic_purchase_price is not null
        GROUP BY t1.id
        ) o where 1=1
        and  o.warning_inventory  > (o.allNum-o.outNum)
        order by o.create_time desc
    </select>
    <select id="pageListWarehouse" resultType="com.ruoyi.system.vo.TErpProcurementVo">
        select t1.id,
               t1.procurement_code,
               t2.clinic_name,
               t2.clinic_address,
               t1.logistics_number as logisticsNo,
                t1.send_time,
               t1.clinic_id,
               t1.status,
               t1.create_by  userName
               from t_erp_procurement t1
               left JOIN t_crm_clinic t2 on t1.clinic_id = t2.id
        where t1.disabled = 0 and t1.status in(3,4,5) and t1.supplier_id in
        <foreach collection="supplierClinicId" close=")" item="id" separator="," open="(" >
            #{id}
        </foreach>
        <if test="query.procurementCode != null and query.procurementCode != ''">
            and t1.procurement_code = #{query.procurementCode}
        </if>
        <if test="query.clinicName != null and query.clinicName != ''">
            and t2.clinic_name like concat('%',#{query.clinicName},'%')
        </if>
        <if test="query.logisticsNo != null and query.logisticsNo != ''">
            and t1.logistics_number = #{query.logisticsNo}
        </if>
        <if test="sTime != null and eTime != ''">
            and t1.create_time between #{sTime} and #{eTime}
        </if>
        <if test="query.status != null">
            and t1.status = #{query.status}
        </if>
        order by t1.create_time desc
 
 
    </select>
    <select id="supplierThirtyProcurementStatistics"
            resultType="com.ruoyi.system.vo.SupplierThirtyProcurementStatisticsVO">
        select
        date_format(t1.pay_time, '%m.%d') as `time`,
        date_format(t1.pay_time, '%Y-%m-%d') as payTime,
        count(1) as orderCount
        from t_erp_procurement t1
        where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        and t1.status in (3,4,5)
        and t1.pay_time between #{startTime} and #{endTime}
        <if test="roleType != null and roleType == 4">
            and t1.supplier_id = #{supplierAndClinicId}
        </if>
        <if test="roleType != null and roleType == 5">
            and t1.clinic_id = #{supplierAndClinicId}
        </if>
        group by date_format(t1.pay_time, '%m.%d')
    </select>
    <select id="supplierThirtyMoneyProcurementStatistics"
            resultType="com.ruoyi.system.vo.SupplierThirtyMoneyProcurementStatisticsVO">
        select
            date_format(t1.pay_time, '%m.%d') as `time`,
            date_format(t1.pay_time, '%Y-%m-%d') as payTime,
            sum(t1.pay_money) as moneyTotal
        from t_erp_procurement t1
        where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
            and t1.status in (3,4,5)
            and t1.pay_time between #{startTime} and #{endTime}
            <if test="roleType != null and roleType == 4">
                and t1.supplier_id = #{supplierAndClinicId}
            </if>
            <if test="roleType != null and roleType == 5">
                and t1.clinic_id = #{supplierAndClinicId}
            </if>
        group by date_format(t1.pay_time, '%m.%d')
    </select>
    <select id="supplierSalesStatisticsTypeCount" resultType="java.lang.Integer">
        select count(1)
        from t_erp_procurement tep
        left join t_erp_procurement_goods tepg on tep.id = tepg.procurement_id
        left join t_erp_goods teg on tepg.goods_id = teg.id
        where tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        and tep.status in (3,4,5)
        and tep.supplier_id = #{supplierId}
        group by teg.type_id
    </select>
    <select id="supplierSalesStatisticsCount" resultType="java.lang.Integer">
        select count(1)
        from t_erp_procurement tep
         left join t_erp_procurement_goods tepg on tep.id = tepg.procurement_id
        where tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
          and tep.status in (3,4,5)
          and tep.supplier_id = #{supplierId}
    </select>
    <select id="supplierSalesStatisticsMoney" resultType="java.math.BigDecimal">
        select sum(pay_money) from t_erp_procurement
        where disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
          and status in (3,4,5)
          and pay_time between #{startTime} and #{endTime}
          and supplier_id = #{supplierId}
    </select>
    <select id="supplierSalesStatisticsGoodsType"
            resultType="com.ruoyi.system.vo.SupplierSalesStatisticsGoodsTypeVO">
        select count(1), tegt.type_name
        from t_erp_procurement tep
                 left join t_erp_procurement_goods tepg on tep.id = tepg.procurement_id
                 left join t_erp_goods teg on tepg.goods_id = teg.id
                 left join t_erp_goods_type tegt on teg.type_id = tegt.id
        where tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
          and tep.status in (3,4,5)
          and tep.pay_time between #{startTime} and #{endTime}
          and tep.supplier_id = #{supplierId}
        group by teg.type_id
        order by count(1) desc
    </select>
    <select id="supplierSalesStatisticsGoodsCount"
            resultType="com.ruoyi.system.vo.SupplierSalesStatisticsGoodsCountVO">
        select
        date_format(t1.pay_time, '%m.%d') as `time`,
        date_format(t1.pay_time, '%Y-%m-%d') as payTime,
        sum(t2.purchase_count) as goodsCount
        from t_erp_procurement t1
        left join t_erp_procurement_goods t2 on t1.id = t2.procurement_id
        where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        and t1.status in (3,4,5)
        and t1.pay_time between #{startTime} and #{endTime}
        and t1.supplier_id = #{supplierId}
        <if test="goodsName != null and goodsName != ''">
            and t2.goods_name like concat('%',#{goodsName},'%')
        </if>
        group by date_format(t1.pay_time, '%m.%d')
    </select>
    <select id="supplierSalesStatisticsGoodsCountMonth"
            resultType="com.ruoyi.system.vo.SupplierSalesStatisticsGoodsCountVO">
        select
        date_format(t1.pay_time, '%Y.%m') as `time`,
        sum(t2.purchase_count) as goodsCount
        from t_erp_procurement t1
        left join t_erp_procurement_goods t2 on t1.id = t2.procurement_id
        where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        and t1.status in (3,4,5)
        and t1.pay_time between #{startTime} and #{endTime}
        and t1.supplier_id = #{supplierId}
        <if test="goodsName != null and goodsName != ''">
            and t2.goods_name like concat('%',#{goodsName},'%')
        </if>
        group by date_format(t1.pay_time, '%Y.%m')
    </select>
    <select id="branchAdminStatisticsThree" resultType="com.ruoyi.system.model.TErpProcurementGoods">
        select t2.goods_id,t2.goods_name,t2.purchase_count as purchaseCount,t1.pay_time as payTime,t1.pay_money
        from t_erp_procurement t1
        left join t_erp_procurement_goods t2 on t1.id = t2.procurement_id
        where t1.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        and t1.status in (3,4,5)
        and t1.clinic_id in
        <foreach item="item" collection="clinicIds" separator=","  open="(" close=")">
            #{item}
        </foreach>
    </select>
    <select id="clinicProcurementReport" resultType="com.ruoyi.system.vo.ClinicProcurementReportVO">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
               tep.money,tep.supplier_money,
               tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicId != null and query.clinicId != ''">
                and tep.clinic_id = #{query.clinicId}
            </if>
            <if test="query.supplierId != null and query.supplierId != ''">
                and tep.supplier_id = #{query.supplierId}
            </if>
            <if test="query.personChargeName != null and query.personChargeName != ''">
                and tep.person_charge_name like concat('%',#{query.personChargeName},'%')
            </if>
            <if test="query.phone != null and query.phone != ''">
                and tep.phone like concat('%',#{query.phone},'%')
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="exportProcurementReportClinic"
            resultType="com.ruoyi.system.export.ProcurementReportClinicExport">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicId != null and query.clinicId != ''">
                and tep.clinic_id = #{query.clinicId}
            </if>
            <if test="query.supplierId != null and query.supplierId != ''">
                and tep.supplier_id = #{query.supplierId}
            </if>
            <if test="query.personChargeName != null and query.personChargeName != ''">
                and tep.person_charge_name like concat('%',#{query.personChargeName},'%')
            </if>
            <if test="query.phone != null and query.phone != ''">
                and tep.phone like concat('%',#{query.phone},'%')
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="exportProcurementReportSupplier"
            resultType="com.ruoyi.system.export.ProcurementReportSupplierExport">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicId != null and query.clinicId != ''">
                and tep.clinic_id = #{query.clinicId}
            </if>
            <if test="query.supplierId != null and query.supplierId != ''">
                and tep.supplier_id = #{query.supplierId}
            </if>
            <if test="query.personChargeName != null and query.personChargeName != ''">
                and tep.person_charge_name like concat('%',#{query.personChargeName},'%')
            </if>
            <if test="query.phone != null and query.phone != ''">
                and tep.phone like concat('%',#{query.phone},'%')
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="exportProcurementReportPlatform"
            resultType="com.ruoyi.system.export.ProcurementReportPlatformExport">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicId != null and query.clinicId != ''">
                and tep.clinic_id = #{query.clinicId}
            </if>
            <if test="query.supplierId != null and query.supplierId != ''">
                and tep.supplier_id = #{query.supplierId}
            </if>
            <if test="query.personChargeName != null and query.personChargeName != ''">
                and tep.person_charge_name like concat('%',#{query.personChargeName},'%')
            </if>
            <if test="query.phone != null and query.phone != ''">
                and tep.phone like concat('%',#{query.phone},'%')
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="platformLedgerReport" resultType="com.ruoyi.system.vo.ClinicProcurementReportVO">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicId != null and query.clinicId != ''">
                and tep.clinic_id = #{query.clinicId}
            </if>
            <if test="query.supplierId != null and query.supplierId != ''">
                and tep.supplier_id = #{query.supplierId}
            </if>
            <if test="query.personChargeName != null and query.personChargeName != ''">
                and tep.person_charge_name like concat('%',#{query.personChargeName},'%')
            </if>
            <if test="query.phone != null and query.phone != ''">
                and tep.phone like concat('%',#{query.phone},'%')
            </if>
            AND tep.is_platform_commission = 1
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="exportPlatformLedgerReport" resultType="com.ruoyi.system.export.PlatformLedgerReportExport">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicId != null and query.clinicId != ''">
                and tep.clinic_id = #{query.clinicId}
            </if>
            <if test="query.supplierId != null and query.supplierId != ''">
                and tep.supplier_id = #{query.supplierId}
            </if>
            <if test="query.personChargeName != null and query.personChargeName != ''">
                and tep.person_charge_name like concat('%',#{query.personChargeName},'%')
            </if>
            <if test="query.phone != null and query.phone != ''">
                and tep.phone like concat('%',#{query.phone},'%')
            </if>
            AND tep.is_platform_commission = 1
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="branchPerformanceReport" resultType="com.ruoyi.system.vo.BranchPerformanceReportVO">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone,
        tcb.branch_name as branchName
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        left join t_crm_branch tcb on tcc.branch_id = tcb.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicIds != null and query.clinicIds.size()>0">
                and tep.clinic_id in
                <foreach item="item" collection="query.clinicIds" separator="," open="(" close=")" index="">
                    #{item}
                </foreach>
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="salespersonPerformanceReport" resultType="com.ruoyi.system.vo.SalespersonPerformanceReportVO">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone,
        tcb.branch_name as branchName,tcsa.salesperson_name as salespersonName
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        left join t_crm_branch tcb on tcc.branch_id = tcb.id
        left join t_crm_salesperson tcsa on tcc.salesperson_id = tcsa.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicIds != null and query.clinicIds.size()>0">
                and tep.clinic_id in
                <foreach item="item" collection="query.clinicIds" separator="," open="(" close=")" index="">
                    #{item}
                </foreach>
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="exportBranchPerformanceReport" resultType="com.ruoyi.system.vo.BranchPerformanceReportVO">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone,
        tcb.branch_name as branchName
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        left join t_crm_branch tcb on tcc.branch_id = tcb.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicIds != null and query.clinicIds.size()>0">
                and tep.clinic_id in
                <foreach item="item" collection="query.clinicIds" separator="," open="(" close=")" index="">
                    #{item}
                </foreach>
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
    <select id="exportSalespersonPerformanceReport"
            resultType="com.ruoyi.system.vo.SalespersonPerformanceReportVO">
        select tep.id, tep.procurement_code, tep.pay_money, tep.status,tep.pay_time,tep.clinic_id, tep.supplier_id,
        tep.money,tep.supplier_money,
        tcs.supplier_name as supplierName, tcc.clinic_name as clinicName,tcc.person_charge_name,tcc.phone,
        tcb.branch_name as branchName,tcsa.salesperson_name as salespersonName
        from t_erp_procurement tep
        left join t_crm_supplier tcs on tep.supplier_id = tcs.id
        left join t_crm_clinic tcc on tep.clinic_id = tcc.id
        left join t_crm_branch tcb on tcc.branch_id = tcb.id
        left join t_crm_salesperson tcsa on tcc.salesperson_id = tcsa.id
        <where>
            <if test="query.procurementCode != null and query.procurementCode != ''">
                and tep.procurement_code like concat('%',#{query.procurementCode},'%')
            </if>
            <if test="query.supplierName != null and query.supplierName != ''">
                and tcs.supplier_name like concat('%',#{query.supplierName},'%')
            </if>
            <if test="query.clinicName != null and query.clinicName != ''">
                and tcc.clinic_name like concat('%',#{query.clinicName},'%')
            </if>
            <if test="query.status != null and query.status != ''">
                and tep.status = #{query.status}
            </if>
            <if test="query.startTime != null and query.startTime != '' and query.endTime != null and query.endTime != ''">
                AND tep.pay_time &gt;= #{query.startTime}
                AND tep.pay_time &lt;= #{query.endTime}
            </if>
            <if test="query.clinicIds != null and query.clinicIds.size()>0">
                and tep.clinic_id in
                <foreach item="item" collection="query.clinicIds" separator="," open="(" close=")" index="">
                    #{item}
                </foreach>
            </if>
            AND tep.status in (3,4,5)
            AND tep.disabled = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()}
        </where>
        order by tep.pay_time desc
    </select>
 
</mapper>