package com.jwipc.finance.logic.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson2.JSONArray;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.jwipc.api.constant.RestCode;
import com.jwipc.api.dto.SapResposeBody;
import com.jwipc.exception.DaoException;
import com.jwipc.finance.constant.AccountStatementSapClient;
import com.jwipc.finance.convert.*;
import com.jwipc.finance.dto.*;
import com.jwipc.finance.entity.*;
import com.jwipc.finance.logic.CustomsDeclarationLogic;
import com.jwipc.finance.logic.PaymentMatchingLogic;
import com.jwipc.finance.logic.ReceiptVoucherLogic;
import com.jwipc.finance.model.po.*;
import com.jwipc.finance.model.query.CustomsDeclarationQuery;
import com.jwipc.finance.model.query.InvoicedApplyQuery;
import com.jwipc.finance.model.query.PaymentMatchingQuery;
import com.jwipc.finance.service.*;
import com.jwipc.order.clent.dto.PurchaseOrderDTO;
import com.jwipc.order.client.PurchaseOrderClient;
import com.jwipc.page.PageUtil;
import com.jwipc.page.PageView;
import com.jwipc.security.LoginUtil;
import com.jwipc.supplier.clent.dto.SupplierDTO;
import com.jwipc.supplier.client.SupplierClient;
import com.jwipc.sys.client.DictClient;
import com.jwipc.sys.client.SequenceClient;
import com.jwipc.sys.client.dto.DictDTO;
import com.jwipc.sys.client.dto.UserDTO;
import com.jwipc.sys.dto.BusinessAttachmentDTO;
import com.jwipc.sys.dto.KingdeeInvoiceCloudImageDTO;
import com.jwipc.sys.entity.BusinessAttachment;
import com.jwipc.sys.logic.BusinessAttachmentLogic;
import com.jwipc.sys.logic.KingdeeImageLogic;
import com.jwipc.sys.service.IBusinessAttachmentService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import static com.baomidou.dynamic.datasource.support.DdConstants.SLAVE;

/**
 * @author shenyang.ou
 * @date 2025/10/22 15:29
 * @desc
 */
@Service
@RequiredArgsConstructor
public class PaymentMatchingLogicImpl implements PaymentMatchingLogic {
    private final IPaymentMatchingService paymentMatchingService;
    private final BusinessAttachmentLogic businessAttachmentLogic;
    private final KingdeeImageLogic kingdeeImageLogic;
    private final ICustomsDeclarationDetailService customsDeclarationDetailService;
    private final IReceiveVoucherService receiveVoucherService;
    private final IPaymentMatchingApproveService paymentMatchingApproveService;
    private final IPaymentMatchingCustomsDeclarationRelationService paymentMatchingCustomsDeclarationRelationService;
    private final IPaymentMatchingReceiveVoucherRelationService paymentMatchingReceiveVoucherRelationService;
    private final PaymentMatchingConvert paymentMatchingConvert;
    private final PaymentMatchingCustomsDeclarationRelationConvert paymentMatchingCustomsDeclarationRelationConvert;
    private final PaymentMatchingReceiveVoucherRelationConvert paymentMatchingReceiveVoucherRelationConvert;
    private final SequenceClient sequenceClient;
    private final DictClient dictClient;
    private final PurchaseOrderClient purchaseOrderClient;
    private final SupplierClient supplierClient;
    private final IBusinessAttachmentService businessAttachmentService;
    private final AccountStatementSapClient accountStatementSapClient;
    private final ReceiptVoucherLogic receiptVoucherLogic;
    @Override
    public PageView findByPage(PaymentMatchingQuery query) {
        final Page<PaymentMatching> dbPage = PageUtil.toPage(query);
        List<PaymentMatchingPO> priceInfoAuditPOS = paymentMatchingService.findPageByQuery(dbPage, query);
        List<PaymentMatchingDTO> priceInfoAuditDTOS = paymentMatchingConvert.po2DTOList(priceInfoAuditPOS);

        //加载附件
        if (CollUtil.isNotEmpty(priceInfoAuditDTOS)){
            final Set<Long> ids = priceInfoAuditDTOS.stream().map(PaymentMatchingDTO::getId).collect(Collectors.toSet());
            final List<BusinessAttachment> businessAttachmentList = businessAttachmentService.list(new LambdaQueryWrapper<BusinessAttachment>()
                    .in(BusinessAttachment::getBusinessId, ids).eq(BusinessAttachment::getBusinessTypeCode, "payment_matching"));
            final Map<Long, List<Long>> businessAttachmentMap = businessAttachmentList.stream().collect(
                    Collectors.groupingBy(BusinessAttachment::getBusinessId,
                            Collectors.mapping(BusinessAttachment::getFileId, Collectors.toList())));
            for (PaymentMatchingDTO dto : priceInfoAuditDTOS) {
                if (Objects.nonNull(businessAttachmentMap.get(dto.getId()))) {
                    dto.setAttachmentFiles("1");
                }
            }
        }


        return PageUtil.getPV(priceInfoAuditDTOS, dbPage.getTotal());
    }

