🍓 feat(DB-AOP): 添加设置应用Id功能

This commit is contained in:
喵你个汪呀 2025-08-30 00:00:49 +08:00
parent 5a96ecd5ac
commit 4e2b80a261
2 changed files with 14 additions and 3 deletions

View File

@ -30,4 +30,9 @@ public class SqlSugarConst
/// 默认租户Id
/// </summary>
public const long DefaultTenantId = 1300000000001;
/// <summary>
/// 默认应用Id
/// </summary>
public const long DefaultAppId = 1300000000001;
}

View File

@ -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))
{