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

    <insert id="batchSave" parameterType="com.crm.rely.backend.core.pojo.table.SysSalesShareTable">
        insert into sys_sales_share(sales_id, sales_no, new_share, old_share, add_time, add_user)
        values
        <foreach collection="list" index="index" item="item" separator=",">
            (#{item.salesId}, #{item.salesNo}, #{item.newShare}, #{item.oldShare}, #{item.addTime} ,#{item.addUser})
        </foreach>
    </insert>

    <select id="countSearch"
            parameterType="com.crm.rely.backend.core.entity.system.sales.SysSalesShareListEntity"
            resultType="Integer">
        select count(id)
        from sys_sales_share sss
        <where>
            <if test="startDate != null">
                and sss.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and sss.add_time <![CDATA[ < ]]> #{endDate}
            </if>
            <if test="salesNo != null and salesNo != ''">
                and sss.sales_no like concat(#{salesNo},'%')
            </if>
        </where>
    </select>

    <select id="listSearch"
            parameterType="com.crm.rely.backend.core.entity.system.sales.SysSalesShareListEntity"
            resultType="com.crm.rely.backend.core.pojo.table.SysSalesShareTable">
        select sss.*
        from sys_sales_share sss
        <where>
            <if test="startDate != null">
                and sss.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and sss.add_time <![CDATA[ < ]]> #{endDate}
            </if>
            <if test="salesNo != null and salesNo != ''">
                and sss.sales_no like concat(#{salesNo},'%')
            </if>
        </where>
        order by sss.add_time desc
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

</mapper>