    @Override
    @DS(SLAVE)
    @Transactional
    public void saveOrUpdate(PaymentMatchingParamDTO param) {
        //2026-01-13 创建暂存时，判断物料凭证是否齐全，保存时，有多个关联单号时，页面没有全部勾选需要校验
        if (param.getId() == null) {
            param.setCode(sequenceClient.createSequenceNo("payment_matching_no"));
            param.setStatus(1);
            param.setCreateTime(LocalDateTime.now());
            param.setCreateUser(LoginUtil.getUserId());
        } else {
            param.setUpdateTime(LocalDateTime.now());
            param.setUpdateUser(LoginUtil.getUserId());
            //删除明细
            paymentMatchingCustomsDeclarationRelationService.remove(Wrappers.lambdaQuery(PaymentMatchingCustomsDeclarationRelation.class).eq(PaymentMatchingCustomsDeclarationRelation::getMainId,param.getId()));
            paymentMatchingReceiveVoucherRelationService.remove(Wrappers.lambdaQuery(PaymentMatchingReceiveVoucherRelation.class).eq(PaymentMatchingReceiveVoucherRelation::getMainId,param.getId()));
        }
        if (StrUtil.isEmpty(param.getRemark())&&StrUtil.isNotEmpty(param.getCustomsDeclarationDetailCode())){
            param.setRemark(param.getCustomsDeclarationDetailCode()+"_"+param.getSupplierCode()+"_报关单");
        }
        //保存主数据
        PaymentMatching priceInfoAudit = paymentMatchingConvert.DTO2Entity(param);
        paymentMatchingService.saveOrUpdate(priceInfoAudit);
        final List<PaymentMatchingCustomsDeclarationRelationDTO> customsDeclarationRelationList = param.getCustomsDeclarationRelationList();
        AtomicInteger index = new AtomicInteger(1);
        customsDeclarationRelationList.forEach(priceInfoAuditDetailDTO -> {
            priceInfoAuditDetailDTO.setId(null);
            priceInfoAuditDetailDTO.setMainCode(priceInfoAudit.getCode());
            priceInfoAuditDetailDTO.setMainId(priceInfoAudit.getId());
            index.getAndIncrement();
        });
        paymentMatchingCustomsDeclarationRelationService.saveBatch(paymentMatchingCustomsDeclarationRelationConvert.dto2EntityList(customsDeclarationRelationList));

        final List<PaymentMatchingReceiveVoucherRelationDTO> receiveVoucherRelationList = param.getReceiveVoucherRelationList();
        AtomicInteger index1 = new AtomicInteger(1);
        receiveVoucherRelationList.forEach(priceInfoAuditDetailDTO -> {
            priceInfoAuditDetailDTO.setId(null);
            priceInfoAuditDetailDTO.setMainCode(priceInfoAudit.getCode());
            priceInfoAuditDetailDTO.setMainId(priceInfoAudit.getId());
            index1.getAndIncrement();
        });

        // 校验对账单明细的出入库明细数据
        List<Long> rvIdList = Lists.newArrayList();
        for(PaymentMatchingReceiveVoucherRelationDTO asd: receiveVoucherRelationList){
            rvIdList.add(asd.getReceiveVoucherId());
        }
        //物料凭证校验
        final String checkResult = receiptVoucherLogic.checkConsultVoucher(rvIdList,priceInfoAudit.getSupplierCode(), null);
        if(StringUtils.isNotEmpty(checkResult)){
            throw new DaoException(checkResult);
        }
        paymentMatchingReceiveVoucherRelationService.saveBatch(paymentMatchingReceiveVoucherRelationConvert.dto2EntityList(receiveVoucherRelationList));

        // 附件关系
//        businessAttachmentService.remove(Wrappers.lambdaQuery(BusinessAttachment.class).eq(BusinessAttachment::getBusinessId, priceInfoAudit.getId()));
//        List<BusinessAttachmentDTO> businessAttachmentDTOList = param.getBusinessAttachmentDTOList();
//        businessAttachmentDTOList.forEach(item -> {
//            item.setId(null);
//            item.setBusinessId(priceInfoAudit.getId());
//            item.setBusinessTypeCode("payment_matching");
//        });
//        businessAttachmentLogic.saveAttachment(businessAttachmentDTOList);


//        //影像化
//        this.toImg(priceInfoAudit.getId());
    }


