|
|
@ -15,6 +15,42 @@ namespace ZKLT.Hadoop
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class TableService : ITableService
|
|
|
|
public class TableService : ITableService
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 合并条件
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="table">表</param>
|
|
|
|
|
|
|
|
/// <param name="where">条件</param>
|
|
|
|
|
|
|
|
/// <param name="row">数据</param>
|
|
|
|
|
|
|
|
/// <param name="command">命令</param>
|
|
|
|
|
|
|
|
/// <param name="param">参数</param>
|
|
|
|
|
|
|
|
private void MergeWhere(HDP_Table table, Dictionary<string, string>? where, Dictionary<string, object>? row, StringBuilder command, Dictionary<string, object> param)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//执行条件
|
|
|
|
|
|
|
|
StringBuilder _wherestr = new StringBuilder();
|
|
|
|
|
|
|
|
_wherestr.Append("WHERE 1 = 1");
|
|
|
|
|
|
|
|
if (where != null && where.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (var i = 0; i < table.Columns!.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var _column = table.Columns[i];
|
|
|
|
|
|
|
|
if (where.ContainsKey(_column.Key!))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (where[_column.Key!])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case HDP_WhereType.LIKE:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} CONCAT('%',@{_column.Key!},'%')");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} @{_column.Key!}");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
param.Add(_column.Key!, row![_column.Key!]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
command.AppendLine(_wherestr.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 同步结构
|
|
|
|
/// 同步结构
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -398,26 +434,7 @@ namespace ZKLT.Hadoop
|
|
|
|
_command.AppendLine(_colstr.ToString());
|
|
|
|
_command.AppendLine(_colstr.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
//执行条件
|
|
|
|
//执行条件
|
|
|
|
StringBuilder _wherestr = new StringBuilder();
|
|
|
|
MergeWhere(table, where, row, _command, _params);
|
|
|
|
_wherestr.Append("WHERE 1 = 1");
|
|
|
|
|
|
|
|
for (var i = 0; i < table.Columns.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var _column = table.Columns[i];
|
|
|
|
|
|
|
|
if (where.ContainsKey(_column.Key!))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (where[_column.Key!])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case HDP_WhereType.LIKE:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} '%' + @{_column.Key!} + '%'");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} @{_column.Key!}");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_params.Add(_column.Key!, row[_column.Key!]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_command.AppendLine(_wherestr.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params);
|
|
|
|
var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params);
|
|
|
|
_connection.Close();
|
|
|
|
_connection.Close();
|
|
|
@ -475,27 +492,7 @@ namespace ZKLT.Hadoop
|
|
|
|
Dictionary<string, object> _params = new Dictionary<string, object>();
|
|
|
|
Dictionary<string, object> _params = new Dictionary<string, object>();
|
|
|
|
_command.AppendLine(@$"DELETE FROM `{table.Key}`");
|
|
|
|
_command.AppendLine(@$"DELETE FROM `{table.Key}`");
|
|
|
|
|
|
|
|
|
|
|
|
//执行条件
|
|
|
|
MergeWhere(table, where, row, _command, _params);
|
|
|
|
StringBuilder _wherestr = new StringBuilder();
|
|
|
|
|
|
|
|
_wherestr.Append("WHERE 1 = 1");
|
|
|
|
|
|
|
|
for (var i = 0; i < table.Columns.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var _column = table.Columns[i];
|
|
|
|
|
|
|
|
if (where.ContainsKey(_column.Key!))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (where[_column.Key!])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case HDP_WhereType.LIKE:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} '%' + @{_column.Key!} + '%'");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} @{_column.Key!}");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_params.Add(_column.Key!, row[_column.Key!]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_command.AppendLine(_wherestr.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params);
|
|
|
|
var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params);
|
|
|
|
_connection.Close();
|
|
|
|
_connection.Close();
|
|
|
@ -554,26 +551,7 @@ namespace ZKLT.Hadoop
|
|
|
|
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
|
|
|
|
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
|
|
|
|
|
|
|
|
|
|
|
|
//执行条件
|
|
|
|
//执行条件
|
|
|
|
StringBuilder _wherestr = new StringBuilder();
|
|
|
|
MergeWhere(table, where, row, _command, _params);
|
|
|
|
_wherestr.Append("WHERE 1 = 1");
|
|
|
|
|
|
|
|
for (var i = 0; i < table.Columns.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var _column = table.Columns[i];
|
|
|
|
|
|
|
|
if (where.ContainsKey(_column.Key!))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (where[_column.Key!])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case HDP_WhereType.LIKE:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} '%' + @{_column.Key!} + '%'");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} @{_column.Key!}");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_params.Add(_column.Key!, row[_column.Key!]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_command.AppendLine(_wherestr.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var _result = _connection.Query<T>(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params).ToArray();
|
|
|
|
var _result = _connection.Query<T>(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params).ToArray();
|
|
|
|
_connection.Close();
|
|
|
|
_connection.Close();
|
|
|
@ -625,29 +603,7 @@ namespace ZKLT.Hadoop
|
|
|
|
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
|
|
|
|
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
|
|
|
|
|
|
|
|
|
|
|
|
//执行条件
|
|
|
|
//执行条件
|
|
|
|
StringBuilder _wherestr = new StringBuilder();
|
|
|
|
MergeWhere(table, where, row, _command, _params);
|
|
|
|
_wherestr.Append("WHERE 1 = 1");
|
|
|
|
|
|
|
|
if (where != null && where.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (var i = 0; i < table.Columns.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var _column = table.Columns[i];
|
|
|
|
|
|
|
|
if (where.ContainsKey(_column.Key!))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (where[_column.Key!])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case HDP_WhereType.LIKE:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} CONCAT('%',@{_column.Key!},'%')");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} @{_column.Key!}");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_params.Add(_column.Key!, row[_column.Key!]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_command.AppendLine(_wherestr.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//执行排序
|
|
|
|
//执行排序
|
|
|
|
StringBuilder _orderstr = new StringBuilder();
|
|
|
|
StringBuilder _orderstr = new StringBuilder();
|
|
|
@ -719,29 +675,8 @@ namespace ZKLT.Hadoop
|
|
|
|
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
|
|
|
|
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
|
|
|
|
|
|
|
|
|
|
|
|
//执行条件
|
|
|
|
//执行条件
|
|
|
|
StringBuilder _wherestr = new StringBuilder();
|
|
|
|
MergeWhere(table, where, row, _command, _params);
|
|
|
|
_wherestr.Append("WHERE 1 = 1");
|
|
|
|
|
|
|
|
if (where != null && where.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (var i = 0; i < table.Columns.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var _column = table.Columns[i];
|
|
|
|
|
|
|
|
if (where.ContainsKey(_column.Key!))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (where[_column.Key!])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case HDP_WhereType.LIKE:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} '%' + @{_column.Key!} + '%'");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` {where[_column.Key!]} @{_column.Key!}");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_params.Add(_column.Key!, row[_column.Key!]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_command.AppendLine(_wherestr.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//执行排序
|
|
|
|
//执行排序
|
|
|
|
StringBuilder _orderstr = new StringBuilder();
|
|
|
|
StringBuilder _orderstr = new StringBuilder();
|
|
|
|
_orderstr.Append("ORDER BY ");
|
|
|
|
_orderstr.Append("ORDER BY ");
|
|
|
|