package com.zd.airbottle.service.impl;

import java.util.Date;
import java.util.List;

import com.zd.common.core.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zd.airbottle.mapper.QpSupplierCredentialsMapper;
import com.zd.airbottle.domain.QpSupplierCredentials;
import com.zd.airbottle.service.IQpSupplierCredentialsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 供应商证件Service业务层处理
 *
 * @author zd
 */
@Service
public class QpSupplierCredentialsServiceImpl implements IQpSupplierCredentialsService {
    @Autowired
    private QpSupplierCredentialsMapper qpSupplierCredentialsMapper;

    /**
     * 查询供应商证件
     *
     * @param id 供应商证件主键
     * @return 供应商证件
     */
    @Override
    public QpSupplierCredentials selectQpSupplierCredentialsById(Long id) {
        return qpSupplierCredentialsMapper.selectQpSupplierCredentialsById(id);
    }

    /**
     * 查询供应商证件列表
     *
     * @param qpSupplierCredentials 供应商证件
     * @return 供应商证件
     */
    @Override
    public List<QpSupplierCredentials> selectQpSupplierCredentialsList(QpSupplierCredentials qpSupplierCredentials) {
        return qpSupplierCredentialsMapper.selectQpSupplierCredentialsList(qpSupplierCredentials);
    }

    @Override
    public List<QpSupplierCredentials> selectQpSupplierCredentialsListBySupplierIds(Long[] supplierIds) {
        return qpSupplierCredentialsMapper.selectQpSupplierCredentialsListBySupplierIds(supplierIds);
    }

    /**
     * 新增供应商证件
     *
     * @param qpSupplierCredentials 供应商证件
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertQpSupplierCredentials(QpSupplierCredentials qpSupplierCredentials) {
        Date endTime = qpSupplierCredentials.getEndTime();
        Date startTime = qpSupplierCredentials.getStartTime();
        if (startTime!=null && endTime!=null && startTime.getTime()>endTime.getTime()){
            throw new ServiceException("开始时间不能大于使用时间");
        }
        return qpSupplierCredentialsMapper.insertQpSupplierCredentials(qpSupplierCredentials);
    }

    /**
     * 修改供应商证件
     *
     * @param qpSupplierCredentials 供应商证件
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateQpSupplierCredentials(QpSupplierCredentials qpSupplierCredentials) {
        Date endTime = qpSupplierCredentials.getEndTime();
        Date startTime = qpSupplierCredentials.getStartTime();
        if (startTime!=null && endTime!=null && startTime.getTime()>endTime.getTime()){
            throw new ServiceException("开始时间不能大于使用时间");
        }
        return qpSupplierCredentialsMapper.updateQpSupplierCredentials(qpSupplierCredentials);
    }

    /**
     * 批量删除供应商证件
     *
     * @param ids 需要删除的供应商证件主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteQpSupplierCredentialsByIds(Long[] ids) {
        return qpSupplierCredentialsMapper.deleteQpSupplierCredentialsByIds(ids);
    }

    /**
     * 删除供应商证件信息
     *
     * @param id 供应商证件主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteQpSupplierCredentialsById(Long id) {
        return qpSupplierCredentialsMapper.deleteQpSupplierCredentialsById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchInsertQpSupplierCredentials(List<QpSupplierCredentials> qpSupplierCredentials) {
        return qpSupplierCredentialsMapper.batchInsertQpSupplierCredentials(qpSupplierCredentials);
    }
}
