This commit is contained in:
qianjiawei
2023-12-20 16:58:40 +08:00
parent c45c3542a3
commit e8d9f9af81
5 changed files with 97 additions and 4 deletions

View File

@@ -148,5 +148,73 @@ namespace Tnb.WarehouseMgr
{
return await UpdateChackStatus<WmsInstockH>(input);
}
[HttpPost]
public async Task BarCodePrint(BarCodeInput input)
{
if (input == null)
{
throw new AppFriendlyException(nameof(input), 500);
}
List<string> barcodes = new();
try
{
await _db.Ado.BeginTranAsync();
if (_db.Queryable<WmsTempCode>().Where(it => input.BillId == it.require_id).Any())
{
throw new AppFriendlyException("条码已生成", 500);
};
WmsPurchaseD WmsPurchaseD = await _db.Queryable<WmsPurchaseD>().Where(it => input.BillId == it.id).FirstAsync();
List<WmsTempCode> wmsTempCodes = new();
decimal? minPacking = (await _db.Queryable<BasMaterial>().FirstAsync(it => it.id == WmsPurchaseD.material_id))?.minpacking;
int codeNum = 0;
if (minPacking.HasValue && minPacking.Value > 0)
{
int mod = (int)(WmsPurchaseD.purchase_arriveqty % minPacking.Value);
codeNum = (int)(mod > 0 ? (WmsPurchaseD.purchase_arriveqty / minPacking.Value) + 1 : WmsPurchaseD.purchase_arriveqty / minPacking.Value);
for (int j = 0; j < codeNum; j++)
{
int index = j + 1;
string code = $"{WmsPurchaseD.material_code}{WmsPurchaseD.code_batch}{index.ToString().PadLeft(4, '0')}";
WmsTempCode barCode = new()
{
material_id = WmsPurchaseD.material_id,
material_code = WmsPurchaseD.material_code,
barcode = code,
code_batch = WmsPurchaseD.code_batch,
material_specification = WmsPurchaseD.material_specification,
container_no = WmsPurchaseD.container_no,
codeqty = minPacking,
unit_id = WmsPurchaseD.unit_id,
is_lock = 0,
is_end = 0,
require_id = WmsPurchaseD.id,
require_code = WmsPurchaseD.id,
create_id = _userManager.UserId,
create_time = DateTime.Now
};
if (index == codeNum)
barCode.codeqty = mod == 0 ? minPacking : mod;
wmsTempCodes.Add(barCode);
}
await _db.Insertable(wmsTempCodes).ExecuteCommandAsync();
}
await _db.Ado.CommitTranAsync();
barcodes.AddRange(wmsTempCodes.Select(p => p.barcode).ToList());
if (barcodes?.Count > 0)
{
base.BarCodePrint(barcodes, 1);
}
}
catch (Exception)
{
await _db.Ado.RollbackTranAsync();
throw;
}
}
}
}