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

    <select id="listSearch"
            parameterType="com.crm.rely.backend.core.entity.sales.SalesPerformanceConfigSearchEntity"
            resultType="com.crm.rely.backend.core.pojo.table.SalesPerformanceConfigTable">
        select spc.*
        from sales_performance_config spc
        inner join user_info ui on spc.sales_id = ui.id
        <where>
            <if test="salesType != null">
                and spc.sales_type = #{salesType}
            </if>
            <if test="salesName != null">
                and spc.sales_name like concat('%',#{salesName},'%')
            </if>
            <if test="saleNo != null">
                and spc.sales_no like concat('%',#{saleNo},'%')
            </if>
            <if test="stamp != null">
                and ui.stamp like binary concat(#{stamp},'%')
            </if>
        </where>
        order by spc.add_time desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

    <select id="countSearch"
            parameterType="com.crm.rely.backend.core.entity.sales.SalesPerformanceConfigSearchEntity"
            resultType="Integer">
        select count(spc.id)
        from sales_performance_config spc
        inner join user_info ui on spc.sales_id = ui.id
        <where>
            <if test="salesType != null">
                and spc.sales_type = #{salesType}
            </if>
            <if test="salesName != null">
                and spc.sales_name like concat('%',#{salesName},'%')
            </if>
            <if test="saleNo != null">
                and spc.sales_no like concat('%',#{saleNo},'%')
            </if>
            <if test="stamp != null">
                and ui.stamp like binary concat(#{stamp},'%')
            </if>
        </where>
    </select>

</mapper>