123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- using DBHelper;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using WCS.Service.Entity;
- using WCS.Service.Helpers;
- namespace WCS.Service
- {
- public class WMS
- {
- private static string Url = "http://192.168.249.120:8016";
- public static I_WCS_GetInTaskResponse InBound(string barcode, string devCode, bool getTunnel = false)
- {
- var warehouse = "mwhouseputong";
- if (devCode.StartsWith("MW_") || devCode == "2088" || devCode == "3001")
- warehouse = "mwhouseyuanzhi";
- var res = APICaller.CallApi<I_WCS_GetInTaskResponse>(Url + "/api/Task/I_WCS_GetInTask", new I_WCS_GetInTaskRequest
- {
- ContainerBarCode = barcode,
- WareHouseId = warehouse,
- EquipmentNo = devCode,
- Memo1 = getTunnel ? "1" : "" //1:分巷道 2:分货位
- });
- if (!res.ResType)
- {
- TaskException(devCode, res.ResMessage);
- throw new Exception(res.ResMessage);
- }
- return res;
- }
- public static I_WCS_GetInTaskResponse PalletInbound(DB db, string barcode, string dev)
- {
- var res = APICaller.CallApi<Result>(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 InBound(barcode, dev);
- }
- public static short GetPalletType(string rollCode)
- {
- return 1;
- }
- public static I_WCS_GetWareCellResponse GetLocalIn(int wmstaskid, string tunnel, string device)
- {
- var res = APICaller.CallApi<I_WCS_GetWareCellResponse>(Url + "/api/Task/I_WCS_GetWareCell", new I_WCS_GetWareCellRequest
- {
- PickUpEquipmentNo = device,
- TunnelNum = tunnel.Last().ToString(),
- WMSTaskNum = wmstaskid.ToString()
- });
- if (!res.ResType)
- {
- TaskException(device, res.ResMessage);
- throw new Exception(res.ResMessage);
- }
- return res;
- }
- public static void UpdateTask(int wmstaskid, int status, string addnext, int size = -1)
- {
- var res = APICaller.CallApi<List<I_WCS_PutTaskStepResponse>>(Url + "/api/Task/I_WCS_PutTaskStep", new List<I_WCS_TASKRequest>
- {
- new I_WCS_TASKRequest
- {
- TASK_WKSTATUS = status,
- TASK_WMSNO = wmstaskid.ToString(),
- Size=size,
- TASK_POSIDNEXT=addnext
- }
- });
- if (res == null || res.Count == 0)
- {
- throw new Exception("I_WCS_PutTaskStep调用失败");
- }
- if (!res.First().ResType)
- throw new Exception(res.First().ResMessage);
- }
- public static GetProductInfoResponse GetProductInfo(string barcode, string dev)
- {
- var res = APICaller.CallApi<GetProductInfoResponse>(Url + "/api/Task/GetProductInfo", new GetProductInfoRequest
- {
- BarCode = barcode
- });
- try
- {
- if (!res.ResType)
- throw new Exception(res.ResMessage);
- if (res.ChildContainerType <= 0 || res.ChildContainerType > 9)
- throw new Exception("托盘类型错误");
- if (res.LoadCount <= 0)
- throw new Exception("最大组盘数量错误");
- if (res.DocId == 0)
- throw new Exception("单据ID错误");
- if (res.ProLine < 1 || res.ProLine > 9)
- throw new Exception("产线编号" + res.ProLine + "错误");
- }
- catch (Exception ex)
- {
- TaskException(dev, ex.Message);
- throw;
- }
- return res;
- }
- public static I_WCS_GetOutTaskResponseSingle GetPalletOutTask(short palletType, string devCode)
- {
- var warehouse = "mwhouseputong";
- if (devCode.StartsWith("MW_"))
- warehouse = "mwhouseyuanzhi";
- var res = APICaller.CallApi<I_WCS_GetOutTaskResponseSingle>(Url + "/api/Task/I_WCS_GetOutTask", new I_WCS_GetOutTaskRequest
- {
- OutType = 2,
- Memo2 = palletType.ToString(),
- WareHouseId = warehouse,
- OutEndPostion = devCode
- });
- if (!res.ResType)
- {
- TaskException(devCode, res.ResMessage);
- throw new Exception(res.ResMessage);
- }
- var tcode = "TY" + res.TunnelNum;
- //
- var tunnel = Device.Find(tcode);
- var next = tunnel.GetNext(devCode);
- res.Memo1 = next.CODE;
- res.TunnelNum = tunnel.CODE;
- return res;
- }
- public static I_WCS_GetOutTaskResponseSingle GetOutTask(string position, string devCode)
- {
- var warehouse = "mwhouseputong";
- var ws = int.Parse(position.Split('_')[1]);
- //if (ws > 3)
- warehouse = "mwhouseyuanzhi";
- var res = APICaller.CallApi<I_WCS_GetOutTaskResponseSingle>(Url + "/api/Task/I_WCS_GetOutTask", new I_WCS_GetOutTaskRequest
- {
- OutType = 1,
- WareHouseId = warehouse,
- OutEndPostion = position
- });
- if (!res.ResType)
- {
- var msg = $"目标位置[{position}]获取出库任务失败,原因[{res.ResMessage}]";
- LogHelper.AddWCS_EXCEPTION(msg);
- TaskException(position, res.ResMessage);
- throw new Exception(res.ResMessage);
- }
- var tcode = "TY" + res.TunnelNum;
- var tunnel = Device.Find(tcode);
- if (devCode == "3001")
- devCode = "3045";
- var next = tunnel.GetNext(devCode);
- res.Memo1 = next.CODE;
- res.TunnelNum = tunnel.CODE;
- return res;
- }
- public static WcsContractApiResponse AutoBuildUpGroupStock(string containerCode, string barcode, string dev)
- {
- var res = APICaller.CallApi<WcsContractApiResponse>(Url + "/api/Task/AutoBuildUpGroupStock", new
- {
- ContainerCode = containerCode,
- BarCode = barcode
- });
- return res;
- }
- public static I_WCS_GetTunnelListResponse GetTunnelList(int wmsTaskId, string dev)
- {
- var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/Task/I_WCS_GetTunnelList", new I_WCS_GetTunnelListRequest
- {
- WMSTaskNum = wmsTaskId.ToString()
- });
- if (!res.ResType)
- {
- TaskException(dev, res.ResMessage);
- throw new Exception(res.ResMessage);
- }
- return res;
- }
- /// <summary>
- /// 上一个成功上传重量的任务号
- /// </summary>
- public static int lastWMSTaskId = 0;
- /// <summary>
- /// 上传重量
- /// </summary>
- /// <param name="wmsTaskId">WMS任务号</param>
- /// <param name="weight">重量</param>
- /// <param name="dev">调用方法的设备</param>
- /// <returns></returns>
- /// <exception cref="Exception"></exception>
- public static void GetWeight(int wmsTaskId, int weight, string dev)
- {
- if (lastWMSTaskId == wmsTaskId) return;
- var res = APICaller.CallApi<I_WCS_GetWeightResponse>(Url + "/api/Task/I_WCS_GetWeight", new I_WCS_GetWeightRequest
- {
- WMSTaskNum = wmsTaskId.ToString(),
- Weight = weight
- });
- if (!res.ResType)
- {
- TaskException(dev, res.ResMessage);
- throw new Exception(res.ResMessage);
- }
- else
- {
- lastWMSTaskId = wmsTaskId;
- }
- }
- public static void TaskException(string device, string exMsg)
- {
- if (exMsg == "接口调用中")
- return;
- Task.Run(() =>
- {
- try
- {
- Console.WriteLine(device + ":" + exMsg);
- var res = APICaller.CallApi2<I_WCS_GetExcTaskResponse>(Url + "/api/Task/I_WCS_GetExcTask", new I_WCS_GetExcTaskRequest
- {
- ExcCode = exMsg,
- EquipmentNo = device,
- ExcMessage = exMsg,
- });
- if (!res.ResType)
- throw new Exception(res.ResMessage);
- }
- catch (Exception ex)
- {
- }
- });
- }
- private static List<I_WCS_PutDevInfoRequest> DevInfoList = new List<I_WCS_PutDevInfoRequest>();
- 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<I_WCS_PutDevInfoResponse>(Url + "/api/Task/I_WCS_PutDevInfo", DevInfoList);
- if (!res.ResType)
- throw new Exception(res.ResMessage);
- }
- catch (Exception ex)
- {
- Console.WriteLine("I_WCS_PutDevInfo" + "接口调用失败");
- }
- finally
- {
- DevInfoList.Clear();
- }
- }
- public static void UnBound(string barcode)
- {
- try
- {
- var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/PDA/UnboundMwGroupStock", new
- {
- containerCode = barcode
- });
- }
- catch { }
- }
- }
- }
|