package cn.iocoder.yudao.module.system.api.dishesnutrition;


import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.api.dishesnutrition.dto.DishesNutritionRespDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.dishesnutrition.DishesNutritionDO;
import cn.iocoder.yudao.module.system.dal.mysql.dishesnutrition.DishesNutritionMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜品营养 Service 接口
 *
 * @author 开发账号
 */
@Service
public class DishesNutritionApiImpl implements DishesNutritionApi {

    @Resource
    private DishesNutritionMapper dishesNutritionMapper;
    /**
     * @param ids
     * @return
     * @Description: 根据菜品id 获取菜品营养
     * @Author: qjq
     * @Date: 2024/4/2 16:58
     */
    @Override
    public List<DishesNutritionRespDTO> getDishesList(Long ids) {
        return BeanUtils.toBean(dishesNutritionMapper.selectList(new LambdaQueryWrapperX<DishesNutritionDO>()
                .eqIfPresent(DishesNutritionDO::getDishesId,ids)),DishesNutritionRespDTO.class);
    }


    @Override
    public DishesNutritionRespDTO getDishEnergy(Long id) {
        return BeanUtils.toBean(dishesNutritionMapper.selectOne(new LambdaQueryWrapperX<DishesNutritionDO>()
                .eqIfPresent(DishesNutritionDO::getDishesId,id)
                .eqIfPresent(DishesNutritionDO::getNutritionName,"能量")
                .last("limit 1")),DishesNutritionRespDTO.class);
    }

}