From dee56ed8d52f1d8ee1f89b369561c49e9b3b7c2d Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期五, 23 一月 2026 17:56:31 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New' into dev_New
---
src/main/java/com/ruoyi/common/enums/BaseEnum.java | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/common/enums/BaseEnum.java b/src/main/java/com/ruoyi/common/enums/BaseEnum.java
new file mode 100644
index 0000000..cf84dde
--- /dev/null
+++ b/src/main/java/com/ruoyi/common/enums/BaseEnum.java
@@ -0,0 +1,58 @@
+package com.ruoyi.common.enums;
+
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+public interface BaseEnum<T> {
+ @JsonValue
+ T getCode();
+
+ String getValue();
+
+ /**
+ * 閫氱敤闈欐�佸伐鍏锋柟娉曪紙鍙鎵�鏈夋灇涓捐皟鐢級
+ */
+ /**
+ * 閫氱敤闈欐�佸伐鍏锋柟娉曪細鏀寔浠� Integer 鎴� String 绫诲瀷鐨� Code 杩涜鍙嶅簭鍒楀寲
+ */
+ @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
+ static <E extends Enum<E> & BaseEnum<?>> E fromCode(Class<E> enumClass, Object code) {
+ if (code == null) {
+ return null;
+ }
+
+ // 鐩爣 Code 鐨勬暣鏁板��
+ Integer targetCode = null;
+
+ if (code instanceof Integer) {
+ // 1. 濡傛灉浼犲叆鐨勬槸鏁板瓧 (Integer)
+ targetCode = (Integer) code;
+ } else if (code instanceof String) {
+ // 2. 濡傛灉浼犲叆鐨勬槸瀛楃涓� ("1")
+ try {
+ // 灏濊瘯灏嗗瓧绗︿覆杞崲涓烘暣鏁�
+ targetCode = Integer.valueOf((String) code);
+ } catch (NumberFormatException e) {
+ // 濡傛灉瀛楃涓蹭笉鏄湁鏁堢殑鏁板瓧锛堜緥濡� "Unknown"锛夛紝鍒� targetCode 淇濇寔涓� null
+ // 鎮ㄤ篃鍙互鍦ㄨ繖閲岃褰曟棩蹇楁垨鎵ц鍏朵粬閿欒澶勭悊
+ // System.err.println("鏃犳硶灏嗗瓧绗︿覆 Code 杞崲涓烘暟瀛�: " + code);
+ return null; // 鎴栬�呭湪鎵句笉鍒板尮閰嶇殑鎯呭喌涓嬭繑鍥� null
+ }
+ }
+ // else if (code instanceof Long) { ... 鎮ㄤ篃鍙互娣诲姞瀵� Long 绫诲瀷鐨勬敮鎸� }
+
+ if (targetCode == null) {
+ return null;
+ }
+
+ // 浣跨敤鑾峰彇鍒扮殑鏁存暟鍊艰繘琛屾煡鎵�
+ for (E e : enumClass.getEnumConstants()) {
+ if (e.getCode().equals(targetCode)) {
+ return e;
+ }
+ }
+ return null;
+ }
+
+}
\ No newline at end of file
--
Gitblit v1.9.3