package com.bonus.canteen.core.cook.service.impl;

import java.util.List;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.canteen.core.cook.mapper.CookDishesMaterialMapper;
import com.bonus.canteen.core.cook.domain.CookDishesMaterial;
import com.bonus.canteen.core.cook.service.ICookDishesMaterialService;

/**
 * 菜品原料关联Service业务层处理
 * 
 * @author xsheng
 * @date 2025-05-25
 */
@Service
public class CookDishesMaterialServiceImpl implements ICookDishesMaterialService {
    @Autowired
    private CookDishesMaterialMapper cookDishesMaterialMapper;

    /**
     * 查询菜品原料关联
     * 
     * @param id 菜品原料关联主键
     * @return 菜品原料关联
     */
    @Override
    public CookDishesMaterial selectCookDishesMaterialById(Long id) {
        return cookDishesMaterialMapper.selectCookDishesMaterialById(id);
    }

    /**
     * 查询菜品原料关联列表
     * 
     * @param cookDishesMaterial 菜品原料关联
     * @return 菜品原料关联
     */
    @Override
    public List<CookDishesMaterial> selectCookDishesMaterialList(CookDishesMaterial cookDishesMaterial) {
        return cookDishesMaterialMapper.selectCookDishesMaterialList(cookDishesMaterial);
    }

    /**
     * 新增菜品原料关联
     * 
     * @param cookDishesMaterial 菜品原料关联
     * @return 结果
     */
    @Override
    public int insertCookDishesMaterial(CookDishesMaterial cookDishesMaterial) {
        cookDishesMaterial.setCreateTime(DateUtils.getNowDate());
        try {
            return cookDishesMaterialMapper.insertCookDishesMaterial(cookDishesMaterial);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 修改菜品原料关联
     * 
     * @param cookDishesMaterial 菜品原料关联
     * @return 结果
     */
    @Override
    public int updateCookDishesMaterial(CookDishesMaterial cookDishesMaterial) {
        cookDishesMaterial.setUpdateTime(DateUtils.getNowDate());
        try {
            return cookDishesMaterialMapper.updateCookDishesMaterial(cookDishesMaterial);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 批量删除菜品原料关联
     * 
     * @param ids 需要删除的菜品原料关联主键
     * @return 结果
     */
    @Override
    public int deleteCookDishesMaterialByIds(Long[] ids) {
        return cookDishesMaterialMapper.deleteCookDishesMaterialByIds(ids);
    }

    /**
     * 删除菜品原料关联信息
     * 
     * @param id 菜品原料关联主键
     * @return 结果
     */
    @Override
    public int deleteCookDishesMaterialById(Long id) {
        return cookDishesMaterialMapper.deleteCookDishesMaterialById(id);
    }
}
