为枚举类添加 编码->名称 转换方法

master
面包骑士 2024-08-23 18:22:55 +08:00
parent f38c958804
commit 19c9225aa0
7 changed files with 57 additions and 3 deletions

View File

@ -35,4 +35,17 @@ public enum SysApiState {
.map(SysApiState::getCode)
.anyMatch(c -> c.equals(code));
}
/**
* ,
* @param code
* @return
*/
public static String getInfoByCode(String code){
return Arrays.stream(values())
.filter(c -> c.getCode().equals(code))
.findFirst()
.map(SysApiState::getInfo)
.orElse("-");
}
}

View File

@ -37,4 +37,17 @@ public enum SysCheckState {
.map(SysCheckState::getCode)
.anyMatch(c -> c.equals(code));
}
/**
* ,
* @param code
* @return
*/
public static String getInfoByCode(String code){
return Arrays.stream(values())
.filter(c -> c.getCode().equals(code))
.findFirst()
.map(SysCheckState::getInfo)
.orElse("-");
}
}

View File

@ -38,4 +38,17 @@ public enum SysDBType {
.map(SysDBType::getCode)
.anyMatch(c -> c.equals(code));
}
/**
* ,
* @param code
* @return
*/
public static String getInfoByCode(String code){
return Arrays.stream(values())
.filter(c -> c.getCode().equals(code))
.findFirst()
.map(SysDBType::getInfo)
.orElse("-");
}
}

View File

@ -35,9 +35,9 @@ public enum SysPayType {
}
/**
* ,
* @param code
* @return
* ,
* @param code
* @return
*/
public static String getInfoByCode(String code){
return Arrays.stream(values())

View File

@ -32,4 +32,17 @@ public enum SysYesNo {
.map(SysYesNo::getCode)
.anyMatch(c -> c.equals(code));
}
/**
* ,
* @param code
* @return
*/
public static String getInfoByCode(String code){
return Arrays.stream(values())
.filter(c -> c.getCode().equals(code))
.findFirst()
.map(SysYesNo::getInfo)
.orElse("-");
}
}

View File

@ -19,4 +19,5 @@ public enum UserStatus {
this.info = info;
}
}

View File

@ -692,6 +692,7 @@ public class Convert {
public static String str (Object obj, String charsetName) {
try{
return str(obj, Charset.forName(charsetName.isEmpty()? Constants.UTF8 : charsetName));
// return str(obj, Charset.forName(charsetName));
}catch (Exception exception){
log.error("字符转换异常: [{}-{}] -> {}",obj,charsetName,exception.getMessage(),exception);
throw new RuntimeException(exception);