修改Like错误,并且封装where条件方法

main
潘建东 7 months ago
parent 8514a1f4bd
commit 97d01f98a7

@ -15,6 +15,42 @@ namespace ZKLT.Hadoop
{
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>
@ -398,26 +434,7 @@ namespace ZKLT.Hadoop
_command.AppendLine(_colstr.ToString());
//执行条件
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());
MergeWhere(table, where, row, _command, _params);
var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params);
_connection.Close();
@ -475,27 +492,7 @@ namespace ZKLT.Hadoop
Dictionary<string, object> _params = new Dictionary<string, object>();
_command.AppendLine(@$"DELETE FROM `{table.Key}`");
//执行条件
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());
MergeWhere(table, where, row, _command, _params);
var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params);
_connection.Close();
@ -554,26 +551,7 @@ namespace ZKLT.Hadoop
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
//执行条件
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());
MergeWhere(table, where, row, _command, _params);
var _result = _connection.Query<T>(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params).ToArray();
_connection.Close();
@ -625,29 +603,7 @@ namespace ZKLT.Hadoop
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
//执行条件
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;
}
_params.Add(_column.Key!, row[_column.Key!]);
}
}
_command.AppendLine(_wherestr.ToString());
}
MergeWhere(table, where, row, _command, _params);
//执行排序
StringBuilder _orderstr = new StringBuilder();
@ -719,29 +675,8 @@ namespace ZKLT.Hadoop
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
//执行条件
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!]} '%' + @{_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());
}
MergeWhere(table, where, row, _command, _params);
//执行排序
StringBuilder _orderstr = new StringBuilder();
_orderstr.Append("ORDER BY ");

Loading…
Cancel
Save