<?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.AdwebSiteEnquiryRuleMapper">
    <select id="pageList" resultType="org.jeecg.modules.adweb.enquiry.entity.AdwebSiteEnquiryRule">
        SELECT t1.*, t2.num wasteEnquiryNum,t3.`name` siteName
        FROM `adweb_enquiry_site_rule` t1
        LEFT JOIN (
            SELECT
                   t1.reason,t1.site_code,count(*) num
            FROM
            (
                SELECT SUBSTRING_INDEX(effective_reason,'-',-1) reason,site_code
                FROM `adweb_enquiry`
                WHERE `status` = 1 AND user_effective = 0 AND sys_effective = 1 AND waste_enquiry_type = 'keyword'
            ) t1 GROUP BY t1.reason,t1.site_code
        ) t2 ON t2.reason LIKE CONCAT('%',t1.word,'%') AND t2.site_code = t1.site_code,adweb_site t3
        WHERE t1.site_id = t3.id
        AND t1.status = 1
        <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 = "adwebEnquirySiteRule.siteId != null and adwebEnquirySiteRule.siteId != ''" >
            AND t1.site_id = #{adwebEnquirySiteRule.siteId}
        </if>
        <if test="adwebEnquirySiteRule.word != null and adwebEnquirySiteRule.word != ''">
            AND t1.word like CONCAT('%', #{adwebEnquirySiteRule.word}, '%')
        </if>
        <if test="adwebEnquirySiteRule.blackOrWhite != null">
            AND t1.black_or_white = #{adwebEnquirySiteRule.blackOrWhite}
        </if>
    </select>
</mapper>
