Sfoglia il codice sorgente

租户信息完善

zmq 1 anno fa
parent
commit
043fd32b22

+ 4 - 0
src/platform/ZhonTai.Admin/Domain/Tenant/TenantEntity.cs

@@ -78,4 +78,8 @@ public partial class TenantEntity : EntityBase
     [NotGen]
     [Navigate(ManyToMany = typeof(TenantPkgEntity))]
     public ICollection<PkgEntity> Pkgs { get; set; }
+    /// <summary>
+    /// 平台UserId
+    /// </summary>
+    public long PlatfromUserId { get; set; }    
 }

+ 1 - 0
src/platform/ZhonTai.Admin/Services/Tenant/Dto/TenantAddInput.cs

@@ -49,6 +49,7 @@ public class TenantAddInput
     /// <summary>
     /// 手机号码
     /// </summary>
+    [Required(ErrorMessage = "请输入手机号码")]
     public string Phone { get; set; }
 
     /// <summary>

+ 40 - 0
src/platform/ZhonTai.Admin/Services/Tenant/TenantService.cs

@@ -26,6 +26,9 @@ using Yitter.IdGenerator;
 using ZhonTai.Admin.Domain.Pkg;
 using ZhonTai.Admin.Domain.TenantPkg;
 using ZhonTai.Admin.Services.Pkg;
+using ZhonTai.Admin.Domain.Platform;
+using ZhonTai.Admin.Repositories.Platform;
+using ZhonTai.Admin.Core.Auth;
 
 namespace ZhonTai.Admin.Services.Tenant;
 
@@ -47,6 +50,7 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
     private IUserOrgRepository _userOrgRepository => LazyGetRequiredService<IUserOrgRepository>();
     private IPasswordHasher<UserEntity> _passwordHasher => LazyGetRequiredService<IPasswordHasher<UserEntity>>();
     private ITenantPkgRepository _tenantPkgRepository => LazyGetRequiredService<ITenantPkgRepository>();
+    private IPlatformUserRepository _platformUserRepository => LazyGetRequiredService<PlatformUserRepository>();
 
     public TenantService()
     {
@@ -300,11 +304,29 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
             };
             await _userRoleRepository.InsertAsync(userRole);
 
+            //新增平台用户
+            string invite = await CreateInviteCode();
+            var platfromUser = new PlatformUserEntity()
+            {
+                TenantId = tenantId,
+                Name = user.UserName,
+                Phone = user.Mobile,
+                Password = user.Password,
+                Role = "1",
+                ParentId = "0_",
+                InviteCode = invite
+            };
+            await _platformUserRepository.InsertAsync(platfromUser);
+            long platfromUserId = platfromUser.Id;
+
             //更新租户的用户和部门
             tenant.UserId = userId;
             tenant.OrgId = org.Id;
+            tenant.PlatfromUserId = platfromUserId;
             await _tenantRepository.UpdateAsync(tenant);
 
+            
+            
             return tenant.Id;
         }
     }
@@ -412,6 +434,14 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
                 //清除租户下所有用户权限缓存
                 await LazyGetRequiredService<PkgService>().ClearUserPermissionsAsync(new List<long> { tenant.Id });
             }
+            
+            //更新平台用户
+            await _platformUserRepository.UpdateDiy.SetSource(new PlatformUserEntity()
+            {
+                Id=tenant.PlatfromUserId,
+                Name = input.RealName,
+                Phone = input.Phone,
+            }).UpdateColumns(m => new { m.Name, m.Phone }).ExecuteAffrowsAsync(); ;
         }
     }
 
@@ -544,4 +574,14 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
         entity.Enabled = input.Enabled;
         await _tenantRepository.UpdateAsync(entity);
     }
+    private async Task<string> CreateInviteCode()
+    {
+        string invite = StringHelper.GenerateRandomNumber();
+        var count = await _platformUserRepository.Select.Where(m => m.InviteCode == invite).CountAsync();
+        if (count > 0)
+        {
+            invite = await CreateInviteCode();
+        }
+        return invite;
+    }
 }

+ 5 - 0
src/platform/ZhonTai.Admin/ZhonTai.Admin.xml

@@ -3333,6 +3333,11 @@
             套餐列表
             </summary>
         </member>
+        <member name="P:ZhonTai.Admin.Domain.Tenant.TenantEntity.PlatfromUserId">
+            <summary>
+            平台UserId
+            </summary>
+        </member>
         <member name="T:ZhonTai.Admin.Domain.Tenant.TenantType">
             <summary>
             租户类型