<?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.gree.mall.manager.commonmapper.AdminMapper">

    <select id="mchList" resultType="com.gree.mall.manager.plus.entity.AdminUser">
        select a.* from admin_user a
        join admin_user_company_rela b on a.admin_user_id = b.admin_user_id
        join admin_company_wechat c on c.company_wechat_id = b.company_id
        <where>
            <if test="userName != null and userName !=''">
                a.user_name like concat('%',#{userName},'%')
            </if>

            <if test="companyName != null and companyName !=''">
                a.company_name like concat('%',#{companyName},'%')
            </if>
            <if test="linkPhone != null and linkPhone !=''">
                a.link_phone like concat('%',#{linkPhone},'%')
            </if>
            <if test="email != null and email !=''">
                a.email like concat('%',#{email},'%')
            </if>
            <if test="status != null">
                a.status = #{status}
            </if>
        </where>
        order by a.create_time desc
    </select>

    <select id="queryAdminCompanyWechat" resultType="com.gree.mall.manager.plus.entity.AdminCompanyWechat">
        select b.* from admin_user_company_rela a join admin_company_wechat b on a.company_id = b.company_wechat_id
      where  b.del=0
      <if test="adminUserId != null and adminUserId !=''">
          and a.admin_user_id = #{adminUserId}
      </if>
    </select>

    <select id="getAdminUser" resultType="com.gree.mall.manager.plus.entity.AdminUser">
        SELECT u.*
        from admin_user_company_rela aucr
        join admin_user u on aucr.admin_user_id=u.admin_user_id
        <where>
            <if test="roleId != null and roleId != ''">
                and u.role_id = #{roleId}
            </if>
            <if test="status != null and status != ''">
                and u.status = #{status}
            </if>
            <if test="userName != null and userName != ''">
                and u.user_name like concat('%',#{userName},'%')
            </if>
            <if test="companyIds != null and companyIds.size > 0">
                and aucr.company_id in
                <foreach item="item" index="index" collection="companyIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>


    <sql id="adminUserAllCol">
        b.admin_user_id, b.nick_name,b.status,b.role_id,b.role_name,b.last_login_time,b.user_name,
        b.password,b.link_name,b.link_phone,b.email,b.address,b.never_exprise,b.del as del2,b.create_time as create_time2,
        b.type,b.company_id as company_wechat_id2,b.company_name as company_name2
    </sql>

    <select id="list" resultType="com.gree.mall.manager.bean.admin.AdminDeptWebsitVO">
        SELECT
        ${ex.selected}
        FROM admin_dept_websit a
        ${ex.query}
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
    <select id="sysDictCompanyList" resultType="com.gree.mall.manager.bean.common.SysDictCompanyVO">
        select
        a.*,
        b.remark as 'dictTypeName'
        from sys_dict_company a
        left join sys_dict_type_company b on a.dict_type=b.dict_type
        ${ex.query}
        and a.del=0
        <if test="companyIds != null and companyIds.size > 0">
            AND a.company_id IN
            <foreach item="item" index="index" collection="companyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            order by a.sort_num,a.create_time desc
        </if>
        ${ex.orderBy}
    </select>
    <select id="listWebsit" resultType="com.gree.mall.manager.bean.admin.AdminWebsitVO">
        SELECT
        ${ex.selected}
        FROM admin_websit a
        ${ex.query}
        <if test="ex.companyIds != null and ex.companyIds.size > 0">
            and company_id in
            <foreach item="item" index="index" collection="ex.companyIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            and websit_id in
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}

    </select>

</mapper>