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]/SEL/GetTransaction")] public IActionResult SEL_GetTransaction([FromBody] ApiAction action) { ApiAction response; IItemQuery trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as IItemQuery; } else { trans = AutoFacContainer.Instance.Resolve().Init(action.ID, action.Data?.USER_CODE, Request.Host.Value, action.Data?.ORG_CODE); 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]/SEL/CloseTransaction")] public IActionResult SEL_CloseTransaction([FromBody] ApiAction action) { ApiAction response; IItemQuery trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as IItemQuery; 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]/SEL/GetQueryItemSum")] public async Task SEL_GetQueryItemSum([FromBody] ApiAction action) { ApiAction response; IItemQuery trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as IItemQuery; if (!trans.IsFinished) { if (action.IsAsync) { response = action.GetResponse(trans.QueryItemSum(action.Data)); } else { lock (trans.TransLock) { response = action.GetResponse(trans.QueryItemSum(action.Data)); } } } 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]/SEL/GetQueryItemSumDtl")] public async Task SEL_GetQueryItemSumDtl([FromBody] ApiAction action) { ApiAction response; IItemQuery trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as IItemQuery; if (!trans.IsFinished) { if (action.IsAsync) { response = action.GetResponse(trans.GetQueryItemSumDtl(action.Data)); } else { lock (trans.TransLock) { response = action.GetResponse(trans.GetQueryItemSumDtl(action.Data)); } } } 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]/SEL/LightAll")] public async Task SEL_LightAllAsync([FromBody] ApiAction action) { ApiAction response; IItemQuery trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as IItemQuery; if (!trans.IsFinished) { if (action.IsAsync) { response = action.GetResponse(await trans.LightAll(action.Data)); } else { lock (trans.TransLock) { response = action.GetResponse(trans.LightAll(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); } /// /// 灭灯 /// /// /// [HttpPost] [Route("api/[controller]/SEL/CloseLight")] public async Task SEL_CloseLightAsync([FromBody] ApiAction action) { ApiAction response; IItemQuery trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as IItemQuery; if (!trans.IsFinished) { if (action.IsAsync) { response = action.GetResponse(await trans.CloseLight()); } else { lock (trans.TransLock) { response = action.GetResponse(trans.CloseLight().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); } } }