linwei
2024-02-07 aae9bc1ebc7f65cebaec65ac7128f79ca6c827d1
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
<?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.TaskReportForRepairsMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="taskReportForRepairsResultMap" type="org.springblade.modules.task.entity.TaskReportForRepairsEntity">
        <result column="id" property="id"/>
        <result column="type" property="type"/>
        <result column="real_name" property="realName"/>
        <result column="phone" property="phone"/>
        <result column="remark" property="remark"/>
        <result column="image_urls" property="imageUrls"/>
        <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="is_deleted" property="isDeleted"/>
    </resultMap>
 
    <resultMap id="taskReportForRepairsResult" type="org.springblade.modules.task.vo.TaskReportForRepairsVO">
        <result property="id" column="id"/>
        <result property="taskId" column="task_id"/>
        <result property="addressCode" column="address_code"/>
        <result property="type" column="type"/>
        <result property="realName" column="real_name"/>
        <result property="phone" column="phone"/>
        <result property="remark" column="remark"/>
        <result property="imageUrls" column="image_urls"/>
        <result property="confirmUserId" column="confirm_user_id"/>
        <result property="confirmTime" column="confirm_time"/>
        <result property="confirmFlag" column="confirm_flag"/>
        <result property="confirmNotion" column="confirm_notion"/>
        <result property="createTime" column="create_time"/>
        <result property="createUser" column="create_user"/>
        <result property="createDept" column="create_dept"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateUser" column="update_user"/>
        <result property="isDeleted" column="is_deleted"/>
        <result property="status" column="status"/>
        <result property="lng" column="lng"/>
        <result property="lat" column="lat"/>
        <result property="address" column="address"/>
        <result property="viewType" column="view_type"/>
 
 
        <collection property="taskRepairStepList" column="id" select="selectTaskRepairStepList"
                    javaType="java.util.List" ofType="org.springblade.modules.task.entity.TaskRepairStepEntity"
                    autoMapping="true">
            <id property="repairId" column="id"/>
        </collection>
 
        <collection property="taskRepairAppraiseList" column="id" select="selectTaskRepairAppraiseList"
                    javaType="java.util.List" ofType="org.springblade.modules.task.entity.TaskRepairAppraiseEntity"
                    autoMapping="true">
            <id property="repairId" column="id"/>
        </collection>
 
 
    </resultMap>
 
 
    <select id="selectTaskRepairStepList" parameterType="java.lang.Long"
            resultType="org.springblade.modules.task.entity.TaskRepairStepEntity">
        select
        id,
        repair_id,
        content,
        video_list,
        name,
        mobile,
        user_id,
        people_type,
        create_time,
        update_time,
        image_list
        from
        jczz_task_repair_step
        <where>
            <if test="id != null and id != '' ">repair_id = #{id}</if>
        </where>
    </select>
 
 
    <select id="selectTaskRepairAppraiseList" parameterType="java.lang.Long"
            resultType="org.springblade.modules.task.entity.TaskRepairAppraiseEntity">
        select
        id,
        content,
        create_time,
        image_list,
        point,
        repair_id,
        video_list
        from
        jczz_task_repair_appraise
        <where>
            <if test="id != null and id != ''">repair_id = #{id}</if>
        </where>
    </select>
 
 
    <sql id="selectTaskReportForRepairs">
        select id,
               task_id,
               address_code,
               type,
               real_name,
               phone,
               remark,
               image_urls,
               confirm_user_id,
               confirm_time,
               confirm_flag,
               confirm_notion,
               create_time,
               create_user,
               create_dept,
               update_time,
               update_user,
               is_deleted,
               status,
               lng,
               lat,
               address,
               view_type
        from jczz_task_report_for_repairs
    </sql>
 
    <!--自定义分页查询-->
    <select id="selectTaskReportForRepairsPage" resultMap="taskReportForRepairsResult">
        select
        jtrfr.id id,
        jtrfr.task_id,
        jtrfr.address_code,
        jtrfr.type,
        jtrfr.real_name,
        jtrfr.phone,
        jtrfr.remark,
        jtrfr.image_urls,
        jtrfr.confirm_user_id,
        jtrfr.confirm_time,
        jtrfr.confirm_flag,
        jtrfr.confirm_notion,
        jtrfr.create_time,
        jtrfr.create_user,
        jtrfr.create_dept,
        jtrfr.update_time,
        jtrfr.update_user,
        jtrfr.is_deleted,
        jtrfr.status,
        jtrfr.lng,
        jtrfr.lat,
        jtrfr.address,
        jtrfr.view_type,
        br.town_name streetName,
        jg.grid_name,
        jda.aoi_name,
        br.village_name communityName,
        jda.address_name as addressName
        from jczz_task_report_for_repairs jtrfr
        left join jczz_doorplate_address jda on jda.address_code = jtrfr.address_code
        LEFT JOIN jczz_house jh on jh.house_code=jtrfr.address_code
        left join jczz_grid jg on jg.grid_code = jh.grid_code and jg.is_deleted = 0
        left join blade_region br on br.code = jg.community_code
        where jtrfr.is_deleted = 0
        <if test="vo.createUser != null and vo.createUser != ''">
            AND jtrfr.create_user = #{vo.createUser}
        </if>
 
        <if test="vo.streetName != null and vo.streetName != ''">
            AND br.town_name like concat('%',#{vo.streetName},'%')
        </if>
        <if test="vo.communityName != null and vo.communityName != ''">
            AND br.village_name like concat('%',#{vo.communityName},'%')
        </if>
 
        <if test="vo.gridName != null and vo.gridName != ''">
            AND jg.grid_name like concat('%',#{vo.gridName},'%')
        </if>
 
        <if test="vo.aoiName != null and vo.aoiName != ''">
            AND jda.aoi_name like concat('%',#{vo.aoiName},'%')
        </if>
 
        <if test="vo.type != null">
            AND jtrfr.type = #{vo.type}
        </if>
        <if test="vo.realName != null and vo.realName != ''">
            AND jtrfr.real_name like concat('%',#{vo.realName},'%')
        </if>
        <if test="vo.phone != null and vo.phone != ''">
            AND jtrfr.phone like concat('%',#{vo.phone},'%')
        </if>
        <if test="vo.confirmFlag != null">
            AND jtrfr.confirm_flag = #{vo.confirmFlag}
        </if>
 
        <if test="vo.status != null">
            AND jtrfr.status = #{vo.status}
        </if>
        <if test="vo.addressCode != null">
            AND jtrfr.address_code = #{vo.addressCode}
        </if>
        <if test="vo.viewType != null">
            AND jtrfr.view_type = #{vo.viewType}
        </if>
        <if test="vo.startTime != null and vo.startTime != '' and vo.endTime != null and vo.endTime != '' ">
            AND jtrfr.create_time BETWEEN #{vo.startTime} and #{vo.endTime}
        </if>
        <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>
            </choose>
        </if>
        <if test="vo.roleName!=null and vo.roleName!=''">
            <if test="vo.roleName=='网格员'">
                <choose>
                    <when test="list != null and list.size()>0">
                        and (jda.address_code in
                        <foreach collection="list" item="houseCode" separator="," open="(" close=")">
                            #{houseCode}
                        </foreach>
                        or jtrfr.confirm_user_id = #{vo.confirmUserId})
                    </when>
                    <otherwise>
                        and (jtrfr.confirm_user_id = #{vo.confirmUserId})
                    </otherwise>
                </choose>
            </if>
        </if>
 
        <if test="aoiCodeList!=null and aoiCodeList.size()>0">
            and jda.aoi_code in
            <foreach collection="aoiCodeList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
 
        ORDER BY jtrfr.create_time DESC
    </select>
 
    <!--统计查询,个人-->
    <select id="getReportForStatistics" resultType="java.lang.Integer">
 
        SELECT
        COUNT( 1 )
        FROM
        jczz_task_report_for_repairs jtrfr
        LEFT JOIN jczz_doorplate_address jda ON jtrfr.address_code = jda.address_code
        WHERE
        jda.nei_code = #{code}
        AND jtrfr.is_deleted = 0
        <if test="status != null">
            and jtrfr.confirm_flag = #{status}
        </if>
        <if test="type != null">
            and jtrfr.type = #{type}
        </if>
 
        <if test="userId != null and roleType == '1'">
            AND jda.address_code IN (
            SELECT DISTINCT
            jgr.house_code
            FROM
            jczz_grid jg
            LEFT JOIN jczz_gridman jgm ON jg.id = jgm.grid_id
            LEFT JOIN jczz_grid_range jgr ON jgr.grid_id = jg.id
            WHERE
            jgm.user_id = #{userId}
            AND jg.is_deleted = 0
            )
        </if>
        <if test="userId != null and roleType == '3'">
            AND jda.address_code IN (SELECT
            jda.address_code
            FROM
            jczz_doorplate_address jda
            LEFT JOIN jczz_community jc ON jc.CODE = jda.nei_code
            WHERE
            jc.res_police_user_id like concat('%',#{userId},'%'))
            )
        </if>
    </select>
 
 
    <select id="getStatisticsCount" resultType="org.springblade.modules.task.vo.TaskReportStatistics">
        SELECT
        count( 1 ) AS total,
        ifnull( sum( CASE WHEN STATUS = 10 THEN 1 ELSE 0 END ), 0 ) AS handle
        FROM
        jczz_task_report_for_repairs jtrfr
        LEFT JOIN jczz_doorplate_address jda ON jda.address_code = jtrfr.address_code
        WHERE is_deleted = 0
        <if test="userId != null">
            and jtrfr.create_user = #{userId}
        </if>
        <if test="houseCode != null and houseCode != ''">
            and jtrfr.address_code = #{houseCode}
        </if>
        <if test="isAdministrator==2">
            <choose>
                <when test="regionChildCodesList !=null and regionChildCodesList.size()>0">
                    and jda.nei_code in
                    <foreach collection="regionChildCodesList" item="code" open="(" close=")" separator=",">
                        #{code}
                    </foreach>
                </when>
                <otherwise>
                    and jda.nei_code in ('')
                </otherwise>
            </choose>
        </if>
    </select>
 
 
    <select id="getStatistics" resultType="java.lang.Integer">
        SELECT
        count( 1 )
        FROM
        jczz_task_report_for_repairs jtr
        LEFT JOIN jczz_doorplate_address jda ON jtr.address_code = jda.address_code
        <where>
 
            <if test="neiCode != null and neiCode != ''">
                and jda.nei_code = #{neiCode}
            </if>
            <if test="userId != null">
                AND jtr.address_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>
            and jtr.is_deleted = 0
            and jtr.confirm_flag = 1
        </where>
 
 
    </select>
 
    <!--更新状态-临时接口-->
    <update id="updateView">
        update jczz_task_report_for_repairs set view_type = 1
    </update>
 
 
</mapper>