baoshiwei
2025-03-12 f1208474f771a1c233d7425c8ed13fbaa0d521ac
ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/common/enums/MessageTypeEnum.java
@@ -3,8 +3,10 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
 * 消息类型枚举
@@ -14,14 +16,17 @@
@Getter
@AllArgsConstructor
public enum MessageTypeEnum {
    /**
     * 站内信
     */
    SYSTEM_MESSAGE("1", "站内信"),
    /**
     * 邮箱
     */
    EMAIL_MESSAGE("2", "邮箱"),
    /**
     * 短信
     */
@@ -31,21 +36,18 @@
    private final String desc;
    private final static Map<String, MessageTypeEnum> MESSAGE_TYPE_ENUM_MAP = new ConcurrentHashMap<>(MessageTypeEnum.values().length);
    static {
        for (MessageTypeEnum messageType : MessageTypeEnum.values()) {
            MESSAGE_TYPE_ENUM_MAP.put(messageType.code, messageType);
        }
    }
    private static final Map<String, MessageTypeEnum> MESSAGE_TYPE_ENUM_MAP = Arrays.stream(values())
        .collect(Collectors.toConcurrentMap(MessageTypeEnum::getCode, Function.identity()));
    /**
     * 根据消息类型 code 获取 MessageTypeEnum
     *
     * @param code 消息类型code
     * @return MessageTypeEnum
     */
    public static MessageTypeEnum getByCode(String code) {
        return MESSAGE_TYPE_ENUM_MAP.get(code);
        return MESSAGE_TYPE_ENUM_MAP.getOrDefault(code, null);
    }
}