package com.jwipc.finance.service.impl;

import com.google.common.collect.Lists;
import com.jwipc.finance.entity.CostInvoicedApplyDetail;
import com.jwipc.finance.entity.InvoicedApplyDetail;
import com.jwipc.finance.mapper.CostInvoicedApplyDetailMapper;
import com.jwipc.finance.model.po.CreatePcaDetailPO;
import com.jwipc.finance.service.ICostInvoicedApplyDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 对账模块-费用开票申请明细 服务实现类
 * </p>
 *
 * @author shenyang.ou
 * @since 2025-11-06
 */
@Service
public class CostInvoicedApplyDetailServiceImpl extends ServiceImpl<CostInvoicedApplyDetailMapper, CostInvoicedApplyDetail> implements ICostInvoicedApplyDetailService {

    /**
     * 根据开票申请ID获取开票申请明细
     *
     * @param iaId     开票申请单ID
     * @param iaIdList 开票申请单ID集合
     * @return 结果
     */
    @Override
    public List<CostInvoicedApplyDetail> findByInvoiceApplyId(Long iaId, List<Long> iaIdList) {
        if(null == iaId && CollectionUtils.isEmpty(iaIdList)){
            return Lists.newArrayList();
        }

        if(null != iaId && CollectionUtils.isEmpty(iaIdList)){
            iaIdList.add(iaId);
            return baseMapper.findByInvoiceApplyId(iaIdList);
        }

        if(null == iaId && CollectionUtils.isNotEmpty(iaIdList)){
            return baseMapper.findByInvoiceApplyId(iaIdList);
        }

        if(null != iaId && CollectionUtils.isNotEmpty(iaIdList)){
            iaIdList.add(iaId);
        }
        return baseMapper.findByInvoiceApplyId(iaIdList);
    }

    @Override
    public List<CreatePcaDetailPO> queryCodApplyInvoiceById(Long id) {
        return baseMapper.queryCodApplyInvoiceById(id);
    }
}
