<?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.TbAssetAdjustmentMapper">
    
    <resultMap type="TbAssetAdjustment" id="TbAssetAdjustmentResult">
        <result property="id"    column="id"    />
        <result property="assetNumber"    column="asset_number"    />
        <result property="originalAssetInfo"    column="original_asset_info"    />
        <result property="reason"    column="reason"    />
        <result property="orderNumber"    column="order_number"    />
        <result property="preparedBy"    column="prepared_by"    />
        <result property="preparedDepartment"    column="prepared_department"    />
        <result property="recordStatus"    column="record_status"    />
    </resultMap>

    <sql id="selectTbAssetAdjustmentVo">
        select id, asset_number, original_asset_info, reason, order_number, prepared_by, prepared_department, record_status from tb_asset_adjustment
    </sql>

    <select id="selectTbAssetAdjustmentList" parameterType="TbAssetAdjustment" resultMap="TbAssetAdjustmentResult">
        <include refid="selectTbAssetAdjustmentVo"/>
        <where>  
            <if test="assetNumber != null  and assetNumber != ''"> and asset_number = #{assetNumber}</if>
            <if test="originalAssetInfo != null  and originalAssetInfo != ''"> and original_asset_info = #{originalAssetInfo}</if>
            <if test="reason != null  and reason != ''"> and reason like concat('%', #{reason}, '%')</if>
            <if test="orderNumber != null  and orderNumber != ''"> and order_number = #{orderNumber}</if>
            <if test="preparedBy != null  and preparedBy != ''"> and prepared_by like concat('%', #{preparedBy}, '%')</if>
            <if test="preparedDepartment != null  and preparedDepartment != ''"> and prepared_department = #{preparedDepartment}</if>
            <if test="recordStatus != null "> and record_status = #{recordStatus}</if>
        </where>
    </select>
    
    <select id="selectTbAssetAdjustmentById" parameterType="Long" resultMap="TbAssetAdjustmentResult">
        <include refid="selectTbAssetAdjustmentVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbAssetAdjustment" parameterType="TbAssetAdjustment" useGeneratedKeys="true" keyProperty="id">
        insert into tb_asset_adjustment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="assetNumber != null and assetNumber != ''">asset_number,</if>
            <if test="originalAssetInfo != null and originalAssetInfo != ''">original_asset_info,</if>
            <if test="reason != null">reason,</if>
            <if test="orderNumber != null and orderNumber != ''">order_number,</if>
            <if test="preparedBy != null and preparedBy != ''">prepared_by,</if>
            <if test="preparedDepartment != null">prepared_department,</if>
            <if test="recordStatus != null">record_status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="assetNumber != null and assetNumber != ''">#{assetNumber},</if>
            <if test="originalAssetInfo != null and originalAssetInfo != ''">#{originalAssetInfo},</if>
            <if test="reason != null">#{reason},</if>
            <if test="orderNumber != null and orderNumber != ''">#{orderNumber},</if>
            <if test="preparedBy != null and preparedBy != ''">#{preparedBy},</if>
            <if test="preparedDepartment != null">#{preparedDepartment},</if>
            <if test="recordStatus != null">#{recordStatus},</if>
         </trim>
    </insert>

    <update id="updateTbAssetAdjustment" parameterType="TbAssetAdjustment">
        update tb_asset_adjustment
        <trim prefix="SET" suffixOverrides=",">
            <if test="assetNumber != null and assetNumber != ''">asset_number = #{assetNumber},</if>
            <if test="originalAssetInfo != null and originalAssetInfo != ''">original_asset_info = #{originalAssetInfo},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="orderNumber != null and orderNumber != ''">order_number = #{orderNumber},</if>
            <if test="preparedBy != null and preparedBy != ''">prepared_by = #{preparedBy},</if>
            <if test="preparedDepartment != null">prepared_department = #{preparedDepartment},</if>
            <if test="recordStatus != null">record_status = #{recordStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbAssetAdjustmentById" parameterType="Long">
        delete from tb_asset_adjustment where id = #{id}
    </delete>

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