This commit is contained in:
2024-04-11 17:31:32 +08:00
parent f6eaa2f481
commit 4fbc6c0267
200 changed files with 1252 additions and 1860 deletions

View File

@@ -1,6 +1,8 @@
using JNPF.Common.Configuration;
using System.Text.RegularExpressions;
using JNPF.Common.Configuration;
using JNPF.DependencyInjection;
using JNPF.EventBus;
using JNPF.VisualDev.Entitys;
using SqlSugar;
namespace JNPF.EventHandler;
@@ -42,7 +44,18 @@ public class LogEventSubscriber : IEventSubscriber, ISingleton
_sqlSugarClient.ChangeDatabase(log.ConnectionConfig.ConfigId);
}
await _sqlSugarClient.CopyNew().Insertable(log.Entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
string pattern = @"^[0-9]*$";
var db = _sqlSugarClient.CopyNew();
if (!string.IsNullOrEmpty(log.Entity.ModuleId) && new Regex(pattern).IsMatch(log.Entity.ModuleId))
{
var module = await db.Queryable<VisualDevEntity>().Where(x => x.Id == log.Entity.ModuleId).FirstAsync();
if (module != null)
{
log.Entity.ModuleName = module.FullName;
}
}
await db.Insertable(log.Entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync();
}
/// <summary>

View File

@@ -107,7 +107,77 @@ public class RequestActionFilter : IAsyncActionFilter
ModuleName = module.ModuleName,
Json = string.Format("{0}应用【{1}】【{2}】", module.Action, args, result?.ToJsonString())
}));
}else if (actionName == "JNPF.VisualDev.VisualDevModelDataService.Create")
{
var args = context.ActionArguments.ToJsonString();
var result = (actionContext.Result as JsonResult)?.Value;
string moduleId = httpRequest.Path.Value.Substring(httpRequest.Path.Value.LastIndexOf("/")+1);
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateOpLog", options, new SysLogEntity
{
Id = SnowflakeIdHelper.NextId(),
UserId = userId,
UserName = userName,
Category = 3,
IPAddress = NetHelper.Ip,
RequestURL = httpRequest.Path,
RequestDuration = (int)sw.ElapsedMilliseconds,
RequestMethod = "新增",
PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
CreatorTime = DateTime.Now,
ModuleName = moduleId,
ModuleId = moduleId,
Json = string.Format("{0}应用【{1}】【{2}】", "新增", args, result?.ToJsonString())
}));
}else if (actionName == "JNPF.VisualDev.VisualDevModelDataService.Update")
{
var args = context.ActionArguments.ToJsonString();
var result = (actionContext.Result as JsonResult)?.Value;
string[] arr = httpRequest.Path.Value.Split("/");
string moduleId = arr[arr.Length - 2];
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateOpLog", options, new SysLogEntity
{
Id = SnowflakeIdHelper.NextId(),
UserId = userId,
UserName = userName,
Category = 3,
IPAddress = NetHelper.Ip,
RequestURL = httpRequest.Path,
RequestDuration = (int)sw.ElapsedMilliseconds,
RequestMethod = "编辑",
PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
CreatorTime = DateTime.Now,
ModuleName = moduleId,
ModuleId = moduleId,
Json = string.Format("{0}应用【{1}】【{2}】", "编辑", args, result?.ToJsonString())
}));
}else if (actionName == "JNPF.VisualDev.VisualDevModelDataService.Delete")
{
var args = context.ActionArguments.ToJsonString();
var result = (actionContext.Result as JsonResult)?.Value;
string[] arr = httpRequest.Path.Value.Split("/");
string moduleId = arr[arr.Length - 2];
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateOpLog", options, new SysLogEntity
{
Id = SnowflakeIdHelper.NextId(),
UserId = userId,
UserName = userName,
Category = 3,
IPAddress = NetHelper.Ip,
RequestURL = httpRequest.Path,
RequestDuration = (int)sw.ElapsedMilliseconds,
RequestMethod = "删除",
PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
CreatorTime = DateTime.Now,
ModuleName = moduleId,
ModuleId = moduleId,
Json = string.Format("{0}应用【{1}】【{2}】", "删除", args, result?.ToJsonString())
}));
}
}
}
}