Pu Zhibing
2025-03-17 7f302004e78ca5220a4f88a7fab843964a18739a
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
<?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.panzhihua.sangeshenbian.dao.ComplaintMapper">
 
    <select id="selectComplaintPage" resultType="com.panzhihua.sangeshenbian.model.vo.ComplaintVO">
        SELECT sc.id,
        sc.serial_number,
        sc.time,
        sc.problem_type,
        sc.name,
        sc.contact_number,
        sc.location,
        sc.detailed_address,
        sc.description_title,
        sc.description_content,
        sc.images,
        sc.videos,
        CASE
        WHEN scar.audit_type = 1 AND scar.audit_status = 0 THEN 7
        WHEN scar.audit_type = 2 AND scar.audit_status = 0 THEN 5
        WHEN scar.audit_status = 2 THEN 6
        ELSE sc.status
        END AS status,
        sc.report_type,
        sc.superior_id,
        sc.create_by,
        sc.create_time,
        sc.update_by,
        sc.update_time,
        sc.completion_description,
        sc.completion_images,
        sc.completion_videos,
        sc.completion_other_description,
        sc.completion_time,
        sc.completion_user_id,
        sc.completion_username,
        sc.completion_user_phone,
        sc.closing_time,
        sc.over_time_days,
        sc.latitude,
        sc.longitude,
        scar.audit_type,
        scar.audit_status,
        scar.comment,
        scar.create_time AS reportTime,
        scar.system_user_id,
        scar.reporter,
        scar.department_name,
        scar.department_id
        FROM sgsb_complaint sc
        INNER JOIN sgsb_complaint_audit_record scar ON scar.complaint_id = sc.id AND scar.latest_flag = 1
        <where>
            <if test="isSuperior == 1">
                AND scar.superior_id = #{targetId}
            </if>
            <if test="isSuperior == 0">
                AND sc.create_by = #{targetId}
                AND scar.superior_id = 0
            </if>
            <if test="query.type!=null and query.type == 0">
                AND scar.audit_type != 0 AND scar.audit_status = 0
            </if>
            <if test="query.type!=null and query.type == 1">
                AND sc.status IN(0,1,2) AND scar.audit_type = 0
            </if>
            <if test="query.type!=null and query.type == 2">
                AND sc.status = 3
            </if>
        </where>
        ORDER BY sc.create_time DESC
    </select>
 
 
 
 
    <select id="selectComplaintPage1" resultType="com.panzhihua.sangeshenbian.model.vo.ComplaintVO">
        SELECT sc.id,
        sc.serial_number,
        sc.time,
        sc.problem_type,
        sc.name,
        sc.contact_number,
        sc.location,
        sc.detailed_address,
        sc.description_title,
        sc.description_content,
        sc.images,
        sc.videos,
        CASE
        WHEN sc.status = 0 and scar.audit_type = 1 AND scar.audit_status = 0 THEN 7
        WHEN sc.status = 0 and scar.audit_type = 2 AND scar.audit_status = 0 THEN 5
        WHEN sc.status = 0 and scar.audit_status = 2 THEN 6
        ELSE sc.status
        END AS status,
        sc.report_type,
        sc.superior_id,
        sc.create_by,
        sc.create_time,
        sc.update_by,
        sc.update_time,
        sc.completion_description,
        sc.completion_images,
        sc.completion_videos,
        sc.completion_other_description,
        sc.completion_time,
        sc.completion_user_id,
        sc.completion_username,
        sc.completion_user_phone,
        sc.closing_time,
        sc.over_time_days,
        sc.latitude,
        sc.longitude,
        scar.audit_type,
        scar.audit_status,
        scar.comment,
        scar.create_time AS reportTime,
        scar.system_user_id,
        scar.reporter,
        scar.department_name,
        scar.department_id
        FROM sgsb_complaint sc
        INNER JOIN sgsb_complaint_audit_record scar ON scar.complaint_id = sc.id and scar.latest_flag = 1
        <where>
            scar.latest_flag = 1
            <if test="1 == accountLevel">
                and sc.city_code = #{targetId}
            </if>
            <if test="2 == accountLevel">
                and (sc.districts_code = #{targetId} || sc.id in (select complaint_id from sgsb_complaint_audit_record where audit_type = 3 and audit_status = 1 and report_type = #{accountLevel} and superior_id = #{targetId}))
            </if>
            <if test="3 == accountLevel">
                and (sc.street_id = #{streetId} || sc.id in (select complaint_id from sgsb_complaint_audit_record where audit_type = 3 and audit_status = 1 and report_type = #{accountLevel} and superior_id = #{targetId}))
            </if>
            <if test="4 == accountLevel">
                and (sc.community_id = #{targetId} || sc.id in (select complaint_id from sgsb_complaint_audit_record where audit_type = 3 and audit_status = 1 and report_type = #{accountLevel} and superior_id = #{targetId}))
            </if>
            <if test="5 == accountLevel">
                and (sc.party_member_id = #{targetId} || sc.id in (select complaint_id from sgsb_complaint_audit_record where audit_type = 3 and audit_status = 1 and report_type = #{accountLevel} and superior_id = #{targetId}))
            </if>
            <if test="query.type!=null and query.type == 0">
                AND sc.status IN(0,1,2) and scar.audit_status = 0
            </if>
            <if test="query.type!=null and query.type == 1">
                AND sc.status IN(0,1,2) and scar.audit_status != 0
            </if>
            <if test="query.type!=null and query.type == 2">
                AND sc.status = 3
            </if>
        </where>
        ORDER BY sc.create_time DESC
    </select>
 
 
 
 
    <select id="getDetail" resultType="com.panzhihua.sangeshenbian.model.vo.ComplaintVO">
        SELECT sc.id,
        sc.serial_number,
        sc.time,
        sc.problem_type,
        sc.name,
        sc.contact_number,
        sc.location,
        sc.detailed_address,
        sc.description_title,
        sc.description_content,
        sc.images,
        sc.videos,
        CASE
        WHEN sc.status = 0 and scar.audit_type = 1 AND scar.audit_status = 0 THEN 7
        WHEN sc.status = 0 and scar.audit_type = 2 AND scar.audit_status = 0 THEN 5
        WHEN sc.status = 0 and scar.audit_status = 2 THEN 6
        ELSE sc.status
        END          AS status,
        sc.report_type,
        sc.superior_type,
        sc.superior_id,
        sc.create_by,
        sc.create_time,
        sc.update_by,
        sc.update_time,
        sc.completion_description,
        sc.completion_images,
        sc.completion_videos,
        sc.completion_other_description,
        sc.completion_time,
        sc.completion_user_id,
        sc.completion_username,
        sc.completion_user_phone,
        sc.closing_time,
        sc.over_time_days,
        sc.latitude,
        sc.longitude,
        scar.audit_type,
        scar.audit_status,
        scar.comment,
        scar.images,
        scar.videos,
        scar.create_time AS reportTime,
        scar.system_user_id,
        scar.reporter,
        scar.department_name,
        scar.department_id,
        scar.comment,
        ifnull((select a.create_time from sgsb_complaint_audit_record a where a.audit_status != 0 and a.complaint_id = #{id} order by a.sort desc limit 0, 1), "") AS auditTime,
        ifnull((select a.reject_reason from sgsb_complaint_audit_record a where a.audit_status != 0 and a.complaint_id = #{id} order by a.sort desc limit 0, 1), "") as rejectReason,
        su.nick_name,
        su.phone,
        ifnull((select b.nick_name from sgsb_complaint_audit_record a left join sys_user b on (a.create_by = b.user_id) where a.audit_status != 0 and a.complaint_id = #{id} order by a.sort desc limit 0, 1), "") AS auditorName,
        ifnull((select b.phone from sgsb_complaint_audit_record a left join sys_user b on (a.create_by = b.user_id) where a.audit_status != 0 and a.complaint_id = #{id} order by a.sort desc limit 0, 1), "") AS auditorPhone
        FROM sgsb_complaint sc
        LEFT JOIN sys_user su ON su.user_id = sc.create_by
        LEFT JOIN sgsb_complaint_audit_record scar ON scar.complaint_id = sc.id and scar.latest_flag = 1
        <where>
            sc.id = #{id}
        </where>
    </select>
    <select id="getTodoList" resultType="com.panzhihua.sangeshenbian.model.vo.ComplaintTodoVO">
        SELECT sc.id,
        sc.description_title,
        sc.closing_time,
        su.image_url
        FROM sgsb_complaint sc
        LEFT JOIN sys_user su  ON su.user_id = sc.create_by
        <where>
            sc.status = 0
            <if test="isSuperior == 1 and targetId != null">
                AND sc.superior_id = #{targetId}
            </if>
            <if test="isSuperior == 0 and targetId != null">
                AND sc.create_by = #{targetId}
            </if>
        </where>
        ORDER BY sc.create_time DESC
    </select>
    <select id="pageList" resultType="com.panzhihua.sangeshenbian.model.vo.ComplaintVO">
        SELECT * FROM(
        SELECT sc.id,
        sc.serial_number,
        sc.time,
        sc.problem_type,
        sc.name,
        sc.contact_number,
        sc.location,
        sc.detailed_address,
        sc.description_title,
        sc.description_content,
        sc.images,
        sc.videos,
        CASE
        WHEN sc.status = 0 and scar.audit_type = 1 AND scar.audit_status = 0 THEN 4
        WHEN sc.status = 0 and scar.audit_type = 2 AND scar.audit_status = 0 THEN 4
        ELSE sc.status
        END AS status,
        sc.report_type,
        sc.report_user_name,
        sc.report_user_phone,
        sc.superior_id,
        sc.city_code,
        sc.districts_code,
        sc.street_id,
        sc.community_id,
        sc.party_member_id,
        sc.create_by,
        sc.create_time,
        sc.update_by,
        sc.update_time,
        sc.completion_description,
        sc.completion_images,
        sc.completion_videos,
        sc.completion_other_description,
        sc.completion_time,
        sc.completion_user_id,
        sc.completion_username,
        sc.completion_user_phone,
        sc.closing_time,
        sc.over_time_days,
        sc.latitude,
        sc.longitude,
        scar.audit_type,
        scar.audit_status,
        scar.comment,
        scar.create_time AS reportTime,
        scar.system_user_id,
        scar.reporter,
        scar.department_name,
        scar.department_id
        FROM sgsb_complaint sc
        INNER JOIN sgsb_complaint_audit_record scar ON scar.complaint_id = sc.id and scar.latest_flag = 1
        ) AS t
        <where>
            <if test="1 == loginUserInfo.accountLevel">
                and t.city_code = 510400
            </if>
            <if test="2 == loginUserInfo.accountLevel">
                and (t.districts_code = #{loginUserInfo.districtsCode} || t.id in (select complaint_id from
                sgsb_complaint_audit_record where audit_type = 3 and audit_status = 1 and report_type =
                #{loginUserInfo.accountLevel} and superior_id = #{loginUserInfo.districtsCode}))
            </if>
            <if test="3 == loginUserInfo.accountLevel">
                and (t.street_id = #{loginUserInfo.streetId} || t.id in (select complaint_id from
                sgsb_complaint_audit_record where audit_type = 3 and audit_status = 1 and report_type =
                #{loginUserInfo.accountLevel} and superior_id = #{loginUserInfo.streetId}))
            </if>
            <if test="4 == loginUserInfo.accountLevel">
                and (t.community_id = #{loginUserInfo.communityId} || t.id in (select complaint_id from
                sgsb_complaint_audit_record where audit_type = 3 and audit_status = 1 and report_type =
                #{loginUserInfo.accountLevel} and superior_id = #{loginUserInfo.communityId}))
            </if>
            <if test="query.status!=null and query.status!=''">
                AND t.status = #{query.status}
            </if>
            <if test="query.reportUserName != null and query.reportUserName!=''">
                AND t.report_user_name LIKE CONCAT('%',#{query.reportUserName},'%')
            </if>
            <if test="query.reportUserPhone != null and query.reportUserPhone!=''">
                AND t.report_user_phone LIKE CONCAT('%',#{query.phone},'%')
            </if>
            <if test="query.name != null and query.name!=''">
                AND t.name LIKE CONCAT('%',#{query.name},'%')
            </if>
            <if test="query.contactNumber != null and query.contactNumber!=''">
                AND t.contact_number LIKE CONCAT('%',#{query.contactNumber},'%')
            </if>
            <if test="query.startTime != null and query.endTime!=null">
                AND t.create_time BETWEEN #{query.startTime} AND #{query.endTime}
            </if>
            <if test="query.problemType != null and query.problemType!=''">
                AND t.problem_type =#{query.problemType}
            </if>
        </where>
        GROUP BY t.id
        ORDER BY t.create_time DESC
    </select>
    <select id="getList" resultType="com.panzhihua.sangeshenbian.model.vo.ComplaintVO">
        SELECT * FROM(
        SELECT sc.id,
        sc.serial_number,
        sc.time,
        sc.problem_type,
        sc.name,
        sc.contact_number,
        sc.location,
        sc.detailed_address,
        sc.description_title,
        sc.description_content,
        sc.images,
        sc.videos,
        CASE
        WHEN sc.status = 0 and scar.audit_type = 1 AND scar.audit_status = 0 THEN 4
        WHEN sc.status = 0 and scar.audit_type = 2 AND scar.audit_status = 0 THEN 4
        ELSE sc.status
        END AS status,
        sc.report_type,
        sc.report_user_name,
        sc.report_user_phone,
        sc.superior_id,
        sc.city_code,
        sc.districts_code,
        sc.street_id,
        sc.community_id,
        sc.party_member_id,
        sc.create_by,
        sc.create_time,
        sc.update_by,
        sc.update_time,
        sc.completion_description,
        sc.completion_images,
        sc.completion_videos,
        sc.completion_other_description,
        sc.completion_time,
        sc.completion_user_id,
        sc.completion_username,
        sc.completion_user_phone,
        sc.closing_time,
        sc.over_time_days,
        sc.latitude,
        sc.longitude,
        scar.audit_type,
        scar.audit_status,
        scar.comment,
        scar.create_time AS reportTime,
        scar.system_user_id,
        scar.reporter,
        scar.department_name,
        scar.department_id
        FROM sgsb_complaint sc
        INNER JOIN sgsb_complaint_audit_record scar ON scar.complaint_id = sc.id and scar.latest_flag = 1
        ) AS t
        <where>
            <if test="1 == loginUserInfo.accountLevel">
                and t.city_code = 510400
            </if>
            <if test="2 == loginUserInfo.accountLevel">
                and (t.districts_code = #{loginUserInfo.districtsCode} || t.id in (select complaint_id from
                sgsb_complaint_audit_record where audit_type = 3 and audit_status = 1 and report_type =
                #{loginUserInfo.accountLevel} and superior_id = #{loginUserInfo.districtsCode}))
            </if>
            <if test="3 == loginUserInfo.accountLevel">
                and (t.street_id = #{loginUserInfo.streetId} || t.id in (select complaint_id from
                sgsb_complaint_audit_record where audit_type = 3 and audit_status = 1 and report_type =
                #{loginUserInfo.accountLevel} and superior_id = #{loginUserInfo.streetId}))
            </if>
            <if test="4 == loginUserInfo.accountLevel">
                and (t.community_id = #{loginUserInfo.communityId} || t.id in (select complaint_id from
                sgsb_complaint_audit_record where audit_type = 3 and audit_status = 1 and report_type =
                #{loginUserInfo.accountLevel} and superior_id = #{loginUserInfo.communityId}))
            </if>
            <if test="query.status!=null and query.status == 0">
                AND t.status = #{query.status}
            </if>
            <if test="query.reportUserName != null and query.reportUserName!=''">
                AND t.report_user_name LIKE CONCAT('%',#{query.reportUserName},'%')
            </if>
            <if test="query.reportUserPhone != null and query.reportUserPhone!=''">
                AND t.report_user_phone LIKE CONCAT('%',#{query.phone},'%')
            </if>
            <if test="query.name != null and query.name!=''">
                AND t.name LIKE CONCAT('%',#{query.name},'%')
            </if>
            <if test="query.contactNumber != null and query.contactNumber!=''">
                AND t.contact_number LIKE CONCAT('%',#{query.contactNumber},'%')
            </if>
            <if test="query.startTime != null and query.endTime!=null">
                AND t.create_time BETWEEN #{query.startTime} AND #{query.endTime}
            </if>
            <if test="query.problemType != null and query.problemType!=''">
                AND t.problem_type =#{query.problemType}
            </if>
        </where>
        GROUP BY t.id
        ORDER BY t.create_time DESC
    </select>
    
    
    <select id="getTimeoutAndNotComment" resultType="com.panzhihua.sangeshenbian.model.entity.Complaint">
        select * from sgsb_complaint where status = 3 and DATE_ADD(completion_time, INTERVAL 10 DAY) &lt;= NOW() and id not in (select complaint_id from sgsb_complaint_comment where del_flag = 0)
    </select>
    <select id="getDetailBg" resultType="com.panzhihua.sangeshenbian.model.vo.ComplaintVO"
            parameterType="java.lang.Long">
        SELECT * FROM(
                         SELECT sc.id,
                                sc.serial_number,
                                sc.time,
                                sc.problem_type,
                                sc.name,
                                sc.contact_number,
                                sc.location,
                                sc.detailed_address,
                                sc.description_title,
                                sc.description_content,
                                sc.images,
                                sc.videos,
                                CASE
                                    WHEN sc.status = 0 and scar.audit_type = 1 AND scar.audit_status = 0 THEN 4
                                    WHEN sc.status = 0 and scar.audit_type = 2 AND scar.audit_status = 0 THEN 4
                                    ELSE sc.status
                                    END AS status,
                                sc.report_type,
                                sc.report_user_name,
                                sc.report_user_phone,
                                sc.superior_id,
                                sc.city_code,
                                sc.districts_code,
                                sc.street_id,
                                sc.community_id,
                                sc.party_member_id,
                                sc.create_by,
                                sc.create_time,
                                sc.update_by,
                                sc.update_time,
                                sc.completion_description,
                                sc.completion_images,
                                sc.completion_videos,
                                sc.completion_other_description,
                                sc.completion_time,
                                sc.completion_user_id,
                                sc.completion_username,
                                sc.completion_user_phone,
                                sc.closing_time,
                                sc.over_time_days,
                                sc.latitude,
                                sc.longitude,
                                scar.audit_type,
                                scar.audit_status,
                                scar.comment,
                                scar.create_time AS reportTime,
                                scar.system_user_id,
                                scar.reporter,
                                scar.department_name,
                                scar.department_id
                         FROM sgsb_complaint sc
                                  INNER JOIN sgsb_complaint_audit_record scar ON scar.complaint_id = sc.id and scar.latest_flag = 1
                     ) AS t
        WHERE t.id = #{id}
        GROUP BY t.id
    </select>
</mapper>