将日志分表存储 任务表 接口表 操作表

This commit is contained in:
zhougf committed 2024-03-15 14:52:21 +08:00
1 parent 405f7f0872
commit 6d4b220933
9 files changed
+149 -18

No files matched your search

+1 -1
View File
@@ -50,7 +50,7 @@ namespace HHWMS.Web
num = Convert.ToInt32(num) num = Convert.ToInt32(num)
}); });
} }
return Ok(); return ApiResult();
//var inv = _unitwork.Find<Inventory>(x => x.ID > 0).FirstOrDefault(); //var inv = _unitwork.Find<Inventory>(x => x.ID > 0).FirstOrDefault();
//var bizData = new InStore //var bizData = new InStore
//{ //{
@@ -19,15 +19,6 @@ namespace HHWMS.Web
try try
{ {
var _unitwork = new UnitWork(Wtm); var _unitwork = new UnitWork(Wtm);
if (_unitwork.IsExit<ReceiptHeader>(x => x.FirstStatus == ReceiptStatusEnum.收完))
{
_unitwork.BatchDelete<ReceiptHeader>(x => x.FirstStatus == ReceiptStatusEnum.收完);
}
if (_unitwork.IsExit<ShipmentHeader>(x => x.FirstStatus == ShipStatusEnum.拣货完成))
{
_unitwork.BatchDelete<ShipmentHeader>(x => x.FirstStatus == ShipStatusEnum.拣货完成);
}
Wtm.DoLog("清理过期单据", ActionLogTypesEnum.Job, "TestJob"); Wtm.DoLog("清理过期单据", ActionLogTypesEnum.Job, "TestJob");
#region 更新时间 #region 更新时间
@@ -44,7 +35,9 @@ namespace HHWMS.Web
} }
#endregion #endregion
} }
catch { } catch(Exception ex) {
Wtm.DoLog("清理过期单据", ActionLogTypesEnum.Job, "TestJob", request:"error", result:ex.Message);
}
return Task.CompletedTask; return Task.CompletedTask;
} }
} }
+1 -1
View File
@@ -16,7 +16,7 @@
}, },
"WTM": { "WTM": {
"LogLevel": { "LogLevel": {
"Default": "Debug" "Default": "Information"
} }
} }
}, },
+2
View File
@@ -39,6 +39,8 @@ namespace WalkingTec.Mvvm.Core
public DbSet<FrameworkUserRole> BaseFrameworkUserRoles { get; set; } public DbSet<FrameworkUserRole> BaseFrameworkUserRoles { get; set; }
public DbSet<FrameworkUserGroup> BaseFrameworkUserGroups { get; set; } public DbSet<FrameworkUserGroup> BaseFrameworkUserGroups { get; set; }
public DbSet<ActionLog> BaseActionLogs { get; set; } public DbSet<ActionLog> BaseActionLogs { get; set; }
public DbSet<JobLog> JobLogs { get; set; }
public DbSet<InterfaceLog> InterfaceLogs { get; set; }
public DbSet<FrameworkTenant> FrameworkTenants { get; set; } public DbSet<FrameworkTenant> FrameworkTenants { get; set; }
/// <summary> /// <summary>
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WalkingTec.Mvvm.Core
{
/// <summary>
/// ActionLog
/// </summary>
[Table("InterfaceLogs")]
public class InterfaceLog : BasePoco,ITenant
{
[Display(Name = "_Admin.Module")]
[StringLength(255, ErrorMessage = "Validate.{0}stringmax{1}")]
public string ModuleName { get; set; }
[Display(Name = "_Admin.Action")]
[StringLength(255, ErrorMessage = "Validate.{0}stringmax{1}")]
public string ActionName { get; set; }
[Display(Name = "_Admin.Account")]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string ITCode { get; set; }
[Display(Name = "Url")]
[StringLength(250, ErrorMessage = "Validate.{0}stringmax{1}")]
public string ActionUrl { get; set; }
[Display(Name = "_Admin.ActionTime")]
public DateTime ActionTime { get; set; }
[Display(Name = "_Admin.Duration")]
public double Duration { get; set; }
[Display(Name = "_Admin.Remark")]
public string Remark { get; set; }
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
[Display(Name = "IP")]
public string IP { get; set; }
[Display(Name = "_Admin.LogType")]
public ActionLogTypesEnum LogType { get; set; }
[Display(Name = "_Admin.Tenant")]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string TenantCode { get; set; }
[Display(Name = "_Admin.Request")]
public string Request { get; set; }
[Display(Name = "_Admin.Response")]
public string Result { get; set; }
}
}
+58
View File
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace WalkingTec.Mvvm.Core
{
/// <summary>
/// JobLog
/// </summary>
[Table("JobLogs")]
public class JobLog : BasePoco,ITenant
{
[Display(Name = "_Admin.Module")]
[StringLength(255, ErrorMessage = "Validate.{0}stringmax{1}")]
public string ModuleName { get; set; }
[Display(Name = "_Admin.Action")]
[StringLength(255, ErrorMessage = "Validate.{0}stringmax{1}")]
public string ActionName { get; set; }
[Display(Name = "_Admin.Account")]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string ITCode { get; set; }
[Display(Name = "Url")]
[StringLength(250, ErrorMessage = "Validate.{0}stringmax{1}")]
public string ActionUrl { get; set; }
[Display(Name = "_Admin.ActionTime")]
public DateTime ActionTime { get; set; }
[Display(Name = "_Admin.Duration")]
public double Duration { get; set; }
[Display(Name = "_Admin.Remark")]
public string Remark { get; set; }
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
[Display(Name = "IP")]
public string IP { get; set; }
[Display(Name = "_Admin.LogType")]
public ActionLogTypesEnum LogType { get; set; }
[Display(Name = "_Admin.Tenant")]
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
public string TenantCode { get; set; }
[Display(Name = "_Admin.Request")]
public string Request { get; set; }
[Display(Name = "_Admin.Response")]
public string Result { get; set; }
}
}
+21 -2
View File
@@ -8,6 +8,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.Json;
namespace WalkingTec.Mvvm.Core namespace WalkingTec.Mvvm.Core
{ {
@@ -60,13 +61,14 @@ namespace WalkingTec.Mvvm.Core
{ {
return false; return false;
} }
var level = logConfig.Rules.Where(x => var t = logConfig.Rules.Where(x =>
x.ProviderName == "WTM" && x.ProviderName == "WTM" &&
( (
(x.CategoryName != null && categoryName.ToLower().StartsWith(x.CategoryName.ToLower())) || (x.CategoryName != null && categoryName.ToLower().StartsWith(x.CategoryName.ToLower())) ||
categoryName == "WalkingTec.Mvvm.Core.ActionLog" categoryName == "WalkingTec.Mvvm.Core.ActionLog"
) )
) );
var level = t
.Select(x => x.LogLevel).FirstOrDefault(); .Select(x => x.LogLevel).FirstOrDefault();
if (level == null) if (level == null)
{ {
@@ -138,7 +140,24 @@ namespace WalkingTec.Mvvm.Core
try try
{ {
log.TenantCode = wtm.LoginUserInfo?.CurrentTenant; log.TenantCode = wtm.LoginUserInfo?.CurrentTenant;
if (log.ActionUrl.Contains("api"))
{
// 插入接口日志表
var str = JsonSerializer.Serialize(log, typeof(ActionLog));
var apilog = JsonSerializer.Deserialize<InterfaceLog>(str);
dc.AddEntity<InterfaceLog>(apilog);
}
else if(log.LogType == ActionLogTypesEnum.Job)
{
// 插入任务日志表
var str = JsonSerializer.Serialize(log, typeof(ActionLog));
var joblog = JsonSerializer.Deserialize<JobLog>(str);
dc.AddEntity<JobLog>(joblog);
}
else
{
dc.AddEntity<ActionLog>(log); dc.AddEntity<ActionLog>(log);
}
dc.SaveChanges(); dc.SaveChanges();
} }
catch { } catch { }
@@ -12,11 +12,11 @@ namespace $namespace$
[ActionDescription("$des$")] [ActionDescription("$des$")]
public partial class $modelname$Controller : BaseController public partial class $modelname$Controller : BaseController
{ {
private readonly IUnitWork _unitwork; private readonly IUnitWork _unitWork;
public $modelname$Controller(IUnitWork unitwork) public $modelname$Controller(IUnitWork unitWork)
{ {
_unitwork = unitwork; _unitWork = unitWork;
} }
#region Search #region Search
+1 -1
View File
@@ -1,6 +1,6 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<VersionPrefix>6.3.7</VersionPrefix> <VersionPrefix>6.3.9</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">