package com.zd.airbottle.service.impl;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import cn.hutool.core.collection.CollUtil;
import com.zd.common.core.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zd.airbottle.mapper.QpSpecificationDetailMapper;
import com.zd.airbottle.domain.QpSpecificationDetail;
import com.zd.airbottle.service.IQpSpecificationDetailService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 气瓶规格详情Service业务层处理
 *
 * @author zd
 * @date 2022-05-17
 */
@Service
public class QpSpecificationDetailServiceImpl implements IQpSpecificationDetailService {
    @Autowired
    private QpSpecificationDetailMapper qpSpecificationDetailMapper;

    /**
     * 查询气瓶规格详情
     *
     * @param id 气瓶规格详情主键
     * @return 气瓶规格详情
     */
    @Override
    public QpSpecificationDetail selectQpSpecificationDetailById(Long id) {
        return qpSpecificationDetailMapper.selectQpSpecificationDetailById(id);
    }

    /**
     * 根据ID集合查询气瓶规格详情
     *
     * @param ids 气瓶规格详情主键
     * @return 气瓶规格详情
     */
    @Override
    public List<QpSpecificationDetail> getByIds(List<Long> ids) {
        return qpSpecificationDetailMapper.getByIds(ids);
    }

    /**
     * 查询气瓶规格详情列表
     *
     * @param qpSpecificationDetail 气瓶规格详情
     * @return 气瓶规格详情
     */
    @Override
    public List<QpSpecificationDetail> selectQpSpecificationDetailList(QpSpecificationDetail qpSpecificationDetail) {
        return qpSpecificationDetailMapper.selectQpSpecificationDetailList(qpSpecificationDetail);
    }

    /**
     * 新增气瓶规格详情
     *
     * @param qpSpecificationDetail 气瓶规格详情
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertQpSpecificationDetail(QpSpecificationDetail qpSpecificationDetail) {
        return qpSpecificationDetailMapper.insertQpSpecificationDetail(qpSpecificationDetail);
    }

    /**
     * 修改气瓶规格详情
     *
     * @param qpSpecificationDetail 气瓶规格详情
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateQpSpecificationDetail(QpSpecificationDetail qpSpecificationDetail) {
        return qpSpecificationDetailMapper.updateQpSpecificationDetail(qpSpecificationDetail);
    }

    /**
     * 批量删除气瓶规格详情
     *
     * @param ids 需要删除的气瓶规格详情主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteQpSpecificationDetailByIds(Long[] ids) {
        return qpSpecificationDetailMapper.deleteQpSpecificationDetailByIds(ids);
    }

    /**
     * 删除气瓶规格详情信息
     *
     * @param id 气瓶规格详情主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteQpSpecificationDetailById(Long id) {
        return qpSpecificationDetailMapper.deleteQpSpecificationDetailById(id);
    }

    /**
     * 根据气瓶规格ID集合查询气瓶规格详情
     *
     * @param specIds 气瓶规格ID
     * @return 气瓶规格详情集合
     */
    @Override
    public List<QpSpecificationDetail> listBySpecIds(List<Long> specIds) {
        if (CollUtil.isEmpty(specIds))
            return Collections.emptyList();
        return qpSpecificationDetailMapper.listBySpecIds(specIds);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteBySpecIds(Long[] specIds) {
        if (CollUtil.isEmpty(Arrays.asList(specIds))) throw new ServiceException("气瓶配置ID数组为空");
        return qpSpecificationDetailMapper.deleteBySpecIds(specIds);
    }
}
