mirror of https://gitee.com/stylefeng/roses
【7.3.2】更新用户id处理逻辑
parent
e41f3e3e94
commit
f2eee7ee3f
|
@ -67,6 +67,14 @@
|
|||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--数据源容器api-->
|
||||
<!--字段处理过程中,遇到多租户情况,需要切数据源-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>ds-container-api</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--web-->
|
||||
<!--ResourcePersistenceApi会用到web,用在提供feign接口时-->
|
||||
<dependency>
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
package cn.stylefeng.roses.kernel.system.api.format;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.dsctn.api.context.CurrentDataSourceContext;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.TenantConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.format.BaseSimpleFieldFormatProcess;
|
||||
import cn.stylefeng.roses.kernel.system.api.UserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.user.SysUserDTO;
|
||||
|
||||
import static cn.stylefeng.roses.kernel.rule.constants.RuleConstants.TENANT_DB_PREFIX;
|
||||
|
||||
/**
|
||||
* Json响应的针对用户的处理
|
||||
*
|
||||
|
@ -26,6 +33,32 @@ public class UserFormatProcess extends BaseSimpleFieldFormatProcess {
|
|||
|
||||
@Override
|
||||
public Object simpleItemFormat(Object businessId) {
|
||||
|
||||
LoginUser loginUserNullable = LoginContext.me().getLoginUserNullable();
|
||||
if (loginUserNullable == null) {
|
||||
return execute(businessId);
|
||||
}
|
||||
|
||||
// 如果当前登录用户有租户标识
|
||||
try {
|
||||
String tenantCode = loginUserNullable.getTenantCode();
|
||||
if (StrUtil.isNotEmpty(tenantCode) && !TenantConstants.MASTER_DATASOURCE_NAME.equals(tenantCode)) {
|
||||
CurrentDataSourceContext.setDataSourceName(TENANT_DB_PREFIX + tenantCode);
|
||||
}
|
||||
return execute(businessId);
|
||||
} finally {
|
||||
// 清除数据源信息
|
||||
CurrentDataSourceContext.clearDataSourceName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务逻辑执行
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/10 1:29
|
||||
*/
|
||||
private Object execute(Object businessId) {
|
||||
Long userId = Convert.toLong(businessId);
|
||||
UserServiceApi bean = SpringUtil.getBean(UserServiceApi.class);
|
||||
SysUserDTO userInfoByUserId = bean.getUserInfoByUserId(userId);
|
||||
|
|
Loading…
Reference in New Issue