mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
<?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.ComActDynDAO">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.panzhihua.service_community.model.dos.ComActDynDO">
        <id column="id" property="id" />
        <result column="title" property="title" />
        <result column="status" property="status" />
        <result column="is_topping" property="isTopping" />
        <result column="publish_at" property="publishAt" />
        <result column="create_at" property="createAt" />
        <result column="update_at" property="updateAt" />
        <result column="community_id" property="communityId" />
        <result column="content" property="content" />
        <result column="cover" property="cover" />
        <result column="type" property="type" />
        <result column="cover_mode" property="coverMode" />
        <result column="jump_url" property="jumpUrl" />
        <result column="jump_type" property="jumpType" />
        <result column="category" property="category" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id
    </sql>
    <select id="getIndexDynBaseData" resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, num, ROUND(num/total,2) AS percent FROM
        (SELECT t2.`name` AS filed, COUNT(1) AS num FROM com_act_dyn t1
        LEFT JOIN com_act_dyn_type t2 ON t1.type = t2.id
        WHERE t1.community_id = ${communityId} AND t1.`status` = 1 GROUP BY filed) temp1,
        (SELECT COUNT(t1.id) AS total FROM com_act_dyn t1
        LEFT JOIN com_act_dyn_type t2 ON t1.type = t2.id
        WHERE t1.community_id = ${communityId} AND t1.`status` = 1) temp2
    </select>
    <select id="getDynAddPolylineData" resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, SUM(num) AS num FROM (
        SELECT DATE_FORMAT( create_at, '%Y-%m' ) AS filed, COUNT(id) AS num
        FROM com_act_dyn
        WHERE community_id = ${communityId} AND `status` = 1
        AND DATE_FORMAT( 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="getDynTotalPolylineDate"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT COUNT(id) AS num FROM com_act_dyn
        WHERE community_id = ${communityId} AND `status` = 1 AND DATE_FORMAT( create_at, '%Y-%m' ) &lt;= #{date}
    </select>
    <select id="indexDynList" resultType="com.panzhihua.common.model.vos.community.ComActDynVO">
        SELECT t1.id, t1.title, t1.cover, t2.`name` AS typeName
        FROM com_act_dyn t1
        LEFT JOIN com_act_dyn_type t2 ON t1.type = t2.id
        WHERE 1=1 and cadt.area='2'
        <if test="pageBaseDTO.communityIds != null and pageBaseDTO.communityIds.size > 0">
            AND t1.community_id IN
            <foreach collection="pageBaseDTO.communityIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="pageBaseDTO.communityIds == null">
            AND t1.community_id = ${pageBaseDTO.communityId}
        </if>
        AND t1.`status` = 1 AND t2.is_del = 2
        <if test="pageBaseDTO.paramId != null">
            AND t1.type = #{pageBaseDTO.paramId}
        </if>
        ORDER BY t1.id DESC
    </select>
    <select id="getPartyBuildIngBaseData"
            resultType="com.panzhihua.common.model.vos.community.bigscreen.BigScreenPartyBuildIngStatisticsInfo">
        SELECT
        (SELECT COUNT( d.id ) FROM com_pb_dyn d LEFT JOIN com_pb_dyn_user u ON d.id = u.dyn_id LEFT JOIN com_act t ON d.community_id = t.community_id WHERE d.type = 1 AND d.community_id = #{communityId}) AS djdtTotal,
        (SELECT COUNT( a.id ) FROM com_pb_activity a LEFT JOIN sys_user u ON a.create_by = u.user_id WHERE a.community_id = #{communityId} AND a.`status` IN ( 3, 4, 5 )) AS djhdTotal,
        (SELECT COUNT(id) FROM com_act_discuss WHERE community_id = #{communityId} AND is_del = 2) AS ystpTotal,
        (SELECT COUNT(DISTINCT d2.user_id) FROM com_act_discuss d1 INNER JOIN com_act_discuss_comment d2 ON d1.id = d2.discuss_id WHERE d1.community_id = #{communityId} AND d1.is_del = 2) AS ystpcyTotal,
        (SELECT COUNT(id) FROM com_act_discuss WHERE community_id = #{communityId} AND is_del = 2 AND `type` = 1) AS ysTotal,
        (SELECT COUNT(id) FROM com_act_discuss WHERE community_id = #{communityId} AND is_del = 2 AND `type` = 2) AS tpTotal,
        (SELECT COUNT(id) FROM com_act_discuss WHERE community_id = #{communityId} AND content_type = 2 AND is_del = 2) AS ylysTotal,
        (SELECT COUNT(id) FROM com_act_discuss WHERE community_id = #{communityId} AND content_type = 1 AND is_del = 2) AS sqysTotal,
        (SELECT COUNT(id) FROM com_pb_member WHERE community_id = #{communityId} AND audit_result = 1) AS dyTotal,
        (SELECT COUNT(id) FROM com_act_four_member WHERE community_id = #{communityId}) AS szsyTotal,
        (SELECT COUNT(id) FROM com_act_four_member WHERE community_id = #{communityId} AND (position LIKE CONCAT('%','居民小组长','%') OR position = '全部')) AS jmxzzTotal,
        (SELECT COUNT(id) FROM com_act_four_member WHERE community_id = #{communityId} AND (position LIKE CONCAT('%','妇女小组长','%') OR position = '全部')) AS fnxzzTotal,
        (SELECT COUNT(id) FROM com_act_four_member WHERE community_id = #{communityId} AND (position LIKE CONCAT('%','党小组长','%') OR position = '全部')) AS dxzzTotal,
        (SELECT COUNT(id) FROM com_act_four_member WHERE community_id = #{communityId} AND (position LIKE CONCAT('%','楼栋长','%') OR position = '全部')) AS ldzTotal,
        (SELECT COUNT(id) FROM com_act_four_member WHERE community_id = #{communityId} AND (position LIKE CONCAT('%','调解员','%') OR position = '全部')) AS tjyTotal,
        (SELECT COUNT(id) FROM com_act_four_member WHERE community_id = #{communityId} AND (position LIKE CONCAT('%','安全员','%') OR position = '全部')) AS aqyTotal,
        (SELECT COUNT(id) FROM com_act_four_member WHERE community_id = #{communityId} AND (position LIKE CONCAT('%','宣传员','%') OR position = '全部')) AS xcyTotal,
        (SELECT COUNT(id) FROM com_act_four_member WHERE community_id = #{communityId} AND (position LIKE CONCAT('%','监督员','%') OR position = '全部')) AS jdyTotal,
        (SELECT COUNT(t1.id) FROM com_act_easy_photo_handler t1 INNER JOIN com_act_micro_wish t2 ON t1.service_id = t2.id
        WHERE t1.community_id = #{communityId} AND t1.`type` = 2 AND t1.service_type = 2 AND t2.`status` = 6) AS zyxServiceTotal,
        (SELECT COUNT(id) FROM com_act_dyn WHERE community_id = #{communityId} AND `status` = 1) AS jmxcTotal,
        (SELECT COUNT(id) FROM com_sw_patrol_record WHERE community_id = #{communityId}) AS xqxcTotal,
        (SELECT IF(AVG(t1.score) IS NULL,0,ROUND(AVG(t1.score),1)) FROM com_act_easy_photo_evaluate t1
        INNER JOIN com_act_easy_photo t2 ON t1.service_id = t2.id WHERE t1.community_id = #{communityId} AND t1.service_type = 1 AND t2.del_tag = 0) AS qzmydStar
    </select>
    <select id="pagePartyBuildIngAct"
            resultType="com.panzhihua.common.model.vos.partybuilding.PartyBuildingActivityVO">
        SELECT
            id,
            activity_name AS name,
            publish_at AS releaseTime,
            cover
        FROM com_act_activity
        WHERE community_id = #{pageBaseDTO.communityId} AND `status` IN ( 3, 4, 5 ) AND `type` = 3
        ORDER BY publish_at desc
    </select>
    <select id="pagePartyBuildIngDiscuss"
            resultType="com.panzhihua.common.model.vos.community.ComActDiscussVO">
        SELECT
            id,
            discuss_subject,
            `type`,
            photo_pah
        FROM com_act_discuss
        WHERE community_id = #{pageBaseDTO.communityId} AND is_del = 2
        ORDER BY create_at DESC
    </select>
    <select id="getPartyBuildIngDynRecord" resultType="com.panzhihua.common.model.vos.community.ComActDynVO">
        SELECT id,title,publish_at FROM com_act_dyn WHERE community_id = #{communityId} AND `status` = 1 LIMIT #{pageSize}
    </select>
    <select id="getPartyBuildIngPatrolRecord"
            resultType="com.panzhihua.common.model.vos.community.ComSwPatrolRecordVO">
        SELECT id,person_name,patrol_type,patrol_time FROM com_sw_patrol_record WHERE community_id = #{communityId} LIMIT #{pageSize}
    </select>
    <select id="pageDynamic" resultType="com.panzhihua.common.model.vos.community.ComActDynVO">
        SELECT
        d.id,
        d.title,
        IFNULL( u.readNum, 0 ) readNum,
        d.`status`,
        d.`cover`,
        d.`type`,
        d.`cover_mode`,
        d.jump_url,
        d.jump_type,
        d.is_topping,
        d.publish_at,
        d.create_at,
        cadt.`name` AS typeName,
        cadt.color AS typeColor,
        ca.NAME AS communityName,
        d.release_time,
        d.category
        FROM
        com_act_dyn d
        LEFT JOIN ( SELECT dyn_id, count( id ) AS readNum FROM com_act_dyn_user GROUP BY dyn_id ) u ON d.id = u.dyn_id
        LEFT JOIN com_act_dyn_type AS cadt ON cadt.id = d.type
        LEFT JOIN com_act ca ON d.community_id = ca.community_id
        WHERE
        1 = 1
        <if test='comActDynVO.choice == 0 '>
            AND d.community_id in (${comActDynVO.communityId})
        </if>
        <if test="comActDynVO.category != null and comActDynVO.category != '' ">
            AND d.category = #{comActDynVO.category}
        </if>
        <if test='comActDynVO.areaCode !=null and comActDynVO.category == 1 '>
            AND ca.area_code = ${comActDynVO.areaCode}
        </if>
        <if test="comActDynVO.title != null and comActDynVO.title.trim() != '' ">
            AND d.title LIKE concat(#{comActDynVO.title},'%')
        </if>
        <if test="comActDynVO.isTopping != null and comActDynVO.isTopping != '' ">
            AND d.is_topping = #{comActDynVO.isTopping}
        </if>
        <if test="comActDynVO.status != null and comActDynVO.status != '' ">
            AND d.`status` = #{comActDynVO.status}
        </if>
        <if test="comActDynVO.type != null and comActDynVO.type != '' ">
            AND d.type in (${comActDynVO.type})
        </if>
        <if test="comActDynVO.publishAtBegin != null and comActDynVO.publishAtBegin != '' ">
            AND d.publish_at BETWEEN #{comActDynVO.publishAtBegin} AND #{comActDynVO.publishAtEnd}
        </if>
        <if test="comActDynVO.isOrgHatch == 1">
            AND (cadt.`name` = '社会组织培训' OR cadt.`name` = '社工培训')
        </if>
        ORDER BY d.is_topping DESC, d.create_at DESC
    </select>
 
<!--    <select id="pageDynamicByAdmin" resultType="com.panzhihua.common.model.vos.community.ComActDynVO">-->
<!--        SELECT d.id, d.title,(SELECT COUNT(u.id) FROM com_act_dyn_user u WHERE d.id = u.dyn_id ) readNum,-->
<!--               d.`status`, d.`content`, d.`cover`, d.`type`, d.`cover_mode`,-->
<!--        d.is_topping, d.publish_at, d.create_at, cadt.`name` as typeName, ca.name as communityName,d.release_time-->
<!--        FROM com_act_dyn d-->
<!--        LEFT JOIN com_act_dyn_type as cadt ON cadt.id = d.type-->
<!--        LEFT JOIN com_act ca ON d.community_id = ca.community_id-->
<!--        WHERE 1=1-->
<!--        <if test="comActDynVO.communityId != null and comActDynVO.communityId != '' ">-->
<!--            and d.community_id in (${comActDynVO.communityId})-->
<!--        </if>-->
 
<!--        <if test="comActDynVO.communityId == null  and  comActDynVO.streetId != null"  >-->
<!--            and d.community_id in (select community_id from com_act where street_id=#{comActDynVO.streetId})-->
<!--        </if>-->
 
<!--        <if test="comActDynVO.category != null and comActDynVO.category != '' ">-->
<!--            AND d.category = #{comActDynVO.category}-->
<!--        </if>-->
<!--        <if test="comActDynVO.title != null and comActDynVO.title.trim() != '' ">-->
<!--            AND d.title like concat(#{comActDynVO.title},'%')-->
<!--        </if>-->
<!--        <if test="comActDynVO.isTopping != null and comActDynVO.isTopping != '' ">-->
<!--            AND d.is_topping = #{comActDynVO.isTopping}-->
<!--        </if>-->
<!--        <if test="comActDynVO.status != null and comActDynVO.status != '' ">-->
<!--            AND d.`status` = #{comActDynVO.status}-->
<!--        </if>-->
 
<!--        <if test="comActDynVO.typeS == null or comActDynVO.typeS != 2 ">-->
<!--            <if test="comActDynVO.type != null and comActDynVO.type != '' ">-->
<!--                AND d.type = #{comActDynVO.type}-->
<!--            </if>-->
<!--        </if>-->
 
<!--         <if test="comActDynVO.typeS != null and comActDynVO.typeS == 2 ">-->
<!--             AND d.type in (-->
<!--             SELECT cadt.id FROM `com_act_dyn_type` as cadt WHERE cadt.name in-->
<!--             <foreach collection="comActDynVO.typeList" item="id" index="index" open="(" close=")" separator=",">-->
<!--                 #{id}-->
<!--             </foreach>-->
<!--             <if test="comActDynVO.communityId != null and comActDynVO.communityId != '' ">-->
<!--                 and cadt.community_id in (${comActDynVO.communityId})-->
<!--             </if>-->
<!--             union-->
<!--             SELECT cadt2.id FROM `com_act_dyn_type` as cadt2 WHERE  cadt2.area=1 and cadt2.name in-->
<!--             <foreach collection="comActDynVO.typeList" item="id" index="index" open="(" close=")" separator=",">-->
<!--                 #{id}-->
<!--             </foreach>-->
 
<!--             )-->
<!--        </if>-->
 
<!--        <if test="comActDynVO.publishAtBegin != null and comActDynVO.publishAtBegin != '' ">-->
<!--            AND (d.publish_at BETWEEN #{comActDynVO.publishAtBegin} AND #{comActDynVO.publishAtEnd})-->
<!--        </if>-->
<!--        order by d.is_topping desc, d.create_at desc-->
<!--    </select>-->
 
 
    <select id="pageDynamicByAdmin" resultType="com.panzhihua.common.model.vos.community.ComActDynVO">
        SELECT d.id, d.title,
        d.`status`, d.`cover`, d.`type`, d.`cover_mode`,
        d.is_topping, d.publish_at, d.create_at, cadt.`name` as typeName, ca.name as communityName,d.release_time
        FROM com_act_dyn d
        LEFT JOIN com_act_dyn_type as cadt ON cadt.id = d.type
        LEFT JOIN com_act ca ON d.community_id = ca.community_id
        WHERE 1=1
        <if test="comActDynVO.communityId != null and comActDynVO.communityId != '' ">
            and d.community_id in (${comActDynVO.communityId})
        </if>
 
        <if test="comActDynVO.communityId == null  and  comActDynVO.streetId != null"  >
            and d.community_id in (select community_id from com_act where street_id=#{comActDynVO.streetId})
        </if>
 
        <if test="comActDynVO.category != null and comActDynVO.category != '' ">
            AND d.category = #{comActDynVO.category}
        </if>
        <if test="comActDynVO.title != null and comActDynVO.title.trim() != '' ">
            AND d.title like concat(#{comActDynVO.title},'%')
        </if>
        <if test="comActDynVO.isTopping != null and comActDynVO.isTopping != '' ">
            AND d.is_topping = #{comActDynVO.isTopping}
        </if>
        <if test="comActDynVO.status != null and comActDynVO.status != '' ">
            AND d.`status` = #{comActDynVO.status}
        </if>
 
        <if test="comActDynVO.typeS == null or comActDynVO.typeS != 2 ">
            <if test="comActDynVO.type != null and comActDynVO.type != '' ">
                AND d.type = #{comActDynVO.type}
            </if>
        </if>
 
        <if test="comActDynVO.typeS != null and comActDynVO.typeS == 2 ">
            AND d.type in (
            SELECT cadt.id FROM `com_act_dyn_type` as cadt WHERE cadt.name in
            <foreach collection="comActDynVO.typeList" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
            <if test="comActDynVO.communityId != null and comActDynVO.communityId != '' ">
                and cadt.community_id in (${comActDynVO.communityId})
            </if>
            union
            SELECT cadt2.id FROM `com_act_dyn_type` as cadt2 WHERE  cadt2.area=1 and cadt2.name in
            <foreach collection="comActDynVO.typeList" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
 
            )
        </if>
 
        <if test="comActDynVO.publishAtBegin != null ">
            AND (d.publish_at BETWEEN #{comActDynVO.publishAtBegin} AND #{comActDynVO.publishAtEnd})
        </if>
        order by d.is_topping desc, d.create_at desc
    </select>
 
 
    <select id="getContent" resultType="String" parameterType="String">
        SELECT content FROM `com_act_dyn` WHERE id=#{id}
    </select>
 
 
    <select id="getReadNum" resultType="Integer" parameterType="String">
        SELECT COUNT(id) FROM `com_act_dyn_user` WHERE dyn_id=#{dynId}
    </select>
 
 
    <select id="getTypeId" resultType="String">
        select id from com_act_dyn_type where community_id=#{communityId} and name=#{name} and area in (1,2) and is_del=2
    </select>
 
 
 
 
</mapper>