mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-08 12:57:13 +08:00
feat(tenant): 增加查询租户开启状态和租户根据域名查询租户的接口
This commit is contained in:
@@ -16,17 +16,22 @@
|
||||
|
||||
package top.continew.admin.tenant.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.continew.admin.tenant.model.entity.TenantDO;
|
||||
import top.continew.admin.tenant.model.query.PackageQuery;
|
||||
import top.continew.admin.tenant.service.PackageService;
|
||||
import top.continew.admin.tenant.service.TenantService;
|
||||
import top.continew.starter.extension.crud.model.query.SortQuery;
|
||||
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
|
||||
import top.continew.starter.extension.tenant.annotation.TenantIgnore;
|
||||
import top.continew.starter.log.annotation.Log;
|
||||
|
||||
import java.util.List;
|
||||
@@ -47,9 +52,23 @@ public class CommonController {
|
||||
|
||||
private final PackageService packageService;
|
||||
|
||||
private final TenantService tenantService;
|
||||
|
||||
@Operation(summary = "查询套餐字典", description = "查询套餐字典列表")
|
||||
@GetMapping("/dict/package")
|
||||
public List<LabelValueResp> listPackageDict(PackageQuery query, SortQuery sortQuery) {
|
||||
return packageService.listDict(query, sortQuery);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据域名查询租户ID", description = "根据域名查询租户编码")
|
||||
@SaIgnore
|
||||
@TenantIgnore
|
||||
@GetMapping("/id/domain")
|
||||
public Long getTenantIdByUrl(@RequestParam("domain") String domain){
|
||||
TenantDO tenantDO = tenantService.getByDomain(domain);
|
||||
if (tenantDO != null){
|
||||
return tenantDO.getId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -39,6 +39,7 @@ import top.continew.starter.cache.redisson.util.RedisUtils;
|
||||
import top.continew.starter.core.util.ExceptionUtils;
|
||||
import top.continew.starter.core.util.validation.CheckUtils;
|
||||
import top.continew.starter.core.util.validation.ValidationUtils;
|
||||
import top.continew.starter.extension.tenant.context.TenantContextHolder;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@@ -71,7 +72,7 @@ public class AccountLoginHandler extends AbstractLoginHandler<AccountLoginReq> {
|
||||
super.checkUserStatus(user);
|
||||
// 执行认证
|
||||
String token = this.authenticate(user, client);
|
||||
return LoginResp.builder().token(token).build();
|
||||
return LoginResp.builder().token(token).tenantId(TenantContextHolder.isTenantEnabled()? TenantContextHolder.getTenantId():null).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -27,6 +27,7 @@ import top.continew.admin.system.model.entity.user.UserDO;
|
||||
import top.continew.admin.system.model.resp.ClientResp;
|
||||
import top.continew.starter.cache.redisson.util.RedisUtils;
|
||||
import top.continew.starter.core.util.validation.ValidationUtils;
|
||||
import top.continew.starter.extension.tenant.context.TenantContextHolder;
|
||||
|
||||
/**
|
||||
* 邮箱登录处理器
|
||||
@@ -47,8 +48,7 @@ public class EmailLoginHandler extends AbstractLoginHandler<EmailLoginReq> {
|
||||
super.checkUserStatus(user);
|
||||
// 执行认证
|
||||
String token = super.authenticate(user, client);
|
||||
return LoginResp.builder().token(token).build();
|
||||
}
|
||||
return LoginResp.builder().token(token).tenantId(TenantContextHolder.isTenantEnabled()? TenantContextHolder.getTenantId():null).build(); }
|
||||
|
||||
@Override
|
||||
public void preLogin(EmailLoginReq req, ClientResp client, HttpServletRequest request) {
|
||||
|
@@ -27,6 +27,7 @@ import top.continew.admin.system.model.entity.user.UserDO;
|
||||
import top.continew.admin.system.model.resp.ClientResp;
|
||||
import top.continew.starter.cache.redisson.util.RedisUtils;
|
||||
import top.continew.starter.core.util.validation.ValidationUtils;
|
||||
import top.continew.starter.extension.tenant.context.TenantContextHolder;
|
||||
|
||||
/**
|
||||
* 手机号登录处理器
|
||||
@@ -47,8 +48,7 @@ public class PhoneLoginHandler extends AbstractLoginHandler<PhoneLoginReq> {
|
||||
super.checkUserStatus(user);
|
||||
// 执行认证
|
||||
String token = super.authenticate(user, client);
|
||||
return LoginResp.builder().token(token).build();
|
||||
}
|
||||
return LoginResp.builder().token(token).tenantId(TenantContextHolder.isTenantEnabled()? TenantContextHolder.getTenantId():null).build(); }
|
||||
|
||||
@Override
|
||||
public void preLogin(PhoneLoginReq req, ClientResp client, HttpServletRequest request) {
|
||||
|
@@ -53,6 +53,7 @@ import top.continew.admin.system.service.UserSocialService;
|
||||
import top.continew.starter.core.autoconfigure.application.ApplicationProperties;
|
||||
import top.continew.starter.core.exception.BadRequestException;
|
||||
import top.continew.starter.core.util.validation.ValidationUtils;
|
||||
import top.continew.starter.extension.tenant.context.TenantContextHolder;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
@@ -127,7 +128,7 @@ public class SocialLoginHandler extends AbstractLoginHandler<SocialLoginReq> {
|
||||
userSocialService.saveOrUpdate(userSocial);
|
||||
// 执行认证
|
||||
String token = super.authenticate(user, client);
|
||||
return LoginResp.builder().token(token).build();
|
||||
return LoginResp.builder().token(token).tenantId(TenantContextHolder.isTenantEnabled()? TenantContextHolder.getTenantId():null).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -42,4 +42,7 @@ public class LoginResp implements Serializable {
|
||||
*/
|
||||
@Schema(description = "令牌", example = "eyJ0eXAiOiJlV1QiLCJhbGciqiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb29pbiIsImxvZ2luSWQiOjEsInJuU3RyIjoiSjd4SUljYnU5cmNwU09vQ3Uyc1ND1BYYTYycFRjcjAifQ.KUPOYm-2wfuLUSfEEAbpGE527fzmkAJG7sMNcQ0pUZ8")
|
||||
private String token;
|
||||
|
||||
@Schema(description = "租户ID", example = "0")
|
||||
private Long tenantId;
|
||||
}
|
||||
|
@@ -39,6 +39,7 @@ import top.continew.starter.core.util.validation.ValidationUtils;
|
||||
import top.continew.starter.extension.crud.model.query.SortQuery;
|
||||
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
|
||||
import top.continew.starter.extension.tenant.annotation.TenantIgnore;
|
||||
import top.continew.starter.extension.tenant.context.TenantContextHolder;
|
||||
import top.continew.starter.log.annotation.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -126,4 +127,13 @@ public class CommonController {
|
||||
.getDefaultValue())))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@TenantIgnore
|
||||
@SaIgnore
|
||||
@Operation(summary = "查询租户开启状态",description = "查询租户开启状态")
|
||||
@GetMapping("/dict/option/tenant")
|
||||
@Cached(key = "'TENANT'", name = CacheConstants.OPTION_KEY_PREFIX)
|
||||
public Boolean tenantEnabled(){
|
||||
return TenantContextHolder.isTenantEnabled();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user