😎修复租户种子数据初始化(Id隔离)
This commit is contained in:
parent
d9e92bb72e
commit
943b776fa2
@ -34,7 +34,7 @@ public abstract class EntityBase : EntityBaseId, IDeletedFilter
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "更新时间")]
|
||||
public virtual DateTime UpdateTime { get; set; }
|
||||
public virtual DateTime? UpdateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建者Id
|
||||
|
||||
@ -471,7 +471,7 @@ public class SysTenantService : IDynamicApiController, ITransient
|
||||
if (string.IsNullOrWhiteSpace(tenant.Connection) || tenant.Connection.Length < 10)
|
||||
throw Oops.Oh(ErrorCodeEnum.Z1004);
|
||||
|
||||
SqlSugarSetup.InitTenantData(_sysTenantRep.AsTenant(), tenant.Id);
|
||||
SqlSugarSetup.InitTenantData(_sysTenantRep.AsTenant(), SqlSugarConst.MainConfigId.ToLong(), tenant.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -431,15 +431,16 @@ public static class SqlSugarSetup
|
||||
}
|
||||
|
||||
// 初始化租户业务数据
|
||||
InitTenantData(iTenant, config.ConfigId.ToLong());
|
||||
InitTenantData(iTenant, config.ConfigId.ToLong(), config.ConfigId.ToLong());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化租户业务数据
|
||||
/// </summary>
|
||||
/// <param name="iTenant"></param>
|
||||
/// <param name="dbConfigId">租户Id</param>
|
||||
public static void InitTenantData(ITenant iTenant, long dbConfigId)
|
||||
/// <param name="dbConfigId">库标识</param>
|
||||
/// <param name="tenantId">租户Id</param>
|
||||
public static void InitTenantData(ITenant iTenant, long dbConfigId, long tenantId)
|
||||
{
|
||||
var seedDataTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>))))
|
||||
.Where(u => u.IsDefined(typeof(TenantSeedAttribute), false))
|
||||
@ -462,7 +463,7 @@ public static class SqlSugarSetup
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(EntityTenantId.TenantId))!.SetValue(sd, dbConfigId);
|
||||
sd.GetType().GetProperty(nameof(EntityTenantId.TenantId))!.SetValue(sd, tenantId);
|
||||
}
|
||||
}
|
||||
// 若实体包含Pid字段,则设置为当前租户Id
|
||||
@ -470,7 +471,7 @@ public static class SqlSugarSetup
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(SysOrg.Pid))!.SetValue(sd, dbConfigId);
|
||||
sd.GetType().GetProperty(nameof(SysOrg.Pid))!.SetValue(sd, tenantId);
|
||||
}
|
||||
}
|
||||
// 若实体包含Id字段,则设置为当前租户Id递增1
|
||||
@ -478,7 +479,7 @@ public static class SqlSugarSetup
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(EntityBaseId.Id))!.SetValue(sd, ++dbConfigId);
|
||||
sd.GetType().GetProperty(nameof(EntityBaseId.Id))!.SetValue(sd, ++tenantId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user