package com.sunxung.factoring.service.financing.contract.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.sunxung.factoring.component.exception.BusinessException;
import com.sunxung.factoring.component.util.*;
import com.sunxung.factoring.dict.impl.FileModuleDict;
import com.sunxung.factoring.entity.entprise.Enterprise;
import com.sunxung.factoring.entity.financing.apply.CFinancingBasicInfo;
import com.sunxung.factoring.entity.financing.contract.ContractBasicContract;
import com.sunxung.factoring.entity.financing.contract.ContractInfo;
import com.sunxung.factoring.entity.financing.contract.ContractMasterContract;
import com.sunxung.factoring.entity.financing.review.ReviewFinancingInfo;
import com.sunxung.factoring.entity.financing.review.ReviewMasterContract;
import com.sunxung.factoring.entity.financing.review.ReviewMasterContractDebtor;
import com.sunxung.factoring.entity.financing.review.ReviewQuotaDisburse;
import com.sunxung.factoring.entity.salescontractmanagement.CSalesContractBasicInfo;
import com.sunxung.factoring.service.entprise.IEnterpriseService;
import com.sunxung.factoring.service.financing.apply.ICFinancingBasicInfoService;
import com.sunxung.factoring.service.financing.contract.INewContractMakingService;
import com.sunxung.factoring.service.financing.review.ReviewFinancingInfoService;
import com.sunxung.factoring.service.financing.review.ReviewMasterContractDebtorService;
import com.sunxung.factoring.service.financing.review.ReviewMasterContractService;
import com.sunxung.factoring.service.financing.review.ReviewQuotaDisburseService;
import com.sunxung.factoring.service.salescontractmanagement.SalesContractService;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

/**
 * @Description :
 * @Author : L.Jia
 * @Date: 2024-02-19 20:44
 */

@Service
public class NewContractMakingServiceImpl implements INewContractMakingService {

    @Autowired
    private ReviewQuotaDisburseService reviewQuotaDisburseService;
    @Autowired
    private ReviewMasterContractService reviewMasterContractService;
    @Autowired
    private ReviewMasterContractDebtorService reviewMasterContractDebtorService;
    @Autowired
    private ReviewFinancingInfoService reviewFinancingInfoService;
    @Autowired
    private ICFinancingBasicInfoService financingBasicInfoService;
    @Autowired
    private IEnterpriseService enterpriseService;
    @Autowired
    private SalesContractService salesContractService;

    @Override
    public void createContractDocument(String type, Long id, ContractInfo contractInfo, List<File> list) {
        if (type.equals(ConstantConversionUtil.TRIPARTITEAGREEMENTFACTORING)) {
            // 下载(贸理通)三方协议
            dealNewtTripartiteAgreementFactoringDownload(contractInfo, list, id);
        } else if (type.equals(ConstantConversionUtil.POOLFACTORINGBUSINESSCONTRACT)) {
            //下载池保理业务合同
            dealNewPoolFactoringBusinessContract(contractInfo, list, type);
        } else if (type.equals(ConstantConversionUtil.POOLFACTORINGFINANCINGCONFIRM)
                || type.equals(ConstantConversionUtil.POOLFACTORINGINFODOMESTIC)) {
            // 注意事项：设置excel表格的时，一定要设置ss:ExpandedRowCount行数，建议其值设置较大，如500，防止创建excel行数不够导致失败
            // 下载保理信息表或保理融资确认书
//            dealNewFactoringInfo(contractInfo, list, type);
        } else if (type.equals(ConstantConversionUtil.POOLACCOUNTRECEIVABLETRANSFERNOTICEDOMESTICBRIGHT)) {
            // 应收账款转让通知书
//            dealNewNoticeDownloadAll(contractInfo, list, type);
        } else if (type.equals(ConstantConversionUtil.POOLFACTORINGACCOUNTRECEIVABLEINTOPOOLCONFIRM)) {
            // 应收账款入池确认书 应收账款转让协议
//            dealNewConfirmDownload(contractInfo, list, type);
        }
    }

