<?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="org.jeecg.modules.adweb.enquiry.mapper.AdwebSiteBlackEmailMapper">

    <select id="getPageList" resultType="org.jeecg.modules.adweb.enquiry.entity.AdwebSiteBlackEmail">
        SELECT t1.*,t2.`name` siteName,t3.num wasteEnquiryNum,t4.num wasteGeneralEnquiryNum
        FROM adweb_site_black_email t1
        LEFT JOIN (SELECT from_email, COUNT(*) num, site_id
        FROM `adweb_enquiry`
        WHERE `status` = 1
        AND user_effective = 0
        AND sys_effective = 1
        AND waste_enquiry_type = 'email'
        GROUP BY from_email, site_id) t3
        ON t1.email = t3.from_email AND t1.site_id = t3.site_id
        LEFT JOIN (
        SELECT t1.email,SUM(t2.num) num,t1.site_id FROM adweb_site_black_email t1
        LEFT JOIN (SELECT from_email, COUNT(*) num, site_id
        FROM `adweb_enquiry`
        WHERE `status` = 1
        AND user_effective = 0
        AND sys_effective = 1
        AND waste_enquiry_type = 'email'
        GROUP BY from_email,site_id) t2
        ON (t1.email != t2.from_email AND t2.from_email LIKE CONCAT('%',t1.email,'%') AND t1.site_id = t2.site_id)
        WHERE t1.`status` = 1
        GROUP BY t1.email, t1.site_id) t4
        ON t1.email = t4.email AND t1.site_id = t4.site_id
        ,adweb_site t2
        WHERE t1.site_id = t2.id
        AND t1.status = 1
        <if test="enquirySiteBlackEmail.siteId != null and enquirySiteBlackEmail.siteId != ''">
            AND t1.site_id = #{enquirySiteBlackEmail.siteId}
        </if>
        <if test="enquirySiteBlackEmail.email != null and enquirySiteBlackEmail.email != ''">
            AND t1.email like concat('%',#{enquirySiteBlackEmail.email},'%')
        </if>
        <if test="enquirySiteBlackEmail.blackOrWhite != null">
            AND t1.black_or_white = #{enquirySiteBlackEmail.blackOrWhite}
        </if>
        <if test="codeList != null">
            <choose>
                <when test="codeList.size() != 0">
                    AND t1.site_code IN
                    <foreach collection="codeList" item="code" open="(" close=")" separator=",">
                        #{code}
                    </foreach>
                </when>
            </choose>
        </if>
        <if test="column != null and column != ''">
            ORDER BY
            <if test="column == 'createTime'">
                t1.create_time ${order}
            </if>
            <if test="column == 'email'">
                t1.email ${order}
            </if>
        </if>
    </select>
</mapper>
