<?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.zfire.mall.manager.commonmapper.policy.PolicyCommonMapper">

    <select id="queryPolicyCustomer" resultType="com.zfire.mall.manager.bean.policy.PolicyBean">
        select
            a.* ,
            count(1) as 'customer_count'
            from policy a
        join policy_customer b on a.id=b.policy_id
        where a.status=true

            <if test="code != null and code !=''">
                and a.code like concat('%',#{code},'%')
            </if>
            <if test="remark != null and remark !=''">
                and a.remark like concat('%',#{remark},'%')
            </if>
            <if test="title != null and title !=''">
                and a.title like  concat('%',#{title},'%')
            </if>
            <if test="adminCompanyIds != null and adminCompanyIds.size > 0">
                and a.admin_company_id in
                <foreach item="item" index="index" collection="adminCompanyIds" open="(" separator=","
                         close=")">
                    #{item}
                </foreach>
            </if>

        group by a.id
        order by a.create_time  desc
    </select>


</mapper>