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

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fjhx.sale.entity.contract.po.ContractBudget;
import com.fjhx.sale.mapper.contract.ContractBudgetMapper;
import com.fjhx.sale.service.contract.ContractBudgetService;
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.contract.vo.ContractBudgetVo;
import com.fjhx.sale.entity.contract.dto.ContractBudgetSelectDto;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.fjhx.sale.entity.contract.dto.ContractBudgetDto;
import cn.hutool.core.bean.BeanUtil;


/**
 * <p>
 * 外销合同--预算 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-05-17
 */
@Service
public class ContractBudgetServiceImpl extends ServiceImpl<ContractBudgetMapper, ContractBudget> implements ContractBudgetService {

    @Override
    public Page<ContractBudgetVo> getPage(ContractBudgetSelectDto dto) {
        IWrapper<ContractBudget> wrapper = getWrapper();
        wrapper.orderByDesc("cb", ContractBudget::getId);
        Page<ContractBudgetVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

    @Override
    public ContractBudgetVo detail(Long id) {
        ContractBudget ContractBudget = this.getOne(Wrappers.<ContractBudget>query().lambda().eq(com.fjhx.sale.entity.contract.po.ContractBudget::getContractId,id));
        ContractBudgetVo result = BeanUtil.toBean(ContractBudget, ContractBudgetVo.class);
        return result;
    }

    @Override
    public void add(ContractBudgetDto contractBudgetDto) {
        this.save(contractBudgetDto);
    }

    @Override
    public void edit(ContractBudgetDto contractBudgetDto) {
        this.updateById(contractBudgetDto);
    }

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

}
