From f49af6aceedb33bc02cffa7fbe1faf8275745e2e Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Sat, 22 Feb 2025 11:33:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WCS.BLL/DbModels/STZL/AgvTask.cs | 25 +- WCS.BLL/DbModels/STZL/LocationInfo.cs | 13 ++ WCS.BLL/Manager/AGVManager.cs | 53 ++--- WCS.Model/ApiModel/AGV/AGVTaskModel.cs | 111 +++++++++ WCS.Model/ApiModel/AGV/GetAGVTasksRequest.cs | 29 +++ .../AgvCallbackServiceController.cs | 5 +- WCS.WebApi/Controllers/AgvTaskController.cs | 85 +++++++ 货架标准上位机/ViewModels/AGVTaskViewModel.cs | 170 ++++++++------ 货架标准上位机/Views/AGVTaskView.xaml | 214 ++++++------------ 货架标准上位机/Views/AGVTaskView.xaml.cs | 2 +- 10 files changed, 448 insertions(+), 259 deletions(-) create mode 100644 WCS.Model/ApiModel/AGV/AGVTaskModel.cs create mode 100644 WCS.Model/ApiModel/AGV/GetAGVTasksRequest.cs create mode 100644 WCS.WebApi/Controllers/AgvTaskController.cs diff --git a/WCS.BLL/DbModels/STZL/AgvTask.cs b/WCS.BLL/DbModels/STZL/AgvTask.cs index 4906a64..31871c6 100644 --- a/WCS.BLL/DbModels/STZL/AgvTask.cs +++ b/WCS.BLL/DbModels/STZL/AgvTask.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using WCS.DAL.DbModels; +using WCS.Model.ApiModel.AGV; namespace WCS.BLL.DbModels { @@ -61,7 +62,7 @@ namespace WCS.BLL.DbModels /// 货架码 /// [SugarColumn(ColumnName = "shelf_Code", Length = 64, IsNullable = true, ColumnDescription = "AGV编号")] - public string ShlefCode { get; set; } = string.Empty; + public string ShelfCode { get; set; } = string.Empty; /// /// AGV编号 @@ -81,6 +82,18 @@ namespace WCS.BLL.DbModels [SugarColumn(ColumnName = "create_time", IsNullable = true, ColumnDescription = "任务创建时间")] public DateTime? CreateTime { get; set; } = DateTime.Now; + + /// + /// 最后更新时间 + /// + [SugarColumn(ColumnName = "modify_time", IsNullable = true, ColumnDescription = "最后更新时间")] + public DateTime? ModifyTime { get; set; } = DateTime.Now; + + /// + /// 任务状态 + /// + [SugarColumn(ColumnName = "task_status", IsNullable = true, ColumnDescription = "任务状态")] + public TaskStatusEnum TaskStatus { get; set; } = TaskStatusEnum.已创建; #endregion /// @@ -95,14 +108,4 @@ namespace WCS.BLL.DbModels [SugarColumn(IsIgnore = true)] public bool IsSelected { get; set; } } - - //1-已创建,2-正在执行,5-取消完成,9-已结束, 10-被打断 - public enum TaskStatusEnum - { - 已创建 = 1, - 正在执行 = 2, - 取消完成 = 5, - 已结束 = 9, - 被打断 = 10, - } } diff --git a/WCS.BLL/DbModels/STZL/LocationInfo.cs b/WCS.BLL/DbModels/STZL/LocationInfo.cs index 8dee4fb..b924d4b 100644 --- a/WCS.BLL/DbModels/STZL/LocationInfo.cs +++ b/WCS.BLL/DbModels/STZL/LocationInfo.cs @@ -40,6 +40,19 @@ namespace WCS.DAL.DbModels [SugarColumn(ColumnName = "rcs_store_code", Length = 64, IsNullable = true, ColumnDescription = "RCS库位编号")] public string RcsStoreCode { get; set; } + + /// + /// X坐标 + /// + [SugarColumn(ColumnName = "X", IsNullable = true, DefaultValue = "0", ColumnDescription = "X坐标")] + public decimal X { get; set; } + + /// + /// Y坐标 + /// + [SugarColumn(ColumnName = "Y", IsNullable = true, DefaultValue = "0", ColumnDescription = "Y坐标")] + public decimal Y { get; set; } + /// /// 可放置货架类型 /// diff --git a/WCS.BLL/Manager/AGVManager.cs b/WCS.BLL/Manager/AGVManager.cs index ce0b371..ae30c1b 100644 --- a/WCS.BLL/Manager/AGVManager.cs +++ b/WCS.BLL/Manager/AGVManager.cs @@ -13,10 +13,11 @@ namespace WCS.BLL.Manager //AGV动作相关 public static class AGVManager { + public static object lockFlag = new object(); /// /// 产生AGV点到点搬运任务 /// - public static AGVResponseModel GenAgvSchedulingTask(LocationInfo startLocation,LocationInfo endLocation,string shelfCode,string createUser) + public static AGVResponseModel GenAgvSchedulingTask(LocationInfo startLocation, LocationInfo endLocation, string shelfCode, string createUser) { var url = @"http://192.168.18.150:8181/rcms/services/rest/hikRpcService/genAgvSchedulingTask"; var startPositionCodePathItem = new PositionCodePathItem() @@ -32,36 +33,36 @@ namespace WCS.BLL.Manager positionCodePathItems.Add(startPositionCodePathItem); positionCodePathItems.Add((endPositionCodePathItem)); - var body = new AGVRequestModel() + //任务只允许一个一个发送 + lock (lockFlag) { - positionCodePath = positionCodePathItems, - }; - - var response = ApiHelp.GetDataFromHttp(url,body,"POST",true); - if (response.code == "0" && response.message == "成功") - { - //生成任务数据 - var task = new AgvTask() + var body = new AGVRequestModel() { - ShlefCode = shelfCode, - RequestCode = body.reqCode, - TaskCode = body.taskCode, - TaskType = "GenAgvSchedulingTask", - StratLocationId = startLocation.Id, - StartLocationCode = startLocation.LocationCode, - EndLocationId = endLocation.Id, - EndLocationCode = endLocation.LocationCode, - CreateUser = createUser + positionCodePath = positionCodePathItems, }; - DbHelp.db.Insertable(task).ExecuteCommand(); - } - return response; + var response = ApiHelp.GetDataFromHttp(url, body, "POST", true); + if (response.code == "0" && response.message == "成功") + { + //生成任务数据 + var task = new AgvTask() + { + ShelfCode = shelfCode, + RequestCode = body.reqCode, + TaskCode = body.taskCode, + TaskType = "GenAgvSchedulingTask", + StratLocationId = startLocation.Id, + StartLocationCode = startLocation.LocationCode, + EndLocationId = endLocation.Id, + EndLocationCode = endLocation.LocationCode, + CreateUser = createUser + }; + DbHelp.db.Insertable(task).ExecuteCommand(); + } + + return response; + } } } - public class AGVResult - { - public bool IsSuccess { get; set; } - } } diff --git a/WCS.Model/ApiModel/AGV/AGVTaskModel.cs b/WCS.Model/ApiModel/AGV/AGVTaskModel.cs new file mode 100644 index 0000000..2bcf78b --- /dev/null +++ b/WCS.Model/ApiModel/AGV/AGVTaskModel.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; +using WCS.Model.ApiModel.StoreInfo; + +namespace WCS.Model.ApiModel.AGV +{ + public class AGVTaskModel : INotifyPropertyChanged + { + + /// + /// 主键 自增Id + /// + public int Id { get; set; } + + #region 任务属性 + /// + /// 请求码 + /// + public string RequestCode { get; set; } + + /// + /// 任务码 + /// + public string TaskCode { get; set; } + + /// + /// 任务类型 + /// + public string TaskType { get; set; } = string.Empty; + + /// + /// 起点位置ID + /// + public int StratLocationId { get; set; } = 0; + + /// + /// 起点位置编码 + /// + public string StartLocationCode { get; set; } = string.Empty; + + /// + /// 终点位置ID + /// + public int EndLocationId { get; set; } = 0; + + /// + /// 终点位置编码 + /// + public string EndLocationCode { get; set; } = string.Empty; + + + /// + /// 货架码 + /// + public string ShelfCode { get; set; } = string.Empty; + + /// + /// AGV编号 + /// + public string AgvCode { get; set; } = string.Empty; + + /// + /// 任务发起人 + /// + public string? CreateUser { get; set; } + + /// + /// 任务创建时间 + /// + public DateTime? CreateTime { get; set; } = DateTime.Now; + + + /// + /// 最后更新时间 + /// + public DateTime? ModifyTime { get; set; } = DateTime.Now; + + /// + /// 任务状态 + /// + public TaskStatusEnum TaskStatus { get; set; } = TaskStatusEnum.已创建; + #endregion + + /// + /// 序号 + /// + public int RowNumber { get; set; } + + /// + /// 是否选择 + /// + public bool IsSelected + { + get { return isSelected; } + set + { + isSelected = value; + OnPropertyChanged(nameof(IsSelected)); + } + } + public bool isSelected; + + public event PropertyChangedEventHandler PropertyChanged; + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/WCS.Model/ApiModel/AGV/GetAGVTasksRequest.cs b/WCS.Model/ApiModel/AGV/GetAGVTasksRequest.cs new file mode 100644 index 0000000..fe10def --- /dev/null +++ b/WCS.Model/ApiModel/AGV/GetAGVTasksRequest.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WCS.Model.ApiModel.AGV +{ + public class GetAGVTasksRequest : PageQueryRequestBase + { + public string ShelfCode { get; set; } = string.Empty; + + public string CreateUser { get; set; } = string.Empty; + + public string StartLocationCode { get; set; } = string.Empty; + + public string EndLocationCode { get; set; } = string.Empty; + + public TaskStatusEnum? TaskStatus { get; set; } = null; + } + + //1-已创建,2-正在执行,5-取消完成,9-已结束, 10-被打断 + public enum TaskStatusEnum + { + 已创建 = 1, + 正在执行 = 2, + 取消完成 = 5, + 已结束 = 9, + 被打断 = 10, + } +} diff --git a/WCS.WebApi/Controllers/AgvCallbackServiceController.cs b/WCS.WebApi/Controllers/AgvCallbackServiceController.cs index 9f09877..2bc1134 100644 --- a/WCS.WebApi/Controllers/AgvCallbackServiceController.cs +++ b/WCS.WebApi/Controllers/AgvCallbackServiceController.cs @@ -56,7 +56,7 @@ namespace WCS.WebApi.Controllers } //判断并更新数据 - var shelf = await DbHelp.db.Queryable().Where(t => t.ShelfCode == request.podCode || t.ShelfCode == task.ShlefCode) + var shelf = await DbHelp.db.Queryable().Where(t => t.ShelfCode == request.podCode || t.ShelfCode == task.ShelfCode) .FirstAsync(); if (shelf != null && request.method == "outbin") { @@ -67,6 +67,9 @@ namespace WCS.WebApi.Controllers if (shelf != null && request.method == "end") { + task.TaskStatus = TaskStatusEnum.已结束; + DbHelp.db.Updateable(task).ExecuteCommand(); + shelf.CurrentLocationId = shelf.DestinationLocationId; shelf.CurrentLocaiotnCode = shelf.DestinationLocaiotnCode; shelf.DestinationLocationId = 0; diff --git a/WCS.WebApi/Controllers/AgvTaskController.cs b/WCS.WebApi/Controllers/AgvTaskController.cs new file mode 100644 index 0000000..866a315 --- /dev/null +++ b/WCS.WebApi/Controllers/AgvTaskController.cs @@ -0,0 +1,85 @@ +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using NPOI.SS.Formula.Functions; +using SqlSugar; +using WCS.BLL; +using WCS.BLL.DbModels; +using WCS.BLL.HardWare; +using WCS.BLL.Manager; +using WCS.BLL.Services.IService; +using WCS.BLL.Services.Service; +using WCS.DAL.Db; +using WCS.DAL.DbModels; +using WCS.Model; +using WCS.Model.ApiModel.AGV; +using WCS.Model.ApiModel.Home; +using WCS.Model.ApiModel.StoreInfo; +using Mode = WCS.BLL.HardWare.Mode; + +namespace WCS.WebApi.Controllers +{ + /// + /// 主页面的接口 + /// + [ApiController] + [Route("[controller]")] + public class AgvTaskController : ControllerBase + { + + public AgvTaskController() + { + + } + + /// + /// agv任务回调 + /// + /// + /// + [Route("getAGVTasks")] + [HttpPost(Name = "getAGVTasks")] + public async Task> getAGVTasks(GetAGVTasksRequest request) + { + try + { + var recordsQueryable = DbHelp.db.Queryable() + .WhereIF(string.IsNullOrEmpty(request.ShelfCode), t => t.ShelfCode.Contains(request.ShelfCode)) + .WhereIF(string.IsNullOrEmpty(request.CreateUser), t => t.CreateUser.Contains(request.CreateUser)) + .WhereIF(string.IsNullOrEmpty(request.StartLocationCode), t => t.StartLocationCode.Contains(request.StartLocationCode)) + .WhereIF(string.IsNullOrEmpty(request.EndLocationCode), t => t.StartLocationCode.Contains(request.EndLocationCode)) + .WhereIF(request.TaskStatus !=null, t => t.TaskStatus == request.TaskStatus); + + var totalCount = await recordsQueryable.CountAsync(); + var records = await recordsQueryable + .Skip((request.PageNumber - 1) * request.PageSize).Take(request.PageSize) + .ToListAsync(); + //生成序号 + for (int i = 0; i < records.Count; i++) + { + records[i].RowNumber = (request.PageNumber - 1) * request.PageSize + i + 1; + } + return new PageQueryResponse() + { + Code = 200, + Message = $"success", + Data = new PageQueryResponseData() + { + TotalCount = totalCount, + MaxPage = request.PageSize == 0 ? 0 : (int)Math.Ceiling((decimal)totalCount / request.PageSize), + Count = records.Count, + Lists = records.ToList() + } + }; + } + catch (Exception ex) + { + return new PageQueryResponse() + { + Code = 300, + Message = $"操作失败:{ex.Message}", + }; + } + } + + } +} diff --git a/货架标准上位机/ViewModels/AGVTaskViewModel.cs b/货架标准上位机/ViewModels/AGVTaskViewModel.cs index 558d0e1..8fd9b02 100644 --- a/货架标准上位机/ViewModels/AGVTaskViewModel.cs +++ b/货架标准上位机/ViewModels/AGVTaskViewModel.cs @@ -12,6 +12,8 @@ using WCS.Model.ApiModel; using WCS.Model.ApiModel.MatBaseInfo; using System.Collections.ObjectModel; using WCS.Model.ApiModel.Stocktaking; +using System.Security.AccessControl; +using WCS.Model.ApiModel.AGV; namespace 智慧物流软件系统.ViewModel { @@ -21,19 +23,19 @@ namespace 智慧物流软件系统.ViewModel public AGVTaskViewModel() { //初始化下拉列表框 - StocktakingStatuses.Add("全部"); - var statuses = Enum.GetValues(typeof(StocktakingStatusEnum)) - .Cast() + TaskStatus.Add("全部"); + var statuses = Enum.GetValues(typeof(TaskStatusEnum)) + .Cast() .ToList(); foreach (var status in statuses) { - StocktakingStatuses.Add(status.ToString()); + TaskStatus.Add(status.ToString()); } } #region Property - private ObservableCollection dataGridItemSource; - public ObservableCollection DataGridItemSource + private ObservableCollection dataGridItemSource; + public ObservableCollection DataGridItemSource { get { return dataGridItemSource; } set @@ -42,8 +44,8 @@ namespace 智慧物流软件系统.ViewModel } } - public MatDetailStocktakingInfoModel selectedataGridItem; - public MatDetailStocktakingInfoModel SelectedataGridItem + public AGVTaskModel selectedataGridItem; + public AGVTaskModel SelectedataGridItem { get { return selectedataGridItem; } set @@ -53,49 +55,62 @@ namespace 智慧物流软件系统.ViewModel } /// - /// 物料编码 + /// 货架编码 /// - private string matCode; - public string MatCode + private string shelfCode; + public string ShelfCode { - get { return matCode; } + get { return shelfCode; } set { - SetProperty(ref matCode, value); + SetProperty(ref shelfCode, value); } } /// - /// 物料名称 + /// 任务创建人 /// - private string matName; - public string MatName + private string createUser; + public string CreateUser { - get { return matName; } + get { return createUser; } set { - SetProperty(ref matName, value); + SetProperty(ref createUser, value); } } /// - /// 盘点人 + /// 起点 /// - private string stocktakingUser; - public string StocktakingUser + private string startLocationCode; + public string StartLocationCode { - get { return stocktakingUser; } + get { return startLocationCode; } set { - SetProperty(ref stocktakingUser, value); + SetProperty(ref startLocationCode, value); } } /// - /// 盘点状态列表 + /// 终点 + /// + private string endLocationCode; + public string EndLocationCode + { + get { return endLocationCode; } + set + { + SetProperty(ref endLocationCode, value); + } + } + + /// + /// 结束位置 /// private List stocktakingStatuses = new List(); - public List StocktakingStatuses + public List TaskStatus { get { return stocktakingStatuses; } set @@ -104,26 +119,28 @@ namespace 智慧物流软件系统.ViewModel } } - private string selectedStocktakingStatus; - public string SelectedStocktakingStatus + private string selectedTaskStatus; + public string SelectedTaskStatus { - get { return selectedStocktakingStatus; } + get { return selectedTaskStatus; } set { - SetProperty(ref selectedStocktakingStatus, value); + SetProperty(ref selectedTaskStatus, value); } } - #endregion #region Command public ICommand BtnResetCommand { get => new DelegateCommand(BtnReset); } public void BtnReset() { - MatCode = string.Empty; - MatName = string.Empty; - StocktakingUser = string.Empty; - SelectedStocktakingStatus = StocktakingStatuses.Where(t => t.Contains("未提交")).First(); + ShelfCode = string.Empty; + CreateUser = string.Empty; + + StartLocationCode = string.Empty; + EndLocationCode = string.Empty; + + SelectedTaskStatus = TaskStatus.Where(t => t.Contains("正在执行")).First(); } public ICommand BtnSearchCommand { get => new DelegateCommand(BtnSearchReset); } @@ -138,17 +155,20 @@ namespace 智慧物流软件系统.ViewModel CurrentPage = 1; return; } - var isSelected = Enum.TryParse(SelectedStocktakingStatus, out StocktakingStatusEnum status); + + var isSelected = Enum.TryParse(SelectedTaskStatus, out TaskStatusEnum status); #region 调用接口获取数据 var dia = Dialog.Show(new TextDialog()); try { - var body = new GetStocktakingInfosRequest() + var body = new GetAGVTasksRequest() { - MatCode = MatCode, - MatName = MatName, - StocktakingUser = StocktakingUser, - StocktakingStatus = isSelected ? status : null, + ShelfCode = ShelfCode, + StartLocationCode = StartLocationCode, + EndLocationCode = EndLocationCode, + CreateUser = CreateUser, + + TaskStatus = isSelected ? status : null, UserName = LocalStatic.CurrentUser, DeviceType = LocalFile.Config.DeviceType, @@ -156,10 +176,10 @@ namespace 智慧物流软件系统.ViewModel PageSize = PageSize, }; - var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "PDAStocktaking/getStocktakingInfos", body, "POST"); + var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "AgvTask/getAGVTasks", body, "POST"); if (Result != null && Result.Data != null && Result.Data.Lists != null) { - DataGridItemSource = new ObservableCollection(Result.Data.Lists); + DataGridItemSource = new ObservableCollection(Result.Data.Lists); MaxPage = Result.Data.MaxPage; TotalCount = Result.Data.TotalCount; } @@ -224,39 +244,39 @@ namespace 智慧物流软件系统.ViewModel public ICommand BtnEditCommand { get => new DelegateCommand(BtnEdit); } public async void BtnEdit() { - //查询勾选的第一个数据 - var matDetailStocktakingInfo = DataGridItemSource?.Where(t => t.IsSelected == true).FirstOrDefault(); - if (matDetailStocktakingInfo == null) - { - Growl.Warning("请选择需要修改的数据!"); - return; - } - else - { - var updateView = new MatDetailStocktakingInfoUpdateView("修改盘点数据", matDetailStocktakingInfo); - updateView.ShowDialog(); - if (updateView.DialogResult == true) - { - matDetailStocktakingInfo = updateView.matDetailStocktakingInfo; - var body = new UpdateStocktakingInfoRequest() - { - MatDetailStocktakingInfoId = matDetailStocktakingInfo.Id, - StocktakingQty = matDetailStocktakingInfo.StocktakingQty, - UserName = LocalStatic.CurrentUser, - DeviceType = LocalFile.Config.DeviceType, - }; - var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "PDAStocktaking/updateStocktakingInfos", body, "POST"); - if (Result != null && Result.Code == 200) - { - CurrentPage = 1; - Growl.Success("修改成功!"); - } - else - { - Growl.Error($"{Result?.Message?.ToString()}"); - } - } - } + ////查询勾选的第一个数据 + //var matDetailStocktakingInfo = DataGridItemSource?.Where(t => t.IsSelected == true).FirstOrDefault(); + //if (matDetailStocktakingInfo == null) + //{ + // Growl.Warning("请选择需要修改的数据!"); + // return; + //} + //else + //{ + // var updateView = new MatDetailStocktakingInfoUpdateView("修改盘点数据", matDetailStocktakingInfo); + // updateView.ShowDialog(); + // if (updateView.DialogResult == true) + // { + // matDetailStocktakingInfo = updateView.matDetailStocktakingInfo; + // var body = new UpdateStocktakingInfoRequest() + // { + // MatDetailStocktakingInfoId = matDetailStocktakingInfo.Id, + // StocktakingQty = matDetailStocktakingInfo.StocktakingQty, + // UserName = LocalStatic.CurrentUser, + // DeviceType = LocalFile.Config.DeviceType, + // }; + // var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "PDAStocktaking/updateStocktakingInfos", body, "POST"); + // if (Result != null && Result.Code == 200) + // { + // CurrentPage = 1; + // Growl.Success("修改成功!"); + // } + // else + // { + // Growl.Error($"{Result?.Message?.ToString()}"); + // } + // } + //} } /// diff --git a/货架标准上位机/Views/AGVTaskView.xaml b/货架标准上位机/Views/AGVTaskView.xaml index a8553d3..70d8f42 100644 --- a/货架标准上位机/Views/AGVTaskView.xaml +++ b/货架标准上位机/Views/AGVTaskView.xaml @@ -15,8 +15,8 @@ Padding="0"> - - + + - - - - + + + + - - - + + + + + + Text="{Binding ShelfCode}"> + + + + + + + + + Text="{Binding StartLocationCode}"> + - + Text="{Binding EndLocationCode}"> + + -