package com.yunfeiyun.agmp.common.constant;

/**
 * 系统错误定义
 * @author 杨晓辉
 */
public enum ErrorCode {

    SUCCESS(Codes.CODE_SUCCESS, "操作成功"),
    FAILURE(Codes.CODE_FAILURE, "操作失败"),
    UNAUTHORIZED_ERROR(Codes.CODE_AUTH, "授权不可用"),
    UNKNOWN_ERROR(Codes.CODE_UNKNOWN, "服务暂不可用"),
    SERVICE_UNKNOWN_ERROR(Codes.CODE_UNKNOWN, "微服务未知错误"),
    API_DISABLED(Codes.CODE_UNKNOWN, "服务不可用，路由被禁用"),
    GATEWAY_RESPONSE_TIMEOUT(Codes.CODE_UNKNOWN, "网关响应超时"),
    REQUEST_LIMIT(Codes.CODE_UNKNOWN, "限流处理"),
    AOP_INVALID_AUTH_TOKEN(Codes.CODE_AUTH, "无效的访问令牌"),
    AOP_AUTH_TOKEN_TIME_OUT(Codes.CODE_AUTH, "访问令牌已过期"),
    AOP_INVALID_APP_AUTH_TOKEN(Codes.CODE_AUTH, "无效的应用授权令牌"),
    AOP_INVALID_APP_AUTH_TOKEN_NO_API(Codes.CODE_AUTH, "商户未授权当前接口"),
    AOP_APP_AUTH_TOKEN_TIME_OUT(Codes.CODE_AUTH, "应用授权令牌已过期"),
    AOP_NO_PRODUCT_REG_BY_PARTNER(Codes.CODE_AUTH, "商户未签约任何产品"),
    MISSING_METHOD(Codes.CODE_MISSING, "缺少方法名参数"),
    MISSING_SIGNATURE(Codes.CODE_MISSING, "缺少签名参数"),
    MISSING_SIGNATURE_TYPE(Codes.CODE_MISSING, "缺少签名类型参数"),
    MISSING_SIGNATURE_KEY(Codes.CODE_MISSING, "缺少签名配置"),
    MISSING_APP_ID(Codes.CODE_MISSING, "缺少appId参数"),
    MISSING_TIMESTAMP(Codes.CODE_MISSING, "缺少时间戳参数"),
    MISSING_VERSION(Codes.CODE_MISSING, "缺少版本参数"),
    DECRYPTION_ERROR_MISSING_ENCRYPT_TYPE(Codes.CODE_MISSING, "解密出错, 未指定加密算法 "),
    INVALID_PARAMETER(Codes.CODE_INVALID, "参数无效"),
    RES_SAVE_FAIL(Codes.CODE_INVALID, "资源保存失败"),
    RES_DEL_FAIL(Codes.CODE_INVALID, "资源删除失败"),
    RES_CLEAN_FAIL(Codes.CODE_INVALID, "资源清理失败"),
    UPLOAD_OSS_FAIL(Codes.CODE_INVALID, "OSS云端文件上传失败"),
    UPLOAD_FAIL(Codes.CODE_INVALID, "文件上传失败"),
    UPLOAD_RESID_FAIL(Codes.CODE_INVALID, "文件上传失败,无效资源Id"),
    UPLOAD_BIZ_FAIL(Codes.CODE_INVALID, "文件上传失败,无效业务类型"),
    INVALID_FILE_EXTENSION(Codes.CODE_INVALID, "文件扩展名无效"),
    INVALID_FILE_SIZE(Codes.CODE_INVALID, "文件大小无效"),
    INVALID_METHOD(Codes.CODE_INVALID, "不存在的方法名"),
    INVALID_FORMAT(Codes.CODE_INVALID, "无效的数据格式"),
    INVALID_SIGNATURE_TYPE(Codes.CODE_INVALID, "无效的签名类型"),
    INVALID_SIGNATURE(Codes.CODE_INVALID, "无效签名"),
    INVALID_ENCRYPT_TYPE(Codes.CODE_INVALID, "无效的加密类型"),
    INVALID_ENCRYPT(Codes.CODE_INVALID, "解密异常"),
    INVALID_APP_ID(Codes.CODE_INVALID, "无效的appId参数"),
    INVALID_TIMESTAMP(Codes.CODE_INVALID, "非法的时间戳参数"),
    INVALID_CHARSET(Codes.CODE_INVALID, "字符集错误"),
    INVALID_DIGEST(Codes.CODE_INVALID, "摘要错误"),
    DECRYPTION_ERROR_NOT_VALID_ENCRYPT_TYPE(Codes.CODE_INVALID, "解密出错"),
    DECRYPTION_ERROR_NOT_VALID_ENCRYPT_KEY(Codes.CODE_INVALID, "解密出错"),
    DECRYPTION_ERROR_UNKNOWN(Codes.CODE_INVALID, "解密出错"),
    MISSING_SIGNATURE_CONFIG(Codes.CODE_INVALID, "验签出错"),
    NOT_SUPPORT_APP_AUTH(Codes.CODE_INVALID, "本接口不支持第三方代理调用"),
    SUSPECTED_ATTACK(Codes.CODE_INVALID, "可疑的攻击请求"),
    INVALID_CONTENT_TYPE(Codes.CODE_INVALID, "无效的content-type"),
    BIZ_ERROR(Codes.CODE_BIZ, "业务处理失败"),
    ADD_PWDOLD_ERROR(Codes.CODE_INVALID, "修改密码失败，旧密码错误"),
    ADD_PWDDIFF_ERROR(Codes.CODE_INVALID, "修改密码失败，新密码不能与旧密码相同"),
    ADD_PWDUNKNOWN_ERROR(Codes.CODE_INVALID, "修改密码异常，请联系管理员"),
    ADD_PROFILE_BASE_ERROR(Codes.CODE_INVALID, "修改个人信息异常，请联系管理员"),
    ADD_PROFILE_MOBILE_ERROR(Codes.CODE_INVALID, "修改个人信息异常，手机号码已存在"),
    ADD_PROFILE_EMAIL_ERROR(Codes.CODE_INVALID, "修改个人信息异常，邮箱账号已存在"),
    ADD_MENU_NAME_ERROR(Codes.CODE_INVALID, "操作单名称失败，菜单名称已存在"),
    ADD_MENU_OPENTYPE_ERROR(Codes.CODE_INVALID, "操作菜单链接失败，失败，地址必须以http(s)://开头"),
    ADD_MENU_PARENT_ERROR(Codes.CODE_INVALID, "操作单名称失败，上级菜单不能选择自己"),
    ADD_MENU_HAVCHILD_ERROR(Codes.CODE_INVALID, "存在子菜单,不允许删除"),
    ADD_MENU_HAVGIVE_ERROR(Codes.CODE_INVALID, "菜单已分配,不允许删除"),
    ADD_MENU_VALID_ERROR(Codes.CODE_INVALID, "操作菜单失败"),
    ADD_DICT_NAME_ERROR(Codes.CODE_INVALID, "操作字典失败，参数键名已存在"),
    ADD_CONF_NAME_ERROR(Codes.CODE_INVALID, "操作参数失败，参数键名已存在"),
    ADD_ROLE_NAME_ERROR(Codes.CODE_INVALID, "修改角色失败，角色名称已存在"),
    ADD_ROLE_PERM_ERROR(Codes.CODE_INVALID, "新增角色失败，角色权限已存在"),
    ADD_ROLE_FAIL_ERROR(Codes.CODE_INVALID, "修改角色失败，请联系管理员"),
    INSUFFICIENT_ISV_PERMISSIONS(Codes.CODE_PERM, "请检查配置的账户是否有当前接口权限"),
    INSUFFICIENT_USER_PERMISSIONS(Codes.CODE_PERM, "代理的商户没有当前接口权限"),
    ROUTE_NO_PERMISSIONS(Codes.CODE_PERM, "没有当前接口权限"),
    ACCESS_FORBIDDEN(Codes.CODE_PERM, "没有权限，请联系管理员授权"),
    IP_FORBIDDEN(Codes.CODE_PERM, "禁止IP访问"),
    EXIST_FORBID_DELETE(Codes.CODE_FORBID_DELETE, "已存在关联,不允许删除"),
    EXIST_FORBID_ALLOC(Codes.CODE_FORBID_DELETE, "已分配关联,不允许删除"),
    AUTH_SSO(Codes.CODE_SSO, "认证集成门户失败"),
    CUSTOM_BIND_ERROR(Codes.CODE_CUSTOM_BIND, "自定义验证异常"),
    UNKNONW_RUNTIME_ERROR(Codes.CODE_UNKNONW_RUNTIME, "未知运行时异常"),
    SYSTEM_ERROR(Codes.CODE_SYSTEM, "系统异常"),
    WEATHER_PARAM_GET_ERROR(Codes.CODE_SYSTEM,"获取天气信息参数异常"),
    REQUEST_TYPE_UNSUPPORT(Codes.CODE_REQ_TYPE_UNSUPPORT, "请求方式不支持"),
    UPLOAD_FILESZIE_LIMIT(Codes.CODE_UPLOAD_FILESZIE_LIMIT, "upload.exceed.maxSize"),
    UPLOAD_FILENAME_EXCEED(Codes.CODE_UPLOAD_FILENAME_EXCEED, " upload.filename.exceed.length"),
    PASSWORD_ERROR(Codes.CODE_AUTH, "密码错误"),
    VERIFYCODE_ERROR(Codes.CODE_AUTH, "验证码失效"),
    VERIFYCODE_LOGIN_ERROR(Codes.CODE_AUTH, "验证码不正确"),
    VERIFYCODE_GEN_ERROR(Codes.CODE_AUTH, "验证码生成错误"),
    USERPWD_EMPTY_ERROR(Codes.CODE_AUTH, "用户名或密码错误"),
    PWD_UNRANGE_ERROR(Codes.CODE_AUTH, "密码长度应在5~20位之间"),
    IP_INBLACKLIST_ERROR(Codes.CODE_AUTH, "IP不在白名单中"),
    LOGIN_USERNOEXIST_ERROR(Codes.CODE_AUTH, "登录用户不存在"),
    ACCOUNT_DELETE_ERROR(Codes.CODE_AUTH, "对不起，您的账号已被删除"),
    ACCOUNT_DISABLED_ERROR(Codes.CODE_AUTH, "对不起，您的账号已停用"),
    NO_ERROR(Codes.CODE_AUTH, "没有权限访问部门数据！"),
    ACCESS_BUSY(Codes.CODE_ACCESS_BUSY, "访问过于频繁，请稍候再试"),
    ADD_DUPLICATE_ERROR(Codes.CODE_FAILURE, "新增修改删除失败 已重复"),
    ADD_PARENT_ERROR(Codes.CODE_FAILURE, "新增修改删除失败 上级不能是自己"),
    ADD_DEACTIVATED_ERROR(Codes.CODE_FAILURE, "新增修改删除失败 包含未停用的节点"),
    ADD_EXISTCHILD_ERROR(Codes.CODE_FAILURE, "新增修改删除失败 存在下级节点"),
    ADD_EXISTRELNODE_ERROR(Codes.CODE_FAILURE, "新增修改删除失败 存在关联节点"),
    DEL_CURNODE_ERROR(Codes.CODE_FAILURE, "删除失败 当前正在使用"),
    DEL_TOPNODE_ERROR(Codes.CODE_FAILURE, "顶级节点不能删除"),
    DEL_ADMINNODE_ERROR(Codes.CODE_FAILURE, "超级管理员不能删除"),

