<?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.order.mapper.TbOrderDetailMapper">
    
    <resultMap type="TbOrderDetail" id="TbOrderDetailResult">
        <result property="id"    column="id"    />
        <result property="orderNumber"    column="order_number"    />
        <result property="assetNumber"    column="asset_number"    />
        <result property="allocationOldResponsiblePerson"    column="allocation_old_responsible_person"    />
        <result property="allocationOldLocationNumber"    column="allocation_old_location_number"    />
        <result property="allocationNewResponsiblePerson"    column="allocation_new_responsible_person"    />
        <result property="allocationNewLocationNumber"    column="allocation_new_location_number"    />
        <result property="lendReturnDate"    column="lend_return_date"    />
        <result property="lendActualReturnDate"    column="lend_actual_return_date"    />
        <result property="lendBySponsor"    column="lend_by_sponsor"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTbOrderDetailVo">
        select id, order_number, asset_number, allocation_old_responsible_person, allocation_old_location_number, allocation_new_responsible_person, allocation_new_location_number, lend_return_date, lend_actual_return_date, lend_by_sponsor, remark from tb_order_detail
    </sql>

    <select id="selectTbOrderDetailList" parameterType="TbOrderDetail" resultMap="TbOrderDetailResult">
        <include refid="selectTbOrderDetailVo"/>
        <where>  
            <if test="orderNumber != null  and orderNumber != ''"> and order_number = #{orderNumber}</if>
            <if test="assetNumber != null  and assetNumber != ''"> and asset_number = #{assetNumber}</if>
            <if test="allocationOldResponsiblePerson != null  and allocationOldResponsiblePerson != ''"> and allocation_old_responsible_person = #{allocationOldResponsiblePerson}</if>
            <if test="allocationOldLocationNumber != null  and allocationOldLocationNumber != ''"> and allocation_old_location_number = #{allocationOldLocationNumber}</if>
            <if test="allocationNewResponsiblePerson != null  and allocationNewResponsiblePerson != ''"> and allocation_new_responsible_person = #{allocationNewResponsiblePerson}</if>
            <if test="allocationNewLocationNumber != null  and allocationNewLocationNumber != ''"> and allocation_new_location_number = #{allocationNewLocationNumber}</if>
            <if test="lendReturnDate != null "> and lend_return_date = #{lendReturnDate}</if>
            <if test="lendActualReturnDate != null "> and lend_actual_return_date = #{lendActualReturnDate}</if>
            <if test="lendBySponsor != null  and lendBySponsor != ''"> and lend_by_sponsor = #{lendBySponsor}</if>
        </where>
    </select>
    
    <select id="selectTbOrderDetailById" parameterType="Long" resultMap="TbOrderDetailResult">
        <include refid="selectTbOrderDetailVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbOrderDetail" parameterType="TbOrderDetail" useGeneratedKeys="true" keyProperty="id">
        insert into tb_order_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">order_number,</if>
            <if test="assetNumber != null and assetNumber != ''">asset_number,</if>
            <if test="allocationOldResponsiblePerson != null">allocation_old_responsible_person,</if>
            <if test="allocationOldLocationNumber != null">allocation_old_location_number,</if>
            <if test="allocationNewResponsiblePerson != null">allocation_new_responsible_person,</if>
            <if test="allocationNewLocationNumber != null">allocation_new_location_number,</if>
            <if test="lendReturnDate != null">lend_return_date,</if>
            <if test="lendActualReturnDate != null">lend_actual_return_date,</if>
            <if test="lendBySponsor != null">lend_by_sponsor,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">#{orderNumber},</if>
            <if test="assetNumber != null and assetNumber != ''">#{assetNumber},</if>
            <if test="allocationOldResponsiblePerson != null">#{allocationOldResponsiblePerson},</if>
            <if test="allocationOldLocationNumber != null">#{allocationOldLocationNumber},</if>
            <if test="allocationNewResponsiblePerson != null">#{allocationNewResponsiblePerson},</if>
            <if test="allocationNewLocationNumber != null">#{allocationNewLocationNumber},</if>
            <if test="lendReturnDate != null">#{lendReturnDate},</if>
            <if test="lendActualReturnDate != null">#{lendActualReturnDate},</if>
            <if test="lendBySponsor != null">#{lendBySponsor},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTbOrderDetail" parameterType="TbOrderDetail">
        update tb_order_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">order_number = #{orderNumber},</if>
            <if test="assetNumber != null and assetNumber != ''">asset_number = #{assetNumber},</if>
            <if test="allocationOldResponsiblePerson != null">allocation_old_responsible_person = #{allocationOldResponsiblePerson},</if>
            <if test="allocationOldLocationNumber != null">allocation_old_location_number = #{allocationOldLocationNumber},</if>
            <if test="allocationNewResponsiblePerson != null">allocation_new_responsible_person = #{allocationNewResponsiblePerson},</if>
            <if test="allocationNewLocationNumber != null">allocation_new_location_number = #{allocationNewLocationNumber},</if>
            <if test="lendReturnDate != null">lend_return_date = #{lendReturnDate},</if>
            <if test="lendActualReturnDate != null">lend_actual_return_date = #{lendActualReturnDate},</if>
            <if test="lendBySponsor != null">lend_by_sponsor = #{lendBySponsor},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbOrderDetailById" parameterType="Long">
        delete from tb_order_detail where id = #{id}
    </delete>

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