diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SE_DETAIL_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SE_DETAIL_SERVICE.cs index a357e541..816fceda 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SE_DETAIL_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SE_DETAIL_SERVICE.cs @@ -1,6 +1,13 @@ +using Castle.Core.Internal; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Spreadsheet; +using Magicodes.ExporterAndImporter.Core; +using Magicodes.ExporterAndImporter.Excel; +using Magicodes.ExporterAndImporter.Excel.Utility; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.OpenApi.Extensions; +using NPOI.HPSF; using SettleAccount.Domain.BQ; using Shouldly; using SqlSugar; @@ -8,12 +15,15 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using System.Security.Cryptography; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; +using Volo.Abp.BlobStoring; using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.ExcelImporter; +using Win.Sfs.SettleAccount.Reports; using Win.Sfs.Shared.Filter; using Win.Sfs.Shared.RepositoryBase; namespace Win.Sfs.SettleAccount.Entities.BQ @@ -34,14 +44,19 @@ namespace Win.Sfs.SettleAccount.Entities.BQ /// excel服务 /// private readonly IExcelImportAppService _excelImportService; + /// + /// 文件容器 + /// + private readonly IBlobContainer _fileContainer; /// /// 构造 /// - public PUB_SE_DETAIL_SERVICE(INormalEfCoreRepository repository, IExcelImportAppService excelImportService) + public PUB_SE_DETAIL_SERVICE(INormalEfCoreRepository repository, IExcelImportAppService excelImportService, IBlobContainer fileContainer) { _repository = repository; _excelImportService = excelImportService; + _fileContainer = fileContainer; } #region 导出 @@ -70,6 +85,86 @@ namespace Win.Sfs.SettleAccount.Entities.BQ await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }).ConfigureAwait(false); return fileName; } + + [HttpGet] + public async Task TextExportAsync() + { + var fileName = $"发运数据_{Guid.NewGuid()}.xlsx"; + var haveEdiHaveSeList = new List(); + + for (int i = 0; i < 2_000_000; i++) + { + haveEdiHaveSeList.Add(new JisBBACEidSeCompareExport() + { + Category = "JIS", + WmsBillNum = i.ToString(), + CarModeCode = i.ToString(), + LineStationcode = i.ToString(), + SequenceNumber = i.ToString(), + ParType = i.ToString(), + MESConfigCode = i.ToString(), + ShippingDate = DateTime.Now, + PN = i.ToString(), + Seq = i.ToString(), + PjsNum = i.ToString(), + MaterialNumber = i.ToString(), + MaterialDes = i.ToString(), + SEQty = 1, + EdiQty = 1, + AssemblyDate = DateTime.Now, + MatchNumber = i.ToString(), + InjectionCode = i.ToString(), + MateType = "是", + DiffDesc = "WMS有发货EDI有订单" + }); + } + + var jisBBACEidSeCompareEexcelExporterAttribute = typeof(JisBBACEidSeCompareExport).GetAttribute(); + var jisBBACEidSeCompareEexcelMaxRowNumberOnASheet = 9_000_000; + if (jisBBACEidSeCompareEexcelExporterAttribute != null) + { + jisBBACEidSeCompareEexcelMaxRowNumberOnASheet = jisBBACEidSeCompareEexcelExporterAttribute.MaxRowNumberOnASheet > 0 ? jisBBACEidSeCompareEexcelExporterAttribute.MaxRowNumberOnASheet : jisBBACEidSeCompareEexcelMaxRowNumberOnASheet; + } + + ExcelExporter excelExporter = new ExcelExporter(); + excelExporter.Append(haveEdiHaveSeList.Take(jisBBACEidSeCompareEexcelMaxRowNumberOnASheet).ToList(), $"BBACEDI数据和发货对比"); + + var ediSheetCount = (int)(haveEdiHaveSeList.Count / jisBBACEidSeCompareEexcelMaxRowNumberOnASheet) + ((haveEdiHaveSeList.Count % jisBBACEidSeCompareEexcelMaxRowNumberOnASheet) > 0 ? 1 : 0); + if (ediSheetCount > 1) + { + for (int i = 1; i < ediSheetCount; i++) + { + var sheetDataItems = haveEdiHaveSeList.Skip(i * jisBBACEidSeCompareEexcelMaxRowNumberOnASheet) + .Take(jisBBACEidSeCompareEexcelMaxRowNumberOnASheet).ToList(); + excelExporter.SeparateBySheet(); + excelExporter.Append(sheetDataItems, $"BBACEDI数据和发货对比-{i}"); + } + } + + excelExporter.Append(haveEdiHaveSeList.Take(jisBBACEidSeCompareEexcelMaxRowNumberOnASheet).ToList(), $"BBAC发货和EDI数据对比"); + var seSheetCount = (int)(haveEdiHaveSeList.Count / jisBBACEidSeCompareEexcelMaxRowNumberOnASheet) + ((haveEdiHaveSeList.Count % jisBBACEidSeCompareEexcelMaxRowNumberOnASheet) > 0 ? 1 : 0); + if (seSheetCount > 1) + { + for (int i = 1; i < seSheetCount; i++) + { + var sheetDataItems = haveEdiHaveSeList.Skip(i * jisBBACEidSeCompareEexcelMaxRowNumberOnASheet) + .Take(jisBBACEidSeCompareEexcelMaxRowNumberOnASheet).ToList(); + excelExporter.SeparateBySheet(); + excelExporter.Append(sheetDataItems, $"BBAC发货和EDI数据对比-{i}"); + } + } + + //excelExporter + // .Append(haveEdiHaveSeList, $"BBACEDI数据和发货对比"); + //.SeparateBySheet() + ////.Append(haveEdiHaveSeList, $"BBAC发货和EDI数据对比"); + + var result = excelExporter.ExportAppendDataAsByteArray(); + await result.ShouldNotBeNull().ConfigureAwait(false); + await _fileContainer.SaveAsync(fileName, result.Result, true).ConfigureAwait(false); + return fileName; + } + #endregion #region 查询 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 d9fe5bb5..e70ace91 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 @@ -92,8 +92,6 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable ediDetails.ForEach(t => t.IsHaveSeData = true); db.BulkUpdate(ediDetails); } - await uow.SaveChangesAsync().ConfigureAwait(false); - //db.SaveChanges(); } } catch (Exception) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/JisBBACEidSeCompareReport.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/JisBBACEidSeCompareReport.cs index 00916add..02e6cbdc 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/JisBBACEidSeCompareReport.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/JisBBACEidSeCompareReport.cs @@ -15,7 +15,7 @@ public class JisBBACEidSeCompareReport /// /// JisBBAC Edi、发运对比导出 /// -[ExcelExporter(MaxRowNumberOnASheet = 900000)] +[ExcelExporter(MaxRowNumberOnASheet = 500_000)] public class JisBBACEidSeCompareExport { /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/SaSeEdiCompareDiff.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/SaSeEdiCompareDiff.cs index 0d026594..402ef027 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/SaSeEdiCompareDiff.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/SaSeEdiCompareDiff.cs @@ -135,7 +135,7 @@ public class SaSeEdiCompareDiff /// /// 结算、发运、Eid对比明细 /// -[ExcelExporter(MaxRowNumberOnASheet = 900000)] +[ExcelExporter(MaxRowNumberOnASheet = 500_000)] public class SaSeEdiCompareDetailExport { } @@ -192,7 +192,6 @@ public interface ISaSeEdiCompareDetailExport /// /// JisBBAC结算、发运、Eid对比明细 /// - public class SaSeEdiCompareDetailExportJisBBAC : SaSeEdiCompareDetailExport, ISaSeEdiCompareDetailExport { /// @@ -477,7 +476,7 @@ public class SaSeEdiCompareDetailExportJisHBPO : SaSeEdiCompareDetailExport, ISa /// /// PUB结算与发运对比汇总 /// -[ExcelExporter(MaxRowNumberOnASheet = 900000)] +[ExcelExporter(MaxRowNumberOnASheet = 500_000)] public class SaSeEdiCompareSumExport { /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSeEdiCompareExportService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSeEdiCompareExportService.cs index 03accd57..97dbde56 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSeEdiCompareExportService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSeEdiCompareExportService.cs @@ -71,10 +71,10 @@ namespace SettleAccount.Job.Services.Report .Select(t => new JisBBACEidSeCompareExport() { Category = "JIS", - CarModeCode = default, - LineStationcode = default, - SequenceNumber = t.Max(t => t.SeqNumber), - ParType = "01", + CarModeCode = t.Max(t => t.Extend4), + LineStationcode = t.Max(t => t.LineStationCode), + SequenceNumber = t.Max(t => t.Extend3), + ParType = t.Max(t => t.Extend2), PN = t.Key.PN, MaterialNumber = t.Key.LU, EdiQty = t.Sum(t => t.Qty), @@ -111,7 +111,10 @@ namespace SettleAccount.Job.Services.Report groupItem.Key.PN, groupItem.Key.LU, Qty = groupItem.Sum(t => t.Qty), - SeqNumber = groupItem.Max(t => t.SeqNumber) + Extend2 = groupItem.Max(t => t.Extend2), + Extend3 = groupItem.Max(t => t.Extend3), + Extend4 = groupItem.Max(t => t.Extend4), + LineStationCode = groupItem.Max(t => t.LineStationCode) }; var seGroup = from se in _settleAccountDbContext.Set() where se.IsHaveEdiData == true && se.BillTime >= seStartDateTime && se.BillTime <= seEndDateTime @@ -138,10 +141,10 @@ namespace SettleAccount.Job.Services.Report { Category = "JIS", WmsBillNum = se.BillNum, - CarModeCode = default, - LineStationcode = default, - SequenceNumber = edi.SeqNumber, - ParType = "01", + CarModeCode = edi.Extend4, + LineStationcode = edi.LineStationCode, + SequenceNumber = edi.Extend3, + ParType = edi.Extend2, MESConfigCode = se.MESConfigCode, ShippingDate = se.BillTime, PN = se.PN, 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 17f62eb4..db7386a1 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 @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using EFCore.BulkExtensions; +using Magicodes.ExporterAndImporter.Core.Extension; using Magicodes.ExporterAndImporter.Excel; using Microsoft.AspNetCore.SignalR; using SettleAccount.Bases; @@ -116,10 +117,26 @@ namespace SettleAccount.Job.Services.Report /// /// 创建导出文件结构 /// - public ExcelExporter BindExcelExporter(List pubSaSeCompareDetailExports, string businessTypeDisplayName) where T : SaSeEdiCompareDetailExport, ISaSeEdiCompareDetailExport, new() + public ExcelExporter BindExcelExporter(List saSeEdiCompareDetailExports, string businessTypeDisplayName) where T : SaSeEdiCompareDetailExport, ISaSeEdiCompareDetailExport, new() { + //详情Sheet行数 + var detailMaxRowNumberOnASheet = 500_000; + var detailExportExporterAttribute = typeof(T).GetAttribute(); + if (detailExportExporterAttribute != null) + { + detailMaxRowNumberOnASheet = detailExportExporterAttribute.MaxRowNumberOnASheet > 0 ? detailExportExporterAttribute.MaxRowNumberOnASheet : detailMaxRowNumberOnASheet; + } + + //汇总Sheet行数 + var sumMaxRowNumberOnASheet = 500_000; + var sumExportExporterAttribute = typeof(SaSeEdiCompareSumExport).GetAttribute(); + if (sumExportExporterAttribute != null) + { + sumMaxRowNumberOnASheet = sumExportExporterAttribute.MaxRowNumberOnASheet > 0 ? sumExportExporterAttribute.MaxRowNumberOnASheet : sumMaxRowNumberOnASheet; + } + //汇总 - var pubSaSeCompareSumExports = pubSaSeCompareDetailExports.GroupBy(p => p.ReplaceFactoryPartCode).Select(p => new SaSeEdiCompareSumExport() + var saSeEdiCompareSumExports = saSeEdiCompareDetailExports.GroupBy(p => p.ReplaceFactoryPartCode).Select(p => new SaSeEdiCompareSumExport() { FactoryPartCode = p.Key, PartCodeDesc = p.FirstOrDefault().PartCodeDesc, @@ -129,7 +146,7 @@ namespace SettleAccount.Job.Services.Report }).ToList(); //有结算有发运 - var haveSaHaveSeExports = pubSaSeCompareDetailExports.FindAll(t => new EnumSaSeEdiCompareCategory[] { EnumSaSeEdiCompareCategory.HaveSaHaveSeHaveEdi, EnumSaSeEdiCompareCategory.HaveSaHaveSeNotHaveEdi }.Contains(t.Category)); + var haveSaHaveSeExports = saSeEdiCompareDetailExports.FindAll(t => new EnumSaSeEdiCompareCategory[] { EnumSaSeEdiCompareCategory.HaveSaHaveSeHaveEdi, EnumSaSeEdiCompareCategory.HaveSaHaveSeNotHaveEdi }.Contains(t.Category)); //有结算有发运汇总 var haveSaHaveSeSumExports = haveSaHaveSeExports.GroupBy(p => p.ReplaceFactoryPartCode).Select(p => new SaSeEdiCompareSumExport() { @@ -140,7 +157,7 @@ namespace SettleAccount.Job.Services.Report EdiQty = p.Sum(t => t.EdiQty) }).ToList(); //有结算无发运 - var haveSaNotHaveSeExports = pubSaSeCompareDetailExports.FindAll(t => new EnumSaSeEdiCompareCategory[] { EnumSaSeEdiCompareCategory.HaveSaNotHaveSeHaveEdi, EnumSaSeEdiCompareCategory.HaveSaNotHaveSeNotHaveEdi }.Contains(t.Category)); + var haveSaNotHaveSeExports = saSeEdiCompareDetailExports.FindAll(t => new EnumSaSeEdiCompareCategory[] { EnumSaSeEdiCompareCategory.HaveSaNotHaveSeHaveEdi, EnumSaSeEdiCompareCategory.HaveSaNotHaveSeNotHaveEdi }.Contains(t.Category)); //有结算无发运 var haveSaNotHaveSeSumExports = haveSaNotHaveSeExports.GroupBy(p => p.ReplaceFactoryPartCode).Select(p => new SaSeEdiCompareSumExport() { @@ -151,7 +168,7 @@ namespace SettleAccount.Job.Services.Report EdiQty = p.Sum(t => t.EdiQty) }).ToList(); //无结算有发运 - var notHaveSaHaveSeExports = pubSaSeCompareDetailExports.FindAll(t => new EnumSaSeEdiCompareCategory[] { EnumSaSeEdiCompareCategory.NotHaveSaHaveSeHaveEdi, EnumSaSeEdiCompareCategory.NotHaveSaHaveSeNotHaveEdi }.Contains(t.Category)); + var notHaveSaHaveSeExports = saSeEdiCompareDetailExports.FindAll(t => new EnumSaSeEdiCompareCategory[] { EnumSaSeEdiCompareCategory.NotHaveSaHaveSeHaveEdi, EnumSaSeEdiCompareCategory.NotHaveSaHaveSeNotHaveEdi }.Contains(t.Category)); //无结算有发运 var notHaveSaHaveSeSumExports = notHaveSaHaveSeExports.GroupBy(p => p.ReplaceFactoryPartCode).Select(p => new SaSeEdiCompareSumExport() { @@ -163,20 +180,59 @@ namespace SettleAccount.Job.Services.Report }).ToList(); ExcelExporter excelExporter = new ExcelExporter(); - return excelExporter - .Append(pubSaSeCompareDetailExports, $"{businessTypeDisplayName}结算核对明细输出") - .SeparateBySheet() - .Append(pubSaSeCompareSumExports, $"{businessTypeDisplayName}结算核对汇总输出") - .SeparateBySheet() + //结算核对明细输出 + excelExporter.Append(saSeEdiCompareDetailExports.Take(detailMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}结算核对明细输出"); + for (var i = 1; i < saSeEdiCompareDetailExports.Count / detailMaxRowNumberOnASheet + ((saSeEdiCompareDetailExports.Count % detailMaxRowNumberOnASheet) > 0 ? 1 : 0); i++) + { + var sheetDataItems = saSeEdiCompareDetailExports.Skip(i * detailMaxRowNumberOnASheet) + .Take(detailMaxRowNumberOnASheet).ToList(); + excelExporter.SeparateBySheet(); + excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}结算核对明细输出-{i}"); + } + //结算核对汇总输出 + excelExporter.Append(saSeEdiCompareSumExports.Take(sumMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}结算核对汇总输出"); + for (var i = 1; i < saSeEdiCompareSumExports.Count / sumMaxRowNumberOnASheet + ((saSeEdiCompareSumExports.Count % sumMaxRowNumberOnASheet) > 0 ? 1 : 0); i++) + { + var sheetDataItems = saSeEdiCompareSumExports.Skip(i * sumMaxRowNumberOnASheet).Take(sumMaxRowNumberOnASheet).ToList(); + excelExporter.SeparateBySheet(); + excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}结算核对汇总输出-{i}"); + } - .Append(haveSaHaveSeExports, $"{businessTypeDisplayName}有结算有发货明细输出") - .SeparateBySheet() - .Append(haveSaHaveSeSumExports, $"{businessTypeDisplayName}有结算有发货汇总输出") - .SeparateBySheet() + //有结算有发货明细输出 + excelExporter.Append(haveSaHaveSeExports.Take(detailMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算有发货明细输出"); + for (var i = 1; i < haveSaHaveSeExports.Count / detailMaxRowNumberOnASheet + ((haveSaHaveSeExports.Count % detailMaxRowNumberOnASheet) > 0 ? 1 : 0); i++) + { + var sheetDataItems = haveSaHaveSeExports.Skip(i * detailMaxRowNumberOnASheet).Take(detailMaxRowNumberOnASheet).ToList(); + excelExporter.SeparateBySheet(); + excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算有发货明细输出-{i}"); + } + //有结算有发货汇总输出 + excelExporter.Append(haveSaHaveSeSumExports.Take(sumMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算有发货汇总输出"); + for (var i = 1; i < haveSaHaveSeSumExports.Count / sumMaxRowNumberOnASheet + ((haveSaHaveSeSumExports.Count % sumMaxRowNumberOnASheet) > 0 ? 1 : 0); i++) + { + var sheetDataItems = haveSaHaveSeSumExports.Skip(i * sumMaxRowNumberOnASheet).Take(sumMaxRowNumberOnASheet).ToList(); + excelExporter.SeparateBySheet(); + excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算有发货汇总输出-{i}"); + } + + //有结算有发货明细输出 + excelExporter.Append(haveSaNotHaveSeExports.Take(detailMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算无发货明细输出"); + for (var i = 1; i < haveSaNotHaveSeExports.Count / detailMaxRowNumberOnASheet + ((haveSaNotHaveSeExports.Count % detailMaxRowNumberOnASheet) > 0 ? 1 : 0); i++) + { + var sheetDataItems = haveSaNotHaveSeExports.Skip(i * detailMaxRowNumberOnASheet).Take(detailMaxRowNumberOnASheet).ToList(); + excelExporter.SeparateBySheet(); + excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算无发货明细输出-{i}"); + } + //有结算有发货汇总输出 + excelExporter.Append(haveSaNotHaveSeSumExports.Take(sumMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算无发货汇总输出"); + for (var i = 1; i < haveSaNotHaveSeSumExports.Count / sumMaxRowNumberOnASheet + ((haveSaNotHaveSeSumExports.Count % sumMaxRowNumberOnASheet) > 0 ? 1 : 0); i++) + { + var sheetDataItems = haveSaNotHaveSeSumExports.Skip(i * sumMaxRowNumberOnASheet).Take(sumMaxRowNumberOnASheet).ToList(); + excelExporter.SeparateBySheet(); + excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算无发货汇总输出-{i}"); + } - .Append(haveSaNotHaveSeExports, $"{businessTypeDisplayName}有结算无发货明细输出") - .SeparateBySheet() - .Append(haveSaNotHaveSeSumExports, $"{businessTypeDisplayName}有结算无发货汇总输出"); + return excelExporter; } ///