    /**
     * 影像化
     *
     * @param id ID
     */
    @Override
    public void toImg(Long id) {
        PaymentMatching invoicedApply = paymentMatchingService.getById(id);
        //影像化
        List<BusinessAttachmentDTO> accountStatementAttachments = businessAttachmentLogic.getListByBusinessId(id);
        if (CollUtil.isNotEmpty(accountStatementAttachments)) {
            KingdeeInvoiceCloudImageDTO kingdeeInvoiceCloudImageDTO = new KingdeeInvoiceCloudImageDTO();
            kingdeeInvoiceCloudImageDTO.setImageCode(StrUtil.isNotEmpty(invoicedApply.getImgCode()) ? invoicedApply.getImgCode() : sequenceClient.createSequenceNo("image_code"));
            if (CollUtil.isNotEmpty(accountStatementAttachments)) {
                kingdeeInvoiceCloudImageDTO.setBusinessAttachmentList(accountStatementAttachments);
                KingdeeInvoiceCloudImageDTO result = kingdeeImageLogic.pushImage(kingdeeInvoiceCloudImageDTO);
                paymentMatchingService.update(new LambdaUpdateWrapper<PaymentMatching>()
                        .set(PaymentMatching::getImgCode, result.getImageCode())
                        .set(PaymentMatching::getImgTime, LocalDateTime.now())
                        .set(PaymentMatching::getImgUserId, LoginUtil.getUserId())
                        .eq(PaymentMatching::getId, id));
            }

        }
    }

    /**
     * 删除影像化
     *
     * @param id ID
     */
    @Override
    public void deleteImg(Long id) {
        //删除影像化
//        CostMatching invoicedApply = costMatchingService.getById(id);
        List<BusinessAttachment> businessAttachments = businessAttachmentService.list(new LambdaQueryWrapper<BusinessAttachment>().eq(BusinessAttachment::getBusinessId, id));
        if (CollUtil.isNotEmpty(businessAttachments)) {
            //过滤出accountStatementAttachments中存在imageCode的数据
            List<BusinessAttachment> accountStatementAttachmentsImageCode = businessAttachments.stream().filter(accountStatementAttachment -> StringUtils.isNotEmpty(accountStatementAttachment.getImageCode())).toList();
            if (CollUtil.isNotEmpty(accountStatementAttachmentsImageCode)) {
                KingdeeInvoiceCloudImageDTO kingdeeInvoiceCloudImageDTO = new KingdeeInvoiceCloudImageDTO();
                kingdeeInvoiceCloudImageDTO.setImageCode(accountStatementAttachmentsImageCode.get(0).getImageCode());
                kingdeeImageLogic.deleteAllImage(kingdeeInvoiceCloudImageDTO);
                paymentMatchingService.update(new LambdaUpdateWrapper<PaymentMatching>()
//                        .set(InvoicedApply::getImgCode,null)
                        .set(PaymentMatching::getImgTime, null)
                        .set(PaymentMatching::getImgUserId, null)
                        .eq(PaymentMatching::getId, id));
            }
        }
    }

