package com.zhyc.module.feed.service.impl;

import java.util.List;

import com.zhyc.common.annotation.DataScope;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhyc.module.feed.mapper.SgMaterialMapper;
import com.zhyc.module.feed.domain.SgMaterial;
import com.zhyc.module.feed.service.ISgMaterialService;

/**
 * 原料Service业务层处理
 *
 * @author HashMap
 * @date 2026-01-16
 */
@Service
public class SgMaterialServiceImpl implements ISgMaterialService {
    @Autowired
    private SgMaterialMapper sgMaterialMapper;

    /**
     * 查询原料
     *
     * @param materialId 原料主键
     * @return 原料
     */
    @Override
    public SgMaterial selectSgMaterialByMaterialId(String materialId) {
        return sgMaterialMapper.selectSgMaterialByMaterialId(materialId);
    }

    /**
     * 查询原料列表
     *
     * @param sgMaterial 原料
     * @return 原料
     */
    @Override
    @DataScope(deptAlias = "sg_material_alias", userAlias = "sg_material_alias")
    public List<SgMaterial> selectSgMaterialList(SgMaterial sgMaterial) {
        return sgMaterialMapper.selectSgMaterialList(sgMaterial);
    }

    /**
     * 新增原料
     *
     * @param sgMaterial 原料
     * @return 结果
     */
    @Override
    public int insertSgMaterial(SgMaterial sgMaterial) {
        if (sgMaterialMapper.selectSgMaterialByMaterialId(sgMaterial.getMaterialId()) != null) {
            throw new RuntimeException("重复的编码或名称");
        }
        return sgMaterialMapper.insertSgMaterial(sgMaterial);
    }

    /**
     * 修改原料
     *
     * @param sgMaterial 原料
     * @return 结果
     */
    @Override
    public int updateSgMaterial(SgMaterial sgMaterial) {
        return sgMaterialMapper.updateSgMaterial(sgMaterial);
    }

    /**
     * 批量删除原料
     *
     * @param materialIds 需要删除的原料主键
     * @return 结果
     */
    @Override
    public int deleteSgMaterialByMaterialIds(String[] materialIds) {
        return sgMaterialMapper.deleteSgMaterialByMaterialIds(materialIds);
    }

    /**
     * 删除原料信息
     *
     * @param materialId 原料主键
     * @return 结果
     */
    @Override
    public int deleteSgMaterialByMaterialId(String materialId) {
        return sgMaterialMapper.deleteSgMaterialByMaterialId(materialId);
    }
}
