Wms自定义定时服务代码完善
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// 齐套分拣业务接口
|
||||
/// </summary>
|
||||
public interface IWmsSetSortingService
|
||||
{
|
||||
Task PackSortingByAdd(CancellationTokenSource? cts = default);
|
||||
}
|
||||
}
|
||||
@@ -18,5 +18,16 @@ namespace Tnb.WarehouseMgr.Interfaces
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<dynamic> MESKittingOutStk(List<MESKittingOutStkInput> input);
|
||||
/// <summary>
|
||||
/// 齐套出库(新增状态)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task KittingOutByAdd(CancellationTokenSource? cts = default);
|
||||
/// <summary>
|
||||
/// 齐套出库,(待配送状态)
|
||||
/// </summary>
|
||||
/// <param name="cts"></param>
|
||||
/// <returns></returns>
|
||||
Task KittingOutByIsToBeShipped(CancellationTokenSource? cts = default);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,15 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Dtos.Message;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Logging;
|
||||
using JNPF.Message.Interfaces.Message;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Tnb.Common.Extension;
|
||||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
|
||||
@@ -19,28 +24,97 @@ namespace Tnb.WarehouseMgr
|
||||
/// </summary>
|
||||
public class TimedTaskBackgroundService : BackgroundService
|
||||
{
|
||||
private ISendMessageService? _sendService;
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
_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();
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
CancellationTokenSource tokenSource = new();
|
||||
CancellationToken token = tokenSource.Token;
|
||||
var wareHouseService = App.GetRequiredService<IWareHouseService>();
|
||||
TimedTask(withOutParamAction: (cts) => Task.Run(async () =>
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
await wareHouseService.GenTaskExecute(tokenSource);
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
}, token));
|
||||
await TimedTask(cts => wareHouseService.GenTaskExecute(cts), genTaskCTS, toUserIds);
|
||||
//齐套出库
|
||||
|
||||
var kittingOutService = App.GetRequiredService<IWmskittingOutService>();
|
||||
await TimedTask(cts => kittingOutService.KittingOutByAdd(cts), kittingOutAddCts, toUserIds);
|
||||
await TimedTask(cts => kittingOutService.KittingOutByIsToBeShipped(cts), kittingOutShippedCts, toUserIds);
|
||||
//齐套分拣
|
||||
var setSortingService = App.GetRequiredService<IWmsSetSortingService>();
|
||||
await TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, toUserIds);
|
||||
|
||||
#region 老的方式
|
||||
//TimedTask(withOutParamAction: () => Task.Run(async () =>
|
||||
//{
|
||||
// while (!genTaskToken.IsCancellationRequested)
|
||||
// {
|
||||
// await wareHouseService.GenTaskExecute(genTaskCTS).Catch(ex =>
|
||||
// {
|
||||
|
||||
// });
|
||||
// await Task.Delay(1000);
|
||||
// }
|
||||
//}, genTaskToken));
|
||||
|
||||
|
||||
//CancellationTokenSource kittingOutAddCts = new();
|
||||
//CancellationToken kittingOutAddToken = kittingOutAddCts.Token;
|
||||
|
||||
|
||||
//var kittingOutService = App.GetRequiredService<IWmskittingOutService>();
|
||||
//TimedTask(withOutParamAction: () => Task.Run(async () =>
|
||||
//{
|
||||
// while (!kittingOutAddToken.IsCancellationRequested)
|
||||
// {
|
||||
// await kittingOutService.KittingOutByAdd(kittingOutAddCts);
|
||||
// await Task.Delay(1000);
|
||||
// }
|
||||
//}, kittingOutAddToken));
|
||||
|
||||
|
||||
//CancellationTokenSource kittingOutShippedCts = new();
|
||||
//CancellationToken kittingOutShippedToken = kittingOutShippedCts.Token;
|
||||
|
||||
//TimedTask(withOutParamAction: () => Task.Run(async () =>
|
||||
//{
|
||||
// while (!kittingOutShippedToken.IsCancellationRequested)
|
||||
// {
|
||||
// await kittingOutService.KittingOutByIsToBeShipped(kittingOutShippedCts);
|
||||
// await Task.Delay(1000);
|
||||
// }
|
||||
//}, kittingOutShippedToken));
|
||||
#endregion
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private Task? TimedTask(Func<CancellationTokenSource?, Task>? withOutParamAction = null, Func<TimedtaskInput, Task>? withParemAction = null, CancellationTokenSource? cts = default, TimedtaskInput? parameter = null)
|
||||
private Task? TimedTask(Func<Task>? withOutParamAction = null, Func<TimedtaskInput, Task>? withParemAction = null, TimedtaskInput? parameter = null)
|
||||
{
|
||||
return parameter != null ? withParemAction?.Invoke(parameter) : withOutParamAction?.Invoke(cts);
|
||||
return parameter != null ? withParemAction?.Invoke(parameter) : withOutParamAction?.Invoke();
|
||||
}
|
||||
|
||||
private Task TimedTask(Func<CancellationTokenSource, Task> action, CancellationTokenSource cts, List<string>? toUserIds = default)
|
||||
{
|
||||
var token = cts.Token;
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
await action(cts).Catch(ex =>
|
||||
{
|
||||
//MessageSendModel messageSendModel = new();
|
||||
//_sendService?.SendMessage();
|
||||
//messageService.SentMessage(toUserIds!, ex.Message, ex.ToString());
|
||||
});
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
}, token);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\BasicData\Tnb.BasicData.Interfaces\Tnb.BasicData.Interfaces.csproj" />
|
||||
<ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr.Entities\Tnb.EquipMgr.Entities.csproj" />
|
||||
<ProjectReference Include="..\..\message\Tnb.Message.Interfaces\Tnb.Message.Interfaces.csproj" />
|
||||
<ProjectReference Include="..\..\ProductionMgr\Tnb.ProductionMgr.Interfaces\Tnb.ProductionMgr.Interfaces.csproj" />
|
||||
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
|
||||
<ProjectReference Include="..\Tnb.WarehouseMgr.Interfaces\Tnb.WarehouseMgr.Interfaces.csproj" />
|
||||
|
||||
@@ -188,7 +188,6 @@ namespace Tnb.WarehouseMgr
|
||||
var whereExprable = Expressionable.Create<WmsCarryH, WmsCarryCode, BasLocation>()
|
||||
.And((a, b, c) => a.is_lock == 0)
|
||||
.And((a, b, c) => !string.IsNullOrEmpty(a.location_id))
|
||||
//.And((a, b, c) => a.status == (int)EnumCarryStatus.占用)
|
||||
.And((a, b, c) => c.is_type == ((int)EnumLocationType.存储库位).ToString())
|
||||
.And((a, b, c) => a.out_status == "0")
|
||||
.And((a, b, c) => c.wh_id == input.warehouse_id)
|
||||
@@ -217,19 +216,11 @@ namespace Tnb.WarehouseMgr
|
||||
[HttpPost]
|
||||
public async Task GenTaskExecute(CancellationTokenSource? cts = default)
|
||||
{
|
||||
//test
|
||||
//CancellationTokenSource curCts = new();
|
||||
|
||||
//curCts?.Cancel();
|
||||
//if (cts != null)
|
||||
//{
|
||||
// cts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, curCts.Token);
|
||||
//}
|
||||
//cts?.Cancel();
|
||||
//await Task.CompletedTask;
|
||||
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
var db = _db.CopyNew();
|
||||
try
|
||||
{
|
||||
//获取所有未下发的预任务申请
|
||||
var preTasks = await db.Queryable<WmsPretaskH>().InnerJoin<WmsCarryH>((a, b) => a.startlocation_id == b.location_id && a.carry_id == b.id)
|
||||
.InnerJoin<WmsAreaH>((a, b, c) => a.area_id == c.id)
|
||||
@@ -322,8 +313,7 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
disTasks.AddRange(items);
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
await db.Ado.BeginTranAsync();
|
||||
|
||||
//disTasks.ForEach(x => x.id = SnowflakeIdHelper.NextId());
|
||||
@@ -352,18 +342,21 @@ namespace Tnb.WarehouseMgr
|
||||
sw.Stop();
|
||||
JNPF.Logging.Log.Information($"程序运行耗时{sw.ElapsedMilliseconds}ms");
|
||||
await db.Ado.CommitTranAsync();
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
JNPF.Logging.Log.Error("生成预任务执行时出现错误",ex);
|
||||
await db.Ado.RollbackTranAsync();
|
||||
cts?.Cancel();
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cts?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 任务执行
|
||||
/// </summary>
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Tnb.WarehouseMgr
|
||||
/// 齐套分拣服务类
|
||||
/// </summary>
|
||||
[ServiceModule(BizTypeId)]
|
||||
public class WmsSetSortingService : BaseWareHouseService
|
||||
public class WmsSetSortingService : BaseWareHouseService, IWmsSetSortingService
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IWareHouseService _wareHouseService;
|
||||
@@ -50,27 +50,28 @@ namespace Tnb.WarehouseMgr
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task PackSortingByAdd(WmsCarryMat carryMat)
|
||||
public async Task PackSortingByAdd(CancellationTokenSource? cts = default)
|
||||
{
|
||||
var curDb = _db.CopyNew();
|
||||
string firstLocationId = "27010980724501", secondLocationId = "27010987857941";
|
||||
var endLocation = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == secondLocationId);
|
||||
var endLocation = await curDb.Queryable<BasLocation>().SingleAsync(it => it.id == secondLocationId);
|
||||
|
||||
var setSortings = await _db.Queryable<WmsSetsortingH>()
|
||||
var setSortings = await curDb.Queryable<WmsSetsortingH>()
|
||||
.Where(a => a.status == WmsWareHouseConst.BILLSTATUS_ADD_ID)
|
||||
.Select<WmsSetsortingH>()
|
||||
.OrderBy(a => a.seq)
|
||||
.ToListAsync();
|
||||
var items = await _db.Queryable<WmsSetsortingH>().Where(it => it.status == WmsWareHouseConst.BILLSTATUS_ON_ID).ToListAsync();
|
||||
var items = await curDb.Queryable<WmsSetsortingH>().Where(it => it.status == WmsWareHouseConst.BILLSTATUS_ON_ID).ToListAsync();
|
||||
var onFlag = items?.Count > 0;
|
||||
try
|
||||
{
|
||||
await _db.Ado.BeginTranAsync();
|
||||
await curDb.Ado.BeginTranAsync();
|
||||
|
||||
if (setSortings?.Count > 0 && !onFlag)
|
||||
{
|
||||
var singleSorting = setSortings[0];
|
||||
|
||||
var setSortingDList = await _db.Queryable<WmsSetsortingD>().Where(it => it.bill_id == singleSorting.id).ToListAsync();
|
||||
var setSortingDList = await curDb.Queryable<WmsSetsortingD>().Where(it => it.bill_id == singleSorting.id).ToListAsync();
|
||||
if (setSortingDList?.Count > 0)
|
||||
{
|
||||
List<WmsCarryMat> carryMats = new();
|
||||
@@ -81,13 +82,12 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
var OutStockStrategyInput = new OutStockStrategyQuery
|
||||
{
|
||||
carry_id = carryMat.carry_id,
|
||||
material_id = os.material_id,
|
||||
warehouse_id = os.warehouse_id,
|
||||
code_batch = os.code_batch,
|
||||
};
|
||||
var outStkCarrys = await _wareHouseService.OutStockStrategy(OutStockStrategyInput);
|
||||
var carryCodesPart = await _db.Queryable<WmsCarryH>().InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id).InnerJoin<BasLocation>((a, b, c) => a.location_id == c.id)
|
||||
var carryCodesPart = await curDb.Queryable<WmsCarryH>().InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id).InnerJoin<BasLocation>((a, b, c) => a.location_id == c.id)
|
||||
.Where((a, b) => outStkCarrys.Select(x => x.id).Contains(b.carry_id))
|
||||
.Select<WmsCarryCode>()
|
||||
.ToListAsync();
|
||||
@@ -138,19 +138,18 @@ namespace Tnb.WarehouseMgr
|
||||
return carryMat;
|
||||
})
|
||||
.ToList();
|
||||
await _db.Insertable(carryMats).ExecuteCommandAsync();
|
||||
await curDb.Insertable(carryMats).ExecuteCommandAsync();
|
||||
|
||||
carryIds = carryMats.Select(x => x.carry_id).Distinct().ToList();
|
||||
await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.全部出).ToString(), collocation_scheme_id = singleSorting.collocation_scheme_id, collocation_scheme_code = singleSorting.collocation_scheme_code }).Where(it => carryIds.Contains(it.id)).ExecuteCommandAsync();
|
||||
await curDb.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.全部出).ToString(), collocation_scheme_id = singleSorting.collocation_scheme_id, collocation_scheme_code = singleSorting.collocation_scheme_code }).Where(it => carryIds.Contains(it.id)).ExecuteCommandAsync();
|
||||
//天益项目不需要
|
||||
//await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.分拣出).ToString() }).Where(it => sortingOutIds.Contains(it.id)).ExecuteCommandAsync();
|
||||
}
|
||||
var carrys = await _db.Queryable<WmsCarryH>().Where(it => carryIds.Contains(it.id)).ToArrayAsync();
|
||||
var carrys = await curDb.Queryable<WmsCarryH>().Where(it => carryIds.Contains(it.id)).ToArrayAsync();
|
||||
if (carrys?.Length > 0)
|
||||
{
|
||||
if (setSortings?.Count > 0)
|
||||
{
|
||||
|
||||
var curCarry = carrys[^carrys.Length];
|
||||
var isMatch = await IsCarryAndLocationMatchByCarryStd(curCarry, endLocation);
|
||||
if (!isMatch) throw new AppFriendlyException("库位与载具规格不匹配", 500);
|
||||
@@ -184,7 +183,7 @@ namespace Tnb.WarehouseMgr
|
||||
pretaskCodes.AddRange(curPreTaskCodes);
|
||||
}
|
||||
await _wareHouseService.GenPreTask(preTasks, pretaskCodes);
|
||||
await _db.Updateable<WmsSetsortingH>().SetColumns(it => new WmsSetsortingH { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == singleSorting.id).ExecuteCommandAsync();
|
||||
await curDb.Updateable<WmsSetsortingH>().SetColumns(it => new WmsSetsortingH { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == singleSorting.id).ExecuteCommandAsync();
|
||||
GenPreTaskUpInput genPreTaskAfterUpInput = new();
|
||||
genPreTaskAfterUpInput.CarryIds = preTasks.Select(x => x.carry_id).ToList();
|
||||
genPreTaskAfterUpInput.LocationIds = new HashSet<string>(locIds).ToList();
|
||||
@@ -194,11 +193,13 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
}
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
await curDb.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
JNPF.Logging.Log.Error("齐套分拣执行时出现错误", ex);
|
||||
await curDb.Ado.RollbackTranAsync();
|
||||
cts?.Cancel();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,19 +59,20 @@ namespace Tnb.WarehouseMgr
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task KittingOutByAdd()
|
||||
public async Task KittingOutByAdd(CancellationTokenSource? cts = default)
|
||||
{
|
||||
var curDb = _db.CopyNew();
|
||||
try
|
||||
{
|
||||
await _db.Ado.BeginTranAsync();
|
||||
await curDb.Ado.BeginTranAsync();
|
||||
|
||||
var kittingOuts = await _db.Queryable<WmsKittingoutH>()
|
||||
var kittingOuts = await curDb.Queryable<WmsKittingoutH>()
|
||||
.Where(a => a.status == WmsWareHouseConst.BILLSTATUS_ADD_ID)
|
||||
.OrderBy(a => a.seq)
|
||||
.ToListAsync();
|
||||
// 是否有已呼叫的齐套出库任务
|
||||
// var set = true ; 如果有 把set修改为false
|
||||
var items = await _db.Queryable<WmsKittingoutH>().Where(it => it.status == WmsWareHouseConst.BILLSTATUS_CALLED_ID).ToListAsync();
|
||||
var items = await curDb.Queryable<WmsKittingoutH>().Where(it => it.status == WmsWareHouseConst.BILLSTATUS_CALLED_ID).ToListAsync();
|
||||
var isCalled = items?.Count > 0;
|
||||
|
||||
if (kittingOuts?.Count > 0)
|
||||
@@ -82,7 +83,7 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
Expression<Func<WmsCarryH, bool>> whereExp = (ko.carry_id != null) ? a => a.id == ko.carry_id : a => a.carrystd_id == WmsWareHouseConst.CARRY_LJSTD_ID;
|
||||
|
||||
var carrys = await _db.Queryable<WmsCarryH>()
|
||||
var carrys = await curDb.Queryable<WmsCarryH>()
|
||||
.InnerJoin<WmsCollocationSchemeH>((a, b) => a.collocation_scheme_id == b.id)
|
||||
.Where(whereExp.And(a => a.collocation_scheme_id == ko.collocation_scheme_id && a.is_lock == 0))
|
||||
.OrderBy((a, b) => b.seq)
|
||||
@@ -95,7 +96,7 @@ namespace Tnb.WarehouseMgr
|
||||
ko.status = WmsWareHouseConst.BILLSTATUS_TOBESHIPPED_ID;
|
||||
ko.carry_id = firstCarry?.id;
|
||||
ko.carry_code = firstCarry?.carry_code;
|
||||
await _db.Updateable(ko).UpdateColumns(it => new { it.status, it.carry_id, it.carry_code }).ExecuteCommandAsync();
|
||||
await curDb.Updateable(ko).UpdateColumns(it => new { it.status, it.carry_id, it.carry_code }).ExecuteCommandAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -110,9 +111,9 @@ namespace Tnb.WarehouseMgr
|
||||
setSortingH.org_id = _userManager.User.OrganizeId;
|
||||
setSortingH.create_id = _userManager.UserId;
|
||||
setSortingH.create_time = DateTime.Now;
|
||||
await _db.Insertable(setSortingH).ExecuteCommandAsync();
|
||||
await curDb.Insertable(setSortingH).ExecuteCommandAsync();
|
||||
|
||||
var kittingOutDetails = await _db.Queryable<WmsKittingoutD>().Where(it => it.bill_id == ko.id).ToListAsync();
|
||||
var kittingOutDetails = await curDb.Queryable<WmsKittingoutD>().Where(it => it.bill_id == ko.id).ToListAsync();
|
||||
var setSortDetails = kittingOutDetails.Adapt<List<WmsSetsortingD>>();
|
||||
setSortDetails.ForEach(x =>
|
||||
{
|
||||
@@ -123,20 +124,21 @@ namespace Tnb.WarehouseMgr
|
||||
x.create_id = _userManager.UserId;
|
||||
x.create_time = DateTime.Now;
|
||||
});
|
||||
await _db.Insertable(setSortDetails).ExecuteCommandAsync();
|
||||
await curDb.Insertable(setSortDetails).ExecuteCommandAsync();
|
||||
ko.status = WmsWareHouseConst.BILLSTATUS_CALLED_ID;
|
||||
await _db.Updateable(ko).UpdateColumns(it => it.status).ExecuteCommandAsync();
|
||||
await curDb.Updateable(ko).UpdateColumns(it => it.status).ExecuteCommandAsync();
|
||||
isCalled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
await curDb.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
JNPF.Logging.Log.Error("齐套出库,新增时出现错误", ex);
|
||||
await curDb.Ado.RollbackTranAsync();
|
||||
cts?.Cancel();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -145,11 +147,12 @@ namespace Tnb.WarehouseMgr
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task KittingOutByIsToBeShipped()
|
||||
public async Task KittingOutByIsToBeShipped(CancellationTokenSource? cts = default)
|
||||
{
|
||||
var curDb = _db.CopyNew();
|
||||
try
|
||||
{
|
||||
var kittingOuts = await _db.Queryable<WmsKittingoutH>()
|
||||
var kittingOuts = await curDb.Queryable<WmsKittingoutH>()
|
||||
.Where(a => a.status == WmsWareHouseConst.BILLSTATUS_TOBESHIPPED_ID)
|
||||
.OrderBy(a => a.seq)
|
||||
.ToListAsync();
|
||||
@@ -158,21 +161,21 @@ namespace Tnb.WarehouseMgr
|
||||
var grpList = kittingOuts.GroupBy(g => g.location_id).ToList();
|
||||
foreach (var koGrp in grpList)
|
||||
{
|
||||
var locs = await _db.Queryable<BasLocation>().Where(it => it.id == koGrp.Key && it.is_use == ((int)EnumCarryStatus.空闲).ToString() && it.is_lock == 0).ToListAsync();
|
||||
var locs = await curDb.Queryable<BasLocation>().Where(it => it.id == koGrp.Key && it.is_use == ((int)EnumCarryStatus.空闲).ToString() && it.is_lock == 0).ToListAsync();
|
||||
if (locs?.Count > 0)
|
||||
{
|
||||
var arr = koGrp.ToArray();
|
||||
var ko = arr[^arr.Length];
|
||||
var carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == ko.carry_id);
|
||||
var carry = await curDb.Queryable<WmsCarryH>().SingleAsync(it => it.id == ko.carry_id);
|
||||
if (carry != null)
|
||||
{
|
||||
|
||||
WmsPointH sPoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == carry.location_id);
|
||||
WmsPointH ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == ko.location_id);
|
||||
WmsPointH sPoint = await curDb.Queryable<WmsPointH>().FirstAsync(it => it.location_id == carry.location_id);
|
||||
WmsPointH ePoint = await curDb.Queryable<WmsPointH>().FirstAsync(it => it.location_id == ko.location_id);
|
||||
if (sPoint != null && ePoint != null)
|
||||
{
|
||||
//判断目标库位是否自动签收
|
||||
var loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == ePoint.location_id);
|
||||
var loc = await curDb.Queryable<BasLocation>().SingleAsync(it => it.id == ePoint.location_id);
|
||||
var points = await _warehouseService.PathAlgorithms(sPoint.id, ePoint.id);
|
||||
if (points.Count <= 2) throw new AppFriendlyException("该路径不存在", 500);
|
||||
if (points?.Count > 0)
|
||||
@@ -215,11 +218,11 @@ namespace Tnb.WarehouseMgr
|
||||
preTasks[^1].is_sign = 0; // 修改最后一个元素的是否签收值
|
||||
}
|
||||
await _warehouseService.GenPreTask(preTasks, null!);
|
||||
var subCarrys = await _db.Queryable<WmsCarryD>().Where(it => it.carry_id == ko.carry_id).ToListAsync();
|
||||
var subCarrys = await curDb.Queryable<WmsCarryD>().Where(it => it.carry_id == ko.carry_id).ToListAsync();
|
||||
var carryIds = subCarrys.Select(x => x.carry_id).Concat(new[] { ko.carry_id }).Distinct().ToList();
|
||||
GenPreTaskUpInput genPreTaskInput = new() { CarryIds = carryIds!, LocationIds = new List<string> { carry.location_id!, ko.location_id! } };
|
||||
await _warehouseService.GenInStockTaskHandleAfter(genPreTaskInput, it => new WmsCarryH { is_lock = 1, carry_status = ((int)EnumCarryStatus.齐套).ToString() }, it => new BasLocation { is_lock = 1 });
|
||||
await _db.Updateable<WmsKittingoutH>().SetColumns(it => it.status == WmsWareHouseConst.BILLSTATUS_ON_ID).Where(it => it.id == ko.id).ExecuteCommandAsync();
|
||||
await curDb.Updateable<WmsKittingoutH>().SetColumns(it => it.status == WmsWareHouseConst.BILLSTATUS_ON_ID).Where(it => it.id == ko.id).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,8 +238,10 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
JNPF.Logging.Log.Error("齐套出库,待配送时出现错误", ex);
|
||||
cts?.Cancel();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
41
common/Tnb.Common/Extension/TaskExtensions.cs
Normal file
41
common/Tnb.Common/Extension/TaskExtensions.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.Common.Extension
|
||||
{
|
||||
public static class TaskEx
|
||||
{
|
||||
public static Task<T> Catch<T, TError>(this Task<T> task, Func<TError, T> onError) where TError : Exception
|
||||
{
|
||||
var tcs = new TaskCompletionSource<T>(); // #A
|
||||
task.ContinueWith(innerTask =>
|
||||
{
|
||||
if (innerTask.IsFaulted && innerTask?.Exception?.InnerException is TError)
|
||||
tcs.SetResult(onError((TError)innerTask.Exception.InnerException)); // #B
|
||||
else if (innerTask.IsCanceled)
|
||||
tcs.SetCanceled(); // #B
|
||||
else if (innerTask.IsFaulted)
|
||||
tcs.SetException(innerTask?.Exception?.InnerException ?? throw new InvalidOperationException()); // #B
|
||||
else
|
||||
tcs.SetResult(innerTask.Result); // #B
|
||||
});
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
public static async Task Catch(this Task task, Action<Exception> exceptionHandler)
|
||||
{
|
||||
try
|
||||
{
|
||||
await task;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exceptionHandler(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -298,9 +298,10 @@ public class MessageService : IMessageService, IDynamicApiController, ITransient
|
||||
{
|
||||
try
|
||||
{
|
||||
_repository.AsSugarClient().Insertable(receiveEntityList).ExecuteCommand();
|
||||
//modify ly on 20230803 改为CopyNew模式,否则多线程下会报错
|
||||
_repository.AsSugarClient().CopyNew().Insertable(receiveEntityList).ExecuteCommand();
|
||||
|
||||
return _repository.AsInsertable(entity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Create()).ExecuteCommand();
|
||||
return _repository.AsSugarClient().CopyNew().Insertable(entity).IgnoreColumns(ignoreNullColumn: true).CallEntityMethod(m => m.Create()).ExecuteCommand();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user