修改swagger首页
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
"SpecificationDocumentSettings": {
|
"SpecificationDocumentSettings": {
|
||||||
"DocumentTitle": "JNPF.NET",
|
"DocumentTitle": "JNPF.NET",
|
||||||
"DocExpansionState": "None",
|
"DocExpansionState": "None",
|
||||||
|
"RoutePrefix": "swagger",
|
||||||
"GroupOpenApiInfos": [
|
"GroupOpenApiInfos": [
|
||||||
{
|
{
|
||||||
"Group": "Default",
|
"Group": "Default",
|
||||||
@@ -11,7 +12,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"LoginInfo": {
|
"LoginInfo": {
|
||||||
"Enabled": false,
|
"Enabled": false
|
||||||
// "CheckUrl": "https://localhost:5000/Home/CheckUrl",
|
// "CheckUrl": "https://localhost:5000/Home/CheckUrl",
|
||||||
// "SubmitUrl": "https://localhost:5000/Home/SubmitUrl"
|
// "SubmitUrl": "https://localhost:5000/Home/SubmitUrl"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,23 +43,22 @@ public class RequestActionFilter : IAsyncActionFilter
|
|||||||
UserAgent userAgent = new UserAgent(httpContext);
|
UserAgent userAgent = new UserAgent(httpContext);
|
||||||
var actionDes = (ControllerActionDescriptor)context.ActionDescriptor;
|
var actionDes = (ControllerActionDescriptor)context.ActionDescriptor;
|
||||||
var actionName = $"{actionDes.ControllerTypeInfo.FullName}.{actionDes.MethodInfo.Name}";
|
var actionName = $"{actionDes.ControllerTypeInfo.FullName}.{actionDes.MethodInfo.Name}";
|
||||||
|
var ignoreLog = actionDes.EndpointMetadata.Any(m => m.GetType() == typeof(IgnoreLogAttribute));
|
||||||
|
|
||||||
Stopwatch sw = new Stopwatch();
|
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();
|
sw.Start();
|
||||||
var actionContext = await next();
|
var actionContext = await next();
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
Log.Information("Action Finished: {0}() - Elapsed: {1:F2}ms", actionName, sw.ElapsedMilliseconds);
|
|
||||||
|
|
||||||
// 判断是否请求成功(没有异常就是请求成功)
|
// 判断是否请求成功(没有异常就是请求成功)
|
||||||
var isRequestSucceed = actionContext.Exception == null;
|
var isRequestSucceed = actionContext.Exception == null;
|
||||||
var headers = httpRequest.Headers;
|
//var headers = httpRequest.Headers;
|
||||||
if (!context.ActionDescriptor.EndpointMetadata.Any(m => m.GetType() == typeof(IgnoreLogAttribute)))
|
if (!ignoreLog && isRequestSucceed)
|
||||||
{
|
{
|
||||||
|
Log.Information("Action Finished: {0}() - Elapsed: {1:F2}ms", actionName, sw.ElapsedMilliseconds);
|
||||||
ConnectionConfigOptions options = userContext?.FindFirstValue(ClaimConst.CONNECTIONCONFIG)?.ToObject<ConnectionConfigOptions>();
|
ConnectionConfigOptions options = userContext?.FindFirstValue(ClaimConst.CONNECTIONCONFIG)?.ToObject<ConnectionConfigOptions>();
|
||||||
var userId = userContext?.FindFirstValue(ClaimConst.CLAINMUSERID);
|
var userId = userContext?.FindFirstValue(ClaimConst.CLAINMUSERID);
|
||||||
var userName = userContext?.FindFirstValue(ClaimConst.CLAINMREALNAME);
|
var userName = userContext?.FindFirstValue(ClaimConst.CLAINMREALNAME);
|
||||||
|
|
||||||
if (!App.HttpContext.Request.Headers.ContainsKey("Authorization"))
|
if (!App.HttpContext.Request.Headers.ContainsKey("Authorization"))
|
||||||
{
|
{
|
||||||
var bearer = App.HttpContext.Request.QueryString.Value.Matches(@"[?&]token=Bearer%20([\w\.-]+)($|&)");
|
var bearer = App.HttpContext.Request.QueryString.Value.Matches(@"[?&]token=Bearer%20([\w\.-]+)($|&)");
|
||||||
@@ -87,12 +86,12 @@ public class RequestActionFilter : IAsyncActionFilter
|
|||||||
CreatorTime = DateTime.Now
|
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 args = context.ActionArguments.ToJsonString();
|
||||||
var result = (actionContext.Result as JsonResult)?.Value;
|
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
|
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateOpLog", options, new SysLogEntity
|
||||||
{
|
{
|
||||||
|
|||||||
85
extend/Tnb.Extend/DataMgrService.cs
Normal file
85
extend/Tnb.Extend/DataMgrService.cs
Normal 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; }
|
||||||
|
|
||||||
|
}
|
||||||
19
taskschedule/Tnb.TaskScheduler.Entitys/Entity/SnowId.cs
Normal file
19
taskschedule/Tnb.TaskScheduler.Entitys/Entity/SnowId.cs
Normal 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; }
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
using JNPF.DependencyInjection;
|
using JNPF.Common.Security;
|
||||||
|
using JNPF.DependencyInjection;
|
||||||
|
using JNPF.Logging;
|
||||||
using JNPF.Systems.Entitys.Permission;
|
using JNPF.Systems.Entitys.Permission;
|
||||||
|
using JNPF.TaskScheduler.Entitys.Entity;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
||||||
namespace JNPF.TaskScheduler.Listener;
|
namespace JNPF.TaskScheduler.Listener;
|
||||||
@@ -9,42 +12,55 @@ namespace JNPF.TaskScheduler.Listener;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SpareTimeDemo : ISpareTimeWorker
|
public class SpareTimeDemo : ISpareTimeWorker
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 3秒后出勤统计.
|
/// 3秒后出勤统计.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="timer">参数</param>
|
/// <param name="timer">参数</param>
|
||||||
/// <param name="count">次数</param>
|
/// <param name="count">次数</param>
|
||||||
[SpareTime("* * * * * ?", "执行Sql", ExecuteType = SpareTimeExecuteTypes.Serial)]
|
[SpareTime("* * * * * ?", "生成雪花Id", ExecuteType = SpareTimeExecuteTypes.Serial)]
|
||||||
public void ExecSql(SpareTimer timer, long count)
|
public void GenerateSnowId(SpareTimer timer, long count)
|
||||||
|
{
|
||||||
|
// 创建作用域
|
||||||
|
Scoped.Create((factory, scope) =>
|
||||||
{
|
{
|
||||||
// 创建作用域
|
try
|
||||||
Scoped.Create((factory, scope) =>
|
{
|
||||||
|
// 数据库操作
|
||||||
|
var sqlSugarRepository = App.GetService<ISqlSugarRepository<SnowIdEntity>>(scope.ServiceProvider);
|
||||||
|
List<SnowIdEntity> ls = new List<SnowIdEntity>();
|
||||||
|
for (int i = 0; i < 50; i++)
|
||||||
{
|
{
|
||||||
// 数据库操作
|
ls.Add(new SnowIdEntity { Id = SnowflakeIdHelper.NextId() });
|
||||||
var sqlSugarRepository = App.GetService<ISqlSugarRepository<UserEntity>>(scope.ServiceProvider);
|
Thread.Sleep(1);
|
||||||
sqlSugarRepository.DeleteById("226890444955452677");
|
}
|
||||||
});
|
sqlSugarRepository.InsertRange(ls);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error("GenerateSnowId错误:", ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 3秒后出勤统计.
|
/// 3秒后出勤统计.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="timer">参数</param>
|
/// <param name="timer">参数</param>
|
||||||
/// <param name="count">次数</param>
|
/// <param name="count">次数</param>
|
||||||
[SpareTime("0 0/1 * * * ?", "执行Sql1", ExecuteType = SpareTimeExecuteTypes.Serial)]
|
[SpareTime("0 0/1 * * * ?", "执行Sql1", ExecuteType = SpareTimeExecuteTypes.Serial)]
|
||||||
public void ExecSql1(SpareTimer timer, long count)
|
public void ExecSql1(SpareTimer timer, long count)
|
||||||
|
{
|
||||||
|
// 创建作用域
|
||||||
|
Scoped.Create((factory, scope) =>
|
||||||
{
|
{
|
||||||
// 创建作用域
|
var start = DateTime.Now;
|
||||||
Scoped.Create((factory, scope) =>
|
Console.WriteLine(start.ToString("yyyy-MM-dd HH:mm:ss") + ":任务开始-----------");
|
||||||
{
|
// 数据库操作
|
||||||
var start = DateTime.Now;
|
var sqlSugarRepository = App.GetService<ISqlSugarRepository<UserEntity>>(scope.ServiceProvider);
|
||||||
Console.WriteLine(start.ToString("yyyy-MM-dd HH:mm:ss") + ":任务开始-----------");
|
sqlSugarRepository.DeleteById("226890444955452677");
|
||||||
// 数据库操作
|
var end = DateTime.Now;
|
||||||
var sqlSugarRepository = App.GetService<ISqlSugarRepository<UserEntity>>(scope.ServiceProvider);
|
Console.WriteLine(end.ToString("yyyy-MM-dd HH:mm:ss") + ":任务结束-----------");
|
||||||
sqlSugarRepository.DeleteById("226890444955452677");
|
Console.WriteLine($"SQL执行了:{count} 次,耗时:{(end - start).TotalMilliseconds}ms");
|
||||||
var end = DateTime.Now;
|
});
|
||||||
Console.WriteLine(end.ToString("yyyy-MM-dd HH:mm:ss") + ":任务结束-----------");
|
}
|
||||||
Console.WriteLine($"SQL执行了:{count} 次,耗时:{(end - start).TotalMilliseconds}ms");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user