From d99f72ecf4128228ef3e93d0748bfc3b367a675e Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Mon, 3 Mar 2025 14:14:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E8=B4=A7=E6=9E=B6=E5=AD=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IService/IMatDetailCurrentInfoService.cs | 8 +- .../Service/MatDetailCurrentInfoService.cs | 71 +++++++++++++++ .../MatDetailCurrenInfoController.cs | 29 ++++++ .../ViewModels/MatDetailCurrentInfoViewModel.cs | 45 +++++++++ 货架标准上位机/Views/MatBaseInfoView.xaml | 91 +------------------ 5 files changed, 153 insertions(+), 91 deletions(-) diff --git a/WCS.BLL/Services/IService/IMatDetailCurrentInfoService.cs b/WCS.BLL/Services/IService/IMatDetailCurrentInfoService.cs index 68139f7..2fb416d 100644 --- a/WCS.BLL/Services/IService/IMatDetailCurrentInfoService.cs +++ b/WCS.BLL/Services/IService/IMatDetailCurrentInfoService.cs @@ -15,7 +15,13 @@ namespace WCS.BLL.Services.IService /// /// public Task> GetMatDetailCurrentInfos(GetMatDetailCurrentInfosRequest request); - + /// + /// 导出货架存量数据 + /// + /// + /// + public Task> ExportMatDetailCurrentInfos(GetMatDetailCurrentInfosRequest request); + /// /// 更新货架存量 /// diff --git a/WCS.BLL/Services/Service/MatDetailCurrentInfoService.cs b/WCS.BLL/Services/Service/MatDetailCurrentInfoService.cs index b71958a..700d2cb 100644 --- a/WCS.BLL/Services/Service/MatDetailCurrentInfoService.cs +++ b/WCS.BLL/Services/Service/MatDetailCurrentInfoService.cs @@ -99,6 +99,77 @@ namespace WCS.BLL.Services.Service } } + public async Task> ExportMatDetailCurrentInfos(GetMatDetailCurrentInfosRequest request) + { + try + { + var recordsQueryable = DbHelp.db.Queryable() + .LeftJoin((mci, si) => mci.ShelfId == si.Id) + .LeftJoin((mci, si, li) => (si.TransStatus == TransStatusEnum.静止 && si.CurrentLocationId == li.Id) + || (si.TransStatus == TransStatusEnum.运输中 && si.DestinationLocationId == li.Id)) + .WhereIF(request.LocationAreaId != null && request.LocationAreaId != 0, (mci, si, li) => li.LocationAreaId == request.LocationAreaId) + .WhereIF(!string.IsNullOrEmpty(request.LocationCode), (mci, si, li) => li.LocationCode.Contains(request.LocationCode)) + .WhereIF(request.ShelfTypeId != null && request.ShelfTypeId != 0, (mci, si, li) => si.ShelfTypeId == request.ShelfTypeId) + .WhereIF(!string.IsNullOrEmpty(request.ShelfCode), (mci, si, li) => si.ShelfCode.Contains(request.ShelfCode)) + .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)) + .Select((mci, si, li) => new MatDetailCurrentInfoModel() + { + Id = mci.Id, + ShelfId = mci.ShelfId, + ShelfCode = mci.ShelfCode, + ShelfType = mci.ShelfType, + + LocationArea = li.LocationArea, + LocationCode = li.LocationCode, + + MatCode = mci.MatCode, + MatName = mci.MatName, + MatSpec = mci.MatSpec, + MatUnit = mci.MatUnit, + MatCustomer = mci.MatCustomer, + MatQty = mci.MatQty, + MatSupplier = mci.MatSupplier, + + StationCode = mci.StationCode, + ModifyUser = mci.ModifyUser, + ModifyTime = mci.ModifyTime + }); + //分页 + 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> updateMatDetailCurrentInfo(AddLocaionInfoRequest request) { try diff --git a/WCS.WebApi/Controllers/MatDetailCurrenInfoController.cs b/WCS.WebApi/Controllers/MatDetailCurrenInfoController.cs index 197e6d2..d1ab164 100644 --- a/WCS.WebApi/Controllers/MatDetailCurrenInfoController.cs +++ b/WCS.WebApi/Controllers/MatDetailCurrenInfoController.cs @@ -7,6 +7,7 @@ using WCS.BLL.DbModels; using WCS.Model.ApiModel.MatBaseInfo; using WCS.Model.ApiModel.MatDetailCurrentInfo; using WCS.DAL.DbModels; +using WCS.WebApi.Helper; namespace WCS.WebApi.Controllers { @@ -31,6 +32,34 @@ namespace WCS.WebApi.Controllers return await _matDetailCurrentInfoService.GetMatDetailCurrentInfos(request); } + [Route("exportMatDetailCurrentInfos")] + [HttpPost(Name = "exportMatDetailCurrentInfos")] + public async Task ExportMatDetailCurrentInfos(GetMatDetailCurrentInfosRequest request) + { + var result = await _matDetailCurrentInfoService.ExportMatDetailCurrentInfos(request); + var data = result.Data?.Lists; + var columns = new[] + { + new ExportableColumn("序号","RowNumber"), + new ExportableColumn("货架类型","ShelfType"), + new ExportableColumn("货架编码","ShelfCode"), + new ExportableColumn("位置区域","LocationArea"), + new ExportableColumn("位置编号","LocationCode"), + new ExportableColumn("物料编码","MatCode"), + new ExportableColumn("物料名称","MatName"), + new ExportableColumn("物料规格","MatSpec"), + new ExportableColumn("数量", "MatQty"), + new ExportableColumn("更新人", "ModifyUser"), + new ExportableColumn("更新时间", "ModifyTime"), + }; + if (data == null) + { + return NotFound(); + } + else + return ExportExcelHelper.Export("导出数据", columns, data); + } + [HttpPost("updateMatDetailCurrentInfo")] public async Task> updateMatDetailCurrentInfo(AddLocaionInfoRequest request) { diff --git a/货架标准上位机/ViewModels/MatDetailCurrentInfoViewModel.cs b/货架标准上位机/ViewModels/MatDetailCurrentInfoViewModel.cs index 23a2473..844ddb5 100644 --- a/货架标准上位机/ViewModels/MatDetailCurrentInfoViewModel.cs +++ b/货架标准上位机/ViewModels/MatDetailCurrentInfoViewModel.cs @@ -327,6 +327,51 @@ namespace 智慧物流软件系统.ViewModel return true; }); } + + + /// + /// 导出数据为Excel文件 + /// + 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 GetMatDetailCurrentInfosRequest() + { + LocationAreaId = SelectedLocationAreaItems == null ? null : SelectedLocationAreaItems.Id, + LocationCode = LocationCode, + ShelfTypeId = SelectedShelfTypeItem == null ? null : selectedShelfTypeItem.Id, + ShelfCode = ShelfCode, + MatCode = MatCode, + MatName = MatName, + + UserName = LocalStatic.CurrentUser, + DeviceType = LocalFile.Config.DeviceType, + PageNumber = CurrentPage, + PageSize = PageSize, + }; + await ApiHelp.PostDownloadFileAsync(path, System.Net.Http.HttpMethod.Post, LocalFile.Config.ApiIpHost + "matDetailCurrenInfo/exportMatDetailCurrentInfos", body); + Growl.Success("导出成功!"); + } + catch (Exception ex) + { + Growl.Error("导出失败:" + ex.Message); + } + } #endregion #region PageOperation 分页操作 diff --git a/货架标准上位机/Views/MatBaseInfoView.xaml b/货架标准上位机/Views/MatBaseInfoView.xaml index 8c330f8..72c9bd2 100644 --- a/货架标准上位机/Views/MatBaseInfoView.xaml +++ b/货架标准上位机/Views/MatBaseInfoView.xaml @@ -148,7 +148,7 @@ - + @@ -221,95 +221,6 @@ - -