😎优化代码生成(关闭显示系统自带实体、关闭实体遍历时继承、优化实体类模板)
This commit is contained in:
parent
fd3105bc3c
commit
e7bb278910
@ -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" ],
|
||||
|
||||
@ -175,24 +175,22 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
public async Task<List<TableOutput>> 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<DbConnectionOptions>().ConnectionConfigs.FirstOrDefault(u => configId.Equals(u.ConfigId));
|
||||
|
||||
var dbTableNames = dbTableInfos.Select(u => u.Name.ToLower()).ToList();
|
||||
IEnumerable<EntityInfo> entityInfos = await GetEntityInfos();
|
||||
entityInfos = entityInfos.OrderBy(u => u.EntityName.StartsWith("Sys") ? 1 : 0).ThenBy(u => u.EntityName);
|
||||
IEnumerable<EntityInfo> entityInfos = await GetEntityInfos(); // 获取所有实体定义
|
||||
//entityInfos = entityInfos.OrderBy(u => u.EntityName.StartsWith("Sys") ? 1 : 0).ThenBy(u => u.EntityName);
|
||||
|
||||
var tableOutputList = new List<TableOutput>();
|
||||
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
|
||||
/// <returns></returns>
|
||||
private async Task<IEnumerable<EntityInfo>> GetEntityInfos()
|
||||
{
|
||||
var entityInfos = new List<EntityInfo>();
|
||||
|
||||
var type = typeof(SugarTable);
|
||||
var types = new List<Type>();
|
||||
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<EntityInfo>();
|
||||
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,
|
||||
|
||||
@ -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<DbColumnInfo> 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,6 +293,8 @@ 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
|
||||
{
|
||||
@ -303,9 +303,10 @@ public class SysDatabaseService : IDynamicApiController, ITransient
|
||||
input.EntityName,
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -7,13 +7,16 @@
|
||||
@if(@Model.BaseClassName!=""){
|
||||
@:using Admin.NET.Core;
|
||||
}
|
||||
|
||||
namespace @Model.NameSpace;
|
||||
|
||||
/// <summary>
|
||||
/// @(@Model.Description)
|
||||
/// </summary>
|
||||
[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){
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
<el-tab-pane label="代码生成" name="codeGen">
|
||||
<div style="color: red; padding: 10px 10px; background: #faecd8; margin-bottom: 10px">
|
||||
<el-icon style="transform: translateY(2px)"><ele-Bell /></el-icon>
|
||||
<span> 如果是在前端生成的实体/表(在生成表选择项里面找不到),请重启后台服务后再进行代码生成。 </span>
|
||||
<span> 若找不到在前端生成的实体/表,请检查配置文件中实体所在程序集或重启后台服务。 </span>
|
||||
</div>
|
||||
<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto">
|
||||
<el-row :gutter="10">
|
||||
@ -63,7 +63,7 @@
|
||||
<template v-slot:label>
|
||||
<div>
|
||||
生成表
|
||||
<el-tooltip raw-content content="如果是在前端生成的实体/表(在生成表选择项里面找不到),请重启后台服务后再进行代码生成。" placement="top">
|
||||
<el-tooltip raw-content content="若找不到在前端生成的实体/表,请检查配置文件中实体所在程序集或重启后台服务。" placement="top">
|
||||
<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"><ele-QuestionFilled /></el-icon>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user