diff --git a/apihost/Tnb.API.Entry/Configurations/Swagger.json b/apihost/Tnb.API.Entry/Configurations/Swagger.json index 266ed1c4..66d6cf45 100644 --- a/apihost/Tnb.API.Entry/Configurations/Swagger.json +++ b/apihost/Tnb.API.Entry/Configurations/Swagger.json @@ -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" } diff --git a/common/Tnb.Common.Core/Filter/RequestActionFilter.cs b/common/Tnb.Common.Core/Filter/RequestActionFilter.cs index 3faa5c65..9fdaa517 100644 --- a/common/Tnb.Common.Core/Filter/RequestActionFilter.cs +++ b/common/Tnb.Common.Core/Filter/RequestActionFilter.cs @@ -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(); 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 { diff --git a/extend/Tnb.Extend/DataMgrService.cs b/extend/Tnb.Extend/DataMgrService.cs new file mode 100644 index 00000000..f00ad4ec --- /dev/null +++ b/extend/Tnb.Extend/DataMgrService.cs @@ -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; + +/// +/// 工作日志 +/// 版 本:V3.2 +/// 版 权:拓通智联科技有限公司(http://www.tuotong-tech.com) +/// 日 期:2021-06-01 . +/// +[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(); + } + + /// + /// 使用雪花Id + /// + /// + [HttpPost("renew-snow-id")] + [AllowAnonymous] + public async Task RenewSnowIdAsync(DbMainTable mainTbl) + { + int count = 0; + var tbl = await _sugar.Queryable().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().AS(mainTbl.MainTable).Where($"{mainTbl.PrimaryKey}='{oldid}'").SetColumns(mainTbl.PrimaryKey, snowid).ExecuteCommandAsync(); + foreach (var refTbl in mainTbl.RefTables) + { + count += await _sugar.Updateable().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 RefTables { get; set; } = new List(); + public DbMainTable(string tblName) + { + MainTable = tblName; + } +} +public class DbTableRef +{ + public string RefTable { get; set; } + public string RefField { get; set; } + +} \ No newline at end of file diff --git a/taskschedule/Tnb.TaskScheduler.Entitys/Entity/SnowId.cs b/taskschedule/Tnb.TaskScheduler.Entitys/Entity/SnowId.cs new file mode 100644 index 00000000..a0993514 --- /dev/null +++ b/taskschedule/Tnb.TaskScheduler.Entitys/Entity/SnowId.cs @@ -0,0 +1,19 @@ +using JNPF.Common.Const; +using JNPF.Common.Contracts; +using SqlSugar; + +namespace JNPF.TaskScheduler.Entitys.Entity; + +/// +/// 定时任务 +/// 版 本:V3.2 +/// 版 权:拓通智联科技有限公司(http://www.tuotong-tech.com) +/// 日 期:2021-06-01 . +/// +[SugarTable("snowid")] +[Tenant(ClaimConst.TENANTID)] +public class SnowIdEntity : IEntity +{ + //[SugarColumn(ColumnName = "id")] + public string Id { get; set; } +} diff --git a/taskschedule/Tnb.TaskScheduler/Listener/SpareTimeDemo.cs b/taskschedule/Tnb.TaskScheduler/Listener/SpareTimeDemo.cs index ff4c1f17..0ec14f7c 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/SpareTimeDemo.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/SpareTimeDemo.cs @@ -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; /// public class SpareTimeDemo : ISpareTimeWorker { - /// - /// 3秒后出勤统计. - /// - /// 参数 - /// 次数 - [SpareTime("* * * * * ?", "执行Sql", ExecuteType = SpareTimeExecuteTypes.Serial)] - public void ExecSql(SpareTimer timer, long count) + /// + /// 3秒后出勤统计. + /// + /// 参数 + /// 次数 + [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>(scope.ServiceProvider); + List ls = new List(); + for (int i = 0; i < 50; i++) { - // 数据库操作 - var sqlSugarRepository = App.GetService>(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); + } + }); + } - /// - /// 3秒后出勤统计. - /// - /// 参数 - /// 次数 - [SpareTime("0 0/1 * * * ?", "执行Sql1", ExecuteType = SpareTimeExecuteTypes.Serial)] - public void ExecSql1(SpareTimer timer, long count) + /// + /// 3秒后出勤统计. + /// + /// 参数 + /// 次数 + [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>(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>(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"); + }); + } }