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

    <!-- 获取安卓菜谱详情 -->
    <resultMap id="androidRecipeDetailVOTwo" type="com.bonus.canteen.core.menu.vo.AndroidRecipeDetailVO">
        <result property="detailId" column="detail_id"/>
        <result property="intervalId" column="interval_id"/>
        <result property="uptime" column="uptime"/>
        <result property="intervalType" column="interval_type"/>
        <result property="priorityLevel" column="priority_level"/>
        <collection property="typeList" ofType="com.bonus.canteen.core.menu.vo.AndroidRecipeTypeVO">
            <result property="typeId" column="type_id"/>
            <result property="typeName" column="type_name"/>
            <collection property="typeDetail" ofType="com.bonus.canteen.core.menu.vo.AndroidRecipeTypeDetailVO">
                <result property="parentId" column="type_id"/>
                <result property="dishesId" column="dishes_id"/>
                <result property="productId" column="product_id"/>
                <result property="packageId" column="package_id"/>
                <result property="customId" column="custom_id"/>
                <result property="mealType" column="meal_type"/>
                <result property="productName" column="product_name"/>
                <result property="imageUrl" column="image_url"/>
                <result property="surplusNum" column="surplus_num"/>
                <result property="restrictNum" column="restrict_num"/>
                <result property="salePrice" column="sale_price"/>
                <result property="originalPrice" column="original_price"/>
                <result property="prefPrice" column="pref_price"/>
                <result property="salesMode" column="sales_mode"/>
                <result property="unitPrice" column="unit_price"/>
                <result property="calories" column="calories"/>
                <result property="protein" column="protein"/>
                <result property="fat" column="fat"/>
                <result property="carbohydrate" column="carbohydrate"/>
                <result property="dietaryFiber" column="dietary_fiber"/>
                <result property="cholesterol" column="cholesterol"/>
                <result property="calcium" column="calcium"/>
                <result property="sodium" column="sodium"/>
                <result property="canteenId" column="canteen_id"/>
                <result property="shopstallId" column="shopstall_id"/>
                <result property="weight" column="weight"/>
                <collection property="labelList" ofType="String">
                    <result property="labelName" column="label_name"/>
                </collection>
                <collection property="tasteList" ofType="com.bonus.canteen.core.menu.vo.AppletTasteVO">
                    <result property="tasteId" column="taste_id"/>
                    <result property="tasteName" column="taste_name"/>
                </collection>
            </collection>
        </collection>
    </resultMap>

    <resultMap type="com.bonus.canteen.core.marketing.vo.MktEffectiveUserVO" id="mktEffectiveUserVO">
        <result property="effId" column="eff_id"/>
        <result property="userType" column="user_type"/>
