package com.ruoyi.baseinfo.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.baseinfo.mapper.BaseMaterialtypeInfoMapper;
import com.ruoyi.baseinfo.domain.BaseMaterialtypeInfo;
import com.ruoyi.baseinfo.service.IBaseMaterialtypeInfoService;
import com.ruoyi.common.core.text.Convert;

/**
 * 物料类型基础信息Service业务层处理
 * 
 * @author CaesarBao
 * @date 2020-10-22
 */
@Service
public class BaseMaterialtypeInfoServiceImpl implements IBaseMaterialtypeInfoService 
{
    @Autowired
    private BaseMaterialtypeInfoMapper baseMaterialtypeInfoMapper;

    /**
     * 查询物料类型基础信息
     * 
     * @param objid 物料类型基础信息ID
     * @return 物料类型基础信息
     */
    @Override
    public BaseMaterialtypeInfo selectBaseMaterialtypeInfoById(Long objid)
    {
        return baseMaterialtypeInfoMapper.selectBaseMaterialtypeInfoById(objid);
    }

    /**
     * 查询物料类型基础信息列表
     * 
     * @param baseMaterialtypeInfo 物料类型基础信息
     * @return 物料类型基础信息
     */
    @Override
    public List<BaseMaterialtypeInfo> selectBaseMaterialtypeInfoList(BaseMaterialtypeInfo baseMaterialtypeInfo)
    {
        return baseMaterialtypeInfoMapper.selectBaseMaterialtypeInfoList(baseMaterialtypeInfo);
    }

    /**
     * 新增物料类型基础信息
     * 
     * @param baseMaterialtypeInfo 物料类型基础信息
     * @return 结果
     */
    @Override
    public int insertBaseMaterialtypeInfo(BaseMaterialtypeInfo baseMaterialtypeInfo)
    {
        baseMaterialtypeInfo.setCreateTime(DateUtils.getNowDate());
        return baseMaterialtypeInfoMapper.insertBaseMaterialtypeInfo(baseMaterialtypeInfo);
    }

    /**
     * 修改物料类型基础信息
     * 
     * @param baseMaterialtypeInfo 物料类型基础信息
     * @return 结果
     */
    @Override
    public int updateBaseMaterialtypeInfo(BaseMaterialtypeInfo baseMaterialtypeInfo)
    {
        baseMaterialtypeInfo.setUpdateTime(DateUtils.getNowDate());
        return baseMaterialtypeInfoMapper.updateBaseMaterialtypeInfo(baseMaterialtypeInfo);
    }

    /**
     * 删除物料类型基础信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBaseMaterialtypeInfoByIds(String ids)
    {
        return baseMaterialtypeInfoMapper.deleteBaseMaterialtypeInfoByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除物料类型基础信息信息
     * 
     * @param objid 物料类型基础信息ID
     * @return 结果
     */
    @Override
    public int deleteBaseMaterialtypeInfoById(Long objid)
    {
        return baseMaterialtypeInfoMapper.deleteBaseMaterialtypeInfoById(objid);
    }

    @Override
    public List<BaseMaterialtypeInfo> selectAddBaseMaterialtypeInfoList() {

        return baseMaterialtypeInfoMapper.selectAddBaseMaterialtypeInfoList();
    }

    @Override
    public List<BaseMaterialtypeInfo> selectEditBaseMaterialtypeInfoList(String materialTypeId) {

        List<BaseMaterialtypeInfo> cbEditMaterialtypeInfoList = baseMaterialtypeInfoMapper.selectAddBaseMaterialtypeInfoList();
        for (BaseMaterialtypeInfo baseMaterialtypeInfo:cbEditMaterialtypeInfoList
             ) {
            if(baseMaterialtypeInfo.getMaterialTypeId().equals(materialTypeId)){
                baseMaterialtypeInfo.setFlag(true);
                break;
            }
        }
        return cbEditMaterialtypeInfoList;
    }
}
