From ddfbe186246e95e693851978cbe643277f46e944 Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Sat, 22 Feb 2025 18:52:46 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BB=BB=E5=8A=A1=E7=8A=B6=E6=80=81=E7=AD=89?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=90=8C=E6=AD=A5=E5=9B=9Ewcs=20=202.?= =?UTF-8?q?=E8=B4=A7=E6=9E=B6=E7=BB=91=E5=AE=9A=E8=A7=A3=E7=BB=91=E6=8E=A5?= =?UTF-8?q?=E5=85=A5rcs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WCS.BLL/Manager/AGVManager.cs | 83 +++++++++++- .../Services/IService/IPDAMatBindService.cs | 19 +++ WCS.BLL/Services/Service/PDAMatBindService.cs | 125 ++++++++++++++++++ .../PDAShelfLocationBindUnbindService.cs | 83 ++++++++---- .../ApiModel/AGV/AGVBindPodAndBerthRequest.cs | 34 +++++ .../Controllers/PDAMatBindController.cs | 99 +------------- WCS.WebApi/Program.cs | 2 + 7 files changed, 320 insertions(+), 125 deletions(-) create mode 100644 WCS.BLL/Services/IService/IPDAMatBindService.cs create mode 100644 WCS.BLL/Services/Service/PDAMatBindService.cs create mode 100644 WCS.Model/ApiModel/AGV/AGVBindPodAndBerthRequest.cs diff --git a/WCS.BLL/Manager/AGVManager.cs b/WCS.BLL/Manager/AGVManager.cs index df566b7..c399049 100644 --- a/WCS.BLL/Manager/AGVManager.cs +++ b/WCS.BLL/Manager/AGVManager.cs @@ -1,4 +1,5 @@ -using System; +using SqlSugar; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -25,7 +26,7 @@ namespace WCS.BLL.Manager while (true) { //每5秒同步一次 - Thread.Sleep(5000); + Thread.Sleep(3000); try { var url = @"http://192.168.18.150:8181/rcms/services/rest/hikRpcService/queryTaskStatus"; @@ -61,6 +62,23 @@ namespace WCS.BLL.Manager Enum.TryParse(responseData.taskStatus, out TaskStatusEnum status); isUpdate = true; tasks[i].TaskStatus = status; + + //取消任务时 货架数据需要更新 + if (status == TaskStatusEnum.取消完成) + { + var shelf = DbHelp.db.Queryable() + .Where(t => t.ShelfCode == tasks[i].ShelfCode) + .Where(t => t.CurrentLocationId == tasks[i].StratLocationId && t.DestinationLocationId == tasks[i].EndLocationId) + .First(); + if (shelf != null) + { + shelf.DestinationLocationId = 0; + shelf.DestinationLocaiotnCode = string.Empty; + shelf.TransStatus = TransStatusEnum.静止; + DbHelp.db.Updateable(shelf).ExecuteCommand(); + } + } + } if (isUpdate) { @@ -136,6 +154,11 @@ namespace WCS.BLL.Manager } } + /// + /// RCS取消任务 + /// + /// + /// public static AGVResponseModel CancelTask(AgvTask agvTask) { try @@ -153,8 +176,10 @@ namespace WCS.BLL.Manager var response = ApiHelp.GetDataFromHttp(url, body, "POST", true); if (response.code == "0" && response.message == "成功") { - agvTask.TaskStatus = Model.ApiModel.AGV.TaskStatusEnum.取消完成; - DbHelp.db.Updateable(agvTask).ExecuteCommand(); + //取消会统一在后台线程更新 + + //agvTask.TaskStatus = Model.ApiModel.AGV.TaskStatusEnum.取消完成; + //DbHelp.db.Updateable(agvTask).ExecuteCommand(); } return response; } @@ -168,5 +193,55 @@ namespace WCS.BLL.Manager }; } } + + + /// + /// RCS货架绑定 解绑 + /// + /// + /// + public static AGVResponseModel BindPodAndBerth(string shelfCode,string locationCode , BindPodAndBerthMethod bindPodAndBerthMethod) + { + try + { + //货架绑定解绑地址 + var url = @"http://192.168.18.150:8181/rcms/services/rest/hikRpcService/bindPodAndBerth"; + + //任务只允许一个一个发送 + lock (lockFlag) + { + var body = new AGVBindPodAndBerthRequest() + { + podCode = shelfCode, + positionCode = locationCode, + pointCode = locationCode, + indBind = ((int)bindPodAndBerthMethod).ToString(), + }; + var response = ApiHelp.GetDataFromHttp(url, body, "POST", true); + //if (response.code == "0" && response.message == "成功") + //{ + + //} + return response; + } + } + catch (Exception ex) + { + return new AGVResponseModel() + { + code = "-1", + message = $"发生异常:{ex.Message}" + }; + } + } + } + + /// + /// 解绑或者绑定 + /// + public enum BindPodAndBerthMethod + { + 解绑 = 0, + 绑定 = 1, } } diff --git a/WCS.BLL/Services/IService/IPDAMatBindService.cs b/WCS.BLL/Services/IService/IPDAMatBindService.cs new file mode 100644 index 0000000..f1d0b4a --- /dev/null +++ b/WCS.BLL/Services/IService/IPDAMatBindService.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WCS.Model; +using WCS.Model.ApiModel.PDAMatBind; +using WCS.Model.WebSocketModel; + +namespace WCS.BLL.Services.IService +{ + /// + /// Pda物料绑定 + /// + public interface IPDAMatBindService + { + public Task callEmptyShelf(BindMatDetailRequest request); + } +} diff --git a/WCS.BLL/Services/Service/PDAMatBindService.cs b/WCS.BLL/Services/Service/PDAMatBindService.cs new file mode 100644 index 0000000..70efe89 --- /dev/null +++ b/WCS.BLL/Services/Service/PDAMatBindService.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WCS.BLL.Manager; +using WCS.BLL.Services.IService; +using WCS.DAL.Db; +using WCS.DAL.DbModels; +using WCS.Model; +using WCS.Model.ApiModel.PDAMatBind; + +namespace WCS.BLL.Services.Service +{ + public class PDAMatBindService : IPDAMatBindService + { + public async Task callEmptyShelf(BindMatDetailRequest request) + { + try + { + #region 参数校验 + //判断参数 + if (request.LocationId == 0 || string.IsNullOrEmpty(request.LocationCode)) + { + return new ResponseCommon() + { + Code = 201, + Message = "工位或工位编码为空!\r\n请重新扫工位码", + Data = null, + }; + } + #endregion + + #region 数据校验 + //获取是否存在当前工位 + var endLocation = await DbHelp.db.Queryable() + .Where(t => t.Id == request.LocationId) + .Where(t => t.IsEnable == true) + .FirstAsync(); + if (endLocation == null) + { + return new ResponseCommon() + { + Code = 201, + Message = $"工位[{request.LocationCode}]不存在或已被禁用!\r\n请联系系统管理人员维护工位信息!", + Data = null, + }; + } + + //获取当前工位的货架 + var shelf = await DbHelp.db.Queryable() + .Where(t => t.CurrentLocationId == endLocation.Id && t.TransStatus == TransStatusEnum.静止 + || t.DestinationLocationId == endLocation.Id && t.TransStatus == TransStatusEnum.运输中)//解决产线人员 呼叫后货架未到的时候绑定的问题 + .Where(t => t.IsEnable == true) + .FirstAsync(); + if (shelf != null) + { + return new ResponseCommon() + { + Code = 205, + Message = $"货架【{shelf.ShelfCode}】在工位上或即将在工位上,请勿重复呼叫!", + Data = null, + }; + } + #endregion + + //获取空货架进行呼叫 + shelf = await DbHelp.db.Queryable() + .Where(t => t.TransStatus == TransStatusEnum.静止 && t.CurrentLocationId != 0) + .Where(t => t.IsEnable == true) + .FirstAsync(); + if (shelf == null) + { + return new ResponseCommon() + { + Code = 201, + Message = $"不存在空货架!", + Data = null, + }; + } + + var startLocation = await DbHelp.db.Queryable() + .Where(t => t.Id == shelf.CurrentLocationId) + .Where(t => t.IsEnable == true) + .FirstAsync(); + + var response = AGVManager.GenAgvSchedulingTask(startLocation, endLocation, shelf.ShelfCode, request.UserName); + if (response.code == "0" && response.message == "成功") + { + //更新货架位置信息 + shelf.TransStatus = TransStatusEnum.运输中; + shelf.DestinationLocationId = endLocation.Id; + shelf.DestinationLocaiotnCode = endLocation.LocationCode; + DbHelp.db.Updateable(shelf).ExecuteCommand(); + + return new ResponseCommon() + { + Code = 200, + Message = "success", + Data = null, + }; + } + else + { + return new ResponseCommon() + { + Code = 201, + Message = $"海康RCS返回:{response.message}", + Data = null, + }; + } + + } + catch (Exception ex) + { + return new ResponseCommon() + { + Code = 201, + Message = ex.Message, + Data = null, + }; + } + } + } +} diff --git a/WCS.BLL/Services/Service/PDAShelfLocationBindUnbindService.cs b/WCS.BLL/Services/Service/PDAShelfLocationBindUnbindService.cs index 8d960ef..4d22838 100644 --- a/WCS.BLL/Services/Service/PDAShelfLocationBindUnbindService.cs +++ b/WCS.BLL/Services/Service/PDAShelfLocationBindUnbindService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using WCS.BLL.Manager; using WCS.BLL.Services.IService; using WCS.DAL.Db; using WCS.DAL.DbModels; @@ -146,19 +147,35 @@ namespace WCS.BLL.Services.Service }; } - //开始绑定 - shelfInfo.CurrentLocaiotnCode = locationInfo.LocationCode; - shelfInfo.CurrentLocationId = locationInfo.Id; - shelfInfo.TransStatus = TransStatusEnum.静止; - DbHelp.db.Updateable(shelfInfo).ExecuteCommand(); - - //返回成功 - return new ResponseCommon() + //调用RCS绑定 + var rcsResponse = AGVManager.BindPodAndBerth(shelfInfo.ShelfCode, locationInfo.LocationCode, BindPodAndBerthMethod.绑定); + if (rcsResponse.code == "0") { - Code = 200, - Message = "success", - Data = null, - }; + //开始绑定 + shelfInfo.CurrentLocaiotnCode = locationInfo.LocationCode; + shelfInfo.CurrentLocationId = locationInfo.Id; + shelfInfo.DestinationLocationId = 0; + shelfInfo.DestinationLocaiotnCode = string.Empty; + shelfInfo.TransStatus = TransStatusEnum.静止; + DbHelp.db.Updateable(shelfInfo).ExecuteCommand(); + + //返回成功 + return new ResponseCommon() + { + Code = 200, + Message = "success", + Data = null, + }; + } + else + { + return new ResponseCommon() + { + Code = 201, + Message = $"RCS返回:{rcsResponse.message}", + Data = null, + }; + } } catch (Exception ex) { @@ -198,21 +215,35 @@ namespace WCS.BLL.Services.Service }; } - //开始解绑 - shelfInfo.CurrentLocationId = 0; - shelfInfo.CurrentLocaiotnCode = string.Empty; - shelfInfo.DestinationLocationId = 0; - shelfInfo.DestinationLocaiotnCode = string.Empty; - shelfInfo.TransStatus = TransStatusEnum.静止; - DbHelp.db.Updateable(shelfInfo).ExecuteCommand(); - - //返回成功 - return new ResponseCommon() + //调用RCS解绑 + var rcsResponse = AGVManager.BindPodAndBerth(shelfInfo.ShelfCode, shelfInfo.CurrentLocaiotnCode, BindPodAndBerthMethod.解绑); + if (rcsResponse.code == "0") { - Code = 200, - Message = "success", - Data = null, - }; + //开始解绑 + shelfInfo.CurrentLocationId = 0; + shelfInfo.CurrentLocaiotnCode = string.Empty; + shelfInfo.DestinationLocationId = 0; + shelfInfo.DestinationLocaiotnCode = string.Empty; + shelfInfo.TransStatus = TransStatusEnum.静止; + DbHelp.db.Updateable(shelfInfo).ExecuteCommand(); + + //返回成功 + return new ResponseCommon() + { + Code = 200, + Message = "success", + Data = null, + }; + } + else + { + return new ResponseCommon() + { + Code = 201, + Message = $"RCS返回:{rcsResponse.message}", + Data = null, + }; + } } catch (Exception ex) { diff --git a/WCS.Model/ApiModel/AGV/AGVBindPodAndBerthRequest.cs b/WCS.Model/ApiModel/AGV/AGVBindPodAndBerthRequest.cs new file mode 100644 index 0000000..d942f14 --- /dev/null +++ b/WCS.Model/ApiModel/AGV/AGVBindPodAndBerthRequest.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WCS.Model.ApiModel.AGV +{ + public class AGVBindPodAndBerthRequest + { + /// + /// 请求码 每一次请求唯一 + /// + public string reqCode { get; set; } = Guid.NewGuid().ToString().Replace("-", ""); + + /// + /// 货架编号 + /// + public string podCode { get; set; } + + /// + /// 点位码 + /// + public string pointCode { get; set; } + + /// + /// 解绑或者绑定 "1":绑定, "0":解绑 + /// + public string indBind { get; set; } + + /// + /// 位置编号 + /// + public string positionCode { get; set; } + } +} diff --git a/WCS.WebApi/Controllers/PDAMatBindController.cs b/WCS.WebApi/Controllers/PDAMatBindController.cs index c87a85c..19bf449 100644 --- a/WCS.WebApi/Controllers/PDAMatBindController.cs +++ b/WCS.WebApi/Controllers/PDAMatBindController.cs @@ -19,11 +19,11 @@ namespace WCS.WebApi.Controllers [Route("[controller]")] public class PDAMatBindController : ControllerBase { - public IWarningService _warningService { get; set; } + public IPDAMatBindService _PDAMatBindService { get; set; } - public PDAMatBindController(IWarningService warningService) + public PDAMatBindController(IPDAMatBindService PDAMatBindService) { - _warningService = warningService; + _PDAMatBindService = PDAMatBindService; } [Route("getShelfInfoByLocationCode")] @@ -275,98 +275,7 @@ namespace WCS.WebApi.Controllers { try { - #region 参数校验 - //判断参数 - if (request.LocationId == 0 || string.IsNullOrEmpty(request.LocationCode)) - { - return new ResponseCommon() - { - Code = 201, - Message = "工位或工位编码为空!\r\n请重新扫工位码", - Data = null, - }; - } - #endregion - - #region 数据校验 - //获取是否存在当前工位 - var endLocation = await DbHelp.db.Queryable() - .Where(t => t.Id == request.LocationId) - .Where(t => t.IsEnable == true) - .FirstAsync(); - if (endLocation == null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"工位[{request.LocationCode}]不存在或已被禁用!\r\n请联系系统管理人员维护工位信息!", - Data = null, - }; - } - - //获取当前工位的货架 - var shelf = await DbHelp.db.Queryable() - .Where(t => t.CurrentLocationId == endLocation.Id && t.TransStatus == TransStatusEnum.静止 - || t.DestinationLocationId == endLocation.Id && t.TransStatus == TransStatusEnum.运输中)//解决产线人员 呼叫后货架未到的时候绑定的问题 - .Where(t => t.IsEnable == true) - .FirstAsync(); - if (shelf != null) - { - return new ResponseCommon() - { - Code = 205, - Message = $"货架【{shelf.ShelfCode}】在工位上或即将在工位上,请勿重复呼叫!", - Data = null, - }; - } - #endregion - - //获取空货架进行呼叫 - shelf = await DbHelp.db.Queryable() - .Where(t => t.TransStatus == TransStatusEnum.静止 && t.CurrentLocationId != 0) - .Where(t => t.IsEnable == true) - .FirstAsync(); - if (shelf == null) - { - return new ResponseCommon() - { - Code = 201, - Message = $"不存在空货架!", - Data = null, - }; - } - - var startLocation = await DbHelp.db.Queryable() - .Where(t => t.Id == shelf.CurrentLocationId) - .Where(t => t.IsEnable == true) - .FirstAsync(); - - var response = AGVManager.GenAgvSchedulingTask(startLocation, endLocation,shelf.ShelfCode,request.UserName); - if (response.code == "0" && response.message == "成功") - { - //更新货架位置信息 - shelf.TransStatus = TransStatusEnum.运输中; - shelf.DestinationLocationId = endLocation.Id; - shelf.DestinationLocaiotnCode = endLocation.LocationCode; - DbHelp.db.Updateable(shelf).ExecuteCommand(); - - return new ResponseCommon() - { - Code = 200, - Message = "success", - Data = null, - }; - } - else - { - return new ResponseCommon() - { - Code = 201, - Message = $"海康RCS返回:{response.message}", - Data = null, - }; - } - + return await _PDAMatBindService.callEmptyShelf(request); } catch (Exception ex) { diff --git a/WCS.WebApi/Program.cs b/WCS.WebApi/Program.cs index bc49a60..b0e3bea 100644 --- a/WCS.WebApi/Program.cs +++ b/WCS.WebApi/Program.cs @@ -92,6 +92,8 @@ namespace WebApi //롢ɵõģʽ builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + var app = builder.Build(); app.UseMiddleware();