package cn.iocoder.yudao.module.order.service.orderExceptionChannelPrice;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.service.AbstractService;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.module.order.convert.orderExceptionChannelPrice.OrderExceptionChannelPriceConvert;
import cn.iocoder.yudao.module.order.dal.dataobject.orderExceptionChannelPrice.OrderExceptionChannelPriceDO;
import cn.iocoder.yudao.module.order.dal.mysql.orderExceptionChannelPrice.OrderExceptionChannelPriceMapper;
import cn.iocoder.yudao.module.order.vo.orderExceptionChannelPrice.OrderExceptionChannelPriceCreateReqVO;
import cn.iocoder.yudao.module.order.vo.orderExceptionChannelPrice.OrderExceptionChannelPriceQueryVO;
import cn.iocoder.yudao.module.order.vo.orderExceptionChannelPrice.OrderExceptionChannelPriceUpdateReqVO;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * 不可出渠道异常商品价格 Service 实现类
 *
 * @author 系统管理员
 */
@Service
@Validated
public class OrderExceptionChannelPriceServiceImpl extends AbstractService<OrderExceptionChannelPriceMapper, OrderExceptionChannelPriceDO> implements OrderExceptionChannelPriceService {

    @Resource
    private OrderExceptionChannelPriceMapper exceptionChannelPriceMapper;

    @Override
    public Long createExceptionChannelPrice(OrderExceptionChannelPriceCreateReqVO createReqVO) {
        // 插入
        OrderExceptionChannelPriceDO exceptionChannelPrice = OrderExceptionChannelPriceConvert.INSTANCE.convert(createReqVO);
        exceptionChannelPriceMapper.insert(exceptionChannelPrice);
        // 返回
        return exceptionChannelPrice.getId();
    }

    @Override
    public void updateExceptionChannelPrice(OrderExceptionChannelPriceUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateExceptionChannelPriceExists(updateReqVO.getId());
        // 更新
        OrderExceptionChannelPriceDO updateObj = OrderExceptionChannelPriceConvert.INSTANCE.convert(updateReqVO);
        exceptionChannelPriceMapper.updateById(updateObj);
    }

    @Override
    public void deleteExceptionChannelPrice(Long id) {
        // 校验存在
        this.validateExceptionChannelPriceExists(id);
        // 删除
        exceptionChannelPriceMapper.deleteById(id);
    }

    private void validateExceptionChannelPriceExists(Long id) {
        if (exceptionChannelPriceMapper.selectById(id) == null) {

        }
    }

    @Override
    public OrderExceptionChannelPriceDO getExceptionChannelPrice(Long id) {
        return exceptionChannelPriceMapper.selectById(id);
    }

    @Override
    public List<OrderExceptionChannelPriceDO> getExceptionChannelPriceList(Collection<Long> ids) {
        return exceptionChannelPriceMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<OrderExceptionChannelPriceDO> getExceptionChannelPricePage(OrderExceptionChannelPriceQueryVO query, PageVO page) {
        return exceptionChannelPriceMapper.selectPage(page, query);
    }

    @Override
    public List<OrderExceptionChannelPriceDO> getExceptionChannelPriceList(OrderExceptionChannelPriceQueryVO query) {
        return exceptionChannelPriceMapper.selectList(query);
    }
}
