1、加入测试代码生成的Entity
2、BUG:修复树型框、外键框在MySQL下出错
This commit is contained in:
parent
03f3851bb4
commit
03b67f7fef
81
Admin.NET/Admin.NET.Application/Entity/TestCodeGenDemo.cs
Normal file
81
Admin.NET/Admin.NET.Application/Entity/TestCodeGenDemo.cs
Normal file
@ -0,0 +1,81 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Admin.NET.Application.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// 代码自动生成DEMO
|
||||
/// </summary>
|
||||
/// <remarks>这个类型主要用于给新人快速体验代码自动生成功能和测试该功能是否正常</remarks>
|
||||
[SugarTable(null, "代码自动生成DEMO")]
|
||||
public class TestCodeGenDemo : EntityBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 文本
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "文本", Length = 128)]
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数值
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "数值")]
|
||||
public int Age { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 时间选择
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "时间选择")]
|
||||
public DateTime? Date1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开关
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "开关")]
|
||||
public bool IsOk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 外键(sys_user)
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "外键(sys_user)")]
|
||||
public long UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 树选择框(sys_org)
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "树选择框(sys_org)")]
|
||||
public long OrgId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 字典1
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "字典1")]
|
||||
public string Dict1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 枚举1
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "枚举1")]
|
||||
public string Enum1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 常量1
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "常量1")]
|
||||
public int Const1 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传控件
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "上传控件")]
|
||||
public long UploadImage { get; set; }
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
@ -179,8 +179,8 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
|
||||
var config = App.GetOptions<DbConnectionOptions>().ConnectionConfigs.FirstOrDefault(u => configId.Equals(u.ConfigId));
|
||||
|
||||
IEnumerable<EntityInfo> entityInfos = await GetEntityInfos(); // 获取所有实体定义
|
||||
//entityInfos = entityInfos.OrderBy(u => u.EntityName.StartsWith("Sys") ? 1 : 0).ThenBy(u => u.EntityName);
|
||||
IEnumerable<EntityInfo> entityInfos = await GetEntityInfos(false); // 获取所有实体定义
|
||||
entityInfos = entityInfos.OrderBy(u => u.EntityName.StartsWith("Sys") ? 1 : 0).ThenBy(u => u.EntityName);
|
||||
|
||||
var tableOutputList = new List<TableOutput>();
|
||||
foreach (var item in entityInfos)
|
||||
@ -222,7 +222,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
var entityType = provider.DbMaintenance.GetTableInfoList(false).FirstOrDefault(u => u.Name == tableName);
|
||||
if (entityType == null) return null;
|
||||
var entityBasePropertyNames = _codeGenOptions.EntityBaseColumn[nameof(EntityTenant)];
|
||||
var properties = GetEntityInfos().Result.First(u => u.DbTableName == tableName).Type.GetProperties()
|
||||
var properties = GetEntityInfos().Result.First(u => u.DbTableName.ToLower() == tableName.ToLower()).Type.GetProperties()
|
||||
.Where(e => e.GetCustomAttribute<SugarColumn>()?.IsIgnore == false).Select(u => new
|
||||
{
|
||||
PropertyName = u.Name,
|
||||
@ -241,6 +241,8 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
}).ToList();
|
||||
foreach (var column in columnList)
|
||||
{
|
||||
if (!properties.Any(u => u.ColumnName == column.ColumnName))
|
||||
continue;
|
||||
var property = properties.First(u => u.ColumnName == column.ColumnName);
|
||||
column.ColumnComment ??= property?.ColumnComment;
|
||||
column.PropertyName = property?.PropertyName;
|
||||
@ -318,7 +320,7 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
/// 获取库表信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<IEnumerable<EntityInfo>> GetEntityInfos()
|
||||
private async Task<IEnumerable<EntityInfo>> GetEntityInfos(bool filtSysTable = false)
|
||||
{
|
||||
var types = new List<Type>();
|
||||
if (_codeGenOptions.EntityAssemblyNames != null)
|
||||
@ -354,8 +356,8 @@ public class SysCodeGenService : IDynamicApiController, ITransient
|
||||
foreach (var ct in cosType)
|
||||
{
|
||||
//// 若实体贴[SysTable]特性,则禁止显示系统自带的
|
||||
//if (ct.IsDefined(typeof(SysTableAttribute), false))
|
||||
// continue;
|
||||
if (filtSysTable && ct.IsDefined(typeof(SysTableAttribute), false))
|
||||
continue;
|
||||
|
||||
var des = ct.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
var description = des.Length > 0 ? ((DescriptionAttribute)des[0]).Description : "";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user