mitao
2025-03-16 44c6754be97b8772a915f7bc54b44ac736c7673b
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
<?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 and scar.superior_id = #{targetId}
        <where>
            scar.latest_flag = 1
            <if test="null != accountLevel and accountLevel == 5">
                and scar.report_type = 5 and scar.superior_id = #{targetId}
                <if test="query.type == 0">
                    and scar.audit_type != 0 AND scar.audit_status = 0
                </if>
            </if>
            <if test="null != accountLevel and accountLevel == 4">
                <if test="query.type==null">
                    and (
                    (scar.report_type = 4 and scar.superior_id = #{targetId}) or (scar.report_type = 4 and scar.superior_id = #{targetId})
                    or ( scar.audit_type != 0 AND scar.audit_status != 1 and scar.report_type = 4 and scar.superior_id =  #{targetId})
                    )
                </if>
                <if test="query.type == 0">
                    and ( scar.audit_type != 0 AND scar.audit_status = 0 and scar.report_type = 4 and scar.superior_id =  #{targetId})
                </if>
            </if>
            <if test="null != accountLevel and accountLevel == 3">
                <if test="query.type==null">
                    and (
                    (scar.report_type = 3 and scar.superior_id = #{targetId}) or (scar.report_type = 3 and scar.superior_id = #{targetId})
                    or (scar.audit_type != 0 AND scar.audit_status != 1 and scar.report_type = 3 and scar.superior_id =  #{targetId})
                    )
                </if>
                <if test="query.type == 0">
                    and (scar.audit_type != 0 AND scar.audit_status = 0 and scar.report_type = 3 and scar.superior_id =  #{targetId})
                </if>
            </if>
            <if test="null != accountLevel and accountLevel == 2">
                <if test="query.type==null">
                    and ((scar.report_type = 2 and scar.superior_id = #{targetId}) or (scar.report_type = 2 and scar.superior_id = #{targetId})
                    or (scar.audit_type != 0 AND scar.audit_status != 1 and scar.report_type = 2 and scar.superior_id =  #{targetId})
                    )
                </if>
                <if test="query.type == 0">
                    and (scar.audit_type != 0 AND scar.audit_status = 0 and scar.report_type = 2 and scar.superior_id =  #{targetId})
                </if>
            </if>
            <if test="null != accountLevel and accountLevel == 1">
                <if test="query.type == null">
                    and ((scar.report_type = 1 and scar.superior_id = #{targetId}) or (scar.report_type = 1 and scar.superior_id = #{targetId})
                    or (scar.audit_type != 0 AND scar.audit_status != 1 and scar.report_type = 1 and scar.superior_id =  #{targetId}))
                </if>
                <if test="query.type == 0">
                    and (scar.audit_type != 0 AND scar.audit_status = 0 and scar.report_type = 1 and scar.superior_id =  #{targetId})
                </if>
            </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 and scar.superior_id = #{targetId}
        LEFT JOIN sys_user su2 ON su2.user_id = scar.auditor_id AND scar.audit_status != 0
        <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>
</mapper>