From 044c6c50be693c74b4fe6073f7a887c0aa55f529 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=BD=98=E5=BB=BA=E4=B8=9C?= <617601767@qq.com>
Date: Mon, 5 Aug 2024 10:52:19 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=88=97=E8=A1=A8?=
=?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Hadoop/ZKLT.Hadoop/TableService.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Hadoop/ZKLT.Hadoop/TableService.cs b/Hadoop/ZKLT.Hadoop/TableService.cs
index 3d2850d..3a4d9d1 100644
--- a/Hadoop/ZKLT.Hadoop/TableService.cs
+++ b/Hadoop/ZKLT.Hadoop/TableService.cs
@@ -765,6 +765,8 @@ namespace ZKLT.Hadoop
/// 数据表
/// 条件
/// 数据
+ /// 排序
+ /// 筛选返回字段
/// 结果集
public T[] Query(HDP_Source source, HDP_Table table, JContainer? where, JContainer? data,
JContainer? order, string[]? col)
From 0078a00557a7dbebe4251ba9facfd4c29f1a8203 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=BD=98=E5=BB=BA=E4=B8=9C?= <617601767@qq.com>
Date: Wed, 7 Aug 2024 16:39:44 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/HadoopController.cs | 9 +-
.../ZKLT.Hadoop.Interface/IHadoopService.cs | 20 -
Hadoop/ZKLT.Hadoop.Interface/ITableService.cs | 96 +++--
Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs | 14 +-
Hadoop/ZKLT.Hadoop.Model/HDP_CommandAction.cs | 2 +-
Hadoop/ZKLT.Hadoop.Model/HDP_WhereType.cs | 2 +
Hadoop/ZKLT.Hadoop/HadoopService.cs | 270 ++----------
Hadoop/ZKLT.Hadoop/TableService.cs | 400 +++++++++++++-----
8 files changed, 402 insertions(+), 411 deletions(-)
diff --git a/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs b/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs
index 54a4098..74af2ef 100644
--- a/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs
+++ b/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs
@@ -14,13 +14,16 @@ namespace ZKLT.Hadoop.API.Controllers
[ApiController]
public class HadoopController : ControllerBase
{
- public HadoopController(IHadoopService hadoop)
+ public HadoopController(IHadoopService hadoop,ITableService table)
{
_HadoopService = hadoop;
+ _TableService = table;
}
private IHadoopService _HadoopService;
+ private ITableService _TableService;
+
[HttpGet("getid")]
public ActionResult GetId([FromQuery] string? prefix, [FromQuery] int? count) {
if (count != null && count > 0)
@@ -61,7 +64,7 @@ namespace ZKLT.Hadoop.API.Controllers
{
try
{
- return Ok(_HadoopService.GetSource(sourceid));
+ return Ok(_TableService.GetSource(sourceid));
}
catch (Exception e)
{
@@ -126,7 +129,7 @@ namespace ZKLT.Hadoop.API.Controllers
{
try
{
- return Ok(_HadoopService.GetTable(tableid));
+ return Ok(_TableService.GetTable(tableid));
}
catch (Exception e)
{
diff --git a/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs b/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs
index f0813b5..c5c394b 100644
--- a/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs
+++ b/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs
@@ -13,19 +13,6 @@ namespace ZKLT.Hadoop.Interface
///
public interface IHadoopService
{
- ///
- /// 初始化云计算
- ///
- /// 配置
- public void Init(Action config);
-
- ///
- /// 获取源
- ///
- /// 数据源编号
- /// 结果
- public HDP_Source? GetSource(string sourceid);
-
///
/// 创建源
///
@@ -54,13 +41,6 @@ namespace ZKLT.Hadoop.Interface
/// 结果
public HDP_Source[] QuerySource(HDP_Command command);
- ///
- /// 获取表
- ///
- /// 表编号
- /// 结果
- public HDP_Table? GetTable(string tableid);
-
///
/// 创建表
///
diff --git a/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs b/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs
index 047f9cb..4925ef4 100644
--- a/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs
+++ b/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs
@@ -4,36 +4,58 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Transactions;
using ZKLT.Hadoop.Model;
namespace ZKLT.Hadoop.Interface
{
public interface ITableService
{
+ ///
+ /// 初始化云计算
+ ///
+ /// 配置
+ public void Init(Action config);
+
+ ///
+ /// 获取源
+ ///
+ /// 数据源编号
+ /// 结果
+ public HDP_Source GetSource(string sourceid);
+
+ ///
+ /// 获取表
+ ///
+ /// 表编号
+ /// 结果
+ public HDP_Table GetTable(string tableid);
+
+
///
/// 同步结构
///
- /// 数据源
+ /// 数据源
/// 数据表
/// 是否成功
- public bool InitStruct(HDP_Source source, HDP_Table table);
+ public bool InitStruct(string sourceId, HDP_Table table);
///
/// 删除结构
///
- /// 源
- /// 表
+ /// 源
+ /// 表
/// 是否成功
- public bool RemoveStruct(HDP_Source source, string tableKey);
+ public bool RemoveStruct(string sourceId, string tableId);
///
/// 插入数据
///
- /// 数据源
- /// 数据表
- /// 数据
+ /// 数据源
+ /// 数据表
+ /// 数据
/// 是否成功
- public bool Insert(HDP_Source source, HDP_Table table, JContainer? row);
+ public bool Insert(string sourceId, string tableId, JToken? data);
///
/// 更新
@@ -41,29 +63,30 @@ namespace ZKLT.Hadoop.Interface
/// 数据源
/// 数据表
/// 条件
- /// 数据
+ /// 数据
/// 是否成功
- public bool Update(HDP_Source source, HDP_Table table, JContainer? where, JContainer? row);
+ public bool Update(string sourceId, string tableId, JToken? where, JToken? data);
///
/// 删除
///
- /// 数据源
- /// 数据表
+ /// 数据源
+ /// 数据表
/// 条件
/// 数据
/// 是否成功
- public bool Delete(HDP_Source source, HDP_Table table, JContainer? where, JContainer? row);
+ public bool Delete(string sourceId, string tableId, JToken? where, JToken? data);
///
/// 查询单个
///
- /// 数据源
- /// 数据表
+ /// 数据源
+ /// 数据表
/// 条件
- /// 数据
+ /// 数据
/// 结果
- public T? QuerySingle(HDP_Source source, HDP_Table table, JContainer? where, JContainer? row, string[]? col);
+ public T? QuerySingle(string sourceId, string tableId, JToken? where, JToken? data,
+ string[]? col);
///
/// 查询列表
@@ -72,37 +95,46 @@ namespace ZKLT.Hadoop.Interface
/// 数据源
/// 数据表
/// 条件
- /// 数据
+ /// 数据
+ /// 排序
+ /// 筛选返回字段
/// 结果集
- public T[] Query(HDP_Source source, HDP_Table table, JContainer? where, JContainer? row,
- JContainer? order, string[]? col);
+ public T[] Query(string sourceId, string tableId, JToken? where, JToken? data,
+ JToken? order, string[]? col);
+
+ public string QueryString(string sourceId, string tableId, JToken? where, JToken? data,
+ JToken? order, string[]? col, Dictionary param);
///
- /// 查询列表
+ /// 查询分页列表
///
/// 返回类型
- /// 数据源
- /// 数据表
+ /// 数据源
+ /// 数据表
+ /// 分页下标
+ /// 分页大小
/// 条件
- /// 数据
+ /// 数据
+ /// 排序
+ /// 返回咧
/// 结果集
- public HDP_Page QueryPage(HDP_Source source, HDP_Table table, int pageIndex, int pageSize, JContainer? where, JContainer? row, JContainer? order, string[]? col);
-
+ public HDP_Page QueryPage(string sourceId, string tableId, int pageIndex, int pageSize, JToken? where,
+ JToken? data, JToken? order, string[]? col);
///
/// 判断数据源是否存在表
///
- /// 数据源
+ /// 数据源
/// 表名
/// 是否存在
- public bool DbExistTable(HDP_Source source, string tableName);
+ public bool DbExistTable(string sourceId, string tableName);
///
/// 查询数据列
///
- /// 数据源
- /// 表名
+ /// 数据源
+ /// 表
/// 列
- public HDP_Column[] DbGetColumns(HDP_Source source, string tableName);
+ public HDP_Column[] DbGetColumns(string sourceId, string tableId);
}
}
diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs
index bf6f4b1..a5c00e5 100644
--- a/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs
+++ b/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using ZKLT.Hadoop;
namespace ZKLT.Hadoop.Model
{
@@ -12,6 +13,7 @@ namespace ZKLT.Hadoop.Model
///
public class HDP_Command
{
+
private string? _SourceId;
private string? _TableId;
@@ -24,11 +26,11 @@ namespace ZKLT.Hadoop.Model
private string[]? _Col;
- private JContainer? _Where;
+ private JToken? _Where;
- private JContainer? _Data;
+ private JToken? _Data;
- private JContainer? _Order;
+ private JToken? _Order;
///
/// 源
@@ -43,12 +45,12 @@ namespace ZKLT.Hadoop.Model
///
/// 条件
///
- public JContainer? Where { get => _Where; set => _Where = value; }
+ public JToken? Where { get => _Where; set => _Where = value; }
///
/// 数据
///
- public JContainer? Data { get => _Data; set => _Data = value; }
+ public JToken? Data { get => _Data; set => _Data = value; }
///
/// 分页下标
@@ -63,7 +65,7 @@ namespace ZKLT.Hadoop.Model
///
/// 排序
///
- public JContainer? Order { get => _Order; set => _Order = value; }
+ public JToken? Order { get => _Order; set => _Order = value; }
///
/// 命令类型
diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_CommandAction.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_CommandAction.cs
index c92a5fd..78a4fd6 100644
--- a/Hadoop/ZKLT.Hadoop.Model/HDP_CommandAction.cs
+++ b/Hadoop/ZKLT.Hadoop.Model/HDP_CommandAction.cs
@@ -29,7 +29,7 @@ namespace ZKLT.Hadoop.Model
/// 函数
/// 参数
/// 命令
- public static object Convert(string action, JContainer param)
+ public static object Convert(string action, JToken param)
{
if (action == DATENOW)
{
diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_WhereType.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_WhereType.cs
index b39275b..893a2e3 100644
--- a/Hadoop/ZKLT.Hadoop.Model/HDP_WhereType.cs
+++ b/Hadoop/ZKLT.Hadoop.Model/HDP_WhereType.cs
@@ -25,5 +25,7 @@ namespace ZKLT.Hadoop.Model
public const string IN = "IN";
public const string BETWEEN = "BETWEEN";
+
+ public const string QUERYIN = "QUERYIN";
}
}
diff --git a/Hadoop/ZKLT.Hadoop/HadoopService.cs b/Hadoop/ZKLT.Hadoop/HadoopService.cs
index 44291c3..3cde3c4 100644
--- a/Hadoop/ZKLT.Hadoop/HadoopService.cs
+++ b/Hadoop/ZKLT.Hadoop/HadoopService.cs
@@ -38,8 +38,8 @@ namespace ZKLT.Hadoop
///
public static IApplicationBuilder UseHadoop(this IApplicationBuilder app, Action config)
{
- var _HadoopService = app.ApplicationServices.GetRequiredService();
- _HadoopService.Init(config);
+ var _TableService = app.ApplicationServices.GetRequiredService();
+ _TableService.Init(config);
return app;
}
}
@@ -52,105 +52,10 @@ namespace ZKLT.Hadoop
public HadoopService(ITableService tableService)
{
_TableService = tableService;
-
- _Source = new HDP_Source();
-
- _Tables = new List();
}
private ITableService _TableService;
- private HDP_Source _Source;
-
- private List _Tables;
-
- ///
- /// 初始化云计算
- ///
- /// 配置
- public void Init(Action config)
- {
- if (config == null)
- {
- throw new ArgumentNullException("配置无效");
- }
- config(_Source);
-
- //参数校验
- if (string.IsNullOrEmpty(_Source.Host))
- {
- throw new ArgumentException("主机无效");
- }
- if (string.IsNullOrEmpty(_Source.Key))
- {
- throw new ArgumentException("源无效");
- }
- if (string.IsNullOrEmpty(_Source.Account))
- {
- throw new ArgumentException("用户名无效");
- }
- if (string.IsNullOrEmpty(_Source.PassWord))
- {
- throw new ArgumentException("密码无效");
- }
-
- //初始化
- if (_Source.Port == null)
- {
- _Source.Port = 3306;
- }
- if (string.IsNullOrEmpty(_Source.Id))
- {
- _Source.Id = "";
- }
- if (string.IsNullOrEmpty(_Source.Description))
- {
- _Source.Description = "云计算系统";
- }
-
- var _source = HDP_Table.Class2Table();
- _Tables.Add(_source);
- if (!_TableService.InitStruct(_Source, _source))
- {
- throw new Exception("初始化数据源失败");
- }
-
- var _table = HDP_Table.Class2Table();
- _Tables.Add(_table);
- if (!_TableService.InitStruct(_Source, _table))
- {
- throw new Exception("初始化数据表失败");
- }
-
- var _column = HDP_Table.Class2Table();
- _Tables.Add(_column);
- if (!_TableService.InitStruct(_Source, _column))
- {
- throw new Exception("初始化数据列失败");
- }
- }
-
- ///
- /// 获取源
- ///
- /// 数据源编号
- /// 结果
- public HDP_Source? GetSource(string sourceid)
- {
- if (string.IsNullOrEmpty(sourceid) || _Source.Id == sourceid)
- {
- return _Source;
- }
-
- var _result = _TableService.QuerySingle(_Source, GetTable("HDP_Source")!, new JObject
- {
- { "Id","=" }
- }, new JObject {
- { "Id",sourceid}
- }, null);
- return _result;
- }
-
///
/// 创建源
///
@@ -183,12 +88,12 @@ namespace ZKLT.Hadoop
{
throw new ArgumentNullException("密码无效");
}
- if (GetSource(source.Id) != null)
+ if (_TableService.GetSource(source.Id) != null)
{
throw new ArgumentException("编号已存在");
}
- return _TableService.Insert(_Source, GetTable("HDP_Source")!, HDP_Table.Class2JObject(source));
+ return _TableService.Insert("", "HDP_Source", HDP_Table.Class2JObject(source));
}
///
@@ -223,12 +128,8 @@ namespace ZKLT.Hadoop
{
throw new ArgumentNullException("密码无效");
}
- if (GetSource(source.Id) == null)
- {
- throw new ArgumentException("编号不存在");
- }
- return _TableService.Update(_Source, GetTable("HDP_Source")!, new JObject {
+ return _TableService.Update(source.Id, "HDP_Source", new JObject {
{"Id","=" }
}, HDP_Table.Class2JObject(source));
}
@@ -240,17 +141,7 @@ namespace ZKLT.Hadoop
/// 是否成功
public bool DeleteSource(string sourceid)
{
- //校验
- if (string.IsNullOrEmpty(sourceid))
- {
- throw new ArgumentNullException("编号无效");
- }
- if (GetSource(sourceid) == null)
- {
- throw new ArgumentException("编号不存在");
- }
-
- return _TableService.Delete(_Source, GetTable("HDP_Source")!, new JObject{
+ return _TableService.Delete(sourceid, "HDP_Source", new JObject{
{"Id","=" }
}, new JObject{
{"Id",sourceid }
@@ -264,44 +155,9 @@ namespace ZKLT.Hadoop
/// 结果
public HDP_Source[] QuerySource(HDP_Command command)
{
- return _TableService.Query(_Source, GetTable("HDP_Source")!, command.Where!, command.Data!, command.Order!, command.Col);
+ return _TableService.Query(command.SourceId!, command.TableId!, command.Where!, command.Data!, command.Order!, command.Col);
}
- ///
- /// 获取表
- ///
- /// 表编号
- /// 结果
- public HDP_Table? GetTable(string tableid)
- {
- if (string.IsNullOrEmpty(tableid))
- {
- throw new ArgumentNullException("数据表编号无效");
- }
-
- if (_Tables.Any(x => x.Id == tableid))
- {
- return _Tables.First(x => x.Id == tableid);
- }
-
- var _result = _TableService.QuerySingle(_Source, GetTable("HDP_Table")!, new JObject
- {
- { "Id","=" }
- }, new JObject{
- { "Id",tableid}
- }, null);
-
- if (_result != null)
- {
- _result.Columns = _TableService.Query(_Source, GetTable("HDP_Column")!, new JObject {
- { "TableId","="}
- }, new JObject{
- {"TableId",_result.Id! }
- }, null, null);
- }
-
- return _result;
- }
///
/// 创建表
@@ -310,19 +166,15 @@ namespace ZKLT.Hadoop
/// 是否成功
public bool InsertTable(HDP_Table table)
{
- if (string.IsNullOrEmpty(table.Id))
- {
- throw new ArgumentNullException("表编号无效");
- }
- if (GetTable(table.Id) != null)
+ if (_TableService.GetTable(table.Id) != null)
{
throw new ArgumentNullException("表编号已存在");
}
- if (_TableService.InitStruct(_Source, table))
+ if (_TableService.InitStruct("", table))
{
using (TransactionScope _scope = new TransactionScope())
{
- if (!_TableService.Insert(_Source, GetTable("HDP_Table")!, HDP_Table.Class2JObject(table)))
+ if (!_TableService.Insert("", "HDP_Table", HDP_Table.Class2JObject(table)))
{
return false;
}
@@ -330,7 +182,7 @@ namespace ZKLT.Hadoop
{
var _column = table.Columns![i];
_column.TableId = table.Id;
- if (!_TableService.Insert(_Source, GetTable("HDP_Column")!, HDP_Table.Class2JObject(_column)))
+ if (!_TableService.Insert("", "HDP_Column", HDP_Table.Class2JObject(_column)))
{
return false;
}
@@ -352,19 +204,11 @@ namespace ZKLT.Hadoop
/// 是否成功
public bool UpdateTable(HDP_Table table)
{
- if (string.IsNullOrEmpty(table.Id))
- {
- throw new ArgumentNullException("表编号无效");
- }
- if (GetTable(table.Id) == null)
- {
- throw new ArgumentNullException("表编号不存在");
- }
- if (_TableService.InitStruct(_Source, table))
+ if (_TableService.InitStruct("", table))
{
using (TransactionScope _scope = new TransactionScope())
{
- if (!_TableService.Update(_Source, GetTable("HDP_Table")!, new JObject{
+ if (!_TableService.Update("", "HDP_Table", new JObject{
{ "Id","="}
}, HDP_Table.Class2JObject(table)))
{
@@ -375,19 +219,19 @@ namespace ZKLT.Hadoop
{
var _column = table.Columns![i];
_column.TableId = table.Id;
- if (_TableService.QuerySingle(_Source, GetTable("HDP_Column")!, new JObject
+ if (_TableService.QuerySingle("", "HDP_Column", new JObject
{
{"Id","=" }
}, HDP_Table.Class2JObject(_column), null) == null)
{
- if (!_TableService.Insert(_Source, GetTable("HDP_Column")!, HDP_Table.Class2JObject(_column)))
+ if (!_TableService.Insert("", "HDP_Column", HDP_Table.Class2JObject(_column)))
{
return false;
}
}
else
{
- if (!_TableService.Update(_Source, GetTable("HDP_Column")!, new JObject {
+ if (!_TableService.Update("", "HDP_Column", new JObject {
{"Id","=" }
}, HDP_Table.Class2JObject(_column)))
{
@@ -418,14 +262,10 @@ namespace ZKLT.Hadoop
{
throw new ArgumentNullException("编号无效");
}
- if (GetTable(tableId) == null)
- {
- throw new ArgumentException("编号不存在");
- }
using (TransactionScope _scope = new TransactionScope())
{
- if (!_TableService.Delete(_Source, GetTable("HDP_Table")!, new JObject{
+ if (!_TableService.Delete("", "HDP_Table", new JObject{
{"Id","=" }
}, new JObject {
{"Id",tableId }
@@ -433,7 +273,7 @@ namespace ZKLT.Hadoop
{
return false;
}
- if (!_TableService.Delete(_Source, GetTable("HDP_Column")!, new JObject{
+ if (!_TableService.Delete("", "HDP_Column", new JObject{
{ "TableId","="}
}, new JObject {
{"TableId",tableId }
@@ -454,7 +294,7 @@ namespace ZKLT.Hadoop
/// 结果
public HDP_Table[] QueryTable(HDP_Command command)
{
- return _TableService.Query(_Source, GetTable("HDP_Table")!, command.Where!, command.Data!, command.Order!, command.Col!);
+ return _TableService.Query("", "HDP_Table", command.Where!, command.Data!, command.Order!, command.Col!);
}
///
@@ -464,17 +304,7 @@ namespace ZKLT.Hadoop
/// 是否成功
public bool Insert(HDP_Command command)
{
- if (string.IsNullOrEmpty(command.TableId))
- {
- throw new ArgumentNullException("表无效");
- }
- var _table = GetTable(command.TableId);
- if (_table == null)
- {
- throw new ArgumentException("表不存在");
- }
- var _source = GetSource(_table.SourceId!);
- return _TableService.Insert(_source!, _table, command.Data!);
+ return _TableService.Insert(command.SourceId!, command.TableId!, command.Data!);
}
///
@@ -484,17 +314,7 @@ namespace ZKLT.Hadoop
/// 是否成功
public bool Update(HDP_Command command)
{
- if (string.IsNullOrEmpty(command.TableId))
- {
- throw new ArgumentNullException("表无效");
- }
- var _table = GetTable(command.TableId);
- if (_table == null)
- {
- throw new ArgumentException("表不存在");
- }
- var _source = GetSource(_table.SourceId!);
- return _TableService.Update(_source!, _table, command.Where!, command.Data!);
+ return _TableService.Update(command.SourceId!, command.TableId!, command.Where!, command.Data!);
}
///
@@ -504,17 +324,7 @@ namespace ZKLT.Hadoop
/// 是否成功
public bool Delete(HDP_Command command)
{
- if (string.IsNullOrEmpty(command.TableId))
- {
- throw new ArgumentNullException("表无效");
- }
- var _table = GetTable(command.TableId);
- if (_table == null)
- {
- throw new ArgumentException("表不存在");
- }
- var _source = GetSource(_table.SourceId!);
- return _TableService.Delete(_source!, _table, command.Where!, command.Data!);
+ return _TableService.Delete(command.SourceId!, command.TableId!, command.Where!, command.Data!);
}
///
@@ -525,17 +335,7 @@ namespace ZKLT.Hadoop
/// 结果
public T? QuerySingle(HDP_Command command)
{
- if (string.IsNullOrEmpty(command.TableId))
- {
- throw new ArgumentNullException("表无效");
- }
- var _table = GetTable(command.TableId);
- if (_table == null)
- {
- throw new ArgumentException("表不存在");
- }
- var _source = GetSource(_table.SourceId!);
- return _TableService.QuerySingle(_source!, _table, command.Where!, command.Data!, command.Col);
+ return _TableService.QuerySingle(command.SourceId!, command.TableId!, command.Where!, command.Data!, command.Col);
}
///
@@ -546,17 +346,7 @@ namespace ZKLT.Hadoop
/// 结果
public T[] Query(HDP_Command command)
{
- if (string.IsNullOrEmpty(command.TableId))
- {
- throw new ArgumentNullException("表无效");
- }
- var _table = GetTable(command.TableId);
- if (_table == null)
- {
- throw new ArgumentException("表不存在");
- }
- var _source = GetSource(_table.SourceId!);
- return _TableService.Query(_source!, _table, command.Where!, command.Data!, command.Order!, command.Col);
+ return _TableService.Query(command.SourceId!, command.TableId!, command.Where!, command.Data!, command.Order!, command.Col);
}
///
@@ -567,10 +357,6 @@ namespace ZKLT.Hadoop
/// 结果
public HDP_Page Page(HDP_Command command)
{
- if (string.IsNullOrEmpty(command.TableId))
- {
- throw new ArgumentNullException("表无效");
- }
if (command.PageIndex == null || command.PageIndex <= 0)
{
throw new ArgumentNullException("分页下标无效");
@@ -579,13 +365,7 @@ namespace ZKLT.Hadoop
{
throw new ArgumentNullException("分页大小无效");
}
- var _table = GetTable(command.TableId);
- if (_table == null)
- {
- throw new ArgumentException("表不存在");
- }
- var _source = GetSource(_table.SourceId!);
- return _TableService.QueryPage(_source!, _table, (int)command.PageIndex, (int)command.PageSize, command.Where!, command.Data!, command.Order!, command.Col!);
+ return _TableService.QueryPage(command.SourceId!, command.TableId!, (int)command.PageIndex, (int)command.PageSize, command.Where!, command.Data!, command.Order!, command.Col!);
}
///
diff --git a/Hadoop/ZKLT.Hadoop/TableService.cs b/Hadoop/ZKLT.Hadoop/TableService.cs
index 3a4d9d1..6bc4552 100644
--- a/Hadoop/ZKLT.Hadoop/TableService.cs
+++ b/Hadoop/ZKLT.Hadoop/TableService.cs
@@ -19,6 +19,17 @@ namespace ZKLT.Hadoop
{
public class TableService : ITableService
{
+ public TableService()
+ {
+ _Source = new HDP_Source();
+
+ _Tables = new List();
+ }
+
+ private HDP_Source _Source;
+
+ private List _Tables;
+
///
/// 合并条件
///
@@ -26,7 +37,7 @@ namespace ZKLT.Hadoop
/// 条件
/// 数据
/// 参数
- private string MergeWhere(HDP_Table table, JContainer? where, JContainer? data, Dictionary param)
+ private string MergeWhere(HDP_Table table, JToken? where, JToken? data, Dictionary param)
{
StringBuilder _wherestr = new StringBuilder();
string _guid = "";
@@ -42,14 +53,16 @@ namespace ZKLT.Hadoop
}
else if (where.Type == JTokenType.Array)
{
- for(var i = 0;i < where.Count;i++)
+ for (var i = 0; i < where.Count(); i++)
{
_wheres.Add((JObject)where.Children().ToArray()[i]);
- _datas.Add((JObject)data.Children().ToArray()[i]);
+ _datas.Add((JObject)data.Children().ToArray()[i]);
}
}
- for (var j = 0; j < _wheres.Count; j++) {
- if (j > 0) {
+ for (var j = 0; j < _wheres.Count; j++)
+ {
+ if (j > 0)
+ {
_wherestr.AppendLine("OR");
}
_wherestr.AppendLine("(");
@@ -64,31 +77,52 @@ namespace ZKLT.Hadoop
var _item = (JProperty)_fileds[i];
if (table.Columns!.Any(x => x.Key == _item.Name) && _data.ContainsKey(_item.Name))
{
+ List _Itemv = new List();
+ List _Colv = new List();
if (_item.Value.Type == JTokenType.String)
{
- _guid = Guid.NewGuid().ToString("N");
- _wherestr.AppendLine(@$"AND `{_item.Name}` {_item.Value.ToString()} @{_guid}");
- if (_data[_item.Name]!.Type == JTokenType.Object || _data[_item.Name]!.Type == JTokenType.Array)
- {
- param.Add(_guid, _data[_item.Name]!);
- }
- else if (_item.Value.ToString() == HDP_WhereType.LIKE)
- {
- param.Add(_guid,$@"%{((JValue)_data[_item.Name]!).Value!}%" );
- }
- else {
- param.Add(_guid, ((JValue)_data[_item.Name]!).Value!);
- }
+ _Itemv.Add(_item.Value.ToString());
+ _Colv.Add(_data[_item.Name]!);
}
else if (_item.Value.Type == JTokenType.Array)
{
- string[] _itemv = _item.Value.ToObject()!;
- object[] _colv = _data[_item.Name]!.ToObject