# IndexTypeEnum.java

    package cloud.wconnect.finance.cons.pl;

    import cloud.wconnect.finance.pojo.dto.pl.ExportDescIndexDTO;
    import lombok.AllArgsConstructor;
    import lombok.Getter;

    /**
     * 指标类型枚举类
     *
     * @author lichen
     * @date 2025/9/27
     */
    @Getter
    @AllArgsConstructor
    public enum IndexTypeEnum {

        PTD("PTD", ExportDescIndexDTO::setPtd, false),
        REV("REV", ExportDescIndexDTO::setRev, true),
        PTD_BDGT("PTD_BDGT", ExportDescIndexDTO::setPtdBdgt, false),
        VAR_BDGT("VAR_BDGT", ExportDescIndexDTO::setVarBdgt, false),
        VAR_BDGT_PERCENTAGE("VAR_BDGT_PERCENTAGE", ExportDescIndexDTO::setVarBdgtPercentage, true),
        POR("POR", ExportDescIndexDTO::setPor, false),
        PTD_BUDGET_POR("PTD_BUDGET_POR", ExportDescIndexDTO::setPtdBudgetPor, false),
        PTD_FORECAST("PTD_FORECAST", ExportDescIndexDTO::setPtdForecast, false),
        PTD_LY("PTD_LY", ExportDescIndexDTO::setPtdLy, false),
        VAR_LY("VAR_LY", ExportDescIndexDTO::setVarLy, false),
        YTD("YTD", ExportDescIndexDTO::setYtd, false),
        YTD_REV("YTD_REV", ExportDescIndexDTO::setYtdRev, true),
        YTD_BDGT("YTD_BDGT", ExportDescIndexDTO::setYtdBdgt, false),
        YTD_VAR_BDGT("YTD_VAR_BDGT", ExportDescIndexDTO::setYtdVarBdgt, false),
        YTD_FORECAST("YTD_FORECAST", ExportDescIndexDTO::setYtdForecast, false),
        YTD_LY("YTD_LY", ExportDescIndexDTO::setYtdLy, false),
        YTD_VAR_LY("YTD_VAR_LY", ExportDescIndexDTO::setYtdVarLy, false),
        YTD_POR("YTD_POR", ExportDescIndexDTO::setYtdPor, false);

        /**
         * 指标类型
         */
        private String indexType;

        /**
         * 自定义 Setter 函数式接口
         */
        private final SetterBiConsumer setter;

        /**
         * 是否是百分比指标
         */
        private boolean isPercent;

        /**
         * 自定义 Setter 函数式接口
         */
        @FunctionalInterface
        public interface SetterBiConsumer {
            void accept(ExportDescIndexDTO dto, String value);
        }

        /**
         * 是否是 YTD 指标（根据M3基础数据计算的指标）
         *
         * @param indexType 指标类型
         * @return boolean
         * @author lichen
         * @date 2025/9/27
         */
        public static boolean isYtdIndex(String indexType) {
            return YTD.getIndexType().equals(indexType) || YTD_BDGT.getIndexType().equals(indexType) ||
                    YTD_FORECAST.getIndexType().equals(indexType) || YTD_LY.getIndexType().equals(indexType);
        }

        /**
         * 获取指标 setter
         *
         * @param indexType 指标类型
         * @return SetterBiConsumer
         * @author lichen
         * @date 2026/3/17
         */
        public static SetterBiConsumer getSetter(String indexType) {
            for (IndexTypeEnum value : IndexTypeEnum.values()) {
                if (value.getIndexType().equals(indexType)) {
                    return value.getSetter();
                }
            }
            return null;
        }

        /**
         * 获取指标是否是百分比
         *
         * @param indexType 指标类型
         * @return boolean
         * @author lichen
         * @date 2026/3/17
         */
        public static boolean isPercent(String indexType) {
            for (IndexTypeEnum value : IndexTypeEnum.values()) {
                if (value.getIndexType().equals(indexType)) {
                    return value.isPercent;
                }
            }
            return false;
        }
    }