package com.ruoyi.materialType.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.materialType.mapper.CMaterialTypeMapper;
import com.ruoyi.materialType.domain.CMaterialType;
import com.ruoyi.materialType.service.ICMaterialTypeService;

/**
 * 物料类别Service业务层处理
 *
 * @author ruoyi
 * @date 2024-03-01
 */
@Service
public class CMaterialTypeServiceImpl implements ICMaterialTypeService
{
    @Autowired
    private CMaterialTypeMapper cMaterialTypeMapper;

    /**
     * 查询物料类别
     *
     * @param typeId 物料类别主键
     * @return 物料类别
     */
    @Override
    public CMaterialType selectCMaterialTypeByTypeId(Long typeId)
    {
        return cMaterialTypeMapper.selectCMaterialTypeByTypeId(typeId);
    }

    /**
     * 查询物料类别列表
     *
     * @param cMaterialType 物料类别
     * @return 物料类别
     */
    @Override
    public List<CMaterialType> selectCMaterialTypeList(CMaterialType cMaterialType)
    {
        return cMaterialTypeMapper.selectCMaterialTypeList(cMaterialType);
    }

    /**
     * 新增物料类别
     *
     * @param cMaterialType 物料类别
     * @return 结果
     */
    @Override
    public int insertCMaterialType(CMaterialType cMaterialType)
    {
        return cMaterialTypeMapper.insertCMaterialType(cMaterialType);
    }

    /**
     * 修改物料类别
     *
     * @param cMaterialType 物料类别
     * @return 结果
     */
    @Override
    public int updateCMaterialType(CMaterialType cMaterialType)
    {
        return cMaterialTypeMapper.updateCMaterialType(cMaterialType);
    }

    /**
     * 批量删除物料类别
     *
     * @param typeIds 需要删除的物料类别主键
     * @return 结果
     */
    @Override
    public int deleteCMaterialTypeByTypeIds(Long[] typeIds)
    {
        return cMaterialTypeMapper.deleteCMaterialTypeByTypeIds(typeIds);
    }

    /**
     * 删除物料类别信息
     *
     * @param typeId 物料类别主键
     * @return 结果
     */
    @Override
    public int deleteCMaterialTypeByTypeId(Long typeId)
    {
        return cMaterialTypeMapper.deleteCMaterialTypeByTypeId(typeId);
    }

    /**
     * 检查物料编码是否存在
     * @param cMaterialType
     * @return
     */
    @Override
    public boolean checkTypeNoUnique(CMaterialType cMaterialType) {
        Long typeId = StringUtils.isNull(cMaterialType.getTypeId()) ? -1L : cMaterialType.getTypeId();
        CMaterialType info = cMaterialTypeMapper.checkTypeNoUnique(cMaterialType.getTypeNo());
        if (StringUtils.isNotNull(info) && info.getTypeId().longValue() != typeId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
