101captain
2021-12-29 018af6bed3da8be2e7b846aa3e654f16f8f71654
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
<?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
            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
            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.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
                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
                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.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.*
        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  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="selectResidentActHistogramData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT activity_type AS filed, COUNT(id) AS num
        FROM com_act_activity
        WHERE community_id = #{communityId}
        <if test="isResidentAct">
            AND volunteer_max = 0
        </if>
        <if test="!isResidentAct">
            AND volunteer_max != 0
        </if>
        GROUP BY filed
    </select>
    <select id="getIndexResidentActBaseData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT filed, num, ROUND(num/total,2) AS percent FROM
        (SELECT t1.activity_type AS filed, COUNT(t2.id) AS num
        FROM com_act_activity t1
        LEFT JOIN (SELECT * FROM com_act_act_sign WHERE `status` = 1) t2 ON t1.id = t2.activity_id
        WHERE t1.community_id = #{communityId}
        <if test="isResidentAct">
            AND t1.volunteer_max = 0
        </if>
        <if test="!isResidentAct">
            AND t1.volunteer_max != 0
        </if>
        GROUP BY filed) temp1,
        (SELECT COUNT(t2.id) AS total
        FROM com_act_activity t1
        LEFT JOIN (SELECT * FROM com_act_act_sign WHERE `status` = 1) t2 ON t1.id = t2.activity_id
        WHERE t1.community_id = #{communityId}
        <if test="isResidentAct">
            AND t1.volunteer_max = 0
        </if>
        <if test="!isResidentAct">
            AND t1.volunteer_max != 0
        </if>
        ) temp2
    </select>
    <select id="getActAddPolylineData" resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT DATE_FORMAT( publish_at, '%m' ) AS filed, COUNT(id) AS num
        FROM com_act_activity
        WHERE community_id = #{communityId}
        <if test="isResidentAct">
            AND volunteer_max = 0
        </if>
        <if test="!isResidentAct">
            AND volunteer_max != 0
        </if>
        AND DATE_FORMAT( publish_at, '%Y' ) = DATE_FORMAT( CURDATE( ) , '%Y' ) GROUP BY filed
    </select>
    <select id="getActTotalPolylineData"
            resultType="com.panzhihua.common.model.vos.community.StatisticsCommVO">
        SELECT COUNT(id) AS num
        FROM com_act_activity
        WHERE community_id = #{communityId}
        <if test="isResidentAct">
            AND volunteer_max = 0
        </if>
        <if test="!isResidentAct">
            AND volunteer_max != 0
        </if>
        AND DATE_FORMAT( publish_at, '%Y%m' ) &lt;= #{date}
    </select>
    <select id="indexActList" resultType="com.panzhihua.common.model.vos.community.ComActActivityVO">
        SELECT id, `status`, activity_type, activity_name, cover
        FROM com_act_activity
        WHERE community_id = #{pageBaseDTO.communityId}
        <if test="isResidentAct">
            AND volunteer_max = 0
        </if>
        <if test="!isResidentAct">
            AND volunteer_max != 0
        </if>
        <if test="pageBaseDTO.param2 != null and pageBaseDTO.param2 != &quot;&quot;">
            AND activity_type = #{pageBaseDTO.param2}
        </if>
        ORDER BY id DESC
    </select>
</mapper>