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 dd6d9e8b..d566c4d4 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 @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data.SqlClient; using System.Diagnostics; using System.Linq; using System.Linq.Dynamic.Core; @@ -10,11 +11,13 @@ using EFCore.BulkExtensions; using LinqToDB.EntityFrameworkCore; using Magicodes.ExporterAndImporter.Core.Extension; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Omu.ValueInjecter; +using SettleAccount.Job.SignalR; using Volo.Abp; using Volo.Abp.Application.Services; using Volo.Abp.DependencyInjection; @@ -234,14 +237,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ foreach (var item in tables) { var logs = list.Where(o => o.Table == item).Select(o => o.Log).ToList(); - //await context.BulkInsertAsync(logs, new BulkConfig { CustomDestinationTableName = item, }).ConfigureAwait(false); await context.BulkCopyAsync(new LinqToDB.Data.BulkCopyOptions { TableName = item }, logs).ConfigureAwait(false); } - //批量更新消息 - await context.BulkUpdateAsync(messages, new BulkConfig - { - PropertiesToExclude = new List { nameof(VmiMessage.Number) } - }).ConfigureAwait(false); //批量插入负库存补货记录 await context.BulkInsertAsync(vmiReplenishedList).ConfigureAwait(false); //批量插入库存余额 @@ -250,6 +247,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ await context.BulkUpdateAsync(balanceList.Where(o => o.Item2 == 2 && o.Item1.Qty != decimal.Zero).Select(o => o.Item1).ToList()).ConfigureAwait(false); //批量删除库存余额 await context.BulkDeleteAsync(balanceList.Where(o => o.Item2 == 2 && o.Item1.Qty == decimal.Zero).Select(o => o.Item1).ToList()).ConfigureAwait(false); + //批量删除消息 + await context.BulkDeleteAsync(messages).ConfigureAwait(false); transaction.Commit(); } catch (Exception ex) @@ -262,6 +261,20 @@ namespace Win.Sfs.SettleAccount.Entities.BQ sw.Stop(); this._logger.LogInformation($"处理{fetchSize}条,耗时 {sw.ElapsedMilliseconds / 1000 / 60}分钟,{sw.ElapsedMilliseconds / 1000}秒"); } + try + { + using var scope = serviceProvider.CreateScope(); + using var connection2 = new SqlConnection(connectionString); + connection2.Open(); + var command = connection2.CreateCommand(); + command.CommandText = "SELECT count(*) FROM Set_VmiMessage WITH(NOLOCK)"; + var count = Convert.ToInt64(command.ExecuteScalar().ToString()); + scope.ServiceProvider.GetService>().Clients.All.ServerToClient("VmiBalance", count.ToString(), ""); + } + catch (Exception) + { + throw; + } } } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncMessageService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncMessageService.cs index 436291b9..3f915041 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncMessageService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAsyncMessageService.cs @@ -1,9 +1,6 @@ using System; using System.Data.SqlClient; -using System.Linq; -using System.Linq.Dynamic.Core; using System.Threading.Tasks; -using EFCore.BulkExtensions; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Configuration; @@ -30,14 +27,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [NonAction] public Task Invoke(IServiceProvider serviceProvider) { - using var scope = serviceProvider.CreateScope(); - var connectionString = serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); - using var connection = new SqlConnection(connectionString); - connection.Open(); - var command = connection.CreateCommand(); - command.CommandText = "SELECT count(*) FROM Set_VmiMessage WITH(NOLOCK) where isConsumed = 0;"; - var count = Convert.ToInt64(command.ExecuteScalar().ToString()); - scope.ServiceProvider.GetService>().Clients.All.ServerToClient("VmiBalance", count.ToString(), ""); + //using var scope = serviceProvider.CreateScope(); + //var connectionString = serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); + //using var connection = new SqlConnection(connectionString); + //connection.Open(); + //var command = connection.CreateCommand(); + //command.CommandText = "SELECT count(*) FROM Set_VmiMessage WITH(NOLOCK)"; + //var count = Convert.ToInt64(command.ExecuteScalar().ToString()); + //scope.ServiceProvider.GetService>().Clients.All.ServerToClient("VmiBalance", count.ToString(), ""); return Task.CompletedTask; } @@ -46,11 +43,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ /// /// [HttpPost] - public int GetMessageCount() + public long GetMessageCount() { - using var scope = this._serviceProvider.CreateScope(); - var db = scope.ServiceProvider.GetRequiredService(); - var count = db.Set().Where(o => !o.isConsumed).Count(); + using var scope = _serviceProvider.CreateScope(); + var connectionString = _serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); + using var connection = new SqlConnection(connectionString); + connection.Open(); + var command = connection.CreateCommand(); + command.CommandText = "SELECT count(*) FROM Set_VmiMessage WITH(NOLOCK)"; + var count = Convert.ToInt64(command.ExecuteScalar().ToString()); return count; } }