update
This commit is contained in:
@@ -1,50 +0,0 @@
|
|||||||
package com.cool.store.utils;
|
|
||||||
|
|
||||||
import com.cool.store.context.DataSourceContext;
|
|
||||||
import com.cool.store.context.UserContext;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class DataSourceHelper {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DataSourceHelper.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param
|
|
||||||
* @return void
|
|
||||||
* @throws
|
|
||||||
* @Title changeToMy
|
|
||||||
* @Description 切换到自己的数据库
|
|
||||||
*/
|
|
||||||
public static void changeToMy() {
|
|
||||||
DataSourceContext.clearDataSourceType();
|
|
||||||
String dbName = UserContext.getUser().getDbName();
|
|
||||||
DataSourceContext.setDataSourceType(dbName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param datasource
|
|
||||||
* @return void
|
|
||||||
* @throws
|
|
||||||
* @Title changeToSpecificDataSource
|
|
||||||
* @Description 切换到指定的数据库
|
|
||||||
*/
|
|
||||||
public static void changeToSpecificDataSource(String datasource) {
|
|
||||||
DataSourceContext.clearDataSourceType();
|
|
||||||
String dbName = datasource;
|
|
||||||
DataSourceContext.setDataSourceType(dbName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param
|
|
||||||
* @return void
|
|
||||||
* @throws
|
|
||||||
* @Title reset
|
|
||||||
* @Description 重置链接到主库
|
|
||||||
*/
|
|
||||||
public static void reset() {
|
|
||||||
DataSourceContext.clearDataSourceType();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.cool.store.enums.ErrorCodeEnum;
|
import com.cool.store.enums.ErrorCodeEnum;
|
||||||
import com.cool.store.response.ResponseResult;
|
import com.cool.store.response.ResponseResult;
|
||||||
import com.cool.store.context.UserContext;
|
import com.cool.store.context.UserContext;
|
||||||
import com.cool.store.utils.DataSourceHelper;
|
|
||||||
import com.cool.store.utils.RedisUtilPool;
|
import com.cool.store.utils.RedisUtilPool;
|
||||||
import com.cool.store.context.CurrentUser;
|
import com.cool.store.context.CurrentUser;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -97,7 +96,7 @@ public class TokenValidateFilter implements Filter {
|
|||||||
ResponseResult.fail(ErrorCodeEnum.ACCESS_TOKEN_INVALID)));
|
ResponseResult.fail(ErrorCodeEnum.ACCESS_TOKEN_INVALID)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("url:{}, access_token:{}, userId:{}, username:{}, enterpriseId:{}", uri, accessToken, currentUser.getUserId(), currentUser.getName(), currentUser.getEnterpriseId());
|
log.info("url:{}, access_token:{}, userId:{}, username:{}", uri, accessToken, currentUser.getUserId(), currentUser.getName());
|
||||||
}
|
}
|
||||||
if(StringUtils.isBlank(userStr) && !isInWhiteList){
|
if(StringUtils.isBlank(userStr) && !isInWhiteList){
|
||||||
response.setStatus(HttpStatus.OK.value());
|
response.setStatus(HttpStatus.OK.value());
|
||||||
@@ -107,7 +106,6 @@ public class TokenValidateFilter implements Filter {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
UserContext.setUser(userStr);
|
UserContext.setUser(userStr);
|
||||||
DataSourceHelper.changeToMy();
|
|
||||||
filterChain.doFilter(servletRequest, servletResponse);
|
filterChain.doFilter(servletRequest, servletResponse);
|
||||||
} finally {
|
} finally {
|
||||||
UserContext.removeUser();
|
UserContext.removeUser();
|
||||||
|
|||||||
@@ -1,18 +1,10 @@
|
|||||||
package com.cool.store.controller;
|
package com.cool.store.controller;
|
||||||
|
|
||||||
import com.cool.store.dto.enterprise.EnterpriseUserDTO;
|
|
||||||
import com.cool.store.response.ResponseResult;
|
|
||||||
import com.cool.store.service.EnterpriseUserService;
|
import com.cool.store.service.EnterpriseUserService;
|
||||||
import com.cool.store.utils.DataSourceHelper;
|
|
||||||
import com.cool.store.vo.buser.EnterpriseUserPageVO;
|
|
||||||
import com.github.pagehelper.PageInfo;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhangchenbiao
|
* @author zhangchenbiao
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.cool.store.enums.ErrorCodeEnum;
|
|||||||
import com.cool.store.response.ResponseResult;
|
import com.cool.store.response.ResponseResult;
|
||||||
import com.cool.store.context.CurrentUser;
|
import com.cool.store.context.CurrentUser;
|
||||||
import com.cool.store.context.UserContext;
|
import com.cool.store.context.UserContext;
|
||||||
import com.cool.store.utils.DataSourceHelper;
|
|
||||||
import com.cool.store.utils.RedisUtilPool;
|
import com.cool.store.utils.RedisUtilPool;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|||||||
Reference in New Issue
Block a user