package com.yunyan.business.document.y22;

import cn.hutool.json.JSONUtil;
import com.yunyan.business.document.y22.pojo.finalExcelY22.*;
import com.yunyan.business.document.y23.budget.ReadBudgetExcelT6Y22Utils;
import com.yunyan.business.document.y23.budget.ReadBudgetExcelY23Utils;
import com.yunyan.business.document.y23.budget.pojo.budgetY23.*;
import com.yunyan.business.document.y23.finalData.FinalY23PxUtils;
import com.yunyan.business.document.y23.finalData.pojo.ChangeValueItemVo;
import com.yunyan.common.utils.NumberFormatUtils;
import com.yunyan.common.utils.StringUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * 结算数据的处理 工具类
 */
@Slf4j
public class FinalY22CompareLastUtils {

    /**
     * 比较前一年的数据
     * @param excelDataYearVo
     * @param excelDataLastYearVo
     * @return
     */
    public static void compareData(FinalExcelDataVo excelDataYearVo, FinalExcelDataVo excelDataLastYearVo) {
        //FinalP3Vo p3Vo = new FinalP3Vo();

        //比较 表格1
        FinalY22CompareLastUtils finalDataUtils = new FinalY22CompareLastUtils();
        FinalY22CompareLastUtils.compareP3T1Set(excelDataYearVo, excelDataLastYearVo);
        //p3Vo.setP3T1Vo(p3T1Vo);
        //直接 set到对象中
        //excelDataYearVo.setP3T1Vo(p3T1Vo);

        //比较 p3t2
        finalDataUtils.compareP3T2(excelDataYearVo, excelDataLastYearVo.getP3T2Vo());

        //比较 p3t4
        finalDataUtils.compareP3T4Set(excelDataYearVo, excelDataLastYearVo);
        // 比较p3t5
        finalDataUtils.compareP3T5Set(excelDataYearVo, excelDataLastYearVo);
        //比较 p3t7
        finalDataUtils.compareP3T7Set(excelDataYearVo, excelDataLastYearVo);
    }

    /**
     * 比较 预算的数据
     * @param dataVo
     * @param subDeptVo
     */
    public static void compareDataBudget(FinalExcelDataVo dataVo, BudgetP3p5SubDeptVo subDeptVo, String area, String year) {

        FinalY22CompareLastUtils.compareDataP3T2Budget(dataVo, subDeptVo);

        FinalY22CompareLastUtils.compareDataP3T3Budget(dataVo, area, year);

    }

    /**
     * 重新从 表中拿 数据
     * @param dataVo 源数据
     * @param newSetDataVo 重新获取 的excel 数据
     */
    public static void setP2p2HeadData(FinalExcelDataVo dataVo, FinalExcelDataVo newSetDataVo) {
        //3.2部分的年度一般公共预算财政拨款支出决算情况 功能分类科目
        FinalP3T2Vo p3T2Vo = dataVo.getP3T2Vo();
        FinalP3T2Vo newSetP3T2Vo = newSetDataVo.getP3T2Vo();
        p3T2Vo.setExpenditureBudgetBegin(newSetP3T2Vo.getExpenditureBudgetBegin());
        p3T2Vo.setExpenditureFinal(newSetP3T2Vo.getExpenditureFinal());
        p3T2Vo.setExpenditureBudgetRatio(FinalY22Utils.getSuccessRatio(p3T2Vo.getExpenditureFinal(), p3T2Vo.getExpenditureBudgetBegin()));
    }

