package com.hw.mes.service.impl;

import java.util.List;
import com.hw.common.core.utils.DateUtils;
import com.hw.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hw.mes.mapper.MesBaseMaterialTypeMapper;
import com.hw.mes.domain.MesBaseMaterialType;
import com.hw.mes.service.IMesBaseMaterialTypeService;

import static java.awt.SystemColor.info;

/**
 * 物料类型信息Service业务层处理
 * 
 * @author Yinq
 * @date 2024-01-23
 */
@Service
public class MesBaseMaterialTypeServiceImpl implements IMesBaseMaterialTypeService 
{
    @Autowired
    private MesBaseMaterialTypeMapper mesBaseMaterialTypeMapper;

    /**
     * 查询物料类型信息
     * 
     * @param matrialTypeId 物料类型信息主键
     * @return 物料类型信息
     */
    @Override
    public MesBaseMaterialType selectMesBaseMaterialTypeByMatrialTypeId(Long matrialTypeId)
    {
        return mesBaseMaterialTypeMapper.selectMesBaseMaterialTypeByMatrialTypeId(matrialTypeId);
    }

    /**
     * 查询物料类型信息列表
     * 
     * @param mesBaseMaterialType 物料类型信息
     * @return 物料类型信息
     */
    @Override
    public List<MesBaseMaterialType> selectMesBaseMaterialTypeList(MesBaseMaterialType mesBaseMaterialType)
    {
        return mesBaseMaterialTypeMapper.selectMesBaseMaterialTypeList(mesBaseMaterialType);
    }

    /**
     * 新增物料类型信息
     * 
     * @param mesBaseMaterialType 物料类型信息
     * @return 结果
     */
    @Override
    public int insertMesBaseMaterialType(MesBaseMaterialType mesBaseMaterialType)
    {
        mesBaseMaterialType.setCreateTime(DateUtils.getNowDate());
        MesBaseMaterialType info = mesBaseMaterialTypeMapper.selectMesBaseMaterialTypeByMatrialTypeId(mesBaseMaterialType.getParentId());
        if (StringUtils.isNull(info)){
            mesBaseMaterialType.setAncestors(mesBaseMaterialType.getParentId().toString());
        }else {
            mesBaseMaterialType.setAncestors(info.getAncestors() + "," + mesBaseMaterialType.getParentId());
        }
        return mesBaseMaterialTypeMapper.insertMesBaseMaterialType(mesBaseMaterialType);
    }

    /**
     * 修改物料类型信息
     * 
     * @param mesBaseMaterialType 物料类型信息
     * @return 结果
     */
    @Override
    public int updateMesBaseMaterialType(MesBaseMaterialType mesBaseMaterialType)
    {
        mesBaseMaterialType.setUpdateTime(DateUtils.getNowDate());
        MesBaseMaterialType info = mesBaseMaterialTypeMapper.selectMesBaseMaterialTypeByMatrialTypeId(mesBaseMaterialType.getParentId());
        if (StringUtils.isNull(info)){
            mesBaseMaterialType.setAncestors(mesBaseMaterialType.getParentId().toString());
        }else {
            mesBaseMaterialType.setAncestors(info.getAncestors() + "," + mesBaseMaterialType.getParentId());
        }
        return mesBaseMaterialTypeMapper.updateMesBaseMaterialType(mesBaseMaterialType);
    }

    /**
     * 批量删除物料类型信息
     * 
     * @param matrialTypeIds 需要删除的物料类型信息主键
     * @return 结果
     */
    @Override
    public int deleteMesBaseMaterialTypeByMatrialTypeIds(Long[] matrialTypeIds)
    {
        return mesBaseMaterialTypeMapper.deleteMesBaseMaterialTypeByMatrialTypeIds(matrialTypeIds);
    }

    /**
     * 删除物料类型信息信息
     * 
     * @param matrialTypeId 物料类型信息主键
     * @return 结果
     */
    @Override
    public int deleteMesBaseMaterialTypeByMatrialTypeId(Long matrialTypeId)
    {
        return mesBaseMaterialTypeMapper.deleteMesBaseMaterialTypeByMatrialTypeId(matrialTypeId);
    }
}
