com.kalvan.client.system.SystemUtil Maven / Gradle / Ivy
The newest version!
package com.kalvan.client.system;
import com.kalvan.client.context.RequestContextHolder;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Map;
/**
* 应用系统工具类
*
* @author kalvan
*/
@Component(SystemUtil.SYSTEM_UTIL)
public class SystemUtil {
public static final String SYSTEM_UTIL = "systemUtil";
private static SystemConfig staticSystemConfig;
@Resource
SystemConfig systemConfig;
@PostConstruct
private void init() {
setSystemConfig(systemConfig);
}
private static void setSystemConfig(SystemConfig systemConfig) {
staticSystemConfig = systemConfig;
}
public static SystemConfig getSystemConfig() {
return staticSystemConfig;
}
/**
* 国际化匹配
*
* @param message 原始消息
* @return 匹配语言的消息
*/
public static String getI18nMessage(String message) {
String language = RequestContextHolder.getContext().getLanguage();
if (StringUtils.isNotBlank(language)
&& getSystemConfig() != null
&& getSystemConfig().getI18nConfig() != null) {
I18nConfig i18nConfig = getSystemConfig().getI18nConfig();
if (i18nConfig.getMessage() != null) {
//返回码描述动态替换国际化匹配
Map descMap = i18nConfig.getMessage().get(language);
if (descMap != null && descMap.get(message) != null) {
return descMap.get(message);
}
}
}
return message;
}
}