Skip to content

Commit

Permalink
Merge branch 'zhontai:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
yimogit committed Sep 9, 2023
2 parents b6f5712 + 819465d commit 3eefe19
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 65 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,5 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml

**/wwwroot/upload
**/wwwroot/upload
!**/ZhonTai.Admin/Core/Logs
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

```bash
# 克隆项目
git clone https://github.com/zhontai/Admin.Core/git
git clone https://github.com/zhontai/Admin.Core.git

# 进入项目
cd Admin.Core
Expand Down
2 changes: 1 addition & 1 deletion build/pkg.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.7.0</Version>
<Version>3.7.1</Version>
<TargetFramework>net7.0</TargetFramework>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
2 changes: 1 addition & 1 deletion src/hosts/ZhonTai.Host/Configs/appconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
{
"name": "中台Admin",
"code": "admin",
"version": "v3.7.0",
"version": "v3.7.1",
"description": ""
}
]
Expand Down
20 changes: 10 additions & 10 deletions src/hosts/ZhonTai.Host/ZhonTai.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Debug'">
<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.698" />
<PackageReference Include="FreeSql.Provider.SqlServer" Version="3.2.698" />
<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="3.2.698" />
<PackageReference Include="FreeSql.Provider.Oracle" Version="3.2.698" />
<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.697" />
<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.698" />
<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.700" />
<PackageReference Include="FreeSql.Provider.SqlServer" Version="3.2.700" />
<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="3.2.700" />
<PackageReference Include="FreeSql.Provider.Oracle" Version="3.2.700" />
<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.700" />
<PackageReference Include="FreeSql.Provider.MySqlConnector" Version="3.2.700" />
</ItemGroup>

<ItemGroup>
Expand All @@ -39,11 +39,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="7.1.4" />
<PackageReference Include="DotNetCore.CAP.InMemoryStorage" Version="7.1.4" />
<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.698" />
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="7.2.0" />
<PackageReference Include="DotNetCore.CAP.InMemoryStorage" Version="7.2.0" />
<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.700" />
<PackageReference Include="Savorboard.CAP.InMemoryMessageQueue" Version="7.0.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.3" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public override void OnResultExecuting(ResultExecutingContext context)
return sb.ToString();
})
.Aggregate((x, y) => x + "|" + y);
logger.LogError(errors);
context.Result = new JsonResult(ResultOutput.NotOk(errors));
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,26 @@ public static void AddDb(this IServiceCollection services, IHostEnvironment env,
var freeSqlCloud = appConfig.DistributeKey.IsNull() ? new FreeSqlCloud() : new FreeSqlCloud(appConfig.DistributeKey);
DbHelper.RegisterDb(freeSqlCloud, user, dbConfig, appConfig, hostAppOptions);

//运行主库
var masterDb = freeSqlCloud.Use(dbConfig.Key);
services.AddSingleton(provider => masterDb);
masterDb.Select<object>();

//注册多数据库
if (dbConfig.Dbs?.Length > 0)
{
foreach (var db in dbConfig.Dbs)
{
DbHelper.RegisterDb(freeSqlCloud, user, db, appConfig, null);
//运行当前库
var currentDb = freeSqlCloud.Use(dbConfig.Key);
currentDb.Select<object>();
}
}

services.AddSingleton<IFreeSql>(freeSqlCloud);
services.AddSingleton(freeSqlCloud);
services.AddScoped<UnitOfWorkManagerCloud>();
//定义主库
var fsql = freeSqlCloud.Use(dbConfig.Key);
services.AddSingleton(provider => fsql);
//运行主库
fsql.Select<object>();
}

/// <summary>
Expand Down
13 changes: 8 additions & 5 deletions src/platform/ZhonTai.Admin/Core/Filters/ControllerLogFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using ZhonTai.Admin.Core.Attributes;
using ZhonTai.Admin.Core.Configs;
using ZhonTai.Admin.Core.Logs;

namespace ZhonTai.Admin.Core.Filters;
Expand All @@ -11,21 +12,23 @@ namespace ZhonTai.Admin.Core.Filters;
/// </summary>
public class ControllerLogFilter : IAsyncActionFilter
{
private readonly ILogHandler _logHandler;
private readonly AppConfig _appConfig;

public ControllerLogFilter(ILogHandler logHandler)
public ControllerLogFilter(AppConfig appConfig)
{
_logHandler = logHandler;
_appConfig = appConfig;
}

public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
if (context.ActionDescriptor.EndpointMetadata.Any(m => m.GetType() == typeof(NoOprationLogAttribute)))
context.HttpContext.Items["_ActionArguments"] = context.ActionArguments;

if (context.ActionDescriptor.EndpointMetadata.Any(m => m.GetType() == typeof(NoOprationLogAttribute)) || !_appConfig.Log.Operation)
{
await next();
return;
}

await _logHandler.LogAsync(context, next);
await AppInfo.GetRequiredService<ILogHandler>().LogAsync(context, next);
}
}
11 changes: 3 additions & 8 deletions src/platform/ZhonTai.Admin/Core/HostApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,7 @@ string DefaultSchemaIdSelector(Type modelType)

#region 操作日志

if (appConfig.Log.Operation)
{
services.AddScoped<ILogHandler, LogHandler>();
}
services.AddScoped<ILogHandler, LogHandler>();

#endregion 操作日志

Expand All @@ -583,10 +580,8 @@ void mvcConfigure(MvcOptions options)
{
options.Filters.Add<FormatResultFilter>(20);
}
if (appConfig.Log.Operation)
{
options.Filters.Add<ControllerLogFilter>(10);
}

options.Filters.Add<ControllerLogFilter>(10);

//禁止去除ActionAsync后缀
//options.SuppressAsyncSuffixInActionNames = false;
Expand Down
7 changes: 3 additions & 4 deletions src/platform/ZhonTai.Admin/Core/Logs/LogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ IOprationLogService oprationLogService

public async Task LogAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
var sw = new Stopwatch();
sw.Start();
var stopwatch = Stopwatch.StartNew();
var actionExecutedContext = await next();
sw.Stop();
stopwatch.Stop();

//操作参数
//var args = JsonConvert.SerializeObject(context.ActionArguments);
Expand All @@ -48,7 +47,7 @@ public async Task LogAsync(ActionExecutingContext context, ActionExecutionDelega
Status = true,
ApiMethod = context.HttpContext.Request.Method.ToLower(),
ApiPath = context.ActionDescriptor.AttributeRouteInfo.Template.ToLower(),
ElapsedMilliseconds = sw.ElapsedMilliseconds
ElapsedMilliseconds = stopwatch.ElapsedMilliseconds
};

if (actionExecutedContext.Exception != null)
Expand Down
13 changes: 10 additions & 3 deletions src/platform/ZhonTai.Admin/Core/Middlewares/ExceptionMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ZhonTai.Admin.Core.Exceptions;
using ZhonTai.Admin.Core.Dto;
using ZhonTai.Common.Helpers;
using System.Linq;

namespace ZhonTai.Admin.Core.Middlewares;

Expand Down Expand Up @@ -44,8 +45,6 @@ private static Task HandleAppExceptionAsync(HttpContext context, AppException ap
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.OK;

//_logger.LogError(exception, "");

return context.Response.WriteAsync(JsonHelper.Serialize(new ResultOutput<string>()
{
Code = appException.AppCode
Expand All @@ -56,7 +55,15 @@ private Task HandleExceptionAsync(HttpContext context, Exception exception)
{
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
_logger.LogError(exception, "");

var authorization = context.Request.Headers.Authorization.FirstOrDefault();
var userAgent = context.Request.Headers.UserAgent.FirstOrDefault();
context.Items.TryGetValue("_ActionArguments", out object? actionArguments);
_logger.LogError(exception,
"Error while processing request. ActionArguments: {ActionArguments}, Authorization: {Authorization}, UserAgent: {UserAgent}",
actionArguments != null ? JsonHelper.Serialize(actionArguments) : "",
authorization,
userAgent);

return context.Response.WriteAsync(JsonHelper.Serialize(new ResultOutput<string>().NotOk(exception.Message)));
}
Expand Down
16 changes: 7 additions & 9 deletions src/platform/ZhonTai.Admin/Services/Auth/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ public async Task<dynamic> LoginAsync(AuthLoginInput input)
{
using (_userRepository.DataFilter.DisableAll())
{
var sw = new Stopwatch();
sw.Start();
var stopwatch = Stopwatch.StartNew();

#region 验证码校验

Expand Down Expand Up @@ -430,15 +429,15 @@ public async Task<dynamic> LoginAsync(AuthLoginInput input)
string token = GetToken(authLoginOutput);
#endregion

sw.Stop();
stopwatch.Stop();

#region 添加登录日志

var loginLogAddInput = new LoginLogAddInput
{
TenantId = authLoginOutput.TenantId,
Name = authLoginOutput.Name,
ElapsedMilliseconds = sw.ElapsedMilliseconds,
ElapsedMilliseconds = stopwatch.ElapsedMilliseconds,
Status = true,
CreatedUserId = authLoginOutput.Id,
CreatedUserName = user.UserName,
Expand All @@ -464,11 +463,10 @@ public async Task<dynamic> MobileLoginAsync(AuthMobileLoginInput input)
{
using (_userRepository.DataFilter.DisableAll())
{
var sw = new Stopwatch();
sw.Start();
var stopwatch = Stopwatch.StartNew();

#region 短信验证码验证
if(input.CodeId.IsNull() || input.Code.IsNull())
if (input.CodeId.IsNull() || input.Code.IsNull())
{
throw ResultOutput.Exception("验证码错误");
}
Expand Down Expand Up @@ -513,15 +511,15 @@ public async Task<dynamic> MobileLoginAsync(AuthMobileLoginInput input)
string token = GetToken(authLoginOutput);
#endregion

sw.Stop();
stopwatch.Stop();

#region 添加登录日志

var loginLogAddInput = new LoginLogAddInput
{
TenantId = authLoginOutput.TenantId,
Name = authLoginOutput.Name,
ElapsedMilliseconds = sw.ElapsedMilliseconds,
ElapsedMilliseconds = stopwatch.ElapsedMilliseconds,
Status = true,
CreatedUserId = authLoginOutput.Id,
CreatedUserName = user.UserName,
Expand Down
22 changes: 11 additions & 11 deletions src/platform/ZhonTai.Admin/ZhonTai.Admin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="7.0.0-rc2.7" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="7.1.0" />
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="7.1.0" />
<PackageReference Include="Castle.Core.AsyncInterceptor" Version="2.1.0" />
<PackageReference Include="DotNetCore.CAP" Version="7.1.4" />
<PackageReference Include="DotNetCore.CAP" Version="7.2.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="FreeRedis" Version="1.1.5" />
<PackageReference Include="FreeRedis" Version="1.1.7" />
<PackageReference Include="FreeRedis.DistributedCache" Version="1.0.5" />
<PackageReference Include="FreeSql" Version="3.2.698" />
<PackageReference Include="FreeSql" Version="3.2.700" />
<PackageReference Include="FreeSql.Cloud" Version="1.6.6" />
<PackageReference Include="FreeSql.Repository" Version="3.2.698" />
<PackageReference Include="FreeSql.Repository" Version="3.2.700" />
<PackageReference Include="FreeScheduler" Version="1.1.0" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Lazy.SlideCaptcha.Core" Version="2.0.0" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.10" />
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.3.8" />
<PackageReference Include="NLog" Version="5.2.2" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.2" />
<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.1.9" />
<PackageReference Include="NLog" Version="5.2.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.3" />
<PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.2.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta15" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.32.0" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.32.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
Expand Down
4 changes: 2 additions & 2 deletions src/platform/ZhonTai.Common/Helpers/JsonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class JsonHelper
private static readonly JsonSerializerSettings _jsonSerializerSettings = new()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
DateFormatString = "yyyy-MM-dd HH:mm:ss"
};
DateFormatString = "yyyy-MM-dd HH:mm:ss.FFFFFFFK"
};

/// <summary>
/// 序列化
Expand Down
6 changes: 3 additions & 3 deletions src/tests/ZhonTai.Tests/ZhonTai.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.10" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit 3eefe19

Please sign in to comment.