    /**
     * 表一的比较 前一年数据
     * @param excelDataYearVo
     * @param lastYearData
     * @param p3Vo
     */
    private FinalP3T1Vo compareP3T1(FinalExcelDataVo excelDataYearVo, FinalZ01Vo lastYearData, FinalP3Vo p3Vo) {
        //年度的表一数据
        FinalZ01Vo yearData = excelDataYearVo.getT1Z01Vo();
        String year = excelDataYearVo.getYear();
        String lastYear = String.valueOf(Integer.valueOf(year) - 1);


        //设置初始化的对象
        FinalP3T1Vo p3T1Vo = new FinalP3T1Vo();
        //p3Vo.setP3T1Vo(p3T1Vo);

        //收入/支出
        FinalP3T1TotalVo incomeVo = new FinalP3T1TotalVo();
        p3T1Vo.setIncome(incomeVo);
        FinalP3T1TotalVo expenditureVo = new FinalP3T1TotalVo();
        p3T1Vo.setExpenditure(expenditureVo);

        incomeVo.setTotal(yearData.getIncomeTotal());
        incomeVo.setTotalYear(yearData.getIncomeYearTotal());
        incomeVo.setTotalLastYear(lastYearData.getIncomeYearTotal());

        expenditureVo.setTotal(yearData.getExpenditureTotal());
        expenditureVo.setTotalYear(yearData.getExpenditureYearTotal());
        expenditureVo.setTotalLastYear(lastYearData.getExpenditureYearTotal());

        //收入 较2020年度决算数2,488.67万元，减少948.36万元，下降38.11%。
        String addOrSubStr = FinalY22Utils.getAddOrSubString(incomeVo.getTotalYear(), incomeVo.getTotalLastYear());
        String compareLastYear = String.format("较%s年度决算数%s万元，%s", lastYear,
                incomeVo.getTotalLastYear(), addOrSubStr);
//                NumberUtil.decimalFormat(",###.00", incomeVo.getTotalLastYear()), addOrSubStr);
        incomeVo.setCompareLastYear(compareLastYear);

        //支出 较2020年度决算数2,488.67万元，减少948.36万元，下降38.11%
        String addOrSubStr2 = FinalY22Utils.getAddOrSubString(expenditureVo.getTotalYear(), expenditureVo.getTotalLastYear());
        String compareLastYear2 = String.format("较%s年度决算数%s万元，%s", lastYear,
                expenditureVo.getTotalLastYear(), addOrSubStr2);
//                NumberUtil.decimalFormat(",###.00", incomeVo.getTotalLastYear()), addOrSubStr);
        expenditureVo.setCompareLastYear(compareLastYear2);

        List<FinalP3T1TotalItemVo> incomeList = new ArrayList<>();
        incomeVo.setList(incomeList);
        List<FinalP3T1TotalItemVo> expenditureList = new ArrayList<>();
        expenditureVo.setList(expenditureList);

        List<FinalZ01ItemVo> z01ItemVoList = yearData.getList();
        List<FinalZ01ItemVo> z01ItemVoLastList = lastYearData.getList();
        int indexNoIncome = 1;
        int indexNoExpenditure = 1;
        //比对数据项
        for (FinalZ01ItemVo item : z01ItemVoList) {
            FinalZ01ItemVo itemLastYear = z01ItemVoLastList.stream().filter(i->i.getRowNo().equals(item.getRowNo())).findFirst().orElse(null);
            if(null == itemLastYear) {
                log.error("未找到旧数据");
                continue;
            }
            //收入
            if(StringUtils.isNotBlank(item.getIncomeName()) && !item.getIncomeName().equals("本年收入合计") && !item.getIncomeName().equals("总计") ) {
                FinalP3T1TotalItemVo incomeItem = new FinalP3T1TotalItemVo();

                incomeItem.setValueYear(item.getIncomeValue());
                incomeItem.setValueLastYear(itemLastYear.getIncomeValue());
                incomeItem.setName(item.getIncomeName());
                incomeItem.setRowNo(item.getRowNo());

                //一般公共预算财政拨款收入1,490.22 万元，为田阳区财政当年拨付的资金。较2020年度决算数2,107.15万元，减少616.93万元，下降29.28% ，主要原因是
                String addOrSubStrItem = FinalY22Utils.getAddOrSubString(incomeItem.getValueYear(), incomeItem.getValueLastYear());
                /*String compareLastYearItem = String.format("%s.%s %s 万元。较%s年度决算数%s万元，%s",
                        item.getRowNo(), item.getIncomeName().substring(item.getIncomeName().indexOf("、")+1), incomeItem.getValueYear(), lastYear, incomeItem.getValueLastYear(),  addOrSubStrItem);*/
                String compareLastYearItem = FinalY22Utils.getInfoCompareStrItemP3T1(incomeItem.getValueLastYear(), lastYear, addOrSubStrItem);

                incomeItem.setCompareLastYear(compareLastYearItem);
                incomeItem.setInfo(FinalY22Utils.getInfoStrItemP3T1(incomeItem.getName(), incomeItem.getValueYear()));
                //本单位2022年无该项收入，故无数据情况说明。
                incomeItem.setReason(FinalY22Utils.getReasonStrItem(incomeItem.getValueYear(), incomeItem.getValueLastYear(), "本单位年度无该项收入，故无数据情况说明"));
                incomeItem.setReasonFlag(FinalY22Utils.getFlagByValue(incomeItem.getValueYear(), incomeItem.getValueLastYear()));
                incomeList.add(incomeItem);
                indexNoIncome++;
            }


            //支出
            if(StringUtils.isNotBlank(item.getExpenditureName()) && !item.getExpenditureName().equals("本年支出合计") && !item.getExpenditureName().equals("总计") ) {
                FinalP3T1TotalItemVo expenditureItem = new FinalP3T1TotalItemVo();

                expenditureItem.setValueYear(item.getExpenditureValue());
                expenditureItem.setValueLastYear(itemLastYear.getExpenditureValue());
                expenditureItem.setName(item.getExpenditureName());
                expenditureItem.setRowNo(item.getRowNo());

                //一般公共预算财政拨款收入1,490.22 万元，为田阳区财政当年拨付的资金。较2020年度决算数2,107.15万元，减少616.93万元，下降29.28% ，主要原因是
                String addOrSubStrItem = FinalY22Utils.getAddOrSubString(expenditureItem.getValueYear(), expenditureItem.getValueLastYear());
                /*String compareLastYearItem = String.format("%s.%s%s万元。较%s年度决算数%s万元，%s", indexNoExpenditure++,
                        item.getExpenditureName().substring(item.getExpenditureName().indexOf("、")+1), item.getExpenditureValue(), lastYear,
                        itemLastYear.getExpenditureValue(), addOrSubStrItem);*/
                String compareLastYearItem = FinalY22Utils.getInfoCompareStrItemP3T1( expenditureItem.getValueLastYear(), lastYear, addOrSubStrItem);
                expenditureItem.setCompareLastYear(compareLastYearItem);
                expenditureItem.setInfo(FinalY22Utils.getInfoStrItemP3T1(item.getExpenditureName(), expenditureItem.getValueYear()));
                //本单位2022年无该项支出，故无数据情况说明。
                expenditureItem.setReason(FinalY22Utils.getReasonStrItem(expenditureItem.getValueYear(), expenditureItem.getValueLastYear(), "本单位年度无该项支出，故无数据情况说明"));
                expenditureItem.setReasonFlag(FinalY22Utils.getFlagByValue(expenditureItem.getValueYear(), expenditureItem.getValueLastYear()));
                expenditureList.add(expenditureItem);
            }
        }

        //收入-非财政拨款结余, 收入-上年结转和结余, 支出-结余分配, 支出-年末结转和结余 p3p1取消
        //setIncomeExpenditureRestEnd(yearData, lastYearData, indexNoIncome, indexNoExpenditure, lastYear, incomeList, expenditureList);

        log.debug("res [{}]", p3T1Vo);
        return p3T1Vo;
    }

