mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-19 07:44:59 +08:00
调整代码生成器生成变量命名方式
This commit is contained in:
parent
329c2c9f07
commit
5eec669cde
@ -4,6 +4,7 @@ using System.ComponentModel;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Autofac.Extensions.DependencyInjection;
|
using Autofac.Extensions.DependencyInjection;
|
||||||
|
using Humanizer;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Infrastructure.Utilities;
|
using Infrastructure.Utilities;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
@ -22,7 +23,7 @@ namespace OpenAuth.App
|
|||||||
public class DbExtension
|
public class DbExtension
|
||||||
{
|
{
|
||||||
private List<DbContext> _contexts = new List<DbContext>();
|
private List<DbContext> _contexts = new List<DbContext>();
|
||||||
|
|
||||||
private IOptions<AppSetting> _appConfiguration;
|
private IOptions<AppSetting> _appConfiguration;
|
||||||
private IHttpContextAccessor _httpContextAccessor;
|
private IHttpContextAccessor _httpContextAccessor;
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ namespace OpenAuth.App
|
|||||||
{
|
{
|
||||||
var result = new List<BuilderTableColumn>();
|
var result = new List<BuilderTableColumn>();
|
||||||
const string domain = "openauth.repository.domain.";
|
const string domain = "openauth.repository.domain.";
|
||||||
IEntityType entity = null;
|
IEntityType entity = null;
|
||||||
_contexts.ForEach(u =>
|
_contexts.ForEach(u =>
|
||||||
{
|
{
|
||||||
entity = u.Model.GetEntityTypes()
|
entity = u.Model.GetEntityTypes()
|
||||||
@ -58,11 +59,11 @@ namespace OpenAuth.App
|
|||||||
{
|
{
|
||||||
object[] objs = property.GetCustomAttributes(typeof(DescriptionAttribute), true);
|
object[] objs = property.GetCustomAttributes(typeof(DescriptionAttribute), true);
|
||||||
object[] browsableObjs = property.GetCustomAttributes(typeof(BrowsableAttribute), true);
|
object[] browsableObjs = property.GetCustomAttributes(typeof(BrowsableAttribute), true);
|
||||||
var description = objs.Length > 0 ? ((DescriptionAttribute) objs[0]).Description : property.Name;
|
var description = objs.Length > 0 ? ((DescriptionAttribute)objs[0]).Description : property.Name;
|
||||||
if (string.IsNullOrEmpty(description)) description = property.Name;
|
if (string.IsNullOrEmpty(description)) description = property.Name;
|
||||||
//如果没有BrowsableAttribute或 [Browsable(true)]表示可见,其他均为不可见,需要前端配合显示
|
//如果没有BrowsableAttribute或 [Browsable(true)]表示可见,其他均为不可见,需要前端配合显示
|
||||||
bool browsable = browsableObjs == null || browsableObjs.Length == 0 ||
|
bool browsable = browsableObjs == null || browsableObjs.Length == 0 ||
|
||||||
((BrowsableAttribute) browsableObjs[0]).Browsable;
|
((BrowsableAttribute)browsableObjs[0]).Browsable;
|
||||||
var typeName = property.PropertyType.Name;
|
var typeName = property.PropertyType.Name;
|
||||||
if (Nullable.GetUnderlyingType(property.PropertyType) != null)
|
if (Nullable.GetUnderlyingType(property.PropertyType) != null)
|
||||||
{
|
{
|
||||||
@ -88,7 +89,7 @@ namespace OpenAuth.App
|
|||||||
public List<string> GetDbEntityNames()
|
public List<string> GetDbEntityNames()
|
||||||
{
|
{
|
||||||
var names = new List<string>();
|
var names = new List<string>();
|
||||||
var models = _contexts.Select(u =>u.Model);
|
var models = _contexts.Select(u => u.Model);
|
||||||
|
|
||||||
foreach (var model in models)
|
foreach (var model in models)
|
||||||
{
|
{
|
||||||
@ -135,63 +136,65 @@ namespace OpenAuth.App
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private IList<SysTableColumn> GetOracleStructure(string tableName)
|
private IList<SysTableColumn> GetOracleStructure(string tableName)
|
||||||
{
|
{
|
||||||
|
tableName = tableName.ToUpper();
|
||||||
var sql = $@"
|
var sql = $@"
|
||||||
select utc.column_name as columnname
|
select utc.column_name as columnname
|
||||||
, utc.data_type columntype
|
, utc.data_type columntype
|
||||||
, utc.data_length maxlength
|
, utc.data_length maxlength
|
||||||
, case utc.nullable when 'N' then 0 else 1 end isnull
|
, case utc.nullable when 'N' then 0 else 1 end isnull
|
||||||
, utc.data_default defaultval
|
, utc.data_default defaultval
|
||||||
, ucc.comments ""COMMENT""
|
, ucc.comments ""COMMENT""
|
||||||
, utc.table_name tablename
|
, utc.table_name tablename
|
||||||
, case utc.column_name
|
, case utc.column_name
|
||||||
when (select col.column_name
|
when (select col.column_name
|
||||||
from user_constraints con
|
from user_constraints con
|
||||||
, user_cons_columns col
|
, user_cons_columns col
|
||||||
where con.constraint_name = col.constraint_name
|
where con.constraint_name = col.constraint_name
|
||||||
and con.constraint_type = 'P'
|
and con.constraint_type = 'P'
|
||||||
and col.table_name = '{tableName}') then 1
|
and col.table_name = '{tableName}') then 1
|
||||||
else 0 end as iskey
|
else 0 end as iskey
|
||||||
, case
|
, case
|
||||||
when utc.column_name in ('CreateUserId', 'UpdateUserId', 'Id')
|
when utc.column_name in ('CreateUserId', 'UpdateUserId', 'Id')
|
||||||
then 0
|
then 0
|
||||||
else 1
|
else 1
|
||||||
end as isdisplay
|
end as isdisplay
|
||||||
, case
|
, case
|
||||||
when data_type in ('BIT', 'BOOL') then
|
when data_type in ('BIT', 'BOOL') then
|
||||||
'bool'
|
'bool'
|
||||||
when data_type in ('SMALLINT') then 'short'
|
when data_type in ('SMALLINT') then 'short'
|
||||||
when data_type in ('TINYINT') then 'bool'
|
when data_type in ('TINYINT') then 'bool'
|
||||||
when data_type in ('NUMBER', 'CHAR', 'INT', 'Year') then
|
when data_type in ('NUMBER', 'CHAR', 'INT', 'Year') then
|
||||||
'int'
|
'int'
|
||||||
when data_type in ('BIGINT') then
|
when data_type in ('BIGINT') then
|
||||||
'bigint'
|
'bigint'
|
||||||
when data_type in ('FLOAT', 'DOUBLE', 'DECIMAL') then
|
when data_type in ('FLOAT', 'DOUBLE', 'DECIMAL') then
|
||||||
'decimal'
|
'decimal'
|
||||||
when data_type in
|
when data_type in
|
||||||
('CHAR', 'VARCHAR', 'TINY TEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'TINYBLOB', 'BLOB',
|
('CHAR', 'VARCHAR', 'TINY TEXT', 'TEXT', 'MEDIUMTEXT', 'LONGTEXT', 'TINYBLOB', 'BLOB',
|
||||||
'MEDIUMBLOB', 'LONGBLOB', 'Time') then
|
'MEDIUMBLOB', 'LONGBLOB', 'Time') then
|
||||||
'string'
|
'string'
|
||||||
when data_type in ('Date', 'DateTime', 'TIMESTAMP(6)') then
|
when data_type in ('DATE', 'DATETIME', 'TIMESTAMP(6)') then
|
||||||
'DateTime'
|
'DateTime'
|
||||||
else 'string'
|
else 'string'
|
||||||
end as entitytype
|
end as entitytype
|
||||||
from user_tab_columns utc
|
from user_tab_columns utc
|
||||||
, user_col_comments ucc
|
, user_col_comments ucc
|
||||||
where utc.table_name = ucc.table_name
|
where utc.table_name = ucc.table_name
|
||||||
and utc.column_name = ucc.column_name
|
and utc.column_name = ucc.column_name
|
||||||
and utc.table_name = '{tableName}'
|
and utc.table_name = '{tableName}'
|
||||||
order by column_id; ";
|
order by column_id; ";
|
||||||
|
|
||||||
foreach (var context in _contexts)
|
foreach (var context in _contexts)
|
||||||
{
|
{
|
||||||
var columns = context.Set<SysTableColumn>().FromSqlRaw(sql);
|
var columns = context.Set<SysTableColumn>().FromSqlRaw(sql);
|
||||||
var columnList = columns?.ToList();
|
var columnList = columns?.ToList();
|
||||||
if (columnList != null && columnList.Any())
|
if (columnList != null && columnList.Any())
|
||||||
{
|
{
|
||||||
|
columnList.ForEach(u => u.ColumnName = u.ColumnName.Transform(To.LowerCase, To.TitleCase));
|
||||||
return columnList;
|
return columnList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new List<SysTableColumn>();
|
return new List<SysTableColumn>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,9 +203,9 @@ order by column_id; ";
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private IList<SysTableColumn> GetMySqlStructure(string tableName)
|
private IList<SysTableColumn> GetMySqlStructure(string tableName)
|
||||||
{
|
{
|
||||||
var sql = $@"SELECT DISTINCT
|
var sql = $@"SELECT DISTINCT
|
||||||
Column_Name AS ColumnName,
|
Column_Name AS ColumnName,
|
||||||
'{ tableName}' as tableName,
|
'{tableName}' as tableName,
|
||||||
Column_Comment AS Comment,
|
Column_Comment AS Comment,
|
||||||
data_type as ColumnType,
|
data_type as ColumnType,
|
||||||
CASE
|
CASE
|
||||||
@ -253,74 +256,76 @@ order by column_id; ";
|
|||||||
var columnList = columns?.ToList();
|
var columnList = columns?.ToList();
|
||||||
if (columnList != null && columnList.Any())
|
if (columnList != null && columnList.Any())
|
||||||
{
|
{
|
||||||
|
columnList.ForEach(u => u.ColumnName = u.ColumnName.Transform(To.LowerCase, To.TitleCase));
|
||||||
return columnList;
|
return columnList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new List<SysTableColumn>();
|
return new List<SysTableColumn>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取Mysql表结构信息
|
/// 获取pgsql表结构信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private IList<SysTableColumn> GetPostgreStructure(string tableName)
|
private IList<SysTableColumn> GetPostgreStructure(string tableName)
|
||||||
{
|
{
|
||||||
var sql = $@"select attr.attrelid
|
tableName = tableName.ToLower();
|
||||||
, schema.nspname as schemaname
|
var sql = $@"select attr.attrelid
|
||||||
, class.relname as tablename --表名
|
, schema.nspname as schemaname
|
||||||
, attr.attname as columnname --列名
|
, class.relname as tablename --表名
|
||||||
, attr.atttypid --类型ID
|
, attr.attname as columnname --列名
|
||||||
, attr.atttypmod
|
, attr.atttypid --类型ID
|
||||||
, case when con.conname is not null then 1 else 0 end as iskey --是否主键
|
, attr.atttypmod
|
||||||
, case when attr.attnotnull is true then 0 else 1 end as isnull --可空
|
, case when con.conname is not null then 1 else 0 end as iskey --是否主键
|
||||||
, t.typname columntype --类型名称
|
, case when attr.attnotnull is true then 0 else 1 end as isnull --可空
|
||||||
, case
|
, t.typname columntype --类型名称
|
||||||
when typname in ('BIT', 'BOOL', 'bit', 'bool') then
|
, case
|
||||||
'bool'
|
when typname in ('BIT', 'BOOL', 'bit', 'bool') then
|
||||||
when typname in ('smallint', 'SMALLINT') then 'short'
|
'bool'
|
||||||
when typname in ('tinyint', 'TINYINT') then 'bool'
|
when typname in ('smallint', 'SMALLINT') then 'short'
|
||||||
when typname in ('int4', 'int', 'INT') then
|
when typname in ('tinyint', 'TINYINT') then 'bool'
|
||||||
'int'
|
when typname in ('int4', 'int', 'INT') then
|
||||||
when typname in ('BIGINT', 'bigint') then
|
'int'
|
||||||
'bigint'
|
when typname in ('BIGINT', 'bigint') then
|
||||||
when typname in ('FLOAT', 'DOUBLE', 'DECIMAL', 'float', 'double', 'decimal') then
|
'bigint'
|
||||||
'decimal'
|
when typname in ('FLOAT', 'DOUBLE', 'DECIMAL', 'float', 'double', 'decimal') then
|
||||||
when typname in ('varchar', 'text') then
|
'decimal'
|
||||||
'string'
|
when typname in ('varchar', 'text') then
|
||||||
when typname in ('Date', 'DateTime', 'TimeStamp', 'date', 'datetime', 'timestamp') then
|
'string'
|
||||||
'DateTime'
|
when typname in ('Date', 'DateTime', 'TimeStamp', 'date', 'datetime', 'timestamp') then
|
||||||
else 'string'
|
'DateTime'
|
||||||
end as entitytype
|
else 'string'
|
||||||
, comment.description as comment
|
end as entitytype
|
||||||
, 1 as iscolumndata
|
, comment.description as comment
|
||||||
, case
|
, 1 as iscolumndata
|
||||||
when t.typname = 'varchar' or t.typname = 'bpchar' then attr.atttypmod - 4
|
, case
|
||||||
else 10
|
when t.typname = 'varchar' or t.typname = 'bpchar' then attr.atttypmod - 4
|
||||||
end as columnwidth
|
else 10
|
||||||
, 0 as orderno
|
end as columnwidth
|
||||||
, case
|
, 0 as orderno
|
||||||
when t.typname = 'varchar' or t.typname = 'bpchar' then attr.atttypmod - 4
|
, case
|
||||||
else 10
|
when t.typname = 'varchar' or t.typname = 'bpchar' then attr.atttypmod - 4
|
||||||
end as maxlength
|
else 10
|
||||||
, case
|
end as maxlength
|
||||||
when attname in ('createid', 'modifyid', '')
|
, case
|
||||||
or con.conname is null then 0
|
when attname in ('createid', 'modifyid', '')
|
||||||
else 1
|
or con.conname is null then 0
|
||||||
end as isdisplay --是否显示
|
else 1
|
||||||
from pg_catalog.pg_class class
|
end as isdisplay --是否显示
|
||||||
inner join pg_catalog.pg_attribute attr on attr.attrelid = class.oid
|
from pg_catalog.pg_class class
|
||||||
left join pg_catalog.pg_constraint con
|
inner join pg_catalog.pg_attribute attr on attr.attrelid = class.oid
|
||||||
on con.conrelid = class.oid and attr.attnum = any (con.conkey) and con.contype = 'p'
|
left join pg_catalog.pg_constraint con
|
||||||
left join pg_catalog.pg_type t on attr.atttypid = t.oid
|
on con.conrelid = class.oid and attr.attnum = any (con.conkey) and con.contype = 'p'
|
||||||
inner join pg_catalog.pg_description comment
|
left join pg_catalog.pg_type t on attr.atttypid = t.oid
|
||||||
on comment.objoid = attr.attrelid and comment.objsubid = attr.attnum
|
inner join pg_catalog.pg_description comment
|
||||||
inner join pg_catalog.pg_namespace schema on schema.oid = class.relnamespace
|
on comment.objoid = attr.attrelid and comment.objsubid = attr.attnum
|
||||||
where attr.attnum > 0
|
inner join pg_catalog.pg_namespace schema on schema.oid = class.relnamespace
|
||||||
and not attr.attisdropped
|
where attr.attnum > 0
|
||||||
and schema.nspname = 'public' -- replace 'your_schema' with your schema name
|
and not attr.attisdropped
|
||||||
and class.relname = '{tableName}'";
|
and schema.nspname = 'public' -- replace 'your_schema' with your schema name
|
||||||
|
and class.relname = '{tableName}'";
|
||||||
|
|
||||||
foreach (var context in _contexts)
|
foreach (var context in _contexts)
|
||||||
{
|
{
|
||||||
@ -328,24 +333,25 @@ where attr.attnum > 0
|
|||||||
var columnList = columns?.ToList();
|
var columnList = columns?.ToList();
|
||||||
if (columnList != null && columnList.Any())
|
if (columnList != null && columnList.Any())
|
||||||
{
|
{
|
||||||
|
columnList.ForEach(u => u.ColumnName = u.ColumnName.Transform(To.LowerCase, To.TitleCase));
|
||||||
return columnList;
|
return columnList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new List<SysTableColumn>();
|
return new List<SysTableColumn>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取SqlServer表结构信息
|
/// 获取SqlServer表结构信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tableName"></param>
|
/// <param name="tableName"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private IList<SysTableColumn> GetSqlServerStructure(string tableName)
|
private IList<SysTableColumn> GetSqlServerStructure(string tableName)
|
||||||
{
|
{
|
||||||
var sql = $@"
|
var sql = $@"
|
||||||
SELECT TableName,
|
SELECT TableName,
|
||||||
LTRIM(RTRIM(ColumnName)) AS ColumnName,
|
LTRIM(RTRIM(ColumnName)) AS ColumnName,
|
||||||
Comment,
|
Comment,
|
||||||
@ -426,7 +432,7 @@ where attr.attnum > 0
|
|||||||
LEFT JOIN sys.extended_properties epTwo ON obj.id = epTwo.major_id
|
LEFT JOIN sys.extended_properties epTwo ON obj.id = epTwo.major_id
|
||||||
AND epTwo.minor_id = 0
|
AND epTwo.minor_id = 0
|
||||||
AND epTwo.name = 'MS_Description'
|
AND epTwo.name = 'MS_Description'
|
||||||
WHERE obj.name = '{ tableName}') AS t
|
WHERE obj.name = '{tableName}') AS t
|
||||||
ORDER BY t.colorder";
|
ORDER BY t.colorder";
|
||||||
|
|
||||||
foreach (var context in _contexts)
|
foreach (var context in _contexts)
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
<PackageReference Include="Autofac" Version="8.1.1" />
|
<PackageReference Include="Autofac" Version="8.1.1" />
|
||||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
|
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
|
||||||
<PackageReference Include="Autofac.Extras.Quartz" Version="5.1.0" />
|
<PackageReference Include="Autofac.Extras.Quartz" Version="5.1.0" />
|
||||||
|
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.1.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.1.2" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="5.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="5.0.0" />
|
||||||
|
Loading…
Reference in New Issue
Block a user