From eda5c94c826fc57fe0ab56a2a00901718a8e1729 Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Mon, 3 Mar 2025 16:38:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E5=AD=98=E7=9B=98=E7=82=B9=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/IStockTakingService.cs | 2 + .../Services/Service/StockTakingService.cs | 72 +++++++++++++++++++ .../Controllers/PDAStocktakingController.cs | 30 ++++++++ .../ViewModels/MatDetailStocktakingInfoViewModel.cs | 51 ++++++++++++- .../Views/MatDetailStocktakingInfoView.xaml | 7 ++ 5 files changed, 159 insertions(+), 3 deletions(-) diff --git a/WCS.BLL/Services/IService/IStockTakingService.cs b/WCS.BLL/Services/IService/IStockTakingService.cs index ed70413..86cdddb 100644 --- a/WCS.BLL/Services/IService/IStockTakingService.cs +++ b/WCS.BLL/Services/IService/IStockTakingService.cs @@ -41,6 +41,8 @@ namespace WCS.BLL.Services.IService public Task> getStocktakingInfos(GetStocktakingInfosRequest request); + public Task> exportStocktakingInfos(GetStocktakingInfosRequest request); + public Task> getStocktakingInfosByShelfCode(GetStocktakingInfosByShelfCodeRequest request); public Task> updateStocktakingInfo(UpdateStocktakingInfoRequest request); diff --git a/WCS.BLL/Services/Service/StockTakingService.cs b/WCS.BLL/Services/Service/StockTakingService.cs index 12546c3..e738010 100644 --- a/WCS.BLL/Services/Service/StockTakingService.cs +++ b/WCS.BLL/Services/Service/StockTakingService.cs @@ -1171,6 +1171,78 @@ namespace WCS.BLL.Services.Service } } + public async Task> exportStocktakingInfos(GetStocktakingInfosRequest request) + { + try + { + var recordsQueryable = DbHelp.db.Queryable() + .LeftJoin((mci, si) => mci.ShlefId == si.Id) + .LeftJoin((mci, si, li) => (si.TransStatus == TransStatusEnum.静止 && si.CurrentLocationId == li.Id) + || (si.TransStatus == TransStatusEnum.运输中 && si.DestinationLocationId == li.Id)) + .WhereIF(!string.IsNullOrEmpty(request.MatCode), (mci, si, li) => mci.MatCode.Contains(request.MatCode)) + .WhereIF(!string.IsNullOrEmpty(request.MatName), (mci, si, li) => mci.MatName.Contains(request.MatName)) + .WhereIF(!string.IsNullOrEmpty(request.StocktakingUser), (mci, si, li) => mci.StocktakingUser.Contains(request.StocktakingUser)) + .WhereIF(request.StocktakingStatus != null, (mci, si, li) => mci.StocktakingStatus == request.StocktakingStatus) + .Select((mci, si, li) => new MatDetailStocktakingInfoModel() + { + Id = mci.Id, + MatDetailCurrentId = mci.MatDetailCurrentId, + + ShlefId = mci.ShlefId, + ShelfCode = mci.ShelfCode, + ShelfType = si.ShelfTypeName, + ShelfArea = li.LocationArea, + + MatCode = mci.MatCode, + MatName = mci.MatName, + MatSpec = mci.MatSpec, + MatQty = mci.MatQty, + StocktakingQty = mci.StocktakingQty, + MatSupplier = mci.MatSupplier, + MatCustomer = mci.MatCustomer, + + StocktakingUser = mci.StocktakingUser, + StocktakingTime = mci.StocktakingTime, + StocktakingStatus = mci.StocktakingStatus, + }); + + //分页 + var totalCount = await recordsQueryable.CountAsync(); + var records = await recordsQueryable + .OrderByDescending(mci => mci.Id) + .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> getStocktakingInfosByShelfCode(GetStocktakingInfosByShelfCodeRequest request) { try diff --git a/WCS.WebApi/Controllers/PDAStocktakingController.cs b/WCS.WebApi/Controllers/PDAStocktakingController.cs index 4570884..910f539 100644 --- a/WCS.WebApi/Controllers/PDAStocktakingController.cs +++ b/WCS.WebApi/Controllers/PDAStocktakingController.cs @@ -4,6 +4,8 @@ using WCS.BLL.Services.Service; using WCS.Model; using WCS.Model.ApiModel.MatBaseInfo; using WCS.Model.ApiModel.Stocktaking; +using WCS.Model.ApiModel.StoreInfo; +using WCS.WebApi.Helper; namespace WCS.WebApi.Controllers { @@ -81,6 +83,34 @@ namespace WCS.WebApi.Controllers } } + [Route("exportStocktakingInfos")] + [HttpPost(Name = "exportStocktakingInfos")] + public async Task exportStocktakingInfos(GetStocktakingInfosRequest request) + { + var result = await _stockTakingService.exportStocktakingInfos(request); + var data = result.Data?.Lists; + var columns = new[] + { + new ExportableColumn("序号","RowNumber"), + new ExportableColumn("物料编码","MatCode"), + new ExportableColumn("物料名称","MatName"), + new ExportableColumn("物料规格","MatSpec"), + new ExportableColumn("货架编号","ShelfCode"), + new ExportableColumn("货架区域","ShelfArea"), + new ExportableColumn("原数量","MatQty"), + new ExportableColumn("盘点数量","StocktakingQty"), + new ExportableColumn("盘点人", "StocktakingUser"), + new ExportableColumn("盘点时间", "StocktakingTime"), + new ExportableColumn("盘点状态", "StocktakingStatus"), + }; + if (data == null) + { + return NotFound(); + } + else + return ExportExcelHelper.Export("导出数据", columns, data); + } + [Route("getStocktakingInfosByShelfCode")] [HttpPost(Name = "getStocktakingInfosByShelfCode")] public async Task getStocktakingInfosByShelfCode(GetStocktakingInfosByShelfCodeRequest request) diff --git a/货架标准上位机/ViewModels/MatDetailStocktakingInfoViewModel.cs b/货架标准上位机/ViewModels/MatDetailStocktakingInfoViewModel.cs index 23346c0..3870b83 100644 --- a/货架标准上位机/ViewModels/MatDetailStocktakingInfoViewModel.cs +++ b/货架标准上位机/ViewModels/MatDetailStocktakingInfoViewModel.cs @@ -12,6 +12,7 @@ using WCS.Model.ApiModel; using WCS.Model.ApiModel.MatBaseInfo; using System.Collections.ObjectModel; using WCS.Model.ApiModel.Stocktaking; +using WCS.Model.ApiModel.StoreInfo; namespace 智慧物流软件系统.ViewModel { @@ -131,6 +132,7 @@ namespace 智慧物流软件系统.ViewModel { BtnSearch(true); } + public void BtnSearch(bool IsPageReset = true) { if (CurrentPage == 0 || IsPageReset) @@ -175,9 +177,8 @@ namespace 智慧物流软件系统.ViewModel #endregion } - /// - /// 物料删除操作 + /// 盘点提交操作 /// public ICommand BtnCommitCommand { get => new DelegateCommand(BtnCommit); } public async void BtnCommit() @@ -218,6 +219,7 @@ namespace 智慧物流软件系统.ViewModel }); } + /// /// 物料修改操作 /// @@ -265,7 +267,7 @@ namespace 智慧物流软件系统.ViewModel public ICommand BtnDeleteCommand { get => new DelegateCommand(BtnDelete); } public async void BtnDelete() { - Growl.Ask($"是否删除所有勾选得数据]!", isConfirmed => + Growl.Ask($"是否删除所有勾选的数据?", isConfirmed => { if (isConfirmed) { @@ -301,6 +303,49 @@ namespace 智慧物流软件系统.ViewModel return true; }); } + + /// + /// 导出功能 + /// + 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 isSelected = Enum.TryParse(SelectedStocktakingStatus, out StocktakingStatusEnum status); + var body = new GetStocktakingInfosRequest() + { + MatCode = MatCode, + MatName = MatName, + StocktakingUser = StocktakingUser, + StocktakingStatus = isSelected ? status : null, + + UserName = LocalStatic.CurrentUser, + DeviceType = LocalFile.Config.DeviceType, + PageNumber = CurrentPage, + PageSize = PageSize, + + }; + await ApiHelp.PostDownloadFileAsync(path, System.Net.Http.HttpMethod.Post, LocalFile.Config.ApiIpHost + "PDAStocktaking/exportStocktakingInfos", body); + Growl.Success("导出成功!"); + } + catch (Exception ex) + { + Growl.Error("导出失败:" + ex.Message); + } + } #endregion #region PageOperation 分页操作 diff --git a/货架标准上位机/Views/MatDetailStocktakingInfoView.xaml b/货架标准上位机/Views/MatDetailStocktakingInfoView.xaml index 01148d6..9eebd19 100644 --- a/货架标准上位机/Views/MatDetailStocktakingInfoView.xaml +++ b/货架标准上位机/Views/MatDetailStocktakingInfoView.xaml @@ -137,6 +137,13 @@ Foreground="WhiteSmoke" Command="{Binding BtnDeleteCommand}" Style="{StaticResource ButtonDanger}"> + +