From 7d8f716f4bead12d27b54949846fc38ba993335b Mon Sep 17 00:00:00 2001 From: wanshenmean <cathay_xy@163.com> Date: 星期六, 12 四月 2025 19:43:36 +0800 Subject: [PATCH] 123 --- 代码管理/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs | 42 +++++++++++++ 代码管理/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/MESAPIInvoke.cs | 89 +++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/MESAPIInvoke.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/MESAPIInvoke.cs" new file mode 100644 index 0000000..4578847 --- /dev/null +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/MESAPIInvoke.cs" @@ -0,0 +1,89 @@ +锘縰sing StackExchange.Profiling.Internal; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Headers; +using System.Net.Http.Json; +using System.Text; +using System.Threading.Tasks; + +namespace WIDESEAWCS_Tasks +{ + public class MESAPIInvoke + { + // 浣跨敤闈欐�丠ttpClient瀹炰緥 + private static readonly HttpClient _client = new HttpClient + { + BaseAddress = new Uri("http://192.168.12.212:9003/api/WMS/"), + DefaultRequestHeaders = + { + Accept = { new MediaTypeWithQualityHeaderValue("application/json") }, + UserAgent = { new ProductInfoHeaderValue("MESClient", "1.0") } + } + }; + + /// <summary> + /// 鐑樼鐗╂枡缁戝畾 + /// </summary> + /// <param name="Devid"></param> + /// <param name="Materials"></param> + /// <returns></returns> + public static MESback BakingFeedingBinding(string devId, List<BakingClass> materials) + { + var request = new BakingFeedingClass + { + Devid = devId, + Materials = materials + }; + + var response = _client.PostAsJsonAsync("BakingFeedingBinding", request).Result; + response.EnsureSuccessStatusCode(); + return response.Content.ReadFromJsonAsync<MESback>().Result; + + //using (HttpClient client = new HttpClient()) + + //{ + // client.BaseAddress = new Uri("http://192.168.12.212:9003/api/WMS/BakingFeedingBinding"); + // client.DefaultRequestHeaders.Accept.Clear(); + // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + // client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"); + + // HttpResponseMessage response = client.PostAsJsonAsync("BakingFeedingBinding", req).Result; + // if (response.IsSuccessStatusCode) + // { + // MESback back = response.Content.ReadAsStringAsync().Result.FromJson<MESback>(); + // return back; + // } + // else + // { + // throw new Exception("璋冪敤MESAPI澶辫触锛�"); + // } + //} + } + } + + public class MESback + { + /// <summary> + /// 0:鎴愬姛锛屽ぇ浜�0锛氬け璐� + /// </summary> + public int Code { get; set; } + + /// <summary> + /// 鍙嶉淇℃伅 + /// </summary> + public string Message { get; set; } + + /// <summary> + /// 鐗╂枡绫诲瀷 + /// </summary> + public string MaterialType { get; set; } + + /// <summary> + /// 鐗╂枡鎵瑰彿锛屽啓鍏LC + /// </summary> + public string BarCode { get; set; } + + public string ProcessName { get; set; } + } +} \ No newline at end of file diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs" index caf0630..157560b 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/AGVJob/UpdateTaskAGV.cs" @@ -1,4 +1,5 @@ -锘縰sing WIDESEAWCS_Common.AGVEnum; +锘縰sing Newtonsoft.Json; +using WIDESEAWCS_Common.AGVEnum; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_Model.Models; @@ -176,6 +177,32 @@ plcClient.Communicator.Write(taskFbInteractive2, 1); //throw new Exception("浠诲姟鐘舵�佹洿鏀逛负4缁堢偣宸插畬鎴愬け璐�,浠诲姟ID:" + agvTask.agv_tasknum + DateTime.Now + ",浠诲姟鐘舵�佷笉鏄粓鐐规墽琛屼腑!"); } + if (agvTask.TargetAddress.Contains("HXWLX")) + { + if (agvTask.SourceAddress.Contains("KPHLX")) + { + // 绌虹洏绾胯繘鐑樼 + // TODO: 璋冪敤鍒涙櫤鎺ュ彛鑾峰彇瀹屾暣鏉$爜 + var materials = new List<BakingClass> + { + new BakingClass { BarCode = "1", MaterialType = "1" }, + }; + MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.TargetAddress, materials); + if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); return; } + } + else + { + // 鎻愬崌鏈鸿繘鐑樼 + // TODO: 璋冪敤鍒涙櫤鎺ュ彛鑾峰彇瀹屾暣鏉$爜 + var materials = new List<BakingClass> + { + new BakingClass { BarCode = "1", MaterialType = "1" }, + }; + MESback WMSbackresult = MESAPIInvoke.BakingFeedingBinding(agvTask.TargetAddress, materials); + if (WMSbackresult.Code > 0) { new Exception(WMSbackresult.Message); return; } + } + } + //agvtask_HtyRepository.AddTaskHistory(agvTask, OperateType.Finished.ToString()); _taskRepository.DeleteData(agvTask); @@ -385,4 +412,17 @@ } } } + + public class BakingFeedingClass + { + public string Devid { get; set; } + + public List<BakingClass> Materials { get; set; } + } + + public class BakingClass + { + public string MaterialType { get; set; } + public string BarCode { get; set; } + } } \ No newline at end of file -- Gitblit v1.9.3