|
|
@ -9,6 +9,7 @@ using System.Reflection; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using ClosedXML.Excel; |
|
|
|
using LinqToDB.Data; |
|
|
|
using LinqToDB.EntityFrameworkCore; |
|
|
|
using Magicodes.ExporterAndImporter.Core; |
|
|
|
using Magicodes.ExporterAndImporter.Core.Extension; |
|
|
@ -72,6 +73,40 @@ public class VmiAppService : ApplicationService, IJobService, ITransientDependen |
|
|
|
LinqToDBForEFTools.Initialize(); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
public async Task Test(List<VmiLog> logs, int size = 1000) |
|
|
|
{ |
|
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
|
using var dc = db.CreateLinqToDBConnection(); |
|
|
|
dc.BeginTransaction(); |
|
|
|
try |
|
|
|
{ |
|
|
|
//var skip = 0;
|
|
|
|
//var count = logs.Count;
|
|
|
|
//while (count > 0)
|
|
|
|
//{
|
|
|
|
// var batchSize = count > size ? size : count;
|
|
|
|
// var tempLogs = logs.Skip(skip).Take(batchSize);
|
|
|
|
// var tempMessages = tempLogs.Select(o => new VmiMessage { Message = JsonSerializer.Serialize(o) });
|
|
|
|
// await dc.BulkCopyAsync(new BulkCopyOptions { TableName = "Set_VmiLog" }, tempLogs).ConfigureAwait(false);
|
|
|
|
// await dc.BulkCopyAsync(new BulkCopyOptions { TableName = "Set_VmiMessage" }, tempMessages).ConfigureAwait(false);
|
|
|
|
// count -= batchSize;
|
|
|
|
// skip += batchSize;
|
|
|
|
//}
|
|
|
|
await dc.BulkCopyAsync(new BulkCopyOptions { TableName = "Set_VmiMessage", MaxBatchSize = 1 }, new List<VmiMessage> { |
|
|
|
new VmiMessage(Guid.NewGuid()) { Message="1" }, |
|
|
|
new VmiMessage(Guid.NewGuid()) { Message="2" } |
|
|
|
}).ConfigureAwait(false); |
|
|
|
dc.Transaction.Commit(); |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
dc.Transaction.Rollback(); |
|
|
|
throw; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Excel 转 JSON
|
|
|
|
/// </summary>
|
|
|
@ -125,11 +160,12 @@ public class VmiAppService : ApplicationService, IJobService, ITransientDependen |
|
|
|
using var transaction = db.Database.BeginTransaction(); |
|
|
|
try |
|
|
|
{ |
|
|
|
var table = $"Set_VmiBalance_{DateTime.Now.ToString("yyyy_mm_dd_hh_mm_ss")}"; |
|
|
|
var time = DateTime.Now.ToString("yyyy_mm_dd_hh_mm_ss"); |
|
|
|
var table = $"Set_VmiBalance_{time}"; |
|
|
|
var snapshot = db.Set<VmiSnapshot>().Where(o => o.Name == table).FirstOrDefault(); |
|
|
|
if (snapshot == null) |
|
|
|
{ |
|
|
|
snapshot = new VmiSnapshot { Name = table, Path = table }; |
|
|
|
snapshot = new VmiSnapshot { Name = time, Path = table }; |
|
|
|
db.Set<VmiSnapshot>().Add(snapshot); |
|
|
|
db.SaveChanges(); |
|
|
|
var result = db.Database.ExecuteSqlRaw($"select * into {table} from Set_VmiBalance;"); |
|
|
|