🍓 feat(DB-AOP): 添加设置应用Id功能
This commit is contained in:
parent
5a96ecd5ac
commit
4e2b80a261
@ -30,4 +30,9 @@ public class SqlSugarConst
|
||||
/// 默认租户Id
|
||||
/// </summary>
|
||||
public const long DefaultTenantId = 1300000000001;
|
||||
|
||||
/// <summary>
|
||||
/// 默认应用Id
|
||||
/// </summary>
|
||||
public const long DefaultAppId = 1300000000001;
|
||||
}
|
||||
@ -244,10 +244,16 @@ public static class SqlSugarSetup
|
||||
entityInfo.SetValue(DateTime.Now);
|
||||
}
|
||||
// 若当前用户非空(web线程时)
|
||||
if (App.User == null) return;
|
||||
if (App.User == null || userManager.Value == null) return;
|
||||
|
||||
dynamic entityValue = entityInfo.EntityValue;
|
||||
if (entityInfo.PropertyName == nameof(EntityTenantId.TenantId))
|
||||
// 若应用Id为空则赋值当前用户应用Id,若当前用户应用Id为空,则取默认应用Id
|
||||
if (entityInfo.PropertyName == nameof(IAppIdFilter.AppId) && entityValue is IAppIdFilter)
|
||||
{
|
||||
var appId = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue)!;
|
||||
if (appId == null || appId.Equals(0)) entityInfo.SetValue(userManager.Value?.AppId ?? SqlSugarConst.DefaultAppId);
|
||||
}
|
||||
else if (entityInfo.PropertyName == nameof(EntityTenantId.TenantId))
|
||||
{
|
||||
if (entityValue.TenantId == null || entityValue.TenantId == 0)
|
||||
entityInfo.SetValue(userManager.Value.TenantId?.ToString() ?? SqlSugarConst.DefaultTenantId.ToString());
|
||||
@ -255,7 +261,7 @@ public static class SqlSugarSetup
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.CreateUserId))
|
||||
{
|
||||
if (entityValue.CreateUserId == null || entityValue.CreateUserId == 0)
|
||||
entityInfo.SetValue(App.User.FindFirst(ClaimConst.UserId)?.Value);
|
||||
entityInfo.SetValue(userManager.Value.UserId);
|
||||
}
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.CreateUserName))
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user