使用razor模板生成实体文件
This commit is contained in:
@@ -44,6 +44,25 @@ public class SystemMapper : IRegister
|
||||
.Map(dest => dest.IsPrimarykey, src => src.primaryKey)
|
||||
.Map(dest => dest.IsNullable, src => src.allowNull == 1)
|
||||
.Map(dest => dest.DefaultValue, src => src.defaults);
|
||||
config.ForType<DbTableInfo, DbEntityInfo>()
|
||||
.Map(dest => dest.tableName, src => src.Name)
|
||||
.Map(dest => dest.descrip, src => src.Description);
|
||||
config.ForType<DbColumnInfo, DbEntityPropInfo>()
|
||||
.Map(dest => dest.colName, src => src.DbColumnName)
|
||||
.Map(dest => dest.dataType, src => src.DataType)
|
||||
.Map(dest => dest.propName, src => src.PropertyName)
|
||||
.Map(dest => dest.propType, src => src.PropertyType)
|
||||
.Map(dest => dest.length, src => src.Length)
|
||||
.Map(dest => dest.descrip, src => src.ColumnDescription)
|
||||
.Map(dest => dest.defaultValue, src => src.DefaultValue)
|
||||
.Map(dest => dest.allowNull, src => src.IsNullable)
|
||||
.Map(dest => dest.identity, src => src.IsIdentity)
|
||||
.Map(dest => dest.primaryKey, src => src.IsPrimarykey)
|
||||
.Map(dest => dest.isArray, src => src.IsArray)
|
||||
.Map(dest => dest.isJson, src => src.IsJson)
|
||||
.Map(dest => dest.value, src => src.Value)
|
||||
.Map(dest => dest.scale, src => src.Scale)
|
||||
.Map(dest => dest.digits, src => src.DecimalDigits);
|
||||
//config.ForType<DynamicDbTableModel, DbTableModel>()
|
||||
// .Map(dest => dest.table, src => src.F_TABLE)
|
||||
// .Map(dest => dest.tableName, src => src.F_TABLENAME)
|
||||
|
||||
@@ -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