mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
报表服务新增入参/枚举/错误码i18n国际化整理
This commit is contained in:
+5
@@ -7,6 +7,11 @@ package com.cf.imes.framework.common.constants;
|
||||
* @since 2025/11/21 11:33
|
||||
*/
|
||||
public final class ResourceBundleConstants {
|
||||
/**
|
||||
* 错误码资源包
|
||||
*/
|
||||
public static final String MESSAGE_ERROR_PATH = "message_errorcode";
|
||||
|
||||
/**
|
||||
* 枚举资源包
|
||||
*/
|
||||
|
||||
+14
@@ -6,6 +6,8 @@ import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 国际化工具类
|
||||
*
|
||||
@@ -29,4 +31,16 @@ public class I18nUtils {
|
||||
public String getMessage(String code, Object... args) {
|
||||
return messageSource.getMessage(code, args, code, LocaleContextHolder.getLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取国际化描述
|
||||
*
|
||||
* @param locale
|
||||
* @param code
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
public String getMessage(Locale locale, String code, Object... args) {
|
||||
return messageSource.getMessage(code, args, code, locale);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class ResourceBundleUtils {
|
||||
* @param args 占位符数组
|
||||
* @return
|
||||
*/
|
||||
public static String getMessage(String baseName, String key, String defaultMessage, Locale locale, Object args) {
|
||||
public static String getMessage(String baseName, String key, String defaultMessage, Locale locale, Object... args) {
|
||||
try {
|
||||
ResourceBundle messageEnum = ResourceBundle.getBundle(baseName, locale);
|
||||
if (messageEnum != null) {
|
||||
|
||||
+5
-3
@@ -2,8 +2,8 @@ package com.cf.imes.framework.web.core.filter;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||
import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.framework.common.util.i18n.core.util.ResourceBundleUtils;
|
||||
import com.cf.imes.framework.common.util.servlet.ServletUtils;
|
||||
import com.cf.imes.framework.web.config.WebProperties;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -14,6 +14,9 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.cf.imes.framework.common.constants.ResourceBundleConstants.MESSAGE_ERROR_PATH;
|
||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.UNAUTHORIZED;
|
||||
|
||||
/**
|
||||
* @author there
|
||||
* 多数据源过滤器
|
||||
@@ -27,7 +30,6 @@ public class DataSourceFilter extends OncePerRequestFilter {
|
||||
*/
|
||||
public static final String AUTHORIZATION_BEARER = "Bearer";
|
||||
|
||||
|
||||
private WebProperties webProperties;
|
||||
|
||||
public DataSourceFilter (WebProperties webProperties) {
|
||||
@@ -46,7 +48,7 @@ public class DataSourceFilter extends OncePerRequestFilter {
|
||||
String dataCode = request.getHeader(DATA_SOURCE_CODE);
|
||||
if(CharSequenceUtil.isEmpty(dataCode)) {
|
||||
//TODO 如果要严谨一点,应该再去校验一下token
|
||||
ServletUtils.writeJSON(response, CommonResult.error(GlobalErrorCodeConstants.UNAUTHORIZED.getCode(), "访问令牌已过期"));
|
||||
ServletUtils.writeJSON(response, CommonResult.error(UNAUTHORIZED.getCode(), ResourceBundleUtils.getMessage(MESSAGE_ERROR_PATH, UNAUTHORIZED.getMsg(), UNAUTHORIZED.getMsg(), request.getLocale())));
|
||||
log.info("Let the user log in because there is no data-code! requestURI==>{}", request.getRequestURI());
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user