package com.yunyan.business.document.y23.finalData;

import com.yunyan.business.document.y22.pojo.finalExcelY22.*;
import com.yunyan.common.utils.StringUtils;

import java.util.Objects;

public class FinalY23ChangeTableUtils {


    /**
     * 修改 table的空值为空串
     * @param dataVo
     */
    public static void changeZeroValueToBlank(FinalExcelDataVo dataVo) {
        changeT1(dataVo);
        changeT2(dataVo);
        changeT3(dataVo);
        //changeT4(dataVo);
        changeT5(dataVo);
        changeT6(dataVo);
        changeT9(dataVo);
    }

    /**
     * 设置 t1
     * @param dataVo
     */
    private static void changeT1(FinalExcelDataVo dataVo) {
        if(Objects.isNull(dataVo.getT1Z01Vo()) || Objects.isNull(dataVo.getT1Z01Vo().getList())) {
            return;
        }
        //t1
        dataVo.getT1Z01Vo().getList().forEach(item -> {
            if(FinalY23ChangeTableUtils.checkZeroString(item.getIncomeValue())) {
                item.setIncomeValue(FinalY23ChangeTableUtils.zeroStringToBlank(item.getIncomeValue()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getExpenditureValue())) {
                item.setExpenditureValue(FinalY23ChangeTableUtils.zeroStringToBlank(item.getExpenditureValue()));
            }
        });
    }

    /**
     * 设置 t2 的 0为空
     * @param dataVo
     */
    private static void changeT2(FinalExcelDataVo dataVo) {
        FinalZ03Vo entity = dataVo.getT2Z03Vo();
        if(Objects.isNull(entity)) {
            return;
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getTotal())) {
            entity.setTotal(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getTotal()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getAllocation())) {
            entity.setAllocation(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getAllocation()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getSubsidy())) {
            entity.setSubsidy(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getSubsidy()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getProfession())) {
            entity.setProfession(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getProfession()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getOperation())) {
            entity.setOperation(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getOperation()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getSubsidiary())) {
            entity.setSubsidiary(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getSubsidiary()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getOther())) {
            entity.setOther(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getOther()));
        }
        entity.getList().forEach(item -> {
            if(FinalY23ChangeTableUtils.checkZeroString(item.getTotal())) {
                item.setTotal(FinalY23ChangeTableUtils.zeroStringToBlank(item.getTotal()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getAllocation())) {
                item.setAllocation(FinalY23ChangeTableUtils.zeroStringToBlank(item.getAllocation()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getSubsidy())) {
                item.setSubsidy(FinalY23ChangeTableUtils.zeroStringToBlank(item.getSubsidy()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getProfession())) {
                item.setProfession(FinalY23ChangeTableUtils.zeroStringToBlank(item.getProfession()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getOperation())) {
                item.setOperation(FinalY23ChangeTableUtils.zeroStringToBlank(item.getOperation()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getSubsidiary())) {
                item.setSubsidiary(FinalY23ChangeTableUtils.zeroStringToBlank(item.getSubsidiary()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getOther())) {
                item.setOther(FinalY23ChangeTableUtils.zeroStringToBlank(item.getOther()));
            }
        });
    }

    private static void changeT3(FinalExcelDataVo dataVo) {
        FinalZ04Vo entity = dataVo.getT3Z04Vo();
        if(Objects.isNull(entity)) {
            return;
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getTotal())) {
            entity.setTotal(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getTotal()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getBase())) {
            entity.setBase(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getBase()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getProject())) {
            entity.setProject(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getProject()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getParent())) {
            entity.setParent(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getParent()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getOperation())) {
            entity.setOperation(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getOperation()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getSubsidiary())) {
            entity.setSubsidiary(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getSubsidiary()));
        }
        entity.getList().forEach(item -> {
            if(FinalY23ChangeTableUtils.checkZeroString(item.getTotal())) {
                item.setTotal(FinalY23ChangeTableUtils.zeroStringToBlank(item.getTotal()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getBase())) {
                item.setBase(FinalY23ChangeTableUtils.zeroStringToBlank(item.getBase()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getProject())) {
                item.setProject(FinalY23ChangeTableUtils.zeroStringToBlank(item.getProject()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getParent())) {
                item.setParent(FinalY23ChangeTableUtils.zeroStringToBlank(item.getParent()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getOperation())) {
                item.setOperation(FinalY23ChangeTableUtils.zeroStringToBlank(item.getOperation()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getSubsidiary())) {
                item.setSubsidiary(FinalY23ChangeTableUtils.zeroStringToBlank(item.getSubsidiary()));
            }
        });
    }

    private static void changeT4(FinalExcelDataVo dataVo) {
        FinalZ01S1Vo entity = dataVo.getT4Z01S1Vo();
        if(Objects.isNull(entity)) {
            return;
        }
        entity.getList().forEach(item -> {
            if(FinalY23ChangeTableUtils.checkZeroString(item.getIncomeValue())) {
                item.setIncomeValue(FinalY23ChangeTableUtils.zeroStringToBlank(item.getIncomeValue()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getExpenditureSubtotal())) {
                item.setExpenditureSubtotal(FinalY23ChangeTableUtils.zeroStringToBlank(item.getExpenditureSubtotal()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getExpenditurePublic())) {
                item.setExpenditurePublic(FinalY23ChangeTableUtils.zeroStringToBlank(item.getExpenditurePublic()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getExpenditureGovernment())) {
                item.setExpenditureGovernment(FinalY23ChangeTableUtils.zeroStringToBlank(item.getExpenditureGovernment()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getExpenditureState())) {
                item.setExpenditureState(FinalY23ChangeTableUtils.zeroStringToBlank(item.getExpenditureState()));
            }
        });
    }

    private static void changeT5(FinalExcelDataVo dataVo) {
        FinalZ07Vo entity = dataVo.getT5Z07Vo();
        if(Objects.isNull(entity)) {
            return;
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getExpenditureYearSubtotal())) {
            entity.setExpenditureYearSubtotal(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getExpenditureYearSubtotal()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getExpenditureBaseSubtotal())) {
            entity.setExpenditureBaseSubtotal(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getExpenditureBaseSubtotal()));
        }
        if(FinalY23ChangeTableUtils.checkZeroString(entity.getExpenditureProject())) {
            entity.setExpenditureProject(FinalY23ChangeTableUtils.zeroStringToBlank(entity.getExpenditureProject()));
        }
        entity.getList().forEach(item -> {
            if(FinalY23ChangeTableUtils.checkZeroString(item.getExpenditureYearSubtotal())) {
                item.setExpenditureYearSubtotal(FinalY23ChangeTableUtils.zeroStringToBlank(item.getExpenditureYearSubtotal()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getExpenditureBaseSubtotal())) {
                item.setExpenditureBaseSubtotal(FinalY23ChangeTableUtils.zeroStringToBlank(item.getExpenditureBaseSubtotal()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getExpenditureProject())) {
                item.setExpenditureProject(FinalY23ChangeTableUtils.zeroStringToBlank(item.getExpenditureProject()));
            }
        });
    }

    private static void changeT6(FinalExcelDataVo dataVo) {
        FinalZ08S1T6Vo entity = dataVo.getT6VZ08S1Vo();
        if(Objects.isNull(entity)) {
            return;
        }
        entity.getList().forEach(item -> {
            if(FinalY23ChangeTableUtils.checkZeroString(item.getAmount1())) {
                item.setAmount1(FinalY23ChangeTableUtils.zeroStringToBlank(item.getAmount1()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getAmount2())) {
                item.setAmount2(FinalY23ChangeTableUtils.zeroStringToBlank(item.getAmount2()));
            }
        });
    }

    /**
     * 财政拨款安排的“三公”经费支出决算表
     * @param dataVo
     */
    private static void changeT9(FinalExcelDataVo dataVo) {
        FinalF03Vo entity = dataVo.getT7F03Vo();
        if(Objects.isNull(entity)) {
            return;
        }
        entity.getList().forEach(item -> {
            if(FinalY23ChangeTableUtils.checkZeroString(item.getTotal())) {
                item.setTotal(FinalY23ChangeTableUtils.zeroStringToBlank(item.getTotal()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getAbroad())) {
                item.setAbroad(FinalY23ChangeTableUtils.zeroStringToBlank(item.getAbroad()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getCarSubtotal())) {
                item.setCarSubtotal(FinalY23ChangeTableUtils.zeroStringToBlank(item.getCarSubtotal()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getCarBuy())) {
                item.setCarBuy(FinalY23ChangeTableUtils.zeroStringToBlank(item.getCarBuy()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getCarOperate())) {
                item.setCarOperate(FinalY23ChangeTableUtils.zeroStringToBlank(item.getCarOperate()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getReception())) {
                item.setReception(FinalY23ChangeTableUtils.zeroStringToBlank(item.getReception()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getTotal2())) {
                item.setTotal2(FinalY23ChangeTableUtils.zeroStringToBlank(item.getTotal2()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getAbroad2())) {
                item.setAbroad2(FinalY23ChangeTableUtils.zeroStringToBlank(item.getAbroad2()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getCarSubtotal2())) {
                item.setCarSubtotal2(FinalY23ChangeTableUtils.zeroStringToBlank(item.getCarSubtotal2()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getCarBuy2())) {
                item.setCarBuy2(FinalY23ChangeTableUtils.zeroStringToBlank(item.getCarBuy2()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getCarOperate2())) {
                item.setCarOperate2(FinalY23ChangeTableUtils.zeroStringToBlank(item.getCarOperate2()));
            }
            if(FinalY23ChangeTableUtils.checkZeroString(item.getReception2())) {
                item.setReception2(FinalY23ChangeTableUtils.zeroStringToBlank(item.getReception2()));
            }
        });
    }

    /**
     * 检测是否为0
     * @param value
     * @return
     */
    private static boolean checkZeroString(String value) {
        if (StringUtils.isNotBlank(value) && "0".equals(value)) {
            return true;
        }
        return false;
    }

    /**
     * 0转换为空
     * @param value
     * @return
     */
    private static String zeroStringToBlank(String value) {
        if (StringUtils.isNotBlank(value) && "0".equals(value)) {
            return "";
        }
        return value;
    }

}
