puhanshu
2021-10-22 f8b116ce4c5edea7e33c31347d2065ce33fa5f53
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
package com.panzhihua.service_community.dao;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import com.panzhihua.common.model.vos.community.ComActActivityStatisticsVO;
import com.panzhihua.common.model.vos.community.ComActActivityTypeVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panzhihua.common.model.dtos.community.bigscreen.work.ScreenActActivityListDTO;
import com.panzhihua.common.model.vos.community.ComActActivityVO;
import com.panzhihua.common.model.vos.community.CommunityActivitiesVO;
import com.panzhihua.common.model.vos.community.screen.work.ActActivityListVO;
import com.panzhihua.common.model.vos.screen.CarouselInfoVO;
import com.panzhihua.service_community.model.dos.ComActActivityDO;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 社区活动
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2020-12-07 13:59
 **/
@Mapper
public interface ComActActivityDAO extends BaseMapper<ComActActivityDO> {
    // @Select("<script> " +
    // " <where>" +
    // "<if test='nameCn != null and nameCn.trim() != &quot;&quot;'>" +
    // " </if> " +
    // "<if test='nameCn != null and nameCn.trim() != &quot;&quot;'>" +
    // " </if> " +
    // "<if test='nameCn != null and nameCn.trim() != &quot;&quot;'>" +
    // " </if> " +
    // " </where>" +
    // "</script>")
    @Select("<script> " + "SELECT  " + "a.id, " + "a.activity_name, " + "u.`name` sponsorName, "
        + "a.activity_addr, " + "a.aattend_people,"
        + "a.`status`, " + "a.is_qr_code, " + "a.publish_at, " + "a.begin_at, " + "a.cover, " + "a.end_at, " + "a.volunteer_max, "
        + "count(if(s.is_volunteer=1,s.id,null))volunteer_now, "
        + "count(if(s.is_volunteer=0,s.id,null))participant_now, " + "a.participant_max, " + "a.sign_up_begin, "
        + "a.sign_up_end, " + "ca.name as communityName  " + "FROM " + "com_act_activity a  "
        + "left join sys_user u on a.sponsor_id=u.user_id " + "left join com_act_act_sign s on a.id=s.activity_id  "
        + "left join com_act ca on a.community_id=ca.community_id  " + " where 1=1 " +
 
        "<if test='comActActivityVO.choice == 0 '>" + "AND a.community_id=#{comActActivityVO.communityId} " + " </if> "
        +
 
        "<if test='comActActivityVO.activityName != null and comActActivityVO.activityName.trim() != &quot;&quot;'>"
        + " and a.activity_name like concat(#{comActActivityVO.activityName},'%')   " + " </if> "
        + "<if test='comActActivityVO.status != null and comActActivityVO.status !=0 and comActActivityVO.isIng==null'>"
        + "AND a.`status` = #{comActActivityVO.status}  " + " </if> "
        + "<if test='comActActivityVO.status != null and comActActivityVO.status !=0 and comActActivityVO.isIng!=null and comActActivityVO.isIng==1'>"
        + "AND a.`status` in (3,4)  " + " </if> "
        + "<if test='comActActivityVO.isApplets != null and comActActivityVO.isApplets ==1'>"
        + "AND a.`status` != 1 AND  a.`status` != 6   " + " </if> " + "<if test='comActActivityVO.beginAt != null '>"
        + "AND a.begin_at <![CDATA[ >= ]]> #{comActActivityVO.beginAt} AND a.end_at <![CDATA[ <= ]]> #{comActActivityVO.endAt}  "
        + " </if> " + "<if test='comActActivityVO.type != null and comActActivityVO.type==1 '>"
        + "AND a.volunteer_max!=0  " + " </if> "
        + "<if test='comActActivityVO.type != null and comActActivityVO.type==2 '>" + "AND a.volunteer_max=0  "
        + " </if> " + " group by a.id " + " order by a.status asc,a.publish_at desc " + "</script>")
    IPage<ComActActivityVO> pageActivity(Page page, @Param("comActActivityVO") ComActActivityVO comActActivityVO);
 
//    @Select("SELECT  " + "u.name sponsorName, " + "ca.name communityName, "
//        + "count(if(s.is_volunteer=1,s.id,null))volunteer_now, "
//        + "count(if(s.is_volunteer=0,s.id,null))participant_now, " + "a.*  " + "FROM  " + "com_act_activity a  "
//        + "left join sys_user u on a.sponsor_id=u.user_id  " + "left join com_act_act_sign s on a.id=s.activity_id  "
//        + "left join com_act ca on a.community_id=ca.community_id  " + "where a.id=#{id}  " + " group by a.id ")
 
    /**
     * 活动详情
     * @param id
     * @return
     */
    ComActActivityVO inforActivity(@Param("id") Long id);
 
