// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。 // // 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。 // // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! namespace Admin.NET.Core.Service; /// /// 代码生成详细配置参数 /// public class CodeGenConfig { /// /// 主键Id /// public long Id { get; set; } /// /// 代码生成主表ID /// public long CodeGenId { get; set; } /// /// 数据库字段名 /// public string ColumnName { get; set; } /// /// 主外键 /// public string ColumnKey { get; set; } /// /// 实体属性名 /// public string PropertyName { get; set; } /// /// 字段数据长度 /// public int ColumnLength { get; set; } /// /// 数据库字段名(首字母小写) /// public string LowerPropertyName => string.IsNullOrWhiteSpace(PropertyName) ? null : PropertyName[..1].ToLower() + PropertyName[1..]; /// /// 字段描述 /// public string ColumnComment { get; set; } /// /// .NET类型 /// public string NetType { get; set; } /// /// 数据库中类型(物理类型) /// public string DataType { get; set; } /// /// 可空.NET类型 /// public string NullableNetType => Regex.IsMatch(NetType ?? "", "(.*?Enum|bool|char|int|long|double|float|decimal)[?]?") ? NetType.TrimEnd('?') + "?" : NetType; /// /// 作用类型(字典) /// public string EffectType { get; set; } /// /// 外键库标识 /// public string FkConfigId { get; set; } /// /// 外键实体名称 /// public string FkEntityName { get; set; } /// /// 外键表名称 /// public string FkTableName { get; set; } /// /// 外键实体名称(首字母小写) /// public string LowerFkEntityName => string.IsNullOrWhiteSpace(FkEntityName) ? null : FkEntityName[..1].ToLower() + FkEntityName[1..]; /// /// 外键链接字段 /// public string FkLinkColumnName { get; set; } /// /// 外键显示字段 /// [Newtonsoft.Json.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] public string FkDisplayColumns { get; set; } /// /// 外键显示字段 /// public List FkDisplayColumnList { get; set; } /// /// 外键显示字段(首字母小写) /// public List LowerFkDisplayColumnsList => FkDisplayColumnList?.Select(name => name[..1].ToLower() + name[1..]).ToList(); /// /// 外键显示字段.NET类型 /// public string FkColumnNetType { get; set; } /// /// 父级字段 /// public string PidColumn { get; set; } /// /// 字典code /// public string DictTypeCode { get; set; } /// /// 查询方式 /// public string QueryType { get; set; } /// /// 是否是查询条件 /// public string WhetherQuery { get; set; } /// /// 列表是否缩进(字典) /// public string WhetherRetract { get; set; } /// /// 是否必填(字典) /// public string WhetherRequired { get; set; } /// /// 是否可排序(字典) /// public string WhetherSortable { get; set; } /// /// 列表显示 /// public string WhetherTable { get; set; } /// /// 增改 /// public string WhetherAddUpdate { get; set; } /// /// 导入 /// public string WhetherImport { get; set; } /// /// 是否是通用字段 /// public string WhetherCommon { get; set; } /// /// 排序 /// public int OrderNo { get; set; } /// /// 是否是选择器控件 /// public bool IsSelectorEffectType => Regex.IsMatch(EffectType ?? "", "Selector$|ForeignKey", RegexOptions.IgnoreCase); /// /// 去掉尾部Id的属性名 /// public string PropertyNameTrimEndId => PropertyName.TrimEnd("Id"); /// /// 去掉尾部Id的属性名 /// public string LowerPropertyNameTrimEndId => LowerPropertyName.TrimEnd("Id"); /// /// 扩展属性名称 /// public string ExtendedPropertyName => EffectType switch { "ForeignKey" => $"{PropertyName.TrimEnd("Id")}FkDisplayName", "ApiTreeSelector" => $"{PropertyName.TrimEnd("Id")}DisplayName", "DictSelector" => $"{PropertyName.TrimEnd("Id")}DictLabel", "Upload" => $"{PropertyName.TrimEnd("Id")}Attachment", _ => PropertyName }; /// /// 首字母小写的扩展属性名称 /// public string LowerExtendedPropertyName { get { var displayPropertyName = ExtendedPropertyName; if (string.IsNullOrWhiteSpace(displayPropertyName)) return null; return displayPropertyName[..1].ToLower() + displayPropertyName[1..]; } } /// /// 获取外键显示值语句 /// /// 表别名 /// 多字段时的连接符 /// public string GetDisplayColumn(string tableAlias, string separator = "-") => "$\"" + string.Join(separator, FkDisplayColumnList?.Select(name => $"{{{tableAlias}.{name}}}") ?? new List()) + "\""; }