package com.fjhx.service.contract.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.base.StorageBaseEntity;
import com.fjhx.entity.contract.ContractEnclosure;
import com.fjhx.mapper.contract.ContractEnclosureMapper;
import com.fjhx.params.contract.ContractEnclosureVo;
import com.fjhx.service.contract.ContractEnclosureService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 合同附件 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-10-21
 */
@Service
public class ContractEnclosureServiceImpl extends ServiceImpl<ContractEnclosureMapper, ContractEnclosure> implements ContractEnclosureService {

    @Override
    public List<ContractEnclosure> getPage(ContractEnclosure contractEnclosure) {
        LambdaQueryWrapper<ContractEnclosure> wrapper = Wrappers.lambdaQuery();
        wrapper.orderByDesc(StorageBaseEntity::getId)
                .eq(ContractEnclosure::getContractId, contractEnclosure.getContractId())
                .eq(ContractEnclosure::getType, contractEnclosure.getType());

        return list(wrapper);
    }

    @Override
    public void add(ContractEnclosureVo contractEnclosureVo) {
        save(contractEnclosureVo);
    }

    @Override
    public void edit(ContractEnclosureVo contractEnclosureVo) {
        updateById(contractEnclosureVo);
    }

    @Override
    public void delete(ContractEnclosureVo contractEnclosureVo) {
        removeById(contractEnclosureVo.getId());
    }

}
