还原代码解决系统崩溃问题
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
public class ConditionalBackgroundService : IHostedService
|
||||
{
|
||||
private readonly IHostedService _backgroundService;
|
||||
//private readonly Func<bool> _condition;
|
||||
|
||||
public ConditionalBackgroundService(IHostedService backgroundService)
|
||||
{
|
||||
_backgroundService = backgroundService;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await _backgroundService.StartAsync(cancellationToken);
|
||||
}
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await _backgroundService.StopAsync(cancellationToken);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,32 +25,33 @@ namespace Tnb.WarehouseMgr
|
||||
public class TimedTaskBackgroundService : BackgroundService
|
||||
{
|
||||
private ISendMessageService? _sendService;
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
_sendService = App.GetRequiredService<ISendMessageService>();
|
||||
var userManager = App.GetRequiredService<IUserManager>();
|
||||
List<string> toUserIds = new List<string>() { "25398501929509" };
|
||||
//生成任务执行
|
||||
CancellationTokenSource genTaskCTS = new();
|
||||
CancellationTokenSource kittingOutAddCts = new();
|
||||
CancellationTokenSource kittingOutShippedCts = new();
|
||||
CancellationTokenSource setSortingCts = new();
|
||||
return Task.Run(() =>
|
||||
{
|
||||
//_sendService = App.GetRequiredService<ISendMessageService>();
|
||||
List<string> toUserIds = new List<string>() { "25398501929509" };
|
||||
//生成任务执行
|
||||
CancellationTokenSource genTaskCTS = new();
|
||||
CancellationTokenSource kittingOutAddCts = new();
|
||||
CancellationTokenSource kittingOutShippedCts = new();
|
||||
CancellationTokenSource setSortingCts = new();
|
||||
|
||||
var wareHouseService = App.GetRequiredService<IWareHouseService>();
|
||||
TimedTask(cts => wareHouseService.GenTaskExecute(cts), genTaskCTS, toUserIds);
|
||||
//齐套出库
|
||||
var wareHouseService = App.GetRequiredService<IWareHouseService>();
|
||||
TimedTask(cts => wareHouseService.GenTaskExecute(cts), genTaskCTS, toUserIds);
|
||||
//齐套出库
|
||||
|
||||
var kittingOutService = App.GetRequiredService<IWmskittingOutService>();
|
||||
TimedTask(cts => kittingOutService.KittingOutByAdd(cts), kittingOutAddCts, toUserIds);
|
||||
TimedTask(cts => kittingOutService.KittingOutByIsToBeShipped(cts), kittingOutShippedCts, toUserIds);
|
||||
//齐套分拣
|
||||
var setSortingService = App.GetRequiredService<IWmsSetSortingService>();
|
||||
TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, toUserIds);
|
||||
});
|
||||
var kittingOutService = App.GetRequiredService<IWmskittingOutService>();
|
||||
TimedTask(cts => kittingOutService.KittingOutByAdd(cts), kittingOutAddCts, toUserIds);
|
||||
TimedTask(cts => kittingOutService.KittingOutByIsToBeShipped(cts), kittingOutShippedCts, toUserIds);
|
||||
//齐套分拣
|
||||
var setSortingService = App.GetRequiredService<IWmsSetSortingService>();
|
||||
TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, toUserIds);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private Task TimedTask(Func<CancellationTokenSource, Task> action, CancellationTokenSource cts, List<string>? toUserIds = default)
|
||||
{
|
||||
var token = cts.Token;
|
||||
@@ -60,9 +61,7 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
await action(cts).Catch(ex =>
|
||||
{
|
||||
//MessageSendModel messageSendModel = new();
|
||||
//_sendService?.SendMessage();
|
||||
//messageService.SentMessage(toUserIds!, ex.Message, ex.ToString());
|
||||
//notify operator
|
||||
});
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
@@ -283,7 +283,6 @@ namespace Tnb.WarehouseMgr
|
||||
start = end;
|
||||
end = Math.Min((end + moveNum), arrary.Length);
|
||||
}
|
||||
|
||||
foreach (var arr in arrList)
|
||||
{
|
||||
for (int j = 1, len = arr.Length; j <= len; j++)
|
||||
|
||||
@@ -99,8 +99,8 @@ namespace Tnb.WarehouseMgr
|
||||
visualDevModelCrInput.data[nameof(WmsKittingInstock.create_time)] = DateTime.Now;
|
||||
visualDevModelCrInput.data[nameof(WmsKittingInstock.location_id)] = carry!.location_id!;
|
||||
visualDevModelCrInput.data[nameof(WmsKittingInstock.bill_code)] = _billRullService.GetBillNumber("WmsKittingInStk").GetAwaiter().GetResult();
|
||||
visualDevModelCrInput.data[nameof(WmsKittingInstock.source_id)] = kittingout.source_id;
|
||||
visualDevModelCrInput.data[nameof(WmsKittingInstock.source_code)] = kittingout.source_code;
|
||||
visualDevModelCrInput.data[nameof(WmsKittingInstock.source_id)] = kittingout.id;
|
||||
visualDevModelCrInput.data[nameof(WmsKittingInstock.source_code)] = kittingout.bill_code;
|
||||
|
||||
|
||||
var location = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == kittingout.location_id);
|
||||
|
||||
@@ -155,6 +155,8 @@ namespace Tnb.WarehouseMgr
|
||||
[HttpPost]
|
||||
public async Task KittingOutByIsToBeShipped(CancellationTokenSource? cts = default)
|
||||
{
|
||||
if (_userManager.User == null) return;
|
||||
|
||||
var curDb = _db.CopyNew();
|
||||
try
|
||||
{
|
||||
|
||||
@@ -302,7 +302,7 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
|
||||
// 非多租户模式启动自启任务
|
||||
if (!KeyVariable.MultiTenancy)
|
||||
{
|
||||
_repository.AsQueryable().Where(x => x.DeleteMark == null && x.EnabledMark == 1).ToList().ForEach(x=>AddTimerJob(x,false));//modifyby zhoukeda 20230607
|
||||
_repository.AsSugarClient().CopyNew().Queryable<TimeTaskEntity>().Where(x => x.DeleteMark == null && x.EnabledMark == 1).ToList().ForEach(x=>AddTimerJob(x,false));//modifyby zhoukeda 20230607
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user