From ca87a703b2ab1a44c69fd87e04c487aec9822009 Mon Sep 17 00:00:00 2001 From: aq982 Date: Wed, 22 Jan 2025 23:07:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E4=BC=98=E5=8C=96-=E6=96=B0=E5=A2=9E=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E7=BB=93=E6=9E=84-=E9=A2=84=E7=95=99=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin.NET.Core/Entity/SysCodeGenConfig.cs | 6 + .../Extension/StringExtension.cs | 9 + .../Service/CodeGen/Dto/CodeGenConfig.cs | 5 + .../CodeGen/SysCodeGenConfigService.cs | 184 +++++++++++++++++- .../Service/CodeGen/SysCodeGenService.cs | 141 ++------------ .../Service/DataBase/SysDatabaseService.cs | 35 +++- .../wwwroot/template/web_views_UDIndx.vue.vm | 91 +++++++++ .../codeGen/component/genConfigDialog.vue | 51 +++-- Web/src/views/system/codeGen/index.vue | 2 +- 9 files changed, 378 insertions(+), 146 deletions(-) create mode 100644 Admin.NET/Admin.NET.Web.Entry/wwwroot/template/web_views_UDIndx.vue.vm diff --git a/Admin.NET/Admin.NET.Core/Entity/SysCodeGenConfig.cs b/Admin.NET/Admin.NET.Core/Entity/SysCodeGenConfig.cs index 87f3bba3..a9dd2e80 100644 --- a/Admin.NET/Admin.NET.Core/Entity/SysCodeGenConfig.cs +++ b/Admin.NET/Admin.NET.Core/Entity/SysCodeGenConfig.cs @@ -130,6 +130,12 @@ public partial class SysCodeGenConfig : EntityBase [MaxLength(8)] public string? WhetherSortable { get; set; } + /// + /// 是否是统计字段 + /// + [SugarColumn(ColumnDescription = "是否是统计字段", Length = 8)] + [MaxLength(8)] + public string? Statistical { get; set; } /// /// 是否是查询条件 /// diff --git a/Admin.NET/Admin.NET.Core/Extension/StringExtension.cs b/Admin.NET/Admin.NET.Core/Extension/StringExtension.cs index 81a62c0d..5cb3c5ff 100644 --- a/Admin.NET/Admin.NET.Core/Extension/StringExtension.cs +++ b/Admin.NET/Admin.NET.Core/Extension/StringExtension.cs @@ -97,7 +97,16 @@ public static class StringExtension return char.ToLower(input[0]) + input[1..]; } + /// + /// 转首字母大写 + /// + public static string ToFirstLetterUpperCase(this string input) + { + if (string.IsNullOrWhiteSpace(input)) return input; + if (input.Length == 1) return input.ToUpper(); // 处理单字符字符串 + return char.ToUpper(input[0]) + input[1..]; + } /// /// 渲染字符串,替换占位符 /// diff --git a/Admin.NET/Admin.NET.Core/Service/CodeGen/Dto/CodeGenConfig.cs b/Admin.NET/Admin.NET.Core/Service/CodeGen/Dto/CodeGenConfig.cs index f1d15717..80dade27 100644 --- a/Admin.NET/Admin.NET.Core/Service/CodeGen/Dto/CodeGenConfig.cs +++ b/Admin.NET/Admin.NET.Core/Service/CodeGen/Dto/CodeGenConfig.cs @@ -118,6 +118,11 @@ public class CodeGenConfig /// public string WhetherSortable { get; set; } + /// + /// 是否是统计字段 + /// + public string Statistical { get; set; } + /// /// 是否是查询条件 /// diff --git a/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenConfigService.cs b/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenConfigService.cs index bb5d8ec0..08b257be 100644 --- a/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenConfigService.cs +++ b/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenConfigService.cs @@ -4,6 +4,8 @@ // // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! +using System.Management.Automation.Language; + namespace Admin.NET.Core.Service; /// @@ -13,20 +15,200 @@ namespace Admin.NET.Core.Service; public class SysCodeGenConfigService : IDynamicApiController, ITransient { private readonly ISqlSugarClient _db; + private readonly CodeGenOptions _codeGenOptions; + private readonly DbConnectionOptions _dbConnectionOptions; + private readonly SysDatabaseService _databaseService; - public SysCodeGenConfigService(ISqlSugarClient db) + public SysCodeGenConfigService(ISqlSugarClient db, + SysDatabaseService databaseService, + IOptions dbConnectionOptions, + IOptions codeGenOptions) { _db = db; + _dbConnectionOptions = dbConnectionOptions.Value; + _codeGenOptions = codeGenOptions.Value; + _databaseService = databaseService; } + /// + /// 获取数据表列(实体属性)集合 + /// + /// + public List GetColumnList([FromQuery] AddCodeGenInput input) + { + return GetColumnList(input.TableName, input.ConfigId); + } + /// + /// 获取数据表列(实体属性)集合 + /// + /// + /// + /// + public List GetColumnList(string EntityName, string ConfigId) + { + var entityType = GetEntityInfos().GetAwaiter().GetResult().FirstOrDefault(u => u.EntityName == EntityName); + + if (entityType == null) + return null; + var config = _dbConnectionOptions.ConnectionConfigs.FirstOrDefault(u => u.ConfigId.ToString() == ConfigId); + var dbTableName = config!.DbSettings.EnableUnderLine ? UtilMethods.ToUnderLine(entityType.DbTableName) : entityType.DbTableName; + + int bracketIndex = dbTableName.IndexOf('{'); + if (bracketIndex != -1) + { + dbTableName = dbTableName.Substring(0, bracketIndex); + var dbTableInfos = _db.AsTenant().GetConnectionScope(ConfigId).DbMaintenance.GetTableInfoList(false); + var table = dbTableInfos.FirstOrDefault(x => x.Name.StartsWith(config.DbSettings.EnableUnderLine ? UtilMethods.ToUnderLine(dbTableName) : dbTableName, StringComparison.CurrentCultureIgnoreCase)); + if (table != null) + dbTableName = table.Name; + } + + // 切库---多库代码生成用 + var provider = _db.AsTenant().GetConnectionScope(!string.IsNullOrEmpty(ConfigId) ? ConfigId : SqlSugarConst.MainConfigId); + + var entityBasePropertyNames = _codeGenOptions.EntityBaseColumn[nameof(EntityTenant)]; + var columnInfos = provider.DbMaintenance.GetColumnInfosByTableName(dbTableName, false); + var result = columnInfos.Select(u => new ColumnOuput + { + // 转下划线后的列名需要再转回来(暂时不转) + //ColumnName = config.DbSettings.EnableUnderLine ? CodeGenUtil.CamelColumnName(u.DbColumnName, entityBasePropertyNames) : u.DbColumnName, + ColumnName = u.DbColumnName, + ColumnLength = u.Length, + IsPrimarykey = u.IsPrimarykey, + IsNullable = u.IsNullable, + ColumnKey = u.IsPrimarykey.ToString(), + NetType = CodeGenUtil.ConvertDataType(u, provider.CurrentConnectionConfig.DbType), + DataType = u.DataType, + ColumnComment = string.IsNullOrWhiteSpace(u.ColumnDescription) ? u.DbColumnName : u.ColumnDescription, + DefaultValue = u.DefaultValue, + }).ToList(); + + // 获取实体的属性信息,赋值给PropertyName属性(CodeFirst模式应以PropertyName为实际使用名称) + var entityProperties = entityType.Type.GetProperties(); + + for (int i = result.Count - 1; i >= 0; i--) + { + var columnOutput = result[i]; + // 先找自定义字段名的,如果找不到就再找自动生成字段名的(并且过滤掉没有SugarColumn的属性) + var propertyInfo = entityProperties.FirstOrDefault(u => (u.GetCustomAttribute()?.ColumnName ?? "").ToLower() == columnOutput.ColumnName.ToLower()) ?? + entityProperties.FirstOrDefault(u => u.GetCustomAttribute() != null && u.Name.ToLower() == (config.DbSettings.EnableUnderLine + ? CodeGenUtil.CamelColumnName(columnOutput.ColumnName, entityBasePropertyNames).ToLower() + : columnOutput.ColumnName.ToLower())); + if (propertyInfo != null) + { + columnOutput.PropertyName = propertyInfo.Name; + columnOutput.ColumnComment = propertyInfo.GetCustomAttribute()!.ColumnDescription; + } + else + { + result.RemoveAt(i); // 移除没有定义此属性的字段 + } + } + return result; + } + + /// + /// 获取库表信息 + /// + /// 是否排除带SysTable属性的表 + /// + public async Task> GetEntityInfos(bool excludeSysTable = false) + { + var types = new List(); + if (_codeGenOptions.EntityAssemblyNames != null) + { + var assemblies = AppDomain.CurrentDomain.GetAssemblies(); + foreach (var assembly in assemblies) + { + var assemblyName = assembly.GetName().Name!; + if (_codeGenOptions.EntityAssemblyNames.Contains(assemblyName) || _codeGenOptions.EntityAssemblyNames.Any(name => assemblyName.Contains(name))) + { + Assembly asm = Assembly.Load(assemblyName); + types.AddRange(asm.GetExportedTypes().ToList()); + } + } + } + var sugarTableType = typeof(SugarTable); + bool IsMyAttribute(Attribute[] o) + { + foreach (Attribute a in o) + { + if (a.GetType() == sugarTableType) + return true; + } + return false; + } + Type[] cosType = types.Where(u => IsMyAttribute(Attribute.GetCustomAttributes(u, false))).ToArray(); + + var entityInfos = new List(); + foreach (var ct in cosType) + { + // 若实体贴[SysTable]特性,则禁止显示系统自带的 + if (excludeSysTable && ct.IsDefined(typeof(SysTableAttribute), false)) + continue; + + var des = ct.GetCustomAttributes(typeof(DescriptionAttribute), false); + var description = des.Length > 0 ? ((DescriptionAttribute)des[0]).Description : ""; + + var sugarAttribute = ct.GetCustomAttributes(sugarTableType, true).FirstOrDefault(); + + entityInfos.Add(new EntityInfo() + { + EntityName = ct.Name, + DbTableName = sugarAttribute == null ? ct.Name : ((SugarTable)sugarAttribute).TableName, + TableDescription = sugarAttribute == null ? description : ((SugarTable)sugarAttribute).TableDescription, + Type = ct + }); + } + return await Task.FromResult(entityInfos); + } /// /// 获取代码生成配置列表 🔖 /// /// + /// + /// /// [DisplayName("获取代码生成配置列表")] public async Task> GetList([FromQuery] CodeGenConfig input) { + //获取主表 + var CodeGen = _db.Queryable().Single(it => it.Id == input.CodeGenId); //根据ID查询 + //先获取已经存储的配置字段 + var list = await _db.Queryable() + .Where(u => u.CodeGenId == input.CodeGenId).ToListAsync(); + + //找出实体字段 + var ColumnList = GetColumnList(CodeGen.TableName, CodeGen.ConfigId); + //找出新增的字段 + var addColumnList = ColumnList.Where(t => !list.Select(d => d.ColumnName).Contains(t.ColumnName)).ToList(); + //找出已经删除的字段 + var delColumnList = list.Where(t => !ColumnList.Select(d => d.ColumnName).Contains(t.ColumnName)).ToList(); + //找出更新的 + var updateColumnList =new List(); + foreach (var column in list) + { + //找出没有增减的 + if (ColumnList.Any(it => it.ColumnName == column.ColumnName)) + { + var nmd = ColumnList.Single(it => it.ColumnName == column.ColumnName); + //如果数据库类型或者长度改变 + if (nmd.NetType != column.NetType || nmd.ColumnLength != column.ColumnLength || nmd.ColumnComment != column.ColumnComment) + { + column.NetType = nmd.NetType; + column.ColumnLength = nmd.ColumnLength; + column.ColumnComment = nmd.ColumnComment; + updateColumnList.Add(column); + } + } + } + //增加新增 + if(addColumnList.Count>0) AddList(addColumnList, CodeGen); + //删除没有的 + if (delColumnList.Count > 0) await _db.Deleteable(delColumnList).ExecuteCommandAsync(); + //更新 + if (updateColumnList.Count > 0) await _db.Updateable(updateColumnList).ExecuteCommandAsync(); + //重新获取 return await _db.Queryable() .Where(u => u.CodeGenId == input.CodeGenId) .Select() diff --git a/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs b/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs index ae463436..758312a3 100644 --- a/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs +++ b/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs @@ -77,7 +77,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient .ExecuteReturnEntityAsync(); // 增加配置表 - _codeGenConfigService.AddList(GetColumnList(input), newCodeGen); + _codeGenConfigService.AddList(_codeGenConfigService.GetColumnList(input), newCodeGen); } /// @@ -108,9 +108,10 @@ public class SysCodeGenService : IDynamicApiController, ITransient [DisplayName("更新代码生成")] public async Task UpdateCodeGen(UpdateCodeGenInput input) { - var isExist = await _db.Queryable().AnyAsync(u => u.TableName == input.TableName && u.Id != input.Id); - if (isExist) - throw Oops.Oh(ErrorCodeEnum.D1400); + //开发阶段不断生成调整 + //var isExist = await _db.Queryable().AnyAsync(u => u.TableName == input.TableName && u.Id != input.Id); + //if (isExist) + // throw Oops.Oh(ErrorCodeEnum.D1400); var codeGen = input.Adapt(); var templateRelations = GetCodeGenTemplateRelation(codeGen.Id, input.CodeGenTemplateIds); @@ -121,7 +122,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient .ExecuteCommandAsync(); // 更新配置表 - _codeGenConfigService.AddList(GetColumnList(input.Adapt()), codeGen); + _codeGenConfigService.AddList(_codeGenConfigService.GetColumnList(input.Adapt()), codeGen); } /// @@ -183,7 +184,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient var config = _dbConnectionOptions.ConnectionConfigs.FirstOrDefault(u => configId.Equals(u.ConfigId)); - IEnumerable entityInfos = await GetEntityInfos(); // 获取所有实体定义 + IEnumerable entityInfos = await _codeGenConfigService.GetEntityInfos(); // 获取所有实体定义 entityInfos = entityInfos.OrderBy(u => u.EntityName.StartsWith("Sys") ? 1 : 0).ThenBy(u => u.EntityName); var tableOutputList = new List(); @@ -228,7 +229,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient var entityBasePropertyNames = _codeGenOptions.EntityBaseColumn[nameof(EntityTenant)]; tableName = GetRealTableName(tableName); - var properties = GetEntityInfos().Result.First(u => GetRealTableName(u.DbTableName).EqualIgnoreCase(tableName)).Type.GetProperties() + var properties = _codeGenConfigService.GetEntityInfos().Result.First(u => GetRealTableName(u.DbTableName).EqualIgnoreCase(tableName)).Type.GetProperties() .Where(u => u.GetCustomAttribute()?.IsIgnore == false).Select(u => new { PropertyName = u.Name, @@ -269,128 +270,6 @@ public class SysCodeGenService : IDynamicApiController, ITransient } } - /// - /// 获取数据表列(实体属性)集合 - /// - /// - private List GetColumnList([FromQuery] AddCodeGenInput input) - { - var entityType = GetEntityInfos().GetAwaiter().GetResult().FirstOrDefault(u => u.EntityName == input.TableName); - if (entityType == null) - return null; - var config = _dbConnectionOptions.ConnectionConfigs.FirstOrDefault(u => u.ConfigId.ToString() == input.ConfigId); - var dbTableName = config!.DbSettings.EnableUnderLine ? UtilMethods.ToUnderLine(entityType.DbTableName) : entityType.DbTableName; - - int bracketIndex = dbTableName.IndexOf('{'); - if (bracketIndex != -1) - { - dbTableName = dbTableName.Substring(0, bracketIndex); - var dbTableInfos = _db.AsTenant().GetConnectionScope(input.ConfigId).DbMaintenance.GetTableInfoList(false); - var table = dbTableInfos.FirstOrDefault(x => x.Name.StartsWith(config.DbSettings.EnableUnderLine ? UtilMethods.ToUnderLine(dbTableName) : dbTableName, StringComparison.CurrentCultureIgnoreCase)); - if (table != null) - dbTableName = table.Name; - } - - // 切库---多库代码生成用 - var provider = _db.AsTenant().GetConnectionScope(!string.IsNullOrEmpty(input.ConfigId) ? input.ConfigId : SqlSugarConst.MainConfigId); - - var entityBasePropertyNames = _codeGenOptions.EntityBaseColumn[nameof(EntityTenant)]; - var columnInfos = provider.DbMaintenance.GetColumnInfosByTableName(dbTableName, false); - var result = columnInfos.Select(u => new ColumnOuput - { - // 转下划线后的列名需要再转回来(暂时不转) - //ColumnName = config.DbSettings.EnableUnderLine ? CodeGenUtil.CamelColumnName(u.DbColumnName, entityBasePropertyNames) : u.DbColumnName, - ColumnName = u.DbColumnName, - ColumnLength = u.Length, - IsPrimarykey = u.IsPrimarykey, - IsNullable = u.IsNullable, - ColumnKey = u.IsPrimarykey.ToString(), - NetType = CodeGenUtil.ConvertDataType(u, provider.CurrentConnectionConfig.DbType), - DataType = u.DataType, - ColumnComment = string.IsNullOrWhiteSpace(u.ColumnDescription) ? u.DbColumnName : u.ColumnDescription, - DefaultValue = u.DefaultValue, - }).ToList(); - - // 获取实体的属性信息,赋值给PropertyName属性(CodeFirst模式应以PropertyName为实际使用名称) - var entityProperties = entityType.Type.GetProperties(); - - for (int i = result.Count - 1; i >= 0; i--) - { - var columnOutput = result[i]; - // 先找自定义字段名的,如果找不到就再找自动生成字段名的(并且过滤掉没有SugarColumn的属性) - var propertyInfo = entityProperties.FirstOrDefault(u => (u.GetCustomAttribute()?.ColumnName ?? "").ToLower() == columnOutput.ColumnName.ToLower()) ?? - entityProperties.FirstOrDefault(u => u.GetCustomAttribute() != null && u.Name.ToLower() == (config.DbSettings.EnableUnderLine - ? CodeGenUtil.CamelColumnName(columnOutput.ColumnName, entityBasePropertyNames).ToLower() - : columnOutput.ColumnName.ToLower())); - if (propertyInfo != null) - { - columnOutput.PropertyName = propertyInfo.Name; - columnOutput.ColumnComment = propertyInfo.GetCustomAttribute()!.ColumnDescription; - } - else - { - result.RemoveAt(i); // 移除没有定义此属性的字段 - } - } - return result; - } - - /// - /// 获取库表信息 - /// - /// 是否排除带SysTable属性的表 - /// - private async Task> GetEntityInfos(bool excludeSysTable = false) - { - var types = new List(); - if (_codeGenOptions.EntityAssemblyNames != null) - { - var assemblies = AppDomain.CurrentDomain.GetAssemblies(); - foreach (var assembly in assemblies) - { - var assemblyName = assembly.GetName().Name!; - if (_codeGenOptions.EntityAssemblyNames.Contains(assemblyName) || _codeGenOptions.EntityAssemblyNames.Any(name => assemblyName.Contains(name))) - { - Assembly asm = Assembly.Load(assemblyName); - types.AddRange(asm.GetExportedTypes().ToList()); - } - } - } - var sugarTableType = typeof(SugarTable); - bool IsMyAttribute(Attribute[] o) - { - foreach (Attribute a in o) - { - if (a.GetType() == sugarTableType) - return true; - } - return false; - } - Type[] cosType = types.Where(u => IsMyAttribute(Attribute.GetCustomAttributes(u, false))).ToArray(); - - var entityInfos = new List(); - foreach (var ct in cosType) - { - // 若实体贴[SysTable]特性,则禁止显示系统自带的 - if (excludeSysTable && ct.IsDefined(typeof(SysTableAttribute), false)) - continue; - - var des = ct.GetCustomAttributes(typeof(DescriptionAttribute), false); - var description = des.Length > 0 ? ((DescriptionAttribute)des[0]).Description : ""; - - var sugarAttribute = ct.GetCustomAttributes(sugarTableType, true).FirstOrDefault(); - - entityInfos.Add(new EntityInfo() - { - EntityName = ct.Name, - DbTableName = sugarAttribute == null ? ct.Name : ((SugarTable)sugarAttribute).TableName, - TableDescription = sugarAttribute == null ? description : ((SugarTable)sugarAttribute).TableDescription, - Type = ct - }); - } - return await Task.FromResult(entityInfos); - } - /// /// 获取程序保存位置 🔖 /// @@ -442,6 +321,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient .Replace("{TableNameLower}", input.TableName?.ToFirstLetterLowerCase() ?? ""); string tmpPath; + if (!input.GenerateType.StartsWith('1')) { if (templateList[i].Type == CodeGenTypeEnum.Frontend) @@ -599,7 +479,8 @@ public class SysCodeGenService : IDynamicApiController, ITransient if (filename == "web_views_index.vue.vm") { filename = string.IsNullOrEmpty(input.LeftTab) ? filename : "web_views_LeftTree.vue.vm"; // 左树右列表 - filename = string.IsNullOrEmpty(input.BottomTab) ? filename : "web_views_BottomIndx.vue.vm"; // 左数右上列表下列表属性 + filename = (!string.IsNullOrEmpty(input.LeftTab) && !string.IsNullOrEmpty(input.BottomTab)) ? "web_views_BottomIndx.vue.vm" : filename; // 左树右上列表下列表属性 + filename = (string.IsNullOrEmpty(input.LeftTab) && !string.IsNullOrEmpty(input.BottomTab)) ? "web_views_UDIndx.vue.vm" : filename; // 右上列表下列表属性 } var templateFilePath = Path.Combine(templatePath, filename); if (!File.Exists(templateFilePath)) return null; diff --git a/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs b/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs index 0108f9f0..8f8306ce 100644 --- a/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs +++ b/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json.Converters; using Npgsql; +using Admin.NET.Core; namespace Admin.NET.Core.Service; @@ -271,6 +272,36 @@ public class SysDatabaseService : IDynamicApiController, ITransient [ApiDescriptionSettings(Name = "CreateEntity"), HttpPost] [DisplayName("创建实体")] public void CreateEntity(CreateEntityInput input) + { + var tResult = GenerateEntity(input); + var targetPath = GetEntityTargetPath(input); + File.WriteAllText(targetPath, tResult, Encoding.UTF8); + } + + /// + /// 创建实体文件内容 + /// + /// + /// + /// + /// + /// + public string GenerateEntity(string ConfigId, string TableName, string Position, string BaseClassName) + { + var input = new CreateEntityInput(); + input.TableName = TableName; + input.EntityName = TableName.ToFirstLetterUpperCase(); + input.ConfigId = ConfigId; + input.Position = string.IsNullOrWhiteSpace(Position) ? "Admin.NET.Application" : Position; + input.BaseClassName = string.IsNullOrWhiteSpace(BaseClassName) ? "EntityBaseId" : BaseClassName; + return GenerateEntity(input); + } + /// + /// 创建实体文件内容 + /// + /// + /// + public string GenerateEntity(CreateEntityInput input) { var config = App.GetOptions().ConnectionConfigs.FirstOrDefault(u => u.ConfigId.ToString() == input.ConfigId); input.Position = string.IsNullOrWhiteSpace(input.Position) ? "Admin.NET.Application" : input.Position; @@ -307,8 +338,8 @@ public class SysDatabaseService : IDynamicApiController, ITransient Description = string.IsNullOrWhiteSpace(dbTableInfo.Description) ? input.EntityName + "业务表" : dbTableInfo.Description, TableField = dbColumnInfos }); - var targetPath = GetEntityTargetPath(input); - File.WriteAllText(targetPath, tResult, Encoding.UTF8); + + return tResult; } /// diff --git a/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/web_views_UDIndx.vue.vm b/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/web_views_UDIndx.vue.vm new file mode 100644 index 00000000..c13b6798 --- /dev/null +++ b/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/web_views_UDIndx.vue.vm @@ -0,0 +1,91 @@ +@{ + string LowerFirstLetter(string text) + { + return text.ToString()[..1].ToLower() + text[1..]; // 首字母小写 + } + var pkField = Model.TableField.Where(c => c.ColumnKey == "True").FirstOrDefault(); + string pkFieldName = null; + if(pkField != null && !string.IsNullOrEmpty(pkField.PropertyName)) + { + pkFieldName = LowerFirstLetter(pkField.PropertyName); + } + Dictionary definedObjects = new Dictionary(); + bool haveLikeCdt = false; + foreach (var column in Model.TableField){ + if (column.QueryWhether == "Y" && column.QueryType == "like"){ + haveLikeCdt = true; + } + } +} + + + + + diff --git a/Web/src/views/system/codeGen/component/genConfigDialog.vue b/Web/src/views/system/codeGen/component/genConfigDialog.vue index 35a294bf..1ac558d0 100644 --- a/Web/src/views/system/codeGen/component/genConfigDialog.vue +++ b/Web/src/views/system/codeGen/component/genConfigDialog.vue @@ -1,6 +1,7 @@