    /**
     * 比较 p3p1部分的 直接比对
     * @param excelDataYearVo
     * @param excelLastYearData
     * @return
     */
    public static void compareP3T1Set(FinalExcelDataVo excelDataYearVo, FinalExcelDataVo excelLastYearData) {
        //年度的表一数据
        //FinalZ01Vo yearData = excelDataYearVo.getT1Z01Vo();
        String year = excelDataYearVo.getYear();
        String lastYear = String.valueOf(Integer.valueOf(year) - 1);


        //设置初始化的对象
        FinalP3T1Vo p3T1Vo = excelDataYearVo.getP3T1Vo();

        //收入/支出
        FinalP3T1TotalVo incomeVo = p3T1Vo.getIncome();
        FinalP3T1TotalVo expenditureVo = p3T1Vo.getExpenditure();

        incomeVo.setTotalLastYear(excelLastYearData.getP3T1Vo().getIncome().getTotalYear());

        expenditureVo.setTotalLastYear(excelLastYearData.getP3T1Vo().getExpenditure().getTotalYear());

        //收入 较2020年度决算数2,488.67万元，减少948.36万元，下降38.11%。
        String addOrSubStr = FinalY22Utils.getAddOrSubString(incomeVo.getTotalYear(), incomeVo.getTotalLastYear());
        String compareLastYear = String.format("较%s年度决算数%s万元，%s", lastYear,
                incomeVo.getTotalLastYear(), addOrSubStr);
//                NumberUtil.decimalFormat(",###.00", incomeVo.getTotalLastYear()), addOrSubStr);
        incomeVo.setCompareLastYear(compareLastYear);

        //支出 较2020年度决算数2,488.67万元，减少948.36万元，下降38.11%
        String addOrSubStr2 = FinalY22Utils.getAddOrSubString(expenditureVo.getTotalYear(), expenditureVo.getTotalLastYear());
        String compareLastYear2 = String.format("较%s年度决算数%s万元，%s", lastYear,
                expenditureVo.getTotalLastYear(), addOrSubStr2);
//                NumberUtil.decimalFormat(",###.00", incomeVo.getTotalLastYear()), addOrSubStr);
        expenditureVo.setCompareLastYear(compareLastYear2);

        //比对数据项
        for (FinalP3T1TotalItemVo item : p3T1Vo.getIncome().getList()) {
            FinalP3T1TotalItemVo itemLastYear = excelLastYearData.getP3T1Vo().getIncome().getList().stream().filter(i->i.getName().equals(item.getName())).findFirst().orElse(null);
            if(null == itemLastYear) {
                log.error("未找到旧数据");
                continue;
            }
            //收入
            if(StringUtils.isNotBlank(item.getName()) && !item.getName().equals("本年收入合计") && !item.getName().equals("总计") ) {
                item.setValueLastYear(itemLastYear.getValueYear());

                //一般公共预算财政拨款收入1,490.22 万元，为田阳区财政当年拨付的资金。较2020年度决算数2,107.15万元，减少616.93万元，下降29.28% ，主要原因是
                String addOrSubStrItem = FinalY22Utils.getAddOrSubString(item.getValueYear(), item.getValueLastYear());
                String compareLastYearItem = FinalY22Utils.getInfoCompareStrItemP3T1(item.getValueLastYear(), lastYear, addOrSubStrItem);
                item.setCompareLastYear(compareLastYearItem);
                //item.setInfo(FinalY22Utils.getInfoStrItemP3T1(item.getName(), item.getValueYear()));
                //本单位2022年无该项收入，故无数据情况说明。
                item.setReason(FinalY22Utils.getReasonStrItem(item.getValueYear(), item.getValueLastYear(), "本单位年度无该项收入，故无数据情况说明"));
                item.setReasonFlag(FinalY22Utils.getFlagByValue(item.getValueYear(), item.getValueLastYear()));
            }
        }

        //比对数据项
        for (FinalP3T1TotalItemVo item : p3T1Vo.getExpenditure().getList()) {
            FinalP3T1TotalItemVo itemLastYear = excelLastYearData.getP3T1Vo().getExpenditure().getList().stream().filter(i->i.getName().equals(item.getName())).findFirst().orElse(null);
            if(null == itemLastYear) {
                log.error("未找到旧数据");
                continue;
            }

            //支出
            if(StringUtils.isNotBlank(item.getName()) && !item.getName().equals("本年支出合计") && !item.getName().equals("总计") ) {
                item.setValueLastYear(itemLastYear.getValueYear());

                //一般公共预算财政拨款收入1,490.22 万元，为田阳区财政当年拨付的资金。较2020年度决算数2,107.15万元，减少616.93万元，下降29.28% ，主要原因是
                String addOrSubStrItem = FinalY22Utils.getAddOrSubString(item.getValueYear(), item.getValueLastYear());
                String compareLastYearItem = FinalY22Utils.getInfoCompareStrItemP3T1( item.getValueLastYear(), lastYear, addOrSubStrItem);
                item.setCompareLastYear(compareLastYearItem);
                //item.setInfo(FinalY22Utils.getInfoStrItemP3T1(item.getName(), item.getValueYear()));
                //本单位2022年无该项支出，故无数据情况说明。
                item.setReason(FinalY22Utils.getReasonStrItem(item.getValueYear(), item.getValueLastYear(), "本单位年度无该项支出，故无数据情况说明"));
                item.setReasonFlag(FinalY22Utils.getFlagByValue(item.getValueYear(), item.getValueLastYear()));
            }
        }

        //收入-非财政拨款结余, 收入-上年结转和结余, 支出-结余分配, 支出-年末结转和结余 p3p1取消
        //setIncomeExpenditureRestEnd(yearData, lastYearData, indexNoIncome, indexNoExpenditure, lastYear, incomeList, expenditureList);

        //log.debug("res [{}]", p3T1Vo);
    }

