<?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.oa.mapper.CmcBorrowDetailMapper">
    
    <resultMap type="CmcBorrowDetail" id="CmcBorrowDetailResult">
        <result property="borrowDetailId"    column="borrow_detail_id"    />
        <result property="borrowId"    column="borrow_id"    />
        <result property="borrowItem"    column="borrow_item"    />
        <result property="unit"    column="unit"    />
        <result property="price"    column="price"    />
        <result property="quantity"    column="quantity"    />
        <result property="applyAmount"    column="apply_amount"    />
        <result property="managerAmount"    column="manager_amount"    />
    </resultMap>

    <sql id="selectCmcBorrowDetailVo">
        select borrow_detail_id, borrow_id, borrow_item, unit, price, quantity, apply_amount, manager_amount from cmc_borrow_detail
    </sql>

    <select id="selectCmcBorrowDetailList" parameterType="CmcBorrowDetail" resultMap="CmcBorrowDetailResult">
        <include refid="selectCmcBorrowDetailVo"/>
        <where>  
            <if test="borrowId != null  and borrowId != ''"> and borrow_id = #{borrowId}</if>
            <if test="borrowItem != null  and borrowItem != ''"> and borrow_item = #{borrowItem}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="quantity != null "> and quantity = #{quantity}</if>
            <if test="applyAmount != null "> and apply_amount = #{applyAmount}</if>
            <if test="managerAmount != null "> and manager_amount = #{managerAmount}</if>
        </where>
    </select>
    
    <select id="selectCmcBorrowDetailByBorrowId" parameterType="String" resultMap="CmcBorrowDetailResult">
        <include refid="selectCmcBorrowDetailVo"/>
        where borrow_id = #{borrowId}
    </select>
        
    <insert id="insertCmcBorrowDetail" parameterType="CmcBorrowDetail">
        insert into cmc_borrow_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="borrowDetailId != null">borrow_detail_id,</if>
            <if test="borrowId != null">borrow_id,</if>
            <if test="borrowItem != null">borrow_item,</if>
            <if test="unit != null">unit,</if>
            <if test="price != null">price,</if>
            <if test="quantity != null">quantity,</if>
            <if test="applyAmount != null">apply_amount,</if>
            <if test="managerAmount != null">manager_amount,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="borrowDetailId != null">#{borrowDetailId},</if>
            <if test="borrowId != null">#{borrowId},</if>
            <if test="borrowItem != null">#{borrowItem},</if>
            <if test="unit != null">#{unit},</if>
            <if test="price != null">#{price},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="applyAmount != null">#{applyAmount},</if>
            <if test="managerAmount != null">#{managerAmount},</if>
         </trim>
    </insert>

    <update id="updateCmcBorrowDetail" parameterType="CmcBorrowDetail">
        update cmc_borrow_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="borrowId != null">borrow_id = #{borrowId},</if>
            <if test="borrowItem != null">borrow_item = #{borrowItem},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="price != null">price = #{price},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            <if test="applyAmount != null">apply_amount = #{applyAmount},</if>
            <if test="managerAmount != null">manager_amount = #{managerAmount},</if>
        </trim>
        where borrow_detail_id = #{borrowDetailId}
    </update>

    <delete id="deleteCmcBorrowDetailByBorrowId" parameterType="String">
        delete from cmc_borrow_detail where borrow_id = #{borrowId}
    </delete>

    <delete id="deleteCmcBorrowDetailByBorrowIds" parameterType="String">
        delete from cmc_borrow_detail where borrow_id in
        <foreach item="borrowId" collection="array" open="(" separator="," close=")">
            #{borrowId}
        </foreach>
    </delete>

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