Compare commits
15 Commits
05c67811ed
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| f7e3cad931 | |||
| 6a48299e12 | |||
| ed9d500e5d | |||
| 64e9674d0e | |||
| 6804a0a824 | |||
| a3c4b74d33 | |||
| c3bd90f234 | |||
| 5579f7494e | |||
| e9532ae4d7 | |||
| 2d012dbd7f | |||
| 5637690424 | |||
| 6cb23a8eee | |||
| e2520001c9 | |||
| f894c53184 | |||
| 5f253695c4 |
@@ -754,14 +754,8 @@ public class MainController extends BaseController {
|
|||||||
if (!StrUtil.equals(code, cacheClient.get(phone, String.class))) {
|
if (!StrUtil.equals(code, cacheClient.get(phone, String.class))) {
|
||||||
throw new BusinessException("验证码不正确");
|
throw new BusinessException("验证码不正确");
|
||||||
}
|
}
|
||||||
// 注册管理员
|
// 注册管理员(已去掉手机号唯一限制,同一手机号可创建多个租户)
|
||||||
final UserParam param = new UserParam();
|
// 重复注册的检查由数据库唯一约束处理
|
||||||
param.setPhone(phone);
|
|
||||||
param.setTemplateId(user.getTemplateId());
|
|
||||||
param.setIsAdmin(true);
|
|
||||||
if (userService.getAdminByPhone(param) != null) {
|
|
||||||
throw new BusinessException("该手机号码已注册");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证租户名称是否重复
|
// 验证租户名称是否重复
|
||||||
if (StrUtil.isNotBlank(tenantName)) {
|
if (StrUtil.isNotBlank(tenantName)) {
|
||||||
@@ -795,11 +789,12 @@ public class MainController extends BaseController {
|
|||||||
company.setShortName(tenantName);
|
company.setShortName(tenantName);
|
||||||
company.setTenantId(tenant.getTenantId());
|
company.setTenantId(tenant.getTenantId());
|
||||||
company.setTemplateId(user.getTemplateId());
|
company.setTemplateId(user.getTemplateId());
|
||||||
tenantService.initialization(company);
|
final Company addCompany = tenantService.initialization(company);
|
||||||
final UserParam userParam = new UserParam();
|
final UserParam userParam = new UserParam();
|
||||||
userParam.setIsAdmin(true);
|
userParam.setIsAdmin(true);
|
||||||
userParam.setPhone(phone);
|
userParam.setPhone(phone);
|
||||||
userParam.setTemplateId(user.getTemplateId());
|
userParam.setTemplateId(user.getTemplateId());
|
||||||
|
userParam.setTenantId(addCompany.getTenantId()); // 使用新创建的租户ID
|
||||||
final User adminByPhone = userService.getAdminByPhone(userParam);
|
final User adminByPhone = userService.getAdminByPhone(userParam);
|
||||||
|
|
||||||
// 设置过期时间
|
// 设置过期时间
|
||||||
@@ -869,7 +864,9 @@ public class MainController extends BaseController {
|
|||||||
public ApiResult<LoginResult> superAdminRegister(@RequestBody User user) {
|
public ApiResult<LoginResult> superAdminRegister(@RequestBody User user) {
|
||||||
// 验证签名
|
// 验证签名
|
||||||
String tenantName = user.getCompanyName(); // 应用名称
|
String tenantName = user.getCompanyName(); // 应用名称
|
||||||
String phone = user.getPhone(); // 手机号码
|
// 自动使用当前登录用户的手机号
|
||||||
|
User loginUser = getLoginUser();
|
||||||
|
String phone = loginUser != null ? loginUser.getPhone() : user.getPhone();
|
||||||
String password = user.getPassword(); // 密码
|
String password = user.getPassword(); // 密码
|
||||||
String code = user.getCode(); // 短信验证码
|
String code = user.getCode(); // 短信验证码
|
||||||
String email = user.getEmail(); // 邮箱
|
String email = user.getEmail(); // 邮箱
|
||||||
@@ -922,14 +919,8 @@ public class MainController extends BaseController {
|
|||||||
if (!StrUtil.equals(code, cacheClient.get(phone, String.class)) && !StrUtil.equals(code, redisUtil.get(CACHE_KEY_VERIFICATION_CODE_BY_DEV_SMS))) {
|
if (!StrUtil.equals(code, cacheClient.get(phone, String.class)) && !StrUtil.equals(code, redisUtil.get(CACHE_KEY_VERIFICATION_CODE_BY_DEV_SMS))) {
|
||||||
throw new BusinessException("验证码不正确");
|
throw new BusinessException("验证码不正确");
|
||||||
}
|
}
|
||||||
// 注册管理员
|
// 注册管理员(已去掉手机号唯一限制,同一手机号可创建多个租户)
|
||||||
final UserParam param = new UserParam();
|
// 重复注册的检查由数据库唯一约束处理
|
||||||
param.setPhone(phone);
|
|
||||||
param.setIsAdmin(true);
|
|
||||||
param.setTemplateId(user.getTemplateId());
|
|
||||||
if (userService.getAdminByPhone(param) != null) {
|
|
||||||
throw new BusinessException("该手机号码已注册");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证租户名称是否重复
|
// 验证租户名称是否重复
|
||||||
if (StrUtil.isNotBlank(tenantName)) {
|
if (StrUtil.isNotBlank(tenantName)) {
|
||||||
@@ -951,6 +942,7 @@ public class MainController extends BaseController {
|
|||||||
tenant.setPhone(phone);
|
tenant.setPhone(phone);
|
||||||
tenant.setTenantCode(CommonUtil.randomUUID16());
|
tenant.setTenantCode(CommonUtil.randomUUID16());
|
||||||
tenant.setSortNumber(100);
|
tenant.setSortNumber(100);
|
||||||
|
tenant.setUserId(getLoginUserId()); // 保存当前登录用户ID
|
||||||
tenantService.save(tenant);
|
tenantService.save(tenant);
|
||||||
|
|
||||||
// 租户初始化
|
// 租户初始化
|
||||||
@@ -982,6 +974,7 @@ public class MainController extends BaseController {
|
|||||||
userParam1.setIsAdmin(true);
|
userParam1.setIsAdmin(true);
|
||||||
userParam1.setPhone(phone);
|
userParam1.setPhone(phone);
|
||||||
userParam1.setTemplateId(user.getTemplateId());
|
userParam1.setTemplateId(user.getTemplateId());
|
||||||
|
userParam1.setTenantId(addCompany.getTenantId()); // 使用新创建的租户ID
|
||||||
final User adminByPhone = userService.getAdminByPhone(userParam1);
|
final User adminByPhone = userService.getAdminByPhone(userParam1);
|
||||||
|
|
||||||
// 设置过期时间
|
// 设置过期时间
|
||||||
|
|||||||
@@ -53,7 +53,25 @@ public class TenantController extends BaseController {
|
|||||||
@Operation(summary = "分页查询租户")
|
@Operation(summary = "分页查询租户")
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
public ApiResult<PageResult<Tenant>> page(TenantParam param) {
|
public ApiResult<PageResult<Tenant>> page(TenantParam param) {
|
||||||
return success(tenantService.pageRel(param));
|
// 如果传了 all=true,查询全部租户;否则自动用当前登录用户的 userId
|
||||||
|
if (param.getAll() == null || !param.getAll()) {
|
||||||
|
if (param.getUserId() == null) {
|
||||||
|
final User loginUser = getLoginUser();
|
||||||
|
if (loginUser != null && loginUser.getUserId() != null) {
|
||||||
|
param.setUserId(loginUser.getUserId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PageResult<Tenant> result = tenantService.pageRel(param);
|
||||||
|
// 如果传入 mask=false,设置不脱敏
|
||||||
|
if (param.getMask() != null && !param.getMask()) {
|
||||||
|
if (result.getList() != null) {
|
||||||
|
for (Tenant tenant : result.getList()) {
|
||||||
|
tenant.setPhoneMasked(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ public class Tenant implements Serializable {
|
|||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private Object date;
|
private Object date;
|
||||||
|
|
||||||
|
@Schema(description = "用户名")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String username;
|
||||||
|
|
||||||
@Schema(description = "手机号码")
|
@Schema(description = "手机号码")
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String phone;
|
private String phone;
|
||||||
@@ -112,7 +116,21 @@ public class Tenant implements Serializable {
|
|||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String freeDomain;
|
private String freeDomain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否脱敏手机号,默认true脱敏
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
@Schema(description = "手机号是否脱敏,默认true")
|
||||||
|
private boolean phoneMasked = true;
|
||||||
|
|
||||||
public String getPhone(){
|
public String getPhone(){
|
||||||
|
if (phoneMasked) {
|
||||||
return DesensitizedUtil.mobilePhone(this.phone);
|
return DesensitizedUtil.mobilePhone(this.phone);
|
||||||
}
|
}
|
||||||
|
return this.phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhoneMasked(boolean masked) {
|
||||||
|
this.phoneMasked = masked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,6 @@ public class User implements UserDetails {
|
|||||||
private Integer isOrganizationAdmin;
|
private Integer isOrganizationAdmin;
|
||||||
|
|
||||||
@Schema(description = "是否超级管理员")
|
@Schema(description = "是否超级管理员")
|
||||||
@TableField(exist = false)
|
|
||||||
private Boolean isSuperAdmin;
|
private Boolean isSuperAdmin;
|
||||||
|
|
||||||
@Schema(description = "租户管理员ID")
|
@Schema(description = "租户管理员ID")
|
||||||
|
|||||||
@@ -4,9 +4,11 @@
|
|||||||
|
|
||||||
<!-- 关联查询sql -->
|
<!-- 关联查询sql -->
|
||||||
<sql id="selectSql">
|
<sql id="selectSql">
|
||||||
SELECT a.*,b.company_name,b.company_logo as logo,b.admin_url,b.domain,b.free_domain
|
SELECT a.*,b.company_name,b.company_logo as logo,b.admin_url,b.domain,b.free_domain,
|
||||||
|
u.phone,u.username
|
||||||
FROM sys_tenant a
|
FROM sys_tenant a
|
||||||
LEFT JOIN sys_company b ON a.tenant_id = b.tenant_id
|
LEFT JOIN sys_company b ON a.tenant_id = b.tenant_id
|
||||||
|
LEFT JOIN gxwebsoft_core.sys_user u ON u.tenant_id = a.tenant_id AND u.is_super_admin = 1 AND u.deleted = 0
|
||||||
<where>
|
<where>
|
||||||
<if test="param.tenantId != null">
|
<if test="param.tenantId != null">
|
||||||
AND a.tenant_id = #{param.tenantId}
|
AND a.tenant_id = #{param.tenantId}
|
||||||
|
|||||||
@@ -316,18 +316,15 @@
|
|||||||
WHERE user_id = #{userId}
|
WHERE user_id = #{userId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 根据手机号码查询 -->
|
<!-- 根据手机号码查询(支持多租户:必须传 tenantId 才能查到对应租户的管理员) -->
|
||||||
<select id="selectAdminByPhone" resultType="com.gxwebsoft.common.system.entity.User">
|
<select id="selectAdminByPhone" resultType="com.gxwebsoft.common.system.entity.User">
|
||||||
SELECT a.*
|
SELECT a.*
|
||||||
FROM sys_user a
|
FROM sys_user a
|
||||||
<where>
|
<where>
|
||||||
AND a.deleted = 0
|
AND a.deleted = 0
|
||||||
AND a.phone = #{param.phone}
|
AND a.phone = #{param.phone}
|
||||||
AND a.template_id = #{param.templateId}
|
|
||||||
AND (a.username = 'superAdmin' OR a.username = 'admin' OR a.is_admin = 1)
|
AND (a.username = 'superAdmin' OR a.username = 'admin' OR a.is_admin = 1)
|
||||||
<if test="param.tenantId">
|
|
||||||
AND a.tenant_id = #{param.tenantId}
|
AND a.tenant_id = #{param.tenantId}
|
||||||
</if>
|
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package com.gxwebsoft.common.system.param;
|
package com.gxwebsoft.common.system.param;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.gxwebsoft.common.core.annotation.QueryField;
|
import com.gxwebsoft.common.core.annotation.QueryField;
|
||||||
import com.gxwebsoft.common.core.annotation.QueryType;
|
import com.gxwebsoft.common.core.annotation.QueryType;
|
||||||
import com.gxwebsoft.common.core.web.BaseParam;
|
import com.gxwebsoft.common.core.web.BaseParam;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
@@ -52,4 +49,11 @@ public class TenantParam extends BaseParam {
|
|||||||
@QueryField(type = QueryType.EQ)
|
@QueryField(type = QueryType.EQ)
|
||||||
private Integer tenantId;
|
private Integer tenantId;
|
||||||
|
|
||||||
|
@Schema(description = "手机号是否脱敏,默认true")
|
||||||
|
@QueryField(type = QueryType.EQ)
|
||||||
|
private Boolean mask;
|
||||||
|
|
||||||
|
@Schema(description = "查询全部租户,true时忽略userId条件")
|
||||||
|
private Boolean all;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user