package com.bonus.material.ma.service.impl;

import java.util.List;
import com.bonus.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.material.ma.mapper.TypeKeeperMapper;
import com.bonus.material.ma.domain.TypeKeeper;
import com.bonus.material.ma.service.ITypeKeeperService;
import org.springframework.util.CollectionUtils;

/**
 * 库管员配置Service业务层处理
 * 
 * @author syruan
 */
@Service
public class TypeKeeperServiceImpl implements ITypeKeeperService {

    @Autowired
    private TypeKeeperMapper typeKeeperMapper;

    /**
     * 查询库管员配置
     * 
     * @param ID 库管员配置主键
     * @return 库管员配置
     */
    @Override
    public TypeKeeper selectTypeKeeperByID(Long ID) {
        return typeKeeperMapper.selectTypeKeeperByID(ID);
    }

    /**
     * 查询库管员配置列表
     * 
     * @param typeKeeper 库管员配置
     * @return 库管员配置
     */
    @Override
    public List<TypeKeeper> selectTypeKeeperList(TypeKeeper typeKeeper) {
        return typeKeeperMapper.selectTypeKeeperList(typeKeeper);
    }

    /**
     * 查询库管员配置列表-并关联查询用户名称
     *
     * @param typeKeeper 查询条件
     */
    @Override
    public List<TypeKeeper> selectTypeKeeperListAndUserName(TypeKeeper typeKeeper) {
        return typeKeeperMapper.selectTypeKeeperListAndUserName(typeKeeper);
    }

    /**
     * 新增库管员配置
     * 
     * @param typeKeepers 库管员配置
     * @return 结果
     */
    @Override
    public int insertTypeKeeper(List<TypeKeeper> typeKeepers) {
        if (CollectionUtils.isEmpty(typeKeepers)) {
            return 0;
        }
        typeKeepers.forEach(typeKeeper -> typeKeeper.setCreateTime(DateUtils.getNowDate()));
        typeKeeperMapper.deleteTypeKeeperByUserIdAndTypeId(typeKeepers);
        return typeKeeperMapper.insertTypeKeeper(typeKeepers);
    }

    /**
     * 修改库管员配置
     * 
     * @param typeKeeper 库管员配置
     * @return 结果
     */
    @Override
    public int updateTypeKeeper(TypeKeeper typeKeeper) {
        typeKeeper.setUpdateTime(DateUtils.getNowDate());
        return typeKeeperMapper.updateTypeKeeper(typeKeeper);
    }

    /**
     * 批量删除库管员配置
     * 
     * @param IDs 需要删除的库管员配置主键
     * @return 结果
     */
    @Override
    public int deleteTypeKeeperByIDs(Long[] IDs) {
        return typeKeeperMapper.deleteTypeKeeperByIDs(IDs);
    }

    /**
     * 根据主键id删除库管员配置信息
     * 
     * @param ID 库管员配置主键
     * @return 结果
     */
    @Override
    public int deleteTypeKeeperByID(Long ID)
    {
        return typeKeeperMapper.deleteTypeKeeperByID(ID);
    }

    /**
     * 根据用户ID和物资类型ID删除库管员配置信息
     *
     * @param typeKeepers
     * @return
     */
    @Override
    public int deleteTypeKeeperByUserIdAndTypeId(List<TypeKeeper> typeKeepers) {
        if (CollectionUtils.isEmpty(typeKeepers)) {
            return 0;
        }
        return typeKeeperMapper.deleteTypeKeeperByUserIdAndTypeId(typeKeepers);
    }
}
