From 1c44be282022d24a3495a587f34ba680f8109fcd Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Mon, 3 Mar 2025 16:08:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A7=E6=9E=B6=E7=AE=A1=E7=90=86=E7=9A=84?= =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/IService/IStoreInfoService.cs | 8 ++ WCS.BLL/Services/Service/StoreInfoService.cs | 42 ++++++++ WCS.WebApi/Controllers/StoreInfoController.cs | 26 +++++ .../ViewModels/LocaionInfoViewModel.cs | 1 - .../ViewModels/ShelfInfoViewModel.cs | 37 +++++++ 货架标准上位机/Views/ShelfInfoView.xaml | 97 ++----------------- 6 files changed, 120 insertions(+), 91 deletions(-) diff --git a/WCS.BLL/Services/IService/IStoreInfoService.cs b/WCS.BLL/Services/IService/IStoreInfoService.cs index a1a3814..10d4541 100644 --- a/WCS.BLL/Services/IService/IStoreInfoService.cs +++ b/WCS.BLL/Services/IService/IStoreInfoService.cs @@ -20,6 +20,14 @@ namespace WCS.BLL.Services.IService /// /// public Task> GetShelves(GetShelvesRequest request); + + /// + /// 导出货架列表 + /// + /// + /// + public Task> ExportShelves(GetShelvesRequest request); + /// /// 添加、更新、删除货架 /// diff --git a/WCS.BLL/Services/Service/StoreInfoService.cs b/WCS.BLL/Services/Service/StoreInfoService.cs index 6c33c40..3cb9cf5 100644 --- a/WCS.BLL/Services/Service/StoreInfoService.cs +++ b/WCS.BLL/Services/Service/StoreInfoService.cs @@ -67,6 +67,48 @@ namespace WCS.BLL.Services.Service } } + public async Task> ExportShelves(GetShelvesRequest request) + { + try + { + var recordsQueryable = DbHelp.db.Queryable() + .WhereIF(request.ShelfTypeId != null, t => t.ShelfTypeId == request.ShelfTypeId) + .WhereIF(request.IsEnable != null, t => t.IsEnable == request.IsEnable) + .WhereIF(!string.IsNullOrEmpty(request.ShelfCode), t => t.ShelfCode.Contains(request.ShelfCode)); + + var totalCount = await recordsQueryable.CountAsync(); + var records = await recordsQueryable + .Take(65535) + .ToListAsync(); + //生成序号 + var index = 1; + for (int i = 0; i < records.Count; i++) + { + records[i].RowNumber = index++; + } + 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}", + }; + } + } + public async Task> addOrUpdateShelfInfo(AddShelfInfoRequest request) { try diff --git a/WCS.WebApi/Controllers/StoreInfoController.cs b/WCS.WebApi/Controllers/StoreInfoController.cs index f5706e1..7207a84 100644 --- a/WCS.WebApi/Controllers/StoreInfoController.cs +++ b/WCS.WebApi/Controllers/StoreInfoController.cs @@ -7,6 +7,7 @@ using WCS.Model.ApiModel.StoreInfo; using WCS.BLL.DbModels; using WCS.Model.ApiModel.MatBaseInfo; using WCS.DAL.DbModels; +using WCS.WebApi.Helper; namespace WCS.WebApi.Controllers { @@ -30,6 +31,31 @@ namespace WCS.WebApi.Controllers { return await _storeInfoService.GetShelves(request); } + [Route("exportShelves")] + [HttpPost(Name = "exportShelves")] + public async Task exportShelves(GetShelvesRequest request) + { + var result = await _storeInfoService.ExportShelves(request); + var data = result.Data?.Lists; + var columns = new[] + { + new ExportableColumn("序号","RowNumber"), + new ExportableColumn("货架类型","ShelfTypeName"), + new ExportableColumn("货架编号","ShelfCode"), + new ExportableColumn("货架尺寸","ShelfSize"), + new ExportableColumn("备注","Remark"), + new ExportableColumn("货架当前状态","ShelfStatus"), + new ExportableColumn("启用状态","IsEnableStr"), + new ExportableColumn("更新人", "ModifyUser"), + new ExportableColumn("更新时间", "ModifyTime"), + }; + if (data == null) + { + return NotFound(); + } + else + return ExportExcelHelper.Export("导出数据", columns, data); + } [HttpPost("addOrUpdateShelfInfo")] public async Task> addOrUpdateShelfInfo(AddShelfInfoRequest request) diff --git a/货架标准上位机/ViewModels/LocaionInfoViewModel.cs b/货架标准上位机/ViewModels/LocaionInfoViewModel.cs index 8f77009..9348121 100644 --- a/货架标准上位机/ViewModels/LocaionInfoViewModel.cs +++ b/货架标准上位机/ViewModels/LocaionInfoViewModel.cs @@ -286,7 +286,6 @@ namespace 智慧物流软件系统.ViewModel public ICommand BtnExportCommand { get => new DelegateCommand(BtnExport); } - public async void BtnExport() { try diff --git a/货架标准上位机/ViewModels/ShelfInfoViewModel.cs b/货架标准上位机/ViewModels/ShelfInfoViewModel.cs index 91cdae0..f3742c9 100644 --- a/货架标准上位机/ViewModels/ShelfInfoViewModel.cs +++ b/货架标准上位机/ViewModels/ShelfInfoViewModel.cs @@ -281,6 +281,43 @@ namespace 智慧物流软件系统.ViewModel // } //} } + + public ICommand BtnExportCommand { get => new DelegateCommand(BtnExport); } + public async void BtnExport() + { + try + { + #region 选择文件保存路径 + Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog(); + sfd.Title = "选择文件保存路径"; + sfd.Filter = ".xlsx文件(*.xlsx)|*.xlsx"; + sfd.FileName = "货架管理" + DateTime.Now.ToString("yyyyMMddhhmmss"); + sfd.OverwritePrompt = true; + if (sfd.ShowDialog() != true) + { + return; + } + string path = sfd.FileName; + #endregion + + var body = new GetShelvesRequest() + { + ShelfTypeId = SelectedShelfTypeItem == null ? null : SelectedShelfTypeItem.Id, + ShelfCode = ShelfCode, + IsEnable = IsEnable, + UserName = LocalStatic.CurrentUser, + DeviceType = LocalFile.Config.DeviceType, + PageNumber = CurrentPage, + PageSize = PageSize, + }; + await ApiHelp.PostDownloadFileAsync(path, System.Net.Http.HttpMethod.Post, LocalFile.Config.ApiIpHost + "storeInfo/exportShelves", body); + Growl.Success("导出成功!"); + } + catch (Exception ex) + { + Growl.Error("导出失败:" + ex.Message); + } + } #endregion #region PageOperation 分页操作 diff --git a/货架标准上位机/Views/ShelfInfoView.xaml b/货架标准上位机/Views/ShelfInfoView.xaml index d798ae0..6ff6946 100644 --- a/货架标准上位机/Views/ShelfInfoView.xaml +++ b/货架标准上位机/Views/ShelfInfoView.xaml @@ -59,7 +59,7 @@ 启用 禁用 - + + - -