    AUTH_SSO_LOGIN_USERNOEXIST(Codes.CODE_SSO, "认证集成门户失败-登录用户不存在"),
    AUTH_SSO_ACCOUNT_DELETE(Codes.CODE_SSO, "认证集成门户失败-账号已被删除"),
    AUTH_SSO_ACCOUNT_DISABLED(Codes.CODE_SSO, "认证集成门户失败-账号已停用"),
    AUTH_SSO_PASSWOR_ERROR(Codes.CODE_SSO, "认证集成门户失败-密码错误"),
    FMS_TASK_RCD_NO_EXIST(Codes.CODE_FMS_TASK_FAILED,"农事任务提交记录-农事任务提交记录不存在"),
    FMS_TASK_RCD_REPEATED_AUDIT(Codes.CODE_FMS_TASK_FAILED,"农事任务提交记录-农事任务提交记录重复审核"),
    FMS_TASK_TASK_NO_EXIST(Codes.CODE_FMS_TASK_FAILED,"农事任务提交记录-农事任务不存在"),
    FMS_TASK_TASK_REPEATED_AUDIT(Codes.CODE_FMS_TASK_FAILED,"农事任务提交记录-重复审核"),
    FMS_TASK_PICK_TASK_NO_EXIST(Codes.CODE_FMS_TASK_FAILED,"农事任务提交记录-采收任务不存在"),
    FMS_TASK_PATROL_TASK_NO_EXIST(Codes.CODE_FMS_TASK_FAILED,"农事任务提交记录-巡田任务不存在"),
    FMS_TASK_RCD_TASK_STATUS_EXIST(Codes.CODE_FMS_TASK_FAILED,"农事任务提交记录-请勿重复提交"),
    FMS_TASK_RCD_NO_AUDIT_PERMISSION(Codes.CODE_FMS_TASK_FAILED,"农事任务提交记录-无该农事任务的审核权限"),
    INVALID_PARAMETER_AREA(Codes.CODE_INVALID, "地块面积不能大于所属基地"),
    INVALID_PARAMETER_PLAN_AREA(Codes.CODE_INVALID, "种植面积不能大于地块面积"),
    FMS_WARN_RECORD_NO_EXIST(Codes.CODE_FMS_WARN_FAILED, "农事预警-预警记录不存在"),
    FMS_WARN_RECORD_NO_PENDING(Codes.CODE_FMS_WARN_FAILED, "农事预警-仅允许处理待处理状态预警"),
    FMS_WARN_RECORD_NO_READ(Codes.CODE_FMS_WARN_FAILED, "农事预警-仅允许设置已知晓状态"),
    WMS_STOCK_NOT_ENOUGH(Codes.CODE_WMS_STOCK_FAILED,"库存管理，库存不足"),
    WMS_STOCK_NOT_EXIST(Codes.CODE_WMS_STOCK_FAILED,"库存管理，库存不存在"),
    WMS_STOCK_CANNOT_CHANGE_ZERO(Codes.CODE_WMS_STOCK_FAILED,"库存管理，库存变动不能为0"),
    WMS_GOODS_EXIST(Codes.CODE_WMS_STOCK_FAILED,"库存管理，指定的仓库中已存在此类农资"),
    WMS_CHANGE_APPLY_AUDIT_STATUS_ERROR(Codes.CODE_WMS_CHANGE_FAILED,"变动申请,变动申请状态不正确"),
    WMS_CHANGE_APPLY_ITEM_INVALID(Codes.CODE_WMS_CHANGE_FAILED,"变动申请,变动申请物件信息无效"),
    WMS_CHANGE_APPLY_BIZ_TYPE_INVALID(Codes.CODE_WMS_CHANGE_FAILED,"变动申请,变动申请业务类型无效"),
    WMS_CHANGE_APPLY_CHANGE_BUSY(Codes.CODE_WMS_CHANGE_FAILED,"变动申请，当前时间库存变动处理繁忙，请稍后重试"),
    FMS_MACH_RECORD_EXIST(Codes.CODE_FMS_MACH_FAILED,"农机具管理，农机具已存在"),
    FMS_MACH_RECORD_NO_EXIST(Codes.CODE_FMS_MACH_FAILED,"农机具管理，农机具不存在"),
    FMS_MACH_RECORD_MACHNO_EXIST(Codes.CODE_FMS_MACH_FAILED,"农机具管理，农机具编号已存在"),
    FMS_CONFIG_NOT_EXIST(Codes.CODE_SYSTEM,"配置信息，配置信息不存在"),
    FMS_WEATHER_SEARCH_FAILED(Codes.CODE_THIRD_API_CONNECT_FAILED,"天气信息，接口查询失败"),
    FMS_POLICY_NOT_EXIST(Codes.CODE_THIRD_API_CONNECT_FAILED,"农事决策-记录不存在"),
    FMS_POLICY_DELETE_FAILED(Codes.CODE_THIRD_API_CONNECT_FAILED,"农事决策-记录删除失败"),
    FMS_CROP_EXIST(Codes.CODE_INVALID,"作物名称与作物种类已存在"),
    FMS_LAND_EXIST(Codes.CODE_INVALID, "基地名称已存在"),
    FMS_BLOCK_EXIST(Codes.CODE_INVALID, "该基地下地块名称已存在"),
    FMS_CROP_PERIOD_INVALID(Codes.CODE_INVALID, "阶段名称和时长均不能为空"),
    FMS_GOODS_EXIST(Codes.CODE_INVALID,"货物名称与货物类型已存在"),
    FMS_MACH_EXIST(Codes.CODE_INVALID,"农机具名称与类型已存在"),
    WMS_SUPPLIER_TYPE_IS_EMPTY(Codes.CODE_WMS_SUPPLIER_FAILED,"供应商类型不能为空"),
    FMS_PRODUCT_EXIST(Codes.CODE_INVALID, "该产品信息名称已存在"),
    GOOD_UNIT_KG_EXIST(Codes.CODE_INVALID, "单位KG字典中不存在，请确定"),
    FWMS_FINISH_GOODS_NOT_EXIST(Codes.CODE_SYSTEM,"农产品信息不能为空"),
    TSS_TRACE_CODE_DRAW_ERROR(Codes.TRACE_CODE,"溯源码生成过程异常"),
    TSS_TRACE_CODE_TO_BASE64_ERROR(Codes.TRACE_CODE,"溯源码图片转Base64失败"),
    TSS_TRACE_CODE_OUT_TO_STREAM_ERROR(Codes.TRACE_CODE,"溯源码图片流式输出失败"),
    TSS_TRACE_CODE_TPL_NOT_EXIST(Codes.TRACE_CODE,"溯源码模板不存在"),
    TSS_TRACE_CODE_TPL_ID_IS_BLOCK(Codes.TRACE_CODE,"溯源码模板标识为空"),
    TSS_TRACE_CODE_OVER_MAX_SCANS_TIMES(Codes.TRACE_CODE,"超出溯源码扫描次数"),
    TSS_TRACE_CODE_NO_MATCH_GOODS(Codes.TRACE_CODE,"溯源码与销售定的产品信息不匹配"),
    TSS_TRACE_CODE_OFFSITE_SCAN(Codes.TRACE_CODE,"溯源码异地扫码"),
    SPM_ORDER_SALE_STOCK_ID_IS_BLOCK(Codes.SPM_ORDER,"销售库存标识不存在"),
    SPM_ORDER_SALE_CUSTOMER_ID_IS_BLOCK(Codes.SPM_ORDER,"销售客户标识不存在"),
    SPM_ORDER_SALE_SEND_STATUS_ERROR(Codes.SPM_ORDER,"销售客户标识不存在"),