    /**
     * p3t2部分 去年的决算 比较
     * @param excelDataYearVo
     * @param lastYearp3T2Vo
     * @return
     */
    private void compareP3T2(FinalExcelDataVo excelDataYearVo, FinalP3T2Vo  lastYearp3T2Vo) {

        //p3t2
        FinalP3T2Vo p3T2Vo = excelDataYearVo.getP3T2Vo();
        //p3T2Vo.setExpenditureTotal(FinalY22Utils.getMapNumFormat(map, 2));
        p3T2Vo.setExpenditureTotalLastYear(lastYearp3T2Vo.getExpenditureTotal());
        String addOrSubStrItem = FinalY22Utils.getAddOrSubStringP3t2(p3T2Vo.getExpenditureTotal(), p3T2Vo.getExpenditureTotalLastYear());
        String lastYear = new BigDecimal(excelDataYearVo.getYear()).subtract(new BigDecimal(1)).toString();
        String compareStr= String.format("较%s年度决算数%s万元，%s", lastYear, p3T2Vo.getExpenditureTotalLastYear(), addOrSubStrItem);
        p3T2Vo.setExpenditureCompareStr(compareStr);

    }

    /**
     * p3p2部分的 年初预算的查询， 更新比对 对比项
     * @param excelDataYearVo
     * @param subDeptVo
     */
    private static void compareDataP3T2Budget(FinalExcelDataVo excelDataYearVo, BudgetP3p5SubDeptVo subDeptVo) {
        if(null == subDeptVo) {
            log.debug("BudgetP2p5SubDeptVo 为空");
            return;
        }

        //p3t2
        FinalP3T2Vo p3T2Vo = excelDataYearVo.getP3T2Vo();
        /*String addOrSubStrItem = FinalY22Utils.getAddOrSubStringP3t2(p3T2Vo.getExpenditureTotal(), p3T2Vo.getExpenditureTotalLastYear());
        String lastYear = new BigDecimal(excelDataYearVo.getYear()).subtract(new BigDecimal(1)).toString();
        String compareStr= String.format("较%s年度决算数 %s", lastYear, addOrSubStrItem);
        p3T2Vo.setExpenditureCompareStr(compareStr);*/

        List<BudgetP3p5SubDeptItemVo> subDeptList = subDeptVo.getList();

        List<FinalP3T2CategoryItemVo> p3T2CategoryList = p3T2Vo.getList();
        for (FinalP3T2CategoryItemVo categoryItemVo : p3T2CategoryList) {
            List<FinalP3T2ItemVo> p3T2ItemList = categoryItemVo.getList();
            if(p3T2ItemList.isEmpty()) {
                continue;
            }
            for (FinalP3T2ItemVo p3T2ItemVo : p3T2ItemList ) {
                //取 本年的预算数据, 后对比
                Optional<BudgetP3p5SubDeptItemVo> subDeptItemVoOptional = subDeptList.stream().filter(subdep -> subdep.getCode().equals(p3T2ItemVo.getCode())).findFirst();
                if(!subDeptItemVoOptional.isPresent()) {
                    log.debug("决算p3p2的科目[{}]的年初预算没有值", p3T2ItemVo.getCode());
                    //判断是否是增长 大于小于才有 原因的填写, 相等不用输入原因
                    /*int compareInt = FinalY22Utils.compareValue(p3T2ItemVo.getFinalValue(), p3T2ItemVo.getBeginValue());
                    Integer reasonFlag = 0 == compareInt ? 0 : 1;
                    String compareValueStr = FinalY22Utils.compareValueStr(compareInt);
                    p3T2ItemVo.setReasonFlag(reasonFlag);
                    p3T2ItemVo.setCompareValueStr(compareValueStr);*/
                    continue;
                }

                //设置 年初的预算值
                String beginValue = NumberFormatUtils.amountInThousands(subDeptItemVoOptional.get().getTotal().replace(",", ""));

                //更新 比率 与 对比的增长率
                p3T2ItemVo.setBeginValue(beginValue);
                p3T2ItemVo.setRatio(FinalY22Utils.getSuccessRatio(p3T2ItemVo.getFinalValue(), p3T2ItemVo.getBeginValue()));
                p3T2ItemVo.setInfo(FinalY22Utils.getInfoStrP3T2(p3T2ItemVo.getName(), p3T2ItemVo.getFinalValue(), p3T2ItemVo.getBeginValue(), p3T2ItemVo.getRatio()));

                //更新 判断是否是增长 大于小于才有 原因的填写, 相等不用输入原因
                int compareInt = FinalY22Utils.compareValue(p3T2ItemVo.getFinalValue(), p3T2ItemVo.getBeginValue());
                Integer reasonFlag = 0 == compareInt ? 0 : 1;
                String compareValueStr = FinalY22Utils.compareValueStr(compareInt);
                p3T2ItemVo.setReasonFlag(reasonFlag);
                p3T2ItemVo.setCompareValueStr(compareValueStr);
            }
        }



    }

