字段默认值以及函数定义初步完成

pull/1/head
潘建东 9 months ago
parent cd4627d3cc
commit 8514a1f4bd

@ -40,34 +40,34 @@ namespace ZKLT.Hadoop.API
app.UseCors("all"); app.UseCors("all");
#endregion #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) => //app.UseHadoop((c) =>
//{ //{
// c.Host = "127.0.0.1"; // c.Host = "172.17.0.1";
// c.Account = "root"; // c.Account = "root";
// c.PassWord = "root"; // c.PassWord = "root";
// c.Key = "devdb"; // c.Key = "testdb";
// c.Port = 3306; // c.Port = 4000;
//}); //});
//app.UseHadoop((c) => //app.UseHadoop((c) =>
//{ //{
// c.Host = "172.17.0.1"; // c.Host = "118.195.165.218";
// c.Account = "root"; // c.Account = "root";
// c.PassWord = "root"; // c.PassWord = "root";
// c.Key = "testdb"; // c.Key = "testdb";
// c.Port = 4000; // 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. // Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())
{ {

@ -29,16 +29,20 @@ namespace ZKLT.Hadoop.Model
private int _DecimalLength; private int _DecimalLength;
private string? _InsertDefault;
private string? _UpdateDefault;
/// <summary> /// <summary>
/// 编号 /// 编号
/// </summary> /// </summary>
[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; } public string? Id { get => _Id; set => _Id = value; }
/// <summary> /// <summary>
/// 表编号 /// 表编号
/// </summary> /// </summary>
[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; } public string? TableId { get => _TableId; set => _TableId = value; }
/// <summary> /// <summary>
@ -56,7 +60,7 @@ namespace ZKLT.Hadoop.Model
/// <summary> /// <summary>
/// 描述 /// 描述
/// </summary> /// </summary>
[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; } public string? Description { get => _Description; set => _Description = value; }
/// <summary> /// <summary>
@ -76,5 +80,17 @@ namespace ZKLT.Hadoop.Model
/// </summary> /// </summary>
[HDP_Column(Key = "DecimalLength", Description = "小数长度", DataType = HDP_ColumnDataType.INT)] [HDP_Column(Key = "DecimalLength", Description = "小数长度", DataType = HDP_ColumnDataType.INT)]
public int DecimalLength { get => _DecimalLength; set => _DecimalLength = value; } public int DecimalLength { get => _DecimalLength; set => _DecimalLength = value; }
/// <summary>
/// 插入默认值
/// </summary>
[HDP_Column(Key = "InsertDefault", Description = "插入默认值", Length = 100, DataType = HDP_ColumnDataType.VARCHAR)]
public string? InsertDefault { get => _InsertDefault; set => _InsertDefault = value; }
/// <summary>
/// 更新默认值
/// </summary>
[HDP_Column(Key = "UpdateDefault", Description = "更新默认值", Length = 100, DataType = HDP_ColumnDataType.VARCHAR)]
public string? UpdateDefault { get => _UpdateDefault; set => _UpdateDefault = value; }
} }
} }

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZKLT.Hadoop.Model
{
/// <summary>
/// 命令函数
/// </summary>
public class HDP_CommandAction
{
/// <summary>
/// 当前日期
/// </summary>
public const string DATENOW = "DATE_NOW()";
/// <summary>
/// 转换命令
/// </summary>
/// <param name="command">命令</param>
/// <param name="param">参数</param>
/// <returns>命令</returns>
public static string ConvertCommand(string command, Dictionary<string, object> param)
{
command = command.Replace(DATENOW,@$"'{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'");
return command;
}
/// <summary>
/// 判断是否方法
/// </summary>
/// <param name="action">方法</param>
/// <returns>是否包含</returns>
public static bool IsAction(string action)
{
var _Result = false;
if (action == DATENOW) {
return true;
}
return _Result;
}
}
}

@ -285,6 +285,20 @@ namespace ZKLT.Hadoop
_parmstr.Append($@"@{_column.Key},"); _parmstr.Append($@"@{_column.Key},");
_params.Add(_column.Key!, row[_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] == ',') if (_colstr[_colstr.Length - 1] == ',')
{ {
@ -298,7 +312,7 @@ namespace ZKLT.Hadoop
_command.AppendLine(") VALUES ("); _command.AppendLine(") VALUES (");
_command.AppendLine(_parmstr.ToString()); _command.AppendLine(_parmstr.ToString());
_command.AppendLine(")"); _command.AppendLine(")");
var _result = _connection.Execute(_command.ToString(), _params); var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params);
_connection.Close(); _connection.Close();
if (_result > 0) if (_result > 0)
{ {
@ -364,6 +378,18 @@ namespace ZKLT.Hadoop
_colstr.Append($@"`{_column.Key!}`=@{_column.Key!},"); _colstr.Append($@"`{_column.Key!}`=@{_column.Key!},");
_params.Add(_column.Key!, row[_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] == ',') if (_colstr[_colstr.Length - 1] == ',')
{ {
@ -393,7 +419,7 @@ namespace ZKLT.Hadoop
} }
_command.AppendLine(_wherestr.ToString()); _command.AppendLine(_wherestr.ToString());
var _result = _connection.Execute(_command.ToString(), _params); var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params);
_connection.Close(); _connection.Close();
if (_result > 0) if (_result > 0)
{ {
@ -471,7 +497,7 @@ namespace ZKLT.Hadoop
} }
_command.AppendLine(_wherestr.ToString()); _command.AppendLine(_wherestr.ToString());
var _result = _connection.Execute(_command.ToString(), _params); var _result = _connection.Execute(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params);
_connection.Close(); _connection.Close();
if (_result > 0) if (_result > 0)
{ {
@ -549,7 +575,7 @@ namespace ZKLT.Hadoop
} }
_command.AppendLine(_wherestr.ToString()); _command.AppendLine(_wherestr.ToString());
var _result = _connection.Query<T>(_command.ToString(), _params).ToArray(); var _result = _connection.Query<T>(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params).ToArray();
_connection.Close(); _connection.Close();
if (_result.Length > 0) if (_result.Length > 0)
{ {
@ -650,7 +676,7 @@ namespace ZKLT.Hadoop
} }
_command.AppendLine(_orderstr.ToString()); _command.AppendLine(_orderstr.ToString());
} }
var _result = _connection.Query<T>(_command.ToString(), _params); var _result = _connection.Query<T>(HDP_CommandAction.ConvertCommand(_command.ToString(), row), _params);
_connection.Close(); _connection.Close();
return _result.ToArray(); return _result.ToArray();
} }
@ -756,7 +782,7 @@ namespace ZKLT.Hadoop
_pagestr.AppendLine(_command.ToString()); _pagestr.AppendLine(_command.ToString());
_pagestr.AppendLine(") AS Temp"); _pagestr.AppendLine(") AS Temp");
_pagestr.AppendLine(@$"LIMIT {(_result.PageIndex - 1) * _result.PageSize},{_result.PageSize}"); _pagestr.AppendLine(@$"LIMIT {(_result.PageIndex - 1) * _result.PageSize},{_result.PageSize}");
_result.Data = _connection.Query<T>(_pagestr.ToString(), _params).ToArray(); _result.Data = _connection.Query<T>(HDP_CommandAction.ConvertCommand(_pagestr.ToString(), row), _params).ToArray();
_connection.Close(); _connection.Close();
return _result; return _result;
} }

Loading…
Cancel
Save