package com.sz.common.service.sys.web.utils;
import com.sz.common.service.sys.service.api.model.sys.dict.SysDict;
import com.sz.common.service.sys.service.api.model.sys.dict.SysDictVO;
import com.sz.framework.base.enums.annotations.EnumDesc;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.util.ClassUtils;
public class DictUtil {
private static final String BASE_ENUM_PACKAGE_PATH = "com.sz.common.enums";
private static final String COMMON_ENUM_PACKAGE_PATH = "com.sz.common.service.sys.service.api.enums";
private static final String GET_PARAM = "getDictParam";
private static final String GET_KEY = "getDictKey";
private static final String GET_NAME = "getDisplayName";
private static Logger logger = LoggerFactory.getLogger(DictUtil.class);
private static ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
private static MetadataReaderFactory metadataReaderFactory;
private static Environment environment;
private DictUtil() {
}
private static String[] getAllPackages(String... customPackages) {
List<String> packages = new ArrayList();
String[] strings = customPackages;
int var3 = customPackages.length;
for(int var4 = 0; var4 < var3; ++var4) {
String path = strings[var4];
if (StringUtils.isNotEmpty(path)) {
packages.add(path);
}
}
packages.add("com.sz.common.service.sys.service.api.enums");
packages.add("com.sz.common.enums");
strings = new String[packages.size()];
return (String[])packages.toArray(strings);
}
public static Set<Class<?>> scan(String... basePackages) {
try {
Set<ClassMetadata> classMetadatas = new HashSet();
String[] var2 = basePackages;
int var3 = basePackages.length;
for(int var4 = 0; var4 < var3; ++var4) {
String basePackage = var2[var4];
String packageSearchPath = "classpath*:" + resolveBasePackage(basePackage) + "/**/*.class";
Resource[] resource = resourcePatternResolver.getResources(packageSearchPath);
if (resource != null) {
Resource[] var8 = resource;
int var9 = resource.length;
for(int var10 = 0; var10 < var9; ++var10) {
Resource res = var8[var10];
if (res.isReadable()) {
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(res);
classMetadatas.add(metadataReader.getClassMetadata());
}
}
}
}
Set<Class<?>> classes = (Set)classMetadatas.stream().map(ClassMetadata::getClassName).map((name) -> {
try {
return Class.forName(name);
} catch (Throwable var2) {
return null;
}
}).filter((clazz) -> {
return clazz != null;
}).collect(Collectors.toSet());
return classes;
} catch (IOException var13) {
throw new BeanDefinitionStoreException("I/O failure during classpath scanning", var13);
}
}
private static String resolveBasePackage(String basePackage) {
return ClassUtils.convertClassNameToResourcePath(environment.resolveRequiredPlaceholders(basePackage));
}
static {
metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
environment = new StandardEnvironment();
}
}