    @Select("SELECT " + "a.*  " + "FROM " + "com_act_act_sign s " + "JOIN com_act_activity a ON s.activity_id = a.id  "
        + "WHERE " + "s.user_id = #{comActActivityVO.sponsorId}  " + "ORDER BY " + "s.create_at DESC")
    IPage<ComActActivityVO> pageMyActivity(Page page, @Param("comActActivityVO") ComActActivityVO comActActivityVO);
 
    @Select("select " + "t.activity_name," + "t.id," + "t.end_at," + "t.begin_at," + "t.cover," + "t.status "
        + "from com_act_act_sign s  "
        + "join sys_user u on s.user_id=u.user_id and u.phone=#{phone} and s.is_volunteer=1 "
        + "join com_act_activity t on s.activity_id=t.id and t.status=5")
    List<ComActActivityVO> listActivityByPhone(String phone);
 
    @Select("select t.id from ( " + "SELECT  " + "a.id, " + "a.activity_name, "
        + "COUNT(case when s.is_volunteer=1 then s.id else null end )volunteernum, "
        + "COUNT(case when s.is_volunteer=0 then s.id else null end)usernum, " + "a.participant_min, "
        + "a.volunteer_min " + "FROM " + "com_act_activity a  " + "LEFT JOIN com_act_act_sign s on a.id=s.activity_id  "
        + "WHERE " + "a.`status` in(3,4) and TIMESTAMPDIFF(MINUTE,SYSDATE(),a.sign_up_end)<=0 "
        + "GROUP BY a.id)t WHERE t.usernum<participant_min or t.volunteernum<volunteer_min")
    List<Long> selectTimedTaskActActivity();
 
    @Update("<script> " + "update com_act_activity set `status`=6 where id in "
        + "<foreach item=\"item\" collection=\"longs\" separator=\",\" open=\"(\" close=\")\" index=\"\"> " + "#{item} "
        + "</foreach> " + "</script>")
    int updateIdBatch(@Param("longs") List<Long> longs);
 
    @Update("update com_act_activity set `status`=3 where `status`=1 and TIMESTAMPDIFF(MINUTE,SYSDATE(),publish_at)<=0")
    int updateStatusToNotBegin();
 
    @Update("update com_act_activity set `status`=3 where `status`=2 and TIMESTAMPDIFF(MINUTE,SYSDATE(),sign_up_begin)<=0")
    int updateStatusToBeginSign();
 
    @Update("update com_act_activity set `status`=5 where `status` in (3,4) and TIMESTAMPDIFF(MINUTE,SYSDATE(),end_at)<=0")
    int updateStatusToBeginActiveOrEnd();
 
//    @Select("<script> " + "select t.* from ( " + "SELECT  " + "a.id, " + "a.activity_name, " + "u.`name` sponsorName, "
//        + "a.activity_addr, " + "a.participant_max, " + "count(if(s.is_volunteer=1,null,s.id))participant_now, "
//        + "a.volunteer_max, " + "count(if(s.is_volunteer=1,s.id,null))volunteer_now, " + "a.`status`, "
//        + "a.publish_at, " + "a.is_qr_code, " + "a.begin_at, " + "a.end_at, " + "a.sign_up_begin, " + "a.sign_up_end " + "FROM "
//        + " com_act_activity a  " + " LEFT JOIN sys_user u on a.sponsor_id=u.user_id "
//        + " LEFT JOIN com_act_act_sign s on a.id=s.activity_id " + "WHERE "
//        + "  a.`status` = 1 and a.community_id=#{comActActivityVO.communityId} "
//        + "<if test='comActActivityVO.activityName != null and comActActivityVO.activityName !=&quot;&quot;'>"
//        + " and a.activity_name LIKE concat( #{comActActivityVO.activityName}, '%' )  " + " </if> "
//        + "<if test='comActActivityVO.status != null and comActActivityVO.status !=0 and comActActivityVO.status !=1'>"
//        + "AND a.`status` = 99  " + " </if> " + "<if test='comActActivityVO.beginAt != null '>"
//        + "AND a.begin_at <![CDATA[ >= ]]> #{comActActivityVO.beginAt} AND a.end_at <![CDATA[ <= ]]> #{comActActivityVO.endAt}  "
//        + " </if> " + "group by a.id " + "  " + " union all " + "select t1.* from ( " + "  " + " SELECT  " + "a.id, "
//        + "a.activity_name, " + "u.`name` sponsorName, " + "a.activity_addr, " + "a.participant_max, "
//        + "count(if(s.is_volunteer=1,null,s.id))participant_now, " + "a.volunteer_max, "
//        + "count(if(s.is_volunteer=1,s.id,null))volunteer_now, " + "a.`status`, " + "a.publish_at, " + "a.is_qr_code, " + "a.begin_at, "
//        + "a.end_at, " + "a.sign_up_begin, " + "a.sign_up_end " + "FROM " + " com_act_activity a  "
//        + " LEFT JOIN sys_user u on a.sponsor_id=u.user_id " + " LEFT JOIN com_act_act_sign s on a.id=s.activity_id "
//        + "WHERE " + "  a.`status` != 1 and a.community_id=#{comActActivityVO.communityId} "
//        + "<if test='comActActivityVO.activityName != null and comActActivityVO.activityName !=&quot;&quot;'>"
//        + " and a.activity_name LIKE concat( #{comActActivityVO.activityName}, '%' )  " + " </if> "
//        + "<if test='comActActivityVO.status != null and comActActivityVO.status !=0 '>"
//        + "AND a.`status` = #{comActActivityVO.status}  " + " </if> " + "<if test='comActActivityVO.beginAt != null '>"
//        + "AND a.begin_at <![CDATA[ >= ]]> #{comActActivityVO.beginAt} AND a.end_at <![CDATA[ <= ]]> #{comActActivityVO.endAt}  "
//        + " </if> " + " group by a.id order by a.publish_at desc)t1 )t" + "</script>")
    /**
     * 分页查询社区活动
     * @param page
     * @param comActActivityVO
     * @return
     */
    IPage<ComActActivityVO> pageActivityCommunityBack(@Param("page") Page page, @Param("comActActivityVO") ComActActivityVO comActActivityVO);
 
