<?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.bonus.canteen.menu.mapper.MenuRecipeMapper">
    <resultMap type="com.bonus.canteen.menu.domain.MenuRecipe" id="MenuRecipeResult">
        <result property="id"    column="id"    />
        <result property="recipeId"    column="recipe_id"    />
        <result property="planId"    column="plan_id"    />
        <result property="recipeName"    column="recipe_name"    />
        <result property="isDefault"    column="is_default"    />
        <result property="recipeType"    column="recipe_type"    />
        <result property="effectDate"    column="effect_date"    />
        <result property="expireDate"    column="expire_date"    />
        <result property="canteenId"    column="canteen_id"    />
        <result property="stallId"    column="stall_id"    />
        <result property="enableFlag"    column="enable_flag"    />
        <result property="revision"    column="revision"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectMenuRecipeVo">
        select id, recipe_id, plan_id, recipe_name, is_default, recipe_type, effect_date, expire_date, canteen_id, stall_id, enable_flag, revision, create_by, create_time, update_by, update_time, remark from menu_recipe
    </sql>

    <select id="selectMenuRecipeList" parameterType="com.bonus.canteen.menu.domain.MenuRecipe" resultMap="MenuRecipeResult">
        <include refid="selectMenuRecipeVo"/>
        <where>  
            <if test="recipeId != null "> and recipe_id = #{recipeId}</if>
            <if test="planId != null  and planId != ''"> and plan_id = #{planId}</if>
            <if test="recipeName != null  and recipeName != ''"> and recipe_name like concat('%', #{recipeName}, '%')</if>
            <if test="isDefault != null "> and is_default = #{isDefault}</if>
            <if test="recipeType != null "> and recipe_type = #{recipeType}</if>
            <if test="effectDate != null "> and effect_date = #{effectDate}</if>
            <if test="expireDate != null "> and expire_date = #{expireDate}</if>
            <if test="canteenId != null "> and canteen_id = #{canteenId}</if>
            <if test="stallId != null "> and stall_id = #{stallId}</if>
            <if test="enableFlag != null "> and enable_flag = #{enableFlag}</if>
            <if test="revision != null "> and revision = #{revision}</if>
        </where>
    </select>
    
    <select id="selectMenuRecipeById" parameterType="Long" resultMap="MenuRecipeResult">
        <include refid="selectMenuRecipeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertMenuRecipe" parameterType="com.bonus.canteen.menu.domain.MenuRecipe" useGeneratedKeys="true" keyProperty="id">
        insert into menu_recipe
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recipeId != null">recipe_id,</if>
            <if test="planId != null">plan_id,</if>
            <if test="recipeName != null and recipeName != ''">recipe_name,</if>
            <if test="isDefault != null">is_default,</if>
            <if test="recipeType != null">recipe_type,</if>
            <if test="effectDate != null">effect_date,</if>
            <if test="expireDate != null">expire_date,</if>
            <if test="canteenId != null">canteen_id,</if>
            <if test="stallId != null">stall_id,</if>
            <if test="enableFlag != null">enable_flag,</if>
            <if test="revision != null">revision,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="recipeId != null">#{recipeId},</if>
            <if test="planId != null">#{planId},</if>
            <if test="recipeName != null and recipeName != ''">#{recipeName},</if>
            <if test="isDefault != null">#{isDefault},</if>
            <if test="recipeType != null">#{recipeType},</if>
            <if test="effectDate != null">#{effectDate},</if>
            <if test="expireDate != null">#{expireDate},</if>
            <if test="canteenId != null">#{canteenId},</if>
            <if test="stallId != null">#{stallId},</if>
            <if test="enableFlag != null">#{enableFlag},</if>
            <if test="revision != null">#{revision},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateMenuRecipe" parameterType="com.bonus.canteen.menu.domain.MenuRecipe">
        update menu_recipe
        <trim prefix="SET" suffixOverrides=",">
            <if test="recipeId != null">recipe_id = #{recipeId},</if>
            <if test="planId != null">plan_id = #{planId},</if>
            <if test="recipeName != null and recipeName != ''">recipe_name = #{recipeName},</if>
            <if test="isDefault != null">is_default = #{isDefault},</if>
            <if test="recipeType != null">recipe_type = #{recipeType},</if>
            <if test="effectDate != null">effect_date = #{effectDate},</if>
            <if test="expireDate != null">expire_date = #{expireDate},</if>
            <if test="canteenId != null">canteen_id = #{canteenId},</if>
            <if test="stallId != null">stall_id = #{stallId},</if>
            <if test="enableFlag != null">enable_flag = #{enableFlag},</if>
            <if test="revision != null">revision = #{revision},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMenuRecipeById" parameterType="Long">
        delete from menu_recipe where id = #{id}
    </delete>

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