zhongrj
2024-01-26 8ccc73a8b619469482d790aebecd6d1f3714a417
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
<?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="org.springblade.modules.task.mapper.TaskMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="taskResultMap" type="org.springblade.modules.task.vo.TaskVO">
        <result column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="type" property="type"/>
        <result column="frequency" property="frequency"/>
        <result column="remark" property="remark"/>
        <result column="create_time" property="createTime"/>
        <result column="create_user" property="createUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="status" property="status"/>
        <result column="source" property="source"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="house_code" property="houseCode"/>
        <result column="report_type" property="reportType"/>
    </resultMap>
 
 
    <select id="selectTaskPage" resultMap="taskResultMap">
        SELECT
        IFNULL( jda.address_name, jp.location ) AS address_name,
        IFNULL( jgr.district_code, ' ' ) aoiCode,
        jda.region_code,
        jg.community_code neiCode,
        jc.street_code streetCode,
        jp.principal as realName,
        jp.principal_phone as phone,
        jt.id,
        jt.NAME,
        jt.type,
        jt.frequency,
        jt.remark,
        jt.create_time,
        jt.create_user,
        jt.update_time,
        jt.update_user,
        jt.STATUS,
        jt.source,
        jt.is_deleted,
        jt.house_code,
        jt.report_type
        FROM
        jczz_task jt
        LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jt.house_code
        LEFT JOIN jczz_place jp ON locate(jt.house_code,jp.house_code>0 and jp.is_deleted = 0
        LEFT JOIN blade_user bu on bu.id = jt.create_user and bu.is_deleted = 0
        LEFT JOIN jczz_grid_range jgr on jgr.house_code= jt.house_code
        LEFT JOIN jczz_grid jg on jg.id = jgr.grid_id and jg.is_deleted = 0
        LEFT JOIN jczz_community jc on jc.`code`= jg.community_code and jc.is_deleted = 0
        <where>
            <if test="task.userId != null and task.userId != ''">
                AND jt.house_code IN (
                SELECT
                jgr.house_code
                FROM
                jczz_grid_range jgr
                LEFT JOIN jczz_grid jg ON jg.id = jgr.grid_id
                LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
                WHERE
                jg.is_deleted = 0
                <if test="isAdministrator==2">
                    <choose>
                        <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                            and jg.community_code in
                            <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                                #{code}
                            </foreach>
                        </when>
                        <otherwise>
                            and jg.community_code in ('')
                        </otherwise>
                    </choose>
                </if>
                AND jgm.user_id = #{task.userId} )
            </if>
 
            <if test="task.status != null and task.status != null">
                and jt.status = #{task.status}
            </if>
 
            <if test="task.aoiCode != null and task.aoiCode != null">
                and jgr.district_code = #{task.aoiCode}
            </if>
 
            <if test="task.neiCode != null and task.neiCode != null">
                and jg.community_code = #{task.neiCode}
            </if>
 
            <if test="task.communityName != null and task.communityName != null">
                and jc.name like concat('%', #{task.communityName}, '%')
            </if>
 
            <if test="task.streetCode != null and task.streetCode != null">
                and jc.street_code = #{task.streetCode}
            </if>
 
            <if test="task.realName != null and task.realName != null">
                and bu.name like concat('%', #{task.realName}, '%')
            </if>
 
            <if test="task.phone != null and task.phone != null">
                and bu.phone like concat('%', #{task.phone}, '%')
            </if>
 
            <if test="task.communityName != null and task.communityName != null">
                and jc.name like concat('%', #{task.communityName}, '%')
            </if>
 
            <if test="task.districtName != null and task.districtName != null">
                and jgr.district_name like concat('%', #{task.districtName}, '%')
            </if>
 
            <if test="task.frequency != null and task.frequency != ''">
                and jt.frequency = #{task.frequency}
            </if>
            <if test="task.name != null and task.name != ''">
                and jt.name like concat('%', #{task.name}, '%')
            </if>
            <if test="task.id != null ">and jt.id = #{task.id}</if>
            <if test="task.type != null ">and jt.type = #{task.type}</if>
            <if test="task.remark != null  and task.remark != ''">and jt.remark = #{task.remark}</if>
            <if test="task.createTime != null ">and jt.create_time = #{task.createTime}</if>
            <if test="task.createUser != null ">and jt.create_user = #{task.createUser}</if>
            <if test="task.updateTime != null ">and jt.update_time = #{task.updateTime}</if>
            <if test="task.updateUser != null ">and jt.update_user = #{task.updateUser}</if>
            <if test="task.isDeleted != null ">and jt.is_deleted = #{task.isDeleted}</if>
            <if test="task.houseCode != null  and task.houseCode != ''">and jt.house_code = #{task.houseCode}</if>
            <if test="task.startTime != null and task.startTime != '' and task.endTime != null and task.endTime != '' ">
                AND jt.create_time BETWEEN #{task.startTime} and #{task.endTime}
            </if>
            <!-- 取保候审 或 报事报修 -->
            <if test="task.reportType != null and task.reportType != 2 ">
                and jt.report_type = #{task.reportType}
            </if>
            <!-- 场所店铺 -->
            <if test="task.reportType != null and task.reportType == 2 ">
                and jt.report_type in (2,3,4,5,6)
            </if>
            <if test="task.reportType == null">
                and jt.report_type in (2,3,4,5,6)
            </if>
            and jt.is_deleted = 0
            and jt.house_code is not null
            order by jt.create_time desc
        </where>
    </select>
 
 
    <select id="selectTaskCount" resultType="int" parameterType="org.springblade.modules.task.vo.TaskVO">
        SELECT
        count( 1 )
        FROM
        jczz_task jt
        LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jt.house_code
        <where>
            <if test="status != null">
                and jt.status = #{status}
            </if>
            <if test="frequency != null">
                and jt.frequency = #{frequency}
            </if>
            <if test="type != null">
                and jt.type = #{type}
            </if>
            <!-- 取保候审 -->
            <if test="reportType != null and reportType == 1 ">
                and jt.report_type = 1
            </if>
            <!-- 场所店铺 -->
            <if test="reportType != null and reportType == 2 ">
                and jt.report_type in (2,3,4,5,6)
            </if>
 
            <if test="name != null and name != ''">
                and jt.name like concat('%', #{name}, '%')
            </if>
            <if test="neiCode != null and neiCode != ''">
                and jda.nei_code = #{neiCode}
            </if>
            <if test="userId != null">
                AND jt.house_code IN (
                SELECT
                jgr.house_code
                FROM
                jczz_grid_range jgr
                LEFT JOIN jczz_grid jg ON jg.id = jgr.grid_id
                LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
                WHERE
                jg.is_deleted = 0
                AND jgm.user_id = #{userId} )
            </if>
        </where>
        order by jt.create_time desc
    </select>
 
 
    <select id="selectTaskPageBy" resultType="org.springblade.modules.task.vo.TaskVO">
        SELECT
        jt.* ,
        jda.address_name
        FROM
        jczz_task jt
        LEFT JOIN jczz_doorplate_address jda ON jt.house_code = jda.address_code
        LEFT JOIN jczz_community jc ON jc.CODE = jda.nei_code
        <where>
            <if test="task.reportType != null and task.reportType != '' and task.reportType == 1">
                AND jt.report_type = #{task.reportType}
            </if>
 
            <if test="task.reportType == null or task.reportType == ''">
                AND jt.report_type in (2,3,6)
            </if>
            <if test="task.userId != null and task.userId != ''">
                AND jc.res_police_user_id like concat('%',#{task.userId},'%')
            </if>
            <if test="isAdministrator==2">
                <choose>
                    <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                        and jc.code in
                        <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                            #{code}
                        </foreach>
                    </when>
                    <otherwise>
                        and jc.code in ('')
                    </otherwise>
                </choose>
            </if>
        </where>
    </select>
 
    <select id="getBailReportingPage" resultType="org.springblade.modules.task.vo.TaskVO">
        SELECT
        IFNULL( jda.address_name, jp.location ) AS address_name,
        jtbre.apply_name,
        jgr.district_code aoiCode,
        jda.region_code,
        jg.community_code neiCode,
        jc.street_code streetCode,
        bu.name realName,
        bu.phone,
        jt.id,
        jt.NAME,
        jt.type,
        jt.frequency,
        jt.remark,
        jt.create_time,
        jt.create_user,
        jt.update_time,
        jt.update_user,
        jt.STATUS,
        jt.source,
        jt.is_deleted,
        jt.house_code,
        jt.report_type
        FROM
        jczz_task jt
        LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jt.house_code
        LEFT JOIN jczz_place jp ON locate(jt.house_code,jp.house_code>0 and jp.is_deleted = 0
        LEFT JOIN blade_user bu on bu.id = jt.create_user and bu.is_deleted = 0
        LEFT JOIN jczz_grid_range jgr on jgr.house_code= jt.house_code
        LEFT JOIN jczz_grid jg on jg.id = jgr.grid_id and jg.is_deleted = 0
        LEFT JOIN jczz_community jc on jc.`code`= jg.community_code and jc.is_deleted = 0
        LEFT JOIN jczz_task_bail_reporting_event jtbre on jtbre.task_id = jt.id and jtbre.is_deleted = 0
        <where>
            <if test="task.userId != null and task.userId != ''">
                AND jt.house_code IN (
                SELECT
                jgr.house_code
                FROM
                jczz_grid_range jgr
                LEFT JOIN jczz_grid jg ON jg.id = jgr.grid_id
                LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
                WHERE
                jg.is_deleted = 0
                <if test="task.communityCode != null and task.communityCode != ''">
                    and jg.community_code = #{task.communityCode}
                </if>
                AND jgm.user_id = #{task.userId} )
            </if>
 
            <if test="task.status != null and task.status != null">
                and jt.status = #{task.status}
            </if>
 
            <if test="task.aoiCode != null and task.aoiCode != null">
                and jgr.district_code = #{task.aoiCode}
            </if>
 
            <if test="task.neiCode != null and task.neiCode != null">
                and jg.community_code = #{task.neiCode}
            </if>
 
            <if test="task.streetCode != null and task.streetCode != null">
                and jc.street_code = #{task.streetCode}
            </if>
 
            <if test="task.realName != null and task.realName != null">
                and bu.name like concat('%', #{task.realName}, '%')
            </if>
 
            <if test="task.phone != null and task.phone != null">
                and bu.phone like concat('%', #{task.phone}, '%')
            </if>
 
            <if test="task.communityName != null and task.communityName != null">
                and jc.name like concat('%', #{task.communityName}, '%')
            </if>
 
            <if test="task.districtName != null and task.districtName != null">
                and jgr.district_name like concat('%', #{task.districtName}, '%')
            </if>
 
            <if test="task.frequency != null and task.frequency != ''">
                and jt.frequency = #{task.frequency}
            </if>
            <if test="task.name != null and task.name != ''">
                and jt.name like concat('%', #{task.name}, '%')
            </if>
            <if test="task.id != null ">and jt.id = #{task.id}</if>
            <if test="task.type != null ">and jt.type = #{task.type}</if>
            <if test="task.remark != null  and task.remark != ''">and jt.remark = #{task.remark}</if>
            <if test="task.createTime != null ">and jt.create_time = #{task.createTime}</if>
            <if test="task.createUser != null ">and jt.create_user = #{task.createUser}</if>
            <if test="task.updateTime != null ">and jt.update_time = #{task.updateTime}</if>
            <if test="task.updateUser != null ">and jt.update_user = #{task.updateUser}</if>
            <if test="task.isDeleted != null ">and jt.is_deleted = #{task.isDeleted}</if>
            <if test="task.houseCode != null  and task.houseCode != ''">and jt.house_code = #{task.houseCode}</if>
            <if test="task.startTime != null and task.startTime != '' and task.endTime != null and task.endTime != '' ">
                AND jt.create_time BETWEEN #{task.startTime} and #{task.endTime}
            </if>
            <!-- 取保候审 或 报事报修 -->
            <if test="task.reportType != null and task.reportType != 2 ">
                and jt.report_type = #{task.reportType}
            </if>
 
            and jt.is_deleted = 0
            and jt.house_code is not null
            order by jt.create_time desc
        </where>
    </select>
 
 
</mapper>