    /**
     * 决算 设置 比较 p3p4的项的预算数
     * @param excelDataYearVo
     * @param deptList 预算表8的预算数据
     */
    public static void compareDataP3T4Budget(FinalExcelDataVo excelDataYearVo, List<BudgetP3p8DeptVo> deptList, String deptCode) {
        if(null == deptList || deptList.isEmpty()) {
            log.debug("List<BudgetP2p8DeptVo> 为空");
            return;
        }

        //p3t8
        FinalP3T4Vo p3T4Vo = excelDataYearVo.getP3T4Vo();


        Optional<BudgetP3p8DeptVo> deptVoOptional = deptList.stream().filter(deptItem -> deptItem.getDeptCode().equals(deptCode)).findFirst();
        if(!deptVoOptional.isPresent()) {
            log.debug("查询的部门数据 为空");
            return;
        }

        List<FinalP3T4CategoryItemVo> p3T4CategoryList = p3T4Vo.getList();
        for (FinalP3T4CategoryItemVo categoryItemVo : p3T4CategoryList) {
            List<FinalP3T4ItemVo> p3T4ItemList = categoryItemVo.getList();
            if(p3T4ItemList.isEmpty()) {
                continue;
            }
            for (FinalP3T4ItemVo p3T4ItemVo : p3T4ItemList ) {
                //取 本年的预算数据, 后对比
                Optional<BudgetP3p8DeptItemVo> subDeptItemVoOptional = deptVoOptional.get().getList().stream().filter(deptItem -> deptItem.getCode().equals(p3T4ItemVo.getCode())).findFirst();
                if(!subDeptItemVoOptional.isPresent()) {
                    log.debug("决算p3p4的科目[{}]的年初预算没有值", p3T4ItemVo.getCode());
                    continue;
                }

                //设置 年初的预算值
                String beginValue = NumberFormatUtils.amountInThousands(subDeptItemVoOptional.get().getTotal().replace(",", ""));


                //更新 比率 与 对比的增长率
                p3T4ItemVo.setBeginValue(beginValue);
                p3T4ItemVo.setRatio(FinalY22Utils.getSuccessRatio(p3T4ItemVo.getFinalValue(), p3T4ItemVo.getBeginValue()));
                p3T4ItemVo.setInfo(FinalY22Utils.getInfoStrP3T2(p3T4ItemVo.getName(), p3T4ItemVo.getFinalValue(), p3T4ItemVo.getBeginValue(), p3T4ItemVo.getRatio()));

                //判断是否是增长 大于小于才有 原因的填写, 相等不用输入原因
                int compareInt = FinalY22Utils.compareValue(p3T4ItemVo.getFinalValue(), p3T4ItemVo.getBeginValue());
                Integer reasonFlag = 0 == compareInt ? 0 : 1;
                String compareValueStr = FinalY22Utils.compareValueStr(compareInt);
                p3T4ItemVo.setReasonFlag(reasonFlag);
                p3T4ItemVo.setCompareValueStr(compareValueStr);
            }
        }



    }

