<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//oos.juyouhx.com//DTD Mapper 3.0//EN" "http://oss.juyouhx.com/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.scpyun.platform.standard.jilinsscgsdp.keyDmInventory" name="库存">

    <select id="getByMaterialId" parameterType="map" resultType="map">
        SELECT * FROM jl_key_dm_inventory WHERE material_id = #{material_id} AND is_used = 1 LIMIT 1
    </select>

    <update id="decreaseAvailable" parameterType="map">
        UPDATE jl_key_dm_inventory
        SET available_quantity = available_quantity - #{quantity}, borrowed_quantity = borrowed_quantity + #{quantity}, update_by = #{_user.id}, update_time = NOW()
        WHERE material_id = #{material_id} AND available_quantity >= #{quantity}
    </update>
    
    <update id="increaseAvailable" parameterType="map">
        UPDATE jl_key_dm_inventory
        SET available_quantity = available_quantity + #{quantity}, borrowed_quantity = borrowed_quantity - #{quantity}, update_by = #{_user.id}, update_time = NOW()
        WHERE material_id = #{material_id}
    </update>

</mapper>


