package com.xtd.project.system.service.impl;

import java.util.List;

import com.xtd.common.exception.BaseException;
import com.xtd.common.utils.DateUtils;
import com.xtd.framework.aspectj.lang.annotation.DataScope;
import com.xtd.project.system.domain.vo.SelectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xtd.project.system.mapper.DbSupplierMapper;
import com.xtd.project.system.domain.DbSupplier;
import com.xtd.project.system.service.IDbSupplierService;

/**
 * 供应商Service业务层处理
 *
 * @author xtd
 * @date 2020-04-07
 */
@Service
public class DbSupplierServiceImpl implements IDbSupplierService
{
    @Autowired
    private DbSupplierMapper dbSupplierMapper;

    /**
     * 查询供应商
     *
     * @param sId 供应商ID
     * @return 供应商
     */
    @Override
    public DbSupplier selectDbSupplierById(Long sId)
    {
        return dbSupplierMapper.selectDbSupplierById(sId);
    }

    /**
     * 查询供应商列表
     *
     * @param dbSupplier 供应商
     * @return 供应商
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<DbSupplier> selectDbSupplierList(DbSupplier dbSupplier)
    {
        return dbSupplierMapper.selectDbSupplierList(dbSupplier);
    }

    /**
     * 新增供应商
     *
     * @param dbSupplier 供应商
     * @return 结果
     */
    @Override
    public int insertDbSupplier(DbSupplier dbSupplier)
    {
        dbSupplier.setCreateTime(DateUtils.getNowDate());
        return dbSupplierMapper.insertDbSupplier(dbSupplier);
    }

    /**
     * 修改供应商
     *
     * @param dbSupplier 供应商
     * @return 结果
     */
    @Override
    public int updateDbSupplier(DbSupplier dbSupplier)
    {
        dbSupplier.setUpdateTime(DateUtils.getNowDate());
        return dbSupplierMapper.updateDbSupplier(dbSupplier);
    }

    /**
     * 批量删除供应商
     *
     * @param sIds 需要删除的供应商ID
     * @return 结果
     */
    @Override
    public int deleteDbSupplierByIds(Long[] sIds)
    {
        List<Long> lis = dbSupplierMapper.deleteCheck(sIds);
        if(lis.size()>0) {
            throw new BaseException("200", "数据被引用无法删除!");
        }
        int i = dbSupplierMapper.deleteDbSupplierByIds(sIds);
        return i;
    }

    /**
     * 删除供应商信息
     *
     * @param sId 供应商ID
     * @return 结果
     */
    @Override
    public int deleteDbSupplierById(Long sId)
    {
        return dbSupplierMapper.deleteDbSupplierById(sId);
    }

    @Override
    public List<SelectVo> selectList() {
        List<SelectVo> list= dbSupplierMapper.selectList();
        return list;
    }
}
