multTasks #2
@ -1,83 +0,0 @@
|
|||||||
using ConsoleApp2.HostedServices.Abstractions;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ConsoleApp2.Const;
|
|
||||||
using ConsoleApp2.Options;
|
|
||||||
using ConsoleApp2.Services;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using System.Reflection.PortableExecutable;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using ConsoleApp2.SimulationService;
|
|
||||||
|
|
||||||
namespace ConsoleApp2.HostedServices
|
|
||||||
{
|
|
||||||
public class TestInputService : IInputService
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
private readonly IOptions<CsvOptions> _csvOptions;
|
|
||||||
private readonly DataRecordQueue _producerQueue;
|
|
||||||
private readonly ProcessContext _context;
|
|
||||||
public TestInputService(ILogger<TestInputService> logger,
|
|
||||||
IOptions<CsvOptions> csvOptions,
|
|
||||||
[FromKeyedServices(ProcessStep.Producer)] DataRecordQueue producerQueue,
|
|
||||||
ProcessContext context)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
_csvOptions = csvOptions;
|
|
||||||
_producerQueue = producerQueue;
|
|
||||||
_context = context;
|
|
||||||
}
|
|
||||||
public async Task ExecuteAsync(TasksOptions tasksOptions, DataRecordQueue producerQueue, ProcessContext context, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var tableName = "order_item";
|
|
||||||
var headers = new string[] { "ID","OrderNo","ItemNo","ItemType","RoomID","BoxID","DataID","PlanID","PackageID","Num","CompanyID","ShardKey" };
|
|
||||||
var dataCount = 1200000000L;
|
|
||||||
var tempCount = 80000;
|
|
||||||
var tempRecords=new List<DataRecord>();
|
|
||||||
var comanyID = 1;
|
|
||||||
short[] shareKeys = { 23040, 23070, 23100, 24000, 24040, 24070, 24100, 25000, 25040, 25070, 25100 };
|
|
||||||
int[] companyIds = { 1, 2, 3, 4 };
|
|
||||||
var sk = shareKeys.First();
|
|
||||||
var companyID = companyIds.First();
|
|
||||||
|
|
||||||
var shareKeyInterval = 20000;
|
|
||||||
var getShareKeyTimes = 0;
|
|
||||||
var getCompanyIDTimes = 0;
|
|
||||||
var shareKeyIntervalCount = 0;
|
|
||||||
for (long i = 1; i <= dataCount; i++)
|
|
||||||
{
|
|
||||||
shareKeyIntervalCount++;
|
|
||||||
if (shareKeyIntervalCount > shareKeyInterval) {
|
|
||||||
sk=DataHelper.GetShareKey(getShareKeyTimes);
|
|
||||||
getShareKeyTimes++;
|
|
||||||
shareKeyIntervalCount = 0;
|
|
||||||
}
|
|
||||||
var fields = new string[] { i.ToString(), "20220104020855", (220105981029 + i).ToString(), "1", "482278", "482279", "3768774", "0", "0", "1", companyID.ToString(), sk.ToString() };
|
|
||||||
var record = new DataRecord(fields, tableName, headers, comanyID);
|
|
||||||
tempRecords.Add(record);
|
|
||||||
if (tempRecords.Count >= tempCount)
|
|
||||||
{
|
|
||||||
foreach (var rc in tempRecords)
|
|
||||||
{
|
|
||||||
_context.AddInput();
|
|
||||||
_producerQueue.Enqueue(rc);
|
|
||||||
if (cancellationToken.IsCancellationRequested)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tempRecords.Clear();
|
|
||||||
companyID = DataHelper. GetCompanyId(getCompanyIDTimes);
|
|
||||||
getCompanyIDTimes++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_context.CompleteInput();
|
|
||||||
_logger.LogInformation("***** Csv input service completed *****");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user