2024-12-10 14:03:09 +08:00
|
|
|
|
using MesETL.App.HostedServices;
|
|
|
|
|
|
|
|
|
|
namespace MesETL.App.Options;
|
2024-01-04 09:00:44 +08:00
|
|
|
|
|
|
|
|
|
public class DatabaseOutputOptions
|
|
|
|
|
{
|
2024-12-10 14:03:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 输出数据库的连接字符串
|
|
|
|
|
/// </summary>
|
2024-01-29 09:29:16 +08:00
|
|
|
|
public string? ConnectionString { get; set; }
|
|
|
|
|
|
2024-12-10 14:03:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// MySql max_allowed_packet变量值大小
|
|
|
|
|
/// </summary>
|
2024-02-15 16:18:50 +08:00
|
|
|
|
public int MaxAllowedPacket { get; set; } = 32 * 1024 * 1024;
|
2024-01-29 09:29:16 +08:00
|
|
|
|
|
2024-12-10 14:03:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 每次Insert提交的数据量
|
|
|
|
|
/// </summary>
|
2024-01-29 09:29:16 +08:00
|
|
|
|
public int FlushCount { get; set; } = 10000;
|
|
|
|
|
|
2024-12-10 14:03:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 每个数据库最大提交任务数
|
|
|
|
|
/// </summary>
|
2024-01-29 09:29:16 +08:00
|
|
|
|
public int MaxDatabaseOutputTask { get; set; } = 4;
|
|
|
|
|
|
2024-12-10 14:03:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 将json列作为16进制格式输出(0x前缀)
|
|
|
|
|
/// </summary>
|
2024-01-29 09:29:16 +08:00
|
|
|
|
public bool TreatJsonAsHex { get; set; } = true;
|
2024-02-15 16:18:50 +08:00
|
|
|
|
|
2024-12-10 14:03:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不对某些表进行输出
|
|
|
|
|
/// </summary>
|
2024-02-15 16:18:50 +08:00
|
|
|
|
public string[] NoOutput { get; set; } = [];
|
2024-01-29 09:29:16 +08:00
|
|
|
|
|
2024-12-10 14:03:09 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>当某张表的键出现重复时,在输出时使用ON DUPLICATE KEY UPDATE更新该条记录</para>
|
|
|
|
|
/// <para>表名为键,更新的字段为值</para>
|
|
|
|
|
/// <example>
|
|
|
|
|
/// <code>
|
|
|
|
|
/// {
|
|
|
|
|
/// // 当order_data_parts表的键出现重复时,使用ON DUPLICATE KEY UPDATE更新已存在记录的CompanyID为新插入记录的值
|
|
|
|
|
/// "order_data_parts": "CompanyID = new.CompanyID"
|
|
|
|
|
/// }
|
|
|
|
|
/// </code>
|
|
|
|
|
/// </example>
|
|
|
|
|
/// </summary>
|
2024-02-15 16:18:50 +08:00
|
|
|
|
public Dictionary<string, string>? ForUpdate { get; set; }
|
2024-01-29 09:29:16 +08:00
|
|
|
|
|
2024-01-04 09:00:44 +08:00
|
|
|
|
/// <summary>
|
2024-12-10 14:03:09 +08:00
|
|
|
|
/// 配置导入数据的特殊列,请在代码中配置
|
2024-01-04 09:00:44 +08:00
|
|
|
|
/// </summary>
|
2024-01-29 09:29:16 +08:00
|
|
|
|
public Dictionary<string, ColumnType> ColumnTypeConfig { get; set; } = new(); // "table.column" -> type
|
2024-12-10 14:03:09 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 所有数据都输出完毕时的事件,请在代码中配置
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action<DataOutputContext>? OutputFinished { get; set; }
|
2024-01-29 09:29:16 +08:00
|
|
|
|
|
|
|
|
|
public ColumnType GetColumnType(string table, string column)
|
|
|
|
|
{
|
2024-12-10 14:03:09 +08:00
|
|
|
|
return ColumnTypeConfig.GetValueOrDefault(string.Concat(table, ".", column), ColumnType.UnDefine);
|
2024-01-29 09:29:16 +08:00
|
|
|
|
}
|
2024-02-15 16:18:50 +08:00
|
|
|
|
|
|
|
|
|
public bool TryGetForUpdate(string table, out string? forUpdate)
|
|
|
|
|
{
|
|
|
|
|
forUpdate = null;
|
|
|
|
|
if (ForUpdate is null || !ForUpdate.TryGetValue(table, out forUpdate))
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-01-04 09:00:44 +08:00
|
|
|
|
}
|