用户模块新增租户
This commit is contained in:
parent
79d6f063c9
commit
0f1aa4cf83
@ -0,0 +1,50 @@
|
||||
package com.cdzy.user.component;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.cdzy.common.model.response.CommonEbikeRole;
|
||||
import com.cdzy.common.model.response.CommonStaffInfo;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.mybatisflex.core.tenant.TenantFactory;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class EbikeTenantFactory implements TenantFactory {
|
||||
|
||||
public Object[] getTenantIds() {
|
||||
if (StpUtil.isLogin()) {
|
||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||
Object attribute = attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST);
|
||||
if (attribute != null) {
|
||||
String id = (String) StpUtil.getLoginId();
|
||||
Object object = StpUtil.getSessionByLoginId(id).get(id);
|
||||
ObjectMapper objectMapper = new ObjectMapper()
|
||||
.registerModule(new JavaTimeModule())
|
||||
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
|
||||
CommonStaffInfo staffInfo = objectMapper.convertValue(object, CommonStaffInfo.class);
|
||||
List<CommonEbikeRole> roles = staffInfo.getRoles();
|
||||
boolean isSysAdmin = false;
|
||||
for (CommonEbikeRole role : roles) {
|
||||
if (role.getSysAdmin()) {
|
||||
isSysAdmin = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
long tenantId = Long.parseLong(attribute.toString());
|
||||
//系统管理员
|
||||
if (isSysAdmin) {
|
||||
return null;
|
||||
} else {
|
||||
return new Object[]{tenantId};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package com.cdzy.user.config;
|
||||
|
||||
import com.cdzy.common.enums.EbikeContents;
|
||||
import com.cdzy.user.component.EbikeTenantFactory;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.audit.AuditManager;
|
||||
@ -53,4 +54,15 @@ public class MyBatisFlexConfiguration {
|
||||
//设置数据已被删除时的值
|
||||
globalConfig.setDeletedValueOfLogicDelete(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详细的租户工厂配置
|
||||
*/
|
||||
@Bean
|
||||
public static TenantFactory tenantFactory() {
|
||||
logger.info("开始初始化租户工厂");
|
||||
EbikeTenantFactory factory = new EbikeTenantFactory();
|
||||
TenantManager.setTenantFactory(factory);
|
||||
return new EbikeTenantFactory();
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,8 @@ import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 用户退款 控制层
|
||||
*
|
||||
* @author yanglei
|
||||
* @since 2025-11-13 20:07
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user