<?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.mapper.TenantUnbindRecordMapper">
    <!-- 表字段 -->
    <sql id="baseColumns">
        t.id_ AS id
        , t.tenant_id_ AS tenantId
        , t.tenant_name_ AS tenantName
        , t.user_id_ AS userId
        , t.user_name_ AS userName
        , t.phone_ AS phone
        , t.user_type_ AS userType
        , t.unbind_reason_ AS unbindReason
        , t.status_ AS status
        , t.verify_user_id_ AS verifyUserId
        , t.reason_ AS reason
        , t.intervene_time_ AS interveneTime
        , t.update_time_ AS updateTime
        , t.create_time_ AS createTime
    </sql>

    <select id="selectPage"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantUnbindRecordWrapper$TenantUnbindRecord">
        SELECT
        <include refid="baseColumns"/>
        ,ti.province_code_ as provinceCode
        ,ti.city_code_ as cityCode
        ,ti.region_code_ as regionCode
        ,ti.username_ as tenantUserName
        ,ti.phone_ as tenantPhone
        ,te.avatar_ as avatar
        FROM tenant_unbind_record t
        LEFT JOIN tenant_info ti ON ti.id_ = t.tenant_id_
        LEFT JOIN teacher te on te.user_id_ = t.user_id_
        <where>
            <if test="param.keyword != null and param.keyword.trim() != ''">
                AND (
                t.user_name_ like concat ('%',#{param.keyword},'%') or
                t.phone_ like concat ('%',#{param.keyword},'%') or
                ti.name_ like concat ('%',#{param.keyword},'%') or
                ti.username_ like concat ('%',#{param.keyword},'%') or
                ti.phone_ like concat ('%',#{param.keyword},'%')
                )
            </if>
            <if test="param.userType != null">
                AND t.user_type_ = #{param.userType}
            </if>
            <if test="param.provinceCode != null">
                AND ti.province_code_ = #{param.provinceCode}
            </if>
            <if test="param.cityCode != null">
                AND ti.city_code_ = #{param.cityCode}
            </if>
            <if test="param.regionCode != null">
                AND ti.region_code_ = #{param.regionCode}
            </if>
            <if test="param.status != null">
                AND t.status_ = #{param.status}
            </if>
        </where>
        order by t.status_='DOING' desc, t.update_time_ desc
    </select>

    <select id="getRecord" resultType="com.yonge.cooleshow.biz.dal.entity.TenantUnbindRecord">
        SELECT
        <include refid="baseColumns"/>
        FROM tenant_unbind_record t
        where tenant_id_ = #{tenantId} and user_id_ = #{userId} and user_type_ = #{userType}
    </select>
</mapper>