diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SE_EDI_Service.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SE_EDI_Service.cs index cd7cf0bc..aee5a3b8 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SE_EDI_Service.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SE_EDI_Service.cs @@ -48,14 +48,14 @@ public class BBAC_SE_EDI_SERVICE : ApplicationService public async Task ExportAsync(RequestDto input) { string fileName = $"BBAC的EDI数据_{Guid.NewGuid()}.xlsx"; - var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); + var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true).ConfigureAwait(false); ; var dtos = ObjectMapper.Map, List>(entities); ExportImporter _exportImporter = new ExportImporter(); - var result = await _exportImporter.ExcelExporter(dtos); + var result = await _exportImporter.ExcelExporter(dtos).ConfigureAwait(false); ; result.ShouldNotBeNull(); - await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }); + await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }).ConfigureAwait(false); ; return fileName; } #endregion @@ -67,8 +67,8 @@ public class BBAC_SE_EDI_SERVICE : ApplicationService [HttpPost] public async Task> GetListAsync(RequestDto input) { - var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true); - var totalCount = await _repository.GetCountByFilterAsync(input.Filters); + var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); + var totalCount = await _repository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); var dtos = ObjectMapper.Map, List>(entities); return new PagedResultDto(totalCount, dtos); } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs index 61b251a4..a42b7b26 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs @@ -92,7 +92,7 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable using var serviceScope = _serviceProvider.CreateScope(); var db = serviceScope.ServiceProvider.GetRequiredService(); //Edi 删除的数据(有发运数据) - var ediDelKeyCodes = db.Set().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct(); + var ediDelKeyCodes = db.Set().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct().ToList(); if (ediDelKeyCodes.Any()) { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs index 92470ab7..9f3ef0cc 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs @@ -109,7 +109,7 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable using var serviceScope = _serviceProvider.CreateScope(); var db = serviceScope.ServiceProvider.GetRequiredService(); //Edi 删除的数据(有发运数据) - var ediDelKeyCodes = db.Set().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct(); + var ediDelKeyCodes = db.Set().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct().ToList(); if (ediDelKeyCodes.Any()) { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeSyncBaseAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeSyncBaseAppService.cs index 078d3753..c472303b 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeSyncBaseAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeSyncBaseAppService.cs @@ -85,7 +85,7 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable return; } await SyncJitRecordAsync().ConfigureAwait(false); - //await SyncJisRecordAsync().ConfigureAwait(false); + await SyncJisRecordAsync().ConfigureAwait(false); } /// @@ -194,7 +194,7 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable if (luRePartCodes.Any()) { var materialRelationships = luRePartCodes.Select(t => new MaterialRelationship(GuidGenerator.Create(), t.FactoryPartCode, "", t.LU, businessType)); - await this.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false); + await _syncExtendManager.AddNewMaterialRelationshipsAsync(materialRelationships).ConfigureAwait(false); } jisSeDetails.ForEach(t => @@ -226,24 +226,4 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable } } } - - /// - /// 添加零件关系 - /// - public async Task AddNewMaterialRelationships(IEnumerable materialRelationships) - { - //新客户零件号和厂内零件号 - var noHaveLuRePartCodes = from item1 in materialRelationships - join item2 in _settleAccountDbContext.Set() - on new { item1.ErpMaterialCode, item1.SettleMaterialCode } equals new { item2.ErpMaterialCode, item2.SettleMaterialCode } - into temp - from item3 in temp.DefaultIfEmpty() - where item3 == null - select item1; - - if (noHaveLuRePartCodes.Any()) - { - await _settleAccountDbContext.BulkInsertAsync(noHaveLuRePartCodes.ToList()).ConfigureAwait(false); - } - } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs index 11af9c82..7dd05aa9 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs @@ -92,7 +92,7 @@ namespace Win.Sfs.SettleAccount.ExcelImporter // Content = memoryStream.ToArray() // } // ); - await fc.SaveAsync(FileOriginName, memoryStream.ToArray(),true).ConfigureAwait(false); + await fc.SaveAsync(FileOriginName, memoryStream.ToArray(), true).ConfigureAwait(false); } ////读取文件保存的根目录 //string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath"); @@ -164,6 +164,8 @@ namespace Win.Sfs.SettleAccount.ExcelImporter public virtual async Task> UploadExcelImportByHeadDesc([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService) where T : class, new() { + using var fs = ServiceProvider.CreateScope(); + var fc = fs.ServiceProvider.GetRequiredService>(); Type type = typeof(T); var ImportList = new List(); ExcelImportResult returnResult = new ExcelImportResult(); @@ -182,54 +184,52 @@ namespace Win.Sfs.SettleAccount.ExcelImporter { //保存成物理文件 await file.CopyToAsync(memoryStream); - await _excelImportService.SaveBlobAsync( - new SaveExcelImportInputDto - { - Name = Path.GetFileName(FileOriginName), - Content = memoryStream.ToArray() - } - ); + //await _excelImportService.SaveBlobAsync( + // new SaveExcelImportInputDto + // { + // Name = Path.GetFileName(FileOriginName), + // Content = memoryStream.ToArray() + // } + // ); + await fc.SaveAsync(FileOriginName, memoryStream.ToArray(), true).ConfigureAwait(false); } - //读取文件保存的根目录 - string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath"); - //读取WMS文件保存的模块的根目录 - string fileSaveDir = ConfigDirHelper.GetAppSetting("App", "WMSFiles"); - //文件保存的相对文件夹(保存到wwwroot目录下) - string absoluteFileDir = fileSaveRootDir + @"\" + fileSaveDir; - //文件保存的路径(应用的工作目录+文件夹相对路径); - string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container" + absoluteFileDir; - var filePath = fileSavePath + getFileName;//获取到导入的excel + ////读取文件保存的根目录 + //string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath"); + ////读取WMS文件保存的模块的根目录 + //string fileSaveDir = ConfigDirHelper.GetAppSetting("App", "WMSFiles"); + ////文件保存的相对文件夹(保存到wwwroot目录下) + //string absoluteFileDir = fileSaveRootDir + @"\" + fileSaveDir; + ////文件保存的路径(应用的工作目录+文件夹相对路径); + //string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container" + absoluteFileDir; + //var filePath = fileSavePath + getFileName;//获取到导入的excel //var import = await _importer.Import(filePath); var import = new ImportResult(); - using (var importer = new ImportHelper(filePath, null)) + using (var stream = new MemoryStream()) { - import = await importer.Import(null); - - Stream Stream = new FileStream(filePath, FileMode.Open); - using (Stream) + await file.CopyToAsync(stream).ConfigureAwait(false); + stream.Position = 0; + IWorkbook wk = new XSSFWorkbook(stream); + //读取当前表数据 + ISheet sheet = wk.GetSheetAt(0); + import = await _importer.Import(await fc.GetAsync(FileOriginName).ConfigureAwait(false)).ConfigureAwait(false); + + var excelImporterHeadDescAttributeProperties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty) + .Where(o => o.GetCustomAttribute(true) != null); + foreach (var item in excelImporterHeadDescAttributeProperties) { - IWorkbook wk = new XSSFWorkbook(Stream); - //读取当前表数据 - ISheet sheet = wk.GetSheetAt(0); + string propertyName = item.Name; + var excelImporterHeadDesc = item.GetCustomAttribute(); + var row = excelImporterHeadDesc.Row; + var cell = excelImporterHeadDesc.Cell; + var value = sheet.GetRow(row).GetCell(cell).ToString(); - var excelImporterHeadDescAttributeProperties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty) - .Where(o => o.GetCustomAttribute(true) != null); - foreach (var item in excelImporterHeadDescAttributeProperties) + if (import.Data != null) { - string propertyName = item.Name; - var excelImporterHeadDesc = item.GetCustomAttribute(); - var row = excelImporterHeadDesc.Row; - var cell = excelImporterHeadDesc.Cell; - var value = sheet.GetRow(row).GetCell(cell).ToString(); - - if (import.Data != null) + foreach (var item2 in import.Data) { - foreach (var item2 in import.Data) - { - item2.GetType().GetProperty(propertyName).SetValue(item2, value); - } + item2.GetType().GetProperty(propertyName).SetValue(item2, value); } } } @@ -291,6 +291,7 @@ namespace Win.Sfs.SettleAccount.ExcelImporter } if (_errorList.Count > 0) { + throw new UserFriendlyException(string.Join("\r\n", _errorList), "400"); throw new BusinessException("8989", string.Join("\r\n", _errorList)); } return ImportList;//返回客户端