feat:完成codefirst与种子数据,发现非空类型问题,等待紧急修复
This commit is contained in:
@@ -26,23 +26,23 @@ namespace Yi.Framework.Infrastructure.Data.DataSeeds
|
||||
{
|
||||
//using (var uow = iUnitOfWorkManager.CreateContext())
|
||||
//{
|
||||
var res = await iUnitOfWorkManager.Ado.UseTranAsync(async () =>
|
||||
{
|
||||
//var res = await iUnitOfWorkManager.Ado.UseTranAsync(async () =>
|
||||
// {
|
||||
foreach (var seed in dataSeeds)
|
||||
{
|
||||
await seed.InvokerAsync();
|
||||
}
|
||||
});
|
||||
//});
|
||||
|
||||
//var res = uow.Commit();
|
||||
|
||||
if (!res.IsSuccess)
|
||||
{
|
||||
throw new ApplicationException("种子数据初始化异常");
|
||||
}
|
||||
//if (!res.IsSuccess)
|
||||
//{
|
||||
//throw new ApplicationException("种子数据初始化异常");
|
||||
//}
|
||||
//}
|
||||
}
|
||||
return builder.UseMiddleware<DataFilterMiddleware>();
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Furion;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Yi.Framework.Infrastructure.Sqlsugar
|
||||
{
|
||||
public static class SqlsugarCodeFirstExtensions
|
||||
{
|
||||
public static void UseSqlsugarCodeFirstServer(this IApplicationBuilder app)
|
||||
{
|
||||
var db = app.ApplicationServices.GetRequiredService<ISqlSugarClient>();
|
||||
var options = app.ApplicationServices.GetRequiredService<IOptions<DbConnOptions>>();
|
||||
|
||||
if (options.Value.EnabledCodeFirst == false) return;
|
||||
|
||||
db.DbMaintenance.CreateDatabase();
|
||||
var assemblys = new List<Assembly>();
|
||||
|
||||
//全盘加载
|
||||
if (options.Value.EntityAssembly is null)
|
||||
{
|
||||
assemblys.AddRange(App.Assemblies.ToList());
|
||||
}
|
||||
//按需加载
|
||||
else
|
||||
{
|
||||
options.Value.EntityAssembly.ForEach(a =>
|
||||
{
|
||||
assemblys.Add(Assembly.Load(a));
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var assembly in assemblys)
|
||||
{
|
||||
TableInvoer(db, assembly.GetTypes().ToList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void TableInvoer(ISqlSugarClient _Db, List<Type> typeList)
|
||||
{
|
||||
foreach (var t in typeList)
|
||||
{
|
||||
//扫描如果存在SugarTable特性 并且 不是分表模型,直接codefirst
|
||||
if (t.GetCustomAttributes(false).Any(a => a.GetType().Equals(typeof(SugarTable))
|
||||
&& !t.GetCustomAttributes(false).Any(a => a.GetType().Equals(typeof(SplitTableAttribute)))))
|
||||
{
|
||||
_Db.CodeFirst.SetStringDefaultLength(200).InitTables(t);//这样一个表就能成功创建了
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using StackExchange.Profiling.SqlFormatters;
|
||||
using Yi.Framework.Infrastructure.AspNetCore;
|
||||
using Yi.Framework.Infrastructure.Auth;
|
||||
using Yi.Framework.Infrastructure.Data;
|
||||
using Yi.Framework.Infrastructure.Data.DataSeeds;
|
||||
using Yi.Framework.Infrastructure.Data.Filters;
|
||||
using Yi.Framework.Infrastructure.Sqlsugar;
|
||||
using Yi.Framework.Infrastructure.Sqlsugar.Filters;
|
||||
@@ -31,13 +32,17 @@ public class Startup : AppStartup
|
||||
|
||||
services.AddSingleton<IPermissionHandler, DefaultPermissionHandler>();
|
||||
services.AddSingleton<PermissionGlobalAttribute>();
|
||||
services.AddControllers(options => {
|
||||
services.AddControllers(options =>
|
||||
{
|
||||
options.Filters.Add<PermissionGlobalAttribute>();
|
||||
});
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
public async void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
app.UseSqlsugarCodeFirstServer();
|
||||
await app.UseDataSeedServer();
|
||||
app.UseDataFiterServer();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Infrastructure.Data.DataSeeds;
|
||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||
using Yi.Framework.Infrastructure.Helper;
|
||||
@@ -89,7 +90,7 @@ namespace Yi.Furion.Core.Rbac.DataSeeds
|
||||
ParentId = monitoring.Id,
|
||||
IsDeleted = false
|
||||
};
|
||||
entities.Add(online);
|
||||
entities.Add(cache);
|
||||
|
||||
//服务监控
|
||||
MenuEntity server = new MenuEntity()
|
||||
@@ -108,7 +109,7 @@ namespace Yi.Furion.Core.Rbac.DataSeeds
|
||||
ParentId = monitoring.Id,
|
||||
IsDeleted = false
|
||||
};
|
||||
entities.Add(online);
|
||||
entities.Add(server);
|
||||
|
||||
|
||||
//系统工具
|
||||
@@ -1104,6 +1105,16 @@ namespace Yi.Furion.Core.Rbac.DataSeeds
|
||||
m.IsDeleted = false;
|
||||
m.State = true;
|
||||
});
|
||||
|
||||
var p = entities.GroupBy(x => x.Id);
|
||||
foreach (var k in p)
|
||||
{
|
||||
if (k.ToList().Count > 1)
|
||||
{
|
||||
Console.WriteLine("菜单id重复");
|
||||
}
|
||||
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Yi.Furion.Core.Rbac.Entities
|
||||
/// 负责人
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "Leader")]
|
||||
public string Leader { get; set; }
|
||||
public string? Leader { get; set; }
|
||||
/// <summary>
|
||||
/// 父级id
|
||||
///</summary>
|
||||
@@ -80,6 +80,6 @@ namespace Yi.Furion.Core.Rbac.Entities
|
||||
/// 描述
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "Remark")]
|
||||
public string Remark { get; set; }
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace Yi.Furion.Core.Rbac.Entities
|
||||
///
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "PermissionCode")]
|
||||
public string PermissionCode { get; set; }
|
||||
public string? PermissionCode { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
@@ -82,12 +82,12 @@ namespace Yi.Furion.Core.Rbac.Entities
|
||||
/// 菜单图标
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "MenuIcon")]
|
||||
public string MenuIcon { get; set; }
|
||||
public string? MenuIcon { get; set; }
|
||||
/// <summary>
|
||||
/// 菜单组件路由
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "Router")]
|
||||
public string Router { get; set; }
|
||||
public string? Router { get; set; }
|
||||
/// <summary>
|
||||
/// 是否为外部链接
|
||||
///</summary>
|
||||
@@ -108,17 +108,17 @@ namespace Yi.Furion.Core.Rbac.Entities
|
||||
/// 描述
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "Remark")]
|
||||
public string Remark { get; set; }
|
||||
public string? Remark { get; set; }
|
||||
/// <summary>
|
||||
/// 组件路径
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "Component")]
|
||||
public string Component { get; set; }
|
||||
public string? Component { get; set; }
|
||||
/// <summary>
|
||||
/// 路由参数
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "Query")]
|
||||
public string Query { get; set; }
|
||||
public string? Query { get; set; }
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public List<MenuEntity> Children { get; set; }
|
||||
|
||||
@@ -69,6 +69,6 @@ namespace Yi.Furion.Core.Rbac.Entities
|
||||
/// 描述
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "Remark")]
|
||||
public string Remark { get; set; }
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,28 +68,28 @@ namespace Yi.Furion.Core.Rbac.Entities
|
||||
/// <summary>
|
||||
/// 头像
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
public string? Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 昵称
|
||||
/// </summary>
|
||||
public string Nick { get; set; }
|
||||
public string? Nick { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 邮箱
|
||||
/// </summary>
|
||||
public string Email { get; set; }
|
||||
public string? Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ip
|
||||
/// </summary>
|
||||
public string Ip { get; set; }
|
||||
public string? Ip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地址
|
||||
/// </summary>
|
||||
|
||||
public string Address { get; set; }
|
||||
public string? Address { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 电话
|
||||
@@ -99,12 +99,12 @@ namespace Yi.Furion.Core.Rbac.Entities
|
||||
/// <summary>
|
||||
/// 简介
|
||||
/// </summary>
|
||||
public string Introduction { get; set; }
|
||||
public string? Introduction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
public string? Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 性别
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<NoWarn>1701;1702;1591</NoWarn>
|
||||
<DocumentationFile>Yi.Furion.Core.xml</DocumentationFile>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
|
||||
@@ -14,10 +14,12 @@ public class SingleFilePublish : ISingleFilePublish
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
"Yi.Furion.Rbac.Application",
|
||||
"Yi.Furion.Rbac.Core",
|
||||
"Yi.Furion.Rbac.EntityFramework.Core",
|
||||
"Yi.Furion.Rbac.Web.Core"
|
||||
"Yi.Framework.Infrastructure",
|
||||
"Yi.Framework.Module",
|
||||
"Yi.Furion.Application",
|
||||
"Yi.Furion.Core",
|
||||
"Yi.Furion.Sqlsugar.Core",
|
||||
"Yi.Furion.Core"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -30,9 +30,6 @@
|
||||
<None Update="ip2region.db">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="yi-sqlsugar-dev.db">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -42,6 +39,17 @@
|
||||
<Folder Include="wwwroot\Image\" />
|
||||
<Folder Include="wwwroot\Thumbnail\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Update="appsettings.Production.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties properties_4launchsettings_1json__JsonSchema="" />
|
||||
|
||||
@@ -19,20 +19,22 @@
|
||||
"DbType": "Sqlite",
|
||||
"EnabledReadWrite": false,
|
||||
"EnabledCodeFirst": false,
|
||||
"EntityAssembly": null,
|
||||
"ReadUrl": [
|
||||
"DataSource=[xxxx]", //Sqlite
|
||||
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]", //Mysql
|
||||
"Data Source=[xxxx];Initial Catalog=[xxxx];User ID=[xxxx];password=[xxxx]" //Sqlserver
|
||||
]
|
||||
},
|
||||
|
||||
"EnabledDataSeed": false,
|
||||
|
||||
"JWTSettings": {
|
||||
"ValidateIssuerSigningKey": true, // 是否验证密钥,bool 类型,默认true
|
||||
"IssuerSigningKey": "你的密钥", // 密钥,string 类型,必须是复杂密钥,长度大于16
|
||||
"IssuerSigningKey": "123456qwerty123456qwerty", // 密钥,string 类型,必须是复杂密钥,长度大于16
|
||||
"ValidateIssuer": true, // 是否验证签发方,bool 类型,默认true
|
||||
"ValidIssuer": "签发方", // 签发方,string 类型
|
||||
"ValidIssuer": "ccnetcore", // 签发方,string 类型
|
||||
"ValidateAudience": true, // 是否验证签收方,bool 类型,默认true
|
||||
"ValidAudience": "签收方", // 签收方,string 类型
|
||||
"ValidAudience": "ccnetcore", // 签收方,string 类型
|
||||
"ValidateLifetime": true, // 是否验证过期时间,bool 类型,默认true,建议true
|
||||
"ExpiredTime": 20, // 过期时间,long 类型,单位分钟,默认20分钟
|
||||
"ClockSkew": 5, // 过期时间容错值,long 类型,单位秒,默认 5秒
|
||||
@@ -46,6 +48,7 @@
|
||||
"TemplateCode": "",
|
||||
"EnableFeature": false
|
||||
},
|
||||
//redis缓存
|
||||
"CachingConnOptions": {
|
||||
"Host": "",
|
||||
"DB": "",
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user