101captain
2022-02-22 c83cf9d2d82a0a29a15e38f4566eb470b9a3517b
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
<?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.ComActActivityDAO">
 
        <!-- 通用查询映射结果 -->
        <resultMap id="BaseResultMap" type="com.panzhihua.service_community.model.dos.ComActActivityDO">
                    <id column="id" property="id" />
                    <result column="activity_name" property="activityName" />
                    <result column="sponsor_id" property="sponsorId" />
                    <result column="activity_addr" property="activityAddr" />
                    <result column="lat" property="lat" />
                    <result column="lng" property="lng" />
                    <result column="status" property="status" />
                    <result column="publish_at" property="publishAt" />
                    <result column="end_at" property="endAt" />
                    <result column="begin_at" property="beginAt" />
                    <result column="sign_up_begin" property="signUpBegin" />
                    <result column="sign_up_end" property="signUpEnd" />
                    <result column="aattend_people" property="aattendPeople" />
                    <result column="volunteer_min" property="volunteerMin" />
                    <result column="volunteer_max" property="volunteerMax" />
                    <result column="participant_min" property="participantMin" />
                    <result column="participant_max" property="participantMax" />
                    <result column="cover" property="cover" />
                    <result column="has_prize" property="hasPrize" />
                    <result column="is_qr_code" property="isQrCode" />
                    <result column="contact_name" property="contactName" />
                    <result column="contact_phone" property="contactPhone" />
                    <result column="is_regist" property="isRegist" />
                    <result column="is_top" property="isTop" />
                    <result column="prize_remark" property="prizeRemark" />
                    <result column="reward_desc" property="rewardDesc" />
                    <result column="content" property="content" />
                    <result column="community_id" property="communityId" />
                    <result column="create_at" property="createAt" />
                    <result column="cancel_reason" property="cancelReason" />
                    <result column="range" property="range" />
                    <result column="have_integral_reward" property="haveIntegralReward" />
                    <result column="reward_way" property="rewardWay" />
                    <result column="reward_integral" property="rewardIntegral" />
                    <result column="limit" property="limit" />
                    <result column="can_cancel" property="canCancel" />
                    <result column="cancel_deduct" property="cancelDeduct" />
                    <result column="activity_type" property="activityType" />
        </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, activity_name, sponsor_id, activity_addr, lat, lng, status, publish_at, end_at, begin_at, sign_up_begin, sign_up_end, aattend_people, volunteer_min, volunteer_max, participant_min, participant_max, cover, has_prize, is_qr_code, contact_name, contact_phone, is_regist, is_top, prize_remark, reward_desc, content, community_id, create_at, cancel_reason
    </sql>
    <insert id="addActivityType">
        INSERT INTO com_act_activity_type (`name`, `type`, community_id)
        VALUES (#{comActActivityTypeVO.name}, #{comActActivityTypeVO.type}, #{comActActivityTypeVO.communityId})
    </insert>
 
    <select id="activityStatistics" resultType="com.panzhihua.common.model.vos.community.ComActActivityStatisticsVO">
        SELECT IFNULL(volunteer_max,0) + IFNULL(participant_max,0) as signTotal
             ,(SELECT count(id) FROM com_act_act_sign WHERE activity_id = #{activityId} AND `status` = 1) as reallySignTotal
             ,(SELECT count(id) FROM com_act_act_sign WHERE activity_id = #{activityId} AND `status` = 1) as registTotal
             ,(SELECT count(id) FROM com_act_act_regist WHERE activity_id = #{activityId}) as reallyRegistTotal
             ,((SELECT count(id) FROM com_act_act_sign WHERE activity_id = #{activityId} AND `status` = 1) - (SELECT count(id) FROM com_act_act_regist WHERE activity_id = #{activityId})) as noRegistTotal
             ,(SELECT count(id) FROM com_act_act_sign WHERE activity_id = #{activityId} AND `status` = 1) as evaluateTotal
             ,(SELECT count(id) FROM com_act_act_evaluate WHERE activity_id = #{activityId}) as reallyEvaluateTotal
             ,((SELECT count(id) FROM com_act_act_sign WHERE activity_id = #{activityId} AND `status` = 1) - (SELECT count(id) FROM com_act_act_evaluate WHERE activity_id = #{activityId})) as noEvaluateTotal
        FROM com_act_activity where id = #{activityId}
    </select>
    <select id="getIndexTopActivityList" resultMap="BaseResultMap">
        SELECT * FROM `com_act_activity`
        WHERE community_id = #{communityId} and is_top = 1 and sign_up_end &gt;= now()
    </select>
    <select id="pageActivityCommunityBack"
            resultType="com.panzhihua.common.model.vos.community.ComActActivityVO">
        SELECT t.* FROM (
            SELECT  a.id, a.activity_name, u.`name` sponsorName, a.activity_addr, a.participant_max, a.contact_name,
                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, a.reward_way, a.activity_type, a.have_integral_reward , a.cover <if test='comActActivityVO.type != null and comActActivityVO.type == 4'>,so.socialCount</if>
            FROM  com_act_activity a
            LEFT JOIN sys_user u ON a.sponsor_id=u.user_id
            LEFT JOIN (SELECT * FROM com_act_act_sign WHERE `status` = 1) s ON a.id=s.activity_id
            <if test='comActActivityVO.type != null and comActActivityVO.type == 4'>
            left join  (select count(t.id) as socialCount,activity_id from   com_act_act_regist  t LEFT JOIN sys_user t1 on  t.user_id = t1.user_id LEFT JOIN com_act_social_worker t2 on t1.phone = t2.telephone where t2.id is not null GROUP BY t.activity_id) so on a.id = so.activity_id
            </if>
            WHERE   a.`status` = 1 AND a.community_id=#{comActActivityVO.communityId}
                <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>
                <if test='comActActivityVO.type != null and comActActivityVO.type == 4'>
                    AND a.is_project = 1
                </if>
                <if test='comActActivityVO.rewardWay != null and comActActivityVO.rewardWay != 0'>
                    AND a.reward_way = #{comActActivityVO.rewardWay}
                </if>
                <if test='comActActivityVO.activityType != null and comActActivityVO.activityType !=&quot;&quot;'>
                    AND a.activity_type = #{comActActivityVO.activityType}
                </if>
                <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, a.contact_name,
                    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, a.reward_way, a.activity_type, a.have_integral_reward ,a.cover<if test='comActActivityVO.type != null and comActActivityVO.type == 4'>,so.socialCount</if>
                FROM  com_act_activity a
                LEFT JOIN sys_user u ON a.sponsor_id=u.user_id
                LEFT JOIN (SELECT * FROM com_act_act_sign WHERE `status` = 1) s ON a.id=s.activity_id
                <if test='comActActivityVO.type != null and comActActivityVO.type == 4'>
                    left join  (select count(t.id) as socialCount,activity_id from   com_act_act_regist  t LEFT JOIN sys_user t1 on  t.user_id = t1.user_id LEFT JOIN com_act_social_worker t2 on t1.phone = t2.telephone where t2.id is not null GROUP BY t.activity_id) so on a.id = so.activity_id
                </if>
                WHERE   a.`status` != 1 AND a.community_id=#{comActActivityVO.communityId}
                    <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>
                    <if test='comActActivityVO.type != null and comActActivityVO.type == 4'>
                        AND a.is_project = 1
                    </if>
                    <if test='comActActivityVO.rewardWay != null and comActActivityVO.rewardWay != 0'>
                        AND a.reward_way = #{comActActivityVO.rewardWay}
                    </if>
                    <if test='comActActivityVO.activityType != null and comActActivityVO.activityType !=&quot;&quot;'>
                        AND a.activity_type = #{comActActivityVO.activityType}
                    </if>
                    <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
    </select>
    <select id="inforActivity" resultType="com.panzhihua.common.model.vos.community.ComActActivityVO">
        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.*,t1.name as projectName
        FROM  com_act_activity a
        left join sys_user u on a.sponsor_id=u.user_id
        left join (select * from com_act_act_sign where `status` = 1) s on a.id=s.activity_id
        left join com_act ca on a.community_id=ca.community_id  left join com_act_social_project t1 on a.project_id = t1.id where a.id = #{id} group by a.id
 
    </select>
    <select id="listActivityType" resultType="com.panzhihua.common.model.vos.community.ComActActivityTypeVO">
        SELECT * FROM com_act_activity_type WHERE `type` = #{type} AND community_id = #{communityId} ORDER BY id ASC
    </select>
 
    <select id="selectProjectActivity" resultType="com.panzhihua.common.model.vos.community.ComActActivityVO">
        SELECT  a.id, a.activity_name, u.`name` sponsorName, a.activity_addr, a.participant_max, a.contact_name,
                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, a.reward_way, a.activity_type, a.have_integral_reward , a.cover , t1.evaluateLevel
        FROM  com_act_activity a
                  LEFT JOIN sys_user u ON a.sponsor_id=u.user_id
                  LEFT JOIN (SELECT * FROM com_act_act_sign WHERE `status` = 1) s ON a.id=s.activity_id
                  LEFT JOIN (select AVG(star_level) as evaluateLevel,activity_id from com_act_act_evaluate GROUP BY activity_id) t1 on a.id = t1.activity_id
        WHERE   is_project=1 order by t1.evaluateLevel desc
    </select>
 
    <select id="selectActivityBySocialWorker" resultType="com.panzhihua.common.model.vos.community.ComActActivityVO">
        select t.* from com_act_activity t left join com_act_act_regist t1 on t.id=t1.activity_id where t1.user_id =
        (select t1.user_id from com_act_social_worker t LEFT JOIN sys_user t1 on t.telephone = t1.phone where t.id = #{id})
    </select>
</mapper>