StatisticsAnchorMapper.xml
17.1 KB
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
<?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.bjivt.entity.showtime.StatisticsAnchor">
<resultMap id="BaseResultMap" type="com.bjivt.entity.vo.StatisticsUser">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="msisdn" jdbcType="VARCHAR" property="msisdn" />
<result column="email" jdbcType="VARCHAR" property="email" />
<result column="signature" jdbcType="VARCHAR" property="signature" />
<result column="hometown" jdbcType="VARCHAR" property="hometown" />
<result column="sex" jdbcType="VARCHAR" property="sex" />
<result column="fans_count" jdbcType="INTEGER" property="fansCount" />
<result column="follower_count" jdbcType="INTEGER" property="followerCount" />
<result column="chinese_coin" jdbcType="INTEGER" property="chineseCoin" />
<result column="me_coin_balance" jdbcType="INTEGER" property="meCoinBalance" />
<result column="level" jdbcType="INTEGER" property="level" />
<result column="money" jdbcType="INTEGER" property="money" />
<result column="recharge" jdbcType="INTEGER" property="recharge" />
<result column="age" jdbcType="INTEGER" property="age" />
</resultMap>
<!-- 统计注册人数 总数变化情况-->
<select id="getUserAnchorTotal" parameterType="com.bjivt.entity.vo.StatisticsAnchor" resultType="com.bjivt.entity.vo.StatisticsResult">
<if test="types==0 or types==1" >
select date_format(u.date,'%Y-%m-%d') time,(
select sum(new_broadcaster_count) counts from db_showtime_stat.tbl_daily_statistics ds
where <![CDATA[ date_format(ds.date,'%Y-%m-%d') <= str_to_date(u.date,'%Y-%m-%d') ]]> ) as counts
from db_showtime_stat.tbl_daily_statistics u
where u.date is not null
<![CDATA[ and date_format(u.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
<![CDATA[ and date_format(u.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
order by time
</if>
<if test="types==2">
select date_format(u.date,'%Y年第%u周') time,(
select sum(new_broadcaster_count) counts from db_showtime_stat.tbl_daily_statistics ds
where <![CDATA[ date_format(ds.date,'%Y年第%u周') <= str_to_date(u.date,'%Y年第%u周') ]]> ) as counts
from db_showtime_stat.tbl_daily_statistics u
where u.date is not null
<![CDATA[ and date_format(u.date,'%Y年第%u周') >= str_to_date(#{startTime},'%Y年第%u周') ]]>
<![CDATA[ and date_format(u.date,'%Y年第%u周') <= str_to_date(#{endTime},'%Y年第%u周') ]]>
order by time
</if>
<if test="types==3">
select date_format(u.date,'%Y年%m月') time,(
select sum(new_broadcaster_count) counts from db_showtime_stat.tbl_daily_statistics ds
where <![CDATA[ date_format(ds.date,'%Y年%m月') <= str_to_date(u.date,'%Y年%m月') ]]> ) as counts
from db_showtime_stat.tbl_daily_statistics u
where u.date is not null
<![CDATA[ and date_format(u.date,'%Y年%m月') >= str_to_date(#{startTime},'%Y年%m月') ]]>
<![CDATA[ and date_format(u.date,'%Y年%m月') <= str_to_date(#{endTime},'%Y年%m月') ]]>
order by time
</if>
<if test="types==4">
select date_format(u.date,'%Y') time,(
select sum(new_broadcaster_count) counts from db_showtime_stat.tbl_daily_statistics ds
where <![CDATA[ date_format(ds.date,'%Y') <= str_to_date(u.date,'%Y') ]]> ) as counts
from db_showtime_stat.tbl_daily_statistics u
where u.date is not null
<![CDATA[ and date_format(u.date,'%Y') >= str_to_date(#{startTime},'%Y') ]]>
<![CDATA[ and date_format(u.date,'%Y') <= str_to_date(#{endTime},'%Y') ]]>
order by time
</if>
</select>
<!-- 统计注册人数, 统计每日新增主播人数-->
<select id="getUserAnchorDayIncrease" parameterType="java.util.Map" resultType="com.bjivt.entity.vo.StatisticsResult">
<if test="types==0 or types==1" >
select date_format(u.date,'%Y-%m-%d') time,(u.new_broadcaster_count) counts
from db_showtime_stat.tbl_daily_statistics u
where u.date is not null
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(u.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(u.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time,new_broadcaster_count
</if>
<if test="types==2">
select date_format(u.date,'%Y年第%u周') time,sum(u.new_broadcaster_count) counts
from db_showtime_stat.tbl_daily_statistics u
where u.date is not null
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(u.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(u.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
<if test="types==3">
select date_format(u.date,'%Y年%m月') time,sum(u.new_broadcaster_count) counts
from db_showtime_stat.tbl_daily_statistics u
where u.date is not null
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(u.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(u.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
<if test="types==4">
select date_format(u.date,'%Y年') time,sum(u.new_broadcaster_count) counts
from db_showtime_stat.tbl_daily_statistics u
where u.date is not null
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(u.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(u.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
</select>
<!--列表显示主播用户的数据-->
<select id="getAnchorUserDataList" parameterType="java.util.Map" resultMap="BaseResultMap">
select tu.id,tu.name, tu.msisdn,tu.email,tu.signature,tu.hometown,tu.sex,tu.age,
tu.fans_count,tu.follower_count,tu.chinese_coin,tu.me_coin_balance,
(<![CDATA[select te.level from db_showtime_platform.tbl_level te where tu.exp>=te.exp_start AND tu.exp<=te.exp_end ]]>) level,
(select sum(ws.withdraw) from db_showtime_stat.tbl_user_withdraw_statistics ws
where ls.user_id=ws.user_id
<![CDATA[and date_format(ws.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') and date_format(ws.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>) as money,
(select sum(rs.recharge) from db_showtime_stat.tbl_user_recharge_statistics rs
where ls.user_id=rs.user_id
<![CDATA[and date_format(rs.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') and date_format(rs.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>) as recharge
from db_showtime_stat.tbl_user_live_statistics ls, db_showtime_platform.tbl_user_list tu
where ls.user_id=tu.id
<![CDATA[and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d')
and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d')]]>
<![CDATA[and ls.live_seconds_total>=3600]]>
<if test="id != null and id !=''">
and tu.id=#{id}
</if>
group by tu.id
order by ${orderfield} ${orderrule}
<if test="page != null and page !=''">
<if test="page.from != null and page.size != null">
limit #{page.from},#{page.size}
</if>
</if>
</select>
<!-- 与getAnchorUserDataList配合使用的 -->
<select id="getAnchorUserDataCount" resultType="java.lang.Integer" parameterType="java.util.Map">
select count(distinct tu.id)
from db_showtime_stat.tbl_user_live_statistics ls, db_showtime_platform.tbl_user_list tu
where ls.user_id=tu.id
<![CDATA[and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d')
and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d')]]>
<![CDATA[and ls.live_seconds_total>=3600]]>
</select>
<!--列表显示主播用户的数据-->
<select id="getAnchorUserDataList_bak" parameterType="java.util.Map" resultMap="BaseResultMap">
select tu.id,tu.name, tu.msisdn,tu.email,tu.signature,tu.hometown,tu.sex,tu.age,
tu.fans_count,tu.follower_count,tu.chinese_coin,tu.me_coin_balance,
(<![CDATA[select te.level from tbl_level te where tu.exp>=te.exp_start AND tu.exp<=te.exp_end]]>) level,
(select sum(me_coin) from db_showtime_log.tbl_withdraw_record where user_id=tu.id
<![CDATA[and date_format(record_time,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d')
and date_format(record_time,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>) money,
(select sum(tr.money) as tmoney from db_showtime_log.tbl_recharge_record tr
where tr.user_id=tu.id
<![CDATA[ and date_format(tr.record_time,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d')
and date_format(tr.record_time,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>) as recharge
from tbl_user_list tu
left join tbl_live_list u on tu.id=u.user_id
<if test="id != null and id !=''">
where tu.id=#{id}
</if>
group by tu.id
having sum(TIMESTAMPDIFF(hour, u.create_time, case when u.ended_time is null then u.create_time else u.ended_time end)) >=1
order by ${orderfield} ${orderrule}
<if test="page != null and page !=''">
<if test="page.from != null and page.size != null">
limit #{page.from},#{page.size}
</if>
</if>
</select>
<!-- 与getAnchorUserDataList配合使用的 -->
<select id="getAnchorUserDataCount_bak" resultType="java.lang.Integer" parameterType="java.util.Map">
SELECT count(*) from (
SELECT tu.id FROM tbl_user_list tu
left join tbl_live_list u on tu.id=u.user_id
group by tu.id
having sum(TIMESTAMPDIFF(hour, u.create_time, case when u.ended_time is null then u.create_time else u.ended_time end)) >=1 ) as tbl
</select>
<!-- 统计主播直播的时长每天或每周、每月,直播了多长时间-->
<select id="getAnchorUserTimeTotal" parameterType="java.util.Map" resultType="com.bjivt.entity.vo.StatisticsDecResult">
<if test="types==0 or types==1" >
select date_format(ls.date,'%Y-%m-%d') time,sum(live_seconds_total)/3600 counts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
<if test="types==2">
select date_format(ls.date,'%Y年第%u周') time,sum(live_seconds_total)/3600 counts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
<if test="types==3">
select date_format(ls.date,'%Y年%m月') time,sum(live_seconds_total)/3600 counts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
<if test="types==4">
select date_format(ls.date,'%Y年') time,sum(live_seconds_total)/3600 counts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
</select>
<!-- 统计主播直播的观看人数,每天或每周、每月,有多少人观看了直播-->
<select id="getAnchorByVisitUser" parameterType="java.util.Map" resultType="com.bjivt.entity.vo.StatisticsResult">
<if test="types==0 or types==1" >
select date_format(ls.date,'%Y-%m-%d') time,sum(live_count) counts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
<if test="types==2">
select date_format(ls.date,'%Y年第%u周') time,sum(live_count) counts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
<if test="types==3">
select date_format(ls.date,'%Y年%m月') time,sum(live_count) counts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
<if test="types==4">
select date_format(ls.date,'%Y年') time,sum(live_count) counts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
</select>
<!-- 统计主播直播的观看人数,每天或每周、每月,有多少人观看了直播-->
<select id="getAnchorVisitUserAndTimeTotal" parameterType="java.util.Map" resultType="com.bjivt.entity.vo.StatisticsTwoSeries">
<if test="types==0 or types==1" >
select date_format(ls.date,'%Y-%m-%d') time,sum(live_count) visitCounts, sum(live_seconds_total)/3600 timeCounts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
<if test="types==2">
select date_format(ls.date,'%Y年第%u周') time,sum(live_count) visitCounts, sum(live_seconds_total)/3600 timeCounts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
<if test="types==3">
select date_format(ls.date,'%Y年%m月') time,sum(live_count) visitCounts, sum(live_seconds_total)/3600 timeCounts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
<if test="types==4">
select date_format(ls.date,'%Y年') time,sum(live_count) visitCounts, sum(live_seconds_total)/3600 timeCounts from db_showtime_stat.tbl_user_live_statistics ls
where ls.user_id= #{id}
<if test="startTime !=null and startTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d') ]]>
</if>
<if test="endTime !=null and endTime!=''">
<![CDATA[ and date_format(ls.date,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d') ]]>
</if>
group by time
</if>
</select>
</mapper>