diff --git a/Hadoop/ZKLT.Hadoop.API/Program.cs b/Hadoop/ZKLT.Hadoop.API/Program.cs index 98637bc..3d373ef 100644 --- a/Hadoop/ZKLT.Hadoop.API/Program.cs +++ b/Hadoop/ZKLT.Hadoop.API/Program.cs @@ -40,34 +40,34 @@ namespace ZKLT.Hadoop.API app.UseCors("all"); #endregion + app.UseHadoop((c) => + { + c.Host = "127.0.0.1"; + c.Account = "root"; + c.PassWord = "root"; + c.Key = "devdb"; + c.Port = 3306; + }); + + //app.UseHadoop((c) => //{ - // c.Host = "127.0.0.1"; + // c.Host = "172.17.0.1"; // c.Account = "root"; // c.PassWord = "root"; - // c.Key = "devdb"; - // c.Port = 3306; + // c.Key = "testdb"; + // c.Port = 4000; //}); - //app.UseHadoop((c) => //{ - // c.Host = "172.17.0.1"; + // c.Host = "118.195.165.218"; // c.Account = "root"; // c.PassWord = "root"; // c.Key = "testdb"; // c.Port = 4000; //}); - app.UseHadoop((c) => - { - c.Host = "118.195.165.218"; - c.Account = "root"; - c.PassWord = "root"; - c.Key = "testdb"; - c.Port = 4000; - }); - // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_Column.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_Column.cs index a1b2794..626b14f 100644 --- a/Hadoop/ZKLT.Hadoop.Model/HDP_Column.cs +++ b/Hadoop/ZKLT.Hadoop.Model/HDP_Column.cs @@ -29,16 +29,20 @@ namespace ZKLT.Hadoop.Model private int _DecimalLength; + private string? _InsertDefault; + + private string? _UpdateDefault; + /// /// 编号 /// - [HDP_Column(Key = "Id",Description = "编号", Length = 100, DataType = HDP_ColumnDataType.VARCHAR, IsPrimary = true)] + [HDP_Column(Key = "Id", Description = "编号", Length = 100, DataType = HDP_ColumnDataType.VARCHAR, IsPrimary = true)] public string? Id { get => _Id; set => _Id = value; } /// /// 表编号 /// - [HDP_Column(Key = "TableId",Description = "表编号", Length = 100, DataType = HDP_ColumnDataType.VARCHAR)] + [HDP_Column(Key = "TableId", Description = "表编号", Length = 100, DataType = HDP_ColumnDataType.VARCHAR)] public string? TableId { get => _TableId; set => _TableId = value; } /// @@ -56,7 +60,7 @@ namespace ZKLT.Hadoop.Model /// /// 描述 /// - [HDP_Column(Key = "Description", Description = "描述",Length = 200, DataType = HDP_ColumnDataType.VARCHAR)] + [HDP_Column(Key = "Description", Description = "描述", Length = 200, DataType = HDP_ColumnDataType.VARCHAR)] public string? Description { get => _Description; set => _Description = value; } /// @@ -76,5 +80,17 @@ namespace ZKLT.Hadoop.Model /// [HDP_Column(Key = "DecimalLength", Description = "小数长度", DataType = HDP_ColumnDataType.INT)] public int DecimalLength { get => _DecimalLength; set => _DecimalLength = value; } + + /// + /// 插入默认值 + /// + [HDP_Column(Key = "InsertDefault", Description = "插入默认值", Length = 100, DataType = HDP_ColumnDataType.VARCHAR)] + public string? InsertDefault { get => _InsertDefault; set => _InsertDefault = value; } + + /// + /// 更新默认值 + /// + [HDP_Column(Key = "UpdateDefault", Description = "更新默认值", Length = 100, DataType = HDP_ColumnDataType.VARCHAR)] + public string? UpdateDefault { get => _UpdateDefault; set => _UpdateDefault = value; } } } diff --git a/Hadoop/ZKLT.Hadoop.Model/HDP_CommandAction.cs b/Hadoop/ZKLT.Hadoop.Model/HDP_CommandAction.cs new file mode 100644 index 0000000..31d944d --- /dev/null +++ b/Hadoop/ZKLT.Hadoop.Model/HDP_CommandAction.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZKLT.Hadoop.Model +{ + /// + /// 命令函数 + /// + public class HDP_CommandAction + { + /// + /// 当前日期 + /// + public const string DATENOW = "DATE_NOW()"; + + /// + /// 转换命令 + /// + /// 命令 + /// 参数 + /// 命令 + public static string ConvertCommand(string command, Dictionary param) + { + command = command.Replace(DATENOW,@$"'{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'"); + + return command; + } + + /// + /// 判断是否方法 + /// + /// 方法 + /// 是否包含 + public static bool IsAction(string action) + { + var _Result = false; + + if (action == DATENOW) { + return true; + } + + return _Result; + } + } +} diff --git a/Hadoop/ZKLT.Hadoop/TableService.cs b/Hadoop/ZKLT.Hadoop/TableService.cs index ff7332f..9adae70 100644 --- a/Hadoop/ZKLT.Hadoop/TableService.cs +++ b/Hadoop/ZKLT.Hadoop/TableService.cs @@ -285,6 +285,20 @@ namespace ZKLT.Hadoop _parmstr.Append($@"@{_column.Key},"); _params.Add(_column.Key!, row[_column.Key!]); } + else if (!string.IsNullOrEmpty(_column.InsertDefault)) + { + if (HDP_CommandAction.IsAction(_column.InsertDefault)) + { + _colstr.Append($@"`{_column.Key!}`,"); + _parmstr.Append($"{_column.InsertDefault},"); + } + else + { + _colstr.Append($@"`{_column.Key!}`,"); + _parmstr.Append($@"@{_column.Key},"); + _params.Add(_column.Key!, _column.InsertDefault); + } + } } if (_colstr[_colstr.Length - 1] == ',') { @@ -298,7 +312,7 @@ namespace ZKLT.Hadoop _command.AppendLine(") VALUES ("); _command.AppendLine(_parmstr.ToString()); _command.AppendLine(")"); - var _result = _connection.Execute(_command.ToString(), _params); + var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params); _connection.Close(); if (_result > 0) { @@ -364,6 +378,18 @@ namespace ZKLT.Hadoop _colstr.Append($@"`{_column.Key!}`=@{_column.Key!},"); _params.Add(_column.Key!, row[_column.Key!]); } + else if (!string.IsNullOrEmpty(_column.UpdateDefault)) + { + if (HDP_CommandAction.IsAction(_column.UpdateDefault)) + { + _colstr.Append($@"`{_column.Key!}`={_column.UpdateDefault}"); + } + else + { + _colstr.Append($@"`{_column.Key!}`=@{_column.Key!},"); + _params.Add(_column.Key!, _column.UpdateDefault); + } + } } if (_colstr[_colstr.Length - 1] == ',') { @@ -393,7 +419,7 @@ namespace ZKLT.Hadoop } _command.AppendLine(_wherestr.ToString()); - var _result = _connection.Execute(_command.ToString(), _params); + var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params); _connection.Close(); if (_result > 0) { @@ -471,7 +497,7 @@ namespace ZKLT.Hadoop } _command.AppendLine(_wherestr.ToString()); - var _result = _connection.Execute(_command.ToString(), _params); + var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params); _connection.Close(); if (_result > 0) { @@ -549,7 +575,7 @@ namespace ZKLT.Hadoop } _command.AppendLine(_wherestr.ToString()); - var _result = _connection.Query(_command.ToString(), _params).ToArray(); + var _result = _connection.Query(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params).ToArray(); _connection.Close(); if (_result.Length > 0) { @@ -650,7 +676,7 @@ namespace ZKLT.Hadoop } _command.AppendLine(_orderstr.ToString()); } - var _result = _connection.Query(_command.ToString(), _params); + var _result = _connection.Query(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params); _connection.Close(); return _result.ToArray(); } @@ -756,7 +782,7 @@ namespace ZKLT.Hadoop _pagestr.AppendLine(_command.ToString()); _pagestr.AppendLine(") AS Temp"); _pagestr.AppendLine(@$"LIMIT {(_result.PageIndex - 1) * _result.PageSize},{_result.PageSize}"); - _result.Data = _connection.Query(_pagestr.ToString(), _params).ToArray(); + _result.Data = _connection.Query(HDP_CommandAction.ConvertCommand(_pagestr.ToString(), row), _params).ToArray(); _connection.Close(); return _result; }