package com.jwipc.finance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jwipc.finance.entity.PaymentPlanSummary;
import com.jwipc.finance.mapper.PaymentPlanSummaryMapper;
import com.jwipc.finance.model.po.PaymentPlanSummaryPO;
import com.jwipc.finance.model.query.PaymentPlanQuery;
import com.jwipc.finance.service.IPaymentPlanSummaryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 对账模块-付款计划汇总表 服务实现类
 * </p>
 *
 * @author 邓京术
 * @since 2025-07-14
 */
@Service
public class PaymentPlanSummaryServiceImpl extends ServiceImpl<PaymentPlanSummaryMapper, PaymentPlanSummary> implements IPaymentPlanSummaryService {

    @Override
    public List<PaymentPlanSummaryPO> findByPaymentPlanSummaryList(Page<PaymentPlanSummary> dbPage, PaymentPlanQuery paymentPlanQuery) {
        //不区分维度
        if (null == paymentPlanQuery.getPaymentType() || "-1".equals(paymentPlanQuery.getPaymentType())) {
            if (dbPage==null){
                return baseMapper.findPageByQueryD(paymentPlanQuery);
            }
            return baseMapper.findPageByQueryD(dbPage,paymentPlanQuery);
        } else {
            if (dbPage==null){
                return baseMapper.findPageByQuery(paymentPlanQuery);
            }
            return baseMapper.findPageByQuery(dbPage,paymentPlanQuery);
        }
    }

    @Override
    public List<PaymentPlanSummary> findPaymentPlanSummaryBySupplier(PaymentPlanQuery paymentPlanQuery) {
        LambdaQueryWrapper<PaymentPlanSummary> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(PaymentPlanSummary::getSupplierCode, paymentPlanQuery.getSupplierCode());
        lambdaQueryWrapper.eq(PaymentPlanSummary::getPaymentPlanId, paymentPlanQuery.getPpId());
        lambdaQueryWrapper.eq(PaymentPlanSummary::getCompanyCode, paymentPlanQuery.getCompanyCode());
        if (null != paymentPlanQuery.getPaymentType()) {
            lambdaQueryWrapper.eq(PaymentPlanSummary::getPaymentType, paymentPlanQuery.getPaymentType());
        }
        List<PaymentPlanSummary> paymentPlanSummary = this.list(lambdaQueryWrapper);
        return paymentPlanSummary;
    }
}