    @Override
    @Transactional
    public void remove(Long id) {
        paymentMatchingService.update(Wrappers.lambdaUpdate(PaymentMatching.class).set(PaymentMatching::getDeleteFlag,1).eq(PaymentMatching::getId,id));
        //删除明细
        paymentMatchingCustomsDeclarationRelationService.update(Wrappers.lambdaUpdate(PaymentMatchingCustomsDeclarationRelation.class).set(PaymentMatchingCustomsDeclarationRelation::getDeleteFlag,1).eq(PaymentMatchingCustomsDeclarationRelation::getMainId,id));
        paymentMatchingReceiveVoucherRelationService.update(Wrappers.lambdaUpdate(PaymentMatchingReceiveVoucherRelation.class).set(PaymentMatchingReceiveVoucherRelation::getDeleteFlag,1).eq(PaymentMatchingReceiveVoucherRelation::getMainId,id));
    }

    @Override
    @Transactional
    public void pushConfirm(Long id) {
        PaymentMatching paymentMatching = paymentMatchingService.getById(id);
        paymentMatching.setStatus(7);
        paymentMatching.setUpdateTime(LocalDateTime.now());
        paymentMatching.setUpdateUser(LoginUtil.getUserId());
        paymentMatchingService.updateById(paymentMatching);
    }

    @Override
    @Transactional
    public PaymentMatchingDTO getById(Long id) {
        PaymentMatching paymentMatching = paymentMatchingService.getById(id);
        return paymentMatchingConvert.entity2DTO(paymentMatching);
    }


    @Override
    @Transactional
    public void financeConfirm(PaymentMatchingParamDTO param) {
        PaymentMatching paymentMatching = paymentMatchingService.getById(param.getId());
        paymentMatching.setStatus(param.getApproveStatus()==1?9:8);
        paymentMatching.setFinanceConfirmTime(LocalDateTime.now());
        paymentMatching.setFinanceConfirmUser(LoginUtil.getUserId());
        paymentMatchingService.updateById(paymentMatching);
        // 2.记录原因
        PaymentMatchingApprove approve = new PaymentMatchingApprove();
        approve.setMainId(paymentMatching.getId());
        approve.setMainNo(paymentMatching.getCode());
        approve.setApproveResult(param.getApproveStatus());
        approve.setApproveOpinion(param.getApproveOpinion());
        approve.setApproveUserId(LoginUtil.getUserId());
        approve.setApproveUserCode(LoginUtil.getAccount());
        approve.setApproveUserName(LoginUtil.getName());
        // 财务节点
        approve.setApproveNode(2);
        approve.setApproveTime(LocalDateTime.now());
        paymentMatchingApproveService.save(approve);
    }

