<?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.TenantApplyRecordMapper">

	 
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ AS id
        , t.tenant_id_ AS tenantId
        , t.name_ AS name
        , t.logo_ AS logo
        , t.province_code_ AS provinceCode
        , t.city_code_ AS cityCode
        , t.region_code_ AS regionCode
        , t.username_ AS username
        , t.phone_ AS phone
        , t.user_id_ AS userId
        , t.status_ AS status
        , t.verify_user_id_ AS verifyUserId
        , t.reason_ AS reason
        , t.update_time_ AS updateTime
        , t.create_time_ AS createTime
        , t.brief_Introduction_ AS briefIntroduction
        </sql>
    <update id="updateStatusById">
        update  tenant_apply_record
        set status_ = 'PASS'
        where  id_ =#{id}
    </update>
    <update id="updateUnpassStatusById">
        update  tenant_apply_record
        set status_ = 'UNPASS'
        where  id_ =#{id}
    </update>

    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantApplyRecordWrapper$TenantApplyRecord">
        SELECT * from(
            SELECT
            t.id_ AS id
            , t.name_ AS name
            , t.logo_ AS logo
            , t.province_code_ AS provinceCode
            , t.city_code_ AS cityCode
            , t.region_code_ AS regionCode
            , t.username_ AS username
            , t.phone_ AS phone
            , t.user_id_ AS userId
            , t.status_ AS status
            , t.verify_user_id_ AS verifyUserId
            , t.reason_ AS reason
            , t.update_time_ AS updateTime
            , t.create_time_ AS createTime
            , t.brief_Introduction_ AS briefIntroduction
            , if(t.status_='PASS',su.del_flag_,0) userDelFlag
            FROM tenant_apply_record t
            left join sys_user su on t.user_id_ = su.id_
            <where>
                <if test="param.keyword != null and param.keyword  != ''">
                    and (
                    t.name_ like concat('%',#{param.keyword},'%')
                    or t.username_ like concat('%',#{param.keyword},'%')
                    or t.phone_ like concat('%',#{param.keyword},'%')
                    )
                </if>
                <if test="param.provinceCode != null">
                    and t.province_code_ = #{param.provinceCode}
                </if>
                <if test="param.cityCode != null">
                    and t.city_code_ = #{param.cityCode}
                </if>
                <if test="param.regionCode != null">
                    and t.region_code_ = #{param.regionCode}
                </if>
            </where>
        ) k
        where k.userDelFlag = 0
    </select>
    <select id="selectHistoryPage"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantApplyRecordWrapper$TenantApply">
        select
        id_ AS id,
        tenant_apply_record_id_ AS tenantApplyRecordId,
        name_ AS name,
        logo_ as logo,
        province_code_ AS provinceCode,
        city_code_ AS cityCode,
        region_code_ AS regionCode,
        username_ AS username,
        phone_ AS phone,
        status_ AS status,
        verify_user_id_ AS verifyUserId,
        reason_ AS reason,
        update_time_ AS updateTime,
        create_time_ AS createTime,
        brief_Introduction_ AS briefIntroduction
        FROM
        tenant_entry_record
        WHERE
        1=1
        <if test="id != null">
            and tenant_apply_record_id_ = #{id}
        </if>
        order by update_time_ DESC
    </select>
    <select id="queryNow"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantApplyRecordWrapper$TenantApplyRecord">
        select
        id_ AS id,
        name_ AS name,
        logo_ as logo,
        province_code_ AS provinceCode,
        city_code_ AS cityCode,
        region_code_ AS regionCode,
        username_ AS username,
        phone_ AS phone,
        status_ AS status,
        verify_user_id_ AS verifyUserId,
        reason_ AS reason,
        update_time_ AS updateTime,
        create_time_ AS createTime,
        brief_Introduction_ AS briefIntroduction
        from
        tenant_apply_record
        where
        1=1
        <if test="param.id != null">
            and
            id_ = #{param.id}
        </if>
    </select>
    <select id="queryLast"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantApplyRecordWrapper$LastRecord">
        select
        id_ AS id,
        name_ AS name,
        logo_ as logo,
        province_code_ AS provinceCode,
        city_code_ AS cityCode,
        region_code_ AS regionCode,
        username_ AS username,
        phone_ AS phone,
        status_ AS status,
        verify_user_id_ AS verifyUserId,
        reason_ AS reason,
        update_time_ AS updateTime,
        create_time_ AS createTime,
        brief_Introduction_ AS briefIntroduction
        from
        tenant_apply_record
        where
        1=1
        <if test="param.id != null">
            and
            id_ = #{param.id}
        </if>
        ORDER BY update_time_ desc
        limit 1,1
    </select>
    <select id="selectEntry"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantApplyRecordWrapper$LastRecord">
        select
        id_ AS id,
        tenant_apply_record_id_ AS tenantApplyRecordId,
        name_ AS name,
        logo_ as logo,
        province_code_ AS provinceCode,
        city_code_ AS cityCode,
        region_code_ AS regionCode,
        username_ AS username,
        phone_ AS phone,
        status_ AS status,
        verify_user_id_ AS verifyUserId,
        reason_ AS reason,
        update_time_ AS updateTime,
        create_time_ AS createTime,
        brief_Introduction_ AS briefIntroduction
        from
        tenant_entry_record
        where
        1=1
        <if test="id != null">
            and
            tenant_apply_record_id_ = #{id}
        </if>
        ORDER BY update_time_ desc
        limit 1
    </select>
    <select id="selectLastEntry"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantApplyRecordWrapper$TenantApplyRecord">
        select
        id_ AS id,
        tenant_apply_record_id_ AS tenantApplyRecordId,
        name_ AS name,
        logo_ as logo,
        province_code_ AS provinceCode,
        city_code_ AS cityCode,
        region_code_ AS regionCode,
        username_ AS username,
        phone_ AS phone,
        status_ AS status,
        verify_user_id_ AS verifyUserId,
        reason_ AS reason,
        update_time_ AS updateTime,
        create_time_ AS createTime,
        brief_Introduction_ AS briefIntroduction
        from
        tenant_entry_record
        where
        1=1
        <if test="id != null">
            and
            tenant_apply_record_id_ = #{id}
        </if>
        ORDER BY update_time_ desc
        limit 1
    </select>
    <select id="selectSecondEntry"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantApplyRecordWrapper$LastRecord">
        select
        id_ AS id,
        tenant_apply_record_id_ AS tenantApplyRecordId,
        name_ AS name,
        logo_ as logo,
        province_code_ AS provinceCode,
        city_code_ AS cityCode,
        region_code_ AS regionCode,
        username_ AS username,
        phone_ AS phone,
        status_ AS status,
        verify_user_id_ AS verifyUserId,
        reason_ AS reason,
        update_time_ AS updateTime,
        create_time_ AS createTime,
        brief_Introduction_ AS briefIntroduction
        from
        tenant_entry_record
        where
        1=1
        <if test="id != null">
            and
            tenant_apply_record_id_ = #{id}
        </if>
        ORDER BY update_time_ desc
        limit 1,1
    </select>

</mapper>