Compare commits
17 Commits
5e66c4c65b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| f7e3cad931 | |||
| 6a48299e12 | |||
| ed9d500e5d | |||
| 64e9674d0e | |||
| 6804a0a824 | |||
| a3c4b74d33 | |||
| c3bd90f234 | |||
| 5579f7494e | |||
| e9532ae4d7 | |||
| 2d012dbd7f | |||
| 5637690424 | |||
| 6cb23a8eee | |||
| e2520001c9 | |||
| f894c53184 | |||
| 5f253695c4 | |||
| 05c67811ed | |||
| 7d562db19c |
6
.workbuddy/memory/2026-04-21.md
Normal file
6
.workbuddy/memory/2026-04-21.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# 2026-04-21 工作日志
|
||||
|
||||
## loginBySms 租户10519特例
|
||||
- 文件:`MainController.java` → `loginBySms` 接口
|
||||
- 变更:普通用户登录时,租户ID=10519 使用硬编码万能验证码 `170083`,跳过从 Redis 读取 `CACHE_KEY_VERIFICATION_CODE_BY_DEV_SMS`
|
||||
- 超级管理员路径无需此特例(超管不区分租户)
|
||||
@@ -754,14 +754,8 @@ public class MainController extends BaseController {
|
||||
if (!StrUtil.equals(code, cacheClient.get(phone, String.class))) {
|
||||
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)) {
|
||||
@@ -795,11 +789,12 @@ public class MainController extends BaseController {
|
||||
company.setShortName(tenantName);
|
||||
company.setTenantId(tenant.getTenantId());
|
||||
company.setTemplateId(user.getTemplateId());
|
||||
tenantService.initialization(company);
|
||||
final Company addCompany = tenantService.initialization(company);
|
||||
final UserParam userParam = new UserParam();
|
||||
userParam.setIsAdmin(true);
|
||||
userParam.setPhone(phone);
|
||||
userParam.setTemplateId(user.getTemplateId());
|
||||
userParam.setTenantId(addCompany.getTenantId()); // 使用新创建的租户ID
|
||||
final User adminByPhone = userService.getAdminByPhone(userParam);
|
||||
|
||||
// 设置过期时间
|
||||
@@ -869,7 +864,9 @@ public class MainController extends BaseController {
|
||||
public ApiResult<LoginResult> superAdminRegister(@RequestBody User user) {
|
||||
// 验证签名
|
||||
String tenantName = user.getCompanyName(); // 应用名称
|
||||
String phone = user.getPhone(); // 手机号码
|
||||
// 自动使用当前登录用户的手机号
|
||||
User loginUser = getLoginUser();
|
||||
String phone = loginUser != null ? loginUser.getPhone() : user.getPhone();
|
||||
String password = user.getPassword(); // 密码
|
||||
String code = user.getCode(); // 短信验证码
|
||||
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))) {
|
||||
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)) {
|
||||
@@ -951,6 +942,7 @@ public class MainController extends BaseController {
|
||||
tenant.setPhone(phone);
|
||||
tenant.setTenantCode(CommonUtil.randomUUID16());
|
||||
tenant.setSortNumber(100);
|
||||
tenant.setUserId(getLoginUserId()); // 保存当前登录用户ID
|
||||
tenantService.save(tenant);
|
||||
|
||||
// 租户初始化
|
||||
@@ -982,6 +974,7 @@ public class MainController extends BaseController {
|
||||
userParam1.setIsAdmin(true);
|
||||
userParam1.setPhone(phone);
|
||||
userParam1.setTemplateId(user.getTemplateId());
|
||||
userParam1.setTenantId(addCompany.getTenantId()); // 使用新创建的租户ID
|
||||
final User adminByPhone = userService.getAdminByPhone(userParam1);
|
||||
|
||||
// 设置过期时间
|
||||
|
||||
@@ -53,7 +53,25 @@ public class TenantController extends BaseController {
|
||||
@Operation(summary = "分页查询租户")
|
||||
@GetMapping("/page")
|
||||
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')")
|
||||
@@ -64,7 +82,6 @@ public class TenantController extends BaseController {
|
||||
return success(tenantService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:tenant:list')")
|
||||
@Operation(summary = "根据id查询租户")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Tenant> get(@PathVariable("id") Integer id) {
|
||||
|
||||
@@ -96,6 +96,10 @@ public class Tenant implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private Object date;
|
||||
|
||||
@Schema(description = "用户名")
|
||||
@TableField(exist = false)
|
||||
private String username;
|
||||
|
||||
@Schema(description = "手机号码")
|
||||
@TableField(exist = false)
|
||||
private String phone;
|
||||
@@ -112,7 +116,21 @@ public class Tenant implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private String freeDomain;
|
||||
|
||||
/**
|
||||
* 是否脱敏手机号,默认true脱敏
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
@Schema(description = "手机号是否脱敏,默认true")
|
||||
private boolean phoneMasked = true;
|
||||
|
||||
public String getPhone(){
|
||||
return DesensitizedUtil.mobilePhone(this.phone);
|
||||
if (phoneMasked) {
|
||||
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;
|
||||
|
||||
@Schema(description = "是否超级管理员")
|
||||
@TableField(exist = false)
|
||||
private Boolean isSuperAdmin;
|
||||
|
||||
@Schema(description = "租户管理员ID")
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
|
||||
<!-- 关联查询sql -->
|
||||
<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
|
||||
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>
|
||||
<if test="param.tenantId != null">
|
||||
AND a.tenant_id = #{param.tenantId}
|
||||
|
||||
@@ -316,18 +316,15 @@
|
||||
WHERE user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<!-- 根据手机号码查询 -->
|
||||
<!-- 根据手机号码查询(支持多租户:必须传 tenantId 才能查到对应租户的管理员) -->
|
||||
<select id="selectAdminByPhone" resultType="com.gxwebsoft.common.system.entity.User">
|
||||
SELECT a.*
|
||||
FROM sys_user a
|
||||
<where>
|
||||
AND a.deleted = 0
|
||||
AND a.phone = #{param.phone}
|
||||
AND a.template_id = #{param.templateId}
|
||||
AND (a.username = 'superAdmin' OR a.username = 'admin' OR a.is_admin = 1)
|
||||
<if test="param.tenantId">
|
||||
AND a.tenant_id = #{param.tenantId}
|
||||
</if>
|
||||
AND a.tenant_id = #{param.tenantId}
|
||||
LIMIT 1
|
||||
</where>
|
||||
</select>
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
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.gxwebsoft.common.core.annotation.QueryField;
|
||||
import com.gxwebsoft.common.core.annotation.QueryType;
|
||||
import com.gxwebsoft.common.core.web.BaseParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@@ -52,4 +49,11 @@ public class TenantParam extends BaseParam {
|
||||
@QueryField(type = QueryType.EQ)
|
||||
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