From c2badd9a449e8780cac6a41912e043f1db3d25c3 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 21 Jun 2023 09:12:12 +0800 Subject: [PATCH] 1 --- .../Tnb.WarehouseMgr/WmsPDAInStockService.cs | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInStockService.cs index 06f7cf80..49ac21a0 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInStockService.cs @@ -261,36 +261,48 @@ namespace Tnb.WarehouseMgr { if (input == null) throw new ArgumentNullException("input"); //更具distaskCode的barcode 更新 instockcode 的 is_end 为 1 - if (input.distaskCodes?.Count > 0) + try { - var barCodes = input.distaskCodes.Select(x => x.barcode); - await _db.Updateable().SetColumns(it => new WmsInstockCode { is_end = 1 }).Where(it => barCodes.Contains(it.barcode)).ExecuteCommandAsync(); - var instockCodes = await _db.Queryable().Where(it => barCodes.Contains(it.barcode)).Select(it => new - { - id = it.bill_d_id, - barcode_qty = it.barcode_qty, - }).ToListAsync(); - var dic = instockCodes.GroupBy(g => g.id).ToDictionary(x => x.Key, x => x.Select(d => d.barcode_qty).ToList()); - var ids = instockCodes.Select(it => it.id).ToList(); - var instockDetails = await _db.Queryable().Where(it => ids.Contains(it.id)).ToListAsync(); + await _db.Ado.BeginTranAsync(); - foreach (var item in instockDetails) + if (input.distaskCodes?.Count > 0) { - if (dic.ContainsKey(item.id)) + var barCodes = input.distaskCodes.Select(x => x.barcode); + await _db.Updateable().SetColumns(it => new WmsInstockCode { is_end = 1 }).Where(it => barCodes.Contains(it.barcode)).ExecuteCommandAsync(); + var instockCodes = await _db.Queryable().Where(it => barCodes.Contains(it.barcode)).Select(it => new { - item.qty += dic[item.id].Sum(x => x); - if (item.qty >= item.pr_qty) + id = it.bill_d_id, + barcode_qty = it.barcode_qty, + }).ToListAsync(); + var dic = instockCodes.GroupBy(g => g.id).ToDictionary(x => x.Key, x => x.Select(d => d.barcode_qty).ToList()); + var ids = instockCodes.Select(it => it.id).ToList(); + var instockDetails = await _db.Queryable().Where(it => ids.Contains(it.id)).ToListAsync(); + + foreach (var item in instockDetails) + { + if (dic.ContainsKey(item.id)) { - item.line_status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID; + item.qty += dic[item.id].Sum(x => x); + if (item.qty >= item.pr_qty) + { + item.line_status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID; + } } } + await _db.Updateable(instockDetails).ExecuteCommandAsync(); + if (instockDetails.All(x => x.line_status == WmsWareHouseConst.BILLSTATUS_COMPLETE_ID)) + { + await _db.Updateable().SetColumns(it => new WmsInstockH { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID }).Where(it => it.id == input.requireId).ExecuteCommandAsync(); + //如果是自动单据,需要回更上层系统 + } } - await _db.Updateable(instockDetails).ExecuteCommandAsync(); - if (instockDetails.All(x => x.line_status == WmsWareHouseConst.BILLSTATUS_COMPLETE_ID)) - { - await _db.Updateable().SetColumns(it => new WmsInstockH { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID }).Where(it => it.id == input.requireId).ExecuteCommandAsync(); - //如果是自动单据,需要回更上层系统 - } + + await _db.Ado.CommitTranAsync(); + } + catch (Exception) + { + await _db.Ado.RollbackTranAsync(); + throw; } } }