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

    <select id="countSearch" parameterType="com.crm.rely.backend.core.entity.base.BaseIbReportListEntity" resultType="Integer">
        select count(sdsr.id)
        from sales_dps_salary_record sdsr
        <include refid="listWhere"></include>
    </select>

    <select id="listSearch" parameterType="com.crm.rely.backend.core.entity.base.BaseIbReportListEntity" resultType="com.crm.rely.backend.core.pojo.table.SalesDpsSalaryRecordTable">
        select sdsr.*
        from sales_dps_salary_record sdsr
        <include refid="listWhere"></include>
    </select>

    <select id="sumSearch" parameterType="com.crm.rely.backend.core.entity.base.BaseIbReportListEntity" resultType="com.crm.rely.backend.core.pojo.table.SalesDpsSalaryRecordTable">
        select sum(sdsr.basic_salary) basic_salary,
               sum(sdsr.net_salary) net_salary,
               sum(sdsr.net_deposit_amount) net_deposit_amount,
               sum(sdsr.gross_deposit_amount) gross_deposit_amount,
               sum(sdsr.cumulative_gross_deposit) cumulative_gross_deposit,
               sum(sdsr.dps_salary) dps_salary,
               sum(sdsr.other_performance_salary) other_performance_salary,
               sum(sdsr.volume_rebate) volume_rebate
        from sales_dps_salary_record sdsr
        <include refid="listWhere"></include>
    </select>


    <sql id="listWhere">
        <where>
            <if test="salesNo != null and salesNo != ''">
                and sdsr.sales_no  like concat('%',#{salesNo},'%')
            </if>
            <if test="ym != null and ym != ''">
                and sdsr.ym = #{ym}
            </if>
            <if test="salesId != null and salesId>0">
                and sdsr.sales_id=#{salesId}
            </if>
        </where>
    </sql>

</mapper>