diff --git a/Admin.NET/Admin.NET.Application/Configuration/CodeGen.json b/Admin.NET/Admin.NET.Application/Configuration/CodeGen.json index 275087a8..5852736c 100644 --- a/Admin.NET/Admin.NET.Application/Configuration/CodeGen.json +++ b/Admin.NET/Admin.NET.Application/Configuration/CodeGen.json @@ -3,8 +3,8 @@ // 代码生成配置项-程序集名称集合 "CodeGen": { - "EntityAssemblyNames": [ "Admin.NET.Core", "Admin.NET.Application" ], - "BaseEntityNames": [ "EntityTenantId", "EntityTenant", "EntityTenantBaseData", "EntityBaseData", "EntityBase", "EntityBaseId" ], + "EntityAssemblyNames": [ "Admin.NET.Core", "Admin.NET.Application" ], // 实体所在程序集 + "BaseEntityNames": [ "EntityTenantId", "EntityTenant", "EntityTenantBaseData", "EntityBaseData", "EntityBase", "EntityBaseId" ], // 实体基类名称 "EntityBaseColumn": { "EntityTenantId": [ "Id", "TenantId" ], "EntityTenant": [ "Id", "CreateTime", "UpdateTime", "CreateUserId", "UpdateUserId", "CreateUserName", "UpdateUserName", "IsDelete", "TenantId" ], diff --git a/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs b/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs index 563985f1..46c64ed9 100644 --- a/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs +++ b/Admin.NET/Admin.NET.Core/Service/CodeGen/SysCodeGenService.cs @@ -175,24 +175,22 @@ public class SysCodeGenService : IDynamicApiController, ITransient public async Task> GetTableList(string configId = SqlSugarConst.MainConfigId) { var provider = _db.AsTenant().GetConnectionScope(configId); - var dbTableInfos = provider.DbMaintenance.GetTableInfoList(false); // 不能走缓存,否则切库不起作用 + var dbTableInfos = provider.DbMaintenance.GetTableInfoList(false); var config = App.GetOptions().ConnectionConfigs.FirstOrDefault(u => configId.Equals(u.ConfigId)); - var dbTableNames = dbTableInfos.Select(u => u.Name.ToLower()).ToList(); - IEnumerable entityInfos = await GetEntityInfos(); - entityInfos = entityInfos.OrderBy(u => u.EntityName.StartsWith("Sys") ? 1 : 0).ThenBy(u => u.EntityName); + IEnumerable entityInfos = await GetEntityInfos(); // 获取所有实体定义 + //entityInfos = entityInfos.OrderBy(u => u.EntityName.StartsWith("Sys") ? 1 : 0).ThenBy(u => u.EntityName); var tableOutputList = new List(); foreach (var item in entityInfos) { - string dbTableName = item.DbTableName; + var dbTableName = item.DbTableName; int bracketIndex = dbTableName.IndexOf('{'); if (bracketIndex != -1) - { dbTableName = dbTableName.Substring(0, bracketIndex); - } - var table = dbTableInfos.FirstOrDefault(x => x.Name.ToLower().StartsWith((config != null && config.DbSettings.EnableUnderLine ? UtilMethods.ToUnderLine(dbTableName) : dbTableName).ToLower())); + + var table = dbTableInfos.FirstOrDefault(u => u.Name.ToLower().StartsWith((config != null && config.DbSettings.EnableUnderLine ? UtilMethods.ToUnderLine(dbTableName) : dbTableName).ToLower())); if (table == null) continue; tableOutputList.Add(new TableOutput { @@ -303,9 +301,6 @@ public class SysCodeGenService : IDynamicApiController, ITransient /// private async Task> GetEntityInfos() { - var entityInfos = new List(); - - var type = typeof(SugarTable); var types = new List(); if (_codeGenOptions.EntityAssemblyNames != null) { @@ -320,31 +315,34 @@ public class SysCodeGenService : IDynamicApiController, ITransient } } } + var sugarTableType = typeof(SugarTable); bool IsMyAttribute(Attribute[] o) { foreach (Attribute a in o) { - if (a.GetType() == type) + if (a.GetType() == sugarTableType) return true; } return false; } - Type[] cosType = types.Where(o => + Type[] cosType = types.Where(u => { - return IsMyAttribute(Attribute.GetCustomAttributes(o, true)); + return IsMyAttribute(Attribute.GetCustomAttributes(u, false)); } ).ToArray(); + var entityInfos = new List(); foreach (var ct in cosType) { - var sugarAttribute = ct.GetCustomAttributes(type, true)?.FirstOrDefault(); + // 若实体贴[SysTable]特性,则禁止显示系统自带的 + if (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(); - var des = ct.GetCustomAttributes(typeof(DescriptionAttribute), true); - var description = ""; - if (des.Length > 0) - { - description = ((DescriptionAttribute)des[0]).Description; - } entityInfos.Add(new EntityInfo() { EntityName = ct.Name, diff --git a/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs b/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs index 4b362410..a9cf2a86 100644 --- a/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs +++ b/Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs @@ -282,11 +282,9 @@ public class SysDatabaseService : IDynamicApiController, ITransient if (dbColumnNames is null || dbColumnNames is { Length: 0 }) throw Oops.Oh("基类配置文件不存在此类型"); } - var templatePath = GetEntityTemplatePath(); - var targetPath = GetEntityTargetPath(input); + var db = _db.AsTenant().GetConnectionScope(input.ConfigId); - DbTableInfo dbTableInfo = db.DbMaintenance.GetTableInfoList(false).FirstOrDefault(u => u.Name == input.TableName || u.Name == input.TableName.ToLower()) ?? throw Oops.Oh(ErrorCodeEnum.db1001); - List dbColumnInfos = db.DbMaintenance.GetColumnInfosByTableName(input.TableName, false); + var dbColumnInfos = db.DbMaintenance.GetColumnInfosByTableName(input.TableName, false); dbColumnInfos.ForEach(u => { u.PropertyName = config.DbSettings.EnableUnderLine ? CodeGenUtil.CamelColumnName(u.DbColumnName, dbColumnNames) : u.DbColumnName; // 转下划线后的列名需要再转回来 @@ -295,17 +293,20 @@ public class SysDatabaseService : IDynamicApiController, ITransient if (_codeGenOptions.BaseEntityNames.Contains(input.BaseClassName, StringComparer.OrdinalIgnoreCase)) dbColumnInfos = dbColumnInfos.Where(u => !dbColumnNames.Contains(u.PropertyName, StringComparer.OrdinalIgnoreCase)).ToList(); + var dbTableInfo = db.DbMaintenance.GetTableInfoList(false).FirstOrDefault(u => u.Name == input.TableName || u.Name == input.TableName.ToLower()) ?? throw Oops.Oh(ErrorCodeEnum.db1001); + var templatePath = GetEntityTemplatePath(); var tContent = File.ReadAllText(templatePath); var tResult = _viewEngine.RunCompileFromCached(tContent, new { NameSpace = $"{input.Position}.Entity", input.TableName, input.EntityName, - BaseClassName = string.IsNullOrWhiteSpace(input.BaseClassName) ? "" : $" : {input.BaseClassName}", + BaseClassName = string.IsNullOrWhiteSpace(input.BaseClassName) ? "" : $": {input.BaseClassName}", input.ConfigId, - dbTableInfo.Description, + Description = string.IsNullOrWhiteSpace(dbTableInfo.Description) ? input.EntityName + "业务表" : dbTableInfo.Description, TableField = dbColumnInfos }); + var targetPath = GetEntityTargetPath(input); File.WriteAllText(targetPath, tResult, Encoding.UTF8); } diff --git a/Admin.NET/Admin.NET.Core/Service/Wechat/Dto/WechatPayOutput.cs b/Admin.NET/Admin.NET.Core/Service/Wechat/Dto/WechatPayOutput.cs index c3133a7d..108d75d2 100644 --- a/Admin.NET/Admin.NET.Core/Service/Wechat/Dto/WechatPayOutput.cs +++ b/Admin.NET/Admin.NET.Core/Service/Wechat/Dto/WechatPayOutput.cs @@ -68,23 +68,23 @@ public class CreatePayTransactionOutput { public string PrepayId { get; set; } public string OutTradeNumber { get; set; } - public WechatPayParaOutput SingInfo { get; set; } + //public WechatPayParaOutput SingInfo { get; set; } } -public class WechatPayParaOutput -{ - public string AppId { get; set; } +//public class WechatPayParaOutput +//{ +// public string AppId { get; set; } - public string TimeStamp { get; set; } +// public string TimeStamp { get; set; } - public string NonceStr { get; set; } +// public string NonceStr { get; set; } - public string Package { get; set; } +// public string Package { get; set; } - public string SignType { get; set; } +// public string SignType { get; set; } - public string PaySign { get; set; } -} +// public string PaySign { get; set; } +//} public class CreatePayTransactionNativeOutput { diff --git a/Admin.NET/Admin.NET.Core/Service/Wechat/SysWechatPayService.cs b/Admin.NET/Admin.NET.Core/Service/Wechat/SysWechatPayService.cs index b6eddbbd..cb87f848 100644 --- a/Admin.NET/Admin.NET.Core/Service/Wechat/SysWechatPayService.cs +++ b/Admin.NET/Admin.NET.Core/Service/Wechat/SysWechatPayService.cs @@ -121,12 +121,12 @@ public class SysWechatPayService : IDynamicApiController, ITransient await _sysWechatPayRep.InsertAsync(wechatPay); } - var singInfo = GenerateParametersForJsapiPay(new WechatPayParaInput() { PrepayId = response.PrepayId }); + //var singInfo = GenerateParametersForJsapiPay(new WechatPayParaInput() { PrepayId = response.PrepayId }); return new CreatePayTransactionOutput { PrepayId = response.PrepayId, OutTradeNumber = request.OutTradeNumber, - SingInfo = singInfo + //SingInfo = singInfo }; } diff --git a/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/Entity.cs.vm b/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/Entity.cs.vm index e4baf1fa..52565d29 100644 --- a/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/Entity.cs.vm +++ b/Admin.NET/Admin.NET.Web.Entry/wwwroot/template/Entity.cs.vm @@ -7,13 +7,16 @@ @if(@Model.BaseClassName!=""){ @:using Admin.NET.Core; } + namespace @Model.NameSpace; /// /// @(@Model.Description) /// -[SugarTable("@(@Model.TableName)","@(@Model.Description)")] -[Tenant("@(@Model.ConfigId)")] +[SugarTable(null, "@(@Model.Description)")] +@if(@Model.ConfigId!="1300000000001"){ +@:[Tenant("@(@Model.ConfigId)")] +} public class @(@Model.EntityName) @Model.BaseClassName { @foreach (var column in Model.TableField){ diff --git a/Web/src/views/system/codeGen/component/editCodeGenDialog.vue b/Web/src/views/system/codeGen/component/editCodeGenDialog.vue index 74ae5e0b..4e48595f 100644 --- a/Web/src/views/system/codeGen/component/editCodeGenDialog.vue +++ b/Web/src/views/system/codeGen/component/editCodeGenDialog.vue @@ -11,7 +11,7 @@
- 如果是在前端生成的实体/表(在生成表选择项里面找不到),请重启后台服务后再进行代码生成。 + 若找不到在前端生成的实体/表,请检查配置文件中实体所在程序集或重启后台服务。
@@ -63,7 +63,7 @@