refactor: ♻️ 框架代码同步

This commit is contained in:
tk 2024-12-16 11:39:51 +08:00 committed by nsnail
parent 7c47c09838
commit e5e1d6f50f
10 changed files with 29 additions and 19 deletions

View File

@ -2,6 +2,7 @@ using CsvHelper;
using Microsoft.Net.Http.Headers;
using NetAdmin.Application.Repositories;
using NetAdmin.Domain;
using NetAdmin.Domain.Contexts;
using NetAdmin.Domain.DbMaps.Dependency;
using NetAdmin.Domain.DbMaps.Dependency.Fields;
using NetAdmin.Domain.Dto.Dependency;
@ -53,9 +54,7 @@ public abstract class RepositoryService<TEntity, TPrimary, TLogger>(BasicReposit
{
var select = selector(query).WithNoLockNoWait().Take(Numbers.MAX_LIMIT_EXPORT);
object list = listExp == null
? await select.ToListAsync().ConfigureAwait(false)
: await select.ToListAsync(listExp).ConfigureAwait(false);
object list = listExp == null ? await select.ToListAsync().ConfigureAwait(false) : await select.ToListAsync(listExp).ConfigureAwait(false);
return await GetExportFileStreamAsync<TExport>(fileName, list).ConfigureAwait(false);
}
@ -135,6 +134,25 @@ public abstract class RepositoryService<TEntity, TPrimary, TLogger>(BasicReposit
return new FileStreamResult(stream, Chars.FLG_HTTP_HEADER_VALUE_APPLICATION_OCTET_STREAM);
}
private static Dictionary<string, object> IncludeToDictionary(TEntity entity, List<string> includeFields)
{
var ret = includeFields!.ToDictionary(
x => x, x => typeof(TEntity).GetProperty(x, BindingFlags.Public | BindingFlags.Instance)!.GetValue(entity));
if (entity is not IFieldModifiedUser) {
return ret;
}
var userInfo = App.GetService<ContextUserInfo>();
if (userInfo == null) {
return ret;
}
ret.Add(nameof(IFieldModifiedUser.ModifiedUserId), userInfo.Id);
ret.Add(nameof(IFieldModifiedUser.ModifiedUserName), userInfo.UserName);
return ret;
}
private IUpdate<TEntity> BuildUpdate(TEntity entity, List<string> includeFields, List<string> excludeFields, bool ignoreVersion)
{
IUpdate<TEntity> updateExp;
@ -145,9 +163,7 @@ public abstract class RepositoryService<TEntity, TPrimary, TLogger>(BasicReposit
}
}
else {
updateExp = Rpo.UpdateDiy.SetDto(includeFields!.ToDictionary(
x => x
, x => typeof(TEntity).GetProperty(x, BindingFlags.Public | BindingFlags.Instance)!.GetValue(entity)));
updateExp = Rpo.UpdateDiy.SetDto(IncludeToDictionary(entity, includeFields));
if (!ignoreVersion && entity is IFieldVersion ver) {
updateExp = updateExp.Where($"{nameof(IFieldVersion.Version)} = {ver.Version}");
}

View File

@ -47,7 +47,7 @@ public abstract record MutableEntity<T> : LiteMutableEntity<T>, IFieldCreatedUse
[Column(CanInsert = false, Position = -1)]
[CsvIgnore]
[JsonIgnore]
public long? ModifiedUserId { get; init; }
public virtual long? ModifiedUserId { get; init; }
/// <summary>
/// 修改者用户名
@ -55,5 +55,5 @@ public abstract record MutableEntity<T> : LiteMutableEntity<T>, IFieldCreatedUse
[Column(DbType = Chars.FLG_DB_FIELD_TYPE_VARCHAR_31, CanInsert = false, Position = -1)]
[CsvIgnore]
[JsonIgnore]
public string ModifiedUserName { get; init; }
public virtual string ModifiedUserName { get; init; }
}

View File

@ -27,9 +27,11 @@ public sealed class SafetyShopHostMiddleware(RequestDelegate next)
public static void OnStopping()
{
Stop();
#if !DEBUG
while (Interlocked.Read(ref _connections) > 0) {
Thread.Sleep(10);
}
#endif
}
/// <summary>

View File

@ -3,8 +3,8 @@
<Import Project="$(SolutionDir)/build/copy.pkg.xml.comment.files.targets"/>
<Import Project="$(SolutionDir)/build/prebuild.targets"/>
<ItemGroup>
<PackageReference Include="NetAdmin.FreeSql.DbContext" Version="1.0.3" Label="refs"/>
<PackageReference Include="NetAdmin.FreeSql.Provider.Sqlite" Version="1.0.3" Label="refs"/>
<PackageReference Include="NetAdmin.FreeSql.DbContext" Version="1.0.6" Label="refs"/>
<PackageReference Include="NetAdmin.FreeSql.Provider.Sqlite" Version="1.0.6" Label="refs"/>
<PackageReference Include="Gurion" Version="1.2.5" Label="refs"/>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.0"/>
<PackageReference Include="Minio" Version="6.0.3"/>

View File

@ -60,7 +60,7 @@ export default {
.sc-statistic-title {
font-size: 0.9rem;
color: var(--el-color-info);
margin-bottom: 1rem;
margin-bottom: 0.5rem;
display: flex;
align-items: center;
}

View File

@ -48,7 +48,6 @@
}
}) ?? []),
],
w100p: true,
},
]"
:label-width="10"

View File

@ -30,7 +30,6 @@
}
}) ?? []),
],
w100p: true,
},
]"
:label-width="9"

View File

@ -35,7 +35,6 @@
}
}) ?? []),
],
w100p: true,
},
{
title: $t('登录用户名'),
@ -50,7 +49,6 @@
}
}) ?? []),
],
w100p: true,
},
{
title: $t('客户端IP地址'),
@ -65,7 +63,6 @@
}
}) ?? []),
],
w100p: true,
},
]"
:label-width="10"

View File

@ -34,7 +34,6 @@
}
}) ?? []),
],
w100p: true,
},
{
title: $t('请求服务'),
@ -51,7 +50,6 @@
}
}) ?? []),
],
w100p: true,
},
]"
:label-width="10"

View File

@ -68,7 +68,6 @@
}
}),
],
w100p: true,
},
]"
:label-width="15"