vengine初步实现增删改查
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using JNPF.Common.Extension;
|
||||
using Newtonsoft.Json;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace Tnb.Vengine.Domain;
|
||||
@@ -12,138 +14,197 @@ namespace Tnb.Vengine.Domain;
|
||||
/// </summary>
|
||||
public class VmDbProp : VmBaseProp
|
||||
{
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// 字段名称
|
||||
/// </summary>
|
||||
public string field { get; set; } = string.Empty;
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// 字段名称
|
||||
/// </summary>
|
||||
public string field { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 数据类型
|
||||
/// </summary>
|
||||
public string dataType { get; set; } = "varchar";
|
||||
/// <summary>
|
||||
/// 数据类型
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string dataType { get; set; } = "varchar";
|
||||
|
||||
/// <summary>
|
||||
/// 数据类型
|
||||
/// </summary>
|
||||
public string? csType { get; set; }
|
||||
/// <summary>
|
||||
/// 数据类型
|
||||
/// </summary>
|
||||
public string? csType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 长度
|
||||
/// </summary>
|
||||
public int length { get; set; }
|
||||
/// <summary>
|
||||
/// 长度
|
||||
/// </summary>
|
||||
public int length { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 精度
|
||||
/// </summary>
|
||||
public int digit { get; set; }
|
||||
/// <summary>
|
||||
/// 精度
|
||||
/// </summary>
|
||||
public int digit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int ordinal { get; set; }
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
public int ordinal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 非空
|
||||
/// </summary>
|
||||
public bool required { get; set; }
|
||||
/// <summary>
|
||||
/// 非空
|
||||
/// </summary>
|
||||
public bool required { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否主键
|
||||
/// </summary>
|
||||
public bool pkey { get; set; }
|
||||
/// <summary>
|
||||
/// 是否主键
|
||||
/// </summary>
|
||||
public bool pkey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否模糊搜索
|
||||
/// </summary>
|
||||
public bool fuzzy { get; set; }
|
||||
/// <summary>
|
||||
/// 是否模糊搜索
|
||||
/// </summary>
|
||||
public bool fuzzy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 默认值
|
||||
/// </summary>
|
||||
public string? defValue { get; set; }
|
||||
/// <summary>
|
||||
/// 默认值
|
||||
/// </summary>
|
||||
public string? defValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string? descrip { get; set; }
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string? descrip { get; set; }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认值
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object? GetDefaultValue()
|
||||
{
|
||||
object? val = null;
|
||||
if (string.IsNullOrEmpty(defValue))
|
||||
/// <summary>
|
||||
/// 获取默认值
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object? GetDefaultValue()
|
||||
{
|
||||
val = defValue switch
|
||||
{
|
||||
"@@snowid" => YitIdHelper.NextId().ToString(),
|
||||
"@@now" => DateTime.Now,
|
||||
"@@userid" => YitIdHelper.NextId().ToString(),
|
||||
"@@orgid" => YitIdHelper.NextId().ToString(),
|
||||
_ => null
|
||||
};
|
||||
object? val = null;
|
||||
if(!required) { return val; }
|
||||
if (string.IsNullOrEmpty(defValue))
|
||||
{
|
||||
val = csType switch
|
||||
{
|
||||
"string" => string.Empty,
|
||||
"short" or "int" or "long" => 0,
|
||||
"float" or "double" or "decimal" => 0f,
|
||||
"DateTime" => DateTime.Now,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
val = defValue switch
|
||||
{
|
||||
"@@snowid" => YitIdHelper.NextId().ToString(),
|
||||
"@@now" => DateTime.Now,
|
||||
"@@userid" => YitIdHelper.NextId().ToString(),
|
||||
"@@orgid" => YitIdHelper.NextId().ToString(),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
val = csType switch
|
||||
{
|
||||
"string" => string.Empty,
|
||||
"short" or "int" or "long" => 0,
|
||||
"float" or "double" or "decimal" => 0f,
|
||||
"DateTime" => DateTime.Now,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认宽度
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetDefaultWidth()
|
||||
{
|
||||
return csType switch
|
||||
/// <summary>
|
||||
/// 获取默认值文本
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object? GetDefaultValueString()
|
||||
{
|
||||
"string" => "\"width\": \"auto\"",
|
||||
"int" or "short" or "long" => "\"width\": 80",
|
||||
"DateTime" => "\"width\": 150",
|
||||
_ => ""
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认组件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public CompOption GetDefaultComp()
|
||||
{
|
||||
CompOption comp = new CompOption();
|
||||
if (pkey)
|
||||
{
|
||||
comp.attr.Add("disabled", true);
|
||||
return comp;
|
||||
string val = "";
|
||||
if (!required) return val;
|
||||
if (!string.IsNullOrWhiteSpace(defValue))
|
||||
{
|
||||
val = defValue switch
|
||||
{
|
||||
"@@snowid" => "YitIdHelper.NextId().ToString()",
|
||||
"@@now" => "DateTime.Now",
|
||||
_ => defValue
|
||||
};
|
||||
}
|
||||
if (string.IsNullOrEmpty(val))
|
||||
{
|
||||
val = csType switch
|
||||
{
|
||||
"string" => "string.Empty;",
|
||||
"DateTime" => "DateTime.Now;",
|
||||
_ => ""
|
||||
};
|
||||
}
|
||||
return string.IsNullOrEmpty(val) ? "" : " = " + val;
|
||||
}
|
||||
switch (csType)
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认宽度
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetDefaultWidth()
|
||||
{
|
||||
case "string":
|
||||
comp.attr.Add("clearable", true);
|
||||
comp.attr.Add("maxlength", length);
|
||||
comp.attr.Add("showWordLimit", true);
|
||||
break;
|
||||
case "int":
|
||||
case "short":
|
||||
case "long":
|
||||
comp.type = "el-input-number";
|
||||
break;
|
||||
case "DateTime":
|
||||
comp.type = "el-date-picker";
|
||||
break;
|
||||
};
|
||||
return comp;
|
||||
}
|
||||
return csType switch
|
||||
{
|
||||
"string" => "\"width\": \"auto\"",
|
||||
"int" or "short" or "long" => "\"width\": 80",
|
||||
"DateTime" => "\"width\": 150",
|
||||
_ => ""
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认组件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public CompOption GetDefaultComp()
|
||||
{
|
||||
CompOption comp = new CompOption();
|
||||
if (pkey)
|
||||
{
|
||||
comp.attr.Add("disabled", true);
|
||||
return comp;
|
||||
}
|
||||
switch (csType)
|
||||
{
|
||||
case "string":
|
||||
comp.attr.Add("clearable", true);
|
||||
comp.attr.Add("maxlength", length);
|
||||
comp.attr.Add("showWordLimit", true);
|
||||
break;
|
||||
case "int":
|
||||
case "short":
|
||||
case "long":
|
||||
comp.type = "el-input-number";
|
||||
break;
|
||||
case "DateTime":
|
||||
comp.type = "el-date-picker";
|
||||
break;
|
||||
};
|
||||
return comp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取SqlSugar特性文本
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetAttributeString()
|
||||
{
|
||||
var attr = "";
|
||||
var sb = new List<string>();
|
||||
if (!string.IsNullOrEmpty(field) && code != field) sb.Add($"ColumnName = \"{field}\"");
|
||||
if (pkey) sb.Add("IsPrimaryKey = true");
|
||||
//sb.Add("IsIdentity = true");
|
||||
if (required && !pkey) sb.Add("IsNullable = false");
|
||||
if (csType == "string" && length > 0)
|
||||
{
|
||||
sb.Add($"Length = {CodeHelper.LengthToString(length)}");
|
||||
}
|
||||
|
||||
if (csType == "decimal")
|
||||
{
|
||||
if (length > 0) sb.Add($"Length = {length}");
|
||||
if (digit > 0) sb.Add($"DecimalDigits = {digit}");
|
||||
}
|
||||
//if(isJson) sb.Add("IsJson = true")
|
||||
if (sb.Any()) attr += $"\t[SugarColumn({sb.JoinAsString(", ")})]{Environment.NewLine}";
|
||||
return attr;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user