<?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.crm.manager.dao.mapper.CooperativePartnerMapper">

    <select id="countAgentList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.cooperative.partner.agent.CooperativePartnerAgentSearchEntity">

        select count(*)
        from cooperative_partner
        <where>
            <if test="type != null">
                and cooperative_partner.type =#{type}
            </if>
            <if test="email != null and email != ''">
                and cooperative_partner.email like binary concat(#{email},'%')
            </if>
            <if test="phone != null and phone != ''">
                and cooperative_partner.phone like binary concat(#{phone},'%')
            </if>
            <if test="status != null ">
                and cooperative_partner.status =#{status}
            </if>
            <if test="startDate != null">
                and add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>

    </select>

    <select id="pageAgentList" resultType="com.crm.rely.backend.core.pojo.table.CooperativePartnerTable"
            parameterType="com.crm.rely.backend.core.entity.cooperative.partner.agent.CooperativePartnerAgentSearchEntity">

        select *
        from cooperative_partner
        <where>
            <if test="type != null">
                and cooperative_partner.type =#{type}
            </if>
            <if test="email != null and email != ''">
                and cooperative_partner.email like binary concat(#{email},'%')
            </if>
            <if test="phone != null and phone != ''">
                and cooperative_partner.phone like binary concat(#{phone},'%')
            </if>
            <if test="status != null ">
                and cooperative_partner.status =#{status}
            </if>
            <if test="startDate != null">
                and add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>
        order by add_time desc
        limit #{page.offset},#{page.row}
    </select>

    <select id="countSubsetList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.cooperative.partner.subset.CooperativePartnerSubsetSearchEntity">

        select count(*)
        from cooperative_partner
        <where>
            <if test="type != null">
                and cooperative_partner.type =#{type}
            </if>
            <if test="email != null and email != ''">
                and cooperative_partner.email like binary concat(#{email},'%')
            </if>
            <if test="phone != null and phone != ''">
                and cooperative_partner.phone like binary concat(#{phone},'%')
            </if>
            <if test="status != null ">
                and cooperative_partner.status =#{status}
            </if>
            <if test="startDate != null">
                and add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>

    </select>

    <select id="pageSubsetList" resultType="com.crm.rely.backend.core.pojo.table.CooperativePartnerTable"
            parameterType="com.crm.rely.backend.core.entity.cooperative.partner.subset.CooperativePartnerSubsetSearchEntity">

        select *
        from cooperative_partner
        <where>
            <if test="type != null">
                and cooperative_partner.type =#{type}
            </if>
            <if test="email != null and email != ''">
                and cooperative_partner.email like binary concat(#{email},'%')
            </if>
            <if test="phone != null and phone != ''">
                and cooperative_partner.phone like binary concat(#{phone},'%')
            </if>
            <if test="status != null ">
                and cooperative_partner.status =#{status}
            </if>
            <if test="startDate != null">
                and add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>
        order by add_time desc
        limit #{page.offset},#{page.row}
    </select>

    <select id="countUsList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.cooperative.partner.us.CooperativePartnerUsSearchEntity">

        select count(*)
        from cooperative_partner
        <where>
            <if test="type != null">
                and cooperative_partner.type =#{type}
            </if>
            <if test="email != null and email != ''">
                and cooperative_partner.email like binary concat(#{email},'%')
            </if>
            <if test="phone != null and phone != ''">
                and cooperative_partner.phone like binary concat(#{phone},'%')
            </if>
            <if test="status != null ">
                and cooperative_partner.status =#{status}
            </if>
            <if test="startDate != null">
                and add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>

    </select>

    <select id="pageUsList" resultType="com.crm.rely.backend.core.pojo.table.CooperativePartnerTable"
            parameterType="com.crm.rely.backend.core.entity.cooperative.partner.us.CooperativePartnerUsSearchEntity">

        select *
        from cooperative_partner
        <where>
            <if test="type != null">
                and cooperative_partner.type =#{type}
            </if>
            <if test="email != null and email != ''">
                and cooperative_partner.email like binary concat(#{email},'%')
            </if>
            <if test="phone != null and phone != ''">
                and cooperative_partner.phone like binary concat(#{phone},'%')
            </if>
            <if test="status != null ">
                and cooperative_partner.status =#{status}
            </if>
            <if test="startDate != null">
                and add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>
        order by add_time desc
        limit #{page.offset},#{page.row}
    </select>
</mapper>