广州市综治平台后端
xusd
2025-06-07 36306491396230522fa20585c2621a7fc899849a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
<?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">
<!-- 
 * @title: 第三方系统对接-转人民调解系统申请表
 * @description: 自定义sql,请自行实现业务逻辑
 * @company: hugeinfo
 * @author: liyj
 * @time:2024-11-18 16:19:37
 * @version 1.0.0
-->
<mapper namespace="cn.huge.module.thirdByRmtj.dao.mapper.ThRmtjApplyMapper">
    <!-- 结果集 -->
    <resultMap id="dataResult" type="cn.huge.module.thirdByRmtj.domain.po.ThRmtjApply">
            <result property="id" column="id"/>
            <result property="caseId" column="case_id"/>
            <result property="applyIndex" column="apply_index"/>
            <result property="process" column="process"/>
            <result property="auditNode" column="audit_node"/>
            <result property="applyUserId" column="apply_user_id"/>
            <result property="applyUserName" column="apply_user_name"/>
            <result property="applyUnitId" column="apply_unit_id"/>
            <result property="applyUnitName" column="apply_unit_name"/>
            <result property="applyTime" column="apply_time"/>
            <result property="firstAuditUnit" column="first_audit_unit"/>
            <result property="firstAuditUnitName" column="first_audit_unit_name"/>
            <result property="firstAuditUser" column="first_audit_user"/>
            <result property="firstAuditUserName" column="first_audit_user_name"/>
            <result property="firstAuditResult" column="first_audit_result"/>
            <result property="firstAuditTime" column="first_audit_time"/>
            <result property="endAuditUnit" column="end_audit_unit"/>
            <result property="endAuditUnitName" column="end_audit_unit_name"/>
            <result property="endAuditUser" column="end_audit_user"/>
            <result property="endAuditUserName" column="end_audit_user_name"/>
            <result property="endAuditResult" column="end_audit_result"/>
            <result property="endAuditTime" column="end_audit_time"/>
            <result property="rmtjStatus" column="rmtj_status"/>
            <result property="rmtjCaseId" column="rmtj_case_id"/>
            <result property="rmtjFalseInfo" column="rmtj_false_info"/>
            <result property="rmtjTime" column="rmtj_time"/>
            <result property="custId" column="cust_id"/>
            <result property="createTime" column="create_time"/>
            <result property="updateTime" column="update_time"/>
    </resultMap>
    <!-- 表 -->
    <sql id='table-name'>dyh_th_rmtj_apply</sql>
    <!-- 字段 -->
    <sql id="column-part">
        id,
        case_id,
        apply_index,
        process,
        audit_node,
        apply_user_id,
        apply_user_name,
        apply_unit_id,
        apply_unit_name,
        apply_time,
        first_audit_unit,
        first_audit_unit_name,
        first_audit_user,
        first_audit_user_name,
        first_audit_result,
        first_audit_time,
        end_audit_unit,
        end_audit_unit_name,
        end_audit_user,
        end_audit_user_name,
        end_audit_result,
        end_audit_time,
        rmtj_status,
        rmtj_case_id,
        rmtj_false_info,
        rmtj_time,
        cust_id,
        create_time,
        update_time
    </sql>
    <!-- 更新实体字段 -->
    <sql id="set-part">
            <if test="entity.caseId != null">case_id = #{entity.caseId},</if>
            <if test="entity.applyIndex != null">apply_index = #{entity.applyIndex},</if>
            <if test="entity.process != null">process = #{entity.process},</if>
            <if test="entity.auditNode != null">audit_node = #{entity.auditNode},</if>
            <if test="entity.applyUserId != null">apply_user_id = #{entity.applyUserId},</if>
            <if test="entity.applyUserName != null">apply_user_name = #{entity.applyUserName},</if>
            <if test="entity.applyUnitId != null">apply_unit_id = #{entity.applyUnitId},</if>
            <if test="entity.applyUnitName != null">apply_unit_name = #{entity.applyUnitName},</if>
            <if test="entity.applyTime != null">apply_time = #{entity.applyTime},</if>
            <if test="entity.firstAuditUnit != null">first_audit_unit = #{entity.firstAuditUnit},</if>
            <if test="entity.firstAuditUnitName != null">first_audit_unit_name = #{entity.firstAuditUnitName},</if>
            <if test="entity.firstAuditUser != null">first_audit_user = #{entity.firstAuditUser},</if>
            <if test="entity.firstAuditUserName != null">first_audit_user_name = #{entity.firstAuditUserName},</if>
            <if test="entity.firstAuditResult != null">first_audit_result = #{entity.firstAuditResult},</if>
            <if test="entity.firstAuditTime != null">first_audit_time = #{entity.firstAuditTime},</if>
            <if test="entity.endAuditUnit != null">end_audit_unit = #{entity.endAuditUnit},</if>
            <if test="entity.endAuditUnitName != null">end_audit_unit_name = #{entity.endAuditUnitName},</if>
            <if test="entity.endAuditUser != null">end_audit_user = #{entity.endAuditUser},</if>
            <if test="entity.endAuditUserName != null">end_audit_user_name = #{entity.endAuditUserName},</if>
            <if test="entity.endAuditResult != null">end_audit_result = #{entity.endAuditResult},</if>
            <if test="entity.endAuditTime != null">end_audit_time = #{entity.endAuditTime},</if>
            <if test="entity.rmtjStatus != null">rmtj_status = #{entity.rmtjStatus},</if>
            <if test="entity.rmtjCaseId != null">rmtj_case_id = #{entity.rmtjCaseId},</if>
            <if test="entity.rmtjFalseInfo != null">rmtj_false_info = #{entity.rmtjFalseInfo},</if>
            <if test="entity.rmtjTime != null">rmtj_time = #{entity.rmtjTime},</if>
            <if test="entity.custId != null">cust_id = #{entity.custId},</if>
            <if test="entity.createTime != null">create_time = #{entity.createTime},</if>
            <if test="entity.updateTime != null">update_time = #{entity.updateTime}</if>
    </sql>
    <!-- 条件 -->
    <sql id="where-part">
        <if test="terms != null">
            <where>
                <if test="terms.id != null and terms.id !=''">
                    and id = #{terms.id}
                </if>
                <if test="terms.caseId != null and terms.caseId !=''">
                    and case_id = #{terms.caseId}
                </if>
                <if test="terms.applyIndex != null and terms.applyIndex !=''">
                    and apply_index = #{terms.applyIndex}
                </if>
                <if test="terms.process != null and terms.process !=''">
                    and process = #{terms.process}
                </if>
                <if test="terms.auditNode != null and terms.auditNode !=''">
                    and audit_node = #{terms.auditNode}
                </if>
                <if test="terms.applyUserId != null and terms.applyUserId !=''">
                    and apply_user_id = #{terms.applyUserId}
                </if>
                <if test="terms.applyUserName != null and terms.applyUserName !=''">
                    and apply_user_name = #{terms.applyUserName}
                </if>
                <if test="terms.applyUnitId != null and terms.applyUnitId !=''">
                    and apply_unit_id = #{terms.applyUnitId}
                </if>
                <if test="terms.applyUnitName != null and terms.applyUnitName !=''">
                    and apply_unit_name = #{terms.applyUnitName}
                </if>
                <if test="terms.applyTime != null and terms.applyTime !=''">
                    and apply_time = #{terms.applyTime}
                </if>
                <if test="terms.firstAuditUnit != null and terms.firstAuditUnit !=''">
                    and first_audit_unit = #{terms.firstAuditUnit}
                </if>
                <if test="terms.firstAuditUnitName != null and terms.firstAuditUnitName !=''">
                    and first_audit_unit_name = #{terms.firstAuditUnitName}
                </if>
                <if test="terms.firstAuditUser != null and terms.firstAuditUser !=''">
                    and first_audit_user = #{terms.firstAuditUser}
                </if>
                <if test="terms.firstAuditUserName != null and terms.firstAuditUserName !=''">
                    and first_audit_user_name = #{terms.firstAuditUserName}
                </if>
                <if test="terms.firstAuditResult != null and terms.firstAuditResult !=''">
                    and first_audit_result = #{terms.firstAuditResult}
                </if>
                <if test="terms.firstAuditTime != null and terms.firstAuditTime !=''">
                    and first_audit_time = #{terms.firstAuditTime}
                </if>
                <if test="terms.endAuditUnit != null and terms.endAuditUnit !=''">
                    and end_audit_unit = #{terms.endAuditUnit}
                </if>
                <if test="terms.endAuditUnitName != null and terms.endAuditUnitName !=''">
                    and end_audit_unit_name = #{terms.endAuditUnitName}
                </if>
                <if test="terms.endAuditUser != null and terms.endAuditUser !=''">
                    and end_audit_user = #{terms.endAuditUser}
                </if>
                <if test="terms.endAuditUserName != null and terms.endAuditUserName !=''">
                    and end_audit_user_name = #{terms.endAuditUserName}
                </if>
                <if test="terms.endAuditResult != null and terms.endAuditResult !=''">
                    and end_audit_result = #{terms.endAuditResult}
                </if>
                <if test="terms.endAuditTime != null and terms.endAuditTime !=''">
                    and end_audit_time = #{terms.endAuditTime}
                </if>
                <if test="terms.rmtjStatus != null and terms.rmtjStatus !=''">
                    and rmtj_status = #{terms.rmtjStatus}
                </if>
                <if test="terms.rmtjCaseId != null and terms.rmtjCaseId !=''">
                    and rmtj_case_id = #{terms.rmtjCaseId}
                </if>
                <if test="terms.rmtjFalseInfo != null and terms.rmtjFalseInfo !=''">
                    and rmtj_false_info = #{terms.rmtjFalseInfo}
                </if>
                <if test="terms.rmtjTime != null and terms.rmtjTime !=''">
                    and rmtj_time = #{terms.rmtjTime}
                </if>
                <if test="terms.custId != null and terms.custId !=''">
                    and cust_id = #{terms.custId}
                </if>
                <if test="terms.createTime != null and terms.createTime !=''">
                    and DATE_FORMAT(create_time,'%Y-%m-%d') = #{terms.createTime}
                </if>
                <if test="terms.createStart != null and terms.createStart !='' and terms.createEnd != null and terms.createEnd !=''">
                    and (DATE_FORMAT(create_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.createStart}
                        and DATE_FORMAT(create_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.createEnd})
                </if>
                <if test="terms.updateTime != null and terms.updateTime !=''">
                    and DATE_FORMAT(update_time,'%Y-%m-%d') = #{terms.updateTime}
                </if>
                <if test="terms.updateStart != null and terms.updateStart !='' and terms.updateEnd != null and terms.updateEnd !=''">
                    and (DATE_FORMAT(update_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.updateStart}
                        and DATE_FORMAT(update_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.updateEnd})
                </if>
            </where>
        </if>
    </sql>
    <!-- 更新对象 -->
    <update id="updateThRmtjApply">
        update
        <include refid="table-name"/>
        <set>
            <include refid="set-part"/>
        </set>
        <where>
            id = #{entity.id}
        </where>
    </update>
    <!-- 条件更新对象 -->
    <update id="updateThRmtjApplyTerms">
        update
        <include refid="table-name"/>
        <set>
            <include refid="set-part"/>
        </set>
        <include refid="where-part"/>
    </update>
    <!--  根据编号物理删除  -->
    <delete id="deleteThRmtjApply">
        delete from
        <include refid="table-name" />
        where id = #{id}
    </delete>
    <!--  根据条件查询  -->
    <select id="listTerms" resultMap="dataResult">
        select
        <include refid="column-part"/>
        from
        <include refid="table-name" />
        <include refid="where-part"/>
    </select>
    <!--  根据条件统计  -->
    <select id="countTerms" resultType="java.lang.Long">
        select
        COUNT(1)
        from
        <include refid="table-name" />
        <include refid="where-part"/>
    </select>
    <!--  根据条件分页查询  -->
    <select id="pageTerms" resultMap="dataResult">
        SELECT
        <include refid="column-part"/>
        FROM
        <include refid="table-name" />
        <include refid="where-part"/>
        <if test="page.sort != null">
            <foreach collection="page.sort" item="s" index="index" separator="," open="order by ">
                isnull(${s.property}), ${s.property} ${s.direction}
            </foreach>
        </if>
        <if test="page.sort == null">
            order by isnull(create_time), create_time desc
        </if>
        limit #{page.offset}, #{page.size}
    </select>
 
 
    <!-- web端-转入人民调解系统-申请列表-条件 -->
    <sql id="pageApply-where-part">
        <if test="terms != null">
            <if test="terms.closeStart != null and terms.closeStart !='' and terms.closeEnd != null and terms.closeEnd !=''">
                and (DATE_FORMAT(t2.close_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.closeStart}
                and DATE_FORMAT(t2.close_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.closeEnd})
            </if>
            <if test="terms.applyStart != null and terms.applyStart !='' and terms.applyEnd != null and terms.applyEnd !=''">
                and (DATE_FORMAT(t3.apply_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.applyStart}
                and DATE_FORMAT(t3.apply_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.applyEnd})
            </if>
            <if test="terms.rmtjStart != null and terms.rmtjStart !='' and terms.rmtjEnd != null and terms.rmtjEnd !=''">
                and (DATE_FORMAT(t3.rmtj_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.rmtjStart}
                and DATE_FORMAT(t3.rmtj_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.rrmtjEnd})
            </if>
            <if test="terms.firstAuditResult != null and terms.firstAuditResult !=''">
                and t3.first_audit_result = #{terms.firstAuditResult}
            </if>
            <if test="terms.endAuditResult != null and terms.endAuditResult !=''">
                and t3.end_audit_result = #{terms.endAuditResult}
            </if>
            <if test="terms.rmtjCaseId != null and terms.rmtjCaseId !=''">
                and t3.rmtj_case_id = #{terms.rmtjCaseId}
            </if>
            <if test="terms.rmtjStatus != null and terms.rmtjStatus !=''">
                and t3.rmtj_status = #{terms.rmtjStatus}
            </if>
            <if test="terms.plaintiffs != null and terms.plaintiffs !=''">
                and concat_ws('', ifnull(t1.plaintiffs, ''), ifnull(t1.pagents, '')) like concat('%', #{terms.plaintiffs}, '%')
            </if>
            <if test="terms.defendants != null and terms.defendants !=''">
                and concat_ws('', ifnull(t1.defendants, ''), ifnull(t1.dagents, '')) like concat('%', #{terms.defendants}, '%')
            </if>
            <if test="terms.caseRef != null and terms.caseRef !=''">
                and t1.case_ref like concat('%', #{terms.caseRef}, '%')
            </if>
            <if test="terms.inputWay != null and terms.inputWay !=''">
                and t1.input_way = #{terms.inputWay}
            </if>
            <if test="terms.mediatorId != null and terms.mediatorId !=''">
                and t2.mediator_id = #{terms.mediatorId}
            </if>
            <if test="terms.mediateUnitId != null and terms.mediateUnitId !=''">
                and t2.mediate_unit_id = #{terms.mediateUnitId}
            </if>
            <if test="terms.applyType == 1">
                and t3.id is null
            </if>
            <if test="terms.applyType == 2">
                and t3.id is not null
            </if>
        </if>
    </sql>
    <!--  web端-转入人民调解系统-申请列表-查询总数  -->
    <select id="countPageApply" resultType="java.lang.Long">
        SELECT
        count(distinct t1.id)
        FROM dyh_case_info t1
        LEFT JOIN dyh_case_info_unfold t2 ON t2.id = t1.id
        LEFT JOIN dyh_th_rmtj_apply t3 ON t3.case_id = t1.id
        WHERE t1.delete_Status = 0
        and t1.info_process = #{terms.infoProcess}
        <include refid="pageApply-where-part"/>
    </select>
    <!--  web端-转入人民调解系统-申请列表-按条件分页查询  -->
    <select id="pageApply" resultType="cn.huge.module.thirdByRmtj.domain.dto.RmtjApplyPageDTO">
        SELECT
        t1.id as caseId, t1.id as taskId, t3.id AS applyId,  t1.case_ref as caseRef, t2.close_time as closeTime,
        t2.medi_result as mediResult, t2.medi_result_name as mediResultName, t2.mediate_unit_name as mediateUnitName,
        t2.mediator, t1.canal_name as caseSource, t1.case_level as caseLevel,
        concat_ws('', ifnull(t1.case_type_first_name, ''), '/' , ifnull(t1.case_type_name, '')) as caseType,
        concat_ws('', ifnull(t1.plaintiffs, ''), ifnull(t1.pagents, '')) as plaintiffs,
        concat_ws('', ifnull(t1.defendants, ''), ifnull(t1.dagents, '')) as defendants,
        t3.apply_time as applyTime, t3.first_audit_result as firstAuditResult,
        (CASE WHEN t3.first_audit_result = 0 THEN '待审核' WHEN t3.first_audit_result = 1 THEN '同意' WHEN  t3.first_audit_result = 2 THEN '未通过' END) AS firstAuditResultName,
        t3.end_audit_result as endAuditResult,
        (CASE WHEN t3.end_audit_result = 0 THEN '待审核' WHEN t3.end_audit_result = 1 THEN '同意' WHEN  t3.end_audit_result = 2 THEN '未通过' END) AS endAuditResultName,
        t3.rmtj_status as rmtjStatus,
        (case WHEN t3.rmtj_status = 1 THEN '未转入' WHEN t3.rmtj_status = 2 THEN '转入中' WHEN t3.rmtj_status = 3 THEN '已转入' WHEN t3.rmtj_status = 4 THEN '转入失败' end) as rmtjStatusName,
        t3.rmtj_time as rmtjTime, t3.rmtj_case_id as rmtjCaseId
        FROM dyh_case_info t1
        LEFT JOIN dyh_case_info_unfold t2 ON t2.id = t1.id
        LEFT JOIN dyh_th_rmtj_apply t3 ON t3.case_id = t1.id
        WHERE t1.delete_Status = 0
        and t1.info_process = #{terms.infoProcess}
        <include refid="pageApply-where-part"/>
        group by t1.id
        <if test="page.sort != null">
            <foreach collection="page.sort" item="s" index="index" separator="," open="order by ">
                ${s.property} ${s.direction}
            </foreach>
        </if>
        <if test="page.sort == null">
            order by t1.create_time desc
        </if>
        limit #{page.offset}, #{page.size}
    </select>
 
    <!-- web端-转入人民调解系统-申请列表统计-条件 -->
    <sql id="countApply-where-part">
        <if test="terms != null">
            <if test="terms.closeStart != null and terms.closeStart !='' and terms.closeEnd != null and terms.closeEnd !=''">
                and (DATE_FORMAT(t2.close_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.closeStart}
                and DATE_FORMAT(t2.close_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.closeEnd})
            </if>
            <if test="terms.applyStart != null and terms.applyStart !='' and terms.applyEnd != null and terms.applyEnd !=''">
                and (DATE_FORMAT(t1.apply_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.applyStart}
                and DATE_FORMAT(t1.apply_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.applyEnd})
            </if>
            <if test="terms.rmtjStart != null and terms.rmtjStart !='' and terms.rmtjEnd != null and terms.rmtjEnd !=''">
                and (DATE_FORMAT(t1.rmtj_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.rmtjStart}
                and DATE_FORMAT(t1.rmtj_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.rrmtjEnd})
            </if>
            <if test="terms.firstAuditResult != null and terms.firstAuditResult !=''">
                and t1.first_audit_result = #{terms.firstAuditResult}
            </if>
            <if test="terms.endAuditResult != null and terms.endAuditResult !=''">
                and t1.end_audit_result = #{terms.endAuditResult}
            </if>
            <if test="terms.rmtjCaseId != null and terms.rmtjCaseId !=''">
                and t1.rmtj_case_id = #{terms.rmtjCaseId}
            </if>
            <if test="terms.rmtjStatus != null and terms.rmtjStatus !=''">
                and t1.rmtj_status = #{terms.rmtjStatus}
            </if>
            <if test="terms.plaintiffs != null and terms.plaintiffs !=''">
                and concat_ws('', ifnull(t3.plaintiffs, ''), ifnull(t3.pagents, '')) like concat('%', #{terms.plaintiffs}, '%')
            </if>
            <if test="terms.defendants != null and terms.defendants !=''">
                and concat_ws('', ifnull(t3.defendants, ''), ifnull(t3.dagents, '')) like concat('%', #{terms.defendants}, '%')
            </if>
            <if test="terms.caseRef != null and terms.caseRef !=''">
                and t3.case_ref like concat('%', #{terms.caseRef}"%"
            </if>
            <if test="terms.inputWay != null and terms.inputWay !=''">
                and t3.input_way = #{terms.inputWay}
            </if>
            <if test="terms.mediatorId != null and terms.mediatorId !=''">
                and t2.mediator_id = #{terms.mediatorId}
            </if>
            <if test="terms.mediateUnitId != null and terms.mediateUnitId !=''">
                and t2.mediate_unit_id = #{terms.mediateUnitId}
            </if>
        </if>
    </sql>
    <!--  web端-转入人民调解系统-申请列表统计  -->
    <select id="countApply" resultType="map">
        SELECT
        count(DISTINCT t1.case_id) as applyCount,
        count(DISTINCT case WHEN t1.rmtj_status = 3 THEN t1.case_id end) as inToCount,
        count(DISTINCT case WHEN t1.rmtj_status = 2 THEN t1.case_id end) as ingToCount,
        count(DISTINCT case WHEN t1.rmtj_status in(1, 4) THEN t1.case_id end) as notToCount
        FROM dyh_th_rmtj_apply t1
        LEFT JOIN dyh_case_info_unfold t2 ON t2.id = t1.case_id
        LEFT JOIN dyh_case_info t3 ON t3.id = t1.case_id
        WHERE t3.delete_Status = 0
        <include refid="countApply-where-part"/>
    </select>
 
    <!-- web端-转入人民调解系统-初审列表-条件 -->
    <sql id="pageFirstAudit-where-part">
        <if test="terms != null">
            <if test="terms.firstAuditStart != null and terms.firstAuditStart !='' and terms.firstAuditEnd != null and terms.firstAuditEnd !=''">
                and (DATE_FORMAT(t1.first_audit_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.firstAuditStart}
                and DATE_FORMAT(t1.first_audit_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.firstAuditEnd})
            </if>
            <if test="terms.applyStart != null and terms.applyStart !='' and terms.applyEnd != null and terms.applyEnd !=''">
                and (DATE_FORMAT(t1.apply_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.applyStart}
                and DATE_FORMAT(t1.apply_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.applyEnd})
            </if>
            <if test="terms.rmtjStart != null and terms.rmtjStart !='' and terms.rmtjEnd != null and terms.rmtjEnd !=''">
                and (DATE_FORMAT(t1.rmtj_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.rmtjStart}
                and DATE_FORMAT(t1.rmtj_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.rrmtjEnd})
            </if>
            <if test="terms.firstAuditResult != null and terms.firstAuditResult !=''">
                and t1.first_audit_result = #{terms.firstAuditResult}
            </if>
            <if test="terms.endAuditResult != null and terms.endAuditResult !=''">
                and t1.end_audit_result = #{terms.endAuditResult}
            </if>
            <if test="terms.rmtjCaseId != null and terms.rmtjCaseId !=''">
                and t1.rmtj_case_id = #{terms.rmtjCaseId}
            </if>
            <if test="terms.rmtjStatus != null and terms.rmtjStatus !=''">
                and t1.rmtj_status = #{terms.rmtjStatus}
            </if>
            <if test="terms.plaintiffs != null and terms.plaintiffs !=''">
                and concat_ws('', ifnull(t2.plaintiffs, ''), ifnull(t2.pagents, '')) like concat('%', #{terms.plaintiffs}, '%')
            </if>
            <if test="terms.defendants != null and terms.defendants !=''">
                and concat_ws('', ifnull(t2.defendants, ''), ifnull(t2.dagents, '')) like concat('%', #{terms.defendants}, '%')
            </if>
            <if test="terms.caseRef != null and terms.caseRef !=''">
                and t2.case_ref like concat('%', #{terms.caseRef}, '%')
            </if>
            <if test="terms.inputWay != null and terms.inputWay !=''">
                and t2.input_way = #{terms.inputWay}
            </if>
            <if test="terms.firstAuditUnit != null and terms.firstAuditUnit !=''">
                and t1.first_audit_unit = #{terms.firstAuditUnit}
            </if>
            <if test="terms.mediateUnitId != null and terms.mediateUnitId !=''">
                and t3.mediate_unit_id = #{terms.mediateUnitId}
            </if>
            <if test="terms.mediateUnitIds != null and terms.mediateUnitIds.size > 0">
                and t3.mediate_unit_id in
                <foreach collection="terms.mediateUnitIds" item="mediateUnitId" index="index" open="(" separator="," close=")">
                    #{mediateUnitId}
                </foreach>
            </if>
            <if test="terms.auditType == 1">
                and t1.first_audit_result = 0
                and t1.process = 1
            </if>
            <if test="terms.auditType == 2">
                and t1.first_audit_result != 0
                and t1.process != 1
            </if>
        </if>
    </sql>
    <!--  web端-转入人民调解系统-初审列表-查询总数  -->
    <select id="countPageFirstAudit" resultType="java.lang.Long">
        SELECT
        count(t1.id)
        FROM dyh_th_rmtj_apply t1
        LEFT JOIN dyh_case_info t2 ON t2.id = t1.case_id
        LEFT JOIN dyh_case_info_unfold t3 ON t3.id = t1.case_id
        WHERE t2.delete_Status = 0
        <include refid="pageFirstAudit-where-part"/>
    </select>
    <!--  web端-转入人民调解系统-初审列表-按条件分页查询  -->
    <select id="pageFirstAudit" resultType="cn.huge.module.thirdByRmtj.domain.dto.RmtjAuditPageDTO">
        SELECT
        t2.id as caseId, t2.id as taskId, t1.id AS applyId, t1.apply_time as applyTime, t2.case_ref as caseRef,
        t3.medi_result as mediResult, t3.medi_result_name as mediResultName, t3.mediate_unit_name as mediateUnitName,
        t3.mediator, t2.canal_name as caseSource, t2.case_level as caseLevel,
        concat_ws('', ifnull(t2.case_type_first_name, ''), '/' , ifnull(t2.case_type_name, '')) as caseType,
        concat_ws('', ifnull(t2.plaintiffs, ''), ifnull(t2.pagents, '')) as plaintiffs,
        concat_ws('', ifnull(t2.defendants, ''), ifnull(t2.dagents, '')) as defendants,
        t1.first_audit_time as firstAuditTime, t1.first_audit_result as firstAuditResult,
        (CASE WHEN t1.first_audit_result = 0 THEN '待审核' WHEN t1.first_audit_result = 1 THEN '同意' WHEN  t1.first_audit_result = 2 THEN '未通过' END) AS firstAuditResultName,
        t1.end_audit_time as endAuditTime, t1.end_audit_result as endAuditResult,
        (CASE WHEN t1.end_audit_result = 0 THEN '待审核' WHEN t1.end_audit_result = 1 THEN '同意' WHEN  t1.end_audit_result = 2 THEN '未通过' END) AS endAuditResultName,
        t1.rmtj_status as rmtjStatus,
        (case WHEN t1.rmtj_status = 1 THEN '未转入' WHEN t1.rmtj_status = 2 THEN '转入中' WHEN t1.rmtj_status = 3 THEN '已转入' WHEN t1.rmtj_status = 4 THEN '转入失败' end) as rmtjStatusName,
        t1.rmtj_time as rmtjTime, t1.rmtj_case_id as rmtjCaseId
        FROM dyh_th_rmtj_apply t1
        LEFT JOIN dyh_case_info t2 ON t2.id = t1.case_id
        LEFT JOIN dyh_case_info_unfold t3 ON t3.id = t1.case_id
        WHERE t2.delete_Status = 0
        <include refid="pageFirstAudit-where-part"/>
        <if test="page.sort != null">
            <foreach collection="page.sort" item="s" index="index" separator="," open="order by ">
                ${s.property} ${s.direction}
            </foreach>
        </if>
        <if test="page.sort == null">
            order by t1.create_time desc
        </if>
        limit #{page.offset}, #{page.size}
    </select>
 
 
 
    <!-- web端-转入人民调解系统-终审列表-条件 -->
    <sql id="pageEndAudit-where-part">
        <if test="terms != null">
            <if test="terms.firstAuditStart != null and terms.firstAuditStart !='' and terms.firstAuditEnd != null and terms.firstAuditEnd !=''">
                and (DATE_FORMAT(t1.first_audit_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.firstAuditStart}
                and DATE_FORMAT(t1.first_audit_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.firstAuditEnd})
            </if>
            <if test="terms.applyStart != null and terms.applyStart !='' and terms.applyEnd != null and terms.applyEnd !=''">
                and (DATE_FORMAT(t1.apply_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.applyStart}
                and DATE_FORMAT(t1.apply_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.applyEnd})
            </if>
            <if test="terms.rmtjStart != null and terms.rmtjStart !='' and terms.rmtjEnd != null and terms.rmtjEnd !=''">
                and (DATE_FORMAT(t1.rmtj_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{terms.rmtjStart}
                and DATE_FORMAT(t1.rmtj_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{terms.rrmtjEnd})
            </if>
            <if test="terms.firstAuditResult != null and terms.firstAuditResult !=''">
                and t1.first_audit_result = #{terms.firstAuditResult}
            </if>
            <if test="terms.endAuditResult != null and terms.endAuditResult !=''">
                and t1.end_audit_result = #{terms.endAuditResult}
            </if>
            <if test="terms.rmtjCaseId != null and terms.rmtjCaseId !=''">
                and t1.rmtj_case_id = #{terms.rmtjCaseId}
            </if>
            <if test="terms.rmtjStatus != null and terms.rmtjStatus !=''">
                and t1.rmtj_status = #{terms.rmtjStatus}
            </if>
            <if test="terms.plaintiffs != null and terms.plaintiffs !=''">
                and concat_ws('', ifnull(t2.plaintiffs, ''), ifnull(t2.pagents, '')) like concat('%', #{terms.plaintiffs}, '%')
            </if>
            <if test="terms.defendants != null and terms.defendants !=''">
                and concat_ws('', ifnull(t2.defendants, ''), ifnull(t2.dagents, '')) like concat('%', #{terms.defendants}, '%')
            </if>
            <if test="terms.caseRef != null and terms.caseRef !=''">
                and t2.case_ref like concat('%', #{terms.caseRef}, '%')
            </if>
            <if test="terms.inputWay != null and terms.inputWay !=''">
                and t2.input_way = #{terms.inputWay}
            </if>
            <if test="terms.endAuditUnit != null and terms.endAuditUnit !=''">
                and t1.end_audit_unit = #{terms.endAuditUnit}
            </if>
            <if test="terms.mediateUnitId != null and terms.mediateUnitId !=''">
                and t3.mediate_unit_id = #{terms.mediateUnitId}
            </if>
            <if test="terms.mediateUnitIds != null and terms.mediateUnitIds.size > 0">
                and t3.mediate_unit_id in
                <foreach collection="terms.mediateUnitIds" item="mediateUnitId" index="index" open="(" separator="," close=")">
                    #{mediateUnitId}
                </foreach>
            </if>
            <if test="terms.auditType == 1">
                and t1.end_audit_result = 0
                and t1.process = 2
            </if>
            <if test="terms.auditType == 2">
                and t1.end_audit_result != 0
                and t1.process in (3, 4, 9)
            </if>
        </if>
    </sql>
    <!--  web端-转入人民调解系统-终审列表-查询总数  -->
    <select id="countPageEndAudit" resultType="java.lang.Long">
        SELECT
        count(t1.id)
        FROM dyh_th_rmtj_apply t1
        LEFT JOIN dyh_case_info t2 ON t2.id = t1.case_id
        LEFT JOIN dyh_case_info_unfold t3 ON t3.id = t1.case_id
        WHERE t2.delete_Status = 0
        <include refid="pageEndAudit-where-part"/>
    </select>
    <!--  web端-转入人民调解系统-终审列表-按条件分页查询  -->
    <select id="pageEndAudit" resultType="cn.huge.module.thirdByRmtj.domain.dto.RmtjAuditPageDTO">
        SELECT
        t2.id as caseId, t2.id as taskId, t1.id AS applyId, t2.case_ref as caseRef,
        t3.medi_result as mediResult, t3.medi_result_name as mediResultName, t3.mediate_unit_name as mediateUnitName,
        t3.mediator, t2.canal_name as caseSource, t2.case_level as caseLevel,
        concat_ws('', ifnull(t2.case_type_first_name, ''), '/' , ifnull(t2.case_type_name, '')) as caseType,
        concat_ws('', ifnull(t2.plaintiffs, ''), ifnull(t2.pagents, '')) as plaintiffs,
        concat_ws('', ifnull(t2.defendants, ''), ifnull(t2.dagents, '')) as defendants,
        t1.first_audit_time as applyTime, t1.first_audit_result as firstAuditResult,
        (CASE WHEN t1.first_audit_result = 0 THEN '待审核' WHEN t1.first_audit_result = 1 THEN '同意' WHEN  t1.first_audit_result = 2 THEN '未通过' END) AS firstAuditResultName,
        t1.end_audit_time as endAuditTime, t1.end_audit_result as endAuditResult,
        (CASE WHEN t1.end_audit_result = 0 THEN '待审核' WHEN t1.end_audit_result = 1 THEN '同意' WHEN  t1.end_audit_result = 2 THEN '未通过' END) AS endAuditResultName,
        t1.rmtj_status as rmtjStatus,
        (case WHEN t1.rmtj_status = 1 THEN '未转入' WHEN t1.rmtj_status = 2 THEN '转入中' WHEN t1.rmtj_status = 3 THEN '已转入市人民调解系统' WHEN t1.rmtj_status = 4 THEN '转入失败' end) as rmtjStatusName,
        t1.rmtj_time as rmtjTime, t1.rmtj_case_id as rmtjCaseId
        FROM dyh_th_rmtj_apply t1
        LEFT JOIN dyh_case_info t2 ON t2.id = t1.case_id
        LEFT JOIN dyh_case_info_unfold t3 ON t3.id = t1.case_id
        WHERE t2.delete_Status = 0
        <include refid="pageEndAudit-where-part"/>
        <if test="page.sort != null">
            <foreach collection="page.sort" item="s" index="index" separator="," open="order by ">
                ${s.property} ${s.direction}
            </foreach>
        </if>
        <if test="page.sort == null">
            order by t1.create_time desc
        </if>
        limit #{page.offset}, #{page.size}
    </select>
 
    <!-- 查询某一单位的所有管辖单位id,包括自己 -->
    <select id="listAllUnitId" resultType="java.lang.String">
        SELECT id
        FROM dyh_ct_unit
        START WITH id = #{parentId}
        CONNECT BY PRIOR id = parent_id
    </select>
 
</mapper>