diff --git a/WCS.BLL/DbModels/STZL/LocationInfo.cs b/WCS.BLL/DbModels/STZL/LocationInfo.cs index 5b7d246..93439d6 100644 --- a/WCS.BLL/DbModels/STZL/LocationInfo.cs +++ b/WCS.BLL/DbModels/STZL/LocationInfo.cs @@ -110,6 +110,8 @@ namespace WCS.DAL.DbModels [SugarColumn(IsIgnore = true)] public List AllowShelfTypesName { get; set; } = new List(); + [SugarColumn(IsIgnore = true)] + public string AllowShelfTypesNameStr { get { return string.Join(",", AllowShelfTypesName); } } /// /// 是否已经选择 /// diff --git a/WCS.BLL/Services/IService/ILocationInfoService.cs b/WCS.BLL/Services/IService/ILocationInfoService.cs index ae61173..8fd6792 100644 --- a/WCS.BLL/Services/IService/ILocationInfoService.cs +++ b/WCS.BLL/Services/IService/ILocationInfoService.cs @@ -15,13 +15,19 @@ namespace WCS.BLL.Services.IService public interface ILocationInfoService { /// - /// 查询货架列表 + /// 查询位置列表 /// /// /// public Task> GetLocationInfos(GetLocationInfosRequest request); /// - /// 添加、更新、删除货架 + /// 导出位置列表 + /// + /// + /// + public Task> ExportLocationInfos(GetLocationInfosRequest request); + /// + /// 添加、更新、删除位置 /// /// /// diff --git a/WCS.BLL/Services/Service/LocationInfoService.cs b/WCS.BLL/Services/Service/LocationInfoService.cs index ccd4f2d..f120cc9 100644 --- a/WCS.BLL/Services/Service/LocationInfoService.cs +++ b/WCS.BLL/Services/Service/LocationInfoService.cs @@ -25,7 +25,11 @@ namespace WCS.BLL.Services.Service { public class LocationInfoService : ILocationInfoService { - + /// + /// 获取位置数据 + /// + /// + /// public async Task> GetLocationInfos(GetLocationInfosRequest request) { try @@ -74,6 +78,58 @@ namespace WCS.BLL.Services.Service } } + /// + /// 导出位置数据 + /// + /// + /// + public async Task> ExportLocationInfos(GetLocationInfosRequest request) + { + try + { + var recordsQueryable = DbHelp.db.Queryable() + .WhereIF(request.LocationAreaId != null, t => t.LocationAreaId == request.LocationAreaId) + .WhereIF(request.IsEnable != null, t => t.IsEnable == request.IsEnable) + .WhereIF(!string.IsNullOrEmpty(request.LocationCode), t => t.LocationCode.Contains(request.LocationCode)); + + var totalCount = await recordsQueryable.CountAsync(); + var records = await recordsQueryable + .Take(65535) + .ToListAsync(); + //获取系统内货架类型 + var shelfTypes = await DbHelp.db.Queryable().ToListAsync(); + + var index = 1; + //生成序号 + for (int i = 0; i < records.Count; i++) + { + records[i].AllowShelfTypesName = shelfTypes.Where(s => records[i].AllowShelfTypes.Contains(s.Id)) + .Select(t => t.ShelfTypeName) + .ToList(); + 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> addOrUpdateLocationInfo(AddLocaionInfoRequest request) { try diff --git a/WCS.WebApi/Controllers/LocationInfoController.cs b/WCS.WebApi/Controllers/LocationInfoController.cs index ae4d7d5..eca2ff8 100644 --- a/WCS.WebApi/Controllers/LocationInfoController.cs +++ b/WCS.WebApi/Controllers/LocationInfoController.cs @@ -10,6 +10,8 @@ using WCS.DAL.DbModels; using WCS.DAL.Db; using WCS.Model.ApiModel.Home; using WCS.Model.ApiModel.LocationInfo; +using WCS.Model.ApiModel.MatDetailCurrentInfo; +using WCS.WebApi.Helper; namespace WCS.WebApi.Controllers { @@ -69,6 +71,31 @@ namespace WCS.WebApi.Controllers return await _locationInfoService.GetLocationInfos(request); } + [Route("exportLocationInfos")] + [HttpPost(Name = "exportLocationInfos")] + public async Task ExportLocationInfos(GetLocationInfosRequest request) + { + var result = await _locationInfoService.ExportLocationInfos(request); + var data = result.Data?.Lists; + var columns = new[] + { + new ExportableColumn("序号","RowNumber"), + new ExportableColumn("位置区域","LocationArea"), + new ExportableColumn("位置编号","LocationCode"), + new ExportableColumn("RCS库位编号","RcsStoreCode"), + new ExportableColumn("可放置货架类型","AllowShelfTypesNameStr"), + new ExportableColumn("启用状态","IsEnableStr"), + new ExportableColumn("更新人", "ModifyUser"), + new ExportableColumn("更新时间", "ModifyTime"), + }; + if (data == null) + { + return NotFound(); + } + else + return ExportExcelHelper.Export("导出数据", columns, data); + } + [HttpPost("addOrUpdateLocationInfo")] public async Task> addOrUpdateLocationInfo(AddLocaionInfoRequest request) { diff --git a/货架标准上位机/ViewModels/LocaionInfoViewModel.cs b/货架标准上位机/ViewModels/LocaionInfoViewModel.cs index 7550745..8f77009 100644 --- a/货架标准上位机/ViewModels/LocaionInfoViewModel.cs +++ b/货架标准上位机/ViewModels/LocaionInfoViewModel.cs @@ -20,6 +20,7 @@ using WCS.Model.ApiModel.User; using WCS.Model.ApiModel; using Newtonsoft.Json.Bson; using WCS.Model.ApiModel.LocationInfo; +using WCS.Model.ApiModel.MatDetailCurrentInfo; namespace 智慧物流软件系统.ViewModel { @@ -282,6 +283,45 @@ 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 GetLocationInfosRequest() + { + LocationAreaId = SelectedLocationAreaItems == null ? null : SelectedLocationAreaItems.Id, + LocationCode = LocationCode, + 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 + "locationInfo/exportLocationInfos", body); + Growl.Success("导出成功!"); + } + catch (Exception ex) + { + Growl.Error("导出失败:" + ex.Message); + } + } #endregion #region PageOperation 分页操作 diff --git a/货架标准上位机/Views/LocationInfoView.xaml b/货架标准上位机/Views/LocationInfoView.xaml index 535097f..a38a1b2 100644 --- a/货架标准上位机/Views/LocationInfoView.xaml +++ b/货架标准上位机/Views/LocationInfoView.xaml @@ -18,12 +18,12 @@ - + - + @@ -116,12 +116,12 @@ > --> - + - - - @@ -215,101 +212,11 @@ Command="{Binding BtnLastPageCommand}"/> - - - diff --git a/货架标准上位机/Views/LocationInfoView.xaml.cs b/货架标准上位机/Views/LocationInfoView.xaml.cs index 788fbd7..67514e1 100644 --- a/货架标准上位机/Views/LocationInfoView.xaml.cs +++ b/货架标准上位机/Views/LocationInfoView.xaml.cs @@ -51,18 +51,7 @@ namespace 智慧物流软件系统 private void DataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) { - //try - //{ - // if (viewModel.SelectedataGridItem != null) - // { - // viewModel.SelectedataGridItem.IsSelected = !viewModel.SelectedataGridItem.IsSelected; - // } - //} - //catch - //{ - - //} } private void allChecked_Checked(object sender, RoutedEventArgs e)