From bde89e6335240fcfb204355a0cda6564ed3bf542 Mon Sep 17 00:00:00 2001 From: zhaoxinyu <89237069@qq.com> Date: Fri, 21 Jun 2024 09:46:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BQ/BBAC_NOT_SA_SERVICE.cs | 10 +- .../Entities/BQ/HBPO_NOT_SA_SERVICE.cs | 6 +- .../Entities/BQ/VmiAppService.cs | 104 ++++++++++-------- .../SettleAccount.Domain/Bases/EntityBase.cs | 19 ++++ .../Entities/BQ/Managers/BBAC_NOT_SA_MNG.cs | 1 + 5 files changed, 90 insertions(+), 50 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_NOT_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_NOT_SA_SERVICE.cs index 9bc19b0c..806a2584 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_NOT_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_NOT_SA_SERVICE.cs @@ -15,6 +15,7 @@ using Shouldly; using TaskJob.EventArgs; using Volo.Abp; using Volo.Abp.Data; +using Volo.Abp.Uow; using Win.Abp.Snowflakes; using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.SettleAccount.Bases; @@ -136,10 +137,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ - + [UnitOfWork(false)] [HttpPost] public override async Task GenerateSettlementOrder(BBAC_NOT_SA_DETAIL_REQ_DTO input) { + + var first = input.Filters.FirstOrDefault(p => p.Column == "businessType"); + if (first != null) + { + input.Filters.Remove(first); + } + //_detailRepository.DbContext.Set().Where(p=>p.) var flag= await _bbacNotMng.IsCompleted().ConfigureAwait(false); if (flag == false) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_NOT_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_NOT_SA_SERVICE.cs index 45986217..cfa0f687 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_NOT_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_NOT_SA_SERVICE.cs @@ -136,7 +136,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ public override async Task GenerateSettlementOrder(HBPO_NOT_SA_DETAIL_REQ_DTO input) { - + var first = input.Filters.FirstOrDefault(p => p.Column == "businessType"); + if (first!=null) + { + input.Filters.Remove(first); + } var flag = await _hbpoNotMng.IsCompleted().ConfigureAwait(false); if (flag == false) { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs index 58548e90..1f976622 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs @@ -10,7 +10,9 @@ using System.IO.Compression; using System.Linq; using System.Linq.Dynamic.Core; using System.Reflection; +using System.Security.AccessControl; using System.Text.Json; +using System.Threading; using System.Threading.Tasks; using AutoMapper; using ClosedXML.Excel; @@ -33,6 +35,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Minio; +using NPOI.POIFS.Crypt; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using Omu.ValueInjecter; @@ -130,6 +134,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ this._hubContext = hubContext; this._currentUser = currentUser; this._logger = logger; + _cfg = cfg; _service = service; LinqToDBForEFTools.Initialize(); _excelImportService = excelImportService; @@ -298,23 +303,28 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var entities = await _vmiBalanceSumDetailRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount, true).ConfigureAwait(false); var dtos = _maper.Map, List>(entities); dtos = dtos.OrderByDescending(p => p.BillTime).ToList(); - var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx"; - ExportImporter _exportImporter = new ExportImporter(); - var result = await _exportImporter.ExcelExporter(dtos).ConfigureAwait(false); - result.ShouldNotBeNull(); - await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }).ConfigureAwait(false); + var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.zip"; + //ExportImporter _exportImporter = new ExportImporter(); + //var result = await _exportImporter.ExcelExporter(dtos).ConfigureAwait(false); + //result.ShouldNotBeNull(); + //await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }).ConfigureAwait(false); + ExtendExcel.BucketName = _cfg.GetValue("MinIO:BucketName", "default"); + ExtendExcel.AccessKey = _cfg.GetValue("MinIO:AccessKey" , "g0GKnhRGEQHI0uiGBYre"); + ExtendExcel.SecretKey = _cfg.GetValue("MinIO:SecretKey" , "iKGlLz6UBzci3xrERw5Zz1gI77enT5u9agFemHPv"); - // var content= ExtendExcel.WriteDataToExcelInParallel( "库存余额", dtos, 500000); + ExtendExcel.EndPoint = _cfg.GetValue("MinIO:EndPoint" , "localhost:10684"); + return await ExtendExcel.WriteDataToExcelInParallel("库存余额", dtos, 500000).ConfigureAwait(false); + - return fileName; + // return fileName; } /// @@ -1965,8 +1975,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } if (propertyType.IsEnum) {//枚举 - var enumValue = Enum.GetNames(propertyType) - .Select(o => new KeyValuePair(o, (Enum)Enum.Parse(propertyType, o))) + var enumValue = System.Enum.GetNames(propertyType) + .Select(o => new KeyValuePair(o, (System.Enum)System.Enum.Parse(propertyType, o))) .Where(o => o.Value.GetDisplayName() == value.ToString()) .Select(o => o.Value) .FirstOrDefault(); @@ -2064,7 +2074,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } else if (propertyType.IsEnum) { - cell.Value = (Enum.Parse(propertyType, value) as Enum)?.GetDisplayName(); + cell.Value = (System.Enum.Parse(propertyType, value) as System.Enum)?.GetDisplayName(); } else if (propertyType == typeof(DateTime)) { @@ -2215,20 +2225,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ // 扩展方法类,用于为IEnumerable类型添加额外功能 - public static class EnumerableExtensions - { - // 扩展方法,将源序列按指定大小分割成多个子序列 - public static IEnumerable> ChunkBy(this IEnumerable source, int chunkSize) - { - // 使用Select方法为序列中的每个元素添加索引和值 - return source - .Select((x, i) => new { Index = i, Value = x }) - // 根据索引除以块大小进行分组 - .GroupBy(x => x.Index / chunkSize) - // 从每个分组中选择值形成新的子序列 - .Select(x => x.Select(v => v.Value)); - } - } + public class FileInfoGroup @@ -2247,6 +2244,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { static ConcurrentBag excelFiles = new ConcurrentBag(); + public static string EndPoint { get; set; } + public static string AccessKey { get; set; } + public static string SecretKey { get; set; } + public static string BucketName { get; set; } + public static bool WithSSL { get; set; } /// /// @@ -2254,7 +2256,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ /// 页签名称 /// 数据 /// 缓存文件行数 - public static byte[] WriteDataToExcelInParallel(string sheetName, List data, int chunkSize) + public static async Task WriteDataToExcelInParallel(string sheetName, List data, int chunkSize) { Stopwatch sw = Stopwatch.StartNew(); var count = data.Count / 1000000 + ((data.Count % 1000000) > 0 ? 1 : 0); @@ -2262,7 +2264,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { var datas = data.Skip((i - 1) * 1000000).Take(1000000).ToList(); var chunks = datas.ChunkBy(chunkSize); - Parallel.ForEach(chunks, chunk => + Parallel.ForEach(chunks, async chunk => { var fileName = $"{sheetName}_{i - 1}_{Guid.NewGuid()}.xlsx"; var fileinfogroup = new FileInfoGroup((fileName), $"{sheetName}_{i - 1}"); @@ -2271,15 +2273,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ }); } string[] filePaths = excelFiles.Select(x => x.FileName).ToArray(); - - // 指定ZIP文件的输出路径 - string zipPath = $"{Guid.NewGuid()}.zip"; - - // 使用ZipFile.CreateFromDirectory方法压缩文件 - - // ZipFile.CreateFromDirectory(string.Empty, zipPath, CompressionLevel.Fastest, false, null); - - // 或者使用ZipFile.CreateFromDirectory方法压缩指定文件 + string zipPath = $"{sheetName}_{Guid.NewGuid()}.zip"; using (var archive = ZipFile.Open(zipPath, ZipArchiveMode.Create)) { foreach (var file in filePaths) @@ -2287,27 +2281,41 @@ namespace Win.Sfs.SettleAccount.Entities.BQ archive.CreateEntryFromFile(file, Path.GetFileName(file)); } } - + //for (var i = 0; i < count; i++) + //{ + // var filelist = excelFiles.Where(p => p.Grpup == $"{sheetName}_{i}").Select(p => p.FileName).ToList(); + // //MergeExcelFiles(filelist.ToArray(), $"{sheetName}.xlsx",filelist.First()); + // //foreach (var file in filelist) + // //{ + // // File.Delete(file); + // //} + //} + sw.Stop(); - for (var i = 0; i < count; i++) - { - var filelist = excelFiles.Where(p => p.Grpup == $"{sheetName}_{i}").Select(p => p.FileName).ToList(); - //MergeExcelFiles(filelist.ToArray(), $"{sheetName}.xlsx",filelist.First()); - //foreach (var file in filelist) - //{ - // File.Delete(file); - //} - } - - sw.Stop(); using (FileStream fileStream = new FileStream(zipPath, FileMode.Open)) { - return fileStream.GetAllBytes(); + var minioClient = new MinioClient(EndPoint, AccessKey, SecretKey, ""); + try + { + await minioClient.PutObjectAsync(BucketName,zipPath, fileStream,fileStream.Length, "application/zip").ConfigureAwait(false); + } + catch (Exception ex) + { + // Console.WriteLine($"上传文件到 MinIO 时发生错误: {ex.Message}"); + } + } + Thread.Sleep(10000); + + return zipPath; + //using (FileStream fileStream = new FileStream(zipPath, FileMode.Open)) + //{ + // return fileStream.GetAllBytes(); + //} } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs index 7feca1aa..fc27d430 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; +using System.Linq; using Volo.Abp.Domain.Entities.Auditing; using Win.Sfs.SettleAccount; using Win.Sfs.SettleAccount.Entities.BQ.Syncs; @@ -8,6 +10,23 @@ using Win.Sfs.SettleAccount.Enums; namespace SettleAccount.Bases { + + public static class EnumerableExtensions + { + // 扩展方法,将源序列按指定大小分割成多个子序列 + public static IEnumerable> ChunkBy(this IEnumerable source, int chunkSize) + { + // 使用Select方法为序列中的每个元素添加索引和值 + return source + .Select((x, i) => new { Index = i, Value = x }) + // 根据索引除以块大小进行分组 + .GroupBy(x => x.Index / chunkSize) + // 从每个分组中选择值形成新的子序列 + .Select(x => x.Select(v => v.Value)); + } + } + + /// /// 所有业务单据基类 /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_NOT_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_NOT_SA_MNG.cs index 15749513..e0950a64 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_NOT_SA_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_NOT_SA_MNG.cs @@ -63,6 +63,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers var list=await _codesettingRepository.Where(p=>p.Project=="BBAC_NOT" && p.Value=="True").ToListAsync().ConfigureAwait(false); if (list.Count > 0) { + return false; }