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


    <select id="list" resultType="com.gree.mall.manager.bean.admin.EnterpriseWechatWorkerImportList">
        SELECT aw.websit_number as websitNum, eww.*
        FROM `enterprise_wechat_worker` eww
        left join admin_websit aw on eww.main_department = aw.websit_id and aw.corp_id = eww.corp_id
        <where>
            <if test="mainDepartmentIds != null and mainDepartmentIds.size > 0">
                and eww.main_department in
                <foreach collection="mainDepartmentIds" separator="," item="mdId" open="(" close=")">
                    #{mdId}
                </foreach>
            </if>
            <if test="keyword != null and keyword != ''">
                and (
                    eww.name like concat('%',#{keyword},'%')
                    or eww.wechat_user_id like concat('%',#{keyword},'%')
                    or eww.mobile like concat('%',#{keyword},'%')
                )
            </if>
            <if test="corpIds != null and  corpIds.size > 0">
                and eww.corp_id in
                <foreach collection="corpIds" open="(" close=")" item="corpId" separator=",">
                    #{corpId}
                </foreach>
            </if>
            <if test="corpId != null and  corpId != ''">
                and eww.corp_id = #{corpId}
            </if>
        </where>
        GROUP BY eww.id
        order by eww.create_time desc
    </select>
</mapper>