This commit is contained in:
alex
2023-06-21 09:12:12 +08:00
parent cbcdd70877
commit c2badd9a44

View File

@@ -261,36 +261,48 @@ namespace Tnb.WarehouseMgr
{ {
if (input == null) throw new ArgumentNullException("input"); if (input == null) throw new ArgumentNullException("input");
//更具distaskCode的barcode 更新 instockcode 的 is_end 为 1 //更具distaskCode的barcode 更新 instockcode 的 is_end 为 1
if (input.distaskCodes?.Count > 0) try
{ {
var barCodes = input.distaskCodes.Select(x => x.barcode); await _db.Ado.BeginTranAsync();
await _db.Updateable<WmsInstockCode>().SetColumns(it => new WmsInstockCode { is_end = 1 }).Where(it => barCodes.Contains(it.barcode)).ExecuteCommandAsync();
var instockCodes = await _db.Queryable<WmsInstockCode>().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<WmsInstockD>().Where(it => ids.Contains(it.id)).ToListAsync();
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<WmsInstockCode>().SetColumns(it => new WmsInstockCode { is_end = 1 }).Where(it => barCodes.Contains(it.barcode)).ExecuteCommandAsync();
var instockCodes = await _db.Queryable<WmsInstockCode>().Where(it => barCodes.Contains(it.barcode)).Select(it => new
{ {
item.qty += dic[item.id].Sum(x => x); id = it.bill_d_id,
if (item.qty >= item.pr_qty) 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<WmsInstockD>().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<WmsInstockH>().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.Ado.CommitTranAsync();
{ }
await _db.Updateable<WmsInstockH>().SetColumns(it => new WmsInstockH { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID }).Where(it => it.id == input.requireId).ExecuteCommandAsync(); catch (Exception)
//如果是自动单据,需要回更上层系统 {
} await _db.Ado.RollbackTranAsync();
throw;
} }
} }
} }