using ServiceCenter; using ServiceCenter.Extensions; using ServiceCenter.Logs; using ServiceCenter.Redis; using ServiceCenter.WebApi; using WCS.WorkEngineering.WebApi.Models.AGV.Response; using WCS.WorkEngineering.WebApi.Models.WCS.Response; using WCS.WorkEngineering.WebApi.Models.WMS.Request; using WCS.WorkEngineering.WebApi.Models.WMS.Response; namespace WCS.WorkEngineering.WebApi.Controllers { /// /// AGV相关接口控制器 /// public static class WmsApi { private static string _WMSUrl = null!; private static string _wareHouseId = null!; /// /// WMS URL /// public static string WMSUrl { get { _WMSUrl ??= RedisHub.Default.Check("WMSUrl"); if (string.IsNullOrEmpty(_WMSUrl)) { throw new KnownException($"请在Redis配置WMSUrl", LogLevelEnum.High); } return _WMSUrl; } } /// /// 仓库编号 /// public static string wareHouseId = ServiceHub.WarehouseName; /// /// 上传重量等信息 /// /// 任务号 /// rfid /// public static SRes WcsUploadInfo(int taskCode, decimal weight) => WcsUploadInfo(taskCode, weight, ""); /// /// 上传重量等信息 /// /// 任务号 /// 重量 /// public static SRes WcsUploadInfo(int taskCode, string RFID) => WcsUploadInfo(taskCode, 0, RFID); /// /// 上传重量等信息 /// /// 任务号 /// 重量 /// rfid /// /// public static SRes WcsUploadInfo(int taskCode, decimal weight, string RFID) { var res = APICaller.CallApi2(WMSUrl + "/api/Hj/WcsUploadInfo", new WcsUploadInfoRequest { TaskCode = taskCode, Weight = weight, RFID = RFID }); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } /// /// 获取巷道 /// /// WMS任务ID /// /// public static SRes GetTunnelPriorityList(int wcsTaskNum) { var res = APICaller.CallApi2>(WMSUrl + "/api/Hj/GetTunnelPriorityList", new GetTunnelPriorityListRequest { TaskNum = wcsTaskNum, }); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } /// /// 分配货位 /// /// WMS任务ID /// 货位 /// 设备号 /// /// public static SRes GetLocalIn(int wcsTaskNum, string tunnel, string device) { var res = APICaller.CallApi2>(WMSUrl + "/api/FJ/ApplyStockInLoc", new ApplyStockInLocRequest { TaskNum = wcsTaskNum, TunnelNum = tunnel.GetLastDigit(), PickUpEquipmentNo = device.ToString(), }); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } /// /// 堆垛机出库任务执行完成 /// /// /// /// public static SRes SrmPickOutCompleted(int taskNum) { var res = APICaller.CallApi2>(WMSUrl + "/api/Hj/SrmPickOutCompleted", new SrmPickOutCompletedRequest { TaskNum = taskNum, }); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } /// /// 一楼空工字轮申请出库 /// /// 出库位置 /// public static SRes ApplyStockOutTask(string outEndPostion) => ApplyStockOutTask(outEndPostion, 2); /// /// 申请出库任务 /// /// 出库位置 /// 出库类型 /// /// public static SRes ApplyStockOutTask(string outEndPostion, int outType) { var request = new ApplyStockOutTaskRequest { OutEndPostion = outEndPostion, OutType = outType, WarehouseCode = wareHouseId, }; switch (outEndPostion) { case "1012": request.Tunnel = "1"; break; case "1014": request.Tunnel = "2"; break; case "1016": request.Tunnel = "3"; break; } var res = APICaller.CallApi2(WMSUrl + "/api/Hj/ApplyStockOutTask", request); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } /// /// 获取各巷道剩余空轮数量 /// /// /// public static SRes GetTunnelEmptyConCount() { var res = APICaller.CallApi2>(WMSUrl + "/api/Hj/GetTunnelEmptyConCount", new GetTunnelEmptyConCountRequest { }); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } /// /// 完成任务 /// /// /// /// public static SRes CompleteTask(int taskNo) { var res = APICaller.CallApi2>(WMSUrl + "/api/Hj/CompleteTask", new CompleteTaskRequest { TaskNum = taskNo, OperationType = Models.WMS.Request.CompleteTask.自动完成, WCSUpdateName = "WCS" }); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } /// /// 二深位获取移库任务 /// /// 任务 /// /// public static SRes AddWcsMoveTask(int taskNo) { var res = APICaller.CallApi2>(WMSUrl + "/api/Hj/AddWcsMoveTask", new CompleteTaskRequest { TaskNum = taskNo, }); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } /// /// 向WMS获取入库任务 一次单卷 /// /// 产品条码 /// 设备条码 /// /// /// public static I_WCS_GetInTaskResponse I_WCS_GetInTask(string barcode, string devCode, bool getTunnel = false) { var res = APICaller.CallApi(WMSUrl + "/api/Task/I_WCS_GetInTask", new List() { new I_WCS_GetInTaskRequest(){ ContainerBarCode = barcode, WareHouseId = wareHouseId, EquipmentNo = devCode, Memo1 = getTunnel ? "1" : "" //1:分巷道 2:分货位 } }); if (!res.ResType) throw new KnownException(res.ResMessage, LogLevelEnum.High); return res; } /// /// 处理任务验证接口 /// /// 需要处理的任务进行验证 /// 目标状态 /// /// public static SRes HandleTaskVerify(List taskNo, int state) { var res = APICaller.CallApi2(WMSUrl + "/api/Hj/CancelTaskVerify", new CancelTaskVerifyRequest { TaskNo = taskNo, State = state }); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } /// /// 处理任务接口 /// /// 处理 /// 目标状态 /// /// public static SRes CarryTaskInfo(List taskNo, int state) { var res = APICaller.CallApi2(WMSUrl + "/api/Hj/CarryTaskInfo", new CancelTaskVerifyRequest { TaskNo = taskNo, State = state }); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } /// /// WMS完成或取消任务验证 /// /// /// /// 99完成,106取消 /// public static SRes? HandleTaskVerify(SRes sRes, int id, int type) { try { var res = WmsApi.HandleTaskVerify(new List() { id }, type); return res; } catch (Exception ex) { sRes.ResDataList.Add(new HandleTaskResponse() { IsSuccess = false, TaskNo = id, Message = $"WMS错误:{ex.Message}", }); return null; } } /// /// WMS完成或取消任务执行 /// /// /// /// 99完成,106取消 /// public static SRes? CarryTaskInfo(SRes sRes, int id, int type) { try { var res = WmsApi.CarryTaskInfo(new List() { id }, type); return res; } catch (Exception ex) { sRes.ResDataList.Add(new HandleTaskResponse() { IsSuccess = false, TaskNo = id, Message = $"WMS错误:{ex.Message}", }); return null; } } /// /// 工字轮/芯股进入主线扫码 /// /// 工字轮条码组 /// /// public static SRes? OneFloorWorkerBuildEmptyPalletsStock(OneFloorWorkerBuildEmptyPalletsStockRequest reqDto) { var res = APICaller.CallApi(WMSUrl + "/api/FJ/OneFloorWorkerBuildEmptyPalletsStock", new OneFloorWorkerBuildEmptyPalletsStockRequest { PalletCode = reqDto.PalletCode, PalletType = reqDto.PalletType, StartLoc = reqDto.StartLoc, WareCode = GetWareCode(reqDto.StartLoc), PalletNum = "1" }); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } /// /// 获取仓库号 /// public static string GetWareCode(string add) { return add switch { "2532" => "1N", "2527" => "1N", "2528" => "1N", "2732" => "1S", "2727" => "1S", "2728" => "1S", _ => "", }; } /// /// 工字轮/芯股进入主线扫码 /// /// /// /// /// public static SRes EnteMainLine(List reqDto, string equNo) { var res = APICaller.CallApi(WMSUrl + "/api/FJ/EnteMainLine", new FJEnteMainLineRequest { IShapedWheelCodes = reqDto, equNo = equNo }); if (res.ResCode != ResponseStatusCodeEnum.Sucess) { throw new KnownException(res.ResMsg, LogLevelEnum.High); } return res; } } }