<?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 where type=1
        <where>
            <if test="userName != null and userName !=''">
                a.user_name like concat('%',#{userName},'%')
            </if>
            <if test="nickName != null and nickName !=''">
                a.nick_name like concat('%',#{nickName},'%')
            </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>
            <if test="companyWechatId != null and companyWechatId != ''">
                and a.company_wechat_id = #{companyWechatId}
            </if>
            <if test="companyWechatIds != null and companyWechatIds.size > 0">
                AND a.company_wechat_id IN
                <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by a.create_time desc
    </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.email,b.never_exprise,b.del as del2,b.create_time as create_time2,
        b.type,b.company_wechat_id as company_wechat_id2,b.company_name as company_name2
    </sql>
    <select id="pageCompanyWechat" resultType="com.gree.mall.manager.bean.admin.respDto.AdminCompanyWechatRespPageBean">
        select * from(
        SELECT DISTINCT
            a.*,
        <include refid="adminUserAllCol"/>
          from admin_company_wechat a
          LEFT JOIN admin_user b on b.company_wechat_id =a.company_wechat_id  and b.type=1
        <where>
            <if test="userName != null and userName !=''">b.user_name like concat('%',#{userName},'%')
            </if>
                <if test="nickName != null and nickName !=''">
                    b.nick_name like concat('%',#{nickName},'%')
                </if>
                <if test="linkPhone != null and linkPhone !=''">
                    b.link_phone like concat('%',#{linkPhone},'%')
                </if>
                <if test="email != null and email !=''">
                    b.email like concat('%',#{email},'%')
                </if>
                <if test="status != null">
                    b.status = #{status}
                </if>
                <if test="companyWechatId != null and companyWechatId !=''">
                    and a.company_wechat_id = #{companyWechatId}
                </if>
            </where>
            ORDER BY b.create_time
        )a
        GROUP BY a.company_wechat_id
    </select>

    <select id="sysDictList" resultType="com.gree.mall.manager.bean.common.SysDictVO">
        select
        a.*,
        b.remark as 'dictTypeName'
        from sys_dict a
        left join sys_dict_type b on a.dict_type=b.dict_type
        ${ex.query}
        and a.del=0
        <if test="ex.orderBy == null or ex.orderBy ==''">
            order by a.sort_num,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="companyWechatIds != null and companyWechatIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="companyWechatIds" 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="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>

</mapper>