    @Override
    public void createPrefabricateInvoice(Long id, Integer type, String invoicePostDate, String statementType) {
        PaymentMatching paymentMatching = paymentMatchingService.getById(id);
        //过账状态 1:暂存 2:待预制 3:预制失败 7:已冲销 2024-08-21 邓京术 财务要求 3和7的也允许过账
        if (ObjectUtil.isNotEmpty(paymentMatching)){
            if (paymentMatching.getPostStatus() != 1&&paymentMatching.getPostStatus() != 2&&paymentMatching.getPostStatus() != 3&&paymentMatching.getPostStatus() != 7){
                throw new DaoException(StrUtil.format("货款匹配单:{}已过账，不允许再次过账",paymentMatching.getCode()));
            }
        }
//        List<CustomsDeclarationDetailPO> list = customsDeclarationDetailService.provideDetailByPaymentMatchingId(id);
        List<StatementItemPO> statementItemPOS = receiveVoucherService.provideDetailByPaymentMatchingId(id);
        statementItemPOS.forEach(dto -> {
            if (dto.getVoucherFlag().equals("H")){
                if (dto.getTaxAmount().compareTo(BigDecimal.ZERO) > 0) { // 只有正数才取负
                    dto.setTaxAmount(dto.getTaxAmount().negate());
                    dto.setMvNum(dto.getMvNum().negate());
                }
            }
        });
        //组装数据传入对账数据到sap接口
        final PaymentToSapDTO accountStatementToSapDTO = new PaymentToSapDTO();
        //头
        final PaymentToSapDTO.ItHead itHead = new PaymentToSapDTO.ItHead();
        itHead.item = Lists.newArrayList();
        PaymentToSapDTO.Head head = new PaymentToSapDTO.Head();
        //SRM单号
        head.setZSRMBILLNO(paymentMatching.getCode());
        // 业务类型
        head.setYWLX("01");
        // 法人主体
        head.setBUKRS(paymentMatching.getCompanyCode());
        // 发票日期
        head.setBLDAT(LocalDateTimeUtil.format(paymentMatching.getInvoiceDate(),"yyyyMMdd"));
        // 过账日期
        head.setBUDAT(LocalDateTimeUtil.format(LocalDateTimeUtil.parse(invoicePostDate,"yyyy-MM-dd"),"yyyyMMdd"));
        // 币别
        head.setWAERS(paymentMatching.getCurrencyCode());
        // 金额（RMWWR）
        head.setRMWWR(paymentMatching.getTaxAmount().stripTrailingZeros().toPlainString());
        // 税额
        head.setWMWST1("0");
        // 文本
//        head.setSGTXT(paymentMatching.getCustomsDeclarationDetailCode()+"_"+paymentMatching.getAgentSupplierCode()+"_报关单");
        head.setSGTXT(paymentMatching.getRemark());
        // 供应商
        head.setLIFNR(paymentMatching.getSupplierCode());
        // 总账科目
        head.setHKONT("");
        // 借/贷
        head.setSHKZG("");
        // 金额（WRBTR）
        head.setWRBTR("");
        itHead.item.add(head);
        //明细
        final PaymentToSapDTO.ItItem itItem = new PaymentToSapDTO.ItItem();
        itItem.item = Lists.newArrayList();
        for(StatementItemPO dto: statementItemPOS){
            PaymentToSapDTO.Item item = new PaymentToSapDTO.Item();
            // 采购订单
            item.setEBELN(dto.getPoCode());
            // 项目（采购订单行项目）
            item.setEBELP(dto.getPoItemNo());
            // 金额
            item.setWRBTR(dto.getTaxAmount().stripTrailingZeros().toPlainString());
            // 数量
            item.setMENGE(dto.getMvNum().stripTrailingZeros().toPlainString());
            // 物料凭证
            item.setMBLNR(dto.getMvCode());
            // 项目（物料凭证行项目）
            item.setZEILE(dto.getReceiveRowNo());
            // 年度
            item.setMJAHR(dto.getReceiveYear());
            itItem.item.add(item);
        }
        accountStatementToSapDTO.setIT_HEAD(itHead);
        accountStatementToSapDTO.setIT_ITEM(itItem);

        SapResposeBody sapResposeBody = accountStatementSapClient.syncPayment(accountStatementToSapDTO);
        if (sapResposeBody.getES_RET().getCODE().equals(RestCode.SAP_SUCCESS.getCode())) {
            paymentMatching.setPostStatus(4);
            paymentMatching.setPostMsg("成功");
            paymentMatching.setPostDate(LocalDateTimeUtil.parseDate(invoicePostDate,"yyyy-MM-dd"));
            paymentMatching.setPostOptTime(LocalDateTime.now());
            paymentMatching.setPostUser(LoginUtil.getUserId());
            paymentMatchingService.updateById(paymentMatching);
        }else {
            paymentMatching.setPostStatus(3);
            paymentMatching.setPostMsg(sapResposeBody.getES_RET().getMSG());
            paymentMatching.setPostDate(LocalDateTimeUtil.parseDate(invoicePostDate,"yyyy-MM-dd"));
            paymentMatching.setPostOptTime(LocalDateTime.now());
            paymentMatching.setPostUser(LoginUtil.getUserId());
            paymentMatchingService.updateById(paymentMatching);
            throw new DaoException("SAP接口报错：" + sapResposeBody.getES_RET().getMSG());
        }
    }

