<?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.InventoryTransactionsMapper">

    <resultMap type="InventoryTransactions" id="InventoryTransactionsResult">
        <result property="id"    column="id"    />
        <result property="transactionType"    column="transaction_type"    />
        <result property="referenceId"    column="reference_id"    />
        <result property="referenceItemId"    column="reference_item_id"    />
        <result property="materialId"    column="material_id"    />
        <result property="batchCode"    column="batch_code"    />
        <result property="warehouseId"    column="warehouse_id"    />
        <result property="locationId"    column="location_id"    />
        <result property="ownerId"    column="owner_id"    />
        <result property="quantityBefore"    column="quantity_before"    />
        <result property="quantityChange"    column="quantity_change"    />
        <result property="quantityAfter"    column="quantity_after"    />
        <result property="transactionTime"    column="transaction_time"    />
        <result property="operatedBy"    column="operated_by"    />
        <result property="remark"    column="remark"    />
        <result property="isUsed"    column="is_used"    />
        <result property="sortNo"    column="sort_no"    />
        <result property="createTime"    column="create_time"    />
        <result property="createUserCode"    column="create_user_code"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateUserCode"    column="update_user_code"    />
        <result property="inventoryId"    column="inventory_id"    />
    </resultMap>

    <sql id="selectInventoryTransactionsVo">
        select id, inventory_id, transaction_type, reference_id, reference_item_id, material_id, batch_code, warehouse_id, location_id, owner_id, quantity_before, quantity_change, quantity_after, transaction_time, operated_by, remark, is_used, sort_no, create_time, create_user_code, update_time, update_user_code from inventory_transactions
    </sql>

    <select id="selectInventoryTransactionsList" parameterType="InventoryTransactions" resultMap="InventoryTransactionsResult">
        <include refid="selectInventoryTransactionsVo"/>
        <where>
            <if test="transactionType != null "> and transaction_type = #{transactionType}</if>
            <if test="referenceId != null  and referenceId != ''"> and reference_id = #{referenceId}</if>
            <if test="inventoryId != null  and inventoryId != ''"> and inventory_id = #{inventoryId}</if>
            <if test="referenceItemId != null  and referenceItemId != ''"> and reference_item_id = #{referenceItemId}</if>
            <if test="materialId != null  and materialId != ''"> and material_id = #{materialId}</if>
            <if test="batchCode != null  and batchCode != ''"> and batch_code = #{batchCode}</if>
            <if test="warehouseId != null  and warehouseId != ''"> and warehouse_id = #{warehouseId}</if>
            <if test="locationId != null  and locationId != ''"> and location_id = #{locationId}</if>
            <if test="ownerId != null  and ownerId != ''"> and owner_id = #{ownerId}</if>
            <if test="quantityBefore != null "> and quantity_before = #{quantityBefore}</if>
            <if test="quantityChange != null "> and quantity_change = #{quantityChange}</if>
            <if test="quantityAfter != null "> and quantity_after = #{quantityAfter}</if>
            <if test="transactionTime != null "> and transaction_time = #{transactionTime}</if>
            <if test="operatedBy != null  and operatedBy != ''"> and operated_by = #{operatedBy}</if>
            <if test="isUsed != null "> and is_used = #{isUsed}</if>
            <if test="sortNo != null "> and sort_no = #{sortNo}</if>
            <if test="createUserCode != null  and createUserCode != ''"> and create_user_code = #{createUserCode}</if>
            <if test="updateUserCode != null  and updateUserCode != ''"> and update_user_code = #{updateUserCode}</if>
        </where>
    </select>

    <select id="selectInventoryTransactionsById" parameterType="String" resultMap="InventoryTransactionsResult">
        <include refid="selectInventoryTransactionsVo"/>
        where id = #{id}
    </select>

    <insert id="insertInventoryTransactions" parameterType="InventoryTransactions">
        insert into inventory_transactions
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="transactionType != null">transaction_type,</if>
            <if test="inventoryId != null">inventory_id,</if>
            <if test="referenceId != null">reference_id,</if>
            <if test="referenceItemId != null">reference_item_id,</if>
            <if test="materialId != null">material_id,</if>
            <if test="batchCode != null">batch_code,</if>
            <if test="warehouseId != null">warehouse_id,</if>
            <if test="locationId != null">location_id,</if>
            <if test="ownerId != null">owner_id,</if>
            <if test="quantityBefore != null">quantity_before,</if>
            <if test="quantityChange != null">quantity_change,</if>
            <if test="quantityAfter != null">quantity_after,</if>
            <if test="transactionTime != null">transaction_time,</if>
            <if test="operatedBy != null">operated_by,</if>
            <if test="remark != null">remark,</if>
            <if test="isUsed != null">is_used,</if>
            <if test="sortNo != null">sort_no,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createUserCode != null">create_user_code,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateUserCode != null">update_user_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="transactionType != null">#{transactionType},</if>
            <if test="inventoryId != null">#{inventoryId},</if>
            <if test="referenceId != null">#{referenceId},</if>
            <if test="referenceItemId != null">#{referenceItemId},</if>
            <if test="materialId != null">#{materialId},</if>
            <if test="batchCode != null">#{batchCode},</if>
            <if test="warehouseId != null">#{warehouseId},</if>
            <if test="locationId != null">#{locationId},</if>
            <if test="ownerId != null">#{ownerId},</if>
            <if test="quantityBefore != null">#{quantityBefore},</if>
            <if test="quantityChange != null">#{quantityChange},</if>
            <if test="quantityAfter != null">#{quantityAfter},</if>
            <if test="transactionTime != null">#{transactionTime},</if>
            <if test="operatedBy != null">#{operatedBy},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isUsed != null">#{isUsed},</if>
            <if test="sortNo != null">#{sortNo},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createUserCode != null">#{createUserCode},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateUserCode != null">#{updateUserCode},</if>
         </trim>
    </insert>

    <update id="updateInventoryTransactions" parameterType="InventoryTransactions">
        update inventory_transactions
        <trim prefix="SET" suffixOverrides=",">
            <if test="transactionType != null">transaction_type = #{transactionType},</if>
            <if test="inventoryId != null">inventory_id = #{inventoryId},</if>
            <if test="referenceId != null">reference_id = #{referenceId},</if>
            <if test="referenceItemId != null">reference_item_id = #{referenceItemId},</if>
            <if test="materialId != null">material_id = #{materialId},</if>
            <if test="batchCode != null">batch_code = #{batchCode},</if>
            <if test="warehouseId != null">warehouse_id = #{warehouseId},</if>
            <if test="locationId != null">location_id = #{locationId},</if>
            <if test="ownerId != null">owner_id = #{ownerId},</if>
            <if test="quantityBefore != null">quantity_before = #{quantityBefore},</if>
            <if test="quantityChange != null">quantity_change = #{quantityChange},</if>
            <if test="quantityAfter != null">quantity_after = #{quantityAfter},</if>
            <if test="transactionTime != null">transaction_time = #{transactionTime},</if>
            <if test="operatedBy != null">operated_by = #{operatedBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isUsed != null">is_used = #{isUsed},</if>
            <if test="sortNo != null">sort_no = #{sortNo},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createUserCode != null">create_user_code = #{createUserCode},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateUserCode != null">update_user_code = #{updateUserCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInventoryTransactionsById" parameterType="String">
        delete from inventory_transactions where id = #{id}
    </delete>

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