Pu Zhibing
2025-02-27 f0a9a41697a8568e8b3bd3436c450e68b3298916
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
<?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.service_community.dao.ComFmsServiceDAO">
 
    <resultMap type="com.panzhihua.service_community.entity.ComFmsService" id="ComFmsServiceMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="userName" column="user_name" jdbcType="VARCHAR"/>
        <result property="userId" column="user_id" jdbcType="INTEGER"/>
        <result property="phone" column="phone" jdbcType="VARCHAR"/>
        <result property="serviceContent" column="service_content" jdbcType="VARCHAR"/>
        <result property="serviceImage" column="service_image" jdbcType="VARCHAR"/>
        <result property="approvalContent" column="approval_content" jdbcType="VARCHAR"/>
        <result property="approvalAt" column="approval_at" jdbcType="TIMESTAMP"/>
        <result property="memberId" column="member_id" jdbcType="INTEGER"/>
        <result property="serviceStatus" column="service_status" jdbcType="INTEGER"/>
        <result property="serviceAt" column="service_at" jdbcType="TIMESTAMP"/>
        <result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
        <result property="createdBy" column="created_by" jdbcType="INTEGER"/>
        <result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
        <result property="updatedBy" column="updated_by" jdbcType="INTEGER"/>
        <result property="communityId" column="community_id" jdbcType="INTEGER"/>
    </resultMap>
 
    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.com_fms_service(user_name, user_id, phone, service_content, service_image, approval_content, approval_at, member_id, service_status, service_at, created_at, created_by, updated_at, updated_by, community_id)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.userName}, #{entity.userId}, #{entity.phone}, #{entity.serviceContent}, #{entity.serviceImage}, #{entity.approvalContent}, #{entity.approvalAt}, #{entity.memberId}, #{entity.serviceStatus}, #{entity.serviceAt}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt}, #{entity.updatedBy}, #{entity.communityId})
        </foreach>
    </insert>
 
 
    <select id="getLastId" resultType="String">
        SELECT LAST_INSERT_ID()
    </select>
 
    <insert id="addBracelet" parameterType="com.panzhihua.service_community.entity.ComFmsService" >
        insert into smart_life.com_fms_service
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="entitie.userName != null">
                user_name,
            </if>
            <if test="entitie.userId != null">
                user_id,
            </if>
            <if test="entitie.phone != null">
                phone,
            </if>
            <if test="entitie.serviceContent != null">
                service_content,
            </if>
            <if test="entitie.serviceImage != null">
                service_image,
            </if>
            <if test="entitie.approvalContent != null">
                approval_content,
            </if>
            <if test="entitie.approvalAt != null">
                approval_at,
            </if>
            <if test="entitie.memberId != null">
                member_id,
            </if>
            <if test="entitie.serviceStatus != null">
                service_status,
            </if>
            <if test="entitie.serviceAt != null">
                service_at,
            </if>
            <if test="entitie.createdBy != null">
                created_by,
            </if>
            <if test="entitie.updatedBy != null">
                updated_by,
            </if>
            <if test="entitie.communityId != null">
                community_id,
            </if>
            created_at
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="entitie.userName != null">
                #{entitie.userName},
            </if>
            <if test="entitie.userId != null">
                #{entitie.userId},
            </if>
            <if test="entitie.phone != null">
                #{entitie.phone},
            </if>
            <if test="entitie.serviceContent != null">
                #{entitie.serviceContent},
            </if>
            <if test="entitie.serviceImage != null">
                #{entitie.serviceImage},
            </if>
            <if test="entitie.approvalContent != null">
                #{entitie.approvalContent},
            </if>
            <if test="entitie.approvalAt != null">
                #{entitie.approvalAt},
            </if>
            <if test="entitie.memberId != null">
                #{entitie.memberId},
            </if>
            <if test="entitie.serviceStatus != null">
                #{entitie.serviceStatus},
            </if>
            <if test="entitie.serviceAt != null">
                #{entitie.serviceAt},
            </if>
            <if test="entitie.createdBy != null">
                #{entitie.createdBy},
            </if>
            <if test="entitie.updatedBy != null">
                #{entitie.updatedBy},
            </if>
            <if test="entitie.communityId != null">
                #{entitie.communityId},
            </if>
            sysdate()
        </trim>
    </insert>
 
 
 
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into smart_life.com_fms_service(user_name, user_id, phone, service_content, service_image, approval_content, approval_at, member_id, service_status, service_at, created_at, created_by, updated_at, updated_by, community_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.userName}, #{entity.userId}, #{entity.phone}, #{entity.serviceContent}, #{entity.serviceImage}, #{entity.approvalContent}, #{entity.approvalAt}, #{entity.memberId}, #{entity.serviceStatus}, #{entity.serviceAt}, #{entity.createdAt}, #{entity.createdBy}, #{entity.updatedAt}, #{entity.updatedBy}, #{entity.communityId})
        </foreach>
        on duplicate key update
         user_name = values(user_name) , user_id = values(user_id) , phone = values(phone) , service_content = values(service_content) , service_image = values(service_image) , approval_content = values(approval_content) , approval_at = values(approval_at) , member_id = values(member_id) , service_status = values(service_status) , service_at = values(service_at) , created_at = values(created_at) , created_by = values(created_by) , updated_at = values(updated_at) , updated_by = values(updated_by) , community_id = values(community_id)     </insert>
    <select id="pageFmsServiceAdmin" resultType="com.panzhihua.common.model.vos.community.fms.ComFmsServiceVO">
        SELECT t1.id, t1.user_name, t1.phone, t1.created_at, t1.service_content, t2.`name` AS serviceMember, t3.star_level, t1.service_status
        FROM com_fms_service t1
        LEFT JOIN com_fms_team_member t2 ON t1.member_id = t2.id
        LEFT JOIN com_fms_service_evaluations t3 ON t1.id = t3.service_id
        WHERE t1.community_id = #{adminDTO.communityId}
        <if test="adminDTO.keyword != null and adminDTO.keyword != &quot;&quot;">
            AND(t1.user_name LIKE CONCAT('%',#{adminDTO.keyword},'%')
            OR t2.`name` LIKE CONCAT('%',#{adminDTO.keyword},'%')
            OR t1.service_content LIKE CONCAT('%',#{adminDTO.keyword},'%'))
        </if>
        <if test="adminDTO.serviceStatus != null">
            AND t1.service_status = #{adminDTO.serviceStatus}
        </if>
        ORDER BY t1.created_at DESC
    </select>
    <select id="detailFmsServiceAdmin"
            resultType="com.panzhihua.common.model.vos.community.fms.ComFmsServiceVO">
        SELECT t1.id, t1.user_name, t2.`name` AS realName, t1.phone, t1.service_content, t1.service_image,
        t1.service_status
        FROM com_fms_service t1
        LEFT JOIN sys_user t2 ON t1.user_id = t2.user_id
        WHERE t1.id = #{serviceId}
    </select>
    <select id="statisticsFmsService"
            resultType="com.panzhihua.common.model.vos.community.fms.FmsServiceTopStatisticsVO">
        SELECT
        (SELECT COUNT(id) FROM com_fms_service WHERE community_id = #{communityId} AND service_status = 4) AS completedCount,
        (SELECT COUNT(id) FROM com_fms_service WHERE community_id = #{communityId} AND service_status = 1) AS unVerifiedCount,
        (SELECT COUNT(id) FROM com_fms_service WHERE community_id = #{communityId} AND service_status = 2) AS inProgressCount,
        (SELECT COUNT(id) FROM com_fms_service WHERE community_id = #{communityId} AND service_status = 3) AS unEvaluateCount,
        (SELECT COUNT(id) FROM com_fms_service WHERE community_id = #{communityId} AND service_status = 5) AS unPassCount
    </select>
    <select id="pageFmsServiceAdminApplets"
            resultType="com.panzhihua.common.model.vos.community.fms.ComFmsServiceVO">
        SELECT t1.id, t1.service_content, t1.service_image,
        IF(t2.nick_name IS NULL,IF(t1.user_name IS NULL,'匿名用户',t1.user_name),t2.nick_name) AS nickName, t2.image_url
        FROM com_fms_service t1
        LEFT JOIN sys_user t2 ON t1.user_id = t2.user_id
        WHERE t1.community_id = #{adminDTO.communityId}
        <if test="adminDTO.status != null and adminDTO.status == 1">
            AND t1.service_status IN (3,4)
        </if>
        <if test="adminDTO.status != null and adminDTO.status == 2">
            AND t1.service_status = 2
        </if>
        ORDER BY t1.created_at DESC
    </select>
    <select id="detailFmsServiceApplets"
            resultType="com.panzhihua.common.model.vos.community.fms.ComFmsServiceVO">
        SELECT t1.id, t1.service_content, t1.service_image, t1.phone, t1.service_status,
        t1.created_at, IF(t2.nick_name IS NULL,IF(t1.user_name IS NULL,'匿名用户',t1.user_name),t2.nick_name) AS nickName, t2.image_url
        FROM com_fms_service t1
        LEFT JOIN sys_user t2 ON t1.user_id = t2.user_id
        WHERE t1.id = #{serviceId}
    </select>
    <select id="pageMyFmsService" resultType="com.panzhihua.common.model.vos.community.fms.ComFmsServiceVO">
        SELECT id, service_content, service_image, service_status, created_at
        FROM com_fms_service WHERE user_id = #{adminDTO.userId} AND community_id = #{adminDTO.communityId}
        ORDER BY created_at DESC
    </select>
    <select id="pageDealFmsService" resultType="com.panzhihua.common.model.vos.community.fms.ComFmsServiceVO">
        SELECT t1.id, t1.service_content, t1.service_image, t1.service_status, t1.created_at,
        IF(t2.nick_name IS NULL,IF(t1.user_name IS NULL,'匿名用户',t1.user_name),t2.nick_name) AS nickName, t2.image_url
        FROM com_fms_service t1
        LEFT JOIN sys_user t2 ON t1.user_id = t2.user_id
        WHERE t1.community_id = #{adminDTO.communityId}
        <if test="adminDTO.dealStatus != null and adminDTO.dealStatus == 1">
            AND t1.member_id = #{adminDTO.memberId} AND t1.service_status = 2
        </if>
        <if test="adminDTO.dealStatus != null and adminDTO.dealStatus == 2">
            AND t1.service_status = 1
        </if>
        <if test="adminDTO.dealStatus != null and adminDTO.dealStatus == 3">
            AND t1.service_status IN (3,4)
        </if>
        ORDER BY t1.created_at DESC
    </select>
    <select id="getFmsBaseData"
            resultType="com.panzhihua.common.model.vos.community.bigscreen.BigScreenFmsStatisticsInfo">
        SELECT
        (SELECT COUNT(id) FROM com_fms_team WHERE community_id = #{communityId}) AS teamTotal,
        (SELECT COUNT(id) FROM com_fms_team_member WHERE community_id = #{communityId}) AS memberTotal,
        (SELECT COUNT(id) FROM com_fms_service WHERE community_id = #{communityId}) AS serviceTotal,
        (SELECT COUNT(id) FROM com_fms_service WHERE community_id = #{communityId} AND service_status = 4) AS completeServiceTotal,
        (SELECT COUNT(id) FROM com_fms_classroom WHERE community_id = #{communityId}) AS classroomTotal,
        (SELECT COUNT(e.id) FROM `event` AS e LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
        WHERE e.event_category = 1 AND e.event_status = 2 AND e.event_process_status = 2 AND egd.grid_community_id = #{communityId} AND e.event_type = 3) AS adjustTotal,
        (SELECT COUNT(e.id) FROM `event` AS e LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
        WHERE e.event_category = 1 AND e.event_status = 2 AND e.event_process_status IN(1,2) AND egd.grid_community_id = #{communityId} AND e.event_type = 1) AS controlTotal,
        (SELECT IF(SUM(scholars) IS NULL,0,SUM(scholars)) FROM com_fms_classroom WHERE community_id = #{communityId}) AS learnTotal,
        (SELECT COUNT(e.id) FROM `event` AS e LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
        WHERE e.event_category = 1 AND e.event_status = 2 AND e.event_process_status IN(1,2) AND egd.grid_community_id = #{communityId} AND e.event_type = 1 AND e.danger_level > 0) AS fxyhTotal,
        (SELECT COUNT(e.id) FROM `event` AS e LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
        WHERE e.event_category = 1 AND e.event_status = 2 AND e.event_process_status = 2 AND egd.grid_community_id = #{communityId} AND e.event_type = 1 AND e.danger_level > 0) AS jjyhTotal
    </select>
    <select id="retrieveTeamTypeCircleData"
            resultType="com.panzhihua.common.model.vos.community.fms.ComFmsTeamVO">
        SELECT
            t1.id,
            t1.`name`,
            t2.`name` AS teamTypeName
        FROM
            com_fms_team t1
            LEFT JOIN com_fms_team_type t2 ON t1.team_type = t2.id
        WHERE
            t1.community_id = #{communityId}
    </select>
    <select id="retrieveServiceAddPolylineData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, SUM(num) AS num FROM (
            SELECT DATE_FORMAT( created_at, '%Y-%m' ) AS filed, COUNT(1) AS num
            FROM com_fms_service
            WHERE community_id = #{communityId} AND DATE_FORMAT( created_at, '%Y-%m' ) &gt; DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m'
            ) GROUP BY filed
            UNION ALL SELECT * FROM
            (
                SELECT DATE_FORMAT(curdate(),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 1 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 2 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 4 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 5 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 7 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 8 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 9 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 10 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 11 month),'%Y-%m') AS filed, 0 AS num
            ) temT
        ) temp GROUP BY filed ORDER BY filed ASC
    </select>
    <select id="retrieveServiceTotalPolylineData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT
            COUNT( 1 ) AS num
        FROM
            com_fms_service
        WHERE
            community_id = #{communityId}
            AND DATE_FORMAT( created_at, '%Y-%m' ) &lt;= #{date}
    </select>
    <select id="retrieveAdjustCircleData" resultType="com.panzhihua.common.model.vos.grid.EventVO">
        SELECT
        e.id,
        substring_index( substring_index( e.event_clazz, ',', b.help_topic_id + 1 ), ',',- 1 ) AS event_clazz
        FROM
        `event` AS e
        LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
        JOIN mysql.help_topic b ON b.help_topic_id &lt; ( length( e.event_clazz ) - length( REPLACE ( e.event_clazz, ',', '' ))+ 1 )
        WHERE
        e.event_category = 1
        AND e.event_status = 2
        AND e.event_process_status = 2
        AND egd.grid_community_id = #{communityId}
        AND e.event_type = 3
    </select>
    <select id="retrieveAdjustAddPolylineData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, SUM(num) AS num FROM (
            SELECT DATE_FORMAT( e.create_at, '%Y-%m' ) AS filed, COUNT(1) AS num
            FROM `event` AS e
                        LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
            WHERE e.event_category = 1
                        AND e.event_status = 2
                        AND e.event_process_status = 2
                        AND egd.grid_community_id = #{communityId}
                        AND e.event_type = 3 AND DATE_FORMAT( e.create_at, '%Y-%m' ) &gt; DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m'
            ) GROUP BY filed
            UNION ALL SELECT * FROM
            (
                SELECT DATE_FORMAT(curdate(),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 1 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 2 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 4 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 5 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 7 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 8 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 9 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 10 month),'%Y-%m') AS filed, 0 AS num union
                SELECT DATE_FORMAT(date_sub(curdate(), interval 11 month),'%Y-%m') AS filed, 0 AS num
            ) temT
        ) temp GROUP BY filed ORDER BY filed ASC
    </select>
    <select id="retrieveAdjustTotalPolylineData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT
            COUNT( e.id ) AS num
        FROM `event` AS e
        LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
        WHERE e.event_category = 1
        AND e.event_status = 2
        AND e.event_process_status = 2
        AND egd.grid_community_id = #{communityId}
        AND e.event_type = 3
        AND DATE_FORMAT( e.create_at, '%Y-%m' ) &lt;= #{date}
    </select>
    <select id="retrieveControlCircleData" resultType="com.panzhihua.common.model.vos.grid.EventVO">
        SELECT
        e.id,
        substring_index( substring_index( e.event_clazz, ',', b.help_topic_id + 1 ), ',',- 1 ) AS event_clazz
        FROM
        `event` AS e
        LEFT JOIN event_grid_data AS egd ON egd.id = e.grid_id
        JOIN mysql.help_topic b ON b.help_topic_id &lt; ( length( e.event_clazz ) - length( REPLACE ( e.event_clazz, ',', '' ))+ 1 )
        WHERE
        e.event_category = 1
        AND e.event_status = 2
        AND e.event_process_status = 2
        AND egd.grid_community_id = #{communityId}
        AND e.event_type = 1
    </select>
    <select id="pageFmsTeam" resultType="com.panzhihua.common.model.vos.community.fms.ComFmsTeamVO">
        SELECT
            t1.id,
            t1.`name`,
            t2.`name` AS teamTypeName,
            COUNT(t3.team_id) AS teamMemberTotal
        FROM com_fms_team t1
        LEFT JOIN com_fms_team_type t2 ON t1.team_type = t2.id
        LEFT JOIN com_fms_team_member_relation t3 ON t1.id = t3.team_id
        WHERE t1.community_id = #{pageBaseDTO.communityId}
        GROUP BY t1.id
    </select>
 
</mapper>