UserGiftStaMapper.xml 7.98 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.vo.StatisticsUserGift">
  <resultMap id="BaseResultMap" type="com.bjivt.entity.vo.StatisticsUserGift">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="date" jdbcType="DATE" property="date"  />
    <result column="from_user_id" jdbcType="INTEGER" property="fromUserId" />
    <result column="to_user_id" jdbcType="INTEGER" property="toUserId" />
    <result column="numTotal" jdbcType="INTEGER" property="numTotal" />
    <result column="moneyTotal" jdbcType="INTEGER" property="moneyTotal" />
    <result column="chinese_coin" jdbcType="INTEGER" property="chineseCoin" />
    <result column="fromUserName" jdbcType="VARCHAR" property="fromUserName" />
  </resultMap>
  <resultMap id="UserDetailMap" type="com.bjivt.entity.vo.StatisticsUserGift">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="from_user_id" jdbcType="INTEGER" property="fromUserId" />
    <result column="to_user_id" jdbcType="INTEGER" property="toUserId" />
    <result column="live_id" jdbcType="INTEGER" property="liveId" />
    <result column="gift_id" jdbcType="INTEGER" property="giftId" />
    <result column="count" jdbcType="INTEGER" property="count" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="fromUserName" jdbcType="VARCHAR" property="fromUserName" />
    <result column="toUserName" jdbcType="VARCHAR" property="toUserName" />
    <result column="liveName" jdbcType="VARCHAR" property="liveName" />
    <result column="giftName" jdbcType="VARCHAR" property="giftName" />
  </resultMap>
  
	<resultMap id="UserIdListMap" type="java.lang.String" >
	    <result column="from_user_id" property="id" />
	</resultMap>

  <sql id="Base_Column_List">
    id, date,from_user_id, to_user_id, numTotal, moneyTotal
  </sql>
  <select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from db_showtime_stat.tbl_user_gift_statistics
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteById" parameterType="java.lang.Integer">
    delete from db_showtime_stat.tbl_user_gift_statistics
    where id = #{id,jdbcType=INTEGER}
  </delete>
  
   <select id="getCountBy" resultType="java.lang.Integer" parameterType="com.bjivt.entity.vo.StatisticsUserGift">
    SELECT
				count(*)
			FROM
				db_showtime_stat.tbl_user_gift_statistics
    <trim prefix="where" prefixOverrides="and|or">
      <if test="fromUserId != null and fromUserId != ''" >
		        	 and  db_showtime_stat.tbl_user_gift_statistics.to_user_id = #{StatisticsUserGift.id}
		    	  </if>
      </trim>
  </select>
  
  
  	
	 
    
  <!-- 获取用户得到礼物的列表信息 -->
  <select id="findListByMap" resultMap="UserDetailMap" parameterType="java.util.Map">
     	select a.*, 
     		b.name fromUserName,
	  		e.name toUserName
	  		from db_showtime_stat.tbl_user_gift_statistics a
	  		 
	  		inner join tbl_user_list b on b.id=a.from_user_id 
	   		inner join tbl_user_list e on e.id=a.to_user_id
			<trim prefix="where" prefixOverrides="and|or">
		  	  	 <if test="StatisticsUserGift.id!= null and StatisticsUserGift.id != ''" >
		        	 and   a.to_user_id = #{StatisticsUserGift.id}
		    	  </if>
		  	  </trim>
		 <if test ="page.orderBy !=null and page.orderBy ==''">
  	  		order by a.numTotal desc
  	  	</if>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'numTotal asc'">
  	  		order by a.numTotal asc
  	  	</if>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'numTotal desc'">
  	  		order by a.numTotal desc
  	  	</if>
  	  	 <if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'moneyTotal asc'">
  	  		order by a.moneyTotal asc
  	  	</if>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'moneyTotal desc'">
  	  		order by a.moneyTotal desc
  	  	</if>
  	  	 <if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'chineseCoin asc'">
  	  		order by a.chinese_coin asc
  	  	</if>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'chineseCoin desc'">
  	  		order by a.chinese_coin desc
  	  	</if>
	    <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="findUserGfitList" resultMap="UserIdListMap" parameterType="java.util.Map">
     	select distinct a.from_user_id
	  		from tbl_user_gift_detail a
 		where a.to_user_id=#{toUserId,jdbcType=INTEGER}
          limit 0,10
  </select>
  
  
  
  <select id="findListByPager" resultMap="BaseResultMap" parameterType="java.util.Map">
			select a.from_user_id,b.name fromUserName, sum(a.numTotal) numTotal, sum(a.moneyTotal) moneyTotal,b.chinese_coin
			from db_showtime_stat.tbl_user_gift_statistics a
			INNER join tbl_user_list b on b.id=a.from_user_id 
			<trim prefix="where" prefixOverrides="and|or">
				<if test="toUserId != null and toUserId !=''">
					and a.to_user_id = #{toUserId}
				</if>
				<if test="startTime != null and startTime !=''  and endTime != null and endTime !=''">
					and date_format(a.date,'%Y-%m-%d')  between str_to_date(#{startTime},'%Y-%m-%d') and str_to_date(#{endTime},'%Y-%m-%d')
				</if>
			</trim>
			group by a.from_user_id
			
	   <if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'createDate desc'">
  	  		order by numTotal desc
  	  	</if>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'numTotal asc'">
  	  		order by numTotal asc
  	  	</if>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'numTotal desc'">
  	  		order by numTotal desc
  	  	</if>
  	  	 <if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'moneyTotal asc'">
  	  		order by moneyTotal asc
  	  	</if>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'moneyTotal desc'">
  	  		order by moneyTotal desc
  	  	</if>
  	  	 <if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'chineseCoin asc'">
  	  		order by b.chinese_coin asc
  	  	</if>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'chineseCoin desc'">
  	  		order by b.chinese_coin desc
  	  	</if>
	    <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="getCountByParam" resultType="java.lang.Integer" parameterType="java.util.Map">
			select count(*)
			from db_showtime_stat.tbl_user_gift_statistics a
			inner join tbl_user_list b on b.id=a.from_user_id 
			<trim prefix="where" prefixOverrides="and|or">
				<if test="toUserId != null and toUserId !=''">
					and a.to_user_id = #{toUserId}
				</if>
				<if test="startTime != null and startTime !=''  and endTime != null and endTime !=''">
					and date_format(a.date,'%Y-%m-%d') between str_to_date(#{startTime},'%Y-%m-%d') and  str_to_date(#{endTime},'%Y-%m-%d') 
				</if>
			</trim>
			
  </select>
  
  <select id="findAllList" resultMap="BaseResultMap" parameterType="java.util.Map">
			select a.from_user_id,b.name fromUserName, sum(a.numTotal) numTotal, sum(a.moneyTotal) moneyTotal,b.chinese_coin
			from db_showtime_stat.tbl_user_gift_statistics a
			inner join tbl_user_list b on b.id=a.from_user_id 
			<trim prefix="where" prefixOverrides="and|or">
				<if test="toUserId != null and toUserId !=''">
					and a.to_user_id = #{toUserId}
				</if>
				<if test="startTime != null and startTime !='' and endTime != null and endTime !=''">
					and date_format(a.date,'%Y-%m-%d')  between str_to_date(#{startTime},'%Y-%m-%d') and  str_to_date(#{endTime},'%Y-%m-%d')
				</if>
			</trim>
			group by a.from_user_id
  </select>
  
</mapper>