库位编码,清空库位接口;提报入库报错回滚

This commit is contained in:
2024-11-08 14:48:26 +08:00
parent a0d2fc5b19
commit 1b4310c60e
2 changed files with 34 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Tnb.BasicData.Entities;
@@ -48,5 +49,37 @@ namespace Tnb.BasicData
List<BasLocation> items = await _db.Queryable<BasLocation>().Where(it => locIds.Contains(it.id)).ToListAsync();
return items;
}
/// <summary>
/// 根据库位编码,清空库位
/// </summary>
/// <param name="dic"></param>
/// <returns></returns>
[HttpPost]
public async Task<string> ClearLocation(Dictionary<string,string> dic)
{
try
{
var location_code = dic["code"].ToString();
if (string.IsNullOrEmpty(location_code))
throw Oops.Bah("库位编码不能为空");
var location = await _db.Queryable<BasLocation>().Where(r => r.location_code == location_code).FirstAsync();
if (location == null)
throw Oops.Bah($"库位编号{location_code}不存在");
await _db.Ado.BeginTranAsync();
//把状态改为空闲
await _db.Updateable<BasLocation>().SetColumns(r => r.is_use == "0").Where(r=>r.id==location.id).ExecuteCommandAsync();
await _db.Ado.CommitTranAsync();
}
catch(Exception e)
{
await _db.Ado.RollbackTranAsync();
throw Oops.Bah(e.Message);
}
return "成功";
}
}
}