|
|
@ -11,6 +11,7 @@ using ZKLT.Hadoop.Model;
|
|
|
|
using MySqlX.XDevAPI.Relational;
|
|
|
|
using MySqlX.XDevAPI.Relational;
|
|
|
|
using Mysqlx.Crud;
|
|
|
|
using Mysqlx.Crud;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
using Mysqlx.Resultset;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ZKLT.Hadoop
|
|
|
|
namespace ZKLT.Hadoop
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -43,9 +44,11 @@ namespace ZKLT.Hadoop
|
|
|
|
param.Add(_column.Key!, row![_column.Key!]);
|
|
|
|
param.Add(_column.Key!, row![_column.Key!]);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case HDP_WhereType.BETWEEN:
|
|
|
|
case HDP_WhereType.BETWEEN:
|
|
|
|
if (row![_column.Key!] != null) {
|
|
|
|
if (row![_column.Key!] != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
var _betweendata = JsonConvert.DeserializeObject<object[]>(JsonConvert.SerializeObject(row![_column.Key!]));
|
|
|
|
var _betweendata = JsonConvert.DeserializeObject<object[]>(JsonConvert.SerializeObject(row![_column.Key!]));
|
|
|
|
if (_betweendata != null) {
|
|
|
|
if (_betweendata != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (_betweendata[0] != null && _betweendata[0].ToString() != "")
|
|
|
|
if (_betweendata[0] != null && _betweendata[0].ToString() != "")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` >= @{_column.Key!}0");
|
|
|
|
_wherestr.Append($@" AND `{_column.Key!}` >= @{_column.Key!}0");
|
|
|
@ -97,6 +100,56 @@ namespace ZKLT.Hadoop
|
|
|
|
command.AppendLine(_colstr.ToString());
|
|
|
|
command.AppendLine(_colstr.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 合并排序
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="table">表</param>
|
|
|
|
|
|
|
|
/// <param name="order">排序</param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
private string MergeOrder(HDP_Table table, Dictionary<string, object>? order, Dictionary<string, object> param)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
StringBuilder _orderstr = new StringBuilder();
|
|
|
|
|
|
|
|
if (order != null && order.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_orderstr.Append("ORDER BY ");
|
|
|
|
|
|
|
|
foreach (var key in order.Keys)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (table.Columns!.Any(x => x.Key == key))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var _column = table.Columns!.First(x => x.Key == key);
|
|
|
|
|
|
|
|
if (order[key] is string)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (order[key])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case "DESC":
|
|
|
|
|
|
|
|
_orderstr.Append($@"`{_column.Key!}` DESC,");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
_orderstr.Append($@"`{_column.Key!}` ASC,");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (order[key] is Newtonsoft.Json.Linq.JArray)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var _orderTemp = JsonConvert.DeserializeObject<object[]>(JsonConvert.SerializeObject(order[key]));
|
|
|
|
|
|
|
|
_orderstr.Append(@$"CASE `{_column.Key!}`");
|
|
|
|
|
|
|
|
for (var i = 0; i < _orderTemp!.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_orderstr.Append(@$" WHEN @OR{_column.Key}{i} THEN {i}");
|
|
|
|
|
|
|
|
param.Add($@"@OR{_column.Key}{i}", _orderTemp[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_orderstr.Append($@" ELSE {_orderTemp.Length} END,");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_orderstr.Length > 0 && _orderstr[_orderstr.Length - 1] == ',')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_orderstr.Remove(_orderstr.Length - 1, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return _orderstr.ToString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 同步结构
|
|
|
|
/// 同步结构
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -621,7 +674,7 @@ namespace ZKLT.Hadoop
|
|
|
|
/// <param name="row">数据</param>
|
|
|
|
/// <param name="row">数据</param>
|
|
|
|
/// <returns>结果集</returns>
|
|
|
|
/// <returns>结果集</returns>
|
|
|
|
public T[] Query<T>(HDP_Source source, HDP_Table table, Dictionary<string, string>? where, Dictionary<string, object>? row,
|
|
|
|
public T[] Query<T>(HDP_Source source, HDP_Table table, Dictionary<string, string>? where, Dictionary<string, object>? row,
|
|
|
|
Dictionary<string, string>? order, string[]? col)
|
|
|
|
Dictionary<string, object>? order, string[]? col)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//数据校验
|
|
|
|
//数据校验
|
|
|
|
if (string.IsNullOrEmpty(table.Key))
|
|
|
|
if (string.IsNullOrEmpty(table.Key))
|
|
|
@ -661,32 +714,8 @@ namespace ZKLT.Hadoop
|
|
|
|
MergeWhere(table, where, row, _command, _params);
|
|
|
|
MergeWhere(table, where, row, _command, _params);
|
|
|
|
|
|
|
|
|
|
|
|
//执行排序
|
|
|
|
//执行排序
|
|
|
|
StringBuilder _orderstr = new StringBuilder();
|
|
|
|
_command.AppendLine(MergeOrder(table, order, _params));
|
|
|
|
_orderstr.Append("ORDER BY ");
|
|
|
|
|
|
|
|
if (order != null && order.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (var i = 0; i < table.Columns.Length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var _column = table.Columns[i];
|
|
|
|
|
|
|
|
if (order.ContainsKey(_column.Key!))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (order[_column.Key!])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case "DESC":
|
|
|
|
|
|
|
|
_orderstr.Append($@"`{_column.Key!}` DESC,");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
_orderstr.Append($@"`{_column.Key!}` ASC,");
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_orderstr[_orderstr.Length - 1] == ',')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_orderstr.Remove(_orderstr.Length - 1, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_command.AppendLine(_orderstr.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var _result = _connection.Query<T>(_command.ToString(), _params);
|
|
|
|
var _result = _connection.Query<T>(_command.ToString(), _params);
|
|
|
|
_connection.Close();
|
|
|
|
_connection.Close();
|
|
|
|
return _result.ToArray();
|
|
|
|
return _result.ToArray();
|
|
|
@ -703,7 +732,7 @@ namespace ZKLT.Hadoop
|
|
|
|
/// <param name="row">数据</param>
|
|
|
|
/// <param name="row">数据</param>
|
|
|
|
/// <returns>结果集</returns>
|
|
|
|
/// <returns>结果集</returns>
|
|
|
|
public HDP_Page<T> QueryPage<T>(HDP_Source source, HDP_Table table, int pageIndex, int pageSize, Dictionary<string, string>? where,
|
|
|
|
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)
|
|
|
|
Dictionary<string, object>? row, Dictionary<string, object>? order, string[]? col)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//数据校验
|
|
|
|
//数据校验
|
|
|
|
if (string.IsNullOrEmpty(table.Key))
|
|
|
|
if (string.IsNullOrEmpty(table.Key))
|
|
|
|