<?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.change.mapper.TbAssetReturnMapper">
    
    <resultMap type="TbAssetReturn" id="TbAssetReturnResult">
        <result property="id"    column="id"    />
        <result property="lendOrderNumber"    column="lend_order_number"    />
        <result property="assetNumber"    column="asset_number"    />
        <result property="returnDate"    column="return_date"    />
        <result property="actualReturnDate"    column="actual_return_date"    />
        <result property="bySponsor"    column="by_sponsor"    />
        <result property="remark"    column="remark"    />
        <result property="recordStatus"    column="record_status"    />
    </resultMap>

    <sql id="selectTbAssetReturnVo">
        select id, lend_order_number, asset_number, return_date, actual_return_date, by_sponsor, remark, record_status from tb_asset_return
    </sql>

    <select id="selectTbAssetReturnList" parameterType="TbAssetReturn" resultMap="TbAssetReturnResult">
        <include refid="selectTbAssetReturnVo"/>
        <where>  
            <if test="lendOrderNumber != null  and lendOrderNumber != ''"> and lend_order_number = #{lendOrderNumber}</if>
            <if test="assetNumber != null  and assetNumber != ''"> and asset_number = #{assetNumber}</if>
            <if test="returnDate != null "> and return_date = #{returnDate}</if>
            <if test="actualReturnDate != null "> and actual_return_date = #{actualReturnDate}</if>
            <if test="bySponsor != null  and bySponsor != ''"> and by_sponsor = #{bySponsor}</if>
            <if test="recordStatus != null "> and record_status = #{recordStatus}</if>
        </where>
    </select>
    
    <select id="selectTbAssetReturnById" parameterType="Long" resultMap="TbAssetReturnResult">
        <include refid="selectTbAssetReturnVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbAssetReturn" parameterType="TbAssetReturn" useGeneratedKeys="true" keyProperty="id">
        insert into tb_asset_return
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="lendOrderNumber != null and lendOrderNumber != ''">lend_order_number,</if>
            <if test="assetNumber != null and assetNumber != ''">asset_number,</if>
            <if test="returnDate != null">return_date,</if>
            <if test="actualReturnDate != null">actual_return_date,</if>
            <if test="bySponsor != null and bySponsor != ''">by_sponsor,</if>
            <if test="remark != null">remark,</if>
            <if test="recordStatus != null">record_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="lendOrderNumber != null and lendOrderNumber != ''">#{lendOrderNumber},</if>
            <if test="assetNumber != null and assetNumber != ''">#{assetNumber},</if>
            <if test="returnDate != null">#{returnDate},</if>
            <if test="actualReturnDate != null">#{actualReturnDate},</if>
            <if test="bySponsor != null and bySponsor != ''">#{bySponsor},</if>
            <if test="remark != null">#{remark},</if>
            <if test="recordStatus != null">#{recordStatus},</if>
         </trim>
    </insert>

    <update id="updateTbAssetReturn" parameterType="TbAssetReturn">
        update tb_asset_return
        <trim prefix="SET" suffixOverrides=",">
            <if test="lendOrderNumber != null and lendOrderNumber != ''">lend_order_number = #{lendOrderNumber},</if>
            <if test="assetNumber != null and assetNumber != ''">asset_number = #{assetNumber},</if>
            <if test="returnDate != null">return_date = #{returnDate},</if>
            <if test="actualReturnDate != null">actual_return_date = #{actualReturnDate},</if>
            <if test="bySponsor != null and bySponsor != ''">by_sponsor = #{bySponsor},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="recordStatus != null">record_status = #{recordStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbAssetReturnById" parameterType="Long">
        delete from tb_asset_return where id = #{id}
    </delete>

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