package com.jwipc.finance.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jwipc.finance.entity.AccountStatement;
import com.jwipc.finance.entity.CompanyInvoicedReceipt;
import com.jwipc.finance.mapper.CompanyInvoicedReceiptMapper;
import com.jwipc.finance.model.po.CompanyInvoicedReceiptPO;
import com.jwipc.finance.model.query.InvoicedDetailQuery;
import com.jwipc.finance.service.ICompanyInvoicedReceiptService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 对账模块-费用关联发票明细 服务实现类
 * </p>
 *
 * @author shenyang.ou
 * @since 2025-11-05
 */
@Service
public class CompanyInvoicedReceiptServiceImpl extends ServiceImpl<CompanyInvoicedReceiptMapper, CompanyInvoicedReceipt> implements ICompanyInvoicedReceiptService {
    /**
     * 根据开票申请单ID获取关联发票数据
     *
     * @param iaId 开票申请单ID
     * @return 关联发票数据
     */
    @Override
    public List<CompanyInvoicedReceiptPO> getInvoiceReceiptListByIaId(Long iaId) {
        return baseMapper.getInvoiceReceiptListByIaId(iaId);
    }

    /**
     * 根据开票申请id和发票号码判断系统中是否已经存在
     *
     * @param iaId          开票申请id
     * @param invoiceNumber 发票号码
     * @return 结果
     */
    @Override
    public CompanyInvoicedReceipt getExitDataByIaIdAndInvoiceNumber(Long iaId, String invoiceNumber) {
        return baseMapper.getExitDataByIaIdAndInvoiceNumber(iaId, invoiceNumber);
    }

    /**
     * 根据开票申请id和数电发票号码判断系统中是否已经存在
     *
     * @param iaId                  开票申请id
     * @param electronInvoiceNumber 数电发票号码
     * @return 结果
     */
    @Override
    public CompanyInvoicedReceipt getExitDataByIaIdAndElectronInvoiceNumber(Long iaId, String electronInvoiceNumber) {
        return baseMapper.getExitDataByIaIdAndElectronInvoiceNumber(iaId, electronInvoiceNumber);
    }

    @Override
    public List<CompanyInvoicedReceiptPO> findPageByQuery(Page<AccountStatement> dbPage, InvoicedDetailQuery query) {
        if (dbPage==null){
            return baseMapper.findPageByQuery(query);
        }
        return baseMapper.findPageByQuery(dbPage,query);
    }
}
