mirror of
https://github.com/nsnail/NetAdmin.git
synced 2025-06-20 02:38:15 +08:00
@ -10,5 +10,5 @@ public sealed class IndicatorAttribute(string indicate) : Attribute
|
||||
/// <summary>
|
||||
/// 状态指示
|
||||
/// </summary>
|
||||
public string Indicate { get; init; } = indicate;
|
||||
public string Indicate { get; } = indicate;
|
||||
}
|
@ -61,7 +61,7 @@ public record Sys_Job : VersionEntity, IFieldEnabled, IFieldSummary
|
||||
[Column]
|
||||
[Ignore]
|
||||
[JsonIgnore]
|
||||
public virtual HttpStatusCode? LastStatusCode { get; init; }
|
||||
public HttpStatusCode? LastStatusCode { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 下次执行时间
|
||||
|
@ -172,6 +172,14 @@ public record Sys_RequestLog : SimpleEntity, IFieldCreatedTime, IFieldCreatedCli
|
||||
[JsonIgnore]
|
||||
public virtual int? ServerIp { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求跟踪标识
|
||||
/// </summary>
|
||||
[Column(DbType = Chars.FLG_DB_FIELD_TYPE_VARCHAR_31)]
|
||||
[Ignore]
|
||||
[JsonIgnore]
|
||||
public virtual string TraceId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户
|
||||
/// </summary>
|
||||
|
@ -6,17 +6,17 @@ namespace NetAdmin.Domain.Dto.Dependency;
|
||||
public sealed record PagedQueryRsp<T>(int Page, int PageSize, long Total, IEnumerable<T> Rows) : IPagedInfo
|
||||
where T : DataAbstraction
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据行
|
||||
/// </summary>
|
||||
public IEnumerable<T> Rows { get; } = Rows;
|
||||
|
||||
/// <inheritdoc cref="IPagedInfo.Page" />
|
||||
public int Page { get; init; } = Page;
|
||||
|
||||
/// <inheritdoc cref="IPagedInfo.PageSize" />
|
||||
public int PageSize { get; init; } = PageSize;
|
||||
|
||||
/// <summary>
|
||||
/// 数据行
|
||||
/// </summary>
|
||||
public IEnumerable<T> Rows { get; init; } = Rows;
|
||||
|
||||
/// <summary>
|
||||
/// 数据总条
|
||||
/// </summary>
|
||||
|
@ -34,6 +34,7 @@ public sealed record GetAllEntriesRsp : DataAbstraction
|
||||
/// <summary>
|
||||
/// 绝对过期时间
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public long AbsExp { get; init; }
|
||||
|
||||
/// <summary>
|
||||
@ -49,5 +50,6 @@ public sealed record GetAllEntriesRsp : DataAbstraction
|
||||
/// <summary>
|
||||
/// 滑动过期时间
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public long SldExp { get; init; }
|
||||
}
|
@ -29,6 +29,7 @@ public sealed record IconExportJsInfo : DataAbstraction
|
||||
/// <summary>
|
||||
/// Icons
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public ICollection<string> Icons { get; init; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -10,6 +10,7 @@ namespace NetAdmin.Domain.Dto.Sys.Job;
|
||||
public record QueryJobRsp : Sys_Job
|
||||
{
|
||||
/// <inheritdoc cref="Sys_Job.LastStatusCode" />
|
||||
[JsonInclude]
|
||||
public new virtual string LastStatusCode =>
|
||||
#pragma warning disable IDE0072
|
||||
base.LastStatusCode switch {
|
||||
|
@ -9,6 +9,7 @@ namespace NetAdmin.Domain.Dto.Sys.JobRecord;
|
||||
public record QueryJobRecordRsp : Sys_JobRecord
|
||||
{
|
||||
/// <inheritdoc cref="Sys_JobRecord.HttpStatusCode" />
|
||||
[JsonInclude]
|
||||
public new virtual string HttpStatusCode =>
|
||||
base.HttpStatusCode == Numbers.HTTP_STATUS_BIZ_FAIL
|
||||
? nameof(ErrorCodes.Unhandled).ToLowerCamelCase()
|
||||
|
@ -31,36 +31,43 @@ public sealed record MetaInfo : DataAbstraction
|
||||
/// <summary>
|
||||
/// 背景颜色
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public string Color { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否整页路由
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public bool FullPage { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否隐藏
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public bool Hidden { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否隐藏面包屑
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public bool HiddenBreadCrumb { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 图标
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public string Icon { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 标签
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public string Tag { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public string Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
@ -68,5 +75,6 @@ public sealed record MetaInfo : DataAbstraction
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(MenuTypes), ErrorMessageResourceType = typeof(Ln)
|
||||
, ErrorMessageResourceName = nameof(Ln.菜单类型不正确))]
|
||||
[JsonInclude]
|
||||
public MenuTypes Type { get; init; }
|
||||
}
|
@ -59,6 +59,12 @@ public record ExportRequestLogRsp : QueryRequestLogRsp
|
||||
[Name(nameof(Ln.请求方式))]
|
||||
public override string Method { get; init; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[CsvIndex(9)]
|
||||
[Ignore(false)]
|
||||
[Name(nameof(Ln.跟踪编号))]
|
||||
public override string TraceId { get; init; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[Ignore]
|
||||
public override QueryUserRsp User { get; init; }
|
||||
|
@ -10,16 +10,19 @@ public record QueryRequestLogRsp : Sys_RequestLog, IRegister
|
||||
/// <summary>
|
||||
/// 创建者客户端IP
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public new virtual string CreatedClientIp => base.CreatedClientIp?.ToIpV4();
|
||||
|
||||
/// <summary>
|
||||
/// 登录名
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public virtual string LoginName => RequestBody?.ToObject<LoginByPwdReq>()?.Account;
|
||||
|
||||
/// <summary>
|
||||
/// 操作系统
|
||||
/// </summary>
|
||||
[JsonInclude]
|
||||
public virtual string Os => UserAgentParser.Create(CreatedUserAgent)?.Platform;
|
||||
|
||||
/// <inheritdoc cref="Sys_RequestLog.ApiId" />
|
||||
@ -91,6 +94,10 @@ public record QueryRequestLogRsp : Sys_RequestLog, IRegister
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public override int? ServerIp { get; init; }
|
||||
|
||||
/// <inheritdoc cref="Sys_RequestLog.TraceId" />
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public override string TraceId { get; init; }
|
||||
|
||||
/// <inheritdoc cref="Sys_RequestLog.User" />
|
||||
public new virtual QueryUserRsp User { get; init; }
|
||||
|
||||
|
@ -68,7 +68,7 @@ public static class IMvcBuilderExtensions
|
||||
/// <summary>
|
||||
/// 设置Json选项
|
||||
/// </summary>
|
||||
public static void SetJsonOptions(bool enumToString, JsonOptions options)
|
||||
private static void SetJsonOptions(bool enumToString, JsonOptions options)
|
||||
{
|
||||
////////////////////////////// json -> object
|
||||
|
||||
|
@ -26,7 +26,7 @@ public abstract class Startup : AppStartup
|
||||
/// <summary>
|
||||
/// 打印Banner
|
||||
/// </summary>
|
||||
protected static void ShowBanner()
|
||||
private static void ShowBanner()
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
var gridInfo = new Grid().AddColumn(new GridColumn().NoWrap().Width(50).PadRight(10))
|
||||
|
@ -19,7 +19,6 @@ public sealed class RequestLogger(ILogger<RequestLogger> logger, IEventPublisher
|
||||
{
|
||||
// 从请求头中读取用户信息
|
||||
var associatedUser = GetAssociatedUser(context);
|
||||
|
||||
var auditData = new CreateRequestLogReq {
|
||||
Duration = duration
|
||||
, Method = context.Request.Method
|
||||
@ -48,6 +47,7 @@ public sealed class RequestLogger(ILogger<RequestLogger> logger, IEventPublisher
|
||||
?.MapToIPv4()
|
||||
.ToString()
|
||||
.IpV4ToInt32()
|
||||
, TraceId = context.TraceIdentifier
|
||||
};
|
||||
|
||||
// 打印日志
|
||||
|
@ -19,5 +19,5 @@ public abstract class NetAdminException(string message, Exception innerException
|
||||
/// <summary>
|
||||
/// 错误码
|
||||
/// </summary>
|
||||
public ErrorCodes Code { get; init; }
|
||||
public ErrorCodes Code { get; }
|
||||
}
|
@ -5,22 +5,22 @@ namespace NetAdmin.Infrastructure.Extensions;
|
||||
/// </summary>
|
||||
public static class HttpRequestMessageExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 将Http请求的Uri、Header、Body打包成Json字符串
|
||||
/// </summary>
|
||||
public static async Task<string> BuildJsonAsync(this HttpRequestMessage me)
|
||||
{
|
||||
var body = me?.Content == null ? null : await me.Content!.ReadAsStringAsync().ConfigureAwait(false);
|
||||
return new { Uri = me?.RequestUri, Header = me?.ToString(), Body = body }.ToJson();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录日志
|
||||
/// </summary>
|
||||
public static async Task<HttpRequestMessage> LogAsync<T>(this HttpRequestMessage me, ILogger<T> logger)
|
||||
{
|
||||
logger.Info(
|
||||
$"HTTP Request: {(await me.BuildJsonAsync().ConfigureAwait(false))?.Sub(0, Numbers.MAX_LIMIT_PRINT_LEN_CONTENT)}");
|
||||
$"HTTP Request {(await me.BuildJsonAsync().ConfigureAwait(false))?.Sub(0, Numbers.MAX_LIMIT_PRINT_LEN_CONTENT)}");
|
||||
return me;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将Http请求的Uri、Header、Body打包成Json字符串
|
||||
/// </summary>
|
||||
private static async Task<string> BuildJsonAsync(this HttpRequestMessage me)
|
||||
{
|
||||
var body = me?.Content == null ? null : await me.Content!.ReadAsStringAsync().ConfigureAwait(false);
|
||||
return new { Uri = me?.RequestUri, Header = me?.ToString(), Body = body }.ToJson();
|
||||
}
|
||||
}
|
@ -11,9 +11,8 @@ public static class HttpResponseMessageExtensions
|
||||
public static async Task LogAsync<T>(this HttpResponseMessage me, ILogger<T> logger
|
||||
, Func<string, string> bodyPreHandle = null)
|
||||
{
|
||||
logger.Info(
|
||||
(await me.BuildJsonAsync(bodyPreHandle).ConfigureAwait(false))?.Sub(
|
||||
0, Numbers.MAX_LIMIT_PRINT_LEN_CONTENT));
|
||||
logger.Info($"HTTP Response {(await me.BuildJsonAsync(bodyPreHandle).ConfigureAwait(false))?.Sub(
|
||||
0, Numbers.MAX_LIMIT_PRINT_LEN_CONTENT)}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -13,4 +13,9 @@ public interface IDicContentService : IService, IDicContentModule
|
||||
/// 编辑字典内容
|
||||
/// </summary>
|
||||
Task<QueryDicContentRsp> EditAsync(EditDicContentReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 通过分类键查询字典内容
|
||||
/// </summary>
|
||||
Task<List<QueryDicContentRsp>> QueryByCatalogCodeAsync(string catalogCode);
|
||||
}
|
@ -141,6 +141,17 @@ public sealed class DicContentService(BasicRepository<Sys_DicContent, long> rpo)
|
||||
return ret.Adapt<IEnumerable<QueryDicContentRsp>>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<List<QueryDicContentRsp>> QueryByCatalogCodeAsync(string catalogCode)
|
||||
{
|
||||
var ret = await Rpo.Orm.Select<Sys_DicContent>()
|
||||
.Include(a => a.Catalog)
|
||||
.Where(a => a.Catalog.Code == catalogCode)
|
||||
.ToListAsync()
|
||||
.ConfigureAwait(false);
|
||||
return ret.Adapt<List<QueryDicContentRsp>>();
|
||||
}
|
||||
|
||||
private ISelect<Sys_DicContent> QueryInternal(QueryReq<QueryDicContentReq> req)
|
||||
{
|
||||
var ret = Rpo.Select.WhereDynamicFilter(req.DynamicFilter).WhereDynamic(req.Filter);
|
||||
|
@ -279,17 +279,16 @@ public sealed class UserService(
|
||||
public async Task<int> ResetPasswordAsync(ResetPasswordReq req)
|
||||
{
|
||||
req.ThrowIfInvalid();
|
||||
if (await verifyCodeService.VerifyAsync(req.VerifySmsCodeReq).ConfigureAwait(false)) {
|
||||
var dto = (await Rpo.Where(a => a.Mobile == req.VerifySmsCodeReq.DestDevice)
|
||||
.ToOneAsync(a => new { a.Version, a.Id })
|
||||
.ConfigureAwait(false)).Adapt<Sys_User>() with {
|
||||
Password = req.PasswordText.Pwd()
|
||||
.Guid()
|
||||
};
|
||||
return await UpdateAsync(dto, [nameof(Sys_User.Password)]).ConfigureAwait(false);
|
||||
if (!await verifyCodeService.VerifyAsync(req.VerifySmsCodeReq).ConfigureAwait(false)) {
|
||||
throw new NetAdminInvalidOperationException(Ln.验证码不正确);
|
||||
}
|
||||
|
||||
throw new NetAdminInvalidOperationException(Ln.验证码不正确);
|
||||
var dto = (await Rpo.Where(a => a.Mobile == req.VerifySmsCodeReq.DestDevice)
|
||||
.ToOneAsync(a => new { a.Version, a.Id })
|
||||
.ConfigureAwait(false)).Adapt<Sys_User>() with {
|
||||
Password = req.PasswordText.Pwd().Guid()
|
||||
};
|
||||
return await UpdateAsync(dto, [nameof(Sys_User.Password)]).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -1,4 +1,5 @@
|
||||
using NetAdmin.Cache;
|
||||
using NetAdmin.Domain.Dto.Sys.Dic.Content;
|
||||
using NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
@ -7,4 +8,10 @@ namespace NetAdmin.SysComponent.Cache.Sys.Dependency;
|
||||
/// <summary>
|
||||
/// 字典内容缓存
|
||||
/// </summary>
|
||||
public interface IDicContentCache : ICache<IDistributedCache, IDicContentService>, IDicContentModule;
|
||||
public interface IDicContentCache : ICache<IDistributedCache, IDicContentService>, IDicContentModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 通过分类键查询字典内容
|
||||
/// </summary>
|
||||
Task<List<QueryDicContentRsp>> QueryByCatalogCodeAsync(string catalogCode);
|
||||
}
|
@ -1,7 +1,4 @@
|
||||
using NetAdmin.Cache;
|
||||
using NetAdmin.Domain.Dto.Dependency;
|
||||
using NetAdmin.Domain.Dto.Sys.User;
|
||||
using NetAdmin.Domain.Dto.Sys.UserProfile;
|
||||
using NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
@ -12,41 +9,6 @@ namespace NetAdmin.SysComponent.Cache.Sys.Dependency;
|
||||
/// </summary>
|
||||
public interface IUserCache : ICache<IDistributedCache, IUserService>, IUserModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除缓存 CheckMobileAvailableAsync
|
||||
/// </summary>
|
||||
Task RemoveCheckMobileAvailableAsync(CheckMobileAvailableReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 删除缓存 CheckUserNameAvailableAsync
|
||||
/// </summary>
|
||||
Task RemoveCheckUserNameAvailableAsync(CheckUserNameAvailableReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 删除缓存 LoginByPwdAsync
|
||||
/// </summary>
|
||||
Task RemoveLoginByPwdAsync(LoginByPwdReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 删除缓存 LoginBySmsAsync
|
||||
/// </summary>
|
||||
Task RemoveLoginBySmsAsync(LoginBySmsReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 删除缓存 QueryProfileAsync
|
||||
/// </summary>
|
||||
Task RemoveQueryProfileAsync(QueryReq<QueryUserProfileReq> req);
|
||||
|
||||
/// <summary>
|
||||
/// 删除缓存 RegisterAsync
|
||||
/// </summary>
|
||||
Task RemoveRegisterAsync(RegisterUserReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 删除缓存 ResetPasswordAsync
|
||||
/// </summary>
|
||||
Task RemoveResetPasswordAsync(ResetPasswordReq req);
|
||||
|
||||
/// <summary>
|
||||
/// 删除缓存 UserInfoAsync
|
||||
/// </summary>
|
||||
|
@ -63,4 +63,16 @@ public sealed class DicContentCache(IDistributedCache cache, IDicContentService
|
||||
{
|
||||
return Service.QueryAsync(req);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<List<QueryDicContentRsp>> QueryByCatalogCodeAsync(string catalogCode)
|
||||
{
|
||||
#if !DEBUG
|
||||
return GetOrCreateAsync( //
|
||||
GetCacheKey(catalogCode), () => Service.QueryByCatalogCodeAsync(catalogCode)
|
||||
, TimeSpan.FromSeconds(Numbers.SECS_CACHE_DIC_CATALOG_CODE));
|
||||
#else
|
||||
return Service.QueryByCatalogCodeAsync(catalogCode);
|
||||
#endif
|
||||
}
|
||||
}
|
@ -119,48 +119,6 @@ public sealed class UserCache(IDistributedCache cache, IUserService service, IVe
|
||||
return Service.RegisterAsync(req);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task RemoveCheckMobileAvailableAsync(CheckMobileAvailableReq req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task RemoveCheckUserNameAvailableAsync(CheckUserNameAvailableReq req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task RemoveLoginByPwdAsync(LoginByPwdReq req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task RemoveLoginBySmsAsync(LoginBySmsReq req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task RemoveQueryProfileAsync(QueryReq<QueryUserProfileReq> req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task RemoveRegisterAsync(RegisterUserReq req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task RemoveResetPasswordAsync(ResetPasswordReq req)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task RemoveUserInfoAsync()
|
||||
{
|
||||
|
Reference in New Issue
Block a user