From 1bc87014caaf167e0cfdc513f668307bba5002ad Mon Sep 17 00:00:00 2001 From: zhaoxinyu Date: Thu, 21 Dec 2023 16:14:37 +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/VmiAppService.cs | 194 +----------------- ...ttleAccountApplicationAutoMapperProfile.cs | 2 +- 2 files changed, 8 insertions(+), 188 deletions(-) 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 f6308c55..370e35a2 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 @@ -208,29 +208,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [HttpPost] public async Task> Balance(RequestDto input) { - - //var connectionString = this._serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); - //var options = new DbContextOptionsBuilder().UseSqlServer(connectionString).Options; - //using var db = new SettleAccountDbContext(options); - //var query = db.Set().AsQueryable(); - - //var filters = input.Filters.ToLambda(); - //if (input.Filters.Count > 0) - //{ - // query =_vmiBalanceSumDetailRepository.Where(filters); - //} - //var totalCount = query.Count(); - - //var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false); - //// _maper.Map(VmiBalanceSumDetail,v) - /// - var entities = await _vmiBalanceSumDetailRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); var totalCount = await _vmiBalanceSumDetailRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); - var dtos = _maper.Map, List>(entities); dtos=dtos.OrderByDescending(p => p.BillTime).ToList(); - return new PagedResultDto(totalCount, dtos); } @@ -240,30 +221,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [HttpPost] public async Task BalanceExport(RequestDto input) { - - - - //var connectionString = this._serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); - //var options = new DbContextOptionsBuilder().UseSqlServer(connectionString).Options; - //using var db = new SettleAccountDbContext(options); - //var query = db.Set().FromSqlRaw("select VinCode,ErpToLoc,RealPartCode,ChangedQty ,BillTime,LogType from Set_VmiLog"); - //var filters = input.Filters.ToLambda(); - //if (input.Filters.Count > 0) - //{ - // query = query.Where(input.Filters.ToLambda()); - //} - //query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); - //var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode, o.VinCode, o.LogType }).Select(o => new VmiBalanceNewDto { VinCode = o.Key.VinCode, ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.ChangedQty), BillTime = o.Max(o => o.BillTime),Se = o.Sum(o => o.LogType == VmiLogType.Type100 ? 1 : 0), ReturnGoods = o.Sum(o => o.LogType == VmiLogType.Type400 ? 1 : 0) }).Where(p => p.Qty != 0); - //var entities = query2.ToList(); - - // var entities = await _balanceRepository.GetListByFilterAsync(input.Filters).ConfigureAwait(false); - var entities = await _vmiBalanceSumDetailRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount, true).ConfigureAwait(false); - //var totalCount = await _vmiBalanceSumDetailRepository.GetCountByFilterAsync(input.Filters).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"; var content = this.GetContent(dtos, "库存余额"); await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); @@ -278,49 +238,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [HttpPost] public async Task> BalanceSum(RequestDto input) { - - - var entities = await _vmiBalanceSumRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); var totalCount = await _vmiBalanceSumRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); - - var dtos = _maper.Map, List>(entities); return new PagedResultDto(totalCount, dtos); } - - - - //var connectionString = this._serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); - // var options = new DbContextOptionsBuilder().UseSqlServer(connectionString).Options; - // using var db = new SettleAccountDbContext(options); - // var query = db.Set().AsQueryable(); - // var filters = input.Filters.ToLambda(); - // if (input.Filters.Count > 0) - // { - // query = query.Where(input.Filters.ToLambda()); - // } - // query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); - - // var totalCount = query.Count(); - - // //var connectionString = this._serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); - // //var options = new DbContextOptionsBuilder().UseSqlServer(connectionString).Options; - // //using var db = new SettleAccountDbContext(options); - // //var query = db.Set().FromSqlRaw("select * from Set_VmiBalance"); - // //var filters = input.Filters.ToLambda(); - // //if (input.Filters.Count > 0) - // //{ - // // query = query.Where(input.Filters.ToLambda()); - // //} - // //var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode }).Select(o => new VmiBalanceSumDto { ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.Qty) }); - // //var totalCount = query2.Count(); - // //query2 = string.IsNullOrEmpty(input.Sorting) ? query2 : DynamicQueryableExtensions.OrderBy(query2, input.Sorting); - // var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false); - - /// /// 1.2库存余额汇总导出 /// @@ -328,47 +252,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ public async Task BalanceSumExport(RequestDto input) { var entities = await _vmiBalanceSumRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount, true).ConfigureAwait(false); - // var totalCount = await _vmiBalanceSumRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); - if (entities.Count > 1000000) - { - throw new UserFriendlyException("导出行数超过100W不能导出,请重新录入查询条件导出", "400"); - } + + if (entities.Count > 1000000) + { + throw new UserFriendlyException("导出行数超过100W不能导出,请重新录入查询条件导出", "400"); + } var dtos = _maper.Map, List>(entities); - //var connectionString = this._serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); - //var options = new DbContextOptionsBuilder().UseSqlServer(connectionString).Options; - //using var db = new SettleAccountDbContext(options); - //var query = db.Set().FromSqlRaw("select * from Set_VmiLog"); - //var filters = input.Filters.ToLambda(); - //if (input.Filters.Count > 0) - //{ - // query = query.Where(input.Filters.ToLambda()); - //} - //query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); - //var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode }).Select(o => new VmiBalanceSumDto { ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.ChangedQty) }); - //var totalCount = query2.Count(); - //var entities = await query2.ToListAsync().ConfigureAwait(false); + var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx"; var content = this.GetContent(dtos, "库存汇总"); await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); return fileName; - - - //var connectionString = this._serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); - //var options = new DbContextOptionsBuilder().UseSqlServer(connectionString).Options; - //using var db = new SettleAccountDbContext(options); - //var query = db.Set().FromSqlRaw("select * from Set_VmiBalance"); - //var filters = input.Filters.ToLambda(); - //if (input.Filters.Count > 0) - //{ - // query = query.Where(input.Filters.ToLambda()); - //} - //query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); - //var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode }).Select(o => new VmiBalanceSumDto { ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.Qty) }); - //var totalCount = query2.Count(); - //var entities = await query2.ToListAsync().ConfigureAwait(false); var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx"; - //var content = this.GetContent(entities, "库存汇总"); - //await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); - //return fileName; } /// @@ -465,79 +359,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [HttpPost] public async Task> Log(LogRequestDto input) { - //var accountday = _codeRepository.FirstOrDefault(p => p.Project == "库存账期").Value; - //var begin= input.Filters.FirstOrDefault(p => p.Column == "BillTime" && p.Action == EnumFilterAction.BiggerThanOrEqual); - //if(begin != null){ - // var begintime=DateTime.Parse(begin.Value); - // int version=GetVersionByBillTime(begintime, accountday); - // input.Filters.Add(new FilterCondition("Version",version.ToString(), EnumFilterAction.BiggerThanOrEqual,EnumFilterLogic.And)); - - - - //} - //var end = input.Filters.FirstOrDefault(p => p.Column == "BillTime" && p.Action == EnumFilterAction.SmallThan); - //if(end != null) { - // var endtime = DateTime.Parse(end.Value); - // int version = GetVersionByBillTime(endtime, accountday); - // input.Filters.Add(new FilterCondition("Version", version.ToString(), EnumFilterAction.SmallThan, EnumFilterLogic.And)); ; - - //} - - //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); @@ -594,8 +416,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }).ConfigureAwait(false); - //var content = this.GetContent(entities, "库存事务_"); - //await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); return fileName; } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs index 368d8bdd..a14d3cf4 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs @@ -954,7 +954,7 @@ namespace Win.Sfs.SettleAccount private void CreateMapBalanceSumDetail() { CreateMap() - .ForMember(x => x.BillTime, y => y.MapFrom(d => d.ShippingTime)) + .ForMember(x => x.BillTime, y => y.MapFrom(d => d.ReceiveTime)) .ForMember(x => x.Qty, y => y.MapFrom(d => d.SumQty)). ReverseMap(); }