123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- using Logs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using WCS.Service.Entity;
- namespace WCS.Service
- {
- public class WMS
- {
- private const string Url = "http://192.168.249.150:8026";
- //private static string Url = "http://127.0.0.1:8026";
- private const string WareHouseId = "opphouse";
- /// <summary>
- /// 向WMS获取入库任务 一次单卷
- /// </summary>
- /// <param name="barcode">产品条码</param>
- /// <param name="devCode">设备条码</param>
- /// <param name="getTunnel"></param>
- /// <returns></returns>
- /// <exception cref="Exception"></exception>
- public static List<I_WCS_GetInTaskResponseItem> I_WCS_GetInTask(string barcode, string devCode, bool getTunnel = false)
- {
- var res = APICaller.CallApi<I_WCS_GetInTaskResponse>(Url + "/api/Task/I_WCS_GetInTask", new List<I_WCS_GetInTaskRequest>()
- {
- new(){
- ContainerBarCode = barcode,
- WareHouseId = WareHouseId,
- EquipmentNo = devCode,
- Memo1 = getTunnel ? "1" : "" //1:分巷道 2:分货位
- }
- });
- if (res.ResType) return res.TaskList;
- TaskException(devCode, res.ResMessage);
- throw new WarnException(res.ResMessage);
- }
- /// <summary>
- /// 向WMS获取入库任务 一次双卷
- /// </summary>
- /// <param name="barcode1">产品1条码</param>
- /// <param name="devCode1">设备1编号</param>
- /// <param name="getTunnel1">产品1是否直接分配巷道</param>
- /// <param name="barcode2">产品2条码</param>
- /// <param name="devCode2">设备2编号</param>
- /// <param name="getTunnel2">产品2是否直接分配巷道</param>
- /// <exception cref="WarnException"></exception>
- /// <returns></returns>
- public static List<I_WCS_GetInTaskResponseItem> I_WCS_GetInTask(string barcode1, string devCode1, string barcode2, string devCode2, bool getTunnel1 = false, bool getTunnel2 = false)
- {
- var res = APICaller.CallApi<I_WCS_GetInTaskResponse>(Url + "/api/Task/I_WCS_GetInTask", new List<I_WCS_GetInTaskRequest>()
- {
- new(){
- ContainerBarCode = barcode1,
- WareHouseId = WareHouseId,
- EquipmentNo = devCode1,
- Memo1 = getTunnel1 ? "1" : "" //1:分巷道 2:分货位
- },
- new(){
- ContainerBarCode = barcode2,
- WareHouseId = WareHouseId,
- EquipmentNo = devCode2,
- Memo1 = getTunnel2 ? "1" : "" //1:分巷道 2:分货位
- },
- });
- if (res.ResType) return res.TaskList;
- TaskException($"G{devCode1}", res.ResMessage);
- throw new WarnException(res.ResMessage);
- }
- /// <summary>
- /// 分配货位
- /// </summary>
- /// <param name="wmstaskid">WMS任务ID</param>
- /// <param name="tunnel">巷道</param>
- /// <param name="device">设备号</param>
- /// <param name="ForkNum">申请任务对应的货叉</param>
- /// <exception cref="WarnException"></exception>
- /// <returns></returns>
- public static I_WCS_GetWareCellResponse GetLocalIn(int wmstaskid, string tunnel, string device, WareCellForkNum ForkNum)
- {
- 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(),
- ForkNum = ForkNum
- });
- if (res.ResType) return res;
- TaskException(device, res.ResMessage);
- throw new WarnException(res.ResMessage);
- }
- public static void UpdateTask(string POSIDNEXT, int wmstaskid, int status, int size = -1)
- {
- var res = APICaller.CallApi<List<I_WCS_PutTaskStepResponse>>(Url + "/api/Task/I_WCS_PutTaskStep", new List<I_WCS_TASKRequest>
- {
- new()
- {
- 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<GetProductInfoResponse>(Url + "/api/Task/GetProductInfo", new GetProductInfoRequest
- {
- BarCode = barcode
- });
- try
- {
- if (!res.ResType)
- throw new WarnException(res.ResMessage);
- if (res.ChildContainerType is <= 0 or > 9)
- throw new WarnException("托盘类型错误");
- if (res.LoadCount <= 0)
- throw new WarnException("最大组盘数量错误");
- if (res.DocId == 0)
- throw new WarnException("单据ID错误");
- if (res.ProLine is < 1 or > 9)
- throw new WarnException("产线编号" + res.ProLine + "错误");
- }
- catch (Exception ex)
- {
- TaskException(dev, ex.Message);
- throw;
- }
- return res;
- }
- /// <summary>
- /// 获取出库任务
- /// </summary>
- /// <param name="position">出库位置</param>
- /// <param name="devCode">调用方法的设备号</param>
- /// <returns></returns>
- /// <exception cref="Exception"></exception>
- public static List<I_WCS_GetOutTaskResponseSingle> GetOutTask(string position, string devCode)
- {
- var res = APICaller.CallApi<I_WCS_GetOutTaskResponse>(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<WcsContractApiResponse>(Url + "/api/Task/AutoBuildUpGroupStock", new
- {
- ContainerCode = containerCode,
- BarCode = barcode
- });
- if (res.ResType) return res;
- TaskException(dev, res.ResMessage);
- throw new WarnException(res.ResMessage);
- }
- /// <summary>
- /// 获取巷道
- /// </summary>
- /// <param name="WMSTaskId">WMS任务号集合</param>
- /// <param name="dev">请求设备号</param>
- /// <returns></returns>
- /// <exception cref="Exception"></exception>
- public static I_WCS_GetTunnelListResponse GetTunnelList(List<string> WMSTaskId, string dev)
- {
- var res = APICaller.CallApi<I_WCS_GetTunnelListResponse>(Url + "/api/Task/I_WCS_GetTunnelList", new I_WCS_GetTunnelListRequest
- {
- WMSTaskNum = WMSTaskId
- });
- if (res.ResType) return res;
- TaskException(dev, res.ResMessage);
- throw new WarnException(res.ResMessage);
- }
- 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,
- });
- InfoLog.INFO_I_WCS_GetExcTask(device + ":" + exMsg);
- if (!res.ResType) throw new WarnException(res.ResMessage);
- }
- catch (Exception)
- {
- }
- });
- }
- private static List<I_WCS_PutDevInfoRequest> DevInfoList = new();
- public static void DevInfo(string device, string exMsg)
- {
- DevInfoList.Add(new I_WCS_PutDevInfoRequest
- {
- STA_EQUIPMENTNO = device,
- STA_ALARMSMSG = exMsg
- });
- }
- public static void UploadDevInfo()
- {
- return;
- try
- {
- var res = APICaller.CallApi<I_WCS_PutDevInfoResponse>(Url + "/api/Task/I_WCS_PutDevInfo", DevInfoList);
- if (!res.ResType)
- throw new WarnException(res.ResMessage);
- }
- catch (Exception)
- {
- 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 { }
- }
- }
- }
|