using JNPF.DependencyInjection; namespace JNPF.Systems.Entitys.Dto.Database; /// /// 数据库表映射实体信息. /// [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 columns { get; set; } = new List(); public List ignoreCols { get; set; } = new List(); 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; } } /// /// 数据库表映射实体属性信息. /// [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 sugarAttrs = new List(); 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; } }