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.TypeRepairMapper;
import com.bonus.material.ma.domain.TypeRepair;
import com.bonus.material.ma.service.ITypeRepairService;
import org.springframework.util.CollectionUtils;

/**
 * 维修班机具配置Service业务层处理
 * 
 * @author xsheng
 * @date 2024-09-27
 */
@Service
public class TypeRepairServiceImpl implements ITypeRepairService {

    @Autowired
    private TypeRepairMapper typeRepairMapper;

    /**
     * 查询维修班机具配置
     * 
     * @param ID 维修班机具配置主键
     * @return 维修班机具配置
     */
    @Override
    public TypeRepair selectTypeRepairByID(Long ID)
    {
        return typeRepairMapper.selectTypeRepairByID(ID);
    }

    /**
     * 查询维修班机具配置列表
     * 
     * @param typeRepair 维修班机具配置
     * @return 维修班机具配置
     */
    @Override
    public List<TypeRepair> selectTypeRepairList(TypeRepair typeRepair)
    {
        return typeRepairMapper.selectTypeRepairList(typeRepair);
    }

    /**
     * 查询配置列表并关联查询用户姓名
     *
     * @param typeRepair
     */
    @Override
    public List<TypeRepair> selectTypeRepairListAndUserName(TypeRepair typeRepair) {
        return typeRepairMapper.selectTypeRepairListAndUserName(typeRepair);
    }

    /**
     * 新增维修班机具配置
     * 
     * @param typeRepairs 维修班机具配置
     * @return 结果
     */
    @Override
    public int insertTypeRepair(List<TypeRepair> typeRepairs)
    {
        if (CollectionUtils.isEmpty(typeRepairs)) {
            return 0;
        }
        typeRepairs.forEach(typeRepair -> typeRepair.setCreateTime(DateUtils.getNowDate()));
        typeRepairMapper.deleteTypeRepairByUserIdAndTypeId(typeRepairs);
        return typeRepairMapper.insertTypeRepair(typeRepairs);
    }

    /**
     * 修改维修班机具配置
     * 
     * @param typeRepair 维修班机具配置
     * @return 结果
     */
    @Override
    public int updateTypeRepair(TypeRepair typeRepair)
    {
        typeRepair.setUpdateTime(DateUtils.getNowDate());
        return typeRepairMapper.updateTypeRepair(typeRepair);
    }

    /**
     * 批量删除维修班机具配置
     * 
     * @param IDs 需要删除的维修班机具配置主键
     * @return 结果
     */
    @Override
    public int deleteTypeRepairByIDs(Long[] IDs)
    {
        return typeRepairMapper.deleteTypeRepairByIDs(IDs);
    }

    /**
     * 删除维修班机具配置信息
     * 
     * @param ID 维修班机具配置主键
     * @return 结果
     */
    @Override
    public int deleteTypeRepairByID(Long ID)
    {
        return typeRepairMapper.deleteTypeRepairByID(ID);
    }

    /**
     * 根据用户id和类型id删除配置信息
     *
     * @param typeRepairs
     */
    @Override
    public int deleteTypeRepairByUserIdAndTypeId(List<TypeRepair> typeRepairs) {
        return typeRepairMapper.deleteTypeRepairByUserIdAndTypeId(typeRepairs);
    }
}
