<?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.ruoyi.system.mapper.CommissionRatesMapper">

    <resultMap type="CommissionRates" id="CommissionRatesResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="startDate"    column="start_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="remark"    column="remark"    />
        <result property="rate"    column="rate"    />
        <result property="turnover"    column="turnover"    />
        <result property="handled"    column="handled"    />
        <result property="handledTime"    column="handled_time"    />
        <result property="deleted"    column="deleted"    />
    </resultMap>

    <sql id="selectCommissionRatesVo">
        select id, user_id, start_date, end_date, remark, rate, turnover, handled, handled_time, deleted from commission_rates
    </sql>

    <select id="selectCommissionRatesList" parameterType="CommissionRates" resultMap="CommissionRatesResult">
        <include refid="selectCommissionRatesVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="startDate != null "> and start_date = #{startDate}</if>
            <if test="endDate != null "> and end_date = #{endDate}</if>
            <if test="rate != null  and rate != ''"> and rate = #{rate}</if>
            <if test="deleted != null "> and deleted = #{deleted}</if>
        </where>
    </select>

    <select id="selectCommissionRatesById" parameterType="Long" resultMap="CommissionRatesResult">
        <include refid="selectCommissionRatesVo"/>
        where id = #{id}
    </select>

    <insert id="insertCommissionRates" parameterType="CommissionRates" useGeneratedKeys="true" keyProperty="id">
        insert into commission_rates
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="startDate != null">start_date,</if>
            <if test="endDate != null">end_date,</if>
            <if test="remark != null">remark,</if>
            <if test="rate != null and rate != ''">rate,</if>
            <if test="turnover != null">turnover,</if>
            <if test="handled != null">handled,</if>
            <if test="handledTime != null">handled_time,</if>
            <if test="deleted != null">deleted,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="remark != null">#{remark},</if>
            <if test="rate != null and rate != ''">#{rate},</if>
            <if test="turnover != null">#{turnover},</if>
            <if test="handled != null">#{handled},</if>
            <if test="handledTime != null">#{handledTime},</if>
            <if test="deleted != null">#{deleted},</if>
        </trim>
    </insert>

    <update id="updateCommissionRates" parameterType="CommissionRates">
        update commission_rates
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="startDate != null">start_date = #{startDate},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="rate != null and rate != ''">rate = #{rate},</if>
            <if test="turnover != null">turnover = #{turnover},</if>
            <if test="handled != null">handled = #{handled},</if>
            <if test="handledTime != null">handled_time = #{handledTime},</if>
            <if test="deleted != null">deleted = #{deleted},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCommissionRatesById" parameterType="Long">
        delete from commission_rates where id = #{id}
    </delete>

    <delete id="deleteCommissionRatesByIds" parameterType="String">
        delete from commission_rates where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
