package com.ruoyi.app.service.impl;

import java.util.List;

import com.ruoyi.app.domain.Pigpen;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.app.mapper.PigCategoryMapper;
import com.ruoyi.app.domain.PigCategory;
import com.ruoyi.app.service.IPigCategoryService;

/**
 * 生猪分类Service业务层处理
 * 
 * @author coede
 * @date 2025-03-19
 */
@Service
public class PigCategoryServiceImpl implements IPigCategoryService 
{
    @Autowired
    private PigCategoryMapper pigCategoryMapper;

    /**
     * 查询生猪分类
     * 
     * @param id 生猪分类主键
     * @return 生猪分类
     */
    @Override
    public PigCategory selectPigCategoryById(Long id)
    {
        return pigCategoryMapper.selectPigCategoryById(id);
    }

    /**
     * 查询生猪分类列表
     * 
     * @param pigCategory 生猪分类
     * @return 生猪分类
     */
    @Override
    public List<PigCategory> selectPigCategoryList(PigCategory pigCategory)
    {
        return pigCategoryMapper.selectPigCategoryList(pigCategory);
    }

    /**
     * 校验分类名称是否唯一
     *
     * @param pigCategory 分类
     * @return 结果
     */
    @Override
    public boolean checkCategoryNameUnique(PigCategory pigCategory)
    {
        Long id = StringUtils.isNull(pigCategory.getId()) ? -1L : pigCategory.getId();
        PigCategory info = pigCategoryMapper.checkCategoryNameUnique(pigCategory.getCategoryName());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue())
        {
            return false;
        }
        return true;
    }

    /**
     * 新增生猪分类
     * 
     * @param pigCategory 生猪分类
     * @return 结果
     */
    @Override
    public int insertPigCategory(PigCategory pigCategory)
    {
        pigCategory.setCreateTime(DateUtils.getNowDate());
        return pigCategoryMapper.insertPigCategory(pigCategory);
    }

    /**
     * 修改生猪分类
     * 
     * @param pigCategory 生猪分类
     * @return 结果
     */
    @Override
    public int updatePigCategory(PigCategory pigCategory)
    {
        pigCategory.setUpdateTime(DateUtils.getNowDate());
        return pigCategoryMapper.updatePigCategory(pigCategory);
    }

    /**
     * 批量删除生猪分类
     * 
     * @param ids 需要删除的生猪分类主键
     * @return 结果
     */
    @Override
    public int deletePigCategoryByIds(Long[] ids)
    {
        return pigCategoryMapper.deletePigCategoryByIds(ids);
    }

    /**
     * 删除生猪分类信息
     * 
     * @param id 生猪分类主键
     * @return 结果
     */
    @Override
    public int deletePigCategoryById(Long id)
    {
        return pigCategoryMapper.deletePigCategoryById(id);
    }
}
