package com.syjy.calculate.entity;

import java.math.BigDecimal;
import java.util.HashMap;

/**
 * 数据返回格式化
 *
 * @author zcl
 * @version 1.0
 * @since 2022/9/9 10:34
 */
public class CalculateResult extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;

    /** 100 */
    public static final BigDecimal ONE_HUNDRED = new BigDecimal("100");

    /** 百分号 */
    public static final String PERCENT = "%";

    /** formula */
    public static final String FORMULA = "FORMULA";

    /** 光场站 */
    public static final String E1 = "E1";

    /** 风场站 */
    public static final String E2 = "E2";

    /** rules */
    public static final String RULES = "RULES";

    /** 下划线 */
    public static final String UNDERLINE = "_";

    /** 横线 */
    public static final String LINE = "-";

    /** 冒号 */
    public static final String COLON = ":";

    /** 忽略 */
    public static final String IGNORE = "666";

    /** 失败 */
    public static final String ERROR = "500";

    /** 状态码 */
    public static final String CODE_TAG = "code";

    /** 返回内容 */
    public static final String MSG_TAG = "msg";

    /** 数据对象 */
    public static final String DATA_TAG = "data";

    /** 公式上下文中的数据 */
    public static final String LIST = "list";

    /** 场站标识 */
    public static final String SIGN = "sign";

    /** 容量 */
    public static final String CAPACITY = "electricCapacity";

    /** 最大容量 */
    public static final String MAX_OPEN_CAPACITY = "maxOpenCapacity";

    /** 时间 */
    public static final String TIME = "time";

    /** 中期上报率考核量 */
    public static final String MID_REPORT_RATE = "ASSESSMENT_MID_REPORT_RATE";

    /** 短期上报率考核量 */
    public static final String SHORT_REPORT_RATE = "ASSESSMENT_SHORT_REPORT_RATE";

    /** 超短期上报率考核量 */
    public static final String ULTRA_SHORT_REPORT_RATE = "ASSESSMENT_ULTRA_SHORT_REPORT_RATE";

    /** 中期准确率考核量 */
    public static final String MID_ACCURACY_RATE = "ASSESSMENT_MID_ACCURACY_RATE";

    /** 短期准确率考核量 */
    public static final String SHORT_ACCURACY_RATE = "ASSESSMENT_SHORT_ACCURACY_RATE";

    /** 超短期准确率考核量 */
    public static final String ULTRA_SHORT_ACCURACY_RATE = "ASSESSMENT_ULTRA_SHORT_ACCURACY_RATE";

    /** 短期合格率考核量 */
    public static final String SHORT_PASS_RATE = "ASSESSMENT_SHORT_PASS_RATE";

    /** 短期合格率考核量 */
    public static final String ULTRA_SHORT_PASS_RATE = "ASSESSMENT_ULTRA_SHORT_PASS_RATE";

    /** 单机信息合格率考核量 */
    public static final String SINGLE_MACHINE_PASS_RATE = "SINGLE_MACHINE_PASS_RATE";

    /** 可用发电功率可用率 */
    public static final String ABLE_POWER_ACCURACY_RATE = "ABLE_POWER_ACCURACY_RATE";

    /** 理论发电功率可用率 */
    public static final String THEORY_POWER_ACCURACY_RATE = "THEORY_POWER_ACCURACY_RATE";

    /** 气象站/测风塔 可用率 */
    public static final String ANEMOMETER_TOWER_ACCURACY_RATE = "ANEMOMETER_TOWER_ACCURACY_RATE";

    /** 装机容量可用率 */
    public static final String INSTALLED_CAPACITY_ACCURACY_RATE = "INSTALLED_CAPACITY_ACCURACY_RATE";

    /** 可用容量可用率 */
    public static final String AVAILABLE_CAPACITY_ACCURACY_RATE = "AVAILABLE_CAPACITY_ACCURACY_RATE";

    /** 消息信息*/
    public static final String MSG_REQUEST_NULL = "入参为空";
    public static final String MSG_FORMULA_TYPE_NULL = "公式类型为空";
    public static final String MSG_FORMULA_TYPE_ERROR = "公式类型不正确";
    public static final String MSG_PROVINCE_NULL = "省调为空";
    public static final String MSG_STATION_CODE_NULL = "场站编码为空";
    public static final String MSG_ELECTRIC_TYPE_NULL = "场站类型为空";
    public static final String MSG_PHOTO_ELECTRICITY_RATED_CAPACITY_NULL = "光场站额定容量为空";
    public static final String MSG_WIND_RATED_CAPACITY_NULL = "风场站类型为空";
    public static final String MSG_ALL_RATED_CAPACITY_NULL = "全场额定容量为空";
    public static final String MSG_SHORT_REPORT_RATE_NULL = "短期上报率为空";
    public static final String MSG_ULTRA_SHORT_REPORT_RATE_NULL = "超短期上报率为空";
    public static final String MSG_SHORT_ACCURACY_RATE_NULL = "短期准确率为空";
    public static final String MSG_ULTRA_SHORT_ACCURACY_RATE_NULL = "超短期准确率为空";
    public static final String MSG_SHORT_PASS_RATE_NULL = "短期合格率为空";
    public static final String MSG_ULTRA_SHORT_PASS_RATE_NULL = "超短期合格率为空";

    public static final String MSG_CALCULATE_DATA_NULL = "无可用数据计算";
    public static final String MSG_CAP_NULL = "容量为空/0，不予考核";
    public static final String MSG_DATA_CHECK_ERROR = "数据校验错误";
    public static final String MSG_NO_FORMULA = "未匹配到公式:";
    public static final String MSG_CALCULATE_SUCCESS = "计算成功";
    public static final String MSG_CHECK_SUCCESS = "校验成功";
    public static final String MSG_CHECK_FAIL = "校验失败:";
    public static final String MSG_NO_CALCULATE_TYPE = "无计算公式";
    public static final String MSG_ERROR = "-0.99";
    public static final String MSG_DB_FAIL = "计算包所用数据库类型不存在或未在配置文件中配置:";

    public static final String MSG_CALCULATE_FAIL = "计算失败:";
    public static final String MSG_CAP_ZERO = "容量为0";
    public static final String MSG_SIZE_ZERO = "个数为0";
    public static final String STR_TRUE = "1";
    public static final String STR_FALSE = "0";

    public static final String DB_ERROR_TABLE_EXIST = "java.sql.SQLException: [KingbaseES Server]ERROR: relation \"t_calculation_formula\" does not exist";
    public static final String DB_MYSQL = "mysql";
    public static final String DB_KINGBASE = "kingbase";


    /**
     * 状态类型
     */
    public enum Type
    {
        /** 成功 */
        SUCCESS("200"),
        /** 忽略 */
        IGNORE("666"),
        /** 警告 */
        WARN("301"),
        /** 错误 */
        ERROR("500");
        private final String value;

        Type(String value)
        {
            this.value = value;
        }

        public String value()
        {
            return this.value;
        }
    }

    /**
     * 初始化一个新创建的 CalculateResult 对象
     *
     * @param type 状态类型
     * @param msg 返回内容
     */
    public CalculateResult(Type type, String msg)
    {
        super.put(CODE_TAG, type.value);
        super.put(MSG_TAG, msg);
    }

    /**
     * 初始化一个新创建的 CalculateResult 对象
     *
     * @param type 状态类型
     * @param msg 返回内容
     * @param data 数据对象
     */
    public CalculateResult(Type type, String msg, Object data)
    {
        super.put(CODE_TAG, type.value);
        super.put(MSG_TAG, msg);
        if (data != null) {
            super.put(DATA_TAG, data);
        }
    }

    /**
     * 返回成功消息
     *
     * @return 成功消息
     */
    public static CalculateResult success()
    {
        return CalculateResult.success("操作成功");
    }

    /**
     * 返回成功数据
     *
     * @return 成功消息
     */
    public static CalculateResult success(Object data)
    {
        return CalculateResult.success("操作成功", data);
    }

    /**
     * 返回成功消息
     *
     * @param msg 返回内容
     * @return 成功消息
     */
    public static CalculateResult success(String msg)
    {
        return CalculateResult.success(msg, null);
    }

    /**
     * 返回成功消息
     *
     * @param msg 返回内容
     * @param data 数据对象
     * @return 成功消息
     */
    public static CalculateResult success(String msg, Object data)
    {
        return new CalculateResult(Type.SUCCESS, msg, data);
    }

    /**
     * 返回警告消息
     *
     * @param msg 返回内容
     * @return 警告消息
     */
    public static CalculateResult warn(String msg)
    {
        return CalculateResult.warn(msg, null);
    }

    /**
     * 返回警告消息
     *
     * @param msg 返回内容
     * @param data 数据对象
     * @return 警告消息
     */
    public static CalculateResult warn(String msg, Object data)
    {
        return new CalculateResult(Type.WARN, msg, data);
    }

    /**
     * 返回错误消息
     *
     * @return
     */
    public static CalculateResult error()
    {
        return CalculateResult.error("操作失败");
    }

    /**
     * 返回错误消息
     *
     * @param msg 返回内容
     * @return 警告消息
     */
    public static CalculateResult error(String msg)
    {
        return CalculateResult.error(msg, null);
    }

    /**
     * 返回错误消息
     *
     * @param msg 返回内容
     * @param data 数据对象
     * @return 警告消息
     */
    public static CalculateResult error(String msg, Object data)
    {
        return new CalculateResult(Type.ERROR, msg, data);
    }
}

