<?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.inventory.mapper.TbInventoryDetailMapper">
    
    <resultMap type="TbInventoryDetail" id="TbInventoryDetailResult">
        <result property="id"    column="id"    />
        <result property="orderNumber"    column="order_number"    />
        <result property="inventoryMetadata"    column="inventory_metadata"    />
        <result property="isUpdateData"    column="is_update_data"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTbInventoryDetailVo">
        select id, order_number, inventory_metadata, is_update_data, remark from tb_inventory_detail
    </sql>

    <select id="selectTbInventoryDetailList" parameterType="TbInventoryDetail" resultMap="TbInventoryDetailResult">
        <include refid="selectTbInventoryDetailVo"/>
        <where>  
            <if test="orderNumber != null  and orderNumber != ''"> and order_number = #{orderNumber}</if>
            <if test="isUpdateData != null "> and is_update_data = #{isUpdateData}</if>
        </where>
    </select>
    
    <select id="selectTbInventoryDetailById" parameterType="Long" resultMap="TbInventoryDetailResult">
        <include refid="selectTbInventoryDetailVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTbInventoryDetail" parameterType="TbInventoryDetail" useGeneratedKeys="true" keyProperty="id">
        insert into tb_inventory_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">order_number,</if>
            <if test="inventoryMetadata != null and inventoryMetadata != ''">inventory_metadata,</if>
            <if test="isUpdateData != null">is_update_data,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">#{orderNumber},</if>
            <if test="inventoryMetadata != null and inventoryMetadata != ''">#{inventoryMetadata},</if>
            <if test="isUpdateData != null">#{isUpdateData},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTbInventoryDetail" parameterType="TbInventoryDetail">
        update tb_inventory_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNumber != null and orderNumber != ''">order_number = #{orderNumber},</if>
            <if test="inventoryMetadata != null and inventoryMetadata != ''">inventory_metadata = #{inventoryMetadata},</if>
            <if test="isUpdateData != null">is_update_data = #{isUpdateData},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTbInventoryDetailById" parameterType="Long">
        delete from tb_inventory_detail where id = #{id}
    </delete>

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