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

    <insert id="save" parameterType="com.crm.rely.backend.core.pojo.table.SalesCommissionManualTable">
        INSERT INTO sales_commission_manual (
            sales_id,
            sales_no,
            ym,
            salary_amount,
            personal_volume_amount,
            team_volume_amount,
            personal_kpi_amount,
            team_kpi_amount,
            entry_type,
            add_time,
            add_user,
            add_ip,
            note
        ) VALUES (
             #{salesId},
             #{salesNo},
             #{ym},
             #{salaryAmount},
             #{personalVolumeAmount},
             #{teamVolumeAmount},
             #{personalKpiAmount},
             #{teamKpiAmount},
             #{entryType},
             #{addTime},
             #{addUser},
             #{addIp},
             #{note}
         )
    </insert>

    <update id="updateById" parameterType="com.crm.rely.backend.core.pojo.table.SalesCommissionManualTable">
        UPDATE sales_commission_manual
        SET
            sales_id = #{salesId},
            sales_no = #{salesNo},
            ym = #{ym},
            salary_amount = #{salaryAmount},
            personal_volume_amount = #{personalVolumeAmount},
            team_volume_amount = #{teamVolumeAmount},
            personal_kpi_amount = #{personalKpiAmount},
            team_kpi_amount = #{teamKpiAmount},
            entry_type = #{entryType},
            modify_time = #{modifyTime},
            modify_user = #{modifyUser},
            modify_ip = #{modifyIp},
            note = #{note}
        WHERE id = #{id}
    </update>


    <select id="countSearch" parameterType="com.crm.rely.backend.core.entity.sales.SalesCommissionManualListEntity" resultType="Integer">
        select count(scm.id)
        from sales_commission_manual scm
        <include refid="whereSql"></include>
    </select>

    <select id="listSearch" parameterType="com.crm.rely.backend.core.entity.sales.SalesCommissionManualListEntity"
            resultType="com.crm.rely.backend.core.pojo.table.SalesCommissionManualTable">
        select scm.*
        from sales_commission_manual scm
        <include refid="whereSql"></include>
    </select>

    <sql id="whereSql">
        <where>
            <if test="salesNo != null and salesNo != ''">
                and scm.sales_no like concat('%',#{salesNo},'%')
            </if>
            <if test="ym != null and ym != ''">
                and scm.ym = #{ym}
            </if>
            <if test="startDate != null">
                and scm.add_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and scm.add_time <![CDATA[ < ]]> #{endDate}
            </if>
        </where>
    </sql>
</mapper>