UserLiveStatisticsMapper.xml
3.75 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
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<!-- 不使用namespace的话sql搜索定位会比较方便 -->
<mapper namespace="UserLiveStatistics">
<resultMap id="UserLiveStatistics" type="com.bjivt.job.executor.service.jobhandler.mijia.model.UserLiveStatistics">
<id column="id" jdbcType="INTEGER" property="id" />
<result property="date" column="date" jdbcType="TIMESTAMP"/>
<result property="userId" column="user_id" jdbcType="INTEGER"/>
<result property="liveCount" column="live_count" jdbcType="INTEGER"/>
<result property="liveSecondsTotal" column="live_seconds_total" jdbcType="INTEGER"/>
<result property="viewUserCount" column="view_user_count" jdbcType="INTEGER"/>
<result property="incomeTotal" column="income_total" jdbcType="INTEGER"/>
</resultMap>
<resultMap id="UserLiveCountMap" type="com.bjivt.job.executor.service.jobhandler.mijia.model.UserLiveCount">
<result property="userId" column="user_id" jdbcType="INTEGER"/>
<result property="counts" column="counts" jdbcType="INTEGER"/>
<result property="timetotal" column="timetotal" jdbcType="INTEGER"/>
<result property="visittotal" column="visittotal" jdbcType="INTEGER"/>
<result property="incometotal" column="incometotal" jdbcType="INTEGER"/>
</resultMap>
<!-- 用于select查询公用抽取的列 -->
<sql id="columns">
<![CDATA[
id,date,user_id,live_count,live_seconds_total,view_user_count,income_total
]]>
</sql>
<!-- useGeneratedKeys="true" keyProperty="xxx" for sqlserver and mysql -->
<insert id="insert" parameterType="com.bjivt.job.executor.service.jobhandler.mijia.model.UserLiveStatistics">
<![CDATA[
INSERT INTO db_showtime_stat.tbl_user_live_statistics (
date ,
user_id ,
live_count ,
live_seconds_total ,
view_user_count ,
income_total
) VALUES (
#{date} ,
#{userId} ,
#{liveCount} ,
#{liveSecondsTotal} ,
#{viewUserCount} ,
#{incomeTotal}
)
]]>
</insert>
<insert id="insertSaveBatch" parameterType="java.util.List">
insert into db_showtime_stat.tbl_user_live_statistics (
date ,
user_id ,
live_count ,
live_seconds_total ,
view_user_count ,
income_total
)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.date},#{item.userId},#{item.liveCount},#{item.liveSecondsTotal},#{item.viewUserCount},#{item.incomeTotal})
</foreach>
</insert>
<!-- 获取每日发送礼物的数量 -->
<select id="getUserLiveStatistics" resultMap="UserLiveCountMap" parameterType="java.util.HashMap">
select u.user_id, count(*) as counts,
sum(TIMESTAMPDIFF(second, u.create_time, case when u.ended_time is null then u.create_time else u.ended_time end)) as timetotal,
(select count(*) as counts from db_showtime_log.tbl_live_record lr where lr.mark=1 and lr.user_id=u.user_id and date_format(lr.record_time,'%Y-%m-%d') = date_sub(curdate(),interval 1 day)) as visittotal,
((select sum(rr.money) from db_showtime_log.tbl_redenvelop_record rr where rr.user_id=u.user_id and date_format(rr.record_time,'%Y-%m-%d') = date_sub(curdate(),interval 1 day)) +
(select sum(ur.gift_count* ur.gift_price) from db_showtime_log.tbl_usergift_record ur
where ur.to_user_id=u.user_id and date_format(ur.record_time,'%Y-%m-%d') = date_sub(curdate(),interval 1 day))) as incometotal
from db_showtime_platform.tbl_live_list u
where date_format(u.create_time,'%Y-%m-%d') = date_sub(curdate(),interval 1 day)
group by u.user_id
</select>
</mapper>