package com.fjhx.sale.service.quotation.impl;

import com.fjhx.sale.entity.quotation.po.QuotationProduct;
import com.fjhx.sale.mapper.quotation.QuotationProductMapper;
import com.fjhx.sale.service.quotation.QuotationProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.sale.entity.quotation.vo.QuotationProductVo;
import com.fjhx.sale.entity.quotation.dto.QuotationProductSelectDto;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.fjhx.sale.entity.quotation.dto.QuotationProductDto;
import cn.hutool.core.bean.BeanUtil;


/**
 * <p>
 * 商品-报价单关联表 服务实现类
 * </p>
 *
 * @author
 * @since 2023-04-14
 */
@Service
public class QuotationProductServiceImpl extends ServiceImpl<QuotationProductMapper, QuotationProduct> implements QuotationProductService {

    @Override
    public Page<QuotationProductVo> getPage(QuotationProductSelectDto dto) {
        IWrapper<QuotationProduct> wrapper = getWrapper();
        wrapper.orderByDesc("qp", QuotationProduct::getId);
        Page<QuotationProductVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

    @Override
    public QuotationProductVo detail(Long id) {
        QuotationProduct QuotationProduct = this.getById(id);
        QuotationProductVo result = BeanUtil.toBean(QuotationProduct, QuotationProductVo.class);
        return result;
    }

    @Override
    public void add(QuotationProductDto quotationProductDto) {
        this.save(quotationProductDto);
    }

    @Override
    public void edit(QuotationProductDto quotationProductDto) {
        this.updateById(quotationProductDto);
    }

    @Override
    public void delete(Long id) {
        this.removeById(id);
    }

}
