From dbdeaeaea7c09482e8b570f88f219541b7b1b5b5 Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Sun, 23 Feb 2025 15:59:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=8F=91=E9=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WCS.BLL/Manager/AGVManager.cs | 117 +++++++++++- .../Services/IService/IPDAMatBindService.cs | 3 + WCS.BLL/Services/Service/PDAMatBindService.cs | 167 ++++++++++++++++++ .../ApiModel/AGV/ResendAGVTasksRequest.cs | 16 ++ WCS.WebApi/Controllers/AgvTaskController.cs | 29 ++- WCS.WebApi/Program.cs | 1 - 货架标准上位机/ViewModels/AGVTaskViewModel.cs | 45 +++-- 货架标准上位机/Views/AGVTaskView.xaml | 2 +- 8 files changed, 356 insertions(+), 24 deletions(-) create mode 100644 WCS.Model/ApiModel/AGV/ResendAGVTasksRequest.cs diff --git a/WCS.BLL/Manager/AGVManager.cs b/WCS.BLL/Manager/AGVManager.cs index c399049..55c872f 100644 --- a/WCS.BLL/Manager/AGVManager.cs +++ b/WCS.BLL/Manager/AGVManager.cs @@ -82,6 +82,7 @@ namespace WCS.BLL.Manager } if (isUpdate) { + tasks[i].ModifyTime = DateTime.Now; DbHelp.db.Updateable(tasks[i]).ExecuteCommand(); } } @@ -126,11 +127,42 @@ namespace WCS.BLL.Manager //任务只允许一个一个发送 lock (lockFlag) { + //正在执行中的任务 + var tasks = DbHelp.db.Queryable() + .Where(t => t.TaskStatus == TaskStatusEnum.已创建 || t.TaskStatus == TaskStatusEnum.正在执行) + .ToList(); + //校验货架 + if (tasks.Where(t => t.ShelfCode == shelfCode).Any()) + { + return new AGVResponseModel() + { + code = "-999", + message = $"货架[{shelfCode}]已有执行中的任务!", + }; + } + //校验起点 + if (tasks.Where(t => t.StratLocationId == startLocation.Id).Any()) + { + return new AGVResponseModel() + { + code = "-999", + message = $"工位[{startLocation.LocationCode}]作为起点已有执行中的任务!", + }; + } + //校验终点 + if (tasks.Where(t => t.EndLocationId == endLocation.Id).Any()) + { + return new AGVResponseModel() + { + code = "-999", + message = $"工位[{endLocation.LocationCode}]作为终点已有执行中的任务!", + }; + } + var body = new GenAgvSchedulingTaskRequest() { positionCodePath = positionCodePathItems, }; - var response = ApiHelp.GetDataFromHttp(url, body, "POST", true); if (response.code == "0" && response.message == "成功") { @@ -154,6 +186,89 @@ namespace WCS.BLL.Manager } } + public static AGVResponseModel GenAgvSchedulingTaskForResend(LocationInfo startLocation, LocationInfo endLocation, AgvTask agvTask,string shelfCode, string createUser) + { + var url = @"http://192.168.18.150:8181/rcms/services/rest/hikRpcService/genAgvSchedulingTask"; + var startPositionCodePathItem = new PositionCodePathItem() + { + positionCode = startLocation.RcsStoreCode, + }; + var endPositionCodePathItem = new PositionCodePathItem() + { + positionCode = endLocation.RcsStoreCode, + }; + List positionCodePathItems = new List(); + + positionCodePathItems.Add(startPositionCodePathItem); + positionCodePathItems.Add((endPositionCodePathItem)); + + //任务只允许一个一个发送 + lock (lockFlag) + { + //正在执行中的任务 + var tasks = DbHelp.db.Queryable() + .Where(t => t.TaskStatus == TaskStatusEnum.已创建 || t.TaskStatus == TaskStatusEnum.正在执行) + .ToList(); + //校验货架 + if (tasks.Where(t => t.ShelfCode == shelfCode).Any()) + { + return new AGVResponseModel() + { + code = "-999", + message = $"货架[{shelfCode}]已有执行中的任务!", + }; + } + //校验起点 + if (tasks.Where(t => t.StratLocationId == startLocation.Id).Any()) + { + return new AGVResponseModel() + { + code = "-999", + message = $"工位[{startLocation.LocationCode}]作为起点已有执行中的任务!", + }; + } + //校验终点 + if (tasks.Where(t => t.EndLocationId == endLocation.Id).Any()) + { + return new AGVResponseModel() + { + code = "-999", + message = $"工位[{endLocation.LocationCode}]作为终点已有执行中的任务!", + }; + } + + agvTask.TaskCode = agvTask.TaskCode + "_resend"; + agvTask.CreateTime = DateTime.Now; + agvTask.CreateUser = createUser; + + var body = new GenAgvSchedulingTaskRequest() + { + taskCode = agvTask.TaskCode, + positionCodePath = positionCodePathItems, + }; + var response = ApiHelp.GetDataFromHttp(url, body, "POST", true); + if (response.code == "0" && response.message == "成功") + { + //DbHelp.db.Updateable(agvTask).ExecuteCommand(); + //生成任务数据 + var task = new AgvTask() + { + ShelfCode = shelfCode, + RequestCode = body.reqCode, + TaskCode = agvTask.TaskCode, + TaskType = "GenAgvSchedulingTask", + StratLocationId = startLocation.Id, + StartLocationCode = startLocation.LocationCode, + EndLocationId = endLocation.Id, + EndLocationCode = endLocation.LocationCode, + CreateUser = createUser + }; + DbHelp.db.Insertable(task).ExecuteCommand(); + } + + return response; + } + } /// /// RCS取消任务 /// diff --git a/WCS.BLL/Services/IService/IPDAMatBindService.cs b/WCS.BLL/Services/IService/IPDAMatBindService.cs index f1d0b4a..e532526 100644 --- a/WCS.BLL/Services/IService/IPDAMatBindService.cs +++ b/WCS.BLL/Services/IService/IPDAMatBindService.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using WCS.Model; +using WCS.Model.ApiModel.AGV; using WCS.Model.ApiModel.PDAMatBind; using WCS.Model.WebSocketModel; @@ -15,5 +16,7 @@ namespace WCS.BLL.Services.IService public interface IPDAMatBindService { public Task callEmptyShelf(BindMatDetailRequest request); + + public Task resendAGVTask(ResendAGVTasksRequest request); } } diff --git a/WCS.BLL/Services/Service/PDAMatBindService.cs b/WCS.BLL/Services/Service/PDAMatBindService.cs index 90c0ff9..a2441d7 100644 --- a/WCS.BLL/Services/Service/PDAMatBindService.cs +++ b/WCS.BLL/Services/Service/PDAMatBindService.cs @@ -3,11 +3,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using WCS.BLL.DbModels; using WCS.BLL.Manager; using WCS.BLL.Services.IService; using WCS.DAL.Db; using WCS.DAL.DbModels; using WCS.Model; +using WCS.Model.ApiModel.AGV; using WCS.Model.ApiModel.PDAMatBind; namespace WCS.BLL.Services.Service @@ -113,6 +115,15 @@ namespace WCS.BLL.Services.Service Data = null, }; } + else if(response.code == "-999") + { + return new ResponseCommon() + { + Code = 201, + Message = $"{response.message}\r\n请重试或等待上一个任务完成", + Data = null, + }; + } else { return new ResponseCommon() @@ -134,5 +145,161 @@ namespace WCS.BLL.Services.Service }; } } + + public async Task resendAGVTask(ResendAGVTasksRequest request) + { + try + { + #region 参数、数据校验 + if (request.TaskId == 0 || string.IsNullOrEmpty(request.TaskCode)) + { + return new ResponseCommon() + { + Code = 201, + Message = $"传入参数错误!", + }; + } + + var agvTask = await DbHelp.db.Queryable() + .Where(t => t.Id == request.TaskId) + .Where(t => t.TaskCode == request.TaskCode) + .FirstAsync(); + if (agvTask == null) + { + return new ResponseCommon() + { + Code = 201, + Message = $"任务[{agvTask.TaskCode}]不存在!", + }; + } + + if (agvTask.TaskStatus != TaskStatusEnum.取消完成) + { + return new ResponseCommon() + { + Code = 201, + Message = $"任务[{agvTask.TaskCode}]状态为【{agvTask.TaskStatus}】,无法重新发送!", + }; + } + + if (agvTask.ModifyTime < DateTime.Now.AddMinutes(-10)) + { + return new ResponseCommon() + { + Code = 201, + Message = $"任务取消已超过10分钟,无法重新发送!", + }; + } + #endregion + + #region 起点终点等现有数据校验 + var startLocation = await DbHelp.db.Queryable() + .Where(t => t.Id == agvTask.StratLocationId) + .Where(t => t.IsEnable == true) + .FirstAsync(); + if (startLocation == null) + { + return new ResponseBase() + { + Code = 201, + Message = "任务重新发送失败:起点位置不存在或已被禁用!", + }; + } + + var endLocation = await DbHelp.db.Queryable() + .Where(t => t.Id == agvTask.EndLocationId) + .Where(t => t.IsEnable == true) + .FirstAsync(); + if (endLocation == null) + { + return new ResponseBase() + { + Code = 201, + Message = "任务重新发送失败:终点位置不存在或已被禁用!", + }; + } + //货架 + var shelf = await DbHelp.db.Queryable() + .Where(t => t.ShelfCode == agvTask.ShelfCode) + .Where (t => t.IsEnable == true) + .FirstAsync(); + if (shelf == null) + { + return new ResponseBase() + { + Code = 201, + Message = $"任务重新发送失败:货架{agvTask.ShelfCode}不存在或已被禁用!", + }; + } + if (shelf.TransStatus != TransStatusEnum.静止 || shelf.CurrentLocationId != agvTask.StratLocationId) + { + return new ResponseBase() + { + Code = 201, + Message = $"任务重新发送失败:货架{agvTask.ShelfCode}已不在起点位置{startLocation.LocationCode}!", + }; + } + //查询终点位置是否有货架占用 + var otherShelf = 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 (otherShelf != null) + { + return new ResponseBase() + { + Code = 201, + Message = $"任务重新发送失败:终点位置已被其他货架占用!", + }; + } + #endregion + + #region 调用RCS进行重新发送任务 + var response = AGVManager.GenAgvSchedulingTaskForResend(startLocation, endLocation, agvTask, 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 if (response.code == "-999") + { + return new ResponseCommon() + { + Code = 201, + Message = $"任务重新发送失败:{response.message}\r\n请重试或等待上一个任务完成", + Data = null, + }; + } + else + { + return new ResponseCommon() + { + Code = 201, + Message = $"任务重新发送失败,海康RCS返回:{response.message}", + Data = null, + }; + } + #endregion + } + catch (Exception ex) + { + return new ResponseCommon() + { + Code = 300, + Message = $"任务重新发送失败:{ex.Message}", + }; + } + } } } diff --git a/WCS.Model/ApiModel/AGV/ResendAGVTasksRequest.cs b/WCS.Model/ApiModel/AGV/ResendAGVTasksRequest.cs new file mode 100644 index 0000000..238ed74 --- /dev/null +++ b/WCS.Model/ApiModel/AGV/ResendAGVTasksRequest.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WCS.Model.ApiModel.AGV +{ + /// + /// 取消任务 + /// + public class ResendAGVTasksRequest : RequestBase + { + public int TaskId { get; set; } = 0; + + public string TaskCode { get; set; } + } +} diff --git a/WCS.WebApi/Controllers/AgvTaskController.cs b/WCS.WebApi/Controllers/AgvTaskController.cs index ea00773..a314ba9 100644 --- a/WCS.WebApi/Controllers/AgvTaskController.cs +++ b/WCS.WebApi/Controllers/AgvTaskController.cs @@ -25,10 +25,10 @@ namespace WCS.WebApi.Controllers [Route("[controller]")] public class AgvTaskController : ControllerBase { - - public AgvTaskController() + public IPDAMatBindService _PDAMatBindService { get; set; } + public AgvTaskController(IPDAMatBindService PDAMatBindService) { - + _PDAMatBindService = PDAMatBindService; } /// @@ -155,5 +155,28 @@ namespace WCS.WebApi.Controllers }; } } + + /// + /// 重新发送任务 + /// + /// + /// + [Route("resendAGVTask")] + [HttpPost(Name = "resendAGVTask")] + public async Task resendAGVTask(ResendAGVTasksRequest request) + { + try + { + return await _PDAMatBindService.resendAGVTask(request); + } + catch (Exception ex) + { + return new ResponseCommon() + { + Code = 300, + Message = $"任务重新发送失败:{ex.Message}", + }; + } + } } } diff --git a/WCS.WebApi/Program.cs b/WCS.WebApi/Program.cs index b0e3bea..5bc454f 100644 --- a/WCS.WebApi/Program.cs +++ b/WCS.WebApi/Program.cs @@ -91,7 +91,6 @@ namespace WebApi //롢ɵõģʽ builder.Services.AddSingleton(); - builder.Services.AddSingleton(); var app = builder.Build(); diff --git a/货架标准上位机/ViewModels/AGVTaskViewModel.cs b/货架标准上位机/ViewModels/AGVTaskViewModel.cs index 6b5ec64..bc3b30a 100644 --- a/货架标准上位机/ViewModels/AGVTaskViewModel.cs +++ b/货架标准上位机/ViewModels/AGVTaskViewModel.cs @@ -195,11 +195,13 @@ namespace 智慧物流软件系统.ViewModel #endregion } - - public ICommand BtnCommitCommand { get => new DelegateCommand(BtnCommit); } - public async void BtnCommit() + /// + /// 任务取消 + /// + public ICommand BtnCancelCommand { get => new DelegateCommand(BtnCancel); } + public async void BtnCancel() { - Growl.Ask($"是否提交所有勾选的数据?", isConfirmed => + Growl.Ask($"是否取消所有勾选的任务?", isConfirmed => { if (isConfirmed) { @@ -207,23 +209,28 @@ namespace 智慧物流软件系统.ViewModel var needDeleteIds = DataGridItemSource?.Where(t => t.IsSelected == true) .Select(t => t.Id) .ToList(); - if (needDeleteIds == null) + + + if (needDeleteIds == null || needDeleteIds.Count == 0) { - Growl.Warning("请选择需要提交的数据!"); + Growl.Warning("请选择需要取消的任务!"); + return true; } else { - var body = new DeleteInfosRequest() + var task = DataGridItemSource?.Where(t => t.IsSelected == true).First(); + var body = new CancelAGVTasksRequest() { + TaskId = task == null ? 0 : task.Id, + TaskCode = task?.TaskCode, UserName = LocalStatic.CurrentUser, DeviceType = LocalFile.Config.DeviceType, - needDeleteIds = needDeleteIds, }; - var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "PDAStocktaking/commitStocktakingInfos", body, "POST"); + var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "agvTask/cancelAGVTask", body, "POST"); if (Result != null && Result.Code == 200) { CurrentPage = 1; - Growl.Success("提交成功!" + Result?.Message); + Growl.Success("取消成功!" + Result?.Message); } else { @@ -237,12 +244,12 @@ namespace 智慧物流软件系统.ViewModel /// - /// 物料删除操作 + /// 任务重新发送 /// - public ICommand BtnCancelCommand { get => new DelegateCommand(BtnCancel); } - public async void BtnCancel() + public ICommand BtnResendCommand { get => new DelegateCommand(BtnResend); } + public async void BtnResend() { - Growl.Ask($"是否取消所有勾选的任务?", isConfirmed => + Growl.Ask($"是否重新发送所勾选的任务?", isConfirmed => { if (isConfirmed) { @@ -250,26 +257,28 @@ namespace 智慧物流软件系统.ViewModel var needDeleteIds = DataGridItemSource?.Where(t => t.IsSelected == true) .Select(t => t.Id) .ToList(); - var task = DataGridItemSource?.Where(t => t.IsSelected == true).First(); + if (needDeleteIds == null || needDeleteIds.Count == 0) { Growl.Warning("请选择需要取消的任务!"); + return true; } else { - var body = new CancelAGVTasksRequest() + var task = DataGridItemSource?.Where(t => t.IsSelected == true).First(); + var body = new ResendAGVTasksRequest() { TaskId = task == null ? 0 : task.Id, TaskCode = task?.TaskCode, UserName = LocalStatic.CurrentUser, DeviceType = LocalFile.Config.DeviceType, }; - var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "agvTask/cancelAGVTask", body, "POST"); + var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "agvTask/resendAGVTask", body, "POST"); if (Result != null && Result.Code == 200) { CurrentPage = 1; - Growl.Success("取消成功!" + Result?.Message); + Growl.Success("任务重新发送成功!" + Result?.Message); } else { diff --git a/货架标准上位机/Views/AGVTaskView.xaml b/货架标准上位机/Views/AGVTaskView.xaml index 6dc2e93..e959cc0 100644 --- a/货架标准上位机/Views/AGVTaskView.xaml +++ b/货架标准上位机/Views/AGVTaskView.xaml @@ -146,7 +146,7 @@ FontFamily="{StaticResource IconFont}" Foreground="WhiteSmoke" Background="Green" - Command="{Binding BtnCommitCommand}"> + Command="{Binding BtnResendCommand}">