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


    <select id="countSearch" parameterType="com.crm.rely.backend.core.entity.base.BaseIbReportListEntity" resultType="Integer">
        select count(sdd.id)
        from sales_dps_dw_${ym} sdd
        <include refid="whereSql"></include>
    </select>

    <select id="listSearch" parameterType="com.crm.rely.backend.core.entity.base.BaseIbReportListEntity"
            resultType="com.crm.rely.backend.core.pojo.table.SalesDpsDwTable">
        select sdd.*
        from sales_dps_dw_${ym} sdd
        <include refid="whereSql"></include>
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

    <select id="sumSearch" parameterType="com.crm.rely.backend.core.entity.base.BaseIbReportListEntity"
            resultType="com.crm.rely.backend.core.pojo.table.SalesDpsDwTable">
        select sum(sdd.amount) amount
        from sales_dps_dw_${ym} sdd
        <include refid="whereSql"></include>
    </select>

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