<?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.goods.mapper.TCanteenInventoryMapper">
    
    <resultMap type="TCanteenInventory" id="TCanteenInventoryResult">
        <result property="inventoryId"    column="inventory_id"    />
        <result property="menuId"    column="menu_id"    />
        <result property="inventoryNum"    column="inventory_num"    />
        <result property="lastRestock"    column="last_restock"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTCanteenInventoryVo">
        select inventory_id, menu_id, inventory_num, last_restock, status, del_flag, creater_code, createdate, updater_code, updatedate, dept_id, remarks from t_canteen_inventory
    </sql>

    <select id="selectTCanteenInventoryList" parameterType="TCanteenInventory" resultMap="TCanteenInventoryResult">
        <include refid="selectTCanteenInventoryVo"/>
        <where>  
            <if test="menuId != null "> and menu_id = #{menuId}</if>
            <if test="inventoryNum != null "> and inventory_num = #{inventoryNum}</if>
            <if test="lastRestock != null "> and last_restock = #{lastRestock}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>
    
    <select id="selectTCanteenInventoryByInventoryId" parameterType="Long" resultMap="TCanteenInventoryResult">
        <include refid="selectTCanteenInventoryVo"/>
        where inventory_id = #{inventoryId}
    </select>

    <insert id="insertTCanteenInventory" parameterType="TCanteenInventory" useGeneratedKeys="true" keyProperty="inventoryId">
        insert into t_canteen_inventory
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="menuId != null">menu_id,</if>
            <if test="inventoryNum != null">inventory_num,</if>
            <if test="lastRestock != null">last_restock,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="menuId != null">#{menuId},</if>
            <if test="inventoryNum != null">#{inventoryNum},</if>
            <if test="lastRestock != null">#{lastRestock},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTCanteenInventory" parameterType="TCanteenInventory">
        update t_canteen_inventory
        <trim prefix="SET" suffixOverrides=",">
            <if test="menuId != null">menu_id = #{menuId},</if>
            <if test="inventoryNum != null">inventory_num = #{inventoryNum},</if>
            <if test="lastRestock != null">last_restock = #{lastRestock},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where inventory_id = #{inventoryId}
    </update>

    <delete id="deleteTCanteenInventoryByInventoryId" parameterType="Long">
        delete from t_canteen_inventory where inventory_id = #{inventoryId}
    </delete>

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