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

    <!-- 获取食材营养信息 -->
    <select id="selectNutritionWeightList" parameterType="Long" resultType="com.bonus.canteen.core.menu.utils.NutritionEntity">
        select mn.edible,
               mn.calories,
               mn.protein,
               mn.fat,
               mn.carbohydrate,
               mn.ash,
               mn.dietary_fiber dietaryFiber,
               mn.cholesterol,
               mn.vitamin_a vitaminA,
               mn.vitamin_c vitaminC,
               mn.vitamin_d vitaminD,
               mn.vitamin_e vitaminE,
               mn.thiamine,
               mn.riboflavin,
               mn.folic,
               mn.niacin,
               mn.carotene,
               mn.calcium,
               mn.phosphorus,
               mn.kalium,
               mn.sodium,
               mn.magnesium,
               mn.iron,
               mn.zinc,
               mn.cuprum,
               mn.manganese,
               mn.selenium,
               mn.glycemic_index,
               mmd.weight,
               md.weight totalWeight,
               100 as base_weight
        from menu_nutrition mn
                 left join menu_material mm on mn.nutrition_id = mm.nutrition_id
                 left join menu_material_dishes mmd on mmd.material_id = mm.material_id
                 left join menu_dishes md on md.dishes_id = mmd.dishes_id
        where mmd.dishes_id = #{dishesId}
    </select>

    <!-- 获取营养信息列表 -->
    <select id="selectNutritionList" parameterType="object" resultType="com.bonus.canteen.core.menu.vo.MenuNutritionPageVO">
        select distinct
        mn.*
        from
        menu_nutrition mn
        left join menu_suit_dishes msd on msd.dishes_id = mn.nutrition_id
        left join menu_dishes_suit mdst on mdst.suit_id = msd.suit_id
        left join menu_dishes_effect_relation mder on mder.dishes_id = mn.nutrition_id
        left join menu_dishes_effect mde on mde.effect_id = mder.effect_id
        where
        mn.del_flag = #{menuNutritionDTO.delFlag}
        <if test="menuNutritionDTO.nutritionCode != null">
            and mn.nutrition_code = #{menuNutritionDTO.nutritionCode}
        </if>
        <if test="menuNutritionDTO.nutritionName != null and menuNutritionDTO.nutritionName != ''">
            and mn.nutrition_name like concat(concat('%', #{menuNutritionDTO.nutritionName}), '%')
        </if>
        <if test="menuNutritionDTO.bigType != null and menuNutritionDTO.bigType != ''">
            and mn.big_type like concat(concat('%', #{menuNutritionDTO.bigType}), '%')
        </if>
        <if test="menuNutritionDTO.littleType != null and menuNutritionDTO.littleType != ''">
            and mn.little_type like concat(concat('%', #{menuNutritionDTO.littleType}), '%')
        </if>
        order by
        mn.crtime desc
    </select>

    <!-- 获取营养信息详情 -->
    <select id="selectMenuNutritionDetailById"
            resultType="com.bonus.canteen.core.menu.vo.MenuNutritionDetailVO">
        select color,
               label,
               processing_method,
               processing_time,
               edible,
               water,
               calories,
               protein,
               fat,
               carbohydrate,
               dietary_fiber,
               cholesterol,
               ash,
               vitamin_a,
               carotene,
               retinol,
               thiamine,
               riboflavin,
               niacin,
               vitamin_c,
               vitamin_d,
               vitamin_e,
               calcium,
               phosphorus,
               kalium,
               sodium,
               magnesium,
               iron,
               zinc,
               selenium
        from menu_nutrition
        where nutrition_id = #{nutritionId}
    </select>
</mapper>
