GiftStatisticsMapper.xml
3.54 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
<?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">
<!-- 每日的发送礼物的数量 -->
<mapper namespace="GiftStatistics">
<resultMap id="GiftStatistics" type="com.bjivt.job.executor.service.jobhandler.mijia.model.GiftStatistics">
<id column="id" jdbcType="INTEGER" property="id" />
<result property="date" column="date" jdbcType="TIMESTAMP"/>
<result property="giftId" column="gift_id" jdbcType="INTEGER"/>
<result property="count" column="count" jdbcType="INTEGER"/>
</resultMap>
<resultMap id="GiftCount" type="com.bjivt.job.executor.service.jobhandler.mijia.model.GiftCount">
<result property="giftId" column="gift_id" jdbcType="INTEGER"/>
<result property="counts" column="counts" jdbcType="INTEGER"/>
</resultMap>
<resultMap id="UserGiftCount" type="com.bjivt.job.executor.service.jobhandler.mijia.model.UserGiftCount">
<result property="fromUserId" column="from_user_id" jdbcType="INTEGER"/>
<result property="toUserId" column="to_user_id" jdbcType="INTEGER"/>
<result property="numTotal" column="moneyTotal" jdbcType="INTEGER"/>
<result property="moneyTotal" column="numTotal" jdbcType="INTEGER"/>
</resultMap>
<!-- 用于select查询公用抽取的列 -->
<sql id="GiftStatistics.columns">
<![CDATA[
id,date,gift_id,count
]]>
</sql>
<!-- useGeneratedKeys="true" keyProperty="xxx" for sqlserver and mysql -->
<insert id="insert" parameterType="com.bjivt.job.executor.service.jobhandler.mijia.model.GiftStatistics">
<![CDATA[
INSERT INTO db_showtime_stat.tbl_gift_statistics (
date ,
gift_id ,
count
) VALUES (
#{date} ,
#{giftId} ,
#{count}
)
]]>
</insert>
<insert id="insertSaveBatch" parameterType="java.util.List">
insert into db_showtime_stat.tbl_gift_statistics (
date ,
gift_id ,
count )
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.date},#{item.giftId},#{item.count})
</foreach>
</insert>
<!-- 获取每日发送礼物的数量 -->
<select id="getGiftCounts" resultMap="GiftCount" parameterType="java.util.HashMap">
select tg.gift_id,count(*) as counts from db_showtime_platform.tbl_user_gift_detail tg
where date_format(tg.create_time,'%Y-%m-%d') = date_sub(curdate(),interval 1 day)
group by gift_id
</select>
<!-- 获取每日发送礼物的数量 -->
<select id="getGiftStatiscAsUser" resultMap="UserGiftCount" parameterType="java.util.HashMap">
select tbl.from_user_id,tbl.to_user_id, sum(tbl.money) moneyTotal, sum( tbl.numTotal) numTotal from
(select tg.from_user_id, tg.to_user_id,(gift.price * tg.count) AS money, tg.count numTotal
from db_showtime_platform.tbl_user_gift_detail tg
LEFT JOIN db_showtime_platform.tbl_gift_list gift
ON gift.id = tg.gift_id
where date_format(tg.create_time,'%Y-%m-%d') = date_sub(curdate(),interval 1 day) ) tbl
group by tbl.from_user_id,tbl.to_user_id
</select>
<insert id="insertUserStaticsBatch" parameterType="java.util.List">
insert into db_showtime_stat.tbl_user_gift_statistics (
date ,
from_user_id ,
to_user_id ,
numTotal ,
moneyTotal
)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.date},#{item.fromUserId},#{item.toUserId},#{item.numTotal},#{item.moneyTotal})
</foreach>
</insert>
</mapper>