package com.jwipc.finance.service.impl;

import com.google.common.collect.Lists;
import com.jwipc.finance.entity.PaymentAdvanceApplyDetail;
import com.jwipc.finance.entity.PaymentCodApplyDetail;
import com.jwipc.finance.mapper.PaymentAdvanceApplyDetailMapper;
import com.jwipc.finance.model.po.CreatePaaDetailPO;
import com.jwipc.finance.model.po.InvoicedApplyPaPO;
import com.jwipc.finance.model.po.PaymentAdvanceApplyDetailPO;
import com.jwipc.finance.model.po.PaymentRecordPO;
import com.jwipc.finance.model.query.PaymentApplyItemQuery;
import com.jwipc.finance.service.IPaymentAdvanceApplyDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 预付款申请明细表 服务实现类
 * </p>
 *
 * @author WT
 * @since 2024-03-08
 */
@Service
        public class PaymentAdvanceApplyDetailServiceImpl extends ServiceImpl<PaymentAdvanceApplyDetailMapper, PaymentAdvanceApplyDetail> implements IPaymentAdvanceApplyDetailService {

    @Override
    public List<CreatePaaDetailPO> findPaaDetailByPaaId(Long applyId) {
        return baseMapper.findPaaDetailByPaaId(applyId);
    }

    @Override
    public List<PaymentAdvanceApplyDetailPO> createGetPoSituationByPoKey(List<String> poKeyList) {
        return baseMapper.createGetPoSituationByPoKey(poKeyList);
    }

    @Override
    public List<PaymentAdvanceApplyDetailPO> findCodApplyByPoKey(List<String> poKeyList) {
        return baseMapper.findCodApplyByPoKey(poKeyList);
    }

    @Override
    public List<PaymentAdvanceApplyDetailPO> editGetPoSituationByApplyId(List<Long> existedItemIdList, List<String> poKeyList) {
        return baseMapper.editGetPoSituationByApplyId(existedItemIdList,poKeyList);
    }

    @Override
    public List<CreatePaaDetailPO> findPaymentDetailByPoCodeList(List<String> poCodeList) {
        return baseMapper.findPaymentDetailByPoCodeList(poCodeList);
    }

    @Override
    public List<PaymentRecordPO> findDetailByPoCode(String poCode) {
        return baseMapper.findDetailByPoCode(poCode);
    }

    @Override
    public List<PaymentAdvanceApplyDetail> findByPaymentDetail(Long applyId) {
        return baseMapper.findByAppIdOrAppNo(applyId, "");
    }

    @Override
    public void updateDetailItemNo(Long applyId) {
        final List<PaymentAdvanceApplyDetail> detailList = baseMapper.findByAppIdOrAppNo(applyId, "");
        List<PaymentAdvanceApplyDetail> updateList = Lists.newArrayList();
        int i = 1;
        for(PaymentAdvanceApplyDetail detail: detailList){
            PaymentAdvanceApplyDetail updateAsd = new PaymentAdvanceApplyDetail();
            updateAsd.setId(detail.getId());
            updateAsd.setItemNo(i+"");
            updateList.add(updateAsd);

            i++;
        }

        this.updateBatchById(updateList);
    }

    @Override
    public void delDetailByApplyId(List<Long> applyIdList) {
        baseMapper.delDetailByApplyId(applyIdList);
    }

    /**
     * 开票申请获取预付款信息
     *
     * @param query 查询条件
     * @return 结果
     */
    @Override
    public List<InvoicedApplyPaPO> provideCreateAdvanceApply(PaymentApplyItemQuery query) {
        return  baseMapper.provideCreateAdvanceApply(query);
    }

    @Override
    public List<InvoicedApplyPaPO> provideCreateAdvanceApplyNew(PaymentApplyItemQuery query,List<String> poKeyList) {
        return  baseMapper.provideCreateAdvanceApplyNew(query,poKeyList);
    }
    @Override
    public List<InvoicedApplyPaPO> provideCreateAdvanceApplyNew1(PaymentApplyItemQuery query,List<String> poKeyList) {
        return  baseMapper.provideCreateAdvanceApplyNew1(query,poKeyList);
    }

    @Override
    public void updateReversedAmount(String paymentChangeNumber, String paymentChangeItemNo, BigDecimal strikePrice) {
        baseMapper.updateReversedAmount(paymentChangeNumber,paymentChangeItemNo,strikePrice);
    }


}
