diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs index 679f1523..6e2369f9 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncBalanceService.cs @@ -19,6 +19,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Omu.ValueInjecter; using SettleAccount.Job.SignalR; +using SqlSugar; using Volo.Abp; using Volo.Abp.Application.Services; using Volo.Abp.DependencyInjection; @@ -72,7 +73,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ private async Task InvokeInternal(IServiceProvider serviceProvider) { - var batchSize = 2500; + var batchSize = 10000; var fetchSize = 0; var connectionString = serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); for (var i = 0; i < 1000; i++) @@ -94,15 +95,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ context.Database.UseTransaction(transaction); var vmiMessageRepo = context.Set(); var vmiLogRepo = context.Set(); - var vmiBalanceRepo = context.Set(); - //sw.Stop(); - //this._logger.LogInformation($"缓存开始:{fetchSize}条,耗时 {sw.ElapsedMilliseconds / 1000} 秒,{sw.ElapsedMilliseconds} 豪秒"); - //sw.Restart(); - //var balanceCachedList = vmiBalanceRepo.AsNoTracking().ToList(); - //sw.Stop(); - //this._logger.LogInformation($"缓存结束:{fetchSize}条,耗时 {sw.ElapsedMilliseconds / 1000} 秒,{sw.ElapsedMilliseconds} 豪秒"); - //sw.Restart(); - //读取可消费消息列表 + var vmiBalanceRepo = context.Set(); //读取可消费消息列表 var messages = vmiMessageRepo.AsNoTracking().Where(o => !o.isConsumed).OrderBy(o => o.Number).Take(batchSize).ToList(); //没有可消费消息则返回 if (!messages.Any()) @@ -110,6 +103,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ transaction.Commit(); break; } + //缓存余额表 + sw.Stop(); + this._logger.LogInformation($"缓存开始:{fetchSize}条,耗时 {sw.ElapsedMilliseconds / 1000} 秒,{sw.ElapsedMilliseconds} 豪秒"); + sw.Restart(); + var balanceCachedList = vmiBalanceRepo.AsNoTracking() + .ToDictionary(o => $"{o.DeliverBillType}.{o.CodeType}.{o.RealPartCode}.{o.VinCode}.{o.ErpToLoc}.{o.OrderNum}.{o.factory}.{o.Configcode}"); + sw.Stop(); + this._logger.LogInformation($"缓存结束:{fetchSize}条,耗时 {sw.ElapsedMilliseconds / 1000} 秒,{sw.ElapsedMilliseconds} 豪秒"); + sw.Restart(); //设置数量为实际返回数量 fetchSize = messages.Count; //反序列化获取库存事务 @@ -162,21 +164,23 @@ namespace Win.Sfs.SettleAccount.Entities.BQ //数据库查找 if (balance == null) { - //sw.Stop(); - ////this._logger.LogInformation($"查询开始:{fetchSize}条,耗时 {sw.ElapsedMilliseconds / 1000} 秒,{sw.ElapsedMilliseconds} 豪秒"); - //sw.Restart(); - balance = vmiBalanceRepo.AsNoTracking().FirstOrDefault(// balanceCachedList.Find( - o => o.DeliverBillType == log.DeliverBillType && - o.CodeType == log.CodeType && - o.RealPartCode == log.RealPartCode && - o.VinCode == log.VinCode && - o.ErpToLoc == log.ErpToLoc && - o.OrderNum == log.OrderNum && - o.factory == log.factory && - o.Configcode == log.Configcode); - //sw.Stop(); - //this._logger.LogInformation($"查询结束:{fetchSize}条,耗时 {sw.ElapsedMilliseconds / 1000} 秒,{sw.ElapsedMilliseconds} 豪秒"); - //sw.Restart(); + sw.Stop(); + //this._logger.LogInformation($"查询开始:{fetchSize}条,耗时 {sw.ElapsedMilliseconds / 1000} 秒,{sw.ElapsedMilliseconds} 豪秒"); + sw.Restart(); + //balance = vmiBalanceRepo.AsNoTracking().FirstOrDefault( + // // balanceCachedList.Find( + // o => o.DeliverBillType == log.DeliverBillType && + // o.CodeType == log.CodeType && + // o.RealPartCode == log.RealPartCode && + // o.VinCode == log.VinCode && + // o.ErpToLoc == log.ErpToLoc && + // o.OrderNum == log.OrderNum && + // o.factory == log.factory && + // o.Configcode == log.Configcode); + balance = balanceCachedList.GetValueOrDefault($"{log.DeliverBillType}.{log.CodeType}.{log.RealPartCode}.{log.VinCode}.{log.ErpToLoc}.{log.OrderNum}.{log.factory}.{log.Configcode}"); + sw.Stop(); + this._logger.LogInformation($"查询结束:{fetchSize}条,耗时 {sw.ElapsedMilliseconds / 1000} 秒,{sw.ElapsedMilliseconds} 豪秒"); + sw.Restart(); } if (balance == null) {//不存在库存记录