    TMN_DEVICE_SYNC_ERROR(Codes.TMN_DEVICE_FAILED,"设备同步错误"),
    TMN_DEVICE_LAND_ERROR(Codes.TMN_DEVICE_FAILED,"基地不存在"),
    TASK_TYPE_ERROR(Codes.CODE_INVALID,"任务类型有误"),
    TSS_TRACE_APPLY_NOT_EXIST(Codes.TRACE_CODE,"溯源码生成单不存在"),
    MPP_QUALITY_CHECK_NOT_EXIST(Codes.CODE_WMS_STOCK_FAILED,"产品未质检"),

    TMN_DEVICE_BIND_ERROR(Codes.TMN_DEVICE_FAILED,"设备已绑定，请先解绑"),
    TMN_DEVICE_NOT_EXIST_ERROR(Codes.TMN_DEVICE_FAILED,"设备不存在"),
    TMN_DEVICE_BIND_BLOCK_ERROR(Codes.TMN_DEVICE_FAILED,"设备已绑定到地块，请先解绑"),
    PICK_CHANGE_STATUS_HAS_IN(Codes.TMN_DEVICE_FAILED,"该记录已入库，无法重复入库"),
    ;

    private String code;
    private String message;

    ErrorCode(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }


    public static String getMessage(String code) {
        for (ErrorCode value : ErrorCode.values()) {
            if (value.getCode().equals(code)) {
                return value.getMessage();
            }
        }
        return null;
    }

