<?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.ReturnVisitDao">
	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.ReturnVisit">
            <result column="id_" property="id" />
	        <result column="user_id_" property="userId" />
	        <result column="client_type_" property="clientType" />
	        <result column="title_" property="title" />
	        <result column="content_" property="content" />
	        <result column="create_time_" property="createTime" />
	        <result column="create_by_" property="createBy" />
		</resultMap>  
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ as id
        , t.user_id_ as userId
        , t.client_type_ as clientType
        , t.title_ as title
        , t.content_ as content
        , t.create_time_ as createTime
        , t.create_by_ as createBy
        </sql> 
    
    <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.ReturnVisitVo">
        SELECT
            <include refid="baseColumns"/>
        FROM return_visit t
        where t.id_ = #{id}
    </select>
    
    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.ReturnVisitVo">
		SELECT         
        	<include refid="baseColumns" />
        ,su.username_ as username
        ,su.phone_ as phone
		FROM return_visit t
        left join sys_user su on t.user_id_ = su.id_
        <where>
            <if test="param.clientType != null">
                and #{param.clientType} = t.client_type_
            </if>
            <if test="param.userId != null">
                and #{param.userId} = t.user_id_
            </if>
            <if test="param.username != null and param.username != ''">
                and su.username_ like '%${param.username}%'
            </if>
            <if test="param.title != null and param.title != ''">
                and t.title_ like '%${param.title}%'
            </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>
            <if test="param.search !=null and param.search != ''">
                and (su.id_ like '%${param.search}%'
                    or su.username_ like '%${param.search}%'
                    or su.phone_ like '%${param.search}%'
                )
            </if>
        </where>
        order by t.id_ desc
	</select>
</mapper>