refactor(system): 移除手机号唯一限制,改由数据库唯一约束处理

- 取消注册管理员时手机号唯一校验,允许同一手机号创建多个租户
- 删除代码中重复注册手机号的业务检查逻辑
- 数据库查询手机号码管理员时,强制必须传入租户ID进行多租户支持
- 修改SQL注释,明确手机管理员查询需提供租户ID
- 保证手机号唯一性通过数据库唯一约束机制实现,提高数据一致性和扩展性
This commit is contained in:
2026-04-27 06:52:47 +08:00
parent e9532ae4d7
commit 5579f7494e
2 changed files with 6 additions and 20 deletions

View File

@@ -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)) {
@@ -924,14 +918,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)) {

View File

@@ -316,7 +316,7 @@
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
@@ -324,9 +324,7 @@
AND a.deleted = 0 AND a.deleted = 0
AND a.phone = #{param.phone} AND a.phone = #{param.phone}
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>