<?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.yonge.cooleshow.biz.dal.dao.ActivityRewardChangeStockDao">
	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.ActivityRewardChangeStock">
            <result column="id_" property="id" />
	        <result column="reward_id_" property="rewardId" />
	        <result column="stock_" property="stock" />
	        <result column="change_type_" property="changeType" />
            <result column="source_" property="source" />
            <result column="create_time_" property="createTime" />
	        <result column="create_by_" property="createBy" />
		</resultMap>  

    <!-- 表字段 -->
    <sql id="baseColumns">
        t.id_ as id
        , t.reward_id_ as rewardId
        , t.stock_ as stock
        , t.change_type_ as changeType
        , t.source_ as `source`
        , t.create_time_ as createTime
        , t.create_by_ as createBy
    </sql>

    <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.ActivityRewardChangeStockVo">
        SELECT
        <include refid="baseColumns"/>
        FROM activity_reward_change_stock t
        where t.id_ = #{id}
    </select>

    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.ActivityRewardChangeStockVo">
        SELECT
            <include refid="baseColumns" />,
            u.username_ as updateByName
        FROM activity_reward_change_stock t
        left join sys_user u on t.create_by_ = u.id_
        <where>
            <if test="param.rewardId != null">
                and t.reward_id_ = #{param.rewardId}
            </if>
            <if test="param.source != null and param.source != ''">
                and t.source_ = #{param.source}
            </if>
            <if test="param.changeType != null">
                and t.change_type_ = #{param.changeType}
            </if>
            <if test="param.updateByName != null and param.updateByName != ''">
                and u.username_ like CONCAT('%',#{param.updateByName},'%')
            </if>
            <if test="param.startTime !=null">
                and t.create_time_ &gt;= #{param.startTime}
            </if>
            <if test="param.endTime !=null">
                and t.create_time_ &lt;= #{param.endTime}
            </if>
        </where>
        order by t.create_time_ desc
    </select>
</mapper>