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

    <!-- 批量插入数据 -->
    <insert id="insertBatch" parameterType="List">
        insert into
        menu_material_dishes (dishes_id, material_id, weight, material_type, crby)
        values
        <foreach collection="materialList" item="materialList" separator="," close=";">
            (#{materialList.dishesId}, #{materialList.materialId}, #{materialList.weight},
            #{materialList.materialType}, #{materialList.crby})
        </foreach>
    </insert>

<!--    <select id="getDishDetails" resultType="com.bonus.canteen.core.menu.vo.DishDetails">-->
<!--        SELECT mmd.dishes_id,-->
<!--               mm.nutrition_id,-->
<!--               mm.material_name,-->
<!--               mn.big_type,-->
<!--               mn.little_type,-->
<!--               mmd.weight,-->
<!--               mn.calories,-->
<!--               mn.protein,-->
<!--               mn.fat,-->
<!--               mn.carbohydrate,-->
<!--               mn.cholesterol,-->
<!--               mn.purine,-->
<!--               mn.glycemic_index,-->
<!--               mn.fatty_acid-->
<!--        FROM menu_material_dishes mmd-->
<!--                 LEFT JOIN menu_material mm ON mm.material_id = mmd.material_id-->
<!--                 LEFT JOIN menu_nutrition mn ON mn.nutrition_id = mm.nutrition_id-->
<!--        WHERE mmd.dishes_id = #{dishesId}-->
<!--    </select>-->

    <select id="getMenuMaterialById" resultType="com.bonus.canteen.core.menu.vo.MenuMaterialBasVO">
        SELECT mm.material_id,
               mm.material_name,
               mm.material_code,
               mm.image_url,
               mmd.weight,
               mmd.material_type,
               mn.big_type,
               mn.little_type
        FROM menu_material mm
                 LEFT JOIN menu_material_dishes mmd ON mm.material_id = mmd.material_id
                 LEFT JOIN menu_nutrition mn ON mn.nutrition_id = mm.nutrition_id
        WHERE mmd.dishes_id = #{dishesId}
            and mmd.del_flag = 2
    </select>
    <select id="selectDishesList" resultType="com.bonus.canteen.core.menu.dto.MenuUpdateDishesModel">
        select
        md.id,
        md.dishes_id
        from
        menu_material_dishes mmd
        left join menu_dishes md on mmd.dishes_id = md.dishes_id
        where
        mmd.material_id in
        <foreach collection="materialIdList" item="materialId" separator="," open="(" close=")">
            #{materialId}
        </foreach>
        group by
        md.id,
        md.dishes_id
    </select>
</mapper>
