使用razor模板生成实体文件
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
using JNPF.DependencyInjection;
|
||||
using SqlSugar;
|
||||
|
||||
namespace JNPF.Systems.Entitys.Dto.Database;
|
||||
|
||||
/// <summary>
|
||||
/// 数据库表列表输出.
|
||||
/// </summary>
|
||||
[SuppressSniffer]
|
||||
public class DatabaseTableInfo
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
DbTableInfo table { get; set; }
|
||||
|
||||
List<DbColumnInfo> columns { get; set; }
|
||||
|
||||
public string clsName { get; set; } = string.Empty;
|
||||
|
||||
public string nsName { get; set; } = "Tnb.Entities";
|
||||
|
||||
public string pkType { get; set; } = "string";
|
||||
|
||||
public string pkName { get; set; } = "id";
|
||||
|
||||
public string GetColumnDefaultValue(string colName)
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
public string GetColumnCsType(string colName)
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
public string GetColumnCsName(string colName)
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
public string GetColumnAttrib(string colName)
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
124
system/Tnb.Systems.Entitys/Model/System/DataBase/DbEntityInfo.cs
Normal file
124
system/Tnb.Systems.Entitys/Model/System/DataBase/DbEntityInfo.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using JNPF.DependencyInjection;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using SqlSugar;
|
||||
|
||||
namespace JNPF.Systems.Entitys.Dto.Database;
|
||||
|
||||
/// <summary>
|
||||
/// 数据库表映射实体信息.
|
||||
/// </summary>
|
||||
[SuppressSniffer]
|
||||
public class DbEntityInfo
|
||||
{
|
||||
public string tableName { get; set; } = string.Empty;
|
||||
|
||||
public string descrip { get; set; } = string.Empty;
|
||||
|
||||
public string clsName { get; set; } = string.Empty;
|
||||
|
||||
public string nsName { get; set; } = "Tnb.Entities";
|
||||
|
||||
public string pkType { get; set; } = "string";
|
||||
|
||||
public string pkName { get; set; } = "id";
|
||||
|
||||
public List<DbEntityPropInfo> columns { get; set; } = new List<DbEntityPropInfo>();
|
||||
public List<string> ignoreCols { get; set; } = new List<string>();
|
||||
|
||||
public string GetInherit()
|
||||
{
|
||||
return pkName == "id" ? $"BaseEntity<{pkType}>" : "IEntity";
|
||||
}
|
||||
public string GetConstruct()
|
||||
{
|
||||
if (pkName == "id")
|
||||
{
|
||||
string str = pkType switch
|
||||
{
|
||||
"string" => "id = SnowflakeIdHelper.NextId();",
|
||||
"long" => "id = YitIdHelper.NextId();",
|
||||
_ => string.Empty
|
||||
};
|
||||
return str;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据库表映射实体属性信息.
|
||||
/// </summary>
|
||||
[SuppressSniffer]
|
||||
public class DbEntityPropInfo
|
||||
{
|
||||
public string colName { get; set; }
|
||||
|
||||
public string dataType { get; set; }
|
||||
|
||||
public string csType { get; set; }
|
||||
|
||||
public string propName { get; set; }
|
||||
|
||||
public Type propType { get; set; }
|
||||
|
||||
public int length { get; set; }
|
||||
|
||||
public string descrip { get; set; }
|
||||
|
||||
public string defaultValue { get; set; }
|
||||
|
||||
public bool allowNull { get; set; }
|
||||
|
||||
public bool identity { get; set; }
|
||||
|
||||
public bool primaryKey { get; set; }
|
||||
|
||||
public bool isArray { get; set; }
|
||||
|
||||
public bool isJson { get; set; }
|
||||
|
||||
public object value { get; set; }
|
||||
|
||||
public int digits { get; set; }
|
||||
|
||||
public int scale { get; set; }
|
||||
|
||||
public string GetPropType()
|
||||
{
|
||||
string propType = csType;
|
||||
if (allowNull)
|
||||
propType = csType + "?";
|
||||
return propType;
|
||||
}
|
||||
public virtual string GetPropAttr()
|
||||
{
|
||||
List<string> sugarAttrs = new List<string>();
|
||||
if (primaryKey)
|
||||
sugarAttrs.Add("IsPrimaryKey = true");
|
||||
if (identity)
|
||||
sugarAttrs.Add("IsIdentity = true");
|
||||
//if (allowNull)
|
||||
// sugarAttrs.Add("IsNullable = true");
|
||||
if (colName != propName)
|
||||
sugarAttrs.Add($"ColumnName = \"{colName}\"");
|
||||
if (sugarAttrs.Count > 0)
|
||||
return $" [SugarColumn({string.Join(", ", sugarAttrs)})]\n";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
public string GetDefaultValue()
|
||||
{
|
||||
if (allowNull) return string.Empty;
|
||||
|
||||
string str = csType switch
|
||||
{
|
||||
"string" => " = string.Empty;",
|
||||
"DateTime" => " = DateTime.Now;",
|
||||
_ => string.Empty
|
||||
};
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user