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

 <select id="getPageList" resultType="org.jeecg.modules.adweb.enquiry.entity.AdwebSiteBlackIp">
    SELECT t1.*,t3.`name` siteName, t2.num wasteEnquiryNum
    FROM adweb_site_black_ip t1
     LEFT JOIN (SELECT customer_ip, site_code,COUNT(*) num
     FROM `adweb_enquiry`
     WHERE `status` = 1
     AND user_effective = 0
     AND sys_effective = 1
     AND waste_enquiry_type = 'ip'
     GROUP BY customer_ip,site_code) t2
     ON t1.ip = t2.customer_ip AND t2.site_code = t1.site_code
       ,adweb_site t3
    WHERE t1.site_id = t3.id
      AND t1.status = 1
    <if test = "adwebSiteBlackIp.siteId != null and adwebSiteBlackIp.siteId != ''" >
        AND t1.site_id = #{adwebSiteBlackIp.siteId}
    </if>
    <if test = "adwebSiteBlackIp.ip != null and adwebSiteBlackIp.ip != ''" >
        AND t1.ip like concat('%',#{adwebSiteBlackIp.ip},'%')
    </if>
    <if test = "adwebSiteBlackIp.blackOrWhite != null">
        AND t1.black_or_white = #{adwebSiteBlackIp.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>
 </select>
</mapper>
