Merge branch 'dev' of https://git.tuotong-tech.com/tnb/tnb.server into dev
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using JNPF.Common.Const;
|
||||||
|
using JNPF.Common.Security;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
||||||
namespace Tnb.WarehouseMgr.Entities.Exceptions
|
namespace Tnb.WarehouseMgr.Entities.Exceptions
|
||||||
@@ -17,28 +20,37 @@ namespace Tnb.WarehouseMgr.Entities.Exceptions
|
|||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
public string RequestURL { get; set; }
|
public string RequestURL { get; set; }
|
||||||
public string RequestMethod { get; set; }
|
public string RequestMethod { get; set; }
|
||||||
public ConnectionConfigOptions options { get; set; }
|
public ClaimsPrincipal UserIdentity { get; set; }
|
||||||
|
public ConnectionConfigOptions? options { get; set; }
|
||||||
|
|
||||||
public TimedTaskException(string message,
|
public TimedTaskException(string message,
|
||||||
string method,
|
|
||||||
string userId,
|
|
||||||
string userName,
|
|
||||||
string requestUrl,
|
string requestUrl,
|
||||||
string requestMethod,
|
string requestMethod,
|
||||||
ConnectionConfigOptions options,
|
ClaimsPrincipal userIdentity,
|
||||||
Exception innerException) : base(message, innerException)
|
Exception innerException) : base(message, innerException)
|
||||||
{
|
{
|
||||||
this.Method = method;
|
this.UserId = userIdentity.FindFirst(ClaimConst.CLAINMUSERID)?.Value ?? string.Empty;
|
||||||
this.UserId = userId;
|
this.UserName = userIdentity.FindFirst(ClaimConst.CLAINMREALNAME)?.Value ?? string.Empty;
|
||||||
this.UserName = userName;
|
this.options = userIdentity.FindFirst(ClaimConst.CONNECTIONCONFIG)?.ToObject<ConnectionConfigOptions>() ?? null;
|
||||||
this.RequestURL = requestUrl;
|
this.RequestURL = requestUrl;
|
||||||
this.RequestMethod = requestMethod;
|
this.RequestMethod = requestMethod;
|
||||||
this.options = options;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TimedTaskExceptionExtensions
|
public static class TimedTaskExceptionExtensions
|
||||||
{
|
{
|
||||||
|
public static TimedTaskException ToTimedTaskException(this Exception exception, ErrorInfo exceptionInfo)
|
||||||
|
{
|
||||||
|
TimedTaskException ex = new(exception.Message, exceptionInfo.RequestURL, exceptionInfo.RequestMethod, exceptionInfo.userIdentity, exception);
|
||||||
|
return ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ErrorInfo
|
||||||
|
{
|
||||||
|
public string RequestURL { get; set; }
|
||||||
|
public string RequestMethod { get; set; }
|
||||||
|
public ClaimsPrincipal userIdentity { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ using JNPF.FriendlyException;
|
|||||||
using JNPF.Logging;
|
using JNPF.Logging;
|
||||||
using JNPF.Message.Interfaces.Message;
|
using JNPF.Message.Interfaces.Message;
|
||||||
using JNPF.Systems.Entitys.System;
|
using JNPF.Systems.Entitys.System;
|
||||||
|
using Mapster;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
@@ -35,7 +36,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
|
|
||||||
protected override Task ExecuteAsync(CancellationToken stoppingToken) => Task.Run(() =>
|
protected override Task ExecuteAsync(CancellationToken stoppingToken) => Task.Run(() =>
|
||||||
{
|
{
|
||||||
//_eventPublisher = App.GetRequiredService<IEventPublisher>();
|
_eventPublisher = App.GetRequiredService<IEventPublisher>();
|
||||||
List<string> toUserIds = new List<string>() { "25398501929509" };
|
List<string> toUserIds = new List<string>() { "25398501929509" };
|
||||||
//生成任务执行
|
//生成任务执行
|
||||||
CancellationTokenSource genTaskCTS = new();
|
CancellationTokenSource genTaskCTS = new();
|
||||||
@@ -64,19 +65,21 @@ namespace Tnb.WarehouseMgr
|
|||||||
{
|
{
|
||||||
await action(cts).Catch(async ex =>
|
await action(cts).Catch(async ex =>
|
||||||
{
|
{
|
||||||
if (ex is TimedTaskException timedTaskEx)
|
if (ex is TimedTaskException timedTaskEx and not null)
|
||||||
{
|
{
|
||||||
//await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", options, new SysLogEntity
|
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", timedTaskEx.options!, new SysLogEntity
|
||||||
//{
|
{
|
||||||
// Id = SnowflakeIdHelper.NextId(),
|
Id = SnowflakeIdHelper.NextId(),
|
||||||
// Category = 4,
|
Category = 4,
|
||||||
// IPAddress = NetHelper.Ip,
|
UserId = timedTaskEx.UserId,
|
||||||
// RequestURL = httpRequest.Path,
|
UserName = timedTaskEx.UserName,
|
||||||
// RequestMethod = httpRequest.Method,
|
IPAddress = NetHelper.Ip,
|
||||||
// Json = timedTaskEx + "\n" + context.Exception.StackTrace + "\n" + context.Exception.TargetSite.GetParameters().ToString(),
|
RequestURL = timedTaskEx.RequestURL,
|
||||||
// PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
|
RequestMethod = timedTaskEx.RequestMethod,
|
||||||
// CreatorTime = DateTime.Now
|
Json = timedTaskEx + "\n" + timedTaskEx.InnerException?.StackTrace + "\n" + timedTaskEx?.TargetSite?.GetParameters().ToString(),
|
||||||
//}));
|
//PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
|
||||||
|
CreatorTime = DateTime.Now
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
|
|||||||
@@ -9,13 +9,16 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Aliyun.Credentials.Http;
|
||||||
using Aop.Api.Domain;
|
using Aop.Api.Domain;
|
||||||
using Aspose.Cells.Drawing;
|
using Aspose.Cells.Drawing;
|
||||||
using JNPF;
|
using JNPF;
|
||||||
|
using JNPF.Common.Const;
|
||||||
using JNPF.Common.Contracts;
|
using JNPF.Common.Contracts;
|
||||||
using JNPF.Common.Core.Manager;
|
using JNPF.Common.Core.Manager;
|
||||||
using JNPF.Common.Enums;
|
using JNPF.Common.Enums;
|
||||||
using JNPF.Common.Extension;
|
using JNPF.Common.Extension;
|
||||||
|
using JNPF.Common.Manager;
|
||||||
using JNPF.Common.Security;
|
using JNPF.Common.Security;
|
||||||
using JNPF.DependencyInjection;
|
using JNPF.DependencyInjection;
|
||||||
using JNPF.DynamicApiController;
|
using JNPF.DynamicApiController;
|
||||||
@@ -59,12 +62,15 @@ namespace Tnb.WarehouseMgr
|
|||||||
private readonly IDictionaryDataService _dictionaryDataService;
|
private readonly IDictionaryDataService _dictionaryDataService;
|
||||||
private readonly IBillRullService _billRullService;
|
private readonly IBillRullService _billRullService;
|
||||||
private readonly IUserManager _userManager;
|
private readonly IUserManager _userManager;
|
||||||
public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService, IBillRullService billRullService, IUserManager userManager)
|
private readonly ICacheManager _cacheManager;
|
||||||
|
|
||||||
|
public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService, IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager)
|
||||||
{
|
{
|
||||||
_db = repository.AsSugarClient();
|
_db = repository.AsSugarClient();
|
||||||
_dictionaryDataService = dictionaryDataService;
|
_dictionaryDataService = dictionaryDataService;
|
||||||
_billRullService = billRullService;
|
_billRullService = billRullService;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
|
_cacheManager = cacheManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -221,6 +227,12 @@ namespace Tnb.WarehouseMgr
|
|||||||
{
|
{
|
||||||
Stopwatch sw = Stopwatch.StartNew();
|
Stopwatch sw = Stopwatch.StartNew();
|
||||||
CancellationTokenSource agvCts = new();
|
CancellationTokenSource agvCts = new();
|
||||||
|
|
||||||
|
//获取用户登录令牌
|
||||||
|
var aToken = await _cacheManager.GetAsync("AsscessToken");
|
||||||
|
if (aToken.IsNullOrWhiteSpace()) return;
|
||||||
|
var curUser = await GetUserIdentity(aToken);
|
||||||
|
|
||||||
var db = _db.CopyNew();
|
var db = _db.CopyNew();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -366,9 +378,18 @@ namespace Tnb.WarehouseMgr
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error("生成预任务执行时出现错误", ex);
|
Log.Error("生成预任务执行时出现错误", ex);
|
||||||
|
var opts = curUser.FindFirst(ClaimConst.CONNECTIONCONFIG)?.Value;
|
||||||
|
|
||||||
|
ErrorInfo ei = new()
|
||||||
|
{
|
||||||
|
RequestURL = App.HttpContext?.Request?.Path,
|
||||||
|
RequestMethod = App.HttpContext?.Request?.Method,
|
||||||
|
userIdentity = curUser,
|
||||||
|
};
|
||||||
|
var timedTaskEx = ex.ToTimedTaskException(ei);
|
||||||
await db.Ado.RollbackTranAsync();
|
await db.Ado.RollbackTranAsync();
|
||||||
cts?.Cancel();
|
cts?.Cancel();
|
||||||
throw;
|
throw timedTaskEx;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user