|
|
@@ -16,6 +16,7 @@ import com.payment.platform.module.system.position.entity.PositionEntity;
|
|
|
import com.payment.platform.module.system.position.mapper.PositionMapper;
|
|
|
import com.payment.platform.module.system.role.entity.RoleEntity;
|
|
|
import com.payment.platform.module.system.role.mapper.RoleMapper;
|
|
|
+import com.payment.platform.module.system.invite.entity.InvitationCodeEntity;
|
|
|
import com.payment.platform.module.system.tenant.entity.TenantEntity;
|
|
|
import com.payment.platform.module.system.tenant.mapper.TenantMapper;
|
|
|
import com.payment.platform.module.system.user.dto.*;
|
|
|
@@ -268,8 +269,20 @@ public class UserService {
|
|
|
if (StrUtil.isBlank(invitationCode))
|
|
|
throw new BusinessException(400, "邀请码不能为空");
|
|
|
|
|
|
- // 先校验邀请码有效性(创建用户之前)
|
|
|
- invitationCodeService.validate(invitationCode);
|
|
|
+ // 先校验邀请码有效性,同时获取邀请码实体(用于推导租户)
|
|
|
+ InvitationCodeEntity codeEntity = invitationCodeService.validate(invitationCode);
|
|
|
+
|
|
|
+ // 通过邀请码创建者推导租户 ID
|
|
|
+ Long tenantId = null;
|
|
|
+ if (codeEntity.getCreatedBy() != null) {
|
|
|
+ UserEntity creator = userMapper.selectById(codeEntity.getCreatedBy());
|
|
|
+ if (creator != null && creator.getTenantId() != null) {
|
|
|
+ tenantId = creator.getTenantId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tenantId == null) {
|
|
|
+ throw new BusinessException(500, "邀请码未关联租户,无法注册");
|
|
|
+ }
|
|
|
|
|
|
// 检查用户名是否已存在(按 username 或 mobile)
|
|
|
UserEntity existByUsername = userMapper.selectOne(
|
|
|
@@ -292,6 +305,7 @@ public class UserService {
|
|
|
entity.setName(StrUtil.isNotBlank(name) ? name : username);
|
|
|
entity.setStatus("0");
|
|
|
entity.setIsSuperuser(false);
|
|
|
+ entity.setTenantId(tenantId);
|
|
|
userMapper.insert(entity);
|
|
|
|
|
|
// 分配默认角色 (role_id=1)
|