1.修改数据源标识的获取途径,由原先从前端传递,到从网关统一传递

This commit is contained in:
yangsb
2024-04-12 14:49:44 +08:00
parent 83318aefcf
commit 00016e4c9b
6 changed files with 36 additions and 10 deletions
@@ -26,6 +26,7 @@ public interface GlobalErrorCodeConstants {
ErrorCode LOCKED = new ErrorCode(423, "请求失败,请稍后重试"); // 并发请求,不允许
ErrorCode TOO_MANY_REQUESTS = new ErrorCode(429, "请求过于频繁,请稍后重试");
ErrorCode DATA_SOURCE_CODE_NOT_FOUND = new ErrorCode(430, "未传递数据源标识");
ErrorCode ORGAN_ID_NOT_FOUND = new ErrorCode(431, "未传组织标识");
// ========== 服务端错误段 ==========
@@ -19,7 +19,7 @@ import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConsta
*/
public class DataSourceFilter extends OncePerRequestFilter {
//数据源编码
private static final String DATA_SOURCE_CODE = "dataCode";
private static final String DATA_SOURCE_CODE = "data-code";
private WebProperties webProperties;
@@ -36,12 +36,12 @@ public class DataSourceFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String dataSourceCode = request.getHeader(DATA_SOURCE_CODE);
if(StrUtil.isBlank(dataSourceCode)) {
String dataCode = request.getHeader(DATA_SOURCE_CODE);
if(StrUtil.isEmpty(dataCode)) {
ServletUtils.writeJSON(response, CommonResult.error(DATA_SOURCE_CODE_NOT_FOUND));
return;
}
DynamicDataSourceContextHolder.push(dataSourceCode);
DynamicDataSourceContextHolder.push(dataCode);
filterChain.doFilter(request, response);
DynamicDataSourceContextHolder.clear();
}