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

    <select id="getById" resultType="com.crm.rely.backend.core.pojo.table.SalesPerformanceInfoTable" parameterType="Long">
        select spi.*
        from sales_performance_info spi
        where spi.id=#{id}
    </select>


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

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

</mapper>