Skip to content

Commit dec5d61

Browse files
MoLi-MoChouCharles7c
authored andcommitted
feat(tenant): 增加查询租户开启状态和租户根据域名查询租户的接口
1 parent 9eff846 commit dec5d61

7 files changed

Lines changed: 40 additions & 6 deletions

File tree

‎continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/controller/CommonController.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,22 @@
1616

1717
package top.continew.admin.tenant.controller;
1818

19+
import cn.dev33.satoken.annotation.SaIgnore;
1920
import io.swagger.v3.oas.annotations.Operation;
2021
import io.swagger.v3.oas.annotations.tags.Tag;
2122
import lombok.RequiredArgsConstructor;
2223
import org.springframework.validation.annotation.Validated;
2324
import org.springframework.web.bind.annotation.GetMapping;
2425
import org.springframework.web.bind.annotation.RequestMapping;
26+
import org.springframework.web.bind.annotation.RequestParam;
2527
import org.springframework.web.bind.annotation.RestController;
28+
import top.continew.admin.tenant.model.entity.TenantDO;
2629
import top.continew.admin.tenant.model.query.PackageQuery;
2730
import top.continew.admin.tenant.service.PackageService;
31+
import top.continew.admin.tenant.service.TenantService;
2832
import top.continew.starter.extension.crud.model.query.SortQuery;
2933
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
34+
import top.continew.starter.extension.tenant.annotation.TenantIgnore;
3035
import top.continew.starter.log.annotation.Log;
3136

3237
import java.util.List;
@@ -47,9 +52,23 @@ public class CommonController {
4752

4853
private final PackageService packageService;
4954

55+
private final TenantService tenantService;
56+
5057
@Operation(summary = "查询套餐字典", description = "查询套餐字典列表")
5158
@GetMapping("/dict/package")
5259
public List<LabelValueResp> listPackageDict(PackageQuery query, SortQuery sortQuery) {
5360
return packageService.listDict(query, sortQuery);
5461
}
62+
63+
@Operation(summary = "根据域名查询租户ID", description = "根据域名查询租户编码")
64+
@SaIgnore
65+
@TenantIgnore
66+
@GetMapping("/id/domain")
67+
public Long getTenantIdByUrl(@RequestParam("domain") String domain){
68+
TenantDO tenantDO = tenantService.getByDomain(domain);
69+
if (tenantDO != null){
70+
return tenantDO.getId();
71+
}
72+
return null;
73+
}
5574
}

‎continew-system/src/main/java/top/continew/admin/auth/handler/AccountLoginHandler.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import top.continew.starter.core.util.ExceptionUtils;
4040
import top.continew.starter.core.util.validation.CheckUtils;
4141
import top.continew.starter.core.util.validation.ValidationUtils;
42+
import top.continew.starter.extension.tenant.context.TenantContextHolder;
4243

4344
import java.time.Duration;
4445

@@ -71,7 +72,7 @@ public LoginResp login(AccountLoginReq req, ClientResp client, HttpServletReques
7172
super.checkUserStatus(user);
7273
// 执行认证
7374
String token = this.authenticate(user, client);
74-
return LoginResp.builder().token(token).build();
75+
return LoginResp.builder().token(token).tenantId(TenantContextHolder.isTenantEnabled()? TenantContextHolder.getTenantId():null).build();
7576
}
7677

7778
@Override

‎continew-system/src/main/java/top/continew/admin/auth/handler/EmailLoginHandler.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import top.continew.admin.system.model.resp.ClientResp;
2828
import top.continew.starter.cache.redisson.util.RedisUtils;
2929
import top.continew.starter.core.util.validation.ValidationUtils;
30+
import top.continew.starter.extension.tenant.context.TenantContextHolder;
3031

