From e4466efbb3f3798c594523e34255aef8296a16fa Mon Sep 17 00:00:00 2001 From: gwbvipvip Date: Tue, 15 Aug 2023 17:07:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BPA.MES.Base.Application.xml | 109 +++++++++++++++++- .../AGVService/Dtos/AGVThirdPartyDto.cs | 69 ++++++++++- .../Services/AGVThirdPartyService.cs | 62 +++++++++- .../Services/IAGVThirdPartyService.cs | 36 +++++- backend/BPA.MES.Base.Web.Core/Startup.cs | 15 +-- 5 files changed, 272 insertions(+), 19 deletions(-) diff --git a/backend/BPA.MES.Base.Application/BPA.MES.Base.Application.xml b/backend/BPA.MES.Base.Application/BPA.MES.Base.Application.xml index 447a729..3308e7e 100644 --- a/backend/BPA.MES.Base.Application/BPA.MES.Base.Application.xml +++ b/backend/BPA.MES.Base.Application/BPA.MES.Base.Application.xml @@ -1602,36 +1602,91 @@ 主键 - + + + 任务完成回报Dto + + + 上游系统任务号,全局唯一 - + 仓库编号 - + 任务快仓系统编号 - + - + 内部任务类型 - + 数据字段 + + + 上下料交互请求DTO + + + + + AGV编号 + + + + + 容器编号,如果一次上/下多个容器,则多个容器用英文逗号分隔 + + + + + 上游设备ID + + + + + 上游设备ID,多个用英文逗号分隔 + + + + + 快仓任务编号 + + + + + 消息ID + + + + + 交互阶段LOAD:上料阶段 UNLOAD:下料阶段 + + + + + 上游任务号 + + + + + 货到货 + + AGV编号 @@ -1811,6 +1866,48 @@ + + + 任务回调 + + + + + + + AGV上下料交互请求 + + + + + + + 下发任务 + + + + + + + 取消任务 + + + + + + + 任务回调 + + + + + + + AGV上下料交互请求 + + + + 名 称 :AGV点位管理 diff --git a/backend/BPA.MES.Base.Application/Services/AGVService/Dtos/AGVThirdPartyDto.cs b/backend/BPA.MES.Base.Application/Services/AGVService/Dtos/AGVThirdPartyDto.cs index 212d7ea..d24e1a5 100644 --- a/backend/BPA.MES.Base.Application/Services/AGVService/Dtos/AGVThirdPartyDto.cs +++ b/backend/BPA.MES.Base.Application/Services/AGVService/Dtos/AGVThirdPartyDto.cs @@ -6,7 +6,21 @@ using System.Threading.Tasks; namespace BPA.MES.Base.Application.Services.AGVService.Dtos { - public class AGVThirdPartyInputBaseDto + + public class AGVExecuteReplyRequest + { + public AGVExecuteReplyDto Event { get; set; } + } + + public class AGVLoadAndUnloadRequest + { + public AGVLoadAndUnloadDto Event { get; set; } + } + + /// + /// 任务完成回报Dto + /// + public class AGVExecuteReplyDto { /// /// 上游系统任务号,全局唯一 @@ -31,7 +45,7 @@ namespace BPA.MES.Base.Application.Services.AGVService.Dtos /// /// 内部任务类型 /// - public jobType jobType { get; set; } + public string jobType { get; set; } /// /// 数据字段 @@ -40,7 +54,57 @@ namespace BPA.MES.Base.Application.Services.AGVService.Dtos } + /// + /// 上下料交互请求DTO + /// + public class AGVLoadAndUnloadDto + { + /// + /// AGV编号 + /// + public string agvCode { get; set; } + + /// + /// 容器编号,如果一次上/下多个容器,则多个容器用英文逗号分隔 + /// + public string containerCode { get; set; } + + /// + /// 上游设备ID + /// + public long equipmentId { get; set; } + /// + /// 上游设备ID,多个用英文逗号分隔 + /// + public string equipmentIds { get; set; } + + /// + /// 快仓任务编号 + /// + public string jobId { get; set; } + + /// + /// 消息ID + /// + public string msgId { get; set; } + + /// + /// 交互阶段LOAD:上料阶段 UNLOAD:下料阶段 + /// + public string command { get; set; } + + /// + /// 上游任务号 + /// + public string robotJobId { get; set; } + + } + + + /// + /// 货到货 + /// public class GoodsToGoods { /// @@ -195,6 +259,7 @@ namespace BPA.MES.Base.Application.Services.AGVService.Dtos /// 1) 辊筒货位到货位搬运 /// SLOT_ROLLER_MOVE = 1, + POINT_ROLLER_MOVE=2 } } diff --git a/backend/BPA.MES.Base.Application/Services/AGVService/Services/AGVThirdPartyService.cs b/backend/BPA.MES.Base.Application/Services/AGVService/Services/AGVThirdPartyService.cs index 64860a3..1cebe95 100644 --- a/backend/BPA.MES.Base.Application/Services/AGVService/Services/AGVThirdPartyService.cs +++ b/backend/BPA.MES.Base.Application/Services/AGVService/Services/AGVThirdPartyService.cs @@ -1,4 +1,8 @@ using BPA.AGV; +using BPA.MES.Base.Application.Services.AGVService.Dtos; +using MQTTnet.Client; +using MQTTnet.Client.Publishing; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; @@ -8,12 +12,15 @@ using System.Threading.Tasks; namespace BPA.MES.Base.Application.Services.AGVService.Services { + [AllowAnonymous, NonUnify] [ApiDescriptionSettings("AGV管理", Name = "AgvThirdParty", Tag = "AGV第三方api", KeepName = true, SplitCamelCase = true, KeepVerb = true)] public class AGVThirdPartyService:IAGVThirdPartyService, ITransient, IDynamicApiController { private readonly AGVHandler _aGVHandler; - public AGVThirdPartyService(AGVHandler aGVHandler) + private readonly IMqttClient _client; + public AGVThirdPartyService(AGVHandler aGVHandler, IMqttClient client) { + _client = client; _aGVHandler = aGVHandler; } @@ -54,6 +61,57 @@ namespace BPA.MES.Base.Application.Services.AGVService.Services return await _aGVHandler.CancelAsync(kCCancelRequest); } - + + /// + /// 任务回调 + /// + /// + /// + [HttpPost] + public async Task ExecuteReplyAsync(AGVExecuteReplyRequest input) + { + try + { + var applicationMessage = new MQTTnet.MqttApplicationMessageBuilder() + .WithTopic("robotjob.report") + .WithPayload(JsonConvert.SerializeObject(input.Event)) + .WithAtLeastOnceQoS() + .Build(); + + var result = await _client.PublishAsync(applicationMessage); + return result.ReasonCode == MqttClientPublishReasonCode.Success; + } + catch (Exception e) + { + return false; + } + } + + + /// + /// AGV上下料交互请求 + /// + /// + /// + [HttpPost] + public async Task LoadAndUnloadAsync(AGVLoadAndUnloadRequest input) + { + try + { + var applicationMessage = new MQTTnet.MqttApplicationMessageBuilder() + .WithTopic("rollerjob.upstreamrequest") + .WithPayload(JsonConvert.SerializeObject(input.Event)) + .WithAtLeastOnceQoS() + .Build(); + + var result = await _client.PublishAsync(applicationMessage); + return result.ReasonCode == MqttClientPublishReasonCode.Success; + } + catch (Exception e) + { + return false; + } + } + } } diff --git a/backend/BPA.MES.Base.Application/Services/AGVService/Services/IAGVThirdPartyService.cs b/backend/BPA.MES.Base.Application/Services/AGVService/Services/IAGVThirdPartyService.cs index 9db9328..7f07cd8 100644 --- a/backend/BPA.MES.Base.Application/Services/AGVService/Services/IAGVThirdPartyService.cs +++ b/backend/BPA.MES.Base.Application/Services/AGVService/Services/IAGVThirdPartyService.cs @@ -1,4 +1,6 @@ -using System; +using BPA.AGV; +using BPA.MES.Base.Application.Services.AGVService.Dtos; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +8,37 @@ using System.Threading.Tasks; namespace BPA.MES.Base.Application.Services.AGVService.Services { - public class IAGVThirdPartyService + public interface IAGVThirdPartyService { + + /// + /// 下发任务 + /// + /// + /// + Task ExecuteAsync(KCExecuteRequest cExecuteRequest); + + /// + /// 取消任务 + /// + /// + /// + Task CancelAsync(KCCancelRequest kCCancelRequest); + + + /// + /// 任务回调 + /// + /// + /// + Task ExecuteReplyAsync(AGVExecuteReplyRequest input); + + + /// + /// AGV上下料交互请求 + /// + /// + /// + Task LoadAndUnloadAsync(AGVLoadAndUnloadRequest input); } } diff --git a/backend/BPA.MES.Base.Web.Core/Startup.cs b/backend/BPA.MES.Base.Web.Core/Startup.cs index ffd0aad..569316f 100644 --- a/backend/BPA.MES.Base.Web.Core/Startup.cs +++ b/backend/BPA.MES.Base.Web.Core/Startup.cs @@ -45,16 +45,17 @@ public class Startup : AppStartup services.AddWebApiClient(); services.AddAGV(op => { - op = new AGVOptions() + new AGVOptions() { Header=new KCOption() { - AppKey="43", - AppSecret="12", - RequestId= "43", - Timestamp= "2234234324", - Version= "2.9" - } + AppKey="43", + AppSecret="12", + RequestId= "43", + Timestamp= "2234234324", + Version= "2.9" + }, + Sign="123456" }; });