Wms自定义定时服务代码完善
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user