|
@ -7,6 +7,7 @@ using System.Text.Json; |
|
|
using System.Threading; |
|
|
using System.Threading; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using EFCore.BulkExtensions; |
|
|
using EFCore.BulkExtensions; |
|
|
|
|
|
using LinqToDB.EntityFrameworkCore; |
|
|
using Magicodes.ExporterAndImporter.Core.Extension; |
|
|
using Magicodes.ExporterAndImporter.Core.Extension; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore; |
|
@ -30,12 +31,13 @@ public class VmiAsyncBalanceService : Controller, IApplicationService, IJobServi |
|
|
{ |
|
|
{ |
|
|
private readonly IServiceProvider _serviceProvider; |
|
|
private readonly IServiceProvider _serviceProvider; |
|
|
private readonly ILogger<VmiAsyncBalanceService> _logger; |
|
|
private readonly ILogger<VmiAsyncBalanceService> _logger; |
|
|
private static SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1, 1); |
|
|
private static readonly SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1, 1); |
|
|
|
|
|
|
|
|
public VmiAsyncBalanceService(IServiceProvider serviceProvider, ILogger<VmiAsyncBalanceService> logger) |
|
|
public VmiAsyncBalanceService(IServiceProvider serviceProvider, ILogger<VmiAsyncBalanceService> logger) |
|
|
{ |
|
|
{ |
|
|
this._serviceProvider = serviceProvider; |
|
|
this._serviceProvider = serviceProvider; |
|
|
this._logger = logger; |
|
|
this._logger = logger; |
|
|
|
|
|
LinqToDBForEFTools.Initialize(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -66,7 +68,7 @@ public class VmiAsyncBalanceService : Controller, IApplicationService, IJobServi |
|
|
|
|
|
|
|
|
private async Task InvokeInternal(IServiceProvider serviceProvider) |
|
|
private async Task InvokeInternal(IServiceProvider serviceProvider) |
|
|
{ |
|
|
{ |
|
|
var batchSize = 1000; |
|
|
var batchSize = 10000; |
|
|
var fetchSize = 0; |
|
|
var fetchSize = 0; |
|
|
var connectionString = serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
var connectionString = serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
for (var i = 0; i < 1000; i++) |
|
|
for (var i = 0; i < 1000; i++) |
|
@ -121,8 +123,6 @@ public class VmiAsyncBalanceService : Controller, IApplicationService, IJobServi |
|
|
{ |
|
|
{ |
|
|
command.CommandText = $"select * into {table} from Set_VmiLog where 1=0;"; |
|
|
command.CommandText = $"select * into {table} from Set_VmiLog where 1=0;"; |
|
|
command.ExecuteNonQuery(); |
|
|
command.ExecuteNonQuery(); |
|
|
command.CommandText = $"create clustered index IX_{table}_ChangedTime on {table} (ChangedTime);"; |
|
|
|
|
|
command.ExecuteNonQuery(); |
|
|
|
|
|
command.CommandText = $"alter table {table} add constraint PK_{table} primary key (Id);"; |
|
|
command.CommandText = $"alter table {table} add constraint PK_{table} primary key (Id);"; |
|
|
command.ExecuteNonQuery(); |
|
|
command.ExecuteNonQuery(); |
|
|
} |
|
|
} |
|
@ -231,15 +231,12 @@ public class VmiAsyncBalanceService : Controller, IApplicationService, IJobServi |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//更新事务分表
|
|
|
//更新事务分表
|
|
|
//foreach (var item in tables)
|
|
|
foreach (var item in tables) |
|
|
//{
|
|
|
{ |
|
|
// var logs = list.Where(o => o.Table == item).Select(o => o.Log).ToList();
|
|
|
var logs = list.Where(o => o.Table == item).Select(o => o.Log).ToList(); |
|
|
// var xxx= logs.Select(o=>o.Id).Distinct().ToList();
|
|
|
//await context.BulkInsertAsync(logs, new BulkConfig { CustomDestinationTableName = item, }).ConfigureAwait(false);
|
|
|
// await context.BulkInsertAsync(logs, new BulkConfig
|
|
|
await context.BulkCopyAsync(new LinqToDB.Data.BulkCopyOptions { TableName = item }, logs).ConfigureAwait(false); |
|
|
// {
|
|
|
} |
|
|
// CustomDestinationTableName = item,
|
|
|
|
|
|
// }).ConfigureAwait(false);
|
|
|
|
|
|
//}
|
|
|
|
|
|
//批量更新消息
|
|
|
//批量更新消息
|
|
|
await context.BulkUpdateAsync(messages, new BulkConfig |
|
|
await context.BulkUpdateAsync(messages, new BulkConfig |
|
|
{ |
|
|
{ |
|
@ -248,19 +245,10 @@ public class VmiAsyncBalanceService : Controller, IApplicationService, IJobServi |
|
|
//批量插入负库存补货记录
|
|
|
//批量插入负库存补货记录
|
|
|
await context.BulkInsertAsync(vmiReplenishedList).ConfigureAwait(false); |
|
|
await context.BulkInsertAsync(vmiReplenishedList).ConfigureAwait(false); |
|
|
//批量插入库存余额
|
|
|
//批量插入库存余额
|
|
|
var addList = balanceList.Where(o => o.Item2 == 1 && o.Item1.Qty != decimal.Zero).Select(o => o.Item1).ToList(); |
|
|
|
|
|
var test0 = addList.Count; |
|
|
|
|
|
var test1 = addList.Select(o => o.Id).Distinct().Count(); |
|
|
|
|
|
await context.BulkInsertAsync(balanceList.Where(o => o.Item2 == 1 && o.Item1.Qty != decimal.Zero).Select(o => o.Item1).ToList()).ConfigureAwait(false); |
|
|
await context.BulkInsertAsync(balanceList.Where(o => o.Item2 == 1 && o.Item1.Qty != decimal.Zero).Select(o => o.Item1).ToList()).ConfigureAwait(false); |
|
|
//批量更新库存余额
|
|
|
//批量更新库存余额
|
|
|
var updateList = balanceList.Where(o => o.Item2 == 2 && o.Item1.Qty != decimal.Zero).Select(o => o.Item1).ToList(); |
|
|
|
|
|
var test20 = updateList.Count; |
|
|
|
|
|
var test21 = updateList.Select(o => o.Id).Distinct().Count(); |
|
|
|
|
|
await context.BulkUpdateAsync(balanceList.Where(o => o.Item2 == 2 && o.Item1.Qty != decimal.Zero).Select(o => o.Item1).ToList()).ConfigureAwait(false); |
|
|
await context.BulkUpdateAsync(balanceList.Where(o => o.Item2 == 2 && o.Item1.Qty != decimal.Zero).Select(o => o.Item1).ToList()).ConfigureAwait(false); |
|
|
//批量删除库存余额
|
|
|
//批量删除库存余额
|
|
|
var deleteList = balanceList.Where(o => o.Item2 == 2 && o.Item1.Qty == decimal.Zero).Select(o => o.Item1).ToList(); |
|
|
|
|
|
var test30 = addList.Count; |
|
|
|
|
|
var test31 = addList.Select(o => o.Id).Distinct().Count(); |
|
|
|
|
|
await context.BulkDeleteAsync(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); |
|
|
transaction.Commit(); |
|
|
transaction.Commit(); |
|
|
} |
|
|
} |
|
|