using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using WCS.Service.Entity; using WCS.Service.Log; namespace WCS.Service { public class WMS { private static string Url = "http://192.168.249.150:8026"; //private static string Url = "http://127.0.0.1:8026"; private static string wareHouseId = "opphouse"; /// /// 向WMS获取入库任务 一次单卷 /// /// 产品条码 /// 设备条码 /// /// /// public static List I_WCS_GetInTask(string barcode, string devCode, bool getTunnel = false) { var res = APICaller.CallApi(Url + "/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) { TaskException(devCode, res.ResMessage); throw new WarnException(res.ResMessage); } return res.TaskList; } /// /// 向WMS获取入库任务 一次双卷 /// /// 产品1条码 /// 设备1编号 /// 产品1是否直接分配巷道 /// 产品2条码 /// 设备2编号 /// 产品2是否直接分配巷道 /// /// public static List I_WCS_GetInTask(string barcode1, string devCode1, string barcode2, string devCode2, bool getTunnel1 = false, bool getTunnel2 = false) { var res = APICaller.CallApi(Url + "/api/Task/I_WCS_GetInTask", new List() { new I_WCS_GetInTaskRequest(){ ContainerBarCode = barcode1, WareHouseId = wareHouseId, EquipmentNo = devCode1, Memo1 = getTunnel1 ? "1" : "" //1:分巷道 2:分货位 }, new I_WCS_GetInTaskRequest(){ ContainerBarCode = barcode2, WareHouseId = wareHouseId, EquipmentNo = devCode2, Memo1 = getTunnel2 ? "1" : "" //1:分巷道 2:分货位 }, }); if (!res.ResType) { TaskException($"G{devCode1}", res.ResMessage); throw new WarnException(res.ResMessage); } return res.TaskList; } //public static I_WCS_GetInTaskResponse PalletInbound(DB db, string barcode, string dev) //{ // var res = APICaller.CallApi(Url + "/api/PDA/PVCSemiFinishedProductContainerReBack", new PVCSemiFinishedProductReBackRequest // { // BarCode = barcode, // ContainerCode = barcode, // Quantity = 1 // }); // if (res.StatusCode != Result.Success && res.StatusCode != 4004) // { // TaskException(dev, res.Message); // throw new Exception(res.Message); // } // return I_WCS_GetInTask(barcode, dev); //} public static short GetPalletType(string rollCode) { return 1; } /// /// 分配货位 /// /// WMS任务ID /// 巷道 /// 设备号 /// 申请任务对应的货叉 /// /// public static I_WCS_GetWareCellResponse GetLocalIn(int wmstaskid, string tunnel, string device, WareCellForkNum ForkNum) { var res = APICaller.CallApi(Url + "/api/Task/I_WCS_GetWareCell", new I_WCS_GetWareCellRequest { PickUpEquipmentNo = device, TunnelNum = tunnel.Last().ToString(), WMSTaskNum = wmstaskid.ToString(), ForkNum = ForkNum }); if (!res.ResType) { TaskException(device, res.ResMessage); throw new WarnException(res.ResMessage); } return res; } public static void UpdateTask(string POSIDNEXT, int wmstaskid, int status, int size = -1) { var res = APICaller.CallApi>(Url + "/api/Task/I_WCS_PutTaskStep", new List { new I_WCS_TASKRequest { TASK_WKSTATUS = status, TASK_WMSNO = wmstaskid.ToString(), TASK_POSIDNEXT=POSIDNEXT, Size=size } }); if (res == null || res.Count == 0) { throw new WarnException("I_WCS_PutTaskStep调用失败"); } if (!res.First().ResType) throw new WarnException(res.First().ResMessage); } public static GetProductInfoResponse GetProductInfo(string barcode, string dev) { var res = APICaller.CallApi(Url + "/api/Task/GetProductInfo", new GetProductInfoRequest { BarCode = barcode }); try { if (!res.ResType) throw new WarnException(res.ResMessage); if (res.ChildContainerType <= 0 || res.ChildContainerType > 9) throw new WarnException("托盘类型错误"); if (res.LoadCount <= 0) throw new WarnException("最大组盘数量错误"); if (res.DocId == 0) throw new WarnException("单据ID错误"); if (res.ProLine < 1 || res.ProLine > 9) throw new WarnException("产线编号" + res.ProLine + "错误"); } catch (Exception ex) { TaskException(dev, ex.Message); throw; } return res; } /// /// 获取出库任务 /// /// 出库位置 /// 调用方法的设备号 /// /// public static List GetOutTask(string position, string devCode) { var res = APICaller.CallApi(Url + "/api/Task/I_WCS_GetOutTask", new I_WCS_GetOutTaskRequest { OutType = 1, WareHouseId = wareHouseId, OutEndPostion = position }); if (!res.ResType) { TaskException(position, res.ResMessage); throw new WarnException(res.ResMessage); } res.WMSTasks.ForEach(v => { var tcode = "TY" + v.TunnelNum; var tunnel = Device.Find(tcode); //var next = tunnel.GetPath(devCode); //v.Memo1 = next.CODE; v.TunnelNum = tunnel.CODE; }); return res.WMSTasks; } public static WcsContractApiResponse AutoBuildUpGroupStock(string containerCode, string barcode, string dev) { var res = APICaller.CallApi(Url + "/api/Task/AutoBuildUpGroupStock", new { ContainerCode = containerCode, BarCode = barcode }); if (!res.ResType) { TaskException(dev, res.ResMessage); throw new WarnException(res.ResMessage); } return res; } /// /// 获取巷道 /// /// WMS任务号集合 /// 请求设备号 /// /// public static I_WCS_GetTunnelListResponse GetTunnelList(List WMSTaskId, string dev) { var res = APICaller.CallApi(Url + "/api/Task/I_WCS_GetTunnelList", new I_WCS_GetTunnelListRequest { WMSTaskNum = WMSTaskId }); if (!res.ResType) { TaskException(dev, res.ResMessage); throw new WarnException(res.ResMessage); } return res; } public static void TaskException(string device, string exMsg) { if (exMsg == "接口调用中") return; Task.Run(() => { try { Console.WriteLine(device + ":" + exMsg); var res = APICaller.CallApi2(Url + "/api/Task/I_WCS_GetExcTask", new I_WCS_GetExcTaskRequest { ExcCode = exMsg, EquipmentNo = device, ExcMessage = exMsg, }); InfoLog.INFO_I_WCS_GetExcTask(device + ":" + exMsg); if (!res.ResType) throw new WarnException(res.ResMessage); } catch (Exception ex) { } }); } private static List DevInfoList = new List(); public static void DevInfo(string device, string exMsg) { DevInfoList.Add(new I_WCS_PutDevInfoRequest { STA_EQUIPMENTNO = device, STA_ALARMSMSG = exMsg }); } public static void UploadDevInfo() { try { var res = APICaller.CallApi(Url + "/api/Task/I_WCS_PutDevInfo", DevInfoList); if (!res.ResType) throw new WarnException(res.ResMessage); } catch (Exception ex) { Console.WriteLine("I_WCS_PutDevInfo" + "接口调用失败"); } finally { DevInfoList.Clear(); } } public static void UnBound(string barcode) { try { var res = APICaller.CallApi(Url + "/api/PDA/UnboundMwGroupStock", new { containerCode = barcode }); } catch { } } } }