UserGiftDetailMapper.xml 6.83 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.UserGiftDetail">
  <resultMap id="BaseResultMap" type="com.bjivt.entity.showtime.GiftDetail">
    <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" />
  </resultMap>
  
  <resultMap id="UserDetailMap" type="com.bjivt.entity.vo.UserGiftDetail">
    <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="name" jdbcType="VARCHAR" property="fromUserName" />
    <result column="name" jdbcType="VARCHAR" property="toUserName" />
    <result column="name" jdbcType="VARCHAR" property="liveName" />
    <result column="name" jdbcType="VARCHAR" property="giftName" />
  </resultMap>

  <sql id="Base_Column_List">
    id, from_user_id, to_user_id, live_id, gift_id, count, create_time
  </sql>
  <select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from tbl_user_gift_detail
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteById" parameterType="java.lang.Integer">
    delete from tbl_user_gift_detail
    where id = #{id,jdbcType=INTEGER}
  </delete>
  
   <select id="getCountBy" resultType="java.lang.Integer" parameterType="com.bjivt.entity.vo.UserGiftDetail">
    SELECT
				count(1)
			FROM
				tbl_user_gift_detail
    <trim prefix="where" prefixOverrides="and|or">
      <if test="liveId != null and liveId != ''" >
		        	 and   tbl_user_gift_detail.live_id = #{liveId}
		    	  </if>
      </trim>
  </select>
  
  <!-- 获取用户得到礼物的列表信息 -->
  <select id="findListByMap" resultMap="UserDetailMap" parameterType="java.util.Map">
     	select a.*, 
			(select name from tbl_user_list where id=a.from_user_id) fromUserName,
			(select name from tbl_user_list where id=a.to_user_id) toUserName,
			(select name from tbl_live_list where id=a.live_id) liveName,
			(select name from tbl_gift_list where id=a.gift_id) giftName
			from tbl_user_gift_detail a
  	  	<trim prefix="where" prefixOverrides="and|or">
		  	  	 <if test="UserGiftDetail.liveId != null and UserGiftDetail.liveId != ''" >
		        	 and   a.live_id = #{UserGiftDetail.liveId}
		    	  </if>
		  	  	 <if test="UserGiftDetail.fromUserId!= null and UserGiftDetail.fromUserId!= ''" >
		        	 and   a.from_user_id = #{UserGiftDetail.fromUserId}
		    	  </if>
		  	  	 <if test="UserGiftDetail.toUserId!= null and UserGiftDetail.toUserId!= ''" >
		        	 and   a.to_user_id = #{UserGiftDetail.toUserId}
		    	  </if>
		  	  	 <if test="UserGiftDetail.giftId!= null and UserGiftDetail.giftId!= ''" >
		        	 and   a.gift_id = #{UserGiftDetail.giftId}
		    	  </if>
  	  	</trim>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'createDate asc'">
  	  		order by a.create_time asc
  	  	</if>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'createDate desc'">
  	  		order by a.create_time desc
  	  	</if>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'count asc'">
  	  		order by a.count asc
  	  	</if>
  	  	<if test ="page.orderBy !=null and page.orderBy !='' and page.orderBy == 'count desc'">
  	  		order by a.count 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="findUserGiftListByMap" resultMap="UserDetailMap" parameterType="java.util.Map">
     	select a.*,  
	  		b.name fromUserName,
	  		e.name toUserName,
	        c.name liveName, 
	        d.name giftName
	   from tbl_user_gift_detail a
	   left join tbl_user_list b on b.id=a.from_user_id 
	   left join tbl_user_list e on e.id=a.to_user_id
	   left join tbl_live_list c on c.id=a.live_id
	   left join tbl_gift_list d on d.id=a.gift_id
     	<trim prefix="where" prefixOverrides="and|or">
		  	  	 <if test="UserGiftDetail.liveName != null and UserGiftDetail.liveName != ''" >
		        	 and   c.name like '%${UserGiftDetail.liveName}%'
		    	  </if>
		  	  	 <if test="UserGiftDetail.fromUserName!= null and UserGiftDetail.fromUserName!= ''" >
		        	 and   b.name = #{UserGiftDetail.fromUserName}
		    	  </if>
		  	  	 <if test="UserGiftDetail.toUserName!= null and UserGiftDetail.toUserName!= ''" >
		        	 and   e.name = #{UserGiftDetail.toUserName}
		    	  </if>
		  	  	 <if test="UserGiftDetail.giftName!= null and UserGiftDetail.giftName!= ''" >
		        	 and   d.name = #{UserGiftDetail.giftName}
		    	  </if>
  	  	</trim>
  	  	order by a.create_time
	    <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="findListByTime" resultMap="UserDetailMap" parameterType="java.util.Map">
     	select a.*, a.count(count),
			(select name from tbl_user_list where id=a.from_user_id) fromUserName,
			(select name from tbl_user_list where id=a.to_user_id) toUserName,
			from tbl_user_gift_detail a
			<!-- 
			select from_user_id, sum(numTotal), sum(moneyTotal) from tbl_user_gift_statistics where to_user_id=2 and 
date  between '2016-01-09' and  '2016-11-09'
group by from_user_id
			 -->
  	  	<trim prefix="where" prefixOverrides="and|or">
		  	  	 
		  	  	 <if test="UserGiftDetail.fromUserId!= null and UserGiftDetail.fromUserId!= ''" >
		        	 and   a.from_user_id = #{GiftList.fromUserId}
		    	  </if>
		  	  	 <if test="UserGiftDetail.toUserId!= null and UserGiftDetail.toUserId!= ''" >
		        	 and   a.to_user_id = #{UserGiftDetail.toUserId}
		    	  </if>
  	  	</trim>
  	  	add a.create_time between #{s_startTime} and #{s_endTime}
  	  	order by a.create_time
	    <if test="page != null and page !=''">
	    <if test="page.from != null and page.size != null">
          limit #{page.from},#{page.size}
   		</if>
   		</if>
  </select>
</mapper>