Pu Zhibing
2025-03-16 b892c2c689bb9464006dc184459fb5a5db5a4827
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
<?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="null != streetId">
                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="null != communityId">
                and (sc.community_id = #{communityId} || 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="null != partyMemberId">
                and (sc.party_member_id = #{partyMemberId} || 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>
    <select id="getList" resultType="com.panzhihua.sangeshenbian.model.vo.ComplaintVO">
 
    </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>
</mapper>