package com.oying.modules.message.common; import lombok.AllArgsConstructor; import lombok.Getter; @Getter @AllArgsConstructor public enum PlatFormEnum { //1=买家 2=商户 3=骑手" BUYER(1, "买家"), MERCHANT(2, "商户"), RIDE(3, "骑手"); private final Integer key; private final String value; /** * 根据key获取枚举实例 * @param key key值 * @return 对应的枚举实例,未找到返回null */ public static PlatFormEnum getByKey(Integer key) { if (key == null) { return null; } for (PlatFormEnum platFormEnum : PlatFormEnum.values()) { if (platFormEnum.key.equals(key)) { return platFormEnum; } } return null; } /** * 根据value获取枚举实例 * @param value value值 * @return 对应的枚举实例,未找到返回null */ public static PlatFormEnum getByValue(String value) { if (value == null) { return null; } for (PlatFormEnum platFormEnum : PlatFormEnum.values()) { if (platFormEnum.value.equals(value)) { return platFormEnum; } } return null; } @Override public String toString() { return "PlatFormEnum{" + "key=" + key + ", value='" + value + '\'' + ", name='" + this.name() + '\'' + '}'; } }