using System; using System.Collections.Generic; 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 { /// /// GetTransaction(ApiAction(Data:UserId)) /// 根据ApiAction的id返回一个货架遥控事务 /// /// /// [HttpPost] [Route("api/[controller]/SR/GetTransaction")] public IActionResult SR_GetTransaction([FromBody] ApiAction action) { ApiAction response; IShelfRemote trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as IShelfRemote; } else { trans = DI.Resolve().Init(action.ID, action.Data?.USER_CODE, Request.Host.Value); iBiz.WMS.Context.NewTransaction(HttpContext, trans, false); } response = action.GetResponse(); } catch (System.Exception ex) { response = action.GetResponse().CatchExceptionWithLog(ex); } trans?.AddHistory(Request, action); return Ok(response); } [HttpPost] [Route("api/[controller]/SR/CloseTransaction")] public IActionResult SR_CloseTransaction([FromBody] ApiAction action) { ApiAction response; IShelfRemote trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as IShelfRemote; 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]/SR/CloseShelfLight")] public async Task SR_CloseShelfLightAsync([FromBody] ApiAction action) { ApiAction response; IShelfRemote trans = null; try { if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) { trans = iBiz.WMS.Context.GetTransDic()[action.ID] as IShelfRemote; if (!trans.IsFinished) { if (action.IsAsync) { response = action.GetResponse(await trans.CloseShelfAllLight(action.Data.ToString())); } else { lock (trans.TransLock) { response = action.GetResponse(trans.CloseShelfAllLight(action.Data.ToString()).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]/SR/Test")] public async Task Test([FromBody] ApiAction action) { ApiAction response = new(); try { response = response.GetResponse(await DI.Resolve().Test(action.Data?.ToString())); } catch (System.Exception ex) { response = response.GetResponse().CatchExceptionWithLog(ex); } return Ok(response); } } }