<?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.core.menu.mapper.MenuRecipeDetailMapper">
    <resultMap type="com.bonus.canteen.core.menu.domain.MenuRecipeDetail" id="MenuRecipeDetailResult">
        <result property="id"    column="id"    />
        <result property="detailId"    column="detail_id"    />
        <result property="saleTypeId"    column="sale_type_id"    />
        <result property="recipeId"    column="recipe_id"    />
        <result property="applyDate"    column="apply_date"    />
        <result property="applyWeek"    column="apply_week"    />
        <result property="applyMonth"    column="apply_month"    />
        <result property="mealtimeType"    column="mealtime_type"    />
        <result property="detailType"    column="detail_type"    />
        <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="selectMenuRecipeDetailVo">
        select id, detail_id, sale_type_id, recipe_id, apply_date, apply_week, apply_month, mealtime_type, detail_type, revision, create_by, create_time, update_by, update_time, remark from menu_recipe_detail
    </sql>

    <select id="selectMenuRecipeDetailList" parameterType="com.bonus.canteen.core.menu.domain.MenuRecipeDetail" resultMap="MenuRecipeDetailResult">
        <include refid="selectMenuRecipeDetailVo"/>
        <where>  
            <if test="detailId != null "> and detail_id = #{detailId}</if>
            <if test="saleTypeId != null  and saleTypeId != ''"> and sale_type_id = #{saleTypeId}</if>
            <if test="recipeId != null "> and recipe_id = #{recipeId}</if>
            <if test="applyDate != null "> and apply_date = #{applyDate}</if>
            <if test="applyWeek != null "> and apply_week = #{applyWeek}</if>
            <if test="applyMonth != null "> and apply_month = #{applyMonth}</if>
            <if test="mealtimeType != null "> and mealtime_type = #{mealtimeType}</if>
            <if test="detailType != null "> and detail_type = #{detailType}</if>
            <if test="revision != null "> and revision = #{revision}</if>
        </where>
    </select>
    
    <select id="selectMenuRecipeDetailById" parameterType="Long" resultMap="MenuRecipeDetailResult">
        <include refid="selectMenuRecipeDetailVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertMenuRecipeDetail" parameterType="com.bonus.canteen.core.menu.domain.MenuRecipeDetail" useGeneratedKeys="true" keyProperty="id">
        insert into menu_recipe_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="detailId != null">detail_id,</if>
            <if test="saleTypeId != null">sale_type_id,</if>
            <if test="recipeId != null">recipe_id,</if>
            <if test="applyDate != null">apply_date,</if>
            <if test="applyWeek != null">apply_week,</if>
            <if test="applyMonth != null">apply_month,</if>
            <if test="mealtimeType != null">mealtime_type,</if>
            <if test="detailType != null">detail_type,</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="detailId != null">#{detailId},</if>
            <if test="saleTypeId != null">#{saleTypeId},</if>
            <if test="recipeId != null">#{recipeId},</if>
            <if test="applyDate != null">#{applyDate},</if>
            <if test="applyWeek != null">#{applyWeek},</if>
            <if test="applyMonth != null">#{applyMonth},</if>
            <if test="mealtimeType != null">#{mealtimeType},</if>
            <if test="detailType != null">#{detailType},</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="updateMenuRecipeDetail" parameterType="com.bonus.canteen.core.menu.domain.MenuRecipeDetail">
        update menu_recipe_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="detailId != null">detail_id = #{detailId},</if>
            <if test="saleTypeId != null">sale_type_id = #{saleTypeId},</if>
            <if test="recipeId != null">recipe_id = #{recipeId},</if>
            <if test="applyDate != null">apply_date = #{applyDate},</if>
            <if test="applyWeek != null">apply_week = #{applyWeek},</if>
            <if test="applyMonth != null">apply_month = #{applyMonth},</if>
            <if test="mealtimeType != null">mealtime_type = #{mealtimeType},</if>
            <if test="detailType != null">detail_type = #{detailType},</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="deleteMenuRecipeDetailById" parameterType="Long">
        delete from menu_recipe_detail where id = #{id}
    </delete>

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