    /**
     * 下载(贸理通)三方协议
     */
    public void dealNewtTripartiteAgreementFactoringDownload(ContractInfo contractInfo, List<File> list, Long basicContractId) {
        try {
            Map<String, Object> map = new HashMap<>();
            ReviewQuotaDisburse reviewQuotaDisburse = reviewQuotaDisburseService.getById(contractInfo.getReviewQuotaDisburseId());
            // 主合同信息
            ReviewMasterContract masterContract = reviewMasterContractService.getOne(new QueryWrapper<ReviewMasterContract>()
                    .eq("review_quota_disburse_id", reviewQuotaDisburse.getId()));
            //融资信息
            ReviewFinancingInfo financingInfo = reviewFinancingInfoService.getOne(new QueryWrapper<ReviewFinancingInfo>()
                    .eq("review_quota_disburse_id", reviewQuotaDisburse.getId()));
            //融资利息
            BigDecimal financingInterest = financingInfo.getFinancingInterest();
            //融资金额
            BigDecimal financingAmount = financingInfo.getFinancingAmount();
            BigDecimal financingTotal = BigDecimal.ZERO;
            financingTotal = financingTotal.add(financingAmount).add(financingInterest);
            // 保理合同编号
            String factoringContractNo = masterContract.getContractNo();

            map.put("financingTotal", financingTotal);
            map.put("managementFeeAmount", financingInfo.getManagementFeeAmount());
            // 国内有追索权（正向、反向）、国内无追索权（正向，目前没有反向业务）、池保理（出口和国内）均有三方协议和交易信息表
            //贸理通默认国内池保理
            List<ContractBasicContract> basicContractList = contractInfo.getContractBasicContractList();
            String path;
            XWPFTemplate template;
            if (null != basicContractList && basicContractList.size() > 0) {
                // 表示有三方协议
                map.put("creditorName", masterContract.getApplicantCompanyName());// 债权人名称
                map.put("creditorAddress", masterContract.getApplicantCompanyAddress());// 债权人注册地址
                map.put("factoringContractNo", factoringContractNo);
                map.put("factoringContractName", masterContract.getContractName());
                map.put("factoringName", masterContract.getFactoringName());
                map.put("factoringAddress", ConstantUtil.OUR_COMPANY_ADDRESS_NAME);
                map.put("applicantCompany", masterContract.getApplicantCompanyName());
                map.put("telephone", masterContract.getApplicantContactNumber());//债权人联系电话
                map.put("contact", masterContract.getApplicantContact());
                map.put("applicantLegalPerson", masterContract.getApplicantCompanyLegalPerson());//债权人公司法人

                ContractBasicContract basic = null;
                for (ContractBasicContract basicContract : basicContractList) {
                    if (basicContract.getId().equals(basicContractId)) {
                        basic = basicContract;
                    }
                }
                if (basic.getSpecialAgreement().equals("")) {
                    map.put("specialAgreement", "");
                } else {
                    String specialAgreement = "4." + basic.getSpecialAgreement();
                    map.put("specialAgreement", specialAgreement);
                }
                map.put("tripartiteAgreementNo", basic.getTripartiteAgreementNo());
                // 债务人
                ReviewMasterContractDebtor contractMasterContractDebtor = new ReviewMasterContractDebtor();
                List<ReviewMasterContractDebtor> debtorList = reviewMasterContractDebtorService.list(new QueryWrapper<ReviewMasterContractDebtor>()
                        .eq("review_master_contract_id", masterContract.getId()));
                for (ReviewMasterContractDebtor contractMasterDebtor : debtorList) {
                    if (contractMasterDebtor.getCompanyName().equals(basic.getDebtorCompanyName())) {
                        contractMasterContractDebtor = contractMasterDebtor;
                    }
                }
                String companyName = contractMasterContractDebtor.getCompanyName();
                map.put("companyName", companyName);
                if (companyName.equals("西安长银保国际贸易有限公司")) {
                    map.put("address", ConstantUtil.OUR_COMPANY_ADDRESS_NAME);
                } else {
                    map.put("address", contractMasterContractDebtor.getAddress());
                }
                map.put("legalPerson", contractMasterContractDebtor.getLegalPerson());
                map.put("contact", contractMasterContractDebtor.getContact());
                map.put("contactNumer", contractMasterContractDebtor.getContactNumber());

                CFinancingBasicInfo financingBasicInfo = financingBasicInfoService.getById(reviewQuotaDisburse.getFinancingBasicInfoId());
                //核心企业名称
                Enterprise coreEnterprise = enterpriseService.getById(financingBasicInfo.getCoreEnterpriseId());
                map.put("enterpriseName", coreEnterprise.getCorporateName());

                CSalesContractBasicInfo salesContractBasicInfo = salesContractService.findByBusinessNumber(financingBasicInfo.getBusinessNumber());
                if (salesContractBasicInfo == null || salesContractBasicInfo.getId() == null) {
                    throw new BusinessException(CodeUtil.FAIL, "销售合同信息不能为空");
                }
                String salesContractNumber = salesContractBasicInfo.getContractNumber();
                String salesContractName = salesContractBasicInfo.getContractName();
                map.put("salesContractNumber", salesContractNumber);
                if (salesContractName == null || salesContractName.equals("")) {
                    map.put("salesContractName", "《买卖合同》");
                } else {
                    map.put("salesContractName", "《" + salesContractName + "》");
                }
                map.put("basicContractNo", financingBasicInfo.getContractNumber());
                map.put("basicContractName", "《" + financingBasicInfo.getContractName() + "》");
                //时间
                Date date = new Date();
                String day = DateUtil.getDay(date);
                String month = DateUtil.getMonth(date);
                String year = DateUtil.getYear(date);
                map.put("day", day);
                map.put("month", month);
                map.put("year", year);

                ClassPathResource classPathResource = new ClassPathResource("ftl/contractTemplate/30、三方协议（贸理通）.docx");
                LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
                Configure configure = Configure.builder()
                        .bind("details", policy).build();
                template = XWPFTemplate.compile(classPathResource.getPath(), configure).render(map);
                path = FileUtil.getAbsolutePath("三方协议（贸理通）" + companyName, ".docx", FileModuleDict.ChildEnum.CONTRACT_FILE_PREVIEW);
                File file = new File(path);
                if (!file.exists()) {
                    FileUtils.createParentDirectories(file);
                }
                template.writeToFile(path);
                list.add(file);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(CodeUtil.FAIL, "下载三方协议（贸理通）出错" + e.getMessage());
        }
    }

    /**
     * 下载池保理业务合同 保理业务合同
     */
    private void dealNewPoolFactoringBusinessContract(ContractInfo contractInfo, List<File> list, String type) {
        XWPFTemplate template;
        String path;
        try {
            Map<String, Object> dataMap = new HashMap<>();

            ReviewQuotaDisburse reviewQuotaDisburse = reviewQuotaDisburseService.getById(contractInfo.getReviewQuotaDisburseId());
            // 主合同信息
            ReviewMasterContract masterContract = reviewMasterContractService.getOne(new QueryWrapper<ReviewMasterContract>()
                    .eq("review_quota_disburse_id", reviewQuotaDisburse.getId()));
            // 保理合同编号
            String factoringContractNo = masterContract.getContractNo();
            // 保理商
            String factoringName = masterContract.getFactoringName();
            // 保理申请人
            String applicantContact = masterContract.getApplicantContact();
            // 保理申请人公司名称
            String applicantCompanyName = masterContract.getApplicantCompanyName();
            if (masterContract.getDoubleFactoringType().equals(1)) {
                if ((masterContract.getPlatformName() != null && !masterContract.getPlatformName().equals(""))) {
                    HashMap<String, String> hashMap = new HashMap<>();
                    hashMap.put("platformName", masterContract.getPlatformName());
                    dataMap.put("doubleFactoringType", hashMap);
                } else {
                    dataMap.put("doubleFactoringType", false);
                }
            } else {
                dataMap.put("doubleFactoringType", false);
            }
            dataMap.put("factoringContractNo", factoringContractNo);
            dataMap.put("factoringName", factoringName);
            dataMap.put("factoringAgentName", masterContract.getFactoringAgentName());
            dataMap.put("factoringAgentEmail", masterContract.getFactoringAgentEmail());
            dataMap.put("factoringAgentPhone", masterContract.getFactoringAgentPhone());
            dataMap.put("factoringAddress", ConstantUtil.OUR_COMPANY_ADDRESS_NAME);
            dataMap.put("applicantContact", applicantContact);
            dataMap.put("applicantCompanyName", applicantCompanyName);
            dataMap.put("applicantContactNumber", masterContract.getApplicantContactNumber());
            dataMap.put("applicantEmail", masterContract.getApplicantEmail());
            dataMap.put("applicantAddress", masterContract.getApplicantCompanyAddress());

            ContractMasterContract contractMasterContract = contractInfo.getContractMasterContract();
            if (contractMasterContract.getFactoringContractAgreement() != null && !contractMasterContract.getFactoringContractAgreement().equals("")) {
                if (type.equals(ConstantConversionUtil.POOLFACTORINGBUSINESSCONTRACT)) {
                    dataMap.put("factoringContractAgreement", "10、" + contractMasterContract.getFactoringContractAgreement());
                }
            }
            Date date = new Date();
            dataMap.put("year", DateUtil.getYear(date));
            dataMap.put("month", DateUtil.getMonth(date));
            dataMap.put("day", DateUtil.getDay(date));
            if (type.equals(ConstantConversionUtil.POOLFACTORINGBUSINESSCONTRACT)) {
                ClassPathResource classPathResource = new ClassPathResource("ftl/contractTemplate/24、池保理业务合同.docx");
                template = XWPFTemplate.compile(classPathResource.getInputStream()).render(dataMap);
                path = FileUtil.getAbsolutePath("池保理业务合同" + applicantCompanyName, ".docx", FileModuleDict.ChildEnum.CONTRACT_FILE_PREVIEW);
                File file = new File(path);
                if (!file.exists()) {
                    FileUtils.createParentDirectories(file);
                }
                template.writeToFile(path);
                list.add(file);
            }

        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException(CodeUtil.FAIL, "下载池保理业务合同错误" + e.getMessage());
        }
    }

    /**
     * 下载保理信息表或保理融资确认书
     */
//    private void dealNewFactoringInfo(ContractInfo making, List<File> fileAllList, String type) {
//        String recourse = making.getRecourseRights();
//        Map<String, String> iMap = ConstantConversionUtil.recourseRightsMap;
//        for (Map.Entry<String, String> name : iMap.entrySet()) {
//            if (name.getValue().equals(recourse)) {
//                recourse = name.getKey();
//            }
//        }
//        making.setRecourseRights(recourse);
//        autoAccountReceivable(making);
//        String path = null;
//        XWPFTemplate template = null;
//        XWPFTable table = null;
//        try {
//            if (null != making && null != making.getMasterContract()) {
//                Map<String, Object> dataMap = new HashMap<>();
//                ContractMasterContract master = making.getMasterContract();
//                // 保理合同编号
//                String contractNo = master.getContractNo();
//                //合同名称
//                String contractName = master.getContractName();
//                // 保理合同名称
//                String factoringContractName = master.getContractName();
//                // 保理商法定代表人
//                String factoringLegalPersion = master.getFactoringLegalPersion();
//                //保理商联系人
//                String factoringAgentName = master.getFactoringAgentName();
//                //保理商联系人电话
//                String factoringAgentPhone = master.getFactoringAgentPhone();
//                String factoringCompanyName = master.getFactoringName();
//                String factoringLegalPerson = master.getFactoringLegalPersion();
//                String factoringAgent = master.getFactoringAgentName();
//                //保理商名称
//                String factoringName = master.getFactoringName();
//                String factoringAddress = master.getFactoringAddress();
//                // 保理申请人公司名称
//                String applicantCompanyName = master.getApplicantCompanyName();
//                // 保理申请人注册地址
//                String applicantCompanyAddress = master.getApplicantCompanyAddress();
//                // 保理申请人公司法定代表人
//                String applicantCompanyLegalPerson = master.getApplicantCompanyLegalPerson();
//                // 有或无追索权
//                String recourseRights = making.getRecourseRights();
//                // 池或非池
//                String isPool = making.getIsPool();
//                // 国内或出口保理
//                String businessType = making.getBusinessType();
//                // 币种，
//                com.sunxung.factoring.entity.sys.Dictionary currency = making.getCurrency();
//                //获取应收账款
//                List<ContractDomesticAccountReceivable> list3 = making.getDomesticAccountReceivableList();
//                List<ContractExportAccountReceivable> list4 = making.getExportAccountReceivableList();
//                // 金额大写时，要求币种纯中文，如人民币，而不是CNY（人民币）的格式，故需要转化
//                currency.setName(ConstantConversionUtil.currencyTypeCnameMap.get(currency.getCode()));
//                // 池保理确认书特殊约定
//                String poolFactoringFinancingConfirmAgree = master.getPoolFactoringFinancingConfirmAgree();
//                //池保理时保理信息表特殊约定
//                String specialAgreement = master.getSpecialAgreement();
//                //E贸特殊约定
//                String specialAgreementStr = null;
//                List<ContractSpecialAgreement> eSpecialAgreements = new ArrayList<>();
//                eSpecialAgreements = master.getContractSpecialAgreementList();
//                for (ContractSpecialAgreement eSpecialAgreement : eSpecialAgreements) {
//                    specialAgreementStr = "4、" + eSpecialAgreement.getAgreementContent();
//                }
//                // 池保理确认书编号
//                String poolFactoringFinancingConfirmNo = master.getPoolFactoringFinancingConfirmNo();
//                // 保理专户户名
//                String factoringAccountName = master.getFactoringAccountName();
//                // 保理专户账号
//                String factoringAccount = master.getFactoringAccount();
//                // 保理专户开户行
//                String factoringAccountBank = master.getFactoringAccountBank();
//                //保理专户(收汇)户名1
//                String factoringAccountName1 = master.getFactoringAccountName();
//                //保理专户（收汇）账户1
//                String factoringAccount1 = master.getFactoringAccount();
//                //保理专户（收汇）开户行1
//                String factoringAccountBank1 = master.getFactoringAccountBank();
//                //保理专户(收汇)户名2
//                String factoringAccountName2 = master.getFactoringAccountName2();
//                //保理专户（收汇）账户2
//                String factoringAccount2 = master.getFactoringAccount2();
//                //保理专户（收汇）开户行2
//                String factoringAccountBank2 = master.getFactoringAccountBank2();
//                //保理申请人指定账户户名
//                String applicantDesignatedAccountName = master.getApplicantDesignatedAccountName();
//                //保理申请人指定账户
//                String applicantDesignatedAccount = master.getApplicantDesignatedAccount();
//                //保理申请人指定账户开户行
//                String applicantDesignatedbank = master.getApplicantDesignatedbank();
//                //我司指定账户户名
//                String ourAccountName = master.getOurAccountName();
//                //我司指定账户
//                String ourAccount = master.getOurAccount();
//                //我司指定账户开户行
//                String ourAccountBank = master.getOurAccountBank();
//                //合同份数
//                Integer contractNum = master.getContractNum();
//                Date date = new Date();
//                String year = DateUtil.getYear(date);
//                String day = DateUtil.getDay(date);
//                String month = DateUtil.getMonth(date);
//                // 债务人个数
//                int debtorNum = 0;
//                // 债务人信息
//                ContractMasterContractDebtor debtor = null;
//                List<ContractMasterContractDebtor> debtorList = master.getDebtorList();
//                if (null != debtorList && debtorList.size() > 0) {
//                    debtorNum = debtorList.size();
//                    debtor = debtorList.get(0);
//                    int i = 0;
//                    ArrayList<Map<String, Object>> mapList = new ArrayList<>();
//                    String debtorNames = "";
//                    if (CollectionUtil.isNotEmpty(debtorList)) {
//                        for (ContractMasterContractDebtor contractDebtor : debtorList) {
//                            i++;
//                            Map<String, Object> iMp = new HashMap<>();
//                            iMp.put("recorsNo", i);
//                            iMp.put("companyName", contractDebtor.getCompanyName());
////                            if (contractDebtor.getCompanyName().equals("西安长银保国际贸易有限公司")) {
////                                iMp.put("debtorAddress", dictionaryService.getByCode(ConstantUtil.OUR_COMPANY_ADDRESS).getName());
////                            } else {
////                                iMp.put("debtorAddress", contractDebtor.getAddress());
////                            }
//                            iMp.put("debtorAddress", contractDebtor.getAddress());
//                            iMp.put("debtorLegalPerson", contractDebtor.getLegalPerson());
//                            iMp.put("debtorContact", contractDebtor.getContact());
//                            iMp.put("debtorContactNumber", contractDebtor.getContactNumer());
//                            mapList.add(iMp);
//                        }
//                        debtorNames = debtorList.stream().map(ContractMasterContractDebtor::getCompanyName)
//                                .collect(Collectors.joining("、"));
//                    }
//
//
//                    dataMap.put("debtorNames", debtorNames);
//                    if (null != mapList && mapList.size() > 0) {
//                        dataMap.put("mapList", mapList);
//                    }
//                }
//                // 明保理或暗保理
//                String disclosedUndisclosedFactoringNum = "";
//                String disclosedUndisclosedFactoring = making.getDisclosedUndisclosedFactoring();
//                if (disclosedUndisclosedFactoring.equals(ConstantConversionUtil.DISCLOSED_FT) || disclosedUndisclosedFactoring.equals(ConstantConversionUtil.DISCLOSED_FT_DISPLAYNAME)) {
//                    // 明保理
//                    disclosedUndisclosedFactoringNum = "1";
//                } else if (disclosedUndisclosedFactoring.equals(ConstantConversionUtil.UNDISCLOSED_FT) || disclosedUndisclosedFactoring.equals(ConstantConversionUtil.UNDISCLOSED_FT_DISPLAYNAME)) {
//                    disclosedUndisclosedFactoringNum = "2";
//                }
//                // 保证金类型放款中最靠后的时间
//                String marginLoanLastDateStr = null;
//                autoIncomeExpenditurePlan(making);
//                List<ContractIncomeExpenditurePlan> incomeExpendPlanList = making.getIncomeExpenditurePlanList();
//                if (null != incomeExpendPlanList && incomeExpendPlanList.size() > 0) {
//                    List<Date> dateList = incomeExpendPlanList.stream()
//                            .filter(e -> null != e.getIncormExpenditureType())
//                            .filter(e -> StringUtil.isNotEmpty(e.getIncormExpenditureType().getCode()))
//                            .filter(e -> e.getIncormExpenditureType().getCode()
//                                    .equals(IncormeExpenditureTypeDict.ChildEnum.MARGIN.getCode()))
//                            .filter(e -> null != e.getLoan())
//                            .map(ContractIncomeExpenditurePlan::getIncormExpenditureDate).collect(Collectors.toList());
//                    if (null != dateList && dateList.size() > 0) {
//                        Optional<Date> op = dateList.stream().sorted((e1, e2) -> e2.compareTo(e1)).findFirst();
//                        marginLoanLastDateStr = DateUtil.formateYMD(op.get());
//                    }
//                }
//                // 融资信息
//                // 服务范围
//                String serviceScopeId = "";
//                // 转让通知方式
//                String transferNoticeMethodId = "";
//                // 融资金额
//                BigDecimal financingAmmount = null;
//                // 融资金额大写
//                String financingAmmountCname = "";
//                // 本金收取方式
//                String principalCollectionMethod = "";
//                // 保理融资期限
//                Integer financingPeriod = null;
//                // 起算日
//                String startingDateTypesNum = "";
//                // 具体日期
//                String yearStr = null;
//                String monthStr = null;
//                String dayStr = null;
//                // 融资利率(年化)
//                String financingRateStr = null;
//                //坏账担保比例
//                String badDebtGuaranteeRate = null;
//                // 逾期利率
//                String overdueInterestRateStr = null;
//                // 融资利息
//                BigDecimal financingInterest = null;
//                // 融资利息金额 大写
//                String financingInterestName = null;
//                // 保理融资利息及支付方式
//                String paymentMethod = null;
//                // 保证金比例
//                String marginRatioStr = null;
//                // 保证金支付方式
//                String marginCollectionMethod = null;
//                // 保证金退还方式
//                String marginReturnMethod = null;
//                // 保证金退还条件
//                String marginReturnCondition = null;
//                // 管理费金额
//                BigDecimal manageFeeAmount = null;
//                // 管理费金额大写
//                String manageFeeAmountName = null;
//                //管理费支付方式
//                String manageFeeCollectionMethod = null;
//                // 其他费用
//                BigDecimal otherFee = null;
//                // 其他费用支付方式
//                String otherFeeCollectionMethod = null;
//                // 其他费用大写
//                String otherFeeName = null;
//                // 信用风险担保金额
//                BigDecimal creditGuaranteeRiskAmount = null;
//                // 信用风险担保金额 大写
//                String creditGuaranteeRiskAmountName = null;
//                // 应收转让率
//                String receivableTransferRateStr = null;
//                //
//                int loanConditionListLength = 0;
//                ContractFinancingInfo financingInfo = contractMakingMapper
//                        .getFinancingByContractMakingId(making.getId());
//                if (null != financingInfo) {
//                    // 池保理
//                    if (isPool.equals(ConstantConversionUtil.POOL_FACTORING)) {
//                        // 服务范围
//                        if (StringUtil.isNotEmpty(financingInfo.getServiceScopeId())) {
//                            List<Long> idList = StringUtil.separatorCharacter(financingInfo.getServiceScopeId());
//                            for (Long dictId : idList) {
//                                com.sunxung.factoring.entity.sys.Dictionary dict = dictionaryService.get(dictId);
//                                if (null != dict && StringUtil.isNotEmpty(dict.getName())) {
//                                    String dictName = dict.getName();
//                                    if (dictName.equals(
//                                            FactoringServiceScope.ChildEnum.ACCOUNTRECEIVABLEFINANCING.getCname())) {
//                                        serviceScopeId = serviceScopeId + "1 ";
//                                    } else if (dictName.equals(
//                                            FactoringServiceScope.ChildEnum.ACCOUNTRECEIVABLEMANAGEMENT.getCname())) {
//                                        serviceScopeId = serviceScopeId + "2 ";
//                                    } else if (dictName
//                                            .equals(FactoringServiceScope.ChildEnum.COLLECTIONRECEIVABLES.getCname())) {
//                                        serviceScopeId = serviceScopeId + "3 ";
//                                    } else if (dictName.equals(
//                                            FactoringServiceScope.ChildEnum.accountReceivableOther.getCname())) {
//                                        serviceScopeId = serviceScopeId + "4 ";
//                                    }
//                                }
//                            }
//                        } else {
//                            serviceScopeId = "-";
//                        }
//                        // 转让通知方式
//                        if (StringUtil.isNotEmpty(financingInfo.getTransferNoticeMethodId())) {
//                            List<Long> idList = StringUtil
//                                    .separatorCharacter(financingInfo.getTransferNoticeMethodId());
//                            for (Long dictId : idList) {
//                                com.sunxung.factoring.entity.sys.Dictionary dict = dictionaryService.get(dictId);
//                                if (null != dict && StringUtil.isNotEmpty(dict.getName())) {
//                                    String dictName = dict.getName();
//                                    if (dictName.equals(TransferNoticeMethodDict.ChildEnum.express.getCname())) {
//                                        transferNoticeMethodId = transferNoticeMethodId + "1 ";
//                                    } else if (dictName
//                                            .equals(TransferNoticeMethodDict.ChildEnum.REGISTEREDLETTER.getCname())) {
//                                        transferNoticeMethodId = transferNoticeMethodId + "2 ";
//                                    } else if (dictName.equals(
//                                            TransferNoticeMethodDict.ChildEnum.DEBTORSTAMPCONFIRMATION.getCname())
//                                            || dictName.equals(TransferNoticeMethodDict.ChildEnum.IMPORTERSEALCONFIRMATION.getCname())) {
//                                        transferNoticeMethodId = transferNoticeMethodId + "3 ";
//                                    } else if (dictName
//                                            .equals(TransferNoticeMethodDict.ChildEnum.NOTARIZEDDELIVERY.getCname())) {
//                                        transferNoticeMethodId = transferNoticeMethodId + "4 ";
//                                    } else if (dictName.equals(
//                                            TransferNoticeMethodDict.ChildEnum.TRANSFERNOTICEMETHODOTHER.getCname())) {
//                                        transferNoticeMethodId = transferNoticeMethodId + "5 ";
//                                    }
//                                }
//                            }
//                        } else {
//                            transferNoticeMethodId = "-";
//                        }
//                    } else {
//                        // 处理服务范围
//                        if ((businessType.equals(ConstantConversionUtil.DOMESTIC_FACTORING)
//                                && recourseRights.equals(ConstantConversionUtil.RECOURSE))
//                                || (businessType.equals(ConstantConversionUtil.EXPORT_FACTORING))
//                                && recourseRights.equals(ConstantConversionUtil.RECOURSE)) {
//                            if (StringUtil.isNotEmpty(financingInfo.getServiceScopeId())) {
//                                List<Long> idList = StringUtil.separatorCharacter(financingInfo.getServiceScopeId());
//                                for (Long dictId : idList) {
//                                    com.sunxung.factoring.entity.sys.Dictionary dict = dictionaryService.get(dictId);
//                                    if (null != dict && StringUtil.isNotEmpty(dict.getName())) {
//                                        String dictName = dict.getName();
//                                        if (dictName.equals(FactoringServiceScope.ChildEnum.ACCOUNTRECEIVABLEFINANCING
//                                                .getCname())) {
//                                            serviceScopeId = serviceScopeId + "1 ";
//                                        } else if (dictName
//                                                .equals(FactoringServiceScope.ChildEnum.ACCOUNTRECEIVABLEMANAGEMENT
//                                                        .getCname())) {
//                                            serviceScopeId = serviceScopeId + "2 ";
//                                        } else if (dictName.equals(
//                                                FactoringServiceScope.ChildEnum.COLLECTIONRECEIVABLES.getCname())) {
//                                            serviceScopeId = serviceScopeId + "3 ";
//                                        } else if (dictName.equals(
//                                                FactoringServiceScope.ChildEnum.accountReceivableOther.getCname())) {
//                                            serviceScopeId = serviceScopeId + "4 ";
//                                        }
//                                    }
//                                }
//                            } else {
//                                serviceScopeId = "-";
//                            }
//                            // 转让通知方式
//                            if (StringUtil.isNotEmpty(financingInfo.getTransferNoticeMethodId())) {
//                                List<Long> idList = StringUtil
//                                        .separatorCharacter(financingInfo.getTransferNoticeMethodId());
//                                for (Long dictId : idList) {
//                                    com.sunxung.factoring.entity.sys.Dictionary dict = dictionaryService.get(dictId);
//                                    if (null != dict && StringUtil.isNotEmpty(dict.getName())) {
//                                        String dictName = dict.getName();
//                                        if (dictName.equals(TransferNoticeMethodDict.ChildEnum.express.getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "1 ";
//                                        } else if (dictName.equals(
//                                                TransferNoticeMethodDict.ChildEnum.REGISTEREDLETTER.getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "2 ";
//                                        } else if (dictName
//                                                .equals(TransferNoticeMethodDict.ChildEnum.DEBTORSTAMPCONFIRMATION
//                                                        .getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "3 ";
//                                        } else if (dictName.equals(
//                                                TransferNoticeMethodDict.ChildEnum.NOTARIZEDDELIVERY.getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "4 ";
//                                        } else if (dictName
//                                                .equals(TransferNoticeMethodDict.ChildEnum.TRANSFERNOTICEMETHODOTHER
//                                                        .getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "5 ";
//                                        }
//                                    }
//                                }
//                            } else {
//                                transferNoticeMethodId = "-";
//                            }
//                        } else if (businessType.equals(ConstantConversionUtil.DOMESTIC_FACTORING)
//                                && recourseRights.equals(ConstantConversionUtil.NORECOURSE)) {
//                            // 服务范围
//                            if (StringUtil.isNotEmpty(financingInfo.getServiceScopeId())) {
//                                List<Long> idList = StringUtil.separatorCharacter(financingInfo.getServiceScopeId());
//                                for (Long dictId : idList) {
//                                    com.sunxung.factoring.entity.sys.Dictionary dict = dictionaryService.get(dictId);
//                                    if (null != dict && StringUtil.isNotEmpty(dict.getName())) {
//                                        String dictName = dict.getName();
//                                        if (dictName.equals(FactoringServiceScope.ChildEnum.ACCOUNTRECEIVABLEFINANCING
//                                                .getCname())) {
//                                            serviceScopeId = serviceScopeId + "1 ";
//                                        } else if (dictName
//                                                .equals(FactoringServiceScope.ChildEnum.ACCOUNTRECEIVABLEMANAGEMENT
//                                                        .getCname())) {
//                                            serviceScopeId = serviceScopeId + "2 ";
//                                        } else if (dictName.equals(
//                                                FactoringServiceScope.ChildEnum.COLLECTIONRECEIVABLES.getCname())) {
//                                            serviceScopeId = serviceScopeId + "3 ";
//                                        } else if (dictName.equals(
//                                                FactoringServiceScope.ChildEnum.CREDITRISKGUARANTEE.getCname())) {
//                                            serviceScopeId = serviceScopeId + "4 ";
//                                        } else if (dictName.equals(
//                                                FactoringServiceScope.ChildEnum.accountReceivableOther.getCname())) {
//                                            serviceScopeId = serviceScopeId + "5 ";
//                                        }
//                                    }
//                                }
//                            } else {
//                                serviceScopeId = "-";
//                            }
//                            // 转让通知方式
//                            if (StringUtil.isNotEmpty(financingInfo.getTransferNoticeMethodId())) {
//                                List<Long> idList = StringUtil
//                                        .separatorCharacter(financingInfo.getTransferNoticeMethodId());
//                                for (Long dictId : idList) {
//                                    com.sunxung.factoring.entity.sys.Dictionary dict = dictionaryService.get(dictId);
//                                    if (null != dict && StringUtil.isNotEmpty(dict.getName())) {
//                                        String dictName = dict.getName();
//                                        if (dictName.equals(TransferNoticeMethodDict.ChildEnum.express.getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "1 ";
//                                        } else if (dictName.equals(
//                                                TransferNoticeMethodDict.ChildEnum.REGISTEREDLETTER.getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "2 ";
//                                        } else if (dictName
//                                                .equals(TransferNoticeMethodDict.ChildEnum.DEBTORSTAMPCONFIRMATION
//                                                        .getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "3 ";
//                                        } else if (dictName.equals(
//                                                TransferNoticeMethodDict.ChildEnum.NOTARIZEDDELIVERY.getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "4 ";
//                                        } else if (dictName
//                                                .equals(TransferNoticeMethodDict.ChildEnum.TRANSFERNOTICEMETHODOTHER
//                                                        .getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "5 ";
//                                        }
//                                    }
//                                }
//                            } else {
//                                transferNoticeMethodId = "-";
//                            }
//                        } else if (businessType.equals(ConstantConversionUtil.EXPORT_FACTORING)
//                                && recourseRights.equals(ConstantConversionUtil.RECOURSE)) {
//                            // 转让通知方式
//                            if (StringUtil.isNotEmpty(financingInfo.getTransferNoticeMethodId())) {
//                                List<Long> idList = StringUtil
//                                        .separatorCharacter(financingInfo.getTransferNoticeMethodId());
//                                for (Long dictId : idList) {
//                                    com.sunxung.factoring.entity.sys.Dictionary dict = dictionaryService.get(dictId);
//                                    if (null != dict && StringUtil.isNotEmpty(dict.getName())) {
//                                        String dictName = dict.getName();
//                                        if (dictName.equals(TransferNoticeMethodDict.ChildEnum.express.getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "1 ";
//                                        } else if (dictName.equals(
//                                                TransferNoticeMethodDict.ChildEnum.REGISTEREDLETTER.getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "2 ";
//                                        } else if (dictName
//                                                .equals(TransferNoticeMethodDict.ChildEnum.IMPORTERSEALCONFIRMATION
//                                                        .getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "3 ";
//                                        } else if (dictName.equals(
//                                                TransferNoticeMethodDict.ChildEnum.NOTARIZEDDELIVERY.getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "4 ";
//                                        } else if (dictName
//                                                .equals(TransferNoticeMethodDict.ChildEnum.TRANSFERNOTICEMETHODOTHER
//                                                        .getCname())) {
//                                            transferNoticeMethodId = transferNoticeMethodId + "5 ";
//                                        }
//                                    }
//                                }
//                            } else {
//                                transferNoticeMethodId = "-";
//                            }
//                        }
//                    }
//                    //信用风险担保金额
//                    creditGuaranteeRiskAmount = financingInfo.getCreditGuaranteeRiskAmount();
//                    if (null != creditGuaranteeRiskAmount) {
//                        creditGuaranteeRiskAmountName = MoneyToCNFormatUtil.formatToCN(creditGuaranteeRiskAmount.doubleValue());
//                    }
//                    // 融资金额
//                    financingAmmount = financingInfo.getFinancingAmmount();
//                    // 本金支付方式
//                    principalCollectionMethod = financingInfo.getPrincipalCollectionMethod();
//                    // 保理融资期限
//                    financingPeriod = financingInfo.getFinancingPeriod();
//                    // 起算日
//                    String startingDateType = financingInfo.getStartingDateType();
//                    if (startingDateType.equals(ConstantConversionUtil.PLAN_DAY)) {
//                        // 自保理融资款实际投放之日
//                        startingDateTypesNum = "1";
//                    } else {
//                        Date startDate = financingInfo.getStartingDate();
//                        yearStr = DateUtil.getYear(startDate);
//                        monthStr = DateUtil.getMonth(startDate);
//                        dayStr = DateUtil.getDay(startDate);
//                        startingDateTypesNum = "2";
//                    }
//                    // 融资利率(年化)
//                    financingRateStr = PercentageUtil.convertPercentage(financingInfo.getFinancingRate());
//                    if (StringUtil.isNotEmpty(financingRateStr)) {
//                        financingRateStr = StringUtil.subZeroAndDot(financingRateStr.split("%")[0]) + "%";
//                    }
//                    //坏账担保比例
//                    badDebtGuaranteeRate = PercentageUtil.convertPercentage(financingInfo.getBadDebtGuaranteeRate());
//                    if (StringUtil.isNotEmpty(badDebtGuaranteeRate)) {
//                        badDebtGuaranteeRate = StringUtil.subZeroAndDot(badDebtGuaranteeRate.split("%")[0]) + "%";
//                    }
//                    // 逾期利息
//                    overdueInterestRateStr = PercentageUtil.convertPercentage(financingInfo.getOverdueInterestRate());
//                    if (StringUtil.isNotEmpty(overdueInterestRateStr)) {
//                        overdueInterestRateStr = StringUtil.subZeroAndDot(overdueInterestRateStr.split("%")[0]) + "%";
//                    }
//                    // 融资利息
//                    financingInterest = financingInfo.getFinancingInterest();
//                    if (null != financingInterest) {
//                        financingInterestName = MoneyToCNFormatUtil.formatToCN(financingInterest.doubleValue());
//                    }
//                    // 支付方式
//                    paymentMethod = financingInfo.getInterestCollectionMethod();
//                    // 保证金比例
//                    marginRatioStr = PercentageUtil.convertPercentage(financingInfo.getMarginRatio());
//                    if (StringUtil.isNotEmpty(marginRatioStr)) {
//                        marginRatioStr = StringUtil.subZeroAndDot(marginRatioStr.split("%")[0]) + "%";
//                    }
//                    // 保证金支付方式
//                    marginCollectionMethod = financingInfo.getMarginCollectionMethod();
//                    // 保证金退还方式
//                    marginReturnMethod = financingInfo.getMarginReturnMethod();
//                    // 保证金退还提交
//                    marginReturnCondition = financingInfo.getMarginReturnCondition();
//                    // 管理费金额
//                    manageFeeAmount = financingInfo.getManagementFeeAmount();
//                    // 管理费金额大写
//                    if (null != manageFeeAmount) {
//                        manageFeeAmountName = MoneyToCNFormatUtil.formatToCN(manageFeeAmount.doubleValue());
//                    }
//                    //管理费支付方式
//                    manageFeeCollectionMethod = financingInfo.getManagementFeeCollectionMethod();
//                    // 其他费用
//                    otherFee = financingInfo.getOtherFeeAmount();
//                    // 其他费用支付方式
//                    otherFeeCollectionMethod = financingInfo.getOtherFeeCollectionMethod();
//                    // 其他费用金额大写
//                    if (null != otherFee) {
//                        otherFeeName = MoneyToCNFormatUtil.formatToCN(otherFee.doubleValue());
//                    }
//                    // 信用风险担保金额
//                    creditGuaranteeRiskAmount = financingInfo.getCreditGuaranteeRiskAmount();
//                    if (null != creditGuaranteeRiskAmount) {
//                        creditGuaranteeRiskAmountName = MoneyToCNFormatUtil
//                                .formatToCN(creditGuaranteeRiskAmount.doubleValue());
//                    }
//                    // 最高转让折率
//                    // receivableTransferRateStr = PercentageUtil
//                    // .convertPercentage(financingInfo.getReceivableTransferRate());
//                    // if (StringUtil.isNotEmpty(receivableTransferRateStr)) {
//                    // receivableTransferRateStr = StringUtil.subZeroAndDot(receivableTransferRateStr.split("%")[0])
//                    // + "%";
//                    // }
//                }
//                if (StringUtil.isNotEmpty(serviceScopeId)) {
//                    serviceScopeId = serviceScopeId.trim();
//                }
//                if (StringUtil.isNotEmpty(transferNoticeMethodId)) {
//                    transferNoticeMethodId = transferNoticeMethodId.trim();
//                }
//                if (null != financingAmmount) {
//                    financingAmmountCname = MoneyToCNFormatUtil.formatToCN(financingAmmount.doubleValue());
//                }
//                // 提款条件
//                List<ContractLoanCondition> loanConditionList = contractLoanConditionService
//                        .findLoanConditionByContractMakingId(making.getId());
//                // 金额合计：
//                BigDecimal amountTotal = null;
//                // 金额合计大写
//                String amountTotalName = "";
//                List<Map<String, Object>> listMap1 = new ArrayList<>();
//                List<Map<String, Object>> listMap2 = new ArrayList<>();
//                int recordNo = 0;
//                List<Map<String, Object>> loanConditionListMap = new ArrayList<>();
//                if (null != loanConditionList && loanConditionList.size() > 0) {
//                    for (ContractLoanCondition loanCondition : loanConditionList) {
//                        Map<String, Object> map = new HashMap<>();
//                        recordNo = recordNo + 1;
//                        map.put("recordNo", NumberToChnUtil.NumberToChn(recordNo));
//                        map.put("currencyEName", currency.getCode());
//                        map.put("currencyZName", currency.getName());
//                        if (null != loanCondition.getAmount()) {
//                            map.put("amountName",
//                                    MoneyToCNFormatUtil.formatToCN(loanCondition.getAmount().doubleValue()));
//                        }
//                        map.put("amount", NumberFormatUtil.convertDecimal(loanCondition.getAmount(),
//                                NumberFormatUtil.THOUSAND_SEPARATOR_TWO_DECIMAL));
//                        // 固定条件序号
//                        String fixedConditionNo = null;
//                        // 补充条件序号
//                        String supplementaryConditionNo = null;
//                        // 付款条件
//                        String paymentCondition = null;
//                        List<ContractLoanConditionSetting> loanConditionSetList = loanCondition
//                                .getLoanConditionSetList();
//                        if (null != loanConditionSetList && loanConditionSetList.size() > 0) {
//                            // 固定条件序号
//                            List<Integer> fixedConditionList = loanConditionSetList.stream()
//                                    .filter(e -> e.getFixedCondition())
//                                    .map(ContractLoanConditionSetting::getOrderNumber).collect(Collectors.toList());
//                            if (null != fixedConditionList && fixedConditionList.size() > 0) {
//                                fixedConditionNo = StringUtil.join(fixedConditionList.toArray(), "、");
//                            }
//                            // 补充条件序号
//                            List<Integer> supplementaryConditionList = loanConditionSetList.stream()
//                                    .filter(e -> !e.getFixedCondition())
//                                    .map(ContractLoanConditionSetting::getOrderNumber).collect(Collectors.toList());
//                            if (null != supplementaryConditionList && supplementaryConditionList.size() > 0) {
//                                supplementaryConditionNo = StringUtil.join(supplementaryConditionList.toArray(), "、");
//                            }
//                            // 付款条件:固定条件和补充条件都存在
//                            if (StringUtil.isNotEmpty(fixedConditionNo)
//                                    && StringUtil.isNotEmpty(supplementaryConditionNo)) {
//                                paymentCondition = fixedConditionNo + "、" + supplementaryConditionNo;
//                            }
//                            // 付款条件:固定条件存在，补充条件不存在
//                            if (StringUtil.isNotEmpty(fixedConditionNo)
//                                    && StringUtil.isEmpty(supplementaryConditionNo)) {
//                                paymentCondition = fixedConditionNo;
//                            }
//                            // 付款条件:固定条件不存在，补充条件存在
//                            if (StringUtil.isEmpty(fixedConditionNo)
//                                    && StringUtil.isNotEmpty(supplementaryConditionNo)) {
//                                paymentCondition = supplementaryConditionNo;
//                            }
//                        }
//                        // 金额合计
//                        amountTotal = loanConditionList.stream().filter(e -> null != e.getAmount())
//                                .map(ContractLoanCondition::getAmount).reduce(BigDecimal::add)
//                                .orElse(new BigDecimal(0));
//                        if (null != amountTotal) {
//                            amountTotalName = MoneyToCNFormatUtil.formatToCN(amountTotal.doubleValue());
//                        }
//                        map.put("fixedConditionNo", fixedConditionNo);
//                        map.put("supplementaryConditionNo", supplementaryConditionNo);
//                        map.put("paymentCondition", paymentCondition);
//                        loanConditionListMap.add(map);
//                    }
//                    dataMap.put("loanConditionListMap", loanConditionListMap);
//                }
//                loanConditionListLength = loanConditionListMap.size() * 2;
////                if (null != loanConditionListMap && loanConditionListMap.size() > 0) {
////                    // 第一个
////                    loanConditionListMapFirst.add(loanConditionListMap.get(0));
////                    // 除去第一个剩余的
////                    if (loanConditionListMap.size() > 1) {
////                        loanConditionListMap.remove(loanConditionListMap.get(0));
////                    }
////                }
//                // 条件设定(全部的)
//                List<ContractLoanConditionSetting> loanConditionSetAllList = contractLoanConditionService
//                        .findLoanConditionSettingByContractMakingId(making.getId(),
//                                ConstantConversionUtil.CONTRACT_LOAN_CONDITION_SETTING_CONDITION);
//                if (null != loanConditionSetAllList && loanConditionSetAllList.size() > 0) {
//                    List<ContractLoanConditionSetting> list2 = loanConditionSetAllList.stream()
//                            .filter(e -> !e.getFixedCondition()).collect(Collectors.toList());
//                    String orderNumbers = "";
//                    if (null != list2 && list2.size() > 0) {
//                        for (ContractLoanConditionSetting setting : list2) {
//                            Map<String, Object> map2 = new HashMap<>();
//                            map2.put("orderNumber", setting.getOrderNumber());
//                            map2.put("condition", setting.getLoanCondition());
//                            orderNumbers = orderNumbers + setting.getOrderNumber() + "、";
//                            listMap2.add(map2);
//                        }
//                    }
//                    dataMap.put("listMap2", listMap2);
//                    dataMap.put("orderNumbers", orderNumbers);
//                }
//                List<Map<String, Object>> listMap3 = new ArrayList<>();
//                BigDecimal receivableAmountTotal = BigDecimal.ZERO;
//                BigDecimal receivableNetAmountTotal = BigDecimal.ZERO;
//                BigDecimal invoiceAmmountTotal = BigDecimal.ZERO;
//                if (list3 != null && list3.size() > 0) {
//                    for (int i = 0; i < list3.size(); i++) {
//                        ContractDomesticAccountReceivable contractDomesticAccountReceivable = list3.get(0);
//                        com.sunxung.factoring.entity.sys.Dictionary dictionary = contractDomesticAccountReceivable.getCurrency();
//                        String currencyName = dictionary.getCode();
//                        dataMap.put("currencyName", currencyName);
//                        ContractDomesticAccountReceivable receivable = list3.get(i);
//                        Map<String, Object> map3 = new HashMap<>();
//                        int m = i + 1;
//                        map3.put("i", m);
//                        map3.put("contractNo", receivable.getContractNo());
//                        map3.put("contractName", receivable.getContractName());
//                        map3.put("debtor", receivable.getDebtor());
//                        map3.put("receivableType", receivable.getAccountsReceivableType());
//                        map3.put("receivableAmount", receivable.getAccountsReceivableAmount().toString());
//                        map3.put("receivableNetAmount", receivable.getAccountsReceivableNetAmount().toString());
//                        if (null != receivable.getTerm()) {
//                            map3.put("term", receivable.getTerm());
//                        }
//                        if (null != receivable.getEndDate()) {
//                            map3.put("expiryDate", DateUtil.formateYMD(receivable.getEndDate()));
//                        }
//                        receivableAmountTotal = receivableAmountTotal.add(receivable.getAccountsReceivableAmount());
//                        receivableNetAmountTotal = receivableNetAmountTotal.add(receivable.getAccountsReceivableNetAmount());
//                        List<ContractDomesticInvoiceInfo> invoiceInfoList = receivable.getDomesticInvoiceInfoList();
//                        String invoice = "";
//                        if (invoiceInfoList != null && invoiceInfoList.size() > 0) {
//                            for (int j = 0; j < invoiceInfoList.size(); j++) {
//                                Integer n = j + 1;
//                                invoice = invoice + "发票" + n + "\n" + "票号:" + invoiceInfoList.get(j).getInvoiceNo() + "\n" + "金额: " + invoiceInfoList.get(j).getInvoiceAmmount() + dictionary.getCode() + "\n";
//                                invoiceAmmountTotal = invoiceAmmountTotal.add(invoiceInfoList.get(j).getInvoiceAmmount());
//                            }
//
//                        }
//                        dataMap.put("receivableAmountTotal", receivableAmountTotal.toString());
//                        dataMap.put("receivableNetAmountTotal", receivableNetAmountTotal.toString());
//                        dataMap.put("invoiceAmmountTotal", invoiceAmmountTotal);
//                        map3.put("invoice", invoice);
//                        listMap3.add(map3);
//                    }
//                    dataMap.put("receivableAmountTotal", receivableAmountTotal);
//                    dataMap.put("receivableNetAmountTotal", receivableNetAmountTotal);
//                    dataMap.put("invoiceAmmountTotal", invoiceAmmountTotal);
//                }
//                if (list4 != null && list4.size() > 0) {
//                    for (int i = 0; i < list4.size(); i++) {
//                        ContractExportAccountReceivable contractExportAccountReceivable = list4.get(0);
//                        Dictionary dictionary = contractExportAccountReceivable.getCurrency();
//                        String currencyName = dictionary.getCode();
//                        dataMap.put("currencyName", currencyName);
//                        ContractExportAccountReceivable receivable = list4.get(i);
//                        Map<String, Object> map3 = new HashMap<>();
//                        int m = i + 1;
//                        map3.put("i", m);
//                        map3.put("contractNo", receivable.getContractNo());
//                        map3.put("contractName", receivable.getContractName());
//                        map3.put("debtor", receivable.getDebtor());
//                        map3.put("receivableType", receivable.getAccountsReceivableType());
//                        map3.put("receivableAmount", receivable.getAccountsReceivableAmount().toString());
//                        map3.put("receivableNetAmount", receivable.getAccountsReceivableNetAmount().toString());
//                        if (null != receivable.getTerm()) {
//                            map3.put("term", receivable.getTerm());
//                        }
//                        if (null != receivable.getEndDate()) {
//                            map3.put("expiryDate", DateUtil.formateYMD(receivable.getEndDate()));
//                        }
//                        map3.put("financingPeriod", financingPeriod);
//                        receivableAmountTotal = receivableAmountTotal.add(receivable.getAccountsReceivableAmount());
//                        receivableNetAmountTotal = receivableNetAmountTotal.add(receivable.getAccountsReceivableNetAmount());
//                        List<ContractExportInvoiceInfo> invoiceInfoList = receivable.getExportInvoiceInfoList();
//                        String invoiceNo = "";
//                        String invoiceAmmount = "";
//                        String invoice = "";
//                        if (invoiceInfoList != null && invoiceInfoList.size() > 0) {
//                            for (int j = 0; j < invoiceInfoList.size(); j++) {
//                                Integer n = j + 1;
//                                invoice = invoice + "发票" + n + "\n" + "票号:" + invoiceInfoList.get(j).getInvoiceNo() + "\n" + "金额: " + invoiceInfoList.get(j).getInvoiceAmmount() + dictionary.getCode() + "\n";
//                                invoiceAmmountTotal = invoiceAmmountTotal.add(invoiceInfoList.get(j).getInvoiceAmmount());
//                            }
//
//                        }
//                        dataMap.put("receivableAmountTotal", receivableAmountTotal.toString());
//                        dataMap.put("receivableNetAmountTotal", receivableNetAmountTotal.toString());
//                        dataMap.put("invoiceAmmountTotal", invoiceAmmountTotal);
//                        map3.put("invoice", invoice);
//                        map3.put("invoiceAmmount", invoiceAmmount);
//                        listMap3.add(map3);
//                    }
//                    dataMap.put("receivableAmountTotal", receivableAmountTotal);
//                    dataMap.put("receivableNetAmountTotal", receivableNetAmountTotal);
//                    dataMap.put("invoiceAmmountTotal", invoiceAmmountTotal);
//                }
//                // 授信金额
//                BigDecimal creditLine = null;
//                // 授信金额金额中文
//                String creditLineName = "";
//                //授信余额
//                BigDecimal creditBalance = null;
//                //授信余额中文
//                String creditBalanceName = "";
//                // 授信期限
//                Integer creditTerm = null;
//                // 授信开始年
//                String creditStartYearStr = null;
//                // 授信开始月
//                String creditStartMonthStr = null;
//                // 授信开始日
//                String creditStartDayStr = null;
//                // 授信信息
//                ContractCreditInfo creditInfo = contractCreditInfoService.getByContractMakingId(making.getId());
//                if (null != creditInfo) {
//                    creditLine = creditInfo.getCreditLine();
//                    creditBalance = creditInfo.getCreditBalance();
//                    if (null != creditBalance) {
//                        if (creditBalance.compareTo(BigDecimal.ZERO) == -1) {
//                            creditBalanceName = MoneyToCNFormatUtil.formatToCN(creditBalance.abs().doubleValue());
//                            creditBalanceName = "负" + creditBalanceName;
//                        } else {
//                            creditBalanceName = MoneyToCNFormatUtil.formatToCN(creditBalance.abs().doubleValue());
//                        }
//                    }
//                    // 授信金额中文
//                    if (null != creditLine) {
//                        creditLineName = MoneyToCNFormatUtil.formatToCN(creditLine.doubleValue());
//                    }
//                    // 授信期限
//                    creditTerm = creditInfo.getCreditTerm();
//                    if (null != creditInfo.getCreditStartDate()) {
//                        Date startDate = creditInfo.getCreditStartDate();
//                        creditStartYearStr = DateUtil.getYear(startDate);
//                        creditStartMonthStr = DateUtil.getMonth(startDate);
//                        creditStartDayStr = DateUtil.getDay(startDate);
//                    }
//                }
//                // 合同信息
//                ContractInfo contractInfo = contractInfoService.get(making.getContractInfo().getId());
//                dataMap.put("quotaDisburseBatch", contractInfo.getQuotaDisburseBatch());
//                dataMap.put("contractNo", contractNo);
//                dataMap.put("contractName", contractName);
//                dataMap.put("factoringContractName", factoringContractName);
//                dataMap.put("factoringLegalPersion", factoringLegalPersion);
//                dataMap.put("factoringAgentName", factoringAgentName);
//                dataMap.put("factoringAgentPhone", factoringAgentPhone);
//                dataMap.put("factoringCompanyName", factoringCompanyName);
//                dataMap.put("factoringAddress", factoringAddress);
//                dataMap.put("factoringLegalPerson", factoringLegalPerson);
//                dataMap.put("factoringAgent", factoringAgent);
//                dataMap.put("applicantCompanyName", applicantCompanyName);
//                dataMap.put("applicantCompanyAddress", applicantCompanyAddress);
//                dataMap.put("applicantCompanyLegalPerson", applicantCompanyLegalPerson);
//                dataMap.put("applicantContact", master.getApplicantContact());
//                dataMap.put("applicantContactNumber", master.getApplicantContactNumber());
//
//                Integer platformNum = master.getDoubleFactoringType();
//                dataMap.put("platformNum", platformNum);
//                if (master.getSpecialAgreement() != null) {
//                    dataMap.put("specialAgreement", master.getSpecialAgreement());
//                } else {
//                    dataMap.put("specialAgreement", "");
//
//                }
//
//
//                dataMap.put("debtor", debtor);
//                dataMap.put("debtorNum", debtorNum);
//
//
//                dataMap.put("disclosedUndisclosedFactoringNum", disclosedUndisclosedFactoringNum);
//                dataMap.put("serviceScopeId", serviceScopeId);
//                // 金额数字处理：千位分隔，并保留两位小数，如192->192.00;0->0.00，下同！
//                dataMap.put("financingAmmount", NumberFormatUtil.convertDecimal(financingAmmount,
//                        NumberFormatUtil.THOUSAND_SEPARATOR_TWO_DECIMAL));
//                dataMap.put("currency", currency);
//                dataMap.put("cName", currency.getName());
//                dataMap.put("eName", currency.getCode());
//                dataMap.put("financingAmmountCname", financingAmmountCname);
//                dataMap.put("creditGuaranteeRiskAmount", creditGuaranteeRiskAmount);
//                dataMap.put("creditGuaranteeRiskAmountName", creditGuaranteeRiskAmountName);
//                dataMap.put("receivableTransferRateStr", receivableTransferRateStr);
//                dataMap.put("principalCollectionMethod", principalCollectionMethod);
//                dataMap.put("financingPeriod", financingPeriod);
//                dataMap.put("startingDateTypesNum", startingDateTypesNum);
//                dataMap.put("yearStr", yearStr);
//                dataMap.put("monthStr", monthStr);
//                dataMap.put("dayStr", dayStr);
//                dataMap.put("loanConditionList", loanConditionListMap);
//                dataMap.put("loanConditionListLength", loanConditionListLength);
//                dataMap.put("amountTotal",
//                        NumberFormatUtil.convertDecimal(amountTotal, NumberFormatUtil.THOUSAND_SEPARATOR_TWO_DECIMAL));
//                dataMap.put("amountTotalName", amountTotalName);
//                dataMap.put("financingRateStr", financingRateStr);
//                dataMap.put("badDebtGuaranteeRate", badDebtGuaranteeRate);
//                dataMap.put("financingInterest", NumberFormatUtil.convertDecimal(financingInterest,
//                        NumberFormatUtil.THOUSAND_SEPARATOR_TWO_DECIMAL));
//                dataMap.put("financingInterestName", financingInterestName);
//                dataMap.put("overdueInterestRateStr", overdueInterestRateStr);
//                dataMap.put("paymentMethod", paymentMethod);
//                dataMap.put("marginRatioStr", marginRatioStr);
//                dataMap.put("marginCollectionMethod", marginCollectionMethod);
//                dataMap.put("marginReturnMethod", marginReturnMethod);
//                dataMap.put("marginReturnCondition", marginReturnCondition);
//                dataMap.put("manageFeeAmount", NumberFormatUtil.convertDecimal(manageFeeAmount,
//                        NumberFormatUtil.THOUSAND_SEPARATOR_TWO_DECIMAL));
//                dataMap.put("manageFeeAmountName", manageFeeAmountName);
//                dataMap.put("manageFeeCollectionMethod", manageFeeCollectionMethod);
//                dataMap.put("otherFee",
//                        NumberFormatUtil.convertDecimal(otherFee, NumberFormatUtil.THOUSAND_SEPARATOR_TWO_DECIMAL));
//                dataMap.put("otherFeeName", otherFeeName);
//                dataMap.put("transferNoticeMethodId", transferNoticeMethodId);
//                dataMap.put("masterContract", master);
//                dataMap.put("list1", listMap1);
//                dataMap.put("list3", listMap3);
//                dataMap.put("marginLoanLastDateStr", marginLoanLastDateStr);
//                dataMap.put("creditBalance", NumberFormatUtil.convertDecimal(creditBalance, NumberFormatUtil.THOUSAND_SEPARATOR_TWO_DECIMAL));
//                dataMap.put("creditBalanceName", creditBalanceName);
//                dataMap.put("creditEcurrency", currency.getCode());
//                dataMap.put("creditCcurrency", currency.getName());
//                dataMap.put("creditLine", NumberFormatUtil.convertDecimal(creditLine, NumberFormatUtil.THOUSAND_SEPARATOR_TWO_DECIMAL));
//                dataMap.put("creditLineName", creditLineName);
//                dataMap.put("creditTerm", creditTerm);
//                dataMap.put("creditStartYearStr", creditStartYearStr);
//                dataMap.put("creditStartMonthStr", creditStartMonthStr);
//                dataMap.put("creditStartDayStr", creditStartDayStr);
//                dataMap.put("quotaDisburseBatch", contractInfo.getQuotaDisburseBatch());
//                dataMap.put("poolFactoringFinancingConfirmNo", poolFactoringFinancingConfirmNo);
//                dataMap.put("poolFactoringFinancingConfirmAgree", poolFactoringFinancingConfirmAgree);
//                dataMap.put("specialAgreement", "4、" + specialAgreement);
//                dataMap.put("factoringSpecialAgreement", specialAgreement);
//                dataMap.put("specialAgreementStr", specialAgreementStr);
//                dataMap.put("factoringAccountName", factoringAccountName);
//                dataMap.put("factoringAccount", factoringAccount);
//                dataMap.put("factoringAccountBank", factoringAccountBank);
//                dataMap.put("factoringAccountName1", factoringAccountName1);
//                dataMap.put("factoringAccount1", factoringAccount1);
//                dataMap.put("factoringAccountBank1", factoringAccountBank1);
//                dataMap.put("factoringAccountName2", factoringAccountName2);
//                dataMap.put("factoringAccount2", factoringAccount2);
//                dataMap.put("factoringAccountBank2", factoringAccountBank2);
//                dataMap.put("applicantDesignatedAccountName", applicantDesignatedAccountName);
//                dataMap.put("applicantDesignatedAccount", applicantDesignatedAccount);
//                dataMap.put("applicantDesignatedbank", applicantDesignatedbank);
//                dataMap.put("ourAccountName", ourAccountName);
//                dataMap.put("ourAccount", ourAccount);
//                dataMap.put("ourAccountBank", ourAccountBank);
//                dataMap.put("contractNum", contractNum);
//                dataMap.put("year", year);
//                dataMap.put("month", month);
//                dataMap.put("day", day);
//                //出口保理债务人只有一个
//                ContractMasterContractDebtor exportDebtor = debtorList.get(0);
//                dataMap.put("exportDebtorCompanyName", exportDebtor.getCompanyName());
////                if (exportDebtor.getCompanyName().equals("西安长银保国际贸易有限公司")) {
////                    dataMap.put("exportDebtorAddress", dictionaryService.getByCode(ConstantUtil.OUR_COMPANY_ADDRESS).getName());
////                } else {
////
////                }
//                dataMap.put("exportDebtorAddress", exportDebtor.getAddress());
//                dataMap.put("exportDebtorLegalPerson", exportDebtor.getLegalPerson());
//                dataMap.put("exportDebtorContact", exportDebtor.getContact());
//                dataMap.put("exportDebtorNumber", exportDebtor.getContactNumer());
//                dataMap.put("date", "日期：" + year + "年" + month + "月" + day + "日");
//                if (master.getDoubleFactoringType().equals(1)) {
//                    dataMap.put("platform", master.getPlatformName());
//                    dataMap.put("platformName", "乙方二（保理申请人）：" + master.getPlatformName());
//                    dataMap.put("platformNameStr", "、" + master.getPlatformName());
////                    if (master.getPlatformName().equals("西安长银保国际贸易有限公司")) {
////                        dataMap.put("platformAddress", dictionaryService.getByCode(ConstantUtil.OUR_COMPANY_ADDRESS).getName());
////                    } else {
////                    }
//                    dataMap.put("platformAddress", master.getPlatformAddress());
//                    dataMap.put("platformLegal", master.getPlatformLegal());
//                    dataMap.put("platformContact", master.getPlatformContact());
//                    dataMap.put("platformContactPhone", master.getPlatformContactPhone());
//                } else {
//                    dataMap.put("platform", "-");
//                    dataMap.put("platformAddress", "-");
//                    dataMap.put("platformLegal", "-");
//                    dataMap.put("platformContact", "-");
//                    dataMap.put("platformContactPhone", "-");
//                }
//                dataMap.put("managementFeeCollectionMethod", financingInfo.getManagementFeeCollectionMethod());// 管理费支付方式
//                dataMap.put("otherFeeCollectionMethod", otherFeeCollectionMethod);
//                //放款条件（新增）
//                ExcelUtils excel = new ExcelUtils();
//                if (type.equals(ConstantConversionUtil.POOLFACTORINGFINANCINGCONFIRM)) {
//                    String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.POOLFACTORINGFINANCINGCONFIRM, making.getTemplateVersionId());
//                    LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                    Configure configure = Configure.builder().bind("listMap2", policy)
//                            .bind("mapList", policy)
//                            .bind("changeList", policy)
//                            .bind("list3", policy)
//                            .bind("loanConditionListMap", policy)
//                            .build();
//                    if (master.getDoubleFactoringType().equals(1)) {
//                        if ((master.getPlatformName() != null && !master.getPlatformName().equals(""))) {
//                            EnterpriseBusinessInfo enterpriseBusinessInfo = enterpriseBusinessInfoService.getEnterpriseByKeyword(master.getPlatformName(), null, null);
//                            HashMap<String, String> hashMap = new HashMap<>();
//                            hashMap.put("platformName", enterpriseBusinessInfo.getEnterpriseCN());
//                            dataMap.put("doubleFactoringType", hashMap);
//                        } else {
//                            dataMap.put("doubleFactoringType", false);
//                        }
//                    } else {
//                        dataMap.put("doubleFactoringType", false);
//                    }
//                    template = XWPFTemplate.compile(templatePath, configure).render(dataMap);
//                    path = FileUtil.getAbsolutePath("池保理保理融资确认书" + master.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                    File file = new File(path);
//                    if (!file.exists()) {
//                        FileUtils.createParentDirectories(file);
//                    }
//                    template.writeToFile(path);
//                    fileAllList.add(file);
//                } else if (type.equals(ConstantConversionUtil.POOLFACTORINGFINANCINGCONFIRMTAX)) {
//                    String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.POOLFACTORINGFINANCINGCONFIRMTAX, making.getTemplateVersionId());
//                    LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                    Configure configure = Configure.builder().bind("listMap2", policy)
//                            .bind("mapList", policy)
//                            .bind("changeList", policy)
//                            .bind("list3", policy)
//                            .bind("loanConditionListMap", policy)
//                            .build();
//                    template = XWPFTemplate.compile(templatePath, configure).render(dataMap);
//                    path = FileUtil.getAbsolutePath("池保理保理融资确认书(税理通)" + master.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                    File file = new File(path);
//                    if (!file.exists()) {
//                        FileUtils.createParentDirectories(file);
//                    }
//                    template.writeToFile(path);
//                    fileAllList.add(file);
//                } else if (type.equals(ConstantConversionUtil.POOLFACTORINGINFODOMESTIC)) {
//                    String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.POOLFACTORINGINFODOMESTIC, making.getTemplateVersionId());
//                    LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                    Configure configure = Configure.builder().bind("listMap2", policy)
//                            .bind("mapList", policy)
//                            .bind("loanConditionList", policy)
//                            .bind("listMap3", policy)
//                            .build();
//                    if (master.getDoubleFactoringType().equals(1)) {
//                        if ((master.getPlatformName() != null && !master.getPlatformName().equals(""))) {
//                            EnterpriseBusinessInfo enterpriseBusinessInfo = enterpriseBusinessInfoService.getEnterpriseByKeyword(master.getPlatformName(), null, null);
//                            HashMap<String, String> hashMap = new HashMap<>();
//                            hashMap.put("platformName", enterpriseBusinessInfo.getEnterpriseCN());
//                            dataMap.put("doubleFactoringType", hashMap);
//                        } else {
//                            dataMap.put("doubleFactoringType", false);
//                        }
//                    } else {
//                        dataMap.put("doubleFactoringType", false);
//                    }
//                    template = XWPFTemplate.compile(templatePath, configure).render(dataMap);
//                    path = FileUtil.getAbsolutePath("池保理保理信息表-国内适用" + master.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                    File file = new File(path);
//                    if (!file.exists()) {
//                        FileUtils.createParentDirectories(file);
//                    }
//                    template.writeToFile(path);
//                    fileAllList.add(file);
//                } else if (type.equals(ConstantConversionUtil.INTERNATIONALCHASEFACTORINGFINANCINGCONFIRM)) {
//                    String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.INTERNATIONALCHASEFACTORINGFINANCINGCONFIRM, making.getTemplateVersionId());
//                    LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                    Configure configure = Configure.builder().bind("listMap2", policy)
//                            .bind("mapList", policy)
//                            .bind("changeList", policy)
//                            .bind("list3", policy)
//                            .bind("loanConditionListMap", policy)
//                            .build();
//                    template = XWPFTemplate.compile(templatePath, configure).render(dataMap);
//                    path = FileUtil.getAbsolutePath("保理融资确认书" + master.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                    File file = new File(path);
//                    if (!file.exists()) {
//                        FileUtils.createParentDirectories(file);
//                    }
//                    template.writeToFile(path);
//                    fileAllList.add(file);
//                } else if (type.equals(ConstantConversionUtil.INTERNATIONALCHASEFACTORINGINFO)) {
//                    String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.INTERNATIONALCHASEFACTORINGINFO, making.getTemplateVersionId());
//                    LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                    Configure configure = Configure.builder().bind("listMap2", policy)
//                            .bind("loanConditionList", policy)
//                            .bind("mapList", policy)
//                            .build();
//                    template = XWPFTemplate.compile(templatePath, configure).render(dataMap);
//                    path = FileUtil.getAbsolutePath("国际有追保理信息表" + master.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                    File file = new File(path);
//                    if (!file.exists()) {
//                        FileUtils.createParentDirectories(file);
//                    }
//                    template.writeToFile(path);
//                    fileAllList.add(file);
//                } else if (type.equals(ConstantConversionUtil.DOMESTICCHASEFACTORINGINFO)) {
//                    String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.DOMESTICCHASEFACTORINGINFO, making.getTemplateVersionId());
//                    LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                    Configure configure = Configure.builder().bind("listMap2", policy)
//                            .bind("mapList", policy)
//                            .build();
//                    template = XWPFTemplate.compile(templatePath, configure).render(dataMap);
//                    path = FileUtil.getAbsolutePath("国内有追保理信息表" + master.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                    File file = new File(path);
//                    if (!file.exists()) {
//                        FileUtils.createParentDirectories(file);
//                    }
//                    template.writeToFile(path);
//                    fileAllList.add(file);
//                } else if (type.equals(ConstantConversionUtil.DOMESTICNOCHASEFACTORINGINFO)) {
//                    String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.DOMESTICNOCHASEFACTORINGINFO, making.getTemplateVersionId());
//                    LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                    Configure configure = Configure.builder().bind("listMap2", policy)
//                            .bind("mapList", policy)
//                            .build();
//                    template = XWPFTemplate.compile(templatePath, configure).render(dataMap);
//                    path = FileUtil.getAbsolutePath("国内无追保理信息表" + master.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                    File file = new File(path);
//                    if (!file.exists()) {
//                        FileUtils.createParentDirectories(file);
//                    }
//                    template.writeToFile(path);
//                    fileAllList.add(file);
//                } else if (type.equals(ConstantConversionUtil.DOMESTICCHASEFACTORINGINFOTICKETING)) {
//                    String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.DOMESTICCHASEFACTORINGINFOTICKETING, making.getTemplateVersionId());
//                    LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                    Configure configure = Configure.builder().bind("listMap2", policy)
//                            .bind("mapList", policy)
//                            .bind("changeList", policy)
//                            .bind("list3", policy)
//                            .bind("loanConditionListMap", policy)
//                            .build();
//                    template = XWPFTemplate.compile(templatePath, configure).render(dataMap);
//                    path = FileUtil.getAbsolutePath("国内有追保理信息表（全保理、票理通、租赁保理化）" + master.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                    File file = new File(path);
//                    if (!file.exists()) {
//                        FileUtils.createParentDirectories(file);
//                    }
//                    template.writeToFile(path);
//                    fileAllList.add(file);
//                } else if (type.equals(ConstantConversionUtil.FACTORINGSERVICECONFIRMATION)) {
//                    String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.FACTORINGSERVICECONFIRMATION, making.getTemplateVersionId());
//                    LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                    Configure configure = Configure.builder().bind("listMap2", policy)
//                            .build();
//                    if (master.getDoubleFactoringType().equals(1)) {
//                        if ((master.getPlatformName() != null && !master.getPlatformName().equals(""))) {
//                            EnterpriseBusinessInfo enterpriseBusinessInfo = enterpriseBusinessInfoService.getEnterpriseByKeyword(master.getPlatformName(), null, null);
//                            HashMap<String, String> hashMap = new HashMap<>();
//                            hashMap.put("platformName", enterpriseBusinessInfo.getEnterpriseCN());
//                            dataMap.put("doubleFactoringType", hashMap);
//                        } else {
//                            dataMap.put("doubleFactoringType", false);
//                        }
//                    } else {
//                        dataMap.put("doubleFactoringType", false);
//                    }
//                    template = XWPFTemplate.compile(templatePath, configure).render(dataMap);
//                    path = FileUtil.getAbsolutePath("保理服务确认书" + master.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                    if (templatePath == null) {
//                        throw new BusinessException(CodeUtil.FAIL, "下载保理服务确认书出错");
//                    }
//                    File file = new File(path);
//                    if (!file.exists()) {
//                        FileUtils.createParentDirectories(file);
//                    }
//                    template.writeToFile(path);
//                    fileAllList.add(file);
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new BusinessException(CodeUtil.FAIL, "下载保理信息表出错" + e.getMessage());
//        }
//    }

    /**
     * 下载应收账款转让通知书
     */
//    private void dealNewNoticeDownloadAll(ContractInfo making, List<File> fileAllList, String type) {
//        String path = null;
//        XWPFTemplate template = null;
//        try {
//            if (making.getTransferReceivable()) {
//                Map<String, Object> noticeMap = new HashMap<>();
//                autoAccountReceivable(making);
//                if (null != making && null != making.getMasterContract()) {
//                    // 主合同信息
//                    ContractMasterContract masterContract = making.getMasterContract();
//                    //主合同信息-债务人
//                    List<ContractMasterContractDebtor> debtorList = masterContract.getDebtorList();
//                    // 合同名称
//                    String contractName = masterContract.getContractName();
//                    // 保理合同编号
//                    String factoringContractNo = masterContract.getContractNo();
//                    // 保理商
//                    String factoringName = masterContract.getFactoringName();
//                    //保理商联系人
//                    String factoringAgentName = masterContract.getFactoringAgentName();
//                    //保理商联系人电话
//                    String factoringAgentPhone = masterContract.getFactoringAgentPhone();
//                    //保理商联系人邮箱
//                    String factoringAgentEmail = masterContract.getFactoringAgentEmail();
//                    //保理商注册地址
//                    String factoringAddress = masterContract.getFactoringAddress();
//                    //保理商法人
//                    String factoringLegalPersion = masterContract.getFactoringLegalPersion();
//                    //我司指定账户户名
//                    String ourAccountName = masterContract.getOurAccountName();
//                    //我司指定账户开户行
//                    String ourAccountBank = masterContract.getOurAccountBank();
//                    //贸易平台公司名称
//                    String platformCompanyName = masterContract.getPlatformName();
//                    //贸易平台法人
//                    String platformLegal = masterContract.getPlatformLegal();
//                    // 保理申请人公司名称
//                    String applicantCompanyName = masterContract.getApplicantCompanyName();
//                    //保理申请人公司法人
//                    String applicantLegalPerson = masterContract.getApplicantCompanyLegalPerson();
//                    //保理申请人公司地址
//                    String applicantCompanyAddress = masterContract.getApplicantCompanyAddress();
//                    // 保理申请人联系人
//                    String applicantContact = masterContract.getApplicantContact();
//                    //保理申请人联系人电话
//                    String applicantContactNumber = masterContract.getApplicantContactNumber();
//                    // 保理专户户名
//                    String factoringAccountName = masterContract.getFactoringAccountName();
//                    // 保理专户账号
//                    String factoringAccount = masterContract.getFactoringAccount();
//                    // 保理专户开户行
//                    String factoringAccountBank = masterContract.getFactoringAccountBank();
//                    //融资信息
//                    ContractFinancingInfo financingInfo = making.getFinancingInfo();
//                    //融资利率
//                    String financingRateStr = null;
//                    //融资本金+融资利息
//                    BigDecimal financingAmountInterest;
//                    // 明或暗保理
//                    String factoringType = making.getDisclosedUndisclosedFactoring();
//                    // 应收账款转让通知书编号
//                    String noticeNo = making.getNoticeNo();
//                    // 池或非池
//                    String isPool = making.getIsPool();
//                    // 有或无追索权
//                    String recourseRights = making.getRecourseRights();
//                    // 合作业务板块
//                    String businessType = making.getBusinessType();
//                    // 币种英文名称
//                    String currencyName = null;
//                    Dictionary currencyDict = dictionaryService.get(making.getCurrency().getId());
//                    if (null != currencyDict) {
//                        currencyName = currencyDict.getCode();
//                    }
//                    List<Map<String, Object>> masterDebtors = new ArrayList<>();
//                    List<Map<String, Object>> debtors = new ArrayList<>();
//                    Integer m = 0;
//                    if (debtorList != null && debtorList.size() > 0) {
//                        for (ContractMasterContractDebtor masterContractDebtor : debtorList) {
//                            //主合同-债务人公司名称
//                            m++;
//                            Map<String, Object> debtorMap = new HashMap<>();
//                            if (debtorList.size() > 1) {
//                                debtorMap.put("debtorName", masterContractDebtor.getCompanyName() + "、");
//                            } else {
//                                debtorMap.put("debtorName", masterContractDebtor.getCompanyName());
//
//                            }
//                            debtorMap.put("num", "qz" + Integer.toString(m));
//                            masterDebtors.add(debtorMap);
//                            debtors.add(debtorMap);
//                        }
//                    }
//                    if (making.getFinancingInfo().geteTradingType() != null && making.getFinancingInfo().geteTradingType().equals(1)) {
//                        noticeMap.put("masterDebtors", masterDebtors);
//                    }
//                    noticeMap.put("debtors", debtors);
//                    noticeMap.put("noticeNo", noticeNo);
//                    File noticeFile = null;
//                    noticeMap.put("factoringContractNo", factoringContractNo);
//                    noticeMap.put("contractName", contractName);
//                    noticeMap.put("ourAccountName", ourAccountName);
//                    noticeMap.put("ourAccountBank", ourAccountBank);
//                    noticeMap.put("applicantContact", applicantContact);
//                    noticeMap.put("applicantContactNumber", applicantContactNumber);
//                    noticeMap.put("applicantCompanyName", applicantCompanyName);
//                    noticeMap.put("factoringName", factoringName);
//                    noticeMap.put("applicantLegalPerson", applicantLegalPerson);
//                    noticeMap.put("applicantCompanyAddress", applicantCompanyAddress);
//                    noticeMap.put("factoringAccountName", factoringAccountName);
//                    noticeMap.put("factoringAccount", factoringAccount);
//                    noticeMap.put("factoringAccountBank", factoringAccountBank);
//                    noticeMap.put("currencyName", currencyName);
//                    noticeMap.put("factoringAgentName", factoringAgentName);
//                    noticeMap.put("factoringAgentPhone", factoringAgentPhone);
//                    noticeMap.put("factoringAgentEmail", factoringAgentEmail);
//                    noticeMap.put("factoringAddress", dictionaryService.getByCode(ConstantUtil.OUR_COMPANY_ADDRESS).getName());
//                    noticeMap.put("factoringLegalPersion", factoringLegalPersion);
//                    noticeMap.put("financingPeriodInt", financingInfo.getFinancingPeriod());
//                    Date date = new Date();
//                    String day = DateUtil.getDay(date);
//                    String month = DateUtil.getMonth(date);
//                    String year = DateUtil.getYear(date);
//                    noticeMap.put("day", day);
//                    noticeMap.put("month", month);
//                    noticeMap.put("year", year);
//                    noticeMap.put("date", "日期：" + year + "年" + month + "月" + day + "日");
//                    if (masterContract.getDoubleFactoringType().equals(1)) {
//                        noticeMap.put("platformCompanyName", "、" + platformCompanyName);
//                        noticeMap.put("platformName", "乙方二（保理申请人）" + platformCompanyName);
//                        noticeMap.put("platformNameNotice", "乙方二：" + platformCompanyName);//通知书
//                        noticeMap.put("platformLegal", platformLegal);
//                        String platform = "【乙方二名称】 ";
//                        noticeMap.put("two", platform);
//                    }
//                    financingRateStr = PercentageUtil.convertPercentage(financingInfo.getFinancingRate());
//                    if (StringUtil.isNotEmpty(financingRateStr)) {
//                        financingRateStr = StringUtil.subZeroAndDot(financingRateStr.split("%")[0]) + "%";
//                    }
//                    noticeMap.put("financingRateStr", financingRateStr);
//                    BigDecimal financingAmmount = financingInfo.getFinancingAmmount();
//                    financingAmountInterest = financingAmmount.add(financingInfo.getFinancingInterest());
//                    noticeMap.put("financingAmountInterest", financingAmountInterest);
//                    Map<Long, List<Map<String, Object>>> groupingByMap = new HashMap<>();
//                    if (StringUtil.isNotEmpty(businessType)
//                            && businessType.equals(ConstantConversionUtil.DOMESTIC_FACTORING)) {
//                        List<ContractDomesticAccountReceivable> domesticList = making
//                                .getDomesticAccountReceivableList();
//                        if (null != domesticList && domesticList.size() > 0) {
////                            List<Map<String,Object>> changeList = new ArrayList<>();
//                            Map<Long, List<ContractDomesticAccountReceivable>> debtorMap = domesticList.stream()
//                                    .collect(Collectors.groupingBy(ContractDomesticAccountReceivable::getDebtorId));
//                            Iterator<Map.Entry<Long, List<ContractDomesticAccountReceivable>>> entries = debtorMap
//                                    .entrySet().iterator();
//                            while (entries.hasNext()) {
//                                Map.Entry<Long, List<ContractDomesticAccountReceivable>> entry = entries.next();
//                                List<ContractDomesticAccountReceivable> receivableList = entry.getValue();
//                                List<Map<String, Object>> changeList = new ArrayList<>();
//                                int i = 0;
//                                BigDecimal invoiceAmmountAll = BigDecimal.ZERO;
//                                BigDecimal receivableAmountAll = BigDecimal.ZERO;
//                                for (ContractDomesticAccountReceivable domestic : receivableList) {
//                                    i = i + 1;
//                                    Map<String, Object> iMap = new HashMap<>();
//                                    iMap.put("recordNo", i);
//                                    iMap.put("contractName", domestic.getContractName());
//                                    iMap.put("contractNo", domestic.getContractNo());
//                                    iMap.put("currency", domestic.getCurrency().getCode());
//                                    iMap.put("debtor", domestic.getDebtor());
//                                    iMap.put("accountsReceivableType", domestic.getAccountsReceivableType());
//                                    iMap.put("accountsReceivableAmount", domestic.getAccountsReceivableAmount());
//                                    receivableAmountAll = receivableAmountAll.add(domestic.getAccountsReceivableAmount());
//                                    //应收账款净额
//                                    iMap.put("netAmount", domestic.getAccountsReceivableNetAmount());
//                                    iMap.put("invoiceAmountTotal", domestic.getInvoiceAmmountTotal());
//                                    if (domestic.getInvoiceAmmountTotal() != null) {
//                                        invoiceAmmountAll = invoiceAmmountAll.add(domestic.getInvoiceAmmountTotal());
//                                    }
//                                    if (making.getPlanFactoringProducts().getCode().equals(FactoringProductsDomesticDict.ChildEnum.FPD_TRADING_FACTORING.getCode())) {
//
//                                        iMap.put("financingPeriod", DateUtil.formateYMD(domestic.getEndDate()));
//
//                                    } else {
//                                        iMap.put("financingPeriod", "自支付融资款之日起" + financingInfo.getFinancingPeriod() + "天");
//                                    }
//                                    if (null != domestic.getEndDate()) {
//                                        iMap.put("expiryDate", DateUtil.formateYMD(domestic.getEndDate()));
//                                    }
//                                    if (null != domestic.getTerm()) {
//                                        iMap.put("term", domestic.getTerm());
//                                    }
//                                    String invoice = "";
//                                    String invoiceNo = "";
//                                    BigDecimal invoiceAmmount = BigDecimal.ZERO;
//                                    List<ContractDomesticInvoiceInfo> domesticInvoiceInfoList = domestic.getDomesticInvoiceInfoList();
//                                    if (domesticInvoiceInfoList != null && domesticInvoiceInfoList.size() > 0) {
//                                        for (int j = 0; j < domesticInvoiceInfoList.size(); j++) {
//                                            int n = j + 1;
//                                            invoiceNo = domesticInvoiceInfoList.get(j).getInvoiceNo();
//                                            invoiceAmmount = domesticInvoiceInfoList.get(j).getInvoiceAmmount();
//                                            invoice = invoice + "发票" + n + "\n" + "票号:" + invoiceNo + "\n" + "金额: " + invoiceAmmount + domestic.getCurrency().getCode() + "\n";
//                                            if (domesticInvoiceInfoList.get(j).getInvoiceAmmount().compareTo(BigDecimal.ZERO) == 0) {
//                                                invoice = "——";
//                                            }
//                                        }
//                                    } else {
//                                        invoice = "——";
//                                    }
//                                    iMap.put("invoice", invoice);
//
////                                    if(domesticInvoiceInfoList.size()==0){
////                                        ContractDomesticInvoiceInfo contractDomesticInvoiceInfo = new ContractDomesticInvoiceInfo();
////                                        contractDomesticInvoiceInfo.setInvoiceNo("");
////                                        contractDomesticInvoiceInfo.setInvoiceAmmount(BigDecimal.ZERO);
////                                        Map<String, Object> invoiceMap = new HashMap<>();
////                                        invoiceMap.put("invoiceNo",contractDomesticInvoiceInfo.getInvoiceNo());
////                                        invoiceMap.put("invoiceAmmount",contractDomesticInvoiceInfo.getInvoiceAmmount());
////                                        invoice = invoice + contractDomesticInvoiceInfo.getInvoiceNo()+" "+contractDomesticInvoiceInfo.getInvoiceAmmount()+"\n";
////
////                                        invoiceList.add(invoiceMap);
////                                    }
//                                    changeList.add(iMap);
//                                    noticeMap.put("receivableCurrency", receivableList.get(0).getCurrency().getCode());
//                                }
//                                noticeMap.put("changeList", changeList);
//                                noticeMap.put("receivableAmountAll", receivableAmountAll);
//                                noticeMap.put("invoiceAmmountAll", invoiceAmmountAll);
//                                groupingByMap.put(entry.getKey(), changeList);
//                            }
//                        }
//                    }
//                    if (StringUtil.isNotEmpty(businessType)
//                            && businessType.equals(ConstantConversionUtil.EXPORT_FACTORING)) {
//                        List<ContractExportAccountReceivable> exportList = making.getExportAccountReceivableList();
//                        if (null != exportList && exportList.size() > 0) {
//                            Map<Long, List<ContractExportAccountReceivable>> debtorMap = exportList.stream().collect(
//                                    Collectors.groupingBy(ContractExportAccountReceivable::getDebtorEntForeignId));
//                            Iterator<Map.Entry<Long, List<ContractExportAccountReceivable>>> entries = debtorMap.entrySet()
//                                    .iterator();
//                            while (entries.hasNext()) {
//                                Map.Entry<Long, List<ContractExportAccountReceivable>> entry = entries.next();
//                                List<ContractExportAccountReceivable> receivableList = entry.getValue();
//                                List<Map<String, Object>> changeList = new ArrayList<>();
//                                int i = 0;
//                                BigDecimal invoiceAmmountAll = BigDecimal.ZERO;
//                                BigDecimal receivableAmountAll = BigDecimal.ZERO;
//                                for (ContractExportAccountReceivable export : receivableList) {
//                                    i = i + 1;
//                                    Map<String, Object> iMap = new HashMap<>();
//                                    iMap.put("recordNo", i);
//                                    iMap.put("contractName", export.getContractName());
//                                    iMap.put("financingPeriod", financingInfo.getFinancingPeriod());
//                                    iMap.put("contractNo", export.getContractNo());
//                                    iMap.put("debtor", export.getDebtor());
//                                    iMap.put("accountsReceivableType", export.getAccountsReceivableType());
//                                    iMap.put("accountsReceivableAmount", export.getAccountsReceivableAmount());
//                                    iMap.put("currency", export.getCurrency().getCode());
//                                    iMap.put("netAmount", export.getAccountsReceivableNetAmount());
//                                    iMap.put("invoiceAmountTotal", export.getInvoiceAmmountTotal());
//                                    receivableAmountAll = receivableAmountAll.add(export.getAccountsReceivableAmount());
//                                    invoiceAmmountAll = invoiceAmmountAll.add(export.getInvoiceAmmountTotal());
//                                    if (null != export.getTerm()) {
//                                        iMap.put("term", export.getTerm());
//                                    }
//                                    if (null != export.getEndDate()) {
//                                        iMap.put("expiryDate", DateUtil.formateYMD(export.getEndDate()));
//                                    }
//                                    String invoice = "";
//                                    String invoiceNo = "";
//                                    BigDecimal invoiceAmmount = BigDecimal.ZERO;
//                                    List<ContractExportInvoiceInfo> exportInvoiceInfos = export.getExportInvoiceInfoList();
//                                    if (exportInvoiceInfos != null && exportInvoiceInfos.size() > 0) {
//                                        for (int j = 0; j < exportInvoiceInfos.size(); j++) {
//                                            invoiceNo = exportInvoiceInfos.get(j).getInvoiceNo();
//                                            invoiceAmmount = exportInvoiceInfos.get(j).getInvoiceAmmount();
//                                            int n = j + 1;
//                                            invoice = invoice + "发票" + n + "\n" + "票号:" + invoiceNo + "\n" + "金额: " + invoiceAmmount + export.getCurrency().getCode() + "\n";
//                                            if (exportInvoiceInfos.get(j).getInvoiceAmmount().compareTo(BigDecimal.ZERO) == 0) {
//                                                invoice = "——";
//                                            }
//                                        }
//                                    } else {
//                                        invoice = "——";
//                                    }
//                                    iMap.put("invoiceNo", invoiceNo);
//                                    iMap.put("invoiceAmmount", invoiceAmmount);
//                                    iMap.put("invoice", invoice);
////                                    if(invoiceList.size()==0){
////                                        Map<String, Object> invoiceMap = new HashMap<>();
////                                        ContractExportInvoiceInfo contractExportInvoiceInfo = new ContractExportInvoiceInfo();
////                                        contractExportInvoiceInfo.setInvoiceNo("");
////                                        contractExportInvoiceInfo.setInvoiceAmmount(BigDecimal.ZERO);
////                                        invoiceMap.put("invoiceNo",contractExportInvoiceInfo.getInvoiceNo());
////                                        invoiceMap.put("invoiceAmmount",contractExportInvoiceInfo.getInvoiceAmmount());
////                                        invoiceList.add(invoiceMap);
////                                    }
//
//                                    changeList.add(iMap);
//                                    noticeMap.put("receivableCurrency", receivableList.get(0).getCurrency().getCode());
//                                }
//                                noticeMap.put("invoiceAmmountAll", invoiceAmmountAll);
//                                noticeMap.put("receivableAmountAll", receivableAmountAll);
//                                noticeMap.put("changeList", changeList);
////                                groupingByMap.put(entry.getKey(), changeList);
//                            }
//                        }
//                    }
//                    //国内
//                    if (type.equals(ConstantConversionUtil.POOLACCOUNTRECEIVABLETRANSFERNOTICEDOMESTICBRIGHT)) {
//                        String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.POOLACCOUNTRECEIVABLETRANSFERNOTICEDOMESTICBRIGHT, making.getTemplateVersionId());
//                        if (templatePath == null) {
//                            throw new BusinessException(CodeUtil.FAIL, "下载池保理应收账款转让通知书出错");
//                        }
//                        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                        Configure configure = Configure.builder().bind("changeList", policy).build();
//                        template = XWPFTemplate.compile(templatePath, configure).render(noticeMap);
//                        path = FileUtil.getAbsolutePath("池保理应收账款转让通知书—国内适用—明保理适用" + masterContract.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                        File file = new File(path);
//                        if (!file.getParentFile().exists()) {
//                            file.getParentFile().mkdirs();
//                        }
//                        template.writeToFile(file.getPath());
//                        fileAllList.add(file);
//                    } else if (type.equals(ConstantConversionUtil.POOLACCOUNTRECEIVABLETRANSFERNOTICEDOMESTICDARK)) {
//                        String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.POOLACCOUNTRECEIVABLETRANSFERNOTICEDOMESTICDARK, making.getTemplateVersionId());
//                        if (templatePath == null) {
//                            throw new BusinessException(CodeUtil.FAIL, "下载池保理应收账款转让通知书出错");
//                        }
//                        if (masterContract.getDoubleFactoringType().equals(1)) {
//                            if ((masterContract.getPlatformName() != null && !masterContract.getPlatformName().equals(""))) {
//                                EnterpriseBusinessInfo enterpriseBusinessInfo = enterpriseBusinessInfoService.getEnterpriseByKeyword(masterContract.getPlatformName(), null, null);
//                                HashMap<String, String> hashMap = new HashMap<>();
//                                hashMap.put("notice2", enterpriseBusinessInfo.getEnterpriseCN());
//                                noticeMap.put("doubleFactoringType", hashMap);
//                            } else {
//                                noticeMap.put("doubleFactoringType", false);
//                            }
//                        } else {
//                            noticeMap.put("doubleFactoringType", false);
//                        }
//                        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                        Configure configure = Configure.builder().bind("changeList", policy).build();
//                        template = XWPFTemplate.compile(templatePath, configure).render(noticeMap);
//                        path = FileUtil.getAbsolutePath("池保理应收账款转让通知书—国内适用—暗保理适用" + masterContract.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                        File file = new File(path);
//                        if (!file.getParentFile().exists()) {
//                            file.getParentFile().mkdirs();
//                        }
//                        template.writeToFile(file.getPath());
//                        fileAllList.add(file);
//                    } else if (type.equals(ConstantConversionUtil.DOMESTICACCOUNTRECEIVABLETRANSFERNOTICEBRIGHT)) {
//                        String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.DOMESTICACCOUNTRECEIVABLETRANSFERNOTICEBRIGHT, making.getTemplateVersionId());
//                        if (templatePath == null) {
//                            throw new BusinessException(CodeUtil.FAIL, "下载国内有追应收账款转让通知书出错");
//                        }
//                        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                        Configure configure = Configure.builder().bind("changeList", policy).build();
//                        template = XWPFTemplate.compile(templatePath, configure).render(noticeMap);
//                        path = FileUtil.getAbsolutePath("国内有追应收账款转让通知书-明保理适用" + masterContract.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                        File file = new File(path);
//                        if (!file.getParentFile().exists()) {
//                            file.getParentFile().mkdirs();
//                        }
//                        template.writeToFile(file.getPath());
//                        fileAllList.add(file);
//                    } else if (type.equals(ConstantConversionUtil.DOMESTINOCACCOUNTRECEIVABLETRANSFERNOTICEBRIGHT)) {
//                        String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.DOMESTINOCACCOUNTRECEIVABLETRANSFERNOTICEBRIGHT, making.getTemplateVersionId());
//                        if (templatePath == null) {
//                            throw new BusinessException(CodeUtil.FAIL, "下载国内无追应收账款转让通知书出错");
//                        }
//                        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                        Configure configure = Configure.builder().bind("changeList", policy).build();
//                        template = XWPFTemplate.compile(templatePath, configure).render(noticeMap);
//                        path = FileUtil.getAbsolutePath("国内无追应收账款转让通知书-明保理适用" + masterContract.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                        File file = new File(path);
//                        if (!file.getParentFile().exists()) {
//                            file.getParentFile().mkdirs();
//                        }
//                        template.writeToFile(file.getPath());
//                        fileAllList.add(file);
//                    } else if (type.equals(ConstantConversionUtil.DOMESTICACCOUNTRECEIVABLETRANSFERNOTICEDARK)) {
//                        String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.DOMESTICACCOUNTRECEIVABLETRANSFERNOTICEDARK, making.getTemplateVersionId());
//                        if (templatePath == null) {
//                            throw new BusinessException(CodeUtil.FAIL, "下载国内有追应收账款转让通知书出错");
//                        }
//                        if (masterContract.getDoubleFactoringType().equals(1)) {
//                            if ((masterContract.getPlatformName() != null && !masterContract.getPlatformName().equals(""))) {
//                                EnterpriseBusinessInfo enterpriseBusinessInfo = enterpriseBusinessInfoService.getEnterpriseByKeyword(masterContract.getPlatformName(), null, null);
//                                HashMap<String, String> hashMap = new HashMap<>();
//                                hashMap.put("notice2", enterpriseBusinessInfo.getEnterpriseCN());
//                                noticeMap.put("doubleFactoringType", hashMap);
//                            } else {
//                                noticeMap.put("doubleFactoringType", false);
//                            }
//                        } else {
//                            noticeMap.put("doubleFactoringType", false);
//                        }
//                        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                        Configure configure = Configure.builder().bind("changeList", policy).build();
//                        template = XWPFTemplate.compile(templatePath, configure).render(noticeMap);
//                        path = FileUtil.getAbsolutePath("国内有追应收账款转让通知书-暗保理适用" + masterContract.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                        File file = new File(path);
//                        if (!file.getParentFile().exists()) {
//                            file.getParentFile().mkdirs();
//                        }
////                                        template.writeToFile(path);
////                                        fileAllList.add(noticeFile);
//
//                        template.writeToFile(file.getPath());
//                        fileAllList.add(file);
//                    } else if (type.equals(ConstantConversionUtil.DOMESTICACCOUNTRECEIVABLETRANSFERNOTICEDARKTAX)) {
//                        String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.DOMESTICACCOUNTRECEIVABLETRANSFERNOTICEDARKTAX, making.getTemplateVersionId());
//                        if (templatePath == null) {
//                            throw new BusinessException(CodeUtil.FAIL, "下载国内有追应收账款转让通知书出错");
//                        }
//                        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                        Configure configure = Configure.builder().bind("changeList", policy).build();
//                        template = XWPFTemplate.compile(templatePath, configure).render(noticeMap);
//                        path = FileUtil.getAbsolutePath("国内有追应收账款转让通知书-暗保理适用(税理通)" + masterContract.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                        File file = new File(path);
//                        if (!file.getParentFile().exists()) {
//                            file.getParentFile().mkdirs();
//                        }
////                                        template.writeToFile(path);
////                                        fileAllList.add(noticeFile);
//
//                        template.writeToFile(file.getPath());
//                        fileAllList.add(file);
//                    } else if (type.equals(ConstantConversionUtil.INTERNATIONALCHASEACCOUNTRECEIVABLETRANSFERNOTICEBRIGHT)) {
//                        String templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.INTERNATIONALCHASEACCOUNTRECEIVABLETRANSFERNOTICEBRIGHT, making.getTemplateVersionId());
//                        if (templatePath == null) {
//                            throw new BusinessException(CodeUtil.FAIL, "下载国际有追应收账款转让通知书出错");
//                        }
//                        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                        Configure configure = Configure.builder().bind("changeList", policy).build();
//                        template = XWPFTemplate.compile(templatePath, configure).render(noticeMap);
//                        path = FileUtil.getAbsolutePath("国际有追应收账款转让通知书—明保理适用" + masterContract.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                        File file = new File(path);
//                        if (!file.getParentFile().exists()) {
//                            file.getParentFile().mkdirs();
//                        }
////                                        template.writeToFile(path);
////                                        fileAllList.add(noticeFile);
//
//                        template.writeToFile(file.getPath());
//                        fileAllList.add(file);
//                    }
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new BusinessException(CodeUtil.FAIL, "下载保理信息表出错" + e.getMessage());
//        }
//    }

    /**
     * 下载池保理应收账款入池确认书
     */
//    private void dealNewConfirmDownload(ContractInfo contractInfo, List<File> fileAllList, String type) {
//        try {
//            ReviewQuotaDisburse reviewQuotaDisburse = reviewQuotaDisburseService.getById(contractInfo.getReviewQuotaDisburseId());
//            // 主合同信息
//            ReviewMasterContract masterContract = reviewMasterContractService.getOne(new QueryWrapper<ReviewMasterContract>()
//                    .eq("review_quota_disburse_id", reviewQuotaDisburse.getId()));
//            if (reviewQuotaDisburse.getTransferReceivable()) {
//                String path = null;
//                XWPFTemplate template = null;
//                Map<String, Object> confirmMap = new HashMap<>();
//                if (null != contractInfo && null != contractInfo.getMasterContract()) {
//                    // 主合同信息
//                    ReviewFinancingInfo financingInfo = reviewFinancingInfoService.getOne(new QueryWrapper<ReviewFinancingInfo>()
//                            .eq("review_quota_disburse_id", reviewQuotaDisburse.getId()));
//                    //融资利率+管理费率
//                    String financingRateAmanagementFee = null;
//                    //管理费率
//                    String managementFeeRatioStr = null;
//                    //逾期利息
//                    String overdueInterestRateStr = PercentageUtil
//                            .convertPercentage(financingInfo.getOverdueInterestRate().doubleValue());
//                    //融资本金+银行应收利息（）
//                    BigDecimal financingAmountInterest;
//                    // 合同名称
//                    String contractName = masterContract.getContractName();
//                    //合同编号
//                    String contractNo = masterContract.getContractNo();
//                    // 保理合同编号
//                    String factoringContractNo = masterContract.getContractNo();
//                    // 应收账款转让确认书编号
//                    String confirmationNo = contractInfo.getConfirmationNo();
//                    //保理商
//                    String factoringName = masterContract.getFactoringName();
//                    String factoringLegalPersion = masterContract.getFactoringLegalPerson();
//                    String factoringAgentName = masterContract.getFactoringAgentName();
//                    String factoringAgentPhone = masterContract.getFactoringAgentPhone();
//                    // 保理申请人公司名称
//                    String applicantCompanyName = masterContract.getApplicantCompanyName();
//                    String applicantLegalPerson = masterContract.getApplicantCompanyLegalPerson();
//                    String applicantCompanyAddress = masterContract.getApplicantCompanyAddress();
//                    String applicantContact = masterContract.getApplicantContact();
//                    String applicantContactNumber = masterContract.getApplicantContactNumber();
//                    //我司指定账户户名
//                    String ourAccountName = masterContract.getOurAccountName();
//                    //我司指定账户开户行
//                    String ourAccountBank = masterContract.getOurAccountBank();
//                    //我司指定账户
//                    String ourAccount = masterContract.getOurAccount();
//                    // 合作业务板块
//                    String businessType = contractInfo.getBusinessType();
//                    //应收账款金额总计
//                    BigDecimal receivableAmountTotal = contractInfo.getAccountsReceivableAmountTotal();
//                    String currencyName = null;
//                    Dictionary currencyDict = dictionaryService.get(contractInfo.getCurrency().getId());
//                    if (null != currencyDict) {
//                        currencyName = currencyDict.getCode();
//                    }
//                    List<ContractMasterContractDebtor> debtorList = masterContract.getDebtorList();
//                    String debtor = null;
//                    confirmMap.put("receivableAmountTotal", receivableAmountTotal);
//                    confirmMap.put("factoringContractNo", factoringContractNo);
//                    confirmMap.put("contractName", contractName);
//                    confirmMap.put("contractNo", contractNo);
//                    confirmMap.put("applicantCompanyName", applicantCompanyName);
//                    confirmMap.put("applicantLegalPerson", applicantLegalPerson);
//                    confirmMap.put("applicantCompanyAddress", applicantCompanyAddress);
//                    confirmMap.put("applicantContact", applicantContact);
//                    confirmMap.put("applicantContactNumber", applicantContactNumber);
//                    confirmMap.put("factoringName", factoringName);
//                    confirmMap.put("ourAccountName", ourAccountName);
//                    confirmMap.put("ourAccountBank", ourAccountBank);
//                    confirmMap.put("ourAccount", ourAccount);
//                    confirmMap.put("confirmationNo", confirmationNo);
//                    confirmMap.put("currencyName", currencyName);
//                    confirmMap.put("factoringLegalPersion", factoringLegalPersion);
//                    confirmMap.put("factoringAddress", ConstantUtil.OUR_COMPANY_ADDRESS_NAME);
//                    confirmMap.put("factoringAgentName", factoringAgentName);
//                    confirmMap.put("factoringAgentPhone", factoringAgentPhone);
//                    //融资本金
//                    BigDecimal financingAmmount = financingInfo.getFinancingAmount() == null ? BigDecimal.ZERO : financingInfo.getFinancingAmount();
//                    BigDecimal financingDays = new BigDecimal(Integer.parseInt(financingInfo.getFinancingPeriod().toString()));
//                    //融资本金+ （融资本金✖12%-管理费率➗360✖融资期限）
//                    BigDecimal balanceLong = financingAmmount.add(financingAmmount.multiply(new BigDecimal(0.12).subtract(financingInfo.getManagementFeeRatio()).divide(new BigDecimal(360), BigDecimal.ROUND_CEILING).multiply(financingDays)));
//                    //BigDecimal balanceLong = financingAmmount.add(financingAmmount.multiply(new BigDecimal(0.12).subtract(new BigDecimal(financingInfo.getManagementFeeRatio()))));
//                    confirmMap.put("financingAmountInterest", balanceLong);
//                    BigDecimal balance = balanceLong.setScale(2, RoundingMode.HALF_UP);
//                    managementFeeRatioStr = PercentageUtil.convertPercentage(financingInfo.getFinancingRate() + financingInfo.getManagementFeeRatio());
//                    if (StringUtil.isNotEmpty(managementFeeRatioStr)) {
//                        managementFeeRatioStr = StringUtil.subZeroAndDot(managementFeeRatioStr.split("%")[0]) + "%";
//                    }
//
//                    if (StringUtil.isNotEmpty(overdueInterestRateStr)) {
//                        overdueInterestRateStr = StringUtil.subZeroAndDot(overdueInterestRateStr.split("%")[0]) + "%";
//                    }
//                    confirmMap.put("balance", balance);
//                    confirmMap.put("managementFeeRatioStr", managementFeeRatioStr);
//                    confirmMap.put("overdueInterestRateStr", overdueInterestRateStr);
//                    confirmMap.put("financingRateStr", managementFeeRatioStr);
//                    Date date = new Date();
//                    confirmMap.put("day", DateUtil.getDay(date));
//                    confirmMap.put("month", DateUtil.getMonth(date));
//                    confirmMap.put("year", DateUtil.getYear(date));
//                    List<Map<String, Object>> changeMapList = new ArrayList<>();
//                    if (StringUtil.isNotEmpty(businessType) && businessType.equals(ConstantConversionUtil.DOMESTIC_FACTORING)) {
//                        List<ContractDomesticAccountReceivable> domesticList = contractInfo.getDomesticAccountReceivableList();
//                        BigDecimal accountsReceivableAmountTotal = BigDecimal.ZERO;
//                        BigDecimal netAmountTotal = BigDecimal.ZERO;
//                        if (null != domesticList && domesticList.size() > 0) {
//                            int i = 0;
//                            for (ContractDomesticAccountReceivable domestic : domesticList) {
//                                i = i + 1;
//                                debtor = domestic.getDebtor();
//                                Map<String, Object> changeMap = new HashMap<>();
//                                changeMap.put("recordNo", i);
//                                changeMap.put("contractName", domestic.getContractName());
//                                changeMap.put("contractNo", domestic.getContractNo());
//                                changeMap.put("debtor", debtor);
//                                changeMap.put("accountsReceivableType", domestic.getAccountsReceivableType());
//                                changeMap.put("accountsReceivableAmount", domestic.getAccountsReceivableAmount());
//                                changeMap.put("netAmount", domestic.getAccountsReceivableNetAmount());
//                                if (contractInfo.getPlanFactoringProducts().getCode().equals(FactoringProductsDomesticDict.ChildEnum.FPD_TRADING_FACTORING.getCode())) {
//                                    if (null != domestic.getEndDate()) {
//                                        changeMap.put("expiryDate", DateUtil.formateYMD(domestic.getEndDate()));
//                                    }
//                                } else {
//                                    changeMap.put("expiryDate", "自支付融资款之日起" + financingInfo.getFinancingPeriod() + "天");
//                                }
//                                if (null != domestic.getTerm()) {
//                                    changeMap.put("term", domestic.getTerm());
//                                }
//                                accountsReceivableAmountTotal = accountsReceivableAmountTotal.add(domestic.getAccountsReceivableAmount());
//                                netAmountTotal = netAmountTotal.add(domestic.getAccountsReceivableNetAmount());
//                                List<ContractDomesticInvoiceInfo> invoiceList = new ArrayList<>();
//                                List<ContractDomesticInvoiceInfo> domesticInvoiceInfoList = domestic.getDomesticInvoiceInfoList();
//                                if (domesticInvoiceInfoList != null && domesticInvoiceInfoList.size() > 0) {
//                                    invoiceList.addAll(domesticInvoiceInfoList);
//                                }
//                                if (invoiceList.size() == 0) {
//                                    ContractDomesticInvoiceInfo contractDomesticInvoiceInfo = new ContractDomesticInvoiceInfo();
//                                    contractDomesticInvoiceInfo.setInvoiceNo("");
//                                    contractDomesticInvoiceInfo.setInvoiceAmmount(BigDecimal.ZERO);
//                                    invoiceList.add(contractDomesticInvoiceInfo);
//                                }
//                                String invoice = "";
//                                BigDecimal invoiceTotal = BigDecimal.ZERO;
//                                if (invoiceList.size() > 0 && invoiceList != null) {
//                                    for (int j = 0; j < invoiceList.size(); j++) {
//                                        String invoiceNo = invoiceList.get(j).getInvoiceNo();
//                                        BigDecimal invoiceAmmount = invoiceList.get(j).getInvoiceAmmount();
//                                        int n = j + 1;
//                                        invoice = invoice + "发票" + n + "\n" + "票号:" + invoiceNo + "\n" + "金额: " + invoiceAmmount + domestic.getCurrency().getCode() + "\n";
//                                        invoiceTotal = invoiceTotal.add(invoiceAmmount);
//                                        if (invoiceAmmount.compareTo(BigDecimal.ZERO) == 0) {
//                                            invoice = "——";
//                                        }
//                                    }
//                                } else {
//                                    invoice = "——";
//                                }
//                                changeMap.put("invoice", invoice);
//                                changeMapList.add(changeMap);
//                            }
//                            BigDecimal invoiceAmountTotal = BigDecimal.ZERO;
//                            if (domesticList != null && domesticList.size() > 0) {
//                                invoiceAmountTotal = domesticList.stream().filter(c -> c.getInvoiceAmmountTotal() != null)
//                                        .map(ContractDomesticAccountReceivable::getInvoiceAmmountTotal)
//                                        .reduce(BigDecimal.ZERO, BigDecimal::add);
//                            }
//                            confirmMap.put("invoiceAmountTotal", invoiceAmountTotal);
//                        }
//                        confirmMap.put("accountsReceivableAmountTotal", accountsReceivableAmountTotal);
//                        confirmMap.put("netAmountTotal", netAmountTotal);
//                    }
//
//                    if (null != changeMapList && changeMapList.size() > 0) {
//                        confirmMap.put("changeList", changeMapList);
//                        confirmMap.put("accountsReceivableAmountTotal", contractInfo.getAccountsReceivableAmountTotal());
//                        confirmMap.put("accountsReceivableNetAmmounTotal",
//                                contractInfo.getAccountsReceivableNetAmmounTotal());
//                    }
//                    confirmMap.put("debtor", debtor);
//                    List<Map<String, Object>> masterDebtors = new ArrayList<>();
//                    Integer m = 0;
//                    if (debtorList != null && debtorList.size() > 0) {
//                        for (ContractMasterContractDebtor masterContractDebtor : debtorList) {
//                            //主合同-债务人公司名称
//                            m++;
//                            Map<String, Object> debtorMap = new HashMap<>();
//                            if (debtorList.size() > 1) {
//                                debtorMap.put("debtorName", masterContractDebtor.getCompanyName() + "、");
//                            } else {
//                                debtorMap.put("debtorName", masterContractDebtor.getCompanyName());
//
//                            }
//                            debtorMap.put("num", "qz" + Integer.toString(m));
//                            masterDebtors.add(debtorMap);
//                        }
//                    }
//                    if (contractInfo.getFinancingInfo().geteTradingType() != null && contractInfo.getFinancingInfo().geteTradingType().equals(1)) {
//                        confirmMap.put("masterDebtors", masterDebtors);
//                    }
//                    confirmMap.put("debtors", masterDebtors);
//
//
//                    String templatePath = "";
//                    if (type.equals(ConstantConversionUtil.POOLFACTORINGACCOUNTRECEIVABLEINTOPOOLCONFIRM)) {
//                        if (masterContract.getDoubleFactoringType().equals(1)) {
//                            if ((masterContract.getPlatformName() != null && !masterContract.getPlatformName().equals(""))) {
//                                EnterpriseBusinessInfo enterpriseBusinessInfo = enterpriseBusinessInfoService.getEnterpriseByKeyword(masterContract.getPlatformName(), null, null);
//                                HashMap<String, String> hashMap = new HashMap<>();
//                                hashMap.put("platformName", enterpriseBusinessInfo.getEnterpriseCN());
//                                confirmMap.put("doubleFactoringType", hashMap);
//                            } else {
//                                confirmMap.put("doubleFactoringType", false);
//                            }
//                        } else {
//                            confirmMap.put("doubleFactoringType", false);
//                        }
//                        templatePath = productTemplateRelService.getTemplateId(ConstantConversionUtil.POOLFACTORINGACCOUNTRECEIVABLEINTOPOOLCONFIRM, contractInfo.getTemplateVersionId());
//                        path = FileUtil.getAbsolutePath("池保理应收账款入池确认书" + masterContract.getApplicantCompanyName(), ".docx", FileModuleDict.ChildEnum.CONTRACTFILEPRIVIEW);
//                    }
//                    LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
//                    Configure configure = Configure.builder().bind("changeList", policy).bind("invoiceMapList", policy).build();
//                    template = XWPFTemplate.compile(templatePath, configure)
//                            .render(confirmMap);
//                    template.writeToFile(path);
//                    File file = new File(path);
//                    if (!file.exists()) {
//                        FileUtils.createParentDirectories(file);
//                    }
//                    fileAllList.add(file);
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new BusinessException(CodeUtil.FAIL, "下载应收账款转让确认书错误" + e.getMessage());
//        }
//    }
}
