From ab16c5eb607067d6357755c457b143ecb5284926 Mon Sep 17 00:00:00 2001 From: zhouhongjun <565221961@qq.com> Date: Thu, 11 Jul 2024 09:26:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E6=96=B9=E6=AF=94=E5=AF=B9=E6=8C=89?= =?UTF-8?q?=E7=B1=BB=E5=88=AB=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Report/NopiDataToExcel.cs | 71 ++++++++++--------- .../Report/SaSeEdiCompareExportBaseService.cs | 13 ++-- .../Report/SeEdiCompareExportBaseService.cs | 2 +- 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/NopiDataToExcel.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/NopiDataToExcel.cs index 746ead7a..7d54125f 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/NopiDataToExcel.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/NopiDataToExcel.cs @@ -37,7 +37,7 @@ namespace SettleAccount.Job.Services.Report /// 页签名称 /// 数据 /// 缓存文件行数 - public async Task WriteDataToExcelInParallel(string sheetName, List data, int chunkSize,string zipFileName, List sumdata) + public async Task WriteDataToExcelInParallel(string sheetName, List data, int chunkSize,string zipFileName, List sumdata,bool isFinish) { var count = data.Count / 1000000 + ((data.Count % 1000000) > 0 ? 1 : 0); for (var i = 1; i <= count; i++) @@ -61,54 +61,55 @@ namespace SettleAccount.Job.Services.Report } - string[] filePaths = excelFiles.Select(x => x.FileName).ToArray(); - string zipPath = zipFileName; - using (var archive = ZipFile.Open(zipPath, ZipArchiveMode.Create)) + if(isFinish) { - foreach (var file in filePaths) + string[] filePaths = excelFiles.Select(x => x.FileName).ToArray(); + string zipPath = zipFileName; + using (var archive = ZipFile.Open(zipPath, ZipArchiveMode.Create)) { - archive.CreateEntryFromFile(file, Path.GetFileName(file)); + foreach (var file in filePaths) + { + archive.CreateEntryFromFile(file, Path.GetFileName(file)); + } } - } - for (var i = 0; i < count; i++) - { - var filelist = excelFiles.Select(p => p.FileName).ToList(); - - foreach (var file in filelist) + for (var i = 0; i < count; i++) { - File.Delete(file); + var filelist = excelFiles.Select(p => p.FileName).ToList(); + + foreach (var file in filelist) + { + File.Delete(file); + } } - } - using (FileStream fileStream = new FileStream(zipPath, FileMode.Open)) - { - var minioClient = new MinioClient(EndPoint, AccessKey, SecretKey, ""); - try + using (FileStream fileStream = new FileStream(zipPath, FileMode.Open)) { - await minioClient.PutObjectAsync(BucketName, "host/"+zipPath, fileStream, fileStream.Length, "application/zip").ConfigureAwait(false); - + var minioClient = new MinioClient(EndPoint, AccessKey, SecretKey, ""); + try + { + await minioClient.PutObjectAsync(BucketName, "host/" + zipPath, fileStream, fileStream.Length, "application/zip").ConfigureAwait(false); - } - catch (Exception ex) - { - Console.WriteLine($"上传文件到 MinIO 时发生错误: {ex.Message}"); - } - finally - { - if (fileStream != null) + + } + catch (Exception ex) + { + Console.WriteLine($"上传文件到 MinIO 时发生错误: {ex.Message}"); + } + finally { - fileStream.Close(); - File.Delete(zipPath); + if (fileStream != null) + { + fileStream.Close(); + File.Delete(zipPath); + } + } - + } } - //using (FileStream fileStream = new FileStream(zipPath, FileMode.Open)) - //{ - // return fileStream.GetAllBytes(); - //} + return zipFileName; } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeEdiCompareExportBaseService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeEdiCompareExportBaseService.cs index 89704b99..e3877eba 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeEdiCompareExportBaseService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeEdiCompareExportBaseService.cs @@ -240,7 +240,7 @@ namespace SettleAccount.Job.Services.Report /// /// 根据单Sheel最大行数配置分Sheel页导出 /// - public string BindExcelExporter(List saSeEdiCompareDetailExports, string businessTypeDisplayName,string fileName) where T : SaSeEdiCompareDetailReport, new() + public string BindExcelExporter(List saSeEdiCompareDetailExports, string businessTypeDisplayName,string fileName) where T : SaSeEdiCompareDetailReport, new() { //详情Sheet行数 var detailMaxRowNumberOnASheet = AppConst.DefaultRowNumberOnASheet; @@ -308,9 +308,9 @@ namespace SettleAccount.Job.Services.Report #region 多线程生成Excel - haveSaNotHaveSeExport.AddRange(notHaveSaHaveSeExports); + //haveSaNotHaveSeExport.AddRange(notHaveSaHaveSeExports); - haveSaNotHaveSeExport.AddRange(haveSaHaveSeExport); + //haveSaNotHaveSeExport.AddRange(haveSaHaveSeExport); NopiExtendExcel nopiExcel = new NopiExtendExcel(); @@ -322,8 +322,13 @@ namespace SettleAccount.Job.Services.Report nopiExcel.EndPoint = _cfg.GetValue("MinIO:EndPoint", "localhost:10684"); - var uploadResult = nopiExcel.WriteDataToExcelInParallel($"{businessTypeDisplayName}结算数据和发货对比", haveSaNotHaveSeExport, 500000, fileName, haveSaHaveSeSumExports).ConfigureAwait(false); + //var uploadResult = nopiExcel.WriteDataToExcelInParallel($"{businessTypeDisplayName}结算数据和发货对比", haveSaNotHaveSeExport, 500000, fileName, haveSaHaveSeSumExports, false).ConfigureAwait(false); + nopiExcel.WriteDataToExcelInParallel($"{businessTypeDisplayName}结算和发货对比_有结无发", haveSaNotHaveSeExport, 500000, fileName, null, false).ConfigureAwait(false); + + nopiExcel.WriteDataToExcelInParallel($"{businessTypeDisplayName}结算和发货对比_有发无结", notHaveSaHaveSeExports, 500000, fileName, null, false).ConfigureAwait(false); + + nopiExcel.WriteDataToExcelInParallel($"{businessTypeDisplayName}结算和发货对比_有结有发", haveSaHaveSeExport, 500000, fileName, haveSaHaveSeSumExports, true).ConfigureAwait(false); return fileName; #endregion diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SeEdiCompareExportBaseService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SeEdiCompareExportBaseService.cs index 6b4925c8..afdd5d70 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SeEdiCompareExportBaseService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SeEdiCompareExportBaseService.cs @@ -232,7 +232,7 @@ namespace SettleAccount.Job.Services.Report nopiExcelHaveEdiNotHaveSe.EndPoint = _cfg.GetValue("MinIO:EndPoint", "localhost:10684"); - var uploadResult = nopiExcelHaveEdiNotHaveSe.WriteDataToExcelInParallel($"{businessTypeDisplayName}EDI数据和发货对比", haveEdiNotHaveSeList, 500000,fileName,null).ConfigureAwait(false); + var uploadResult = nopiExcelHaveEdiNotHaveSe.WriteDataToExcelInParallel($"{businessTypeDisplayName}EDI数据和发货对比", haveEdiNotHaveSeList, 500000,fileName,null,true).ConfigureAwait(false); return fileName;