    @Override
    public void updatePrefabricateInvoice(Long aLong, String invoiceVoucher, String paymentExpireDate, String voucherYear, Integer postStatus) {
        PaymentMatching paymentMatching = paymentMatchingService.getById(aLong);
        paymentMatching.setInvoiceVoucher(invoiceVoucher);
//        paymentMatching.setInvoicePostDate(LocalDateTimeUtil.parse(invoicePostDate,"yyyy-MM-dd"));
        paymentMatching.setPaymentExpireDate(LocalDateTimeUtil.parse(paymentExpireDate,"yyyy-MM-dd"));
        paymentMatching.setVoucherYear(voucherYear);
        paymentMatching.setPostStatus(postStatus);
        paymentMatchingService.updateById(paymentMatching);

        List<PaymentMatchingReceiveVoucherRelation> list = paymentMatchingReceiveVoucherRelationService.list(new LambdaQueryWrapper<PaymentMatchingReceiveVoucherRelation>().eq(PaymentMatchingReceiveVoucherRelation::getMainId,aLong));
        for (PaymentMatchingReceiveVoucherRelation paymentMatchingReceiveVoucherRelation : list) {
            receiptVoucherLogic.updateInvoiceVoucherAndPaymentExpireDate(paymentMatchingReceiveVoucherRelation.getReceiveVoucherId(),paymentMatchingReceiveVoucherRelation.getFactoryCode(),invoiceVoucher,paymentExpireDate);
        }
    }

    /**
     * 匹配单删除
     *
     * @param ids         ID
     * @param logicDelete 是否逻辑删除
     */
    @Override
    public void dataDel(String ids, Boolean logicDelete) {
        if (StringUtils.isEmpty(ids)) {
            throw new DaoException("参数异常, 请重新操作");
        }
        final List<Long> idList = JSONArray.parseArray(ids, Long.class);
        final List<PaymentMatching> list = paymentMatchingService.list(new LambdaQueryWrapper<PaymentMatching>().in(PaymentMatching::getId, idList));
        for (PaymentMatching paymentMatching : list) {
            paymentMatching.setDeleteFlag(1);
            paymentMatching.setUpdateUser(StpUtil.isLogin()?LoginUtil.getUserId():1L);
            paymentMatching.setUpdateTime(LocalDateTime.now());
            paymentMatchingService.updateById(paymentMatching);
        }

        List<PaymentMatchingCustomsDeclarationRelation> updateIadList = paymentMatchingCustomsDeclarationRelationService.list(new LambdaQueryWrapper<PaymentMatchingCustomsDeclarationRelation>().in(PaymentMatchingCustomsDeclarationRelation::getMainId, idList));
        for (PaymentMatchingCustomsDeclarationRelation customsDeclarationRelation : updateIadList) {
            customsDeclarationRelation.setDeleteFlag(1);
            customsDeclarationRelation.setUpdateUser(StpUtil.isLogin()?LoginUtil.getUserId():1L);
            customsDeclarationRelation.setUpdateTime(LocalDateTime.now());
            paymentMatchingCustomsDeclarationRelationService.updateById(customsDeclarationRelation);
        }

        List<PaymentMatchingReceiveVoucherRelation> receiveVoucherRelations = paymentMatchingReceiveVoucherRelationService.list(new LambdaQueryWrapper<PaymentMatchingReceiveVoucherRelation>().in(PaymentMatchingReceiveVoucherRelation::getMainId, idList));
        for (PaymentMatchingReceiveVoucherRelation paymentMatchingReceiveVoucherRelation : receiveVoucherRelations) {
            paymentMatchingReceiveVoucherRelation.setDeleteFlag(1);
            paymentMatchingReceiveVoucherRelation.setUpdateUser(StpUtil.isLogin()?LoginUtil.getUserId():1L);
            paymentMatchingReceiveVoucherRelation.setUpdateTime(LocalDateTime.now());
            paymentMatchingReceiveVoucherRelationService.updateById(paymentMatchingReceiveVoucherRelation);
        }

    }
}
