<?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.asset.mapper.TbAssetStatusRecordMapper">
    
    <resultMap type="TbAssetStatusRecord" id="TbAssetStatusRecordResult">
        <result property="id"    column="id"    />
        <result property="assetBarCode"    column="asset_bar_code"    />
        <result property="borrowNumber"    column="borrow_number"    />
        <result property="faultNumber"    column="fault_number"    />
        <result property="lastFaultDate"    column="last_fault_date"    />
    </resultMap>

    <sql id="selectTbAssetStatusRecordVo">
        select id, asset_bar_code, borrow_number, fault_number, last_fault_date from tb_asset_status_record
    </sql>

    <select id="selectTbAssetStatusRecordList" parameterType="TbAssetStatusRecord" resultMap="TbAssetStatusRecordResult">
        <include refid="selectTbAssetStatusRecordVo"/>
        <where>  
            <if test="assetBarCode != null  and assetBarCode != ''"> and asset_bar_code = #{assetBarCode}</if>
            <if test="lastFaultDate != null "> and last_fault_date = #{lastFaultDate}</if>
        </where>
    </select>
    
    <select id="selectTbAssetStatusRecordById" parameterType="Long" resultMap="TbAssetStatusRecordResult">
        <include refid="selectTbAssetStatusRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbAssetStatusRecord" parameterType="TbAssetStatusRecord" useGeneratedKeys="true" keyProperty="id">
        insert into tb_asset_status_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="assetBarCode != null and assetBarCode != ''">asset_bar_code,</if>
            <if test="borrowNumber != null">borrow_number,</if>
            <if test="faultNumber != null">fault_number,</if>
            <if test="lastFaultDate != null">last_fault_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="assetBarCode != null and assetBarCode != ''">#{assetBarCode},</if>
            <if test="borrowNumber != null">#{borrowNumber},</if>
            <if test="faultNumber != null">#{faultNumber},</if>
            <if test="lastFaultDate != null">#{lastFaultDate},</if>
         </trim>
    </insert>

    <update id="updateTbAssetStatusRecord" parameterType="TbAssetStatusRecord">
        update tb_asset_status_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="assetBarCode != null and assetBarCode != ''">asset_bar_code = #{assetBarCode},</if>
            <if test="borrowNumber != null">borrow_number = #{borrowNumber},</if>
            <if test="faultNumber != null">fault_number = #{faultNumber},</if>
            <if test="lastFaultDate != null">last_fault_date = #{lastFaultDate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbAssetStatusRecordById" parameterType="Long">
        delete from tb_asset_status_record where id = #{id}
    </delete>

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