You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.3 KiB
C#

using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace ZKLT.Hadoop.Model
{
/// <summary>
/// 命令函数
/// </summary>
public class HDP_CommandAction
{
/// <summary>
/// 当前日期
/// </summary>
public const string DATENOW = "DATE_NOW()";
/// <summary>
/// 唯一码
/// </summary>
public const string UUID = "UUID()";
/// <summary>
/// 转换命令
/// </summary>
/// <param name="action">函数</param>
/// <param name="param">参数</param>
/// <returns>命令</returns>
public static object Convert(string action, JToken param)
{
if (action == DATENOW)
{
return DateTime.Now;
}
else if (action == UUID)
{
return Guid.NewGuid().ToString();
}
else {
return action;
}
}
/// <summary>
/// 列转换
/// </summary>
/// <param name="column">列</param>
/// <param name="param">参数</param>
/// <param name="action">公式</param>
/// <returns></returns>
public static string ColConvert(HDP_Column column, Dictionary<string, object> param,object value) {
string _guid;
if (value is string) {
string _action = value.ToString()!;
Regex _regex1 = new Regex(@"(?<=(\+\=))[\d\.]+");
if(_regex1.IsMatch(_action))
{
_guid = Guid.NewGuid().ToString("N");
param.Add(_guid,_regex1.Match(_action).Value);
return @$"`{column.Key}` + @{_guid}";
}
Regex _regex2 = new Regex(@"(?<=(\-\=))[\d\.]+");
if (_regex2.IsMatch(_action))
{
_guid = Guid.NewGuid().ToString("N");
param.Add(_guid, _regex2.Match(_action).Value);
return @$"`{column.Key}` - @{_guid}";
}
}
param.Add(column.Key!, value);
return $@"@{column.Key}";
}
}
}