添加小车暂停和启动接口

master
1 year ago
parent db1d71e270
commit e7ec40a522

@ -88,5 +88,17 @@ namespace Khd.Core.Api.Controllers
LogManager.Info($"AgvTaskComplete 接口收到消息");
return _application.AGVTaskComplete();
}
/// <summary>
/// 通知agv停止或启动
/// </summary>
/// <param name="agvStopOrStart"></param>
/// <returns></returns>
[HttpPost("AgvStopOrStart")]
public ReponseMessage AGVStopOrStart(CallAgvStopOrStart agvStopOrStart)
{
LogManager.Info($"AGVStopOrStart 接口收到消息: {agvStopOrStart.ToJsonString()}");
return _application.CallAgvStopOrStart(agvStopOrStart);
}
}
}

@ -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;
}
/// <summary>
/// 发起POST同步请求
///
/// </summary>
/// <param name="url"></param>
/// <param name="postData"></param>
/// <param name="contentType">application/xml、application/json、application/text、application/x-www-form-urlencoded</param>
/// <param name="headers">填充消息头</param>
/// <returns></returns>
public static string HttpPost(string url, string postData = null, string contentType = null, int timeOut = 30, Dictionary<string, string> 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;
}
}
}
/// <summary>
/// 发起POST异步请求
/// </summary>
/// <param name="url"></param>
/// <param name="postData"></param>
/// <param name="contentType">application/xml、application/json、application/text、application/x-www-form-urlencoded</param>
/// <param name="headers">填充消息头</param>
/// <returns></returns>
public static async Task<string> HttpPostAsync(string url, string postData = null, string contentType = null, int timeOut = 30, Dictionary<string, string> 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();
}
}
}
/// <summary>
/// 发起GET同步请求
/// </summary>
/// <param name="url"></param>
/// <param name="headers"></param>
/// <param name="contentType"></param>
/// <returns></returns>
public static string HttpGet(string url, Dictionary<string, string> 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;
}
}
/// <summary>
/// 发起GET异步请求
/// </summary>
/// <param name="url"></param>
/// <param name="headers"></param>
/// <param name="contentType"></param>
/// <returns></returns>
public static async Task<string> HttpGetAsync(string url, Dictionary<string, string> 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();
}
}
/// <summary>
/// 发起GET同步请求
/// </summary>
/// <param name="url"></param>
/// <param name="headers"></param>
/// <param name="contentType"></param>
/// <returns></returns>
public static string HttpDelete(string url, Dictionary<string, string> 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;
}
}
/// <summary>
/// 发起GET异步请求
/// </summary>
/// <param name="url"></param>
/// <param name="headers"></param>
/// <param name="contentType"></param>
/// <returns></returns>
public static async Task<string> HttpDeleteAsync(string url, Dictionary<string, string> 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();
}
}
}
}

@ -32,5 +32,6 @@ namespace Khd.Core.Application.Interface
ReponseagvCallbackDto AgvCallback2(agvCallbackDto agvCallbackDto);
ReponseMessage CallMaterial(CallMaterial callMaterial);
ReponseMessage AGVTaskComplete();
ReponseMessage CallAgvStopOrStart(CallAgvStopOrStart agvStopOrStart);
}
}

@ -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<ReponseMessage>(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<ReponseMessage>(result);
return reponseMessage;
}
else
{
return new ReponseMessage() { code = "1", message = "传入Meth不正确" };
}
}
catch
{
return new ReponseMessage() { code = "1", message = "调用失败" };
}
}
}
}

@ -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; }
}
}

@ -42,7 +42,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft": "Error",
"Microsoft.Hosting.Lifetime": "Information"
}
}

Loading…
Cancel
Save