diff --git a/src/Khd.Core.Api/Controllers/RecieveRcsController.cs b/src/Khd.Core.Api/Controllers/RecieveRcsController.cs
index 80cd444..4b50591 100644
--- a/src/Khd.Core.Api/Controllers/RecieveRcsController.cs
+++ b/src/Khd.Core.Api/Controllers/RecieveRcsController.cs
@@ -88,5 +88,17 @@ namespace Khd.Core.Api.Controllers
LogManager.Info($"AgvTaskComplete 接口收到消息");
return _application.AGVTaskComplete();
}
+
+ ///
+ /// 通知agv停止或启动
+ ///
+ ///
+ ///
+ [HttpPost("AgvStopOrStart")]
+ public ReponseMessage AGVStopOrStart(CallAgvStopOrStart agvStopOrStart)
+ {
+ LogManager.Info($"AGVStopOrStart 接口收到消息: {agvStopOrStart.ToJsonString()}");
+ return _application.CallAgvStopOrStart(agvStopOrStart);
+ }
}
}
\ No newline at end of file
diff --git a/src/Khd.Core.Application/HttpHelper.cs b/src/Khd.Core.Application/HttpHelper.cs
new file mode 100644
index 0000000..f79cf3e
--- /dev/null
+++ b/src/Khd.Core.Application/HttpHelper.cs
@@ -0,0 +1,170 @@
+using System;
+using System.Collections.Generic;
+using System.Net.Http;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Khd.Core.Application
+{
+ public class HttpHelper
+ {
+
+ public static string SendPostMessage(string ip, int port, string url, string message, string contentType = "application/Text")
+ {
+ string retsult = HttpPost("http://" + ip + ":" + port + "/" + url, message, contentType, 30, null);
+ return retsult;
+ }
+
+
+ public static string SendGetMessage(string ip, int port, string url)
+ {
+ string retsult = HttpGet("http://" + ip + ":" + port + "/" + url);
+ return retsult;
+ }
+
+ ///
+ /// 发起POST同步请求
+ ///
+ ///
+ ///
+ ///
+ /// application/xml、application/json、application/text、application/x-www-form-urlencoded
+ /// 填充消息头
+ ///
+ public static string HttpPost(string url, string postData = null, string contentType = null, int timeOut = 30, Dictionary headers = null)
+ {
+ postData = postData ?? "";
+ using (HttpClient client = new HttpClient())
+ {
+ if (headers != null)
+ {
+ foreach (var header in headers)
+ client.DefaultRequestHeaders.Add(header.Key, header.Value);
+ }
+ using (HttpContent httpContent = new StringContent(postData, Encoding.UTF8))
+ {
+ if (contentType != null)
+ httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
+
+ HttpResponseMessage response = client.PostAsync(url, httpContent).Result;
+ return response.Content.ReadAsStringAsync().Result;
+ }
+ }
+ }
+
+
+ ///
+ /// 发起POST异步请求
+ ///
+ ///
+ ///
+ /// application/xml、application/json、application/text、application/x-www-form-urlencoded
+ /// 填充消息头
+ ///
+ public static async Task HttpPostAsync(string url, string postData = null, string contentType = null, int timeOut = 30, Dictionary headers = null)
+ {
+ postData = postData ?? "";
+ using (HttpClient client = new HttpClient())
+ {
+ client.Timeout = new TimeSpan(0, 0, timeOut);
+ if (headers != null)
+ {
+ foreach (var header in headers)
+ client.DefaultRequestHeaders.Add(header.Key, header.Value);
+ }
+ using (HttpContent httpContent = new StringContent(postData, Encoding.UTF8))
+ {
+ if (contentType != null)
+ httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
+
+ HttpResponseMessage response = await client.PostAsync(url, httpContent);
+ return await response.Content.ReadAsStringAsync();
+ }
+ }
+ }
+
+ ///
+ /// 发起GET同步请求
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string HttpGet(string url, Dictionary headers = null)
+ {
+ using (HttpClient client = new HttpClient())
+ {
+ if (headers != null)
+ {
+ foreach (var header in headers)
+ client.DefaultRequestHeaders.Add(header.Key, header.Value);
+ }
+ HttpResponseMessage response = client.GetAsync(url).Result;
+ return response.Content.ReadAsStringAsync().Result;
+ }
+ }
+
+ ///
+ /// 发起GET异步请求
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static async Task HttpGetAsync(string url, Dictionary headers = null)
+ {
+ using (HttpClient client = new HttpClient())
+ {
+ if (headers != null)
+ {
+ foreach (var header in headers)
+ client.DefaultRequestHeaders.Add(header.Key, header.Value);
+ }
+ HttpResponseMessage response = await client.GetAsync(url);
+ return await response.Content.ReadAsStringAsync();
+ }
+ }
+
+ ///
+ /// 发起GET同步请求
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string HttpDelete(string url, Dictionary headers = null)
+ {
+ using (HttpClient client = new HttpClient())
+ {
+ if (headers != null)
+ {
+ foreach (var header in headers)
+ client.DefaultRequestHeaders.Add(header.Key, header.Value);
+ }
+ HttpResponseMessage response = client.DeleteAsync(url).Result;
+ return response.Content.ReadAsStringAsync().Result;
+ }
+ }
+
+ ///
+ /// 发起GET异步请求
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static async Task HttpDeleteAsync(string url, Dictionary headers = null)
+ {
+ using (HttpClient client = new HttpClient())
+ {
+ if (headers != null)
+ {
+ foreach (var header in headers)
+ client.DefaultRequestHeaders.Add(header.Key, header.Value);
+ }
+ HttpResponseMessage response = await client.DeleteAsync(url);
+ return await response.Content.ReadAsStringAsync();
+ }
+ }
+ }
+}
diff --git a/src/Khd.Core.Application/Interface/IWcsTaskApplication.cs b/src/Khd.Core.Application/Interface/IWcsTaskApplication.cs
index 1071720..285e52c 100644
--- a/src/Khd.Core.Application/Interface/IWcsTaskApplication.cs
+++ b/src/Khd.Core.Application/Interface/IWcsTaskApplication.cs
@@ -32,5 +32,6 @@ namespace Khd.Core.Application.Interface
ReponseagvCallbackDto AgvCallback2(agvCallbackDto agvCallbackDto);
ReponseMessage CallMaterial(CallMaterial callMaterial);
ReponseMessage AGVTaskComplete();
+ ReponseMessage CallAgvStopOrStart(CallAgvStopOrStart agvStopOrStart);
}
}
\ No newline at end of file
diff --git a/src/Khd.Core.Application/WcsTaskApplication.cs b/src/Khd.Core.Application/WcsTaskApplication.cs
index e5c7408..a91d715 100644
--- a/src/Khd.Core.Application/WcsTaskApplication.cs
+++ b/src/Khd.Core.Application/WcsTaskApplication.cs
@@ -3,8 +3,10 @@ using Khd.Core.Application.Interface;
using Khd.Core.Domain.Dto.webapi;
using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework;
+using Masuit.Tools;
using Masuit.Tools.Logging;
using Microsoft.Extensions.DependencyInjection;
+using Newtonsoft.Json;
using System;
using System.Linq;
using Z.EntityFramework.Plus;
@@ -163,7 +165,7 @@ namespace Khd.Core.Application
if (baseEquip != null)
{
var wcsTask = _dbContext.WcsTask
- .Where(t => (t.taskType == 32 || t.taskType == 48)&&(t.endPointId == baseEquip.objid || t.currPointId == baseEquip.objid))
+ .Where(t => (t.taskType == 32 || t.taskType == 48) && (t.endPointId == baseEquip.objid || t.currPointId == baseEquip.objid))
.FirstOrDefault();
if (wcsTask != null)
{
@@ -432,5 +434,44 @@ namespace Khd.Core.Application
}
return reponseMessage;
}
+
+ public ReponseMessage CallAgvStopOrStart(CallAgvStopOrStart agvStopOrStart)
+ {
+ try
+ {
+ string Ip = "172.16.12.24";
+ int Port = 8182;
+ if (agvStopOrStart.Meth.ToLower() == "stop")
+ {
+ var AgvMessage = new
+ {
+ reqCode= _snowId.NextId().ToString(),
+ robots=new string[] {agvStopOrStart.AgvCode}
+ };
+ string result = HttpHelper.SendPostMessage(Ip, Port, "rcms/services/rest/hikRpcService/stopRobot", AgvMessage.ToJsonString());
+ ReponseMessage reponseMessage = JsonConvert.DeserializeObject(result);
+ return reponseMessage;
+ }
+ else if (agvStopOrStart.Meth.ToLower() == "start")
+ {
+ var AgvMessage = new
+ {
+ reqCode = _snowId.NextId().ToString(),
+ robots = new string[] { agvStopOrStart.AgvCode }
+ };
+ string result = HttpHelper.SendPostMessage(Ip, Port, "rcms/services/rest/hikRpcService/resumeRobot", AgvMessage.ToJsonString());
+ ReponseMessage reponseMessage = JsonConvert.DeserializeObject(result);
+ return reponseMessage;
+ }
+ else
+ {
+ return new ReponseMessage() { code = "1", message = "传入Meth不正确" };
+ }
+ }
+ catch
+ {
+ return new ReponseMessage() { code = "1", message = "调用失败" };
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/Khd.Core.Domain/Dto/webapi/CallMaterial.cs b/src/Khd.Core.Domain/Dto/webapi/CallMaterial.cs
index 71d34d0..a366da8 100644
--- a/src/Khd.Core.Domain/Dto/webapi/CallMaterial.cs
+++ b/src/Khd.Core.Domain/Dto/webapi/CallMaterial.cs
@@ -5,4 +5,10 @@
public string rawOutstockId { get; set; }
public string method { get; set; }
}
+
+ public class CallAgvStopOrStart
+ {
+ public string Meth { get; set; }
+ public string AgvCode { get; set; }
+ }
}
diff --git a/src/Khd.Core.Wcs/appsettings.json b/src/Khd.Core.Wcs/appsettings.json
index d70ecf1..0679e37 100644
--- a/src/Khd.Core.Wcs/appsettings.json
+++ b/src/Khd.Core.Wcs/appsettings.json
@@ -42,7 +42,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
- "Microsoft": "Warning",
+ "Microsoft": "Error",
"Microsoft.Hosting.Lifetime": "Information"
}
}