101captain
2022-07-20 d50ef0ec94f90ddf92bcd42671aa62ae38df81b9
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
365
366
367
368
369
370
371
372
373
374
<?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.ComActNeighborCircleDAO">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.panzhihua.service_community.model.dos.ComActNeighborCircleDO">
        <id column="id" property="id"/>
        <result column="release_id" property="releaseId"/>
        <result column="release_phone" property="releasePhone"/>
        <result column="community_id" property="communityId"/>
        <result column="release_content" property="releaseContent"/>
        <result column="release_images" property="releaseImages"/>
        <result column="status" property="status"/>
        <result column="refuse_reason" property="refuseReason"/>
        <result column="comment_num" property="commentNum"/>
        <result column="fabulous_num" property="fabulousNum"/>
        <result column="forward_num" property="forwardNum"/>
        <result column="views_num" property="viewsNum"/>
        <result column="is_boutique" property="isBoutique"/>
        <result column="create_at" property="createAt"/>
        <result column="reply_at" property="replyAt"/>
        <result column="last_comment_num" property="lastCommentNum"/>
        <result column="last_fabulous_num" property="lastFabulousNum"/>
        <result column="last_views_num" property="lastViewsNum"/>
        <result column="type" property="type"/>
        <result column="topic_id" property="topicId"/>
        <result column="hot_num" property="hotNum"/>
        <result column="is_del" property="isDel"/>
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, release_id, release_phone, community_id, release_content, release_images, status, refuse_reason, comment_num, fabulous_num, forward_num, views_num, is_boutique, create_at, reply_at, last_comment_num, last_fabulous_num, last_views_num, type, topic_id, hot_num, is_del
    </sql>
 
    <select id="pageNeighborByApp" parameterType="com.panzhihua.common.model.dtos.neighbor.ComActNeighborCircleAppDTO"
            resultType="com.panzhihua.common.model.vos.neighbor.ComActNeighborCircleAppVO">
        SELECT
        canc.*,
        su.nick_name as name,
        su.community_id,
        ca.`name` as communityName,
        canct.name as topicName,
        su.image_url as headUrl
        FROM
        com_act_neighbor_circle AS canc
        left join sys_user as su on su.user_id = canc.release_id
        left join com_act_neighbor_circle_topic as canct on canct.id = canc.topic_id
        left join com_act as ca on ca.community_id = canc.community_id
        where is_del = 2 and canc.status = 2 and canc.community_id = ${neighborCircleAppDTO.communityId}
        <if test='neighborCircleAppDTO.topicId != null '>
            and canc.topic_id = #{neighborCircleAppDTO.topicId}
        </if>
        <if test='neighborCircleAppDTO.belongType != null '>
            and canc.belong_type = #{neighborCircleAppDTO.belongType}
        </if>
        <if test='neighborCircleAppDTO.keyWord != null and neighborCircleAppDTO.keyWord != &quot;&quot;'>
            and (canct.`name` like concat ('%',#{neighborCircleAppDTO.keyWord},'%') or
            su.nick_name like concat ('%',#{neighborCircleAppDTO.keyWord},'%') or
             canc.release_content like concat ('%',#{neighborCircleAppDTO.keyWord},'%'))
        </if>
        <if test="neighborCircleAppDTO.isHelp ==1">
            and (canc.help_member_content like concat ('%',#{neighborCircleAppDTO.phone},'%') or canc.help_org_content like concat ('%',#{neighborCircleAppDTO.phone},'%') )
        </if>
        order by canc.create_at desc
    </select>
 
    <update id="addHotNum">
        update com_act_neighbor_circle set hot_num = hot_num + #{hotNum} where id = #{circleId}
    </update>
 
    <update id="addTopicHotNum">
        update com_act_neighbor_circle_topic set hot_num = hot_num + 1 where id = (select topic_id from com_act_neighbor_circle where id = #{circleId})
    </update>
 
    <select id="pageNeighborByAdmin" parameterType="com.panzhihua.common.model.dtos.neighbor.ComActNeighborCircleAdminDTO"
            resultType="com.panzhihua.common.model.vos.neighbor.ComActNeighborCircleAdminVO">
        SELECT
        nc.*,
        u.`nick_name` AS releaseName,u.image_url,canct.`name` as topicName ,u.`type` as userType
        ,u.name as communityName,nc.solve_status
        FROM
        com_act_neighbor_circle nc
        LEFT JOIN sys_user u ON nc.release_id = u.user_id
        LEFT JOIN com_act_neighbor_circle_topic as canct ON canct.id = nc.topic_id
        <where>
            nc.community_id = ${neighborCircleAdminDTO.communityId} and is_del = 2
            <if test='neighborCircleAdminDTO.releaseContent != null and neighborCircleAdminDTO.releaseContent != &quot;&quot;'>
                and nc.release_content like concat('%',#{neighborCircleAdminDTO.releaseContent},'%')
            </if>
            <if test='neighborCircleAdminDTO.topicName != null and neighborCircleAdminDTO.topicName != &quot;&quot;'>
                and canct.`name` = #{neighborCircleAdminDTO.topicName}
            </if>
            <if test='neighborCircleAdminDTO.keyWord != null and neighborCircleAdminDTO.keyWord != &quot;&quot;'>
                and (canct.`name` like concat(#{neighborCircleAdminDTO.keyWord},'%') or
                u.`nick_name` like concat(#{neighborCircleAdminDTO.keyWord},'%') or
                nc.`release_content` like concat(#{neighborCircleAdminDTO.keyWord},'%') )
            </if>
            <if test='neighborCircleAdminDTO.startAt != null and neighborCircleAdminDTO.endAt !=null '>
                and nc.create_at between #{neighborCircleAdminDTO.startAt} and #{neighborCircleAdminDTO.endAt}
            </if>
            <if test='neighborCircleAdminDTO.status != null '>
                and nc.status = #{neighborCircleAdminDTO.status}
            </if>
            <if test='neighborCircleAdminDTO.belongType != null '>
                and nc.belong_type = #{neighborCircleAdminDTO.belongType}
            </if>
        </where>
        order by
        case when nc.`status`=1 then 0 else 1 end,
        nc.`status` asc,nc.create_at desc
    </select>
    <select id="getAllImages" resultType="java.lang.String">
        SELECT release_images FROM com_act_neighbor_circle
        WHERE community_id = ${communityId} AND `status` = 2 and belong_type = 1 AND release_images IS NOT NULL AND release_images != ''
        ORDER BY create_at DESC limit #{pageSize}
    </select>
    <select id="getContents" resultType="java.lang.String">
        SELECT release_content FROM com_act_neighbor_circle
        WHERE community_id = ${communityId} AND `status` = 2 and belong_type = 1 AND release_content IS NOT NULL AND release_content != ''
        ORDER BY create_at DESC limit #{pageSize}
    </select>
    <select id="getIndexNeighborBaseData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, num, ROUND(num/total,2) AS percent FROM
        (SELECT IF(t2.`name` IS NULL,'无话题',t2.`name`) AS filed, COUNT(1) AS num FROM com_act_neighbor_circle t1
        LEFT JOIN com_act_neighbor_circle_topic t2 ON t1.topic_id = t2.id
        WHERE t1.community_id = ${communityId} AND t1.`status` IN (2,3) AND t1.is_del = 2 AND (t2.`status` = 1 OR t2.id IS NULL) GROUP BY filed) temp1,
        (SELECT COUNT(t1.id) AS total FROM com_act_neighbor_circle t1
        LEFT JOIN com_act_neighbor_circle_topic t2 ON t1.topic_id = t2.id
        WHERE t1.community_id = ${communityId} AND t1.`status` IN (2,3) AND t1.is_del = 2 AND (t2.`status` = 1 OR t2.id IS NULL)) temp2
    </select>
    <select id="getNeighborAddPolylineData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, SUM(num) AS num FROM (
        SELECT DATE_FORMAT( t1.create_at, '%Y-%m' ) AS filed, COUNT(t1.id) AS num
        FROM com_act_neighbor_circle t1
        LEFT JOIN com_act_neighbor_circle_topic t2 ON t1.topic_id = t2.id
        WHERE t1.community_id = ${communityId} AND t1.`status` IN (2,3) AND t1.is_del = 2 AND (t2.`status` = 1 OR t2.id IS NULL)
        AND DATE_FORMAT( t1.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="getNeighborTotalPolylineDate"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT COUNT(t1.id) AS num FROM com_act_neighbor_circle t1
        LEFT JOIN com_act_neighbor_circle_topic t2 ON t1.topic_id = t2.id
        WHERE t1.community_id = ${communityId} AND t1.`status` IN (2,3) AND t1.is_del = 2 AND (t2.`status` = 1 OR t2.id IS NULL) AND DATE_FORMAT( t1.create_at, '%Y-%m' ) &lt;= #{date}
    </select>
    <select id="indexNeighborList"
            resultType="com.panzhihua.common.model.vos.neighbor.ComActNeighborCircleAdminVO">
        SELECT t1.id, t1.release_content, t1.release_images, t1.comment_num, t1.fabulous_num, t2.`name` AS topicName
        FROM com_act_neighbor_circle t1
        LEFT JOIN com_act_neighbor_circle_topic t2 ON t1.topic_id = t2.id
        WHERE 1=1
        <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` IN (2,3) AND t1.is_del = 2 AND (t2.`status` = 1 OR t2.id IS NULL)
        <if test="pageBaseDTO.paramId != null">
            AND t1.topic_id = #{pageBaseDTO.paramId}
        </if>
        ORDER BY t1.id DESC
    </select>
 
    <select id="selectSolve" resultType="com.panzhihua.common.model.vos.neighbor.ComActNeighborCircleAppVO">
        select canc.id,canc.release_content,canc.release_images,canc.status,canc.create_at,canct.name as topicName
        ,canc.comment_num,canc.fabulous_num,canc.forward_num,canc.views_num,canc.refuse_reason,su.nick_name as name,su.image_url as headUrl,canc.solve_status,canc.community_id
         from com_act_neighbor_circle as canc  left join sys_user as su on su.user_id = canc.release_id
         left join com_act_neighbor_circle_topic as canct on canct.id = canc.topic_id
        <where>
            <if test="neighborCircleAppDTO.solveId !=null">
                and canc.solve_id =#{neighborCircleAppDTO.solveId}
            </if>
            <if test="neighborCircleAppDTO.solveStatus !=null">
                and canc.solve_status =#{neighborCircleAppDTO.solveStatus}
            </if>
            <if test="neighborCircleAppDTO.belongType !=null">
                and canc.belong_type =#{neighborCircleAppDTO.belongType}
            </if>
            <if test="neighborCircleAppDTO.orderType !=null">
                and canc.order_type =#{neighborCircleAppDTO.orderType}
            </if>
        </where>  order by create_at desc
    </select>
 
    <select id="neighborDetailByApp" resultType="com.panzhihua.common.model.vos.neighbor.ComActNeighborCircleDetailAppVO">
        SELECT
            canc.*,
            su.nick_name as name,
            su.community_id,
            ca.`name` as communityName,
            canct.name as topicName,
            su.image_url as headUrl
        FROM
            com_act_neighbor_circle AS canc
                left join sys_user as su on su.user_id = canc.release_id
                left join com_act_neighbor_circle_topic as canct on canct.id = canc.topic_id
                left join com_act as ca on ca.community_id = canc.community_id
        where canc.id =#{circleId}
    </select>
 
    <select id="selectStatsCheckUnit" resultType="com.panzhihua.common.model.vos.neighbor.ServiceStaticsVO">
         select count(t1.checkId) as times,sum(t1.hours) as hours from
         ((select real_service_time as hours,solve_unit_id  as checkId  from com_act_neighbor_circle  where order_type = 1 and solve_status = 4 and solve_unit_id = #{checkUnitId} and create_at between concat(#{date},'-01-01 00:00:00') and concat(#{date},'-12-31 23:59:59'))
          union all
         (select duration as hours,check_unit_id as checkId from com_act_activity  where check_unit_id = #{checkUnitId} and publish_at between concat(#{date},'-01-01 00:00:00') and concat(#{date},'-12-31 23:59:59'))) t1
    </select>
    <select id="selectListByCheckUnitId" resultType="com.panzhihua.common.model.vos.neighbor.ComActNeighborCircleAppVO">
        SELECT
            canc.*,
            su.nick_name as name,
            su.community_id,
            ca.`name` as communityName,
            canct.name as topicName,
            su.image_url as headUrl
        FROM
            com_act_neighbor_circle AS canc
                left join sys_user as su on su.user_id = canc.release_id
                left join com_act_neighbor_circle_topic as canct on canct.id = canc.topic_id
                left join com_act as ca on ca.community_id = canc.community_id
        where is_del = 2 and canc.solve_status=4 and   canc.solve_unit_id = #{checkUnitId} and canc.create_at between concat(#{date},'-01-01 00:00:00') and concat(#{date},'-12-31 23:59:59')
    </select>
 
    <select id="selectStatsUser" resultType="com.panzhihua.common.model.vos.neighbor.ServiceStaticsVO">
        select count(t1.checkId) as times,sum(t1.hours) as hours from  ((select real_service_time as hours,solve_id  as checkId  from com_act_neighbor_circle canc left join sys_user su on canc.solve_id = su.user_id  where order_type = 2 and solve_status = 4 and su.phone = #{phone} and canc.create_at between concat(#{date},'-01-01 00:00:00') and concat(#{date},'-12-31 23:59:59')) union all
                                                                        (select duration as hours,caas.user_id as checkId from com_act_activity caa LEFT JOIN com_act_act_regist caas on caa.id = caas.activity_id left join sys_user su on caas.user_id = su.user_id where caa.type !=5 and caas.end_time is not null and su.phone =#{phone}  and publish_at between concat(#{date},'-01-01 00:00:00') and concat(#{date},'-12-31 23:59:59') group by caa.id)) t1
    </select>
 
    <select id="selectListByPhone" resultType="com.panzhihua.common.model.vos.neighbor.ComActNeighborCircleAppVO">
        SELECT
            canc.*,
            su.nick_name as name,
            su.community_id,
            ca.`name` as communityName,
            canct.name as topicName,
            su.image_url as headUrl
        FROM
            com_act_neighbor_circle AS canc
                left join sys_user as su on su.user_id = canc.release_id
                left join com_act_neighbor_circle_topic as canct on canct.id = canc.topic_id
                left join com_act as ca on ca.community_id = canc.community_id
                left join sys_user su1 on su1.user_id = canc.solve_id
        where is_del = 2 and canc.solve_status=4 and su1.phone = #{phone} and canc.create_at between concat(#{date},'-01-01 00:00:00') and concat(#{date},'-12-31 23:59:59')
    </select>
    <select id="institutionalUnitServiceAnalysis"
            resultType="com.panzhihua.common.model.vos.neighbor.UnitActivityAnalysisVO">
        select canc.solve_unit_id as unitId,sum(canc.real_service_time) as serviceTime,count(canc.real_service_time) as serviceTimes,canc.community_id as communityId,cpcu.belong_to
        from com_act_neighbor_circle as canc
        left join com_pb_check_unit as cpcu on canc.solve_unit_id=cpcu.id
        where canc.solve_unit_id&lt;>''
        <if test="beginTime != null">
            and canc.create_at between #{beginTime} and #{endTime}
        </if>
        <if test="belongTo != null and belongTo != ''">
            and belong_to=#{belongTo}
        </if>
        <if test="communityId != null">
            and canc.community_id=#{communityId}
        </if>
        group by(canc.solve_unit_id)
        having serviceTimes&lt;>'' and serviceTime&lt;>''
        order by serviceTime desc
    </select>
    <select id="institutionalUnitActivityAnalysis"
            resultType="com.panzhihua.common.model.vos.neighbor.UnitActivityAnalysisVO">
        SELECT count(caa.check_unit_id) as serviceTimes,sum(caa.duration) as serviceTime,caa.check_unit_id as unitId,caa.community_id as communityId,cpcu.belong_to
        FROM com_act_activity as caa
        left join com_pb_check_unit as cpcu on caa.check_unit_id=cpcu.id
        where caa.check_unit_id&lt;>''
        and caa.type=5
        <if test="beginTime != null">
            and caa.create_at between #{beginTime} and #{endTime}
        </if>
        <if test="belongTo != null and belongTo != ''">
            and belong_to=#{belongTo}
        </if>
        <if test="communityId != null">
            and caa.community_id=#{communityId}
        </if>
        GROUP BY (caa.check_unit_id)
        having serviceTimes&lt;>'' and serviceTime&lt;>''
        order by serviceTime desc
    </select>
    <select id="institutionalPartyMemberServiceAnalysis"
            resultType="com.panzhihua.common.model.vos.neighbor.PartyMemberAnalysisVO">
        SELECT count(caa.sponsor_id) as serviceTimes,sum(caa.duration) as serviceTime,caa.check_unit_id as unitId
        ,caa.community_id as communityId,caa.sponsor_id as memberId,su.name as memberName,su.relation_name as belongUnit,ca.name as belongCommunity,cpcu.belong_to
        FROM `com_act_activity` as caa
        left join com_act_act_sign as caas on caa.id=caas.activity_id
        left join sys_user as su on caa.sponsor_id=su.user_id
        left join com_act as ca on su.community_id=ca.community_id
        left join com_pb_check_unit as cpcu on ca.community_id=cpcu.community_id
        where caa.sponsor_id&lt;>''
        and caa.type=3
        <if test="beginTime != null">
            and caa.create_at between #{beginTime} and #{endTime}
        </if>
        <if test="belongTo != null and belongTo != ''">
            and belong_to=#{belongTo}
        </if>
        <if test="communityId != null">
            and su.community_id=#{communityId}
        </if>
        <if test="unitId != null">
            and caa.check_unit_id=#{unitId}
        </if>
        GROUP BY (caa.sponsor_id)
        having serviceTimes&lt;>'' and serviceTime&lt;>'' and memberName&lt;>''
        order by serviceTime desc
    </select>
    <select id="institutionalPartyMemberActAnalysis"
            resultType="com.panzhihua.common.model.vos.neighbor.PartyMemberAnalysisVO">
        SELECT count(canc.solve_id) as serviceTimes,sum(canc.real_service_time) as serviceTime
        ,canc.community_id as communityId,canc.solve_id as memberId,su.name as memberName,su.relation_name as belongUnit,ca.name as belongCommunity,cpcu.belong_to
        FROM `com_act_neighbor_circle` as canc
        left join sys_user as su on canc.solve_id=su.user_id
        left join com_act as ca on su.community_id=ca.community_id
        left join com_pb_check_unit as cpcu on ca.community_id=cpcu.community_id
        where canc.solve_id&lt;>''
        <if test="beginTime != null">
            and canc.create_at between #{beginTime} and #{endTime}
        </if>
        <if test="belongTo != null and belongTo != ''">
            and belong_to=#{belongTo}
        </if>
        <if test="communityId != null">
            and su.community_id=#{communityId}
        </if>
        <if test="unitId != null">
            and cpcu.id=#{unitId}
        </if>
        GROUP BY (canc.solve_id)
        having serviceTimes&lt;>'' and serviceTime&lt;>'' and memberName&lt;>''
        order by serviceTime desc
    </select>
    <select id="institutionalPartyMemberServiceAnalysisByServicesTimes"
            resultType="com.panzhihua.common.model.vos.neighbor.PartyMemberAnalysisVO">
        SELECT count(caa.check_unit_id) as serviceTimes,sum(caa.duration) as serviceTime,caa.check_unit_id as unitId,caa.community_id as communityId,cpcu.belong_to
        FROM com_act_activity as caa
        left join com_pb_check_unit as cpcu on caa.check_unit_id=cpcu.id
        where caa.check_unit_id&lt;>''
        and caa.type=5
        <if test="beginTime != null">
            and caa.create_at between #{beginTime} and #{endTime}
        </if>
        <if test="belongTo != null and belongTo != ''">
            and belong_to=#{belongTo}
        </if>
        GROUP BY (caa.check_unit_id)
        having serviceTimes&lt;>'' and serviceTime&lt;>''
        order by serviceTimes desc
    </select>
</mapper>