DailyStatisticsMapper.xml 5.07 KB
<?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="DailyStatisticsMapper">
	<resultMap id="DailyStatistics" type="com.bjivt.job.executor.service.jobhandler.mijia.model.DailyStatistics">
		<id column="id" jdbcType="INTEGER" property="id" />
        <result property="date" column="date" jdbcType="TIMESTAMP"/>
        <result property="newUserCount" column="new_user_count" jdbcType="INTEGER"/>
        <result property="newBroadcasterCount" column="new_broadcaster_count" jdbcType="INTEGER"/>
        <result property="userTotalCount" column="user_total_count" jdbcType="INTEGER"/>
        <result property="broadcasterTotalCount" column="broadcaster_total_count" jdbcType="INTEGER"/>
        <result property="incomeTotal" column="income_total" jdbcType="INTEGER"/>
        <result property="monetaryTotal" column="monetary_total" jdbcType="INTEGER"/>
        <result property="withdrawalsTotal" column="withdrawals_total" jdbcType="INTEGER"/>
        <result property="liveTotal" column="live_total" jdbcType="INTEGER" />
	</resultMap>
	
	<!-- 用于select查询公用抽取的列 -->
	<sql id="columns">
	    <![CDATA[
		id,date,new_user_count,new_broadcaster_count,user_total_count,broadcaster_total_count,income_total,monetary_total,withdrawals_total,live_total
	    ]]>
	</sql>

	<!-- useGeneratedKeys="true" keyProperty="xxx" for sqlserver and mysql -->
	<insert id="insert" parameterType="com.bjivt.job.executor.service.jobhandler.mijia.model.DailyStatistics">
    <![CDATA[
        INSERT INTO db_showtime_stat.tbl_daily_statistics (
        	date ,
        	new_user_count ,
        	new_broadcaster_count ,
        	user_total_count ,
        	broadcaster_total_count ,
        	income_total ,
        	monetary_total ,
        	withdrawals_total ,
        	live_total 
        ) VALUES (
        	#{date} ,
        	#{newUserCount} ,
        	#{newBroadcasterCount} ,
        	#{userTotalCount} ,
        	#{broadcasterTotalCount} ,
        	#{incomeTotal} ,
        	#{monetaryTotal} ,
        	#{withdrawalsTotal} ,
        	#{liveTotal} 
        )
    ]]>
    </insert>
	<!-- 新增用户 -->
  <select id="getNewUser" resultType="java.lang.Integer" parameterType="java.util.HashMap">
    SELECT count(id)
			FROM db_showtime_platform.tbl_user_list
			where date_format(create_time,'%Y-%m-%d') = date_sub(curdate(),interval 1 day) 
  </select>
	<!-- 新增主播 -->
  <select id="getNewAnchor" resultType="java.lang.Integer" parameterType="java.util.HashMap">
		select count(t.user_id) as counts from db_showtime_platform.tbl_live_list t where 
		date_format(t.create_time,'%Y-%m-%d') =  date_sub(curdate(),interval 1 day) 
		 and user_id not in 
		 (select distinct u.user_id from db_showtime_platform.tbl_live_list u 
		 group by u.user_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)
		 group by t.user_id
		having sum(TIMESTAMPDIFF(hour, t.create_time, case when t.ended_time  is null  then t.create_time else t.ended_time  end))>=1
  </select>
	<!-- 用户总数 -->
  <select id="getUserTotal" resultType="java.lang.Integer" parameterType="java.util.HashMap">
	select count(*) as counts FROM db_showtime_platform.tbl_user_list  
	</select>
	<!-- 主播总数 -->
  <select id="getAnchorTotal" resultType="java.lang.Integer" parameterType="java.util.HashMap">
		select count(distinct t.user_id) as counts from db_showtime_platform.tbl_live_list t 
		having sum(TIMESTAMPDIFF(hour, t.create_time, case when t.ended_time  is null  then t.create_time else t.ended_time  end))>=1
	</select>
	<!-- 今日充值金额 -->
  <select id="getRechargeTotal" resultType="java.lang.Integer" parameterType="java.util.HashMap">
		select sum(money) as counts from db_showtime_log.tbl_recharge_record r
  where date_format(r.record_time,'%Y-%m-%d') =  date_sub(curdate(),interval 1 day) 
	</select>
	<!-- 今日消费总金额 -->
  <select id="getConsumeTotal" resultType="java.lang.Integer" parameterType="java.util.HashMap">
	  select (redenvelop.counts+giftprice.counts) as counts from (
	 (select sum(money) as counts from db_showtime_log.tbl_redenvelop_record r
	  where date_format(r.record_time,'%Y-%m-%d') =  date_sub(curdate(),interval 1 day)) as redenvelop, 
	  (select sum(r.gift_count*r.gift_price) as counts from db_showtime_log.tbl_usergift_record r
	  where date_format(r.record_time,'%Y-%m-%d') =  date_sub(curdate(),interval 1 day)) as giftprice)
	</select>
	<!-- 今日提现总金额 -->
  <select id="getWithdrawTotal" resultType="java.lang.Integer" parameterType="java.util.HashMap">
	  select sum(me_coin) as counts from db_showtime_log.tbl_withdraw_record r
	  where date_format(r.record_time,'%Y-%m-%d') =  date_sub(curdate(),interval 1 day)
	</select>
	<!-- 今日直播总数 -->
  <select id="getLiveTotal" resultType="java.lang.Integer" parameterType="java.util.HashMap">
  	select count(t.id) as counts from db_showtime_platform.tbl_live_list t where 
	date_format(t.create_time,'%Y-%m-%d') =  date_sub(curdate(),interval 1 day) 
	</select>
	
</mapper>