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 87738009..bf8b5446 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 @@ -72,6 +72,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ private readonly INormalEfCoreRepository _balanceRepository; private readonly INormalEfCoreRepository _logRepository; private readonly INormalEfCoreRepository _codeRepository; + private readonly INormalEfCoreRepository _vmiBalanceSumDetailRepository; + private readonly INormalEfCoreRepository _vmiBalanceSumRepository; + + private readonly IBlobContainer _fileContainer; private readonly IHubContext _hubContext; private readonly ICurrentUser _currentUser; @@ -83,9 +87,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ public VmiAppService(IConfiguration cfg, IServiceProvider serviceProvider, IGuidGenerator guidGenerator, + INormalEfCoreRepository vmiBalanceSumRepository, INormalEfCoreRepository balanceRepository, INormalEfCoreRepository logRepository, INormalEfCoreRepository codeRepository, + INormalEfCoreRepository vmiBalanceSumDetailRepository, IBlobContainer fileContainer, Volo.Abp.ObjectMapping.IObjectMapper maper, IHubContext hubContext, @@ -98,6 +104,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ ) { + _vmiBalanceSumRepository = vmiBalanceSumRepository; + _vmiBalanceSumDetailRepository = vmiBalanceSumDetailRepository; _maper = maper; this._codeRepository = codeRepository; this._cfg = cfg; @@ -200,21 +208,25 @@ 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 = query.Where(input.Filters.ToLambda()); - } - 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().AsQueryable(); - var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false); - // _maper.Map(VmiBalanceSumDetail,v) + //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); @@ -227,25 +239,31 @@ 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 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); + var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx"; - var content = this.GetContent(entities, "库存余额"); + var content = this.GetContent(dtos, "库存余额"); await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); return fileName; } @@ -259,56 +277,74 @@ namespace Win.Sfs.SettleAccount.Entities.BQ public async Task> BalanceSum(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 = 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); + + 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库存余额汇总导出 /// [HttpPost] public async Task BalanceSumExport(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 * 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(entities, "库存汇总"); + 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); + + + 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;