3132
/**
3233
* 邮箱登录处理器
@@ -47,8 +48,7 @@ public LoginResp login(EmailLoginReq req, ClientResp client, HttpServletRequest
4748
super.checkUserStatus(user);
4849
// 执行认证
4950
String token = super.authenticate(user, client);
50-
return LoginResp.builder().token(token).build();
51-
}
51+
return LoginResp.builder().token(token).tenantId(TenantContextHolder.isTenantEnabled()? TenantContextHolder.getTenantId():null).build(); }
5252

5353
@Override
5454
public void preLogin(EmailLoginReq req, ClientResp client, HttpServletRequest request) {

‎continew-system/src/main/java/top/continew/admin/auth/handler/PhoneLoginHandler.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import top.continew.admin.system.model.resp.ClientResp;
2828
import top.continew.starter.cache.redisson.util.RedisUtils;
2929
import top.continew.starter.core.util.validation.ValidationUtils;
30+
import top.continew.starter.extension.tenant.context.TenantContextHolder;
3031

3132
/**
3233
* 手机号登录处理器
@@ -47,8 +48,7 @@ public LoginResp login(PhoneLoginReq req, ClientResp client, HttpServletRequest
4748
super.checkUserStatus(user);
4849
// 执行认证
4950
String token = super.authenticate(user, client);
50-
return LoginResp.builder().token(token).build();
51-
}
51+
return LoginResp.builder().token(token).tenantId(TenantContextHolder.isTenantEnabled()? TenantContextHolder.getTenantId():null).build(); }
5252

5353
@Override
5454
public void preLogin(PhoneLoginReq req, ClientResp client, HttpServletRequest request) {

‎continew-system/src/main/java/top/continew/admin/auth/handler/SocialLoginHandler.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import top.continew.starter.core.autoconfigure.application.ApplicationProperties;
5454
import top.continew.starter.core.exception.BadRequestException;
5555
import top.continew.starter.core.util.validation.ValidationUtils;
56+
import top.continew.starter.extension.tenant.context.TenantContextHolder;
5657

5758
import java.time.LocalDateTime;
5859
import java.util.Collections;
@@ -127,7 +128,7 @@ public LoginResp login(SocialLoginReq req, ClientResp client, HttpServletRequest
127128
userSocialService.saveOrUpdate(userSocial);
128129
// 执行认证
129130
String token = super.authenticate(user, client);
130-
return LoginResp.builder().token(token).build();
131+
return LoginResp.builder().token(token).tenantId(TenantContextHolder.isTenantEnabled()? TenantContextHolder.getTenantId():null).build();
131132
}
132133

133134
@Override

‎continew-system/src/main/java/top/continew/admin/auth/model/resp/LoginResp.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ public class LoginResp implements Serializable {
4242
*/
4343
@Schema(description = "令牌", example = "eyJ0eXAiOiJlV1QiLCJhbGciqiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb29pbiIsImxvZ2luSWQiOjEsInJuU3RyIjoiSjd4SUljYnU5cmNwU09vQ3Uyc1ND1BYYTYycFRjcjAifQ.KUPOYm-2wfuLUSfEEAbpGE527fzmkAJG7sMNcQ0pUZ8")
4444
private String token;
45+
46+
@Schema(description = "租户ID", example = "0")
47+
private Long tenantId;
4548
}

‎continew-system/src/main/java/top/continew/admin/system/controller/CommonController.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import top.continew.starter.extension.crud.model.query.SortQuery;
4040
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
4141
import top.continew.starter.extension.tenant.annotation.TenantIgnore;
42+
import top.continew.starter.extension.tenant.context.TenantContextHolder;
4243
import top.continew.starter.log.annotation.Log;
4344

4445
import java.io.IOException;
@@ -126,4 +127,13 @@ public List<LabelValueResp<String>> listSiteOptionDict() {
126127
.getDefaultValue())))
127128
.toList();
128129
}
130+
131+
@TenantIgnore
132+
@SaIgnore
133+
@Operation(summary = "查询租户开启状态",description = "查询租户开启状态")
134+
@GetMapping("/dict/option/tenant")
135+
@Cached(key = "'TENANT'", name = CacheConstants.OPTION_KEY_PREFIX)
136+
public Boolean tenantEnabled(){
137+
return TenantContextHolder.isTenantEnabled();
138+
}
129139
}

0 commit comments

Comments
 (0)