{
@SuppressWarnings("unchecked")
static > T valueOf(Class extends BaseEnum
> enumType, P code) {
- BaseEnum
[] enumConstants = enumType.getEnumConstants();
- for (BaseEnum
pBaseEnum : enumConstants) {
- if (ObjectUtil.equals(code, pBaseEnum.getValue())) {
- return (T) pBaseEnum;
+ Map, SelectNodeVo>> nodeVoMap = GlobalCacheManager.ENUM_CACHE.get(enumType);
+ for (Map.Entry, SelectNodeVo>> mapEntry : nodeVoMap.entrySet()) {
+ if (ObjectUtil.equals(code, mapEntry.getValue().getValue())) {
+ return (T) mapEntry.getKey();
}
}
throw new MessageException("不存在值为:{} 的【{}】对象!", code.toString(), enumType.componentType().getSimpleName());
}
- default Object serializer() {
- return Dict.of(
- "value", this.getValue(),
- "label", this.getLabel()
- );
+ @SuppressWarnings("unchecked")
+ default SelectNodeVo serializer() {
+ Map, SelectNodeVo>> map = GlobalCacheManager.ENUM_CACHE.get(this.getClass());
+ if (map != null) {
+ return (SelectNodeVo) map.get(this);
+ }
+ return null;
}
+
}
diff --git a/policeSecurityServer/src/main/java/com/changhu/common/db/enums/CheckStatus.java b/policeSecurityServer/src/main/java/com/changhu/common/db/enums/CheckStatus.java
index 3116c84..b52332d 100644
--- a/policeSecurityServer/src/main/java/com/changhu/common/db/enums/CheckStatus.java
+++ b/policeSecurityServer/src/main/java/com/changhu/common/db/enums/CheckStatus.java
@@ -1,6 +1,5 @@
package com.changhu.common.db.enums;
-import cn.hutool.core.lang.Dict;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.changhu.common.annotation.IsExtData;
import com.changhu.common.db.BaseEnum;
@@ -25,12 +24,4 @@ public enum CheckStatus implements BaseEnum, IEnum {
@IsExtData
private final String color;
- @Override
- public Object serializer() {
- return Dict.of(
- "value", this.getValue(),
- "label", this.getLabel(),
- "extData", Dict.of("color", this.color)
- );
- }
}
diff --git a/policeSecurityServer/src/main/java/com/changhu/common/db/enums/EnterprisesUnitType.java b/policeSecurityServer/src/main/java/com/changhu/common/db/enums/EnterprisesUnitType.java
index e6425e7..91a36c4 100644
--- a/policeSecurityServer/src/main/java/com/changhu/common/db/enums/EnterprisesUnitType.java
+++ b/policeSecurityServer/src/main/java/com/changhu/common/db/enums/EnterprisesUnitType.java
@@ -4,12 +4,10 @@ import cn.hutool.core.lang.Dict;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.changhu.common.annotation.IsExtData;
import com.changhu.common.db.BaseEnum;
+import com.changhu.common.pojo.vo.SelectNodeVo;
import lombok.AllArgsConstructor;
import lombok.Getter;
-import java.util.Arrays;
-import java.util.stream.Collectors;
-
/**
* @author 20252
* @createTime 2024/11/5 下午4:22
@@ -46,11 +44,11 @@ public enum EnterprisesUnitType implements BaseEnum, IEnum {
private final String icon;
@Override
- public Object serializer() {
- return Dict.of(
- "value", this.getValue(),
- "label", this.getLabel(),
- "extData", Dict.of("icon", "/resources/icon/gaode/marker/" + this.icon)
- );
+ public SelectNodeVo serializer() {
+ return SelectNodeVo.builder()
+ .value(this.getValue())
+ .label(this.getLabel())
+ .extData(Dict.of("icon", "/resources/icon/gaode/marker/" + this.icon))
+ .build();
}
}
diff --git a/policeSecurityServer/src/main/java/com/changhu/common/db/enums/IsEnable.java b/policeSecurityServer/src/main/java/com/changhu/common/db/enums/IsEnable.java
index 9ab863e..5244f02 100644
--- a/policeSecurityServer/src/main/java/com/changhu/common/db/enums/IsEnable.java
+++ b/policeSecurityServer/src/main/java/com/changhu/common/db/enums/IsEnable.java
@@ -1,6 +1,5 @@
package com.changhu.common.db.enums;
-import cn.hutool.core.lang.Dict;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.changhu.common.annotation.IsExtData;
import com.changhu.common.db.BaseEnum;
@@ -25,12 +24,4 @@ public enum IsEnable implements BaseEnum, IEnum {
@IsExtData
private final String color;
- @Override
- public Object serializer() {
- return Dict.of(
- "value", this.getValue(),
- "label", this.getLabel(),
- "extData", Dict.of("color", this.color)
- );
- }
}
\ No newline at end of file
diff --git a/policeSecurityServer/src/main/java/com/changhu/common/enums/OpenApiType.java b/policeSecurityServer/src/main/java/com/changhu/common/enums/OpenApiType.java
index c68e356..db2de04 100644
--- a/policeSecurityServer/src/main/java/com/changhu/common/enums/OpenApiType.java
+++ b/policeSecurityServer/src/main/java/com/changhu/common/enums/OpenApiType.java
@@ -1,12 +1,10 @@
package com.changhu.common.enums;
-import cn.hutool.core.util.IdUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
-import java.util.UUID;
/**
* @author 20252
diff --git a/policeSecurityServer/src/main/java/com/changhu/controller/CommonController.java b/policeSecurityServer/src/main/java/com/changhu/controller/CommonController.java
index 0984600..ed3ed63 100644
--- a/policeSecurityServer/src/main/java/com/changhu/controller/CommonController.java
+++ b/policeSecurityServer/src/main/java/com/changhu/controller/CommonController.java
@@ -1,13 +1,7 @@
package com.changhu.controller;
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.lang.Dict;
-import cn.hutool.core.util.ClassUtil;
-import cn.hutool.core.util.ObjectUtil;
-import cn.hutool.core.util.ReflectUtil;
-import com.changhu.common.annotation.IsExtData;
import com.changhu.common.annotation.JsonBody;
-import com.changhu.common.db.BaseEnum;
+import com.changhu.common.cache.GlobalCacheManager;
import com.changhu.common.pojo.model.JsonResult;
import com.changhu.common.pojo.vo.SelectNodeVo;
import com.changhu.common.pojo.vo.TreeNodeVo;
@@ -20,16 +14,14 @@ import com.changhu.support.minio.service.MinioService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.annotation.PostConstruct;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
-import java.lang.reflect.Field;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* @author 20252
@@ -50,9 +42,6 @@ public class CommonController {
@Autowired
private AdministrativeDivisionService administrativeDivisionService;
- private static final Map>> enumsResult = new HashMap<>();
-
-
@Cacheable(value = "common", key = "'AdministrativeDivisionLevel' + #level + 'Tree'")
@Operation(summary = "行政区划树")
@GetMapping("/administrativeDivisionTree")
@@ -95,53 +84,11 @@ public class CommonController {
@Operation(summary = "字典数据")
@GetMapping("/enums")
public Map>> enums() {
+ // 初始化 enumsResult
+ Map>> enumsResult = new HashMap<>();
+ //将缓存的数据转换
+ GlobalCacheManager.ENUM_CACHE.forEach((aClass, item) -> enumsResult.put(aClass.getSimpleName(), item.values().stream().toList()));
return enumsResult;
}
- @SuppressWarnings("unchecked")
- @PostConstruct
- public void initEnums() {
- Set> classes = ClassUtil.scanPackageBySuper("com.changhu.common.db.enums", BaseEnum.class);
- for (Class> aClass : classes) {
- if (BaseEnum.class.isAssignableFrom(aClass)) {
- enumsResult.put(aClass.getSimpleName(), listSelectNodes((Class extends BaseEnum>>) aClass));
- }
- }
- }
-
- public static > List> listSelectNodes(Class enumType) {
- if (enumType == null) {
- return null;
- }
- Field[] fields = ReflectUtil.getFields(enumType);
-
- List extras = new ArrayList<>();
-
- for (Field field : fields) {
- IsExtData annotation = field.getAnnotation(IsExtData.class);
- if (ObjectUtil.isNotNull(annotation)) {
- extras.add(field.getName());
- }
- }
-
- T[] enumConstants = enumType.getEnumConstants();
- if (enumConstants == null) {
- return null;
- }
-
- return Stream.of(enumConstants).map(v -> {
- SelectNodeVo