    private static class Codes {
        public static final String CODE_SUCCESS = "000000";
        public static final String CODE_FAILURE = "001000";
        public static final String CODE_UNKNOWN = "200000";
        public static final String CODE_AUTH = "200001";
        public static final String CODE_MISSING = "400001";
        public static final String CODE_INVALID = "400002";
        public static final String CODE_BIZ = "400004";
        public static final String CODE_PERM = "400005";
        public static final String CODE_CUSTOM_BIND = "400006";
        public static final String CODE_UNKNONW_RUNTIME = "400007";
        public static final String CODE_SYSTEM = "400008";
        public static final String CODE_REQ_TYPE_UNSUPPORT = "400009";
        public static final String CODE_UPLOAD_FILESZIE_LIMIT = "400010";
        public static final String CODE_UPLOAD_FILENAME_EXCEED = "400011";
        public static final String CODE_ACCESS_BUSY = "400012";
        public static final String CODE_FORBID_DELETE = "400030";

        /** 农事任务异常 */
        public static final String CODE_FMS_TASK_FAILED = "500001";

        public static final String CODE_FMS_WARN_FAILED = "600001";

        /** 库存异常 */
        public static final String CODE_WMS_STOCK_FAILED = "700001";
        /** 变动异常 */
        public static final String CODE_WMS_CHANGE_FAILED = "700002";
        /**供应商异常*/
        public static final String CODE_WMS_SUPPLIER_FAILED = "700003";

        /**溯源码异常*/
        public static final String TRACE_CODE = "710001";
        /**销售单异常*/
        public static final String SPM_ORDER = "720001";


        /** 农机具异常 */
        public static final String CODE_FMS_MACH_FAILED = "800002";

        public static final String CODE_THIRD_API_CONNECT_FAILED = "900001";

        public static final String CODE_SSO = "300002";
        /** 农事决策异常 */
        public static final String CODE_FMS_POLICY_FAILED = "500002";

        public static final String TMN_DEVICE_FAILED = "600002";

    }

}