    /**
     * p3p3部分的 年初预算的查询， 更新比对 对比项
     * @param excelDataYearVo
     * @param
     */
    public static void compareDataP3T3Budget(FinalExcelDataVo excelDataYearVo, String area, String year) {
        //p3t3
        FinalP3T3Vo p3T3Vo = excelDataYearVo.getP3T3Vo();

        String deptCode = excelDataYearVo.getDeptCode();
        //deptCode = "209050"; //TODO 测试
        if(StringUtils.isBlank(deptCode)) {
            log.debug("没有部门编码[]的年初预算", deptCode);
        }
        /* 平果的 加 000 取不到值
        if(deptCode.length() == 3) {
            //3位数时， 默认加 000
            deptCode = deptCode + "000";
        }*/

        //取文件里的数据
        BudgetT6DeptVo t6DeptVo = ReadBudgetExcelT6Y22Utils.readData(deptCode, area, year);
        if(null == t6DeptVo) {
            log.debug("没有p3p3部分的年初预算");
            //return;
        }
        //List<BudgetT6ItemVo> t6ItemList = t6DeptVo.getList();


        List<FinalP3T3ItemVo> p3T3List = p3T3Vo.getList();
        for (FinalP3T3ItemVo p3T3ItemVo : p3T3List ) {
            if(null == t6DeptVo) {
                log.debug("没有p3p3部分的年初预算");
                continue;
            }
            List<BudgetT6ItemVo> t6ItemList = t6DeptVo.getList();

            //取 本年的预算数据, 后对比
            Optional<BudgetT6ItemVo> itemVoOptional = t6ItemList.stream().filter(i -> i.getName().equals(p3T3ItemVo.getName())).findFirst();
            if(!itemVoOptional.isPresent()) {
                log.debug("决算p3p3的科目[{}]的年初预算没有值", p3T3ItemVo.getName() );
                continue;
            }

            //设置 年初的预算值
            String beginValue = NumberFormatUtils.amountInThousands(itemVoOptional.get().getTotal().replace(",", ""));


            //更新 比率 与 对比的增长率
            p3T3ItemVo.setBeginValue(beginValue);
            p3T3ItemVo.setRatio(FinalY22Utils.getSuccessRatio(p3T3ItemVo.getFinalValue(), p3T3ItemVo.getBeginValue()));
            p3T3ItemVo.setInfo(FinalY22Utils.getInfoStrP3T3(p3T3ItemVo.getName(), p3T3ItemVo.getFinalValue(), p3T3ItemVo.getBeginValue(), p3T3ItemVo.getRatio()));

            //更新 判断是否是增长 大于小于才有 原因的填写, 相等不用输入原因
            int compareInt = FinalY22Utils.compareValue(p3T3ItemVo.getFinalValue(), p3T3ItemVo.getBeginValue());
            Integer reasonFlag = 0 == compareInt ? 0 : 1;
            String compareValueStr = FinalY22Utils.compareValueStr(compareInt);
            p3T3ItemVo.setReasonFlag(reasonFlag);
            p3T3ItemVo.setCompareValueStr(compareValueStr);
        }

    }

