<?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.logistics.mapper.SysDeptRateMapper">
    
    <resultMap type="SysDeptRate" id="SysDeptRateResult">
        <result property="rateId"    column="rate_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="companyType"    column="company_type"    />
        <result property="productType"    column="product_type"    />
        <result property="intervalBegins"    column="interval_begins"    />
        <result property="intervalEnds"    column="interval_ends"    />
        <result property="rate"    column="rate"    />
        <result property="userId"    column="user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectSysDeptRateVo">
        select rate_id, dept_id, company_type, product_type, interval_begins, interval_ends, rate, user_id, create_time, create_by, update_time, update_by from sys_dept_rate
    </sql>

    <select id="selectSysDeptRateList" parameterType="SysDeptRate" resultMap="SysDeptRateResult">
        <include refid="selectSysDeptRateVo"/>
        <where>  
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="companyType != null  and companyType != ''"> and company_type = #{companyType}</if>
            <if test="productType != null  and productType != ''"> and product_type = #{productType}</if>
            <if test="intervalBegins != null "> and interval_begins = #{intervalBegins}</if>
            <if test="intervalEnds != null "> and interval_ends = #{intervalEnds}</if>
            <if test="rate != null "> and rate = #{rate}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
    </select>
    
    <select id="selectSysDeptRateByRateId" parameterType="Long" resultMap="SysDeptRateResult">
        <include refid="selectSysDeptRateVo"/>
        where rate_id = #{rateId}
    </select>

    <insert id="insertSysDeptRate" parameterType="SysDeptRate" useGeneratedKeys="true" keyProperty="rateId">
        insert into sys_dept_rate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="companyType != null">company_type,</if>
            <if test="productType != null">product_type,</if>
            <if test="intervalBegins != null">interval_begins,</if>
            <if test="intervalEnds != null">interval_ends,</if>
            <if test="rate != null">rate,</if>
            <if test="userId != null">user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deptId != null">#{deptId},</if>
            <if test="companyType != null">#{companyType},</if>
            <if test="productType != null">#{productType},</if>
            <if test="intervalBegins != null">#{intervalBegins},</if>
            <if test="intervalEnds != null">#{intervalEnds},</if>
            <if test="rate != null">#{rate},</if>
            <if test="userId != null">#{userId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateSysDeptRate" parameterType="SysDeptRate">
        update sys_dept_rate
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="companyType != null">company_type = #{companyType},</if>
            <if test="productType != null">product_type = #{productType},</if>
            <if test="intervalBegins != null">interval_begins = #{intervalBegins},</if>
            <if test="intervalEnds != null">interval_ends = #{intervalEnds},</if>
            <if test="rate != null">rate = #{rate},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where rate_id = #{rateId}
    </update>

    <delete id="deleteSysDeptRateByRateId" parameterType="Long">
        delete from sys_dept_rate where rate_id = #{rateId}
    </delete>

    <delete id="deleteSysDeptRateByRateIds" parameterType="String">
        delete from sys_dept_rate where rate_id in 
        <foreach item="rateId" collection="array" open="(" separator="," close=")">
            #{rateId}
        </foreach>
    </delete>




    <select id="findSysDeptRateList"  parameterType="java.util.Map" resultType="java.util.HashMap"  >
        select  rate from  sys_dept_rate where dept_id= #{deptId}
        and  company_type= #{companyType}  and  product_type=  #{productCode}
         and interval_begins <![CDATA[ < ]]> #{payableAmount}  and interval_ends>=#{payableAmount}

    </select>



    <select id="findSysDeptRateListByDept"  parameterType="java.util.Map" resultType="java.util.HashMap"  >
        select  rate from  sys_dept_rate where dept_id= #{deptId}
         and  company_type= #{companyType}  and  product_type=  #{productCode}
          order by   interval_ends desc

    </select>

    <delete id="deleteSysDeptRateByDeptId" parameterType="Long">
        delete from sys_dept_rate where dept_id = #{deptId}
    </delete>
</mapper>