    @Select("select id from com_act_activity where `status` in (3,4) and TIMESTAMPDIFF(MINUTE,SYSDATE(),end_at)<=0")
    List<Long> getActivityEndIds();
 
    @Update("update com_act_activity set `status`=4 where `status`=3 and TIMESTAMPDIFF(MINUTE,SYSDATE(),sign_up_end)<=0")
    int updateStatusToBeginAfterSingEnd();
 
    @Select("select GROUP_CONCAT(t.x1,',',t.x2,',',t.x3,',',t.x4) from ( " + "SELECT "
        + "(select COUNT(d.id) from com_act_discuss d where  d.community_id=#{communityId})x1, "
        + "(select COUNT(w.id) from com_act_micro_wish w where  w.community_id=#{communityId})x2, "
        + "(select COUNT(p.id) from com_act_easy_photo p where  p.community_id=#{communityId})x3, "
        + " COUNT( a.id ) x4 " + "FROM " + " com_pb_activity a  " + "WHERE " + "  a.community_id =#{communityId})t")
    String selectCommunityGovernanceTrendsVO(Long communityId);
 
    @Select(" " + " SELECT "
        + " (select COUNT(d.id) from com_act_discuss d where DATE_FORMAT(d.create_at,'%Y-%m-%d')=DATE_FORMAT(#{date},'%Y-%m-%d') and d.community_id=#{communityId})discuss, "
        + " (select COUNT(w.id) from com_act_micro_wish w where DATE_FORMAT(w.create_at,'%Y-%m-%d')=DATE_FORMAT(#{date},'%Y-%m-%d') and w.community_id=#{communityId})microWish, "
        + " (select COUNT(p.id) from com_act_easy_photo p where DATE_FORMAT(p.create_at,'%Y-%m-%d')=DATE_FORMAT(#{date},'%Y-%m-%d') and p.community_id=#{communityId})eashPhoto, "
        + " (select COUNT(pa.id) from com_pb_activity pa where DATE_FORMAT(pa.create_at,'%Y-%m-%d')=DATE_FORMAT(#{date},'%Y-%m-%d') and pa.community_id=#{communityId})pbActivity, "
        + "  COUNT( a.id ) actActivity " + " FROM " + "  com_pb_activity a  " + " WHERE "
        + "  DATE_FORMAT( a.create_at, '%Y-%m-%d' )=DATE_FORMAT(#{date},'%Y-%m-%d')  "
        + "  AND a.community_id =#{communityId}")
    CommunityActivitiesVO selectCommunityActivitiesVO(@Param("communityId") Long communityId, @Param("date") Date date);
 
    @Select("SELECT " + " count( caa.id ) as totalNum, "
        + " (select count(id) from com_act_activity where `status` IN (1,2,3,4,5) and volunteer_min = 0 and community_id = #{communityId}) as commonNum, "
        + " (select count(id) from com_act_activity where `status` IN (1,2,3,4,5) and volunteer_min > 0 and community_id = #{communityId}) as volunteerNum, "
        + " (select count(caas.user_id) from com_act_act_sign as caas left join com_act_activity as caa on caa.id = caas.activity_id where caa.`status` IN (1,2,3,4,5) and is_volunteer = 0 and caa.community_id = #{communityId}) as commonPeopleNum, "
        + " (select count(caas.user_id) from com_act_act_sign as caas left join com_act_activity as caa on caa.id = caas.activity_id where caa.`status` IN (1,2,3,4,5) and is_volunteer = 1 and caa.community_id = #{communityId}) as volunteerPeopleNum, "
        + " (select count(id) from com_act_activity where `status` IN (1,2,3,4,5) and community_id = #{communityId} and create_at between date_sub(curdate() - day(curdate()) +1,interval 1 month) and now()) as currentNum "
        + "FROM " + " com_act_activity AS caa  " + "WHERE "
        + " caa.`status` IN (1,2,3,4,5) and community_id = #{communityId}")
    Map<String, Long> countByCommunityId(@Param("communityId") Long communityId, @Param("nowDate") String nowDate);
 
    @Select("SELECT id,activity_name as content,IF(volunteer_max = 0,'居民活动','志愿者活动') AS typeName  FROM com_act_activity "
        + "WHERE community_id = #{communityId} AND (status = 3 OR status = 4 OR status = 5) ORDER BY create_at DESC LIMIT #{pageSize}")
    List<CarouselInfoVO> screenActivity(@Param("communityId") Long communityId, @Param("pageSize") Integer pageSize);
 
    @Select("SELECT cover FROM com_act_activity WHERE community_id = #{communityId}")
    List<String> listImg(@Param("communityId") Long communityId);
 
    @Select("<script> " + "SELECT " + " caa.id, " + " su.`name` AS userName , " + " su.image_url, "
        + " caa.sponsor_id, " + " caa.`status`, " + " caa.create_at, " + " caa.begin_at, " + " caa.end_at, "
        + " caa.sign_up_begin, " + " caa.sign_up_end, " + " caa.volunteer_min, " + " caa.volunteer_max, "
        + " caa.participant_min, " + " caa.participant_max, " + " caa.activity_name, " + " caa.cover, "
        + " caa.content, " + " caa.activity_addr  " + "FROM " + " com_act_activity AS caa "
        + " LEFT JOIN sys_user AS su ON su.user_id = caa.sponsor_id" + " <where> "
        + "<if test='actActivityListDTO.communityId != null '>"
        + " and caa.community_id = #{actActivityListDTO.communityId} " + " </if> "
        + "<if test='actActivityListDTO.startTime!=null and actActivityListDTO.startTime != &quot;&quot;'>"
        + " AND DATE_FORMAT(caa.create_at,'%Y-%m-%d %H:%i:%s') <![CDATA[ >= ]]> #{actActivityListDTO.startTime} "
        + " </if> " + "<if test='actActivityListDTO.endTime!=null and actActivityListDTO.endTime != &quot;&quot;'>"
        + " AND DATE_FORMAT(caa.create_at,'%Y-%m-%d %H:%i:%s') <![CDATA[ <= ]]> #{actActivityListDTO.endTime} "
        + " </if> " + "<if test='actActivityListDTO.type!=null'>" + " AND caa.status = #{actActivityListDTO.type} "
        + " </if> " + " </where> " + "ORDER BY " + " caa.create_at DESC " + " </script>")
    IPage<ActActivityListVO> getScreenActActivityList(Page page,
        @Param("actActivityListDTO") ScreenActActivityListDTO actActivityListDTO);
 
    @Select("SELECT " + " count( caas.id ) AS volunteerCount,( " + " SELECT " + "  count( caas1.id )  " + " FROM "
        + "  com_act_act_sign AS caas1 " + "  LEFT JOIN sys_user AS su1 ON su1.user_id = caas1.user_id  " + " WHERE "
        + "  su1.is_volunteer = 0  " + "  AND caas1.activity_id = #{activityId}  " + " ) AS participantCount  "
        + "FROM " + " com_act_act_sign AS caas " + " LEFT JOIN sys_user AS su ON su.user_id = caas.user_id  " + "WHERE "
        + " su.is_volunteer = 1  " + " AND activity_id = #{activityId} ")
    ActActivityListVO getScreenActActivityPeopleCount(@Param("activityId") Long activityId);
 
    ComActActivityStatisticsVO activityStatistics (@Param("activityId") Long activityId);
 
    /**
     * 查询置于顶部的进行中活动
     * @param communityId 社区id
     * @return 活动列表
     */
    List<ComActActivityVO> getIndexTopActivityList(@Param("communityId") Long communityId);
 
    /**
     * 获取活动类型(目前只有志愿者活动需要获取)
     * @param communityId
     * @param type
     * @return
     */
    List<ComActActivityTypeVO> listActivityType(@Param("communityId") Long communityId, @Param("type") Integer type);
 
    /**
     * 添加活动类型
     * @param comActActivityTypeVO
     * @return
     */
    int addActivityType(@Param("comActActivityTypeVO") ComActActivityTypeVO comActActivityTypeVO);
}