    /**
     * 设置 p3T4的 前一年度的
     * @param excelDataYearVo
     * @param excelLastYearData
     */
    private void compareP3T4Set(FinalExcelDataVo excelDataYearVo, FinalExcelDataVo excelLastYearData) {
        FinalP3T4Vo p3T4Vo = excelDataYearVo.getP3T4Vo();
        FinalP3T4Vo p3T4VoLast = excelLastYearData.getP3T4Vo();
        p3T4Vo.setExpenditureTotalLastYear(p3T4VoLast.getExpenditureTotal());
        //判断 2个是否 为0
        if( 1 == FinalY22Utils.getFlagByValue(p3T4Vo.getExpenditureTotal(), p3T4Vo.getExpenditureTotalLastYear()) ) {
            //较2021年度决算数 xx 万元, 增加（减少）xx 万元，增长（下降）xx  %
            String compareLastYear = "，" + FinalY22Utils.getP3t6ComapreTotalStr(excelDataYearVo.getYear(), p3T4Vo.getExpenditureTotal(), p3T4Vo.getExpenditureTotalLastYear());
            p3T4Vo.setCompareLastYear(compareLastYear);
        }

    }

    /**
     * 设置 p3T5的 前一年度的
     * @param excelDataYearVo
     * @param excelLastYearData
     */
    private void compareP3T5Set(FinalExcelDataVo excelDataYearVo, FinalExcelDataVo excelLastYearData) {
        FinalP3T5Vo p3T5Vo = excelDataYearVo.getP3T5Vo();
        FinalP3T5Vo p3T5VoLast = excelLastYearData.getP3T5Vo();
        p3T5Vo.setExpenditureTotalLastYear(p3T5VoLast.getExpenditureTotal());
        //判断 2个是否 为0
        if( 1 == FinalY22Utils.getFlagByValue(p3T5Vo.getExpenditureTotal(), p3T5Vo.getExpenditureTotalLastYear()) ) {
            //较2021年度决算数 xx 万元, 增加（减少）xx 万元，增长（下降）xx  %
            String compareLastYear = "，" + FinalY22Utils.getP3t6ComapreTotalStr(excelDataYearVo.getYear(), p3T5Vo.getExpenditureTotal(), p3T5Vo.getExpenditureTotalLastYear());
            p3T5Vo.setCompareLastYear(compareLastYear);
        }

    }

    /**
     * 设置 p3T7的 前一年度的 经费的年初预算
     * @param excelDataYearVo
     * @param excelLastYearData
     */
    private void compareP3T7Set(FinalExcelDataVo excelDataYearVo, FinalExcelDataVo excelLastYearData) {
        FinalP3T7ItemDeptOperateVo deptOperateVo = excelDataYearVo.getP3T7Vo().getDeptOperateVo();
        FinalP3T7ItemDeptOperateVo deptOperateVoLast = excelLastYearData.getP3T7Vo().getDeptOperateVo();
    }



    /**
     * p3p1 取消
     * 收入-非财政拨款结余, 收入-上年结转和结余, 支出-结余分配, 支出-年末结转和结余
     * @param yearData
     * @param lastYearData
     * @param indexNoIncome
     * @param indexNoExpenditure
     * @param lastYear
     * @param incomeList
     * @param expenditureList
     */
    @Deprecated
    public static void setIncomeExpenditureRestEnd(FinalZ01Vo yearData, FinalZ01Vo lastYearData,
                     int indexNoIncome, int indexNoExpenditure, String lastYear,
                     List<FinalP3T1TotalItemVo> incomeList, List<FinalP3T1TotalItemVo> expenditureList
    ) {
        //收入-非财政拨款结余
        FinalP3T1TotalItemVo incomeItem = new FinalP3T1TotalItemVo();
        incomeItem.setValueYear(yearData.getIncomeRest());
        incomeItem.setValueLastYear(null == lastYearData ? "0" : lastYearData.getIncomeRest());
        incomeItem.setName("收入-非财政拨款结余");
        incomeItem.setRowNo(String.valueOf(indexNoIncome++));

        //一般公共预算财政拨款收入1,490.22 万元，为田阳区财政当年拨付的资金。较2020年度决算数2,107.15万元，减少616.93万元，下降29.28% ，主要原因是
        String addOrSubStrItem = FinalY22Utils.getAddOrSubString(incomeItem.getValueYear(), incomeItem.getValueLastYear());
        /*String compareLastYearItem = String.format("%s.%s %s 万元。较%s年度决算数%s万元，%s" ,
                incomeItem.getRowNo(), incomeItem.getName(), incomeItem.getValueYear(),
                lastYear, incomeItem.getValueLastYear(), addOrSubStrItem);*/
        String compareLastYearItem = FinalY22Utils.getInfoCompareStrItemP3T1(incomeItem.getValueLastYear(), lastYear, addOrSubStrItem);

        incomeItem.setCompareLastYear(compareLastYearItem);
        incomeItem.setInfo(FinalY22Utils.getInfoStrItemP3T1(incomeItem.getName(), incomeItem.getValueYear()));
        incomeList.add(incomeItem);

        //收入-上年结转和结余
        FinalP3T1TotalItemVo incomeIte2 = new FinalP3T1TotalItemVo();
        incomeIte2.setValueYear(yearData.getIncomeYearBegin());
        incomeIte2.setValueLastYear( null == lastYearData ? "0" : lastYearData.getIncomeYearBegin());
        incomeIte2.setName("收入-上年结转和结余");
        incomeIte2.setRowNo(String.valueOf(indexNoIncome++));

        //一般公共预算财政拨款收入1,490.22 万元，为田阳区财政当年拨付的资金。较2020年度决算数2,107.15万元，减少616.93万元，下降29.28% ，主要原因是
        String addOrSubStrItem2 = FinalY22Utils.getAddOrSubString(incomeIte2.getValueYear(), incomeIte2.getValueLastYear());
        String compareLastYearItem2 = FinalY22Utils.getInfoCompareStrItemP3T1(incomeIte2.getValueLastYear(), lastYear, addOrSubStrItem2);
        /*String compareLastYearItem2 = String.format("%s.%s%s万元。较%s年度决算数%s万元，%s" ,
                incomeIte2.getRowNo(), incomeIte2.getName(), incomeIte2.getValueYear(),
                lastYear, incomeIte2.getValueLastYear(), addOrSubStrItem2);*/

        incomeIte2.setCompareLastYear(compareLastYearItem2);
        incomeIte2.setInfo(FinalY22Utils.getInfoStrItemP3T1( incomeIte2.getName(), incomeIte2.getValueYear()));
        incomeList.add(incomeIte2);

        //支出-结余分配
        FinalP3T1TotalItemVo expenditureItem = new FinalP3T1TotalItemVo();
        expenditureItem.setValueYear(yearData.getExpenditureRest());
        expenditureItem.setValueLastYear( null == lastYearData ? "0" : lastYearData.getExpenditureRest());
        expenditureItem.setName("支出-结余分配");
        expenditureItem.setRowNo(String.valueOf(indexNoExpenditure++));

        //结余分配 的比较说明
        String addOrSubStrItem3 = FinalY22Utils.getAddOrSubString(expenditureItem.getValueYear(), expenditureItem.getValueLastYear());
        String compareLastYearItem3 = FinalY22Utils.getInfoCompareStrItemP3T1( expenditureItem.getValueLastYear(), lastYear, addOrSubStrItem3);
        /*String compareLastYearItem3 = String.format("%s.%s%s万元。较%s年度决算数%s万元，%s" ,
                indexNoExpenditure++, expenditureItem.getName(), expenditureItem.getValueYear(),
                lastYear,expenditureItem.getValueLastYear(), addOrSubStrItem3);*/

        expenditureItem.setCompareLastYear(compareLastYearItem3);
        expenditureItem.setInfo(FinalY22Utils.getInfoStrItemP3T1( expenditureItem.getName(), expenditureItem.getValueYear()));
        expenditureList.add(expenditureItem);


        //支出-年末结转和结余
        FinalP3T1TotalItemVo expenditureItem2 = new FinalP3T1TotalItemVo();
        expenditureItem2.setValueYear(yearData.getExpenditureYearEnd());
        expenditureItem2.setValueLastYear( null == lastYearData ? "0" : lastYearData.getExpenditureYearEnd());
        expenditureItem2.setName("支出-年末结转和结余");
        expenditureItem2.setRowNo(String.valueOf(indexNoExpenditure++));

        //年末结转和结余 的比较说明
        String addOrSubStrItem4 = FinalY22Utils.getAddOrSubString(expenditureItem2.getValueYear(), expenditureItem2.getValueLastYear());
        String compareLastYearItem4 = FinalY22Utils.getInfoCompareStrItemP3T1(expenditureItem2.getValueLastYear(), lastYear, addOrSubStrItem4);
        /*String compareLastYearItem4 = String.format("%s.%s%s万元。较%s年度决算数%s万元，%s" ,
                indexNoExpenditure++, expenditureItem2.getName(), expenditureItem2.getValueYear(),
                lastYear,expenditureItem2.getValueLastYear(), addOrSubStrItem4);*/

        expenditureItem2.setCompareLastYear(compareLastYearItem4);
        expenditureItem2.setInfo(FinalY22Utils.getInfoStrItemP3T1( expenditureItem2.getName(), expenditureItem2.getValueYear()));
        expenditureList.add(expenditureItem2);

    }

}
