huanghongfa
2021-01-26 32f0563f97700b7ed3a7e7f5339cd5d367aa1f96
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
package com.panzhihua.service_community.dao;
 
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.vos.community.ComActActivityVO;
import com.panzhihua.common.model.vos.partybuilding.PageActivityMembersVO;
import com.panzhihua.service_community.model.dos.ComActActivityDO;
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 java.util.List;
 
/**
 * @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 \n" +
            "a.id,\n" +
            "a.activity_name,\n" +
            "u.`name` sponsorName,\n" +
            "a.activity_addr,\n" +
            "a.`status`,\n" +
            "a.publish_at,\n" +
            "a.begin_at,\n" +
            "a.cover,\n" +
            "a.end_at,\n" +
            "a.volunteer_max,\n" +
            "count(if(s.is_volunteer=1,s.id,null))volunteer_now,\n"+
            "count(if(s.is_volunteer=0,s.id,null))participant_now,\n"+
            "a.participant_max,\n" +
            "a.sign_up_begin,\n" +
            "a.sign_up_end\n" +
            "FROM\n" +
            "com_act_activity a \n" +
            "join sys_user u on a.sponsor_id=u.user_id\n" +
            "left join com_act_act_sign s on a.id=s.activity_id \n"+
            " where a.community_id=#{comActActivityVO.communityId}" +
            "<if test='comActActivityVO.activityName != null and comActActivityVO.activityName.trim() != &quot;&quot;'>" +
            " and a.activity_name like concat(#{comActActivityVO.activityName},'%')  \n" +
            " </if> " +
            "<if test='comActActivityVO.status != null and comActActivityVO.status !=0 and comActActivityVO.isIng==null'>" +
            "AND a.`status` = #{comActActivityVO.status} \n" +
            " </if> " +
            "<if test='comActActivityVO.status != null and comActActivityVO.status !=0 and comActActivityVO.isIng!=null and comActActivityVO.isIng==1'>" +
            "AND a.`status` in (3,4) \n" +
            " </if> " +
            "<if test='comActActivityVO.isApplets != null and comActActivityVO.isApplets ==1'>" +
            "AND a.`status` != 1 \n" +
            " </if> " +
            "<if test='comActActivityVO.beginAt != null '>" +
            "AND a.begin_at <![CDATA[ >= ]]> #{comActActivityVO.beginAt} AND a.end_at <![CDATA[ <= ]]> #{comActActivityVO.endAt} \n" +
            " </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 \n" +
            "u.name sponsorName,\n" +
            "count(if(s.is_volunteer=1,s.id,null))volunteer_now,\n"+
            "count(if(s.is_volunteer=0,s.id,null))participant_now,\n"+
            "a.* \n" +
            "FROM \n" +
            "com_act_activity a \n" +
            "join sys_user u on a.sponsor_id=u.user_id \n"+
            "left join com_act_act_sign s on a.id=s.activity_id \n"+
            "where a.id=#{id} \n"+
            " group by a.id "
    )
    ComActActivityVO inforActivity(Long id);
 
    @Select("SELECT\n" +
            "a.* \n" +
            "FROM\n" +
            "com_act_act_sign s\n" +
            "JOIN com_act_activity a ON s.activity_id = a.id \n" +
            "WHERE\n" +
            "s.user_id = #{comActActivityVO.sponsorId} \n" +
            "ORDER BY\n" +
            "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 (\n" +
            "SELECT \n" +
            "a.id,\n" +
            "a.activity_name,\n" +
            "COUNT(case when s.is_volunteer=1 then s.id else null end )volunteernum,\n" +
            "COUNT(case when s.is_volunteer=0 then s.id else null end)usernum,\n" +
            "a.participant_min,\n" +
            "a.volunteer_min\n" +
            "FROM\n" +
            "com_act_activity a \n" +
            "LEFT JOIN com_act_act_sign s on a.id=s.activity_id \n" +
            "WHERE\n" +
            "a.`status` in(3,4) and TIMESTAMPDIFF(MINUTE,SYSDATE(),a.sign_up_end)<=0\n" +
            "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\n" +
            "<foreach item=\"item\" collection=\"longs\" separator=\",\" open=\"(\" close=\")\" index=\"\">\n"+
            "#{item}\n"+
            "</foreach>\n"+
        "</script>")
    int updateIdBatch(@Param("longs") List<Long> longs);
 
    @Update("update com_act_activity set `status`=2 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`=(if(DATEDIFF(SYSDATE(),end_at)>=0,5,4)) where `status` in (3,4) and TIMESTAMPDIFF(MINUTE,SYSDATE(),sign_up_end)<=0")
    int updateStatusToBeginActiveOrEnd();
    @Select("<script> " +
            "select t.* from (\n" +
            "SELECT \n" +
            "a.id,\n" +
            "a.activity_name,\n" +
            "u.`name` sponsorName,\n" +
            "a.activity_addr,\n" +
            "a.participant_max,\n" +
            "count(if(s.is_volunteer=1,null,s.id))participant_now,\n"+
            "a.volunteer_max,\n" +
            "count(if(s.is_volunteer=1,s.id,null))volunteer_now,\n"+
            "a.`status`,\n" +
            "a.publish_at,\n" +
            "a.begin_at,\n" +
            "a.end_at,\n" +
            "a.sign_up_begin,\n" +
            "a.sign_up_end\n" +
            "FROM\n" +
            "\tcom_act_activity a \n" +
            "\tLEFT JOIN sys_user u on a.sponsor_id=u.user_id\n" +
            "\tLEFT JOIN com_act_act_sign s on a.id=s.activity_id\n" +
            "WHERE\n" +
            "\t a.`status` = 1 and a.community_id=#{comActActivityVO.communityId}\n" +
            "<if test='comActActivityVO.activityName != null and comActActivityVO.activityName !=&quot;&quot;'>" +
            "\tand a.activity_name LIKE concat( #{comActActivityVO.activityName}, '%' ) \n" +
            " </if> " +
            "<if test='comActActivityVO.status != null and comActActivityVO.status !=0 and comActActivityVO.status !=1'>" +
            "AND a.`status` = 99 \n" +
            " </if> " +
            "<if test='comActActivityVO.beginAt != null '>" +
            "AND a.begin_at <![CDATA[ >= ]]> #{comActActivityVO.beginAt} AND a.end_at <![CDATA[ <= ]]> #{comActActivityVO.endAt} \n" +
            " </if> " +
            "group by a.id\n" +
            "\t\n" +
            "\tunion all\n" +
            "select t1.* from (\n"+
            "\t\n" +
            "\tSELECT \n" +
            "a.id,\n" +
            "a.activity_name,\n" +
            "u.`name` sponsorName,\n" +
            "a.activity_addr,\n" +
            "a.participant_max,\n" +
            "count(if(s.is_volunteer=1,null,s.id))participant_now,\n"+
            "a.volunteer_max,\n" +
            "count(if(s.is_volunteer=1,s.id,null))volunteer_now,\n"+
            "a.`status`,\n" +
            "a.publish_at,\n" +
            "a.begin_at,\n" +
            "a.end_at,\n" +
            "a.sign_up_begin,\n" +
            "a.sign_up_end\n" +
            "FROM\n" +
            "\tcom_act_activity a \n" +
            "\tLEFT JOIN sys_user u on a.sponsor_id=u.user_id\n" +
            "\tLEFT JOIN com_act_act_sign s on a.id=s.activity_id\n" +
            "WHERE\n" +
            "\t a.`status` != 1 and a.community_id=#{comActActivityVO.communityId}\n" +
            "<if test='comActActivityVO.activityName != null and comActActivityVO.activityName !=&quot;&quot;'>" +
            "\tand a.activity_name LIKE concat( #{comActActivityVO.activityName}, '%' ) \n" +
            " </if> " +
            "<if test='comActActivityVO.status != null and comActActivityVO.status !=0 '>" +
            "AND a.`status` = #{comActActivityVO.status} \n" +
            " </if> " +
            "<if test='comActActivityVO.beginAt != null '>" +
            "AND a.begin_at <![CDATA[ >= ]]> #{comActActivityVO.beginAt} AND a.end_at <![CDATA[ <= ]]> #{comActActivityVO.endAt} \n" +
            " </if> " +
            " group by a.id order by a.publish_at desc)t1 )t"+
            "</script>")
    IPage<ComActActivityVO> pageActivityCommunityBack(Page page, @Param("comActActivityVO") ComActActivityVO comActActivityVO);
 
    @Update("update com_act_activity set `status`=4 where `status`=3 and TIMESTAMPDIFF(MINUTE,SYSDATE(),sign_up_end)<=0")
    int updateStatusToBeginAfterSingEnd();
}