diff --git a/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs b/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs index a8a6c80..a65953a 100644 --- a/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs +++ b/Hadoop/ZKLT.Hadoop.API/Controllers/HadoopController.cs @@ -307,5 +307,18 @@ namespace ZKLT.Hadoop.API.Controllers return BadRequest(e.Message); } } + + [HttpPost("storedProcedure")] + public ActionResult StoredProcedure(HDP_Command command) + { + try + { + return Ok(_HadoopService.StoredProcedure(command)); + } + catch (Exception e) + { + return BadRequest(e.Message); + } + } } } diff --git a/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs b/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs index c5c394b..287866b 100644 --- a/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs +++ b/Hadoop/ZKLT.Hadoop.Interface/IHadoopService.cs @@ -120,5 +120,13 @@ namespace ZKLT.Hadoop.Interface /// 指令 /// public object?[] PatchCommand(HDP_Command[] command); + + /// + /// 存储过程 + /// + /// + /// + /// + public T? StoredProcedure(HDP_Command command); } } diff --git a/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs b/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs index 4925ef4..43310d6 100644 --- a/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs +++ b/Hadoop/ZKLT.Hadoop.Interface/ITableService.cs @@ -136,5 +136,14 @@ namespace ZKLT.Hadoop.Interface /// 表 /// public HDP_Column[] DbGetColumns(string sourceId, string tableId); + + /// + /// 执行存储过程 + /// + /// + /// + /// + /// + public T? StoredProcedure(string sourceId, string name, JToken? data); } } diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs index a5c00e5..5b4ba9b 100644 --- a/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs +++ b/Hadoop/ZKLT.Hadoop.Model/HDP_Command.cs @@ -26,6 +26,8 @@ namespace ZKLT.Hadoop.Model private string[]? _Col; + private string? _StoredProcedureName; + private JToken? _Where; private JToken? _Data; @@ -42,6 +44,11 @@ namespace ZKLT.Hadoop.Model /// public string? TableId { get => _TableId; set => _TableId = value; } + /// + /// 存储过程名 + /// + public string? StoredProcedureName { get => _StoredProcedureName; set => _StoredProcedureName = value; } + /// /// 条件 /// diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_StoredParams.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_StoredParams.cs new file mode 100644 index 0000000..c9163bc --- /dev/null +++ b/Hadoop/ZKLT.Hadoop.Model/HDP_StoredParams.cs @@ -0,0 +1,31 @@ +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ZKLT.Hadoop; + +namespace ZKLT.Hadoop.Model +{ + /// + /// 存储过程 + /// + public class HDP_StoredParams + { + + private string _Name; + + private JToken? _Params; + + /// + /// 存储过程名称 + /// + public string Name { get => _Name; set => _Name = value; } + + /// + /// 存储过程参数 + /// + public JToken? Params { get => _Params; set => _Params = value; } + } +} diff --git a/Hadoop/ZKLT.Hadoop/HadoopService.cs b/Hadoop/ZKLT.Hadoop/HadoopService.cs index c2ff30c..f95e89b 100644 --- a/Hadoop/ZKLT.Hadoop/HadoopService.cs +++ b/Hadoop/ZKLT.Hadoop/HadoopService.cs @@ -188,7 +188,7 @@ namespace ZKLT.Hadoop throw; } } - + if (_TableService.InitStruct("", table)) { using (TransactionScope _scope = new TransactionScope()) @@ -485,6 +485,10 @@ namespace ZKLT.Hadoop } return _result.ToArray(); } - + + public T? StoredProcedure(HDP_Command command) + { + return _TableService.StoredProcedure(command.SourceId!, command.StoredProcedureName!, command.Data!); + } } } diff --git a/Hadoop/ZKLT.Hadoop/TableService.cs b/Hadoop/ZKLT.Hadoop/TableService.cs index 3dff2c2..0dca58b 100644 --- a/Hadoop/ZKLT.Hadoop/TableService.cs +++ b/Hadoop/ZKLT.Hadoop/TableService.cs @@ -14,6 +14,9 @@ using Newtonsoft.Json; using Mysqlx.Resultset; using Newtonsoft.Json.Linq; using System.Transactions; +using Org.BouncyCastle.Asn1.X509; +using static System.Runtime.InteropServices.JavaScript.JSType; +using System.Data; namespace ZKLT.Hadoop { @@ -1142,5 +1145,57 @@ namespace ZKLT.Hadoop return _result.ToArray(); } } + + /// + /// 执行存储过程 + /// + /// + /// + /// + /// + public T? StoredProcedure(string sourceId,string name, JToken? data) + { + var source = GetSource(sourceId); + using (MySqlConnection _connection = new MySqlConnection(source.GetConnectString())) + { + try + { + _connection.Open(); + } + catch + { + throw new ArgumentException("数据源连接失败"); + } + using (MySqlCommand _command = new MySqlCommand(name, _connection)) + { + _command.CommandType = CommandType.StoredProcedure; + if (data != null) + { + var _datas = data.ToObject>()!; + foreach (var item in _datas) + { + _command.Parameters.AddWithValue(item.Key, item.Value); + } + } + using (MySqlDataReader _reader = _command.ExecuteReader()) + { + var _result = new List>(); + while (_reader.Read()) + { + var row = new Dictionary(); + for (int i = 0; i < _reader.FieldCount; i++) + { + row[_reader.GetName(i)] = _reader.GetValue(i); + } + _result.Add(row); + } + _reader.Close(); + _connection.Close(); + return (T)(object)_result; + } + } + + } + } } }