<?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.PianoRoomChangeRecordDao">
    <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.PianoRoomChangeRecord">
        <result column="id_" property="id" />
        <result column="user_id_" property="userId" />
        <result column="times_" property="times" />
        <result column="in_or_out_" property="inOrOut" />
        <result column="reason_" property="reason" />
        <result column="create_time_" property="createTime" />
        <result column="create_by_" property="createBy" />
        <result column="source_type_" property="sourceType" />
        <result column="biz_id_" property="bizId" />
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t.id_ as id
        , t.user_id_ as userId
        , t.times_ as times
        , t.in_or_out_ as inOrOut
        , t.reason_ as reason
        , t.create_time_ as createTime
        , t.create_by_ as createBy
        , t.source_type_ as sourceType
        , t.biz_id_ as bizId
    </sql>

    <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.PianoRoomChangeRecordVo">
        SELECT
            <include refid="baseColumns" />,
            ifnull(u.real_name_,u.username_) as operaUser
        FROM piano_room_change_record t
        left join sys_user u on t.create_by_ = u.id_
        where t.id_ = #{id}
    </select>

    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.PianoRoomChangeRecordVo">
        SELECT
            <include refid="baseColumns" />,
            ifnull(u.real_name_,u.username_) as operaUser
        FROM piano_room_change_record t
        left join sys_user u on t.create_by_ = u.id_
        <where>
            <if test="param.userId != null">
                and t.user_id_ = #{param.userId}
            </if>
            <if test="param.inOrOut != null">
                and t.in_or_out_ = #{param.inOrOut}
            </if>
            <if test="param.operaUser != null and param.operaUser != ''">
                and (
                    u.real_name_ LIKE CONCAT('%', #{param.operaUser}, '%') or u.username_ LIKE CONCAT('%', #{param.operaUser}, '%')
                )
            </if>
            <if test="param.startTime !=null">
                <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
            </if>
            <if test="param.endTime !=null">
                <![CDATA[AND t.create_time_ <= #{param.endTime} ]]>
            </if>
        </where>
    </select>
</mapper>