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

	 
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ AS id
        , t.tenant_id_ AS tenantId
        , t.user_id_ AS userId
        , t.nickname_ AS nickname
        , t.im_token_ AS imToken
        , t.wechat_id_ AS wechatId
        , t.wx_openid_ AS wxOpenid
        , t.subscribe_flag_ AS subscribeFlag
        , t.manage_admin_ AS manageAdmin
        , t.introduction_ AS introduction
        , t.status_ AS status
        , t.update_time_ AS updateTime
        , t.create_time_ AS createTime
        </sql>
    <update id="updateUserId">
        update Tenant_staff set  user_id_ = #{newId}
        <where>
        </where>

    </update>

    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantStaffWrapper$TenantStaff">
        SELECT
        <include refid="baseColumns"/>
        ,su.avatar_ as avatar
        ,su.phone_ as phone
        ,if(t.wx_openid_ is null,false,true) bindStatus
        FROM tenant_staff t
        left join sys_user su on t.user_id_ = su.id_
        <where>
            <if test="param.keyword != null and param.keyword.trim() != ''">
                and (
                t.user_id_ like concat('%',#{param.keyword},'%')
                or t.nickname_ like concat('%',#{param.keyword},'%')
                or su.phone_ like concat('%',#{param.keyword},'%')
                )
            </if>
            <if test="param.tenantId != null">
                and t.tenant_id_ = #{param.tenantId}
            </if>
            <if test="param.status != null">
                and t.status_ = #{param.status}
            </if>
            <if test="param.manageAdmin != null">
                and t.manage_admin_ = #{param.manageAdmin}
            </if>
            <if test="param.bindStatus != null">
                <if test="param.bindStatus == 1">
                    and t.wx_openid_ is not null
                </if>
                <if test="param.bindStatus == 0">
                    and t.wx_openid_ is null
                </if>
            </if>
        </where>
        order by t.id_ desc
    </select>

    <select id="getByPhone" resultType="com.yonge.cooleshow.biz.dal.entity.TenantStaff">
        select
            <include refid="baseColumns" />
        ,t1.avatar_ as avatar
        from tenant_staff t
        left join sys_user t1 on t1.id_ = t.user_id_
        where t1.phone_ = #{phone}
    </select>
    <select id="selectByUserId" resultType="com.yonge.cooleshow.biz.dal.entity.TenantStaff">
        select <include refid="baseColumns" />
        ,su.avatar_ as avatar
        from  tenant_staff t
        left join sys_user su on t.user_id_ = su.id_
        where user_id_ = #{id}
    </select>
</mapper>