From 294f13344761a00f9eab378bfe957e8be6a3d519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A6=20=E8=B5=B5?= <89237069@qq.com> Date: Mon, 27 Nov 2023 10:07:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=93=E5=AD=98=E4=BA=8B?= =?UTF-8?q?=E5=8A=A1=E6=9D=A1=E4=BB=B6=E6=9F=A5=E8=AF=A2=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bases/PD_SERVICE.cs | 3 +- .../Entities/BQ/VmiAppService.cs | 132 ++++++++++-------- .../SettleAccountApplicationModule.cs | 2 + .../Entities/BQ/Vmi/VmiLog.cs | 13 +- 4 files changed, 85 insertions(+), 65 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs index 12854b6f..2ff046cf 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs @@ -96,7 +96,6 @@ namespace Win.Sfs.SettleAccount.Bases var totalCount = await _detailRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); var dtos = ObjectMapper.Map, List>(entitys); return new PagedResultDto(totalCount, dtos); - } /// /// 导出 @@ -272,6 +271,8 @@ namespace Win.Sfs.SettleAccount.Bases await _repository.DbContext.BulkUpdateAsync(ls); var _taskid = await p_service.ExportEnqueueAsync($"{first1.BusinessType.ToString()}待扣减任务", ExportExtentsion.Excel, DateTime.Now.ToString("yyyyMM"), string.Empty, CurrentUser, typeof(PendingDeductionService), customConditionList, (rs) => { + + }); return _taskid; 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 e89144bb..d15bf8cd 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 @@ -41,6 +41,7 @@ using Volo.Abp.Application.Services; using Volo.Abp.BlobStoring; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; +using Volo.Abp.ObjectMapping; using Volo.Abp.Users; using Volo.Abp.Validation; using Win.Sfs.BaseData.ImportExcelCommon; @@ -420,61 +421,72 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [HttpPost] public async Task> Log(LogRequestDto input) { - if (input.UseHistory) - { - return await Log2(input).ConfigureAwait(false); - } - //按季度计算查询需要 union 的表名 - var start = DateTime.Parse(input.Filters.FirstOrDefault(o => o.Column == "changedTime" && o.Action == EnumFilterAction.BiggerThanOrEqual).Value); - var end = DateTime.Parse(input.Filters.FirstOrDefault(o => o.Column == "changedTime" && o.Action == EnumFilterAction.SmallThan).Value); - var tables = new List(); - var connectionString = this._serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); - using var connection = new SqlConnection(connectionString); - connection.Open(); - for (var time = start; time <= end; time = time.AddMonths(1)) - { - var tableName = $"Set_VmiLog_{time.Year}_{(time.Month - 1) / 3 + 1}"; - if (!tables.Contains(tableName)) - { - var command = connection.CreateCommand(); - command.CommandText = $"select OBJECT_ID('{tableName}', 'U')"; - var result = command.ExecuteScalar().ToString(); - if (result != string.Empty) - { - tables.Add(tableName); - } - else - { - this._logger.LogInformation($"{tableName}不存在"); - } - } - } - var options = new DbContextOptionsBuilder().UseSqlServer(connectionString).Options; - using var db = new SettleAccountDbContext(options); - var sql = string.Empty; - if (tables.Any()) - { - //生成 union all 的 SQL使用 FromSqlRaw 查询,如果没有分表则使用原始表 - sql = $"select * from {tables.First()} WITH(NOLOCK)"; - tables.Skip(1).ForEach(o => sql += $" union all select * from {o} WITH(NOLOCK)"); - } - else - { - sql = "select * from Set_VmiLog WITH(NOLOCK)"; - } - var query = string.IsNullOrEmpty(sql) ? db.Set().AsQueryable() : db.Set().FromSqlRaw(sql); - var filters = input.Filters.ToLambda(); - if (input.Filters.Count > 0) - { - query = query.Where(input.Filters.ToLambda()); - } - if (input.LogTypes.Count > 0) - { - query = query.Where(o => input.LogTypes.Contains(o.LogType)); - } - var totalCount = query.Count(); - query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); - var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false); + //if (input.UseHistory) + //{ + // return await Log2(input).ConfigureAwait(false); + //} + ////按季度计算查询需要 union 的表名 + //var start = DateTime.Parse(input.Filters.FirstOrDefault(o => o.Column == "changedTime" && o.Action == EnumFilterAction.BiggerThanOrEqual).Value); + //var end = DateTime.Parse(input.Filters.FirstOrDefault(o => o.Column == "changedTime" && o.Action == EnumFilterAction.SmallThan).Value); + //var tables = new List(); + //var connectionString = this._serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); + //using var connection = new SqlConnection(connectionString); + //connection.Open(); + //for (var time = start; time <= end; time = time.AddMonths(1)) + //{ + // var tableName = $"Set_VmiLog_{time.Year}_{(time.Month - 1) / 3 + 1}"; + // if (!tables.Contains(tableName)) + // { + // var command = connection.CreateCommand(); + // command.CommandText = $"select OBJECT_ID('{tableName}', 'U')"; + // var result = command.ExecuteScalar().ToString(); + // if (result != string.Empty) + // { + // tables.Add(tableName); + // } + // else + // { + // this._logger.LogInformation($"{tableName}不存在"); + // } + // } + //} + //var options = new DbContextOptionsBuilder().UseSqlServer(connectionString).Options; + //using var db = new SettleAccountDbContext(options); + //var sql = string.Empty; + //if (tables.Any()) + //{ + // //生成 union all 的 SQL使用 FromSqlRaw 查询,如果没有分表则使用原始表 + // sql = $"select * from {tables.First()} WITH(NOLOCK)"; + // tables.Skip(1).ForEach(o => sql += $" union all select * from {o} WITH(NOLOCK)"); + //} + //else + //{ + // sql = "select * from Set_VmiLog WITH(NOLOCK)"; + //} + //var query = string.IsNullOrEmpty(sql) ? db.Set().AsQueryable() : db.Set().FromSqlRaw(sql); + //var filters = input.Filters.ToLambda(); + //if (input.Filters.Count > 0) + //{ + // query = query.Where(input.Filters.ToLambda()); + //} + //if (input.LogTypes.Count > 0) + //{ + // query = query.Where(o => input.LogTypes.Contains(o.LogType)); + //} + //var totalCount = query.Count(); + //query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); + //var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false); + + + + + + + + + var entities = await _logRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount).ConfigureAwait(false); + var totalCount = await _logRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); + return new PagedResultDto(totalCount, entities); } @@ -513,6 +525,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { var entities = await _logRepository.GetListByFilterAsync(input.Filters, input.Sorting).ConfigureAwait(false); var fileName = $"库存事务_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx"; + + if (entities.Count > 1000000) + { + throw new UserFriendlyException("导出行数超过100W不能导出,请重新录入查询条件导出","400"); + } + var content = this.GetContent(entities, "库存事务_"); await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); return fileName; @@ -614,12 +632,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var endDate = DateTime.Parse(input.endBillTime).ToString("yyyy/MM/dd") + " 23:59:59 "; DateTimeFormatInfo dtFormat = new DateTimeFormatInfo(); dtFormat.ShortDatePattern = "yyyy/MM/dd HH:mm:ss"; - //DateTime aa= DateTime.ParseExact(DateTime.Parse(input.startBillTime).ToString("yyyy/MM/dd"), "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); + //DateTime aa= DateTime.ParseExact(DateTime.Parse(input.startBillTime).ToString("yyyy/MM/dd"), "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); var entities = await _logRepository.Where(p => p.BillTime >= DateTime.Parse(beginDate) && p.BillTime <= DateTime.Parse(endDate)).ToListAsync(); //IQueryable query = _logRepository.WhereIf(input.Filters?.Count != 0, input.Filters.ToLambda()); - - IExporter _csv = new CsvExporter(); IExporter _excel = new ExcelExporter(); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs index 19e848e6..5930063d 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs @@ -45,6 +45,8 @@ namespace Win.Sfs.SettleAccount //context.Services.AddTransient(typeof(INormalEfCoreRepository<,>), //typeof(SettleAccountNormalEfCoreRepository<,>)); context.Services.AddTransient(); + + context.Services.AddTransient(implementationFactory => { Func accesor = key => diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs index 7276b313..6c76b2e6 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using Magicodes.ExporterAndImporter.Core; using SequentialGuid; namespace Win.Sfs.SettleAccount.Entities.BQ.Vmi @@ -37,22 +38,22 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Vmi yield return new ValidationResult("客户客户订单号不能为空", new string[] { nameof(this.OrderNum) }); } } - + [ExporterHeader(DisplayName = "库存事务分类")] [Display(Name = "库存事务分类", Order = 0)] public VmiLogType LogType { get; set; } - + [ExporterHeader(DisplayName = "变动单号")] [Display(Name = "变动单号", Order = 1)] public string ChangedNumber { get; set; } - + [ExporterHeader(DisplayName = "变动时间")] [Display(Name = "变动时间", Order = 2)] public DateTime ChangedTime { get; set; } - + [ExporterHeader(DisplayName = "变动类型")] [Display(Name = "变动类型", Order = 3)] public VmiType ChangedType { get; set; } - + [ExporterHeader(DisplayName = "变动人")] [Display(Name = "变动人", Order = 4)] public string ChangedBy { get; set; } - + [ExporterHeader(DisplayName = "库存变动")] [Display(Name = "库存变动", Order = 5)] public decimal ChangedQty { get; set; }