修改swagger首页

This commit is contained in:
2023-03-16 09:17:36 +08:00
parent a4ed390e82
commit b03cd609ac
5 changed files with 164 additions and 44 deletions

View File

@@ -2,6 +2,7 @@
"SpecificationDocumentSettings": {
"DocumentTitle": "JNPF.NET",
"DocExpansionState": "None",
"RoutePrefix": "swagger",
"GroupOpenApiInfos": [
{
"Group": "Default",
@@ -11,7 +12,7 @@
}
],
"LoginInfo": {
"Enabled": false,
"Enabled": false
// "CheckUrl": "https://localhost:5000/Home/CheckUrl",
// "SubmitUrl": "https://localhost:5000/Home/SubmitUrl"
}

View File

@@ -43,23 +43,22 @@ public class RequestActionFilter : IAsyncActionFilter
UserAgent userAgent = new UserAgent(httpContext);
var actionDes = (ControllerActionDescriptor)context.ActionDescriptor;
var actionName = $"{actionDes.ControllerTypeInfo.FullName}.{actionDes.MethodInfo.Name}";
var ignoreLog = actionDes.EndpointMetadata.Any(m => m.GetType() == typeof(IgnoreLogAttribute));
Stopwatch sw = new Stopwatch();
Log.Information("Action Starting: {0}({1})", actionName, context.ActionArguments.ToJsonString());
if (!ignoreLog) Log.Information("Action Starting: {0}({1})", actionName, context.ActionArguments.ToJsonString());
sw.Start();
var actionContext = await next();
sw.Stop();
Log.Information("Action Finished: {0}() - Elapsed: {1:F2}ms", actionName, sw.ElapsedMilliseconds);
// 判断是否请求成功(没有异常就是请求成功)
var isRequestSucceed = actionContext.Exception == null;
var headers = httpRequest.Headers;
if (!context.ActionDescriptor.EndpointMetadata.Any(m => m.GetType() == typeof(IgnoreLogAttribute)))
//var headers = httpRequest.Headers;
if (!ignoreLog && isRequestSucceed)
{
Log.Information("Action Finished: {0}() - Elapsed: {1:F2}ms", actionName, sw.ElapsedMilliseconds);
ConnectionConfigOptions options = userContext?.FindFirstValue(ClaimConst.CONNECTIONCONFIG)?.ToObject<ConnectionConfigOptions>();
var userId = userContext?.FindFirstValue(ClaimConst.CLAINMUSERID);
var userName = userContext?.FindFirstValue(ClaimConst.CLAINMREALNAME);
if (!App.HttpContext.Request.Headers.ContainsKey("Authorization"))
{
var bearer = App.HttpContext.Request.QueryString.Value.Matches(@"[?&]token=Bearer%20([\w\.-]+)($|&)");
@@ -87,12 +86,12 @@ public class RequestActionFilter : IAsyncActionFilter
CreatorTime = DateTime.Now
}));
if (context.ActionDescriptor.EndpointMetadata.Any(m => m.GetType() == typeof(OperateLogAttribute)))
var module = actionDes.EndpointMetadata.Where(x => x.GetType() == typeof(OperateLogAttribute)).FirstOrDefault() as OperateLogAttribute;
if (module != null)
{
// 操作参数
var args = context.ActionArguments.ToJsonString();
var result = (actionContext.Result as JsonResult)?.Value;
var module = context.ActionDescriptor.EndpointMetadata.Where(x => x.GetType() == typeof(OperateLogAttribute)).ToList().FirstOrDefault() as OperateLogAttribute;
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateOpLog", options, new SysLogEntity
{

View File

@@ -0,0 +1,85 @@
using System.Data;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Extend.Entitys;
using JNPF.Extend.Entitys.Dto.WoekLog;
using JNPF.Extend.Entitys.Dto.WorkLog;
using JNPF.FriendlyException;
using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Interfaces.Permission;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Yitter.IdGenerator;
namespace JNPF.Extend;
/// <summary>
/// 工作日志
/// 版 本V3.2
/// 版 权拓通智联科技有限公司http://www.tuotong-tech.com
/// 日 期2021-06-01 .
/// </summary>
[ApiDescriptionSettings(Tag = "Extend", Name = "DataMgr", Order = 600)]
[Route("api/extend/[controller]")]
public class DataMgrService : IDynamicApiController, ITransient
{
private readonly SqlSugarScope _sugar;
private readonly ITenant _db;
public DataMgrService(ISqlSugarClient context)
{
_sugar = (SqlSugarScope)context;
_db = context.AsTenant();
}
/// <summary>
/// 使用雪花Id
/// </summary>
/// <returns></returns>
[HttpPost("renew-snow-id")]
[AllowAnonymous]
public async Task<dynamic> RenewSnowIdAsync(DbMainTable mainTbl)
{
int count = 0;
var tbl = await _sugar.Queryable<dynamic>().AS(mainTbl.MainTable).ToDataTableAsync();
if (!tbl.Columns.Contains(mainTbl.PrimaryKey))
{
return count;
}
foreach (DataRow row in tbl.Rows)
{
var oldid = row[mainTbl.PrimaryKey].ToString();
var snowid = SnowflakeIdHelper.NextId();
count += await _sugar.Updateable<dynamic>().AS(mainTbl.MainTable).Where($"{mainTbl.PrimaryKey}='{oldid}'").SetColumns(mainTbl.PrimaryKey, snowid).ExecuteCommandAsync();
foreach (var refTbl in mainTbl.RefTables)
{
count += await _sugar.Updateable<dynamic>().AS(refTbl.RefTable).Where($"{refTbl.RefField}='{oldid}'").SetColumns(refTbl.RefField, snowid).ExecuteCommandAsync();
}
}
return count;
}
}
public class DbMainTable
{
public string MainTable { get; set; }
public string PrimaryKey { get; set; } = "f_id";
public List<DbTableRef> RefTables { get; set; } = new List<DbTableRef>();
public DbMainTable(string tblName)
{
MainTable = tblName;
}
}
public class DbTableRef
{
public string RefTable { get; set; }
public string RefField { get; set; }
}

View File

@@ -0,0 +1,19 @@
using JNPF.Common.Const;
using JNPF.Common.Contracts;
using SqlSugar;
namespace JNPF.TaskScheduler.Entitys.Entity;
/// <summary>
/// 定时任务
/// 版 本V3.2
/// 版 权拓通智联科技有限公司http://www.tuotong-tech.com
/// 日 期2021-06-01 .
/// </summary>
[SugarTable("snowid")]
[Tenant(ClaimConst.TENANTID)]
public class SnowIdEntity : IEntity<string>
{
//[SugarColumn(ColumnName = "id")]
public string Id { get; set; }
}

View File

@@ -1,5 +1,8 @@
using JNPF.DependencyInjection;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.Logging;
using JNPF.Systems.Entitys.Permission;
using JNPF.TaskScheduler.Entitys.Entity;
using SqlSugar;
namespace JNPF.TaskScheduler.Listener;
@@ -9,42 +12,55 @@ namespace JNPF.TaskScheduler.Listener;
/// </summary>
public class SpareTimeDemo : ISpareTimeWorker
{
/// <summary>
/// 3秒后出勤统计.
/// </summary>
/// <param name="timer">参数</param>
/// <param name="count">次数</param>
[SpareTime("* * * * * ?", "执行Sql", ExecuteType = SpareTimeExecuteTypes.Serial)]
public void ExecSql(SpareTimer timer, long count)
/// <summary>
/// 3秒后出勤统计.
/// </summary>
/// <param name="timer">参数</param>
/// <param name="count">次数</param>
[SpareTime("* * * * * ?", "生成雪花Id", ExecuteType = SpareTimeExecuteTypes.Serial)]
public void GenerateSnowId(SpareTimer timer, long count)
{
// 创建作用域
Scoped.Create((factory, scope) =>
{
// 创建作用域
Scoped.Create((factory, scope) =>
try
{
// 数据库操作
var sqlSugarRepository = App.GetService<ISqlSugarRepository<SnowIdEntity>>(scope.ServiceProvider);
List<SnowIdEntity> ls = new List<SnowIdEntity>();
for (int i = 0; i < 50; i++)
{
// 数据库操作
var sqlSugarRepository = App.GetService<ISqlSugarRepository<UserEntity>>(scope.ServiceProvider);
sqlSugarRepository.DeleteById("226890444955452677");
});
}
ls.Add(new SnowIdEntity { Id = SnowflakeIdHelper.NextId() });
Thread.Sleep(1);
}
sqlSugarRepository.InsertRange(ls);
}
catch (Exception ex)
{
Log.Error("GenerateSnowId错误", ex);
}
});
}
/// <summary>
/// 3秒后出勤统计.
/// </summary>
/// <param name="timer">参数</param>
/// <param name="count">次数</param>
[SpareTime("0 0/1 * * * ?", "执行Sql1", ExecuteType = SpareTimeExecuteTypes.Serial)]
public void ExecSql1(SpareTimer timer, long count)
/// <summary>
/// 3秒后出勤统计.
/// </summary>
/// <param name="timer">参数</param>
/// <param name="count">次数</param>
[SpareTime("0 0/1 * * * ?", "执行Sql1", ExecuteType = SpareTimeExecuteTypes.Serial)]
public void ExecSql1(SpareTimer timer, long count)
{
// 创建作用域
Scoped.Create((factory, scope) =>
{
// 创建作用域
Scoped.Create((factory, scope) =>
{
var start = DateTime.Now;
Console.WriteLine(start.ToString("yyyy-MM-dd HH:mm:ss") + ":任务开始-----------");
// 数据库操作
var sqlSugarRepository = App.GetService<ISqlSugarRepository<UserEntity>>(scope.ServiceProvider);
sqlSugarRepository.DeleteById("226890444955452677");
var end = DateTime.Now;
Console.WriteLine(end.ToString("yyyy-MM-dd HH:mm:ss") + ":任务结束-----------");
Console.WriteLine($"SQL执行了{count} 次,耗时:{(end - start).TotalMilliseconds}ms");
});
}
var start = DateTime.Now;
Console.WriteLine(start.ToString("yyyy-MM-dd HH:mm:ss") + ":任务开始-----------");
// 数据库操作
var sqlSugarRepository = App.GetService<ISqlSugarRepository<UserEntity>>(scope.ServiceProvider);
sqlSugarRepository.DeleteById("226890444955452677");
var end = DateTime.Now;
Console.WriteLine(end.ToString("yyyy-MM-dd HH:mm:ss") + ":任务结束-----------");
Console.WriteLine($"SQL执行了{count} 次,耗时:{(end - start).TotalMilliseconds}ms");
});
}
}