mirror of
https://github.com/yzcheng90/X-SpringBoot
synced 2025-11-10 09:39:22 +08:00
新增租户管理
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
package com.suke.czx.common.base;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.suke.czx.authentication.detail.CustomUserDetailsUser;
|
||||
import com.suke.czx.common.utils.HttpContextUtils;
|
||||
import com.suke.czx.common.utils.MPPageConvert;
|
||||
import com.suke.czx.common.utils.UserUtil;
|
||||
import com.suke.czx.modules.tenancy.entity.TbPlatformTenancy;
|
||||
import com.suke.czx.modules.tenancy.service.TbPlatformTenancyService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Controller公共组件
|
||||
@@ -16,15 +23,77 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public abstract class AbstractController {
|
||||
|
||||
@Autowired
|
||||
protected MPPageConvert mpPageConvert;
|
||||
@Resource
|
||||
protected MPPageConvert mpPageConvert;
|
||||
|
||||
protected CustomUserDetailsUser getUser() {
|
||||
return UserUtil.getUser();
|
||||
}
|
||||
@Resource
|
||||
public TbPlatformTenancyService tbPlatformTenancyService;
|
||||
|
||||
@SneakyThrows
|
||||
protected String getUserId() {
|
||||
return UserUtil.getUserId();
|
||||
}
|
||||
}
|
||||
protected CustomUserDetailsUser getUser() {
|
||||
return UserUtil.getUser();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
protected String getUserId() {
|
||||
return UserUtil.getUserId();
|
||||
}
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
protected Integer getUserTenancyId() {
|
||||
return UserUtil.getUserTenancyId();
|
||||
}
|
||||
|
||||
public boolean isAdmin() {
|
||||
return UserUtil.isAdmin() || UserUtil.isMiniAdmin();
|
||||
}
|
||||
|
||||
public boolean isAdmin(String userId) {
|
||||
return UserUtil.isAdmin(userId) || UserUtil.isMiniAdmin(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 优先从参数获取租户
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
public String getTenancyId(Map<String, Object> params) {
|
||||
String tenancyId = MapUtil.getStr(params, "tenancyId");
|
||||
if (StrUtil.isEmpty(tenancyId)) {
|
||||
tenancyId = HttpContextUtils.getHttpServletRequest().getHeader("tenancyId");
|
||||
}
|
||||
if (StrUtil.isEmpty(tenancyId)) {
|
||||
TbPlatformTenancy defaultTenancy = getDefaultTenancy();
|
||||
if (defaultTenancy != null) {
|
||||
tenancyId = defaultTenancy.getTenancyId().toString();
|
||||
}
|
||||
}
|
||||
return tenancyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 优先从请求头获取租户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTenancyId() {
|
||||
String tenancyId = HttpContextUtils.getHttpServletRequest().getHeader("tenancyId");
|
||||
if (StrUtil.isEmpty(tenancyId)) {
|
||||
TbPlatformTenancy defaultTenancy = getDefaultTenancy();
|
||||
if (defaultTenancy != null) {
|
||||
tenancyId = defaultTenancy.getTenancyId().toString();
|
||||
}
|
||||
}
|
||||
return tenancyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认租户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public TbPlatformTenancy getDefaultTenancy() {
|
||||
return tbPlatformTenancyService.getDefaultTenancy();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user