parent
f4f04ace01
commit
2ea90d207b
8 changed files with 100 additions and 15 deletions
@ -0,0 +1,85 @@ |
||||
package org.springblade.desk.energy.util; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.videasoft.configs.EnumConfiger; |
||||
import com.videasoft.configs.XmlConfigReader; |
||||
import jakarta.annotation.PostConstruct; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.text.MessageFormat; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
@Component |
||||
public class Configer { |
||||
private static final Map<String, String> configerMap = new LinkedHashMap(); |
||||
private static final Map<String, EnumConfiger> enumConfigerMap = new LinkedHashMap(); |
||||
|
||||
public Configer() { |
||||
} |
||||
|
||||
public static String getValue(String code) { |
||||
return (String)configerMap.get(code); |
||||
} |
||||
|
||||
public static String getValue(String code, String defaultValue) { |
||||
String v = getValue(code); |
||||
return v == null ? defaultValue : v; |
||||
} |
||||
|
||||
public static String getValue(String id, String[] args) { |
||||
String value = getValue(id); |
||||
if (value != null) { |
||||
value = MessageFormat.format(value, (Object[])args); |
||||
} |
||||
|
||||
return value; |
||||
} |
||||
|
||||
public static EnumConfiger getEnumConfiger(String id) { |
||||
return (EnumConfiger)enumConfigerMap.get(id); |
||||
} |
||||
|
||||
public static String getEnumValue(String id, String code) { |
||||
String enumValue = null; |
||||
EnumConfiger enumConfiger = getEnumConfiger(id); |
||||
if (enumConfiger != null) { |
||||
enumValue = enumConfiger.getEnumValue(code); |
||||
} |
||||
|
||||
return enumValue; |
||||
} |
||||
|
||||
public static String getEnumValue(String id, String code, String[] args) { |
||||
String enumValue = getEnumValue(id, code); |
||||
if (enumValue != null) { |
||||
enumValue = MessageFormat.format(enumValue, (Object[])args); |
||||
} |
||||
|
||||
return enumValue; |
||||
} |
||||
|
||||
public static JSONObject getJsonEnum(String id) { |
||||
JSONObject json = new JSONObject(); |
||||
EnumConfiger enumConfiger = getEnumConfiger(id); |
||||
if (enumConfiger != null) { |
||||
json.putAll(enumConfiger.getOption()); |
||||
} |
||||
|
||||
return json; |
||||
} |
||||
@PostConstruct |
||||
public static void init() { |
||||
XmlConfigReader loader = new XmlConfigReader(); |
||||
configerMap.clear(); |
||||
configerMap.putAll(loader.loadKeyValues()); |
||||
enumConfigerMap.clear(); |
||||
enumConfigerMap.putAll(loader.loadEnumConfigs()); |
||||
} |
||||
|
||||
public static void appendLoad(XmlConfigReader reader) { |
||||
if (reader != null) { |
||||
configerMap.putAll(reader.loadKeyValues()); |
||||
enumConfigerMap.putAll(reader.loadEnumConfigs()); |
||||
} |
||||
} |
||||
} |
||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue