StatisticsAnchorMapper.xml 17.1 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="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>