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

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fjhx.sale.entity.quotation.po.QuotationPay;
import com.fjhx.sale.mapper.quotation.QuotationPayMapper;
import com.fjhx.sale.service.quotation.QuotationPayService;
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.QuotationPayVo;
import com.fjhx.sale.entity.quotation.dto.QuotationPaySelectDto;
import com.fjhx.sale.entity.quotation.dto.QuotationPayDto;
import cn.hutool.core.bean.BeanUtil;


/**
 * <p>
 * 报价 -收费项目表 服务实现类
 * </p>
 *
 * @author
 * @since 2023-04-14
 */
@Service
public class QuotationPayServiceImpl extends ServiceImpl<QuotationPayMapper, QuotationPay> implements QuotationPayService {

    @Override
    public Page<QuotationPayVo> getPage(QuotationPaySelectDto dto) {
        LambdaQueryWrapper<QuotationPay> wrapper = Wrappers.<QuotationPay>lambdaQuery();
        wrapper.orderByDesc(QuotationPay::getCreateTime);
        wrapper.like(ObjectUtil.isNotEmpty(dto.getPayName()),QuotationPay::getPayName,dto.getPayName());
        Page<QuotationPayVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

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

    /**
     * 报价表新增
     */
    @Override
    public void add(QuotationPayDto quotationPayDto) {
        this.save(quotationPayDto);
    }

    @Override
    public void edit(QuotationPayDto quotationPayDto) {
        this.updateById(quotationPayDto);
    }

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

}