<!--        <result property="orgId" column="org_id"/>-->
<!--        <result property="psnType" column="psn_type"/>-->
        <collection property="orgIdList" ofType="Long">
            <result property="orgId" column="org_id"/>
        </collection>
        <collection property="psnTypeList" ofType="Integer">
            <result property="psnType" column="psn_type"/>
        </collection>
    </resultMap>

    <resultMap id="appletWeekRecipeVO" type="com.bonus.canteen.core.menu.vo.AppletWeekRecipeVO">
        <result property="mealtimeType" column="mealtime_type"/>
        <collection property="typeList" ofType="com.bonus.canteen.core.menu.vo.AppletWeekRecipeTypeVO">
            <result property="typeId" column="type_id"/>
            <result property="typeName" column="type_name"/>
            <collection property="dishesList" ofType="com.bonus.canteen.core.menu.vo.AppletWeekRecipeDishesVO">
                <result property="baseDishesId" column="base_dishes_id"/>
                <result property="dishesName" column="dishes_name"/>
                <result property="dishesImgUrl" column="dishes_img_url"/>
                <result property="detailId" column="detail_id"/>
                <result property="canteenId" column="canteen_id"/>
                <result property="canteenName" column="canteen_name"/>
                <result property="stallId" column="stall_id"/>
                <result property="stallName" column="stall_name"/>
                <collection property="dishesDetailList" ofType="com.bonus.canteen.core.menu.vo.AppletCurrentDishesDetailVO">
                    <result property="dishesId" column="dishes_id"/>
                    <result property="dishesName" column="real_dishes_name"/>
                    <result property="surplusNum" column="surplus_num"/>
                    <result property="restrictNum" column="restrict_num"/>
                    <result property="dishesPrice" column="dishes_price"/>
                    <result property="prefPrice" column="pref_price"/>
                    <result property="sizeType" column="size_type"/>
                    <result property="sizeJson" column="size_json"/>
                </collection>
            </collection>
        </collection>
    </resultMap>

    <!-- 获取菜谱信息(电子菜排) -->
    <resultMap id="menuEleDishRowRecipeVO" type="com.bonus.canteen.core.menu.vo.MenuEleDishRowRecipeVO">
        <result property="applyDate" column="apply_date"/>
        <result property="intervalId" column="interval_id"/>
        <result property="intervalName" column="interval_name"/>
        <result property="canteenId" column="canteen_id"/>
        <result property="canteenName" column="canteen_name"/>
        <result property="shopstallId" column="shopstall_id"/>
        <result property="shopstallName" column="shopstall_name"/>
        <collection property="detailList" ofType="com.bonus.canteen.core.menu.vo.MenuEleDishRowRecipeDetailVO">
            <result property="mealId" column="meal_id"/>
            <result property="mealName" column="meal_name"/>
            <result property="mealType" column="meal_type"/>
            <result property="imageUrl" column="image_url"/>
            <result property="salePrice" column="sale_price"/>
            <result property="weight" column="weight"/>
            <result property="calories" column="calories"/>
            <result property="protein" column="protein"/>
            <result property="fat" column="fat"/>
            <result property="carbohydrate" column="carbohydrate"/>
            <result property="dietaryFiber" column="dietary_fiber"/>
            <result property="cholesterol" column="cholesterol"/>
            <result property="calcium" column="calcium"/>
            <result property="sodium" column="sodium"/>
        </collection>
    </resultMap>

    <!-- 获取安卓菜谱详情 -->
    <resultMap id="androidRecipeDetailThreeVO" type="com.bonus.canteen.core.menu.vo.AndroidRecipeDetailThreeVO">
        <result property="intervalId" column="interval_id"/>
        <result property="intervalType" column="interval_type"/>
        <result property="priorityLevel" column="priority_level"/>
        <collection property="typeList" ofType="com.bonus.canteen.core.menu.vo.AndroidRecipeTypeThreeVO">
            <result property="typeId" column="type_id"/>
            <result property="typeName" column="type_name"/>
            <collection property="typeDetail" ofType="com.bonus.canteen.core.menu.vo.AndroidRecipeTypeDetailThreeVO">
                <result property="detailId" column="detail_id"/>
                <result property="parentId" column="type_id"/>
                <result property="dishesId" column="dishes_id"/>
                <result property="productId" column="product_id"/>
                <result property="packageId" column="package_id"/>
                <result property="customId" column="custom_id"/>
                <result property="mealType" column="meal_type"/>
                <result property="productName" column="product_name"/>
                <result property="imageUrl" column="image_url"/>
                <result property="surplusNum" column="surplus_num"/>
                <result property="restrictNum" column="restrict_num"/>
                <result property="salePrice" column="sale_price"/>
                <result property="originalPrice" column="original_price"/>
                <result property="prefPrice" column="pref_price"/>
                <result property="salesMode" column="sales_mode"/>
                <result property="unitPrice" column="unit_price"/>
                <result property="calories" column="calories"/>
                <result property="protein" column="protein"/>
                <result property="fat" column="fat"/>
                <result property="carbohydrate" column="carbohydrate"/>
                <result property="dietaryFiber" column="dietaryFiber"/>
                <result property="cholesterol" column="cholesterol"/>
                <result property="calcium" column="calcium"/>
                <result property="sodium" column="sodium"/>
                <result property="diningId" column="canteen_id"/>
                <result property="canteenName" column="canteen_name"/>
                <result property="shopstallId" column="shopstall_id"/>
                <result property="stname" column="shopstall_name"/>
                <collection property="labelList" ofType="String">
                    <result property="labelName" column="label_name"/>
                </collection>
                <collection property="tasteList" ofType="com.bonus.canteen.core.menu.vo.AppletTasteVO">
                    <result property="tasteId" column="taste_id"/>
                    <result property="tasteName" column="taste_name"/>
                </collection>
            </collection>
        </collection>
    </resultMap>

    <resultMap id="androidGetRecipeDishesVO" type="com.bonus.canteen.core.menu.vo.AndroidGetRecipeDishesVO">
        <result property="intervalId" column="interval_id"/>
        <collection property="typeList" ofType="com.bonus.canteen.core.menu.vo.AndroidGetRecipeTypeVO">
            <result property="typeId" column="type_id"/>
            <result property="typeName" column="type_name"/>
            <collection property="dishesList" ofType="com.bonus.canteen.core.menu.vo.AndroidGetRecipeDishesDetailVO">
                <result property="dishesId" column="dishes_id"/>
                <result property="dishesName" column="dishes_name"/>
                <result property="dishesImgUrl" column="dishes_img_url"/>
                <result property="detailId" column="detail_id"/>
                <result property="surplusNum" column="surplus_num"/>
                <result property="restrictNum" column="restrict_num"/>
                <result property="dishesPrice" column="dishes_price"/>
                <result property="prefPrice" column="pref_price"/>
                <result property="canteenId" column="canteen_id"/>
                <result property="canteenName" column="canteen_name"/>
                <result property="shopstallId" column="shopstall_id"/>
                <result property="shopstallName" column="shopstall_name"/>
                <result property="weight" column="weight"/>
                <result property="calories" column="calories"/>
                <result property="protein" column="protein"/>
                <result property="fat" column="fat"/>
                <result property="carbohydrate" column="carbohydrate"/>
                <result property="dietaryFiber" column="dietary_fiber"/>
                <result property="cholesterol" column="cholesterol"/>
                <result property="calcium" column="calcium"/>
                <result property="sodium" column="sodium"/>
            </collection>
        </collection>
    </resultMap>

    <select id="selectOrgAndPsnByCustLimitId" parameterType="com.bonus.canteen.core.customer.model.CustInfo" resultType="com.bonus.canteen.core.customer.model.CustInfo">
        select org_id, psn_type
        from cust_info
        where cust_id = #{custId} and cust_state = 1
    </select>

    <!-- 获取指定类型的生效范围详情 -->
    <select id="selectAllUserEff" resultMap="mktEffectiveUserVO">
        select me.eff_id,
               me.user_type,
               med.org_id,
               med.psn_type
        from mkt_effective me
                 left join mkt_effective_detail med on me.eff_id = med.eff_id
        where me.eff_type = #{effType}
          and me.del_flag = #{delFlag}
    </select>

    <!-- 获取一周菜谱 -->
    <select id="selectWeekRecipe" resultMap="appletWeekRecipeVO">
        select
        mrd.mealtime_type,
        if(md.meal_type = 2, 2, mdt.type_id) as type_id,
        if(md.meal_type = 2, '套餐', mdt.type_name) as type_name,
        mdb.base_dishes_id,
        md.dishes_id,
        mdb.dishes_name,
        md.dishes_name as real_dishes_name,
        md.image_url as dishes_img_url,
        mrd.detail_id,
        m.surplus_num,
        m.restrict_num,
        m.price as dishes_price,
        m.sale_price as pref_price,
        ac.canteen_id,
        ac.canteen_name,
        ass.stall_id,
        ass.stall_name,
        m.size_type,
        md.size_json
        from
        menu_recipe_detail mrd
        inner join menu_recipe_dishes m on mrd.detail_id = m.detail_id
        inner join menu_dishes md on m.dishes_id = md.dishes_id
        inner join menu_dishes_type mdt on md.type_id = mdt.type_id
        inner join menu_recipe mr on mrd.recipe_id = mr.recipe_id
        left join menu_dishes_sale_record mdsr on md.dishes_id = mdsr.dishes_id
        and mr.stall_id = mdsr.stall_id
        and mdsr.sale_month = month(curdate())
        left join alloc_canteen ac on mr.canteen_id = ac.canteen_id
        left join alloc_stall ass on mr.stall_id = ass.stall_id
        left join menu_dishes_base mdb on md.base_dishes_id = mdb.base_dishes_id
        where
        mrd.apply_date = #{applyDate}
        <if test="recipeId != null">
            and mrd.recipe_id = #{recipeId}
        </if>
        <if test="recipeIdList != null and recipeIdList.size() > 0">
            and mrd.recipe_id in
            <foreach collection="recipeIdList" item="recipeId" open="(" separator="," close=")">
                #{recipeId}
            </foreach>
        </if>
        order by
        m.sort_num asc
    </select>

    <!-- 获取菜谱全部菜品 -->
    <select id="selectAllRecipeDishesList" resultType="com.bonus.canteen.core.menu.vo.AppletRecommendDishesVO">
        select
        md.dishes_id,
        md.dishes_name,
        m.price as dishes_price,
        md.image_url as dishes_img_url
        from
        menu_recipe_detail mrd
        inner join menu_recipe_dishes m on mrd.detail_id = m.detail_id
        inner join menu_dishes md on m.dishes_id = md.dishes_id
        where
        mrd.recipe_id = #{recipeId}
        and mrd.apply_date = curdate()
        <if test="mealtimeType != null">
            and mrd.mealtime_type = #{mealtimeType}
        </if>
        order by m.sort_num asc
    </select>

    <resultMap id="appletReserveRecipeVO" type="com.bonus.canteen.core.menu.vo.AppletReserveRecipeVO">
        <result property="mealtimeType" column="mealtime_type"/>
        <collection property="typeList" ofType="com.bonus.canteen.core.menu.vo.AppletReserveRecipeTypeVO">
            <result property="typeId" column="type_id"/>
            <result property="typeName" column="type_name"/>
            <collection property="dishesList" ofType="com.bonus.canteen.core.menu.vo.AppletReserveRecipeDishesVO">
                <result property="baseDishesId" column="base_dishes_id"/>
                <result property="dishesName" column="dishes_name"/>
                <result property="detailType" column="detail_type"/>
                <result property="dishesImgUrl" column="dishes_img_url"/>
                <result property="detailId" column="detail_id"/>
                <result property="canteenId" column="canteen_id"/>
                <result property="canteenName" column="canteen_name"/>
                <result property="stallId" column="stall_id"/>
                <result property="stallName" column="stall_name"/>
                <result property="recommendFlag" column="recommend_flag"/>
                <collection property="dishesDetailList" ofType="com.bonus.canteen.core.menu.vo.AppletCurrentDishesDetailVO">
                    <result property="dishesId" column="dishes_id"/>
                    <result property="dishesName" column="real_dishes_name"/>
                    <result property="surplusNum" column="surplus_num"/>
                    <result property="restrictNum" column="restrict_num"/>
                    <result property="dishesPrice" column="dishes_price"/>
                    <result property="prefPrice" column="pref_price"/>
                    <result property="sizeType" column="size_type"/>
                    <result property="sizeJson" column="size_json"/>
                    <result property="monthlySales" column="monthly_sales"/>
                    <result property="goodProbability" column="good_probability"/>
                </collection>
                <collection property="tasteNameList" ofType="string">
                    <result property="tasteName" column="taste_name"/>
                </collection>
            </collection>
        </collection>
    </resultMap>
    <!-- 获取预定点餐菜谱 -->
    <select id="selectReserveRecipe" resultMap="appletReserveRecipeVO">
        select
            mrd.mealtime_type,
            if(md.meal_type = 2, 2, mdt.type_id) as type_id,
            if(md.meal_type = 2, '套餐', mdt.type_name) as type_name,
            mdb.base_dishes_id,
            md.dishes_id,
            mdb.dishes_name,
            md.dishes_name as real_dishes_name,
            md.meal_type as detail_type,
            md.image_url as dishes_img_url,
            mrd.detail_id,
            m.surplus_num,
            m.restrict_num,
            m.price as dishes_price,
            m.sale_price as pref_price,
            ac.canteen_id,
            ac.canteen_name,
            ass.stall_id,
            ass.stall_name,
            m.size_type,
            m.recommend_flag,
            md.size_json,
            mdtt.taste_name,
            mdsr.monthly_sales,
            mdsr.good_probability
        from
            menu_recipe_detail mrd
                inner join menu_recipe_dishes m on mrd.detail_id = m.detail_id
                inner join menu_dishes md on m.dishes_id = md.dishes_id
                inner join menu_dishes_type mdt on md.type_id = mdt.type_id
                inner join menu_recipe mr on mrd.recipe_id = mr.recipe_id
                inner join menu_app_recipe mar on mr.recipe_id = mar.recipe_id
                and mar.bind_type = 2
                left join menu_dishes_sale_record mdsr on md.dishes_id = mdsr.dishes_id
                and mr.stall_id = mdsr.stall_id
                and mdsr.sale_month = month(curdate())
            left join alloc_canteen ac on mr.canteen_id = ac.canteen_id
            left join alloc_stall ass on mr.stall_id = ass.stall_id
            left join menu_dishes_base mdb on md.base_dishes_id = mdb.base_dishes_id
            left join menu_taste_dishes mtd on md.dishes_id = mtd.dishes_id
            left join menu_dishes_taste mdtt on mtd.taste_id = mdtt.taste_id
        where
            mrd.apply_date = #{applyDate}
          and mr.recipe_id = #{recipeId}
        order by
            m.sort_num asc
    </select>

    <!-- 分页获取套餐基础信息 -->
    <select id="selectAllRecipeV2List" resultType="com.bonus.canteen.core.menu.vo.MenuRecipeV2PageVO">
        select
        mr.recipe_id,
        mr.recipe_name,
        mr.recipe_type,
        ac.canteen_id,
        ac.canteen_name,
        aa.area_id,
        aa.area_name,
        a.stall_id,
        a.stall_name,
        me.eff_id,
        me.eff_name,
        mr.crby,
        mr.crtime
        from
        menu_recipe mr
        left join alloc_canteen ac on mr.canteen_id = ac.canteen_id
        left join alloc_stall a on mr.stall_id = a.stall_id
        left join mkt_effective me on mr.eff_id = me.eff_id
        left join alloc_area aa on  ac.area_id = aa.area_id
        where
        mr.del_flag = #{delFlag}
        <if test="content.recipeId != null ">
            and mr.recipe_id = #{content.recipeId}
        </if>
        <if test="content.areaIds != null and content.areaIds.size >0">
            and  aa.area_id in
            <foreach collection="content.areaIds" item="areaId" open="(" separator="," close=")">
                #{areaId}
            </foreach>
        </if>
        <if test="content.recipeName != null and content.recipeName != ''">
            and mr.recipe_name like concat('%', #{content.recipeName}, '%')
        </if>
        <if test="content.canteenId != null and content.canteenId !=-1">
            and mr.canteen_id = #{content.canteenId}
        </if>
        <if test="content.canteenIds != null and content.canteenIds.size >0">
            and  ac.canteen_id in
            <foreach collection="content.canteenIds" item="canteenId" open="(" separator="," close=")">
                #{canteenId}
            </foreach>
        </if>
        <if test="content.stallId != null and content.stallId !=-1">
            and mr.stall_id = #{content.stallId}
        </if>
        <if test="content.stallIds != null and content.stallIds.size >0">
            and  a.stall_id in
            <foreach collection="content.stallIds" item="stallId" open="(" separator="," close=")">
                #{stallId}
            </foreach>
        </if>
        <if test="content.areaId != null and content.areaId !=-1">
            and ac.area_id = #{content.areaId}
        </if>
        <if test="content.areaIds != null and content.areaIds.size >0">
            and  ac.area_id in
            <foreach collection="content.areaIds" item="areaId" open="(" separator="," close=")">
                #{areaId}
            </foreach>
        </if>
        <if test="content.recipeType != null">
            and mr.recipe_type = #{content.recipeType}
        </if>
        order by
        mr.crtime desc
    </select>

    <!-- 获取安卓菜谱详情 -->
    <select id="selectAndroidRecipeTwo" resultMap="androidRecipeDetailVOTwo">
        select
            mrd.detail_id,
            mrd.mealtime_type as interval_id,
            mrd.uptime,
            mrd.mealtime_type as interval_type,
            if(md.meal_type = 2, 2, mdt.type_id) as type_id,
            if(md.meal_type = 2, '套餐', mdt.type_name) as type_name,
            if(md.meal_type = 1, md.dishes_id, null) as dishes_id,
            null as product_id,
            if(md.meal_type = 2, md.dishes_id, null) as package_id,
            md.custom_id,
            md.meal_type,
            md.dishes_name as product_name,
            md.image_url,
            md.weight,
            mdl.label_name,
            mdtt.taste_id,
            mdtt.taste_name,
            mrdd.surplus_num,
            mrdd.restrict_num,
            mrdd.price as sale_price,
            md.price as original_price,
            mrdd.sale_price as pref_price,
            md.sales_mode,
            md.unit_price,
            md.calories,
            md.protein,
            md.fat,
            md.carbohydrate,
            md.dietary_fiber,
            md.cholesterol,
            md.calcium,
            md.sodium,
            ac.canteen_id,
            ass.stall_id as shopstall_id
        from
            menu_recipe mr
                left join menu_recipe_detail mrd on mr.recipe_id = mrd.recipe_id
                left join menu_recipe_dishes mrdd on mrd.detail_id = mrdd.detail_id
                and mrdd.size_type != 3
                left join menu_dishes md on mrdd.dishes_id = md.dishes_id
                left join menu_dishes_type mdt on md.type_id = mdt.type_id
                left join menu_label_dishes mld on md.dishes_id = mld.dishes_id
                left join menu_dishes_label mdl on mld.label_id = mdl.label_id
                left join menu_taste_dishes mtd on md.dishes_id = mtd.dishes_id
                left join menu_dishes_taste mdtt on mtd.taste_id = mdtt.taste_id
                left join alloc_canteen ac on mr.canteen_id = ac.canteen_id
                left join alloc_stall ass on mr.stall_id = ass.stall_id
        where
            mrd.recipe_id = #{recipeId}
          and mrd.apply_date = #{applyDate}
          and md.dishes_id is not null
        order by mrdd.sort_num asc
    </select>

    <!-- 获取菜谱信息(电子菜排) -->
    <select id="selectEleDishRowRecipe" resultMap="menuEleDishRowRecipeVO">
        select
            mrd.apply_date,
            mrd.mealtime_type as interval_id,
            ac.canteen_id,
            ac.canteen_name,
            ass.stall_id as shopstall_id,
            ass.stall_name as shopstall_name,
            md.dishes_id as meal_id,
            md.dishes_name as meal_name,
            md.meal_type,
            md.image_url,
            mrdd.price as sale_price,
            md.weight,
            md.calories,
            md.protein,
            md.fat,
            md.carbohydrate,
            md.dietary_fiber,
            md.cholesterol,
            md.calcium,
            md.sodium
        from
            menu_recipe_detail mrd
                left join menu_recipe mr on mrd.recipe_id = mr.recipe_id
                left join alloc_canteen ac on mr.canteen_id = ac.canteen_id
                left join alloc_stall ass on mr.stall_id = ass.stall_id
                left join menu_recipe_dishes mrdd on mrd.detail_id = mrdd.detail_id
                and mrdd.size_type != 3
                left join menu_dishes md on mrdd.dishes_id = md.dishes_id
        WHERE
            mr.del_flag = 2
          and mrd.recipe_id = #{recipeId}
          and mrd.apply_date = #{applyDate}
        order by mrdd.sort_num asc
    </select>

    <!-- 获取指定人员指定时间内的饮食详情 -->
    <select id="selectOrdDetailByCustId" resultType="com.bonus.canteen.core.menu.vo.PersonalDietRecordVO">
        select
        od.goods_dishes_name as mealName,
        od.price as price
        from
        order_detail od
        left join order_info oai on od.order_id = oai.order_id
        where
        oai.cust_id = #{custId}
        and oai.order_date between #{startTime} and #{endTime}
        and oai.order_state in
        <foreach collection="ordStateList" item="ordState" separator="," open="(" close=")">
            #{ordState}
        </foreach>
    </select>

    <!-- 获取所有出品机绑定菜谱详情 -->
    <select id="selectAndroidRecipeDetail"
            resultType="com.bonus.canteen.core.menu.vo.AndroidAllProductsRecipeVO">
        select
        md.dishes_name as mealName,
        mrdd.price,
        substring_index(md.image_url, ',', 1) as imageUrl,
        cast(avg(med.star_level) as decimal(10, 2)) as starLevel
        from
        menu_recipe_detail mrd
        left join menu_recipe_dishes mrdd on mrd.detail_id = mrdd.detail_id
        and mrdd.size_type != 3
        left join menu_dishes md on mrdd.dishes_id = md.dishes_id
        left join menu_evalua_detail med on md.dishes_id = med.meal_id
        where
        md.del_flag = #{delFlag}
        and mrd.apply_date = #{applyDate}
        and mrd.mealtime_type = #{mealtimeType}
        and mrd.recipe_id in
        <foreach collection="recipeIdList" item="recipeId" separator="," open="(" close=")">
            #{recipeId}
        </foreach>
        group by
        md.dishes_name,
        mrdd.price,
        md.image_url
        order by mrdd.sort_num asc
    </select>

    <!-- 获取安卓菜谱详情 -->
    <select id="selectAndroidRecipeThree" resultMap="androidRecipeDetailThreeVO">
        select
        mrd.mealtime_type as interval_id,
        '' as interval_alias_name,
        mrd.mealtime_type as interval_type,
        if(md.meal_type = 2, 2, mdt.type_id) as type_id,
        if(md.meal_type = 2, '套餐', mdt.type_name) as type_name,
        if(md.meal_type = 2, 'meal', mdt.alias_name) as type_alias_name,
        mrd.detail_id,
        mr.uptime,
        if(md.meal_type = 1, md.dishes_id, null) as dishes_id,
        null as product_id,
        if(md.meal_type = 2, md.dishes_id, null) as package_id,
        md.custom_id,
        md.meal_type,
        md.dishes_name as product_name,
        md.alias_name,
        md.image_url,
        mdl.label_name,
        mdtt.taste_id,
        mdtt.taste_name,
        mrdd.surplus_num,
        mrdd.restrict_num,
        mrdd.price as sale_price,
        md.price as original_price,
        mrdd.sale_price as pref_price,
        md.initial_score,
        md.calories,
        md.protein,
        md.fat,
        md.carbohydrate,
        md.dietary_fiber,
        md.cholesterol,
        md.calcium,
        md.sodium,
        ac.canteen_id,
        ac.canteen_name,
        '' as canteen_alias_name,
        ass.stall_id as shopstall_id,
        ass.stall_name as shopstall_name,
        '' as shopstall_alias_name
        from
        menu_recipe_detail mrd
        left join menu_recipe mr on mrd.recipe_id = mr.recipe_id
        left join alloc_canteen ac on mr.canteen_id = ac.canteen_id
        left join alloc_stall ass on mr.stall_id = ass.stall_id
        left join menu_recipe_dishes mrdd on mrd.detail_id = mrdd.detail_id
        and mrdd.size_type != 3
        left join menu_dishes md on mrdd.dishes_id = md.dishes_id
        left join menu_dishes_type mdt on md.type_id = mdt.type_id
        left join menu_label_dishes mld on md.dishes_id = mld.dishes_id
        left join menu_dishes_label mdl on mld.label_id = mdl.label_id
        left join menu_taste_dishes mtd on md.dishes_id = mtd.dishes_id
        left join menu_dishes_taste mdtt on mtd.taste_id = mdtt.taste_id
        where
        mrd.recipe_id in
        <foreach collection="recipeIdList" item="recipeId" separator="," open="(" close=")">
            #{recipeId}
        </foreach>
        and mr.eff_id in
        <foreach collection="effIdSet" item="effId" separator="," open="(" close=")">
            #{effId}
        </foreach>
        and mrd.apply_date = #{applyDate}
        order by mrdd.sort_num asc
    </select>

    <!--菜谱ID 获取菜谱绑定食堂相关信息-->
    <select id="getRecipeInfoByRecipeId" resultType="com.bonus.canteen.core.menu.vo.AppletMenuRecipeCanteenVO"
            parameterType="java.lang.Long">
        select
            mr.recipe_id,
            mr.recipe_name,
            mr.canteen_id,
            ac.canteen_name,
            mr.stall_id as shopstall_id,
            ass.stall_name as stname
        from
            menu_recipe mr
                left join alloc_canteen ac on mr.canteen_id = ac.canteen_id
                left join alloc_stall ass on mr.stall_id = ass.stall_id
        where
            mr.recipe_id = #{recipeId}
    </select>

    <select id="selectAndroidRecipeDetailByRecipeId" resultMap="androidGetRecipeDishesVO">
        select
            mrd.mealtime_type as interval_id,
            mdt.type_id,
            mdt.type_name,
            md.dishes_id,
            md.dishes_name,
            md.image_url as dishes_img_url,
            md.calories,
            md.protein,
            md.fat,
            md.carbohydrate,
            md.dietary_fiber,
            md.cholesterol,
            md.calcium,
            md.sodium,
            md.weight,
            mrd.detail_id,
            m.surplus_num,
            m.restrict_num,
            m.price as dishes_price,
            m.sale_price as pref_price,
            ac.canteen_id,
            ac.canteen_name,
            ass.stall_id as shopstall_id,
            ass.stall_name as shopstall_name
        from
            menu_recipe mr
                left join menu_recipe_detail mrd on mr.recipe_id = mrd.recipe_id
                left join menu_recipe_dishes m on mrd.detail_id = m.detail_id
                and m.size_type != 3
                left join menu_dishes md on m.dishes_id = md.dishes_id
                left join menu_dishes_type mdt on md.type_id = mdt.type_id
                left join alloc_canteen ac on mr.canteen_id = ac.canteen_id
                left join alloc_stall ass on mr.stall_id = ass.stall_id
        where
            mrd.recipe_id = #{recipeId}
          and mrd.apply_date = #{applyDate}
        order by m.sort_num asc
    </select>
</mapper>
