整理代码

This commit is contained in:
2024-01-16 18:00:23 +08:00
parent 78cd833617
commit a74cf5ddb7
7 changed files with 344 additions and 136 deletions

View File

@@ -1,6 +1,9 @@
using System.Text;
using System.Reflection.Metadata;
using System.Text;
using ConsoleApp2.Helpers;
using ConsoleApp2.Options;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using MySqlConnector;
using ServiceStack;
@@ -48,14 +51,14 @@ public class MySqlDestination : IDisposable, IAsyncDisposable
}
}
public async Task FlushAsync(int maxAllowPacket)
public async Task FlushAsync(int maxAllowPacket, IOptions<DataTransformOptions> transOptions)
{
if (_recordCache.Count == 0)
return;
var cmd = _conn.CreateCommand();
cmd.CommandTimeout = 3 * 60;
var excuseList = GetExcuseList(_recordCache, maxAllowPacket, _prettyOutput);
var excuseList = GetExcuseList(_recordCache, maxAllowPacket, transOptions, _prettyOutput);
try
{
foreach (var insertSql in excuseList)
@@ -77,7 +80,7 @@ public class MySqlDestination : IDisposable, IAsyncDisposable
}
}
public static IList<string> GetExcuseList(IDictionary<string, IList<DataRecord>> tableRecords,int maxAllowPacket,
public static IList<string> GetExcuseList(IDictionary<string, IList<DataRecord>> tableRecords,int maxAllowPacket, IOptions<DataTransformOptions> transOptions,
bool prettyOutput = false)
{
var resultList = new List<string>();
@@ -109,8 +112,14 @@ public class MySqlDestination : IDisposable, IAsyncDisposable
for (var j = 0; j < record.Fields.Length; j++)
{
var field = record.Fields[j];
if (record.TableName == "order_block_plan_result" && j == 2)
var header = record.Headers[j];
if (transOptions.Value.GetColumnType(record.TableName, header) ==ColumnType.Blob)
{
if (string.IsNullOrEmpty(field))
{
recordSb.Append("NULL");
}
else
recordSb.Append("0x"+field);
}
else