增加查询接口列设置

pull/1/head
潘建东 8 months ago
parent eb63fd5088
commit d9df8b5111

@ -62,7 +62,7 @@ namespace ZKLT.Hadoop.Interface
/// <param name="where">条件</param>
/// <param name="row">数据</param>
/// <returns>结果</returns>
public T? QuerySingle<T>(HDP_Source source, HDP_Table table, Dictionary<string, string> where, Dictionary<string, object> row);
public T? QuerySingle<T>(HDP_Source source, HDP_Table table, Dictionary<string, string> where, Dictionary<string, object> row, string[]? col);
/// <summary>
/// 查询列表
@ -73,7 +73,7 @@ namespace ZKLT.Hadoop.Interface
/// <param name="where">条件</param>
/// <param name="row">数据</param>
/// <returns>结果集</returns>
public T[] Query<T>(HDP_Source source, HDP_Table table, Dictionary<string, string>? where = null, Dictionary<string, object>? row = null, Dictionary<string, string>? order = null);
public T[] Query<T>(HDP_Source source, HDP_Table table, Dictionary<string, string>? where, Dictionary<string, object>? row, Dictionary<string, string>? order, string[]? col);
/// <summary>
/// 查询列表
@ -84,7 +84,7 @@ namespace ZKLT.Hadoop.Interface
/// <param name="where">条件</param>
/// <param name="row">数据</param>
/// <returns>结果集</returns>
public HDP_Page<T> QueryPage<T>(HDP_Source source, HDP_Table table, int pageIndex, int pageSize, Dictionary<string, string>? where = null, Dictionary<string, object>? row = null, Dictionary<string, string>? order = null);
public HDP_Page<T> QueryPage<T>(HDP_Source source, HDP_Table table, int pageIndex, int pageSize, Dictionary<string, string>? where, Dictionary<string, object>? row, Dictionary<string, string>? order, string[]? col);
/// <summary>

@ -21,6 +21,8 @@ namespace ZKLT.Hadoop.Model
private string? _Type;
private string[]? _Col;
private Dictionary<string, string>? _Where;
private Dictionary<string, object>? _Data;
@ -66,5 +68,10 @@ namespace ZKLT.Hadoop.Model
/// 命令类型
/// </summary>
public string? Type { get => _Type; set => _Type = value; }
/// <summary>
/// 列
/// </summary>
public string[]? Col { get => _Col; set => _Col = value; }
}
}

@ -145,7 +145,7 @@ namespace ZKLT.Hadoop
{ "Id","=" }
}, new Dictionary<string, object> {
{ "Id",sourceid}
});
}, null);
return _result;
}
@ -262,7 +262,7 @@ namespace ZKLT.Hadoop
/// <returns>结果</returns>
public HDP_Source[] QuerySource(HDP_Command command)
{
return _TableService.Query<HDP_Source>(_Source, GetTable("HDP_Source")!, command.Where!, command.Data!, command.Order!);
return _TableService.Query<HDP_Source>(_Source, GetTable("HDP_Source")!, command.Where!, command.Data!, command.Order!, command.Col);
}
/// <summary>
@ -287,7 +287,7 @@ namespace ZKLT.Hadoop
{ "Id","=" }
}, new Dictionary<string, object> {
{ "Id",tableid}
});
}, null);
if (_result != null)
{
@ -295,7 +295,7 @@ namespace ZKLT.Hadoop
{ "TableId","="}
}, new Dictionary<string, object> {
{"TableId",_result.Id! }
});
}, null, null);
}
return _result;
@ -376,7 +376,7 @@ namespace ZKLT.Hadoop
if (_TableService.QuerySingle<HDP_Column>(_Source, GetTable("HDP_Column")!, new Dictionary<string, string>
{
{"Id","=" }
}, HDP_Table.Class2Dictionary(_column)) == null)
}, HDP_Table.Class2Dictionary(_column), null) == null)
{
if (!_TableService.Insert(_Source, GetTable("HDP_Column")!, HDP_Table.Class2Dictionary(_column)))
{
@ -452,7 +452,7 @@ namespace ZKLT.Hadoop
/// <returns>结果</returns>
public HDP_Table[] QueryTable(HDP_Command command)
{
return _TableService.Query<HDP_Table>(_Source, GetTable("HDP_Table")!, command.Where!, command.Data!, command.Order!);
return _TableService.Query<HDP_Table>(_Source, GetTable("HDP_Table")!, command.Where!, command.Data!, command.Order!, command.Col!);
}
/// <summary>
@ -533,7 +533,7 @@ namespace ZKLT.Hadoop
throw new ArgumentException("表不存在");
}
var _source = GetSource(_table.SourceId!);
return _TableService.QuerySingle<T>(_source!, _table, command.Where!, command.Data!);
return _TableService.QuerySingle<T>(_source!, _table, command.Where!, command.Data!, command.Col);
}
/// <summary>
@ -554,7 +554,7 @@ namespace ZKLT.Hadoop
throw new ArgumentException("表不存在");
}
var _source = GetSource(_table.SourceId!);
return _TableService.Query<T>(_source!, _table, command.Where!, command.Data!, command.Order!);
return _TableService.Query<T>(_source!, _table, command.Where!, command.Data!, command.Order!, command.Col);
}
/// <summary>
@ -583,7 +583,7 @@ namespace ZKLT.Hadoop
throw new ArgumentException("表不存在");
}
var _source = GetSource(_table.SourceId!);
return _TableService.QueryPage<T>(_source!, _table, (int)command.PageIndex, (int)command.PageSize, command.Where!, command.Data!, command.Order!);
return _TableService.QueryPage<T>(_source!, _table, (int)command.PageIndex, (int)command.PageSize, command.Where!, command.Data!, command.Order!, command.Col!);
}
/// <summary>

@ -51,6 +51,33 @@ namespace ZKLT.Hadoop
}
}
/// <summary>
/// 合并列
/// </summary>
/// <param name="table">表</param>
/// <param name="cols">列</param>
/// <param name="command">命令</param>
private void MergeCols(HDP_Table table, string[]? cols, StringBuilder command)
{
if (cols == null || cols.Length == 0)
{
command.AppendLine(" * ");
}
StringBuilder _colstr = new StringBuilder();
for (var i = 0; i < table.Columns!.Length; i++)
{
if (cols!.Any(x => x == table.Columns[i].Key))
{
_colstr.Append($@"`{table.Columns[i].Key}`,");
}
}
if (_colstr[_colstr.Length - 1] == ',')
{
_colstr.Remove(_colstr.Length - 1, 1);
}
command.AppendLine(_colstr.ToString());
}
/// <summary>
/// 同步结构
/// </summary>
@ -504,7 +531,8 @@ namespace ZKLT.Hadoop
/// <param name="where">条件</param>
/// <param name="row">数据</param>
/// <returns>结果</returns>
public T? QuerySingle<T>(HDP_Source source, HDP_Table table, Dictionary<string, string> where, Dictionary<string, object> row)
public T? QuerySingle<T>(HDP_Source source, HDP_Table table, Dictionary<string, string> where, Dictionary<string, object> row,
string[]? col)
{
//数据校验
if (string.IsNullOrEmpty(table.Key))
@ -537,7 +565,16 @@ namespace ZKLT.Hadoop
//查询命令
StringBuilder _command = new StringBuilder();
Dictionary<string, object> _params = new Dictionary<string, object>();
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
if (col == null || col.Length == 0)
{
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
}
else
{
_command.AppendLine("SELECT");
MergeCols(table, col, _command);
_command.AppendLine($@"FROM `{table.Key}`");
}
//执行条件
MergeWhere(table, where, row, _command, _params);
@ -564,7 +601,8 @@ namespace ZKLT.Hadoop
/// <param name="where">条件</param>
/// <param name="row">数据</param>
/// <returns>结果集</returns>
public T[] Query<T>(HDP_Source source, HDP_Table table, Dictionary<string, string>? where = null, Dictionary<string, object>? row = null, Dictionary<string, string>? order = null)
public T[] Query<T>(HDP_Source source, HDP_Table table, Dictionary<string, string>? where, Dictionary<string, object>? row,
Dictionary<string, string>? order, string[]? col)
{
//数据校验
if (string.IsNullOrEmpty(table.Key))
@ -589,7 +627,16 @@ namespace ZKLT.Hadoop
//查询命令
StringBuilder _command = new StringBuilder();
Dictionary<string, object> _params = new Dictionary<string, object>();
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
if (col == null || col.Length == 0)
{
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
}
else
{
_command.AppendLine("SELECT");
MergeCols(table, col, _command);
_command.AppendLine($@"FROM `{table.Key}`");
}
//执行条件
MergeWhere(table, where, row, _command, _params);
@ -636,7 +683,8 @@ namespace ZKLT.Hadoop
/// <param name="where">条件</param>
/// <param name="row">数据</param>
/// <returns>结果集</returns>
public HDP_Page<T> QueryPage<T>(HDP_Source source, HDP_Table table, int pageIndex, int pageSize, Dictionary<string, string>? where = null, Dictionary<string, object>? row = null, Dictionary<string, string>? order = null)
public HDP_Page<T> QueryPage<T>(HDP_Source source, HDP_Table table, int pageIndex, int pageSize, Dictionary<string, string>? where,
Dictionary<string, object>? row, Dictionary<string, string>? order, string[]? col)
{
//数据校验
if (string.IsNullOrEmpty(table.Key))
@ -661,7 +709,16 @@ namespace ZKLT.Hadoop
//查询命令
StringBuilder _command = new StringBuilder();
Dictionary<string, object> _params = new Dictionary<string, object>();
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
if (col == null || col.Length == 0)
{
_command.AppendLine(@$"SELECT * FROM `{table.Key}`");
}
else
{
_command.AppendLine("SELECT");
MergeCols(table, col, _command);
_command.AppendLine($@"FROM `{table.Key}`");
}
//执行条件
MergeWhere(table, where, row, _command, _params);

Loading…
Cancel
Save