# IndexCalculationDTO.java

    package cloud.wconnect.finance.pojo.dto.pl.index;

    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    import lombok.ToString;
    import org.apache.commons.lang3.StringUtils;

    import java.math.BigDecimal;
    import java.util.Collections;
    import java.util.List;
    import java.util.Objects;

    /**
     * 指标计算dto
     *
     * @author lichen
     * @date 2025/9/27
     */
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @ToString
    public class IndexCalculationDTO {

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

        /**
         * 指标值
         */
        private BigDecimal indexValue;

        /**
         * 是否计算成功
         */
        private boolean calculationResult;

        /**
         * 导致计算失败的计算因子，存储的是RowNumber
         */
        private List<String> failFactorList;

        /**
         * 指标名称id,只有计算PTD Forecast 和 YTD Forecast时才有值
         */
        private String indexNameId;

        public IndexCalculationDTO(String indexType, BigDecimal indexValue, boolean calculationResult, List<String> failFactorList) {
            this.indexType = indexType;
            this.indexValue = indexValue;
            this.calculationResult = calculationResult;
            this.failFactorList = failFactorList;
        }

        public IndexCalculationDTO(String indexType, BigDecimal indexValue, boolean calculationResult) {
            this.indexType = indexType;
            this.indexValue = indexValue;
            this.calculationResult = calculationResult;
            this.failFactorList = Collections.emptyList();
        }

        /**
         * 计算失败
         *
         * @param indexType      指标类型
         * @param indexNameId    指标名称id
         * @param failFactorList 失败的计算因子
         * @return cloud.wconnect.finance.pojo.dto.pl.index.IndexCalculationDTO
         * @author lichen
         * @date 2025/10/1
         */
        public static IndexCalculationDTO fail(String indexType, String indexNameId, List<String> failFactorList) {
            return new IndexCalculationDTO(indexType, null, false, failFactorList, indexNameId);
        }

        /**
         * 计算成功
         *
         * @param indexType   指标类型
         * @param indexValue  指标值
         * @param indexNameId 指标名称id
         * @return cloud.wconnect.finance.pojo.dto.pl.index.IndexCalculationDTO
         * @author lichen
         * @date 2025/10/1
         */
        public static IndexCalculationDTO success(String indexType, BigDecimal indexValue, String indexNameId) {
            return new IndexCalculationDTO(indexType, indexValue, true, Collections.emptyList(), indexNameId);
        }

        /**
         * 生成key
         *
         * @return java.lang.String
         * @author lichen
         * @date 2025/9/27
         */
        public String generateKey() {
            if (StringUtils.isNotBlank(indexNameId)) {
                return indexType + "_" + indexNameId;
            } else {
                return indexType;
            }
        }

    }