package com.oying.modules.message.common; import lombok.AllArgsConstructor; import lombok.Getter; import java.util.Arrays; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; /** * 订单状态枚举 * * @author leomon * @date 2025-05-20 */ @Getter @AllArgsConstructor public enum OrderStatusEnum { ZERO(0, "订单已提交"), ONE(1, "支付成功"), TWO(2, "商家已接单"), THREE(3, "骑手已接单"), FOUR(4, "商家已备货"), FIVE(5, "骑手已到店"), SIX(6, "骑手已取货"), SEVEN(7, "商品已送达"), EIGHT(8, "订单已完成"), NINE(9, "订单已取消"); private final Integer key; private final String value; /* ========== 工具方法 ========== */ /** 根据 key 获取枚举 */ public static OrderStatusEnum of(Integer key) { return key == null ? null : MAP.get(key); } /** 根据 key 获取描述 */ public static String descOf(Integer key) { OrderStatusEnum e = of(key); return e == null ? "" : e.getValue(); } /** 反向映射,提升查找速度 */ private static final Map MAP = Arrays.stream(values()) .collect(Collectors.toMap(OrderStatusEnum::getKey, Function.identity())); }