StatisticsUserMapper.xml 7.73 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.StatisticsUser">
  	<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="getUserDataByMap"  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 
	   <if test="id != null and id !=''">
	   	where tu.id=#{id}
	   </if>
	    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>  
  <select id="getUserDataCountBy" resultType="java.lang.Integer" parameterType="java.util.Map">
    SELECT
				count(id)
			FROM
				tbl_user_list
  </select>
   <!-- 统计观众观看时长-->  
  <select id="getUserVisitTime"  parameterType="java.util.Map" resultType="com.bjivt.entity.vo.StatisticsResult">
    <if test="types==0 or types==1" >
    	select date_format(u.record_time,'%Y-%m-%d') time, sum(TIMESTAMPDIFF(SECOND, u.record_time, case when u.end_time  is null  then u.record_time else u.end_time  end)) as counts
  		from db_showtime_log.tbl_live_record u where u.mark=1 and u.visit_user_id=${id} and u.record_time is not null 
    	<if test="startTime !=null and startTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d')   ]]>
		</if>
		<if test="endTime !=null and endTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d')   ]]>
		</if>
		group by time
    
    </if>
    <if test="types==2">
    
    	select date_format(u.record_time,'%Y年第%u周') time, sum(TIMESTAMPDIFF(SECOND, u.record_time, case when u.end_time  is null  then u.record_time else u.end_time  end)) as counts
  		from db_showtime_log.tbl_live_record u where u.mark=1 and u.visit_user_id=${id} and u.record_time is not null
    	<if test="startTime !=null and startTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d')   ]]>
		</if>
		<if test="endTime !=null and endTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d')   ]]>
		</if>
		group by time
    	
    </if>
    <if test="types==3">
    
    	select date_format(u.record_time,'%Y年%m月') time, sum(TIMESTAMPDIFF(SECOND, u.record_time, case when u.end_time  is null  then u.record_time else u.end_time  end)) as counts
  		from db_showtime_log.tbl_live_record u where u.mark=1 and u.visit_user_id=${id} and u.record_time is not null
    	<if test="startTime !=null and startTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d')   ]]>
		</if>
		<if test="endTime !=null and endTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d')   ]]>
		</if>
		group by time
    	
    </if>
    <if test="types==4">
    	select date_format(u.record_time,'%Y年') time, sum(TIMESTAMPDIFF(SECOND, u.record_time, case when u.end_time  is null  then u.record_time else u.end_time  end)) as counts
  		from db_showtime_log.tbl_live_record u where u.mark=1 and u.visit_user_id=${id} and u.record_time is not null
		and date_format(u.record_time,'%Y') between date_format(#{startTime},'%Y') and date_format(#{endTime},'%Y') 
		group by time
    </if>
 </select>  
   <!-- 统计用户充值金额-->  
  <select id="getUserRecharge"  parameterType="java.util.Map" resultType="com.bjivt.entity.vo.StatisticsResult">
    <if test="types==0 or types==1" >
    	select date_format(u.record_time,'%Y-%m-%d') time,sum( case when u.money is null  then 0 else u.money  end ) as counts 
  		from db_showtime_log.tbl_recharge_record u where u.user_id=${id} and u.record_time is not null 
    	<if test="startTime !=null and startTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d')   ]]>
		</if>
		<if test="endTime !=null and endTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d')   ]]>
		</if>
		group by time
    
    </if>
    <if test="types==2">
    
    	select date_format(u.record_time,'%Y年第%u周') time,sum( case when u.money is null  then 0 else u.money  end ) as counts 
  		from db_showtime_log.tbl_recharge_record u where u.user_id=${id} and u.record_time is not null 
    	<if test="startTime !=null and startTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d')   ]]>
		</if>
		<if test="endTime !=null and endTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d')   ]]>
		</if>
		group by time
    	
    </if>
    <if test="types==3">
    	select date_format(u.record_time,'%Y年%m月') time,sum( case when u.money is null  then 0 else u.money  end ) as counts 
  		from db_showtime_log.tbl_recharge_record u where u.user_id=${id} and u.record_time is not null 
    	<if test="startTime !=null and startTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') >= str_to_date(#{startTime},'%Y-%m-%d')   ]]>
		</if>
		<if test="endTime !=null and endTime!=''">
	   	 	<![CDATA[   and date_format(u.record_time,'%Y-%m-%d') <= str_to_date(#{endTime},'%Y-%m-%d')   ]]>
		</if>
		group by time
    	
    </if>
    <if test="types==4">
    	select date_format(u.record_time,'%Y年') time,sum( case when u.money is null  then 0 else u.money  end ) as counts 
  		from db_showtime_log.tbl_recharge_record u where u.user_id=${id} and u.record_time is not null 
		and date_format(u.record_time,'%Y') between date_format(#{startTime},'%Y') and date_format(#{endTime},'%Y') 
		group by time
    </if>
 </select>  

</mapper>