using System; using System.Threading.Tasks; using Rhea.Common; using Tiger.Model; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Autofac; using Tiger.IBusiness; namespace Tiger.Api.Controllers.WMS { public partial class WMSController : ControllerBase { [HttpPost] [Route("api/[controller]/LTF/GetTransaction")] public IActionResult LTF_GetTransaction([FromBody] ApiAction action) { ApiAction response; ILocationTransfer trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ILocationTransfer; } else { trans = AutoFacContainer.Instance.Resolve().Init(action.ID, action.Data?.USER_CODE, Request.Host.Value); iBiz.WMS.Context.NewTransaction(HttpContext, trans); } response = action.GetResponse(trans); } catch (System.Exception ex) { response = action.GetResponse().CatchExceptionWithLog(ex); } trans?.AddHistory(Request, action); return Ok(response); } /// /// CloseTransaction(ApiAction) /// 关闭事务 /// /// /// [HttpPost] [Route("api/[controller]/LTF/CloseTransaction")] public IActionResult LTF_CloseTransaction([FromBody] ApiAction action) { ApiAction response; ILocationTransfer trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ILocationTransfer; if (!trans.IsFinished) { if (action.IsAsync) { response = action.GetResponse(trans.Close()); } else { lock (trans.TransLock) { response = action.GetResponse(trans.Close()); } } response.Message = $"储位调拨事务[ID:{action.ID}]关闭{(response.IsSuccessed ? "成功" : "失败")}"; } else { response = action.GetResponse($"Transaction Error: 储位调拨事务[ID:{action.ID}]已经关闭", false); } } else { response = action.GetResponse($"Transaction Error: 储位调拨事务[ID:{action.ID}]已经关闭", false); } } catch (System.Exception ex) { response = action.GetResponse().CatchExceptionWithLog(ex); } trans?.AddHistory(Request, action); return Ok(response); } /// /// 扫描下架 /// /// /// [HttpPost] [Route("api/[controller]/LTF/ScanItem")] public async Task LTF_ScanItemAsync([FromBody] ApiAction action) { ApiAction response; ILocationTransfer trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ILocationTransfer; if (!trans.IsFinished) { if (action.IsAsync) { response = action.GetResponse(await trans.ScanItem(action.Data)); } else { lock (trans.TransLock) { response = action.GetResponse(trans.ScanItem(action.Data).Result); } } } else { response = action.GetResponse($"Transaction Error: 储位调拨事务[ID:{action.ID}]已经关闭,请重新打开上架功能", false); } } else { response = action.GetResponse($"Transaction Error: 储位调拨事务[ID:{action.ID}]数据丢失,请重新打开上架功能", false); } } catch (System.Exception ex) { response = action.GetResponse().CatchExceptionWithLog(ex); } trans?.AddHistory(Request, action); return Ok(response); } } }