feat:完成codefirst与种子数据,发现非空类型问题,等待紧急修复
This commit is contained in:
@@ -26,23 +26,23 @@ namespace Yi.Framework.Infrastructure.Data.DataSeeds
|
|||||||
{
|
{
|
||||||
//using (var uow = iUnitOfWorkManager.CreateContext())
|
//using (var uow = iUnitOfWorkManager.CreateContext())
|
||||||
//{
|
//{
|
||||||
var res = await iUnitOfWorkManager.Ado.UseTranAsync(async () =>
|
//var res = await iUnitOfWorkManager.Ado.UseTranAsync(async () =>
|
||||||
{
|
// {
|
||||||
foreach (var seed in dataSeeds)
|
foreach (var seed in dataSeeds)
|
||||||
{
|
{
|
||||||
await seed.InvokerAsync();
|
await seed.InvokerAsync();
|
||||||
}
|
}
|
||||||
});
|
//});
|
||||||
|
|
||||||
//var res = uow.Commit();
|
//var res = uow.Commit();
|
||||||
|
|
||||||
if (!res.IsSuccess)
|
//if (!res.IsSuccess)
|
||||||
{
|
//{
|
||||||
throw new ApplicationException("种子数据初始化异常");
|
//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.AspNetCore;
|
||||||
using Yi.Framework.Infrastructure.Auth;
|
using Yi.Framework.Infrastructure.Auth;
|
||||||
using Yi.Framework.Infrastructure.Data;
|
using Yi.Framework.Infrastructure.Data;
|
||||||
|
using Yi.Framework.Infrastructure.Data.DataSeeds;
|
||||||
using Yi.Framework.Infrastructure.Data.Filters;
|
using Yi.Framework.Infrastructure.Data.Filters;
|
||||||
using Yi.Framework.Infrastructure.Sqlsugar;
|
using Yi.Framework.Infrastructure.Sqlsugar;
|
||||||
using Yi.Framework.Infrastructure.Sqlsugar.Filters;
|
using Yi.Framework.Infrastructure.Sqlsugar.Filters;
|
||||||
@@ -31,13 +32,17 @@ public class Startup : AppStartup
|
|||||||
|
|
||||||
services.AddSingleton<IPermissionHandler, DefaultPermissionHandler>();
|
services.AddSingleton<IPermissionHandler, DefaultPermissionHandler>();
|
||||||
services.AddSingleton<PermissionGlobalAttribute>();
|
services.AddSingleton<PermissionGlobalAttribute>();
|
||||||
services.AddControllers(options => {
|
services.AddControllers(options =>
|
||||||
|
{
|
||||||
options.Filters.Add<PermissionGlobalAttribute>();
|
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();
|
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.Data.DataSeeds;
|
||||||
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
using Yi.Framework.Infrastructure.Ddd.Repositories;
|
||||||
using Yi.Framework.Infrastructure.Helper;
|
using Yi.Framework.Infrastructure.Helper;
|
||||||
@@ -89,7 +90,7 @@ namespace Yi.Furion.Core.Rbac.DataSeeds
|
|||||||
ParentId = monitoring.Id,
|
ParentId = monitoring.Id,
|
||||||
IsDeleted = false
|
IsDeleted = false
|
||||||
};
|
};
|
||||||
entities.Add(online);
|
entities.Add(cache);
|
||||||
|
|
||||||
//服务监控
|
//服务监控
|
||||||
MenuEntity server = new MenuEntity()
|
MenuEntity server = new MenuEntity()
|
||||||
@@ -108,7 +109,7 @@ namespace Yi.Furion.Core.Rbac.DataSeeds
|
|||||||
ParentId = monitoring.Id,
|
ParentId = monitoring.Id,
|
||||||
IsDeleted = false
|
IsDeleted = false
|
||||||
};
|
};
|
||||||
entities.Add(online);
|
entities.Add(server);
|
||||||
|
|
||||||
|
|
||||||
//系统工具
|
//系统工具
|
||||||
@@ -1104,6 +1105,16 @@ namespace Yi.Furion.Core.Rbac.DataSeeds
|
|||||||
m.IsDeleted = false;
|
m.IsDeleted = false;
|
||||||
m.State = true;
|
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;
|
return entities;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace Yi.Furion.Core.Rbac.Entities
|
|||||||
/// 负责人
|
/// 负责人
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "Leader")]
|
[SugarColumn(ColumnName = "Leader")]
|
||||||
public string Leader { get; set; }
|
public string? Leader { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 父级id
|
/// 父级id
|
||||||
///</summary>
|
///</summary>
|
||||||
@@ -80,6 +80,6 @@ namespace Yi.Furion.Core.Rbac.Entities
|
|||||||
/// 描述
|
/// 描述
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "Remark")]
|
[SugarColumn(ColumnName = "Remark")]
|
||||||
public string Remark { get; set; }
|
public string? Remark { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace Yi.Furion.Core.Rbac.Entities
|
|||||||
///
|
///
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "PermissionCode")]
|
[SugarColumn(ColumnName = "PermissionCode")]
|
||||||
public string PermissionCode { get; set; }
|
public string? PermissionCode { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
///</summary>
|
///</summary>
|
||||||
@@ -82,12 +82,12 @@ namespace Yi.Furion.Core.Rbac.Entities
|
|||||||
/// 菜单图标
|
/// 菜单图标
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "MenuIcon")]
|
[SugarColumn(ColumnName = "MenuIcon")]
|
||||||
public string MenuIcon { get; set; }
|
public string? MenuIcon { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 菜单组件路由
|
/// 菜单组件路由
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "Router")]
|
[SugarColumn(ColumnName = "Router")]
|
||||||
public string Router { get; set; }
|
public string? Router { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否为外部链接
|
/// 是否为外部链接
|
||||||
///</summary>
|
///</summary>
|
||||||
@@ -108,17 +108,17 @@ namespace Yi.Furion.Core.Rbac.Entities
|
|||||||
/// 描述
|
/// 描述
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "Remark")]
|
[SugarColumn(ColumnName = "Remark")]
|
||||||
public string Remark { get; set; }
|
public string? Remark { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 组件路径
|
/// 组件路径
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "Component")]
|
[SugarColumn(ColumnName = "Component")]
|
||||||
public string Component { get; set; }
|
public string? Component { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 路由参数
|
/// 路由参数
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "Query")]
|
[SugarColumn(ColumnName = "Query")]
|
||||||
public string Query { get; set; }
|
public string? Query { get; set; }
|
||||||
|
|
||||||
[SugarColumn(IsIgnore = true)]
|
[SugarColumn(IsIgnore = true)]
|
||||||
public List<MenuEntity> Children { get; set; }
|
public List<MenuEntity> Children { get; set; }
|
||||||
|
|||||||
@@ -69,6 +69,6 @@ namespace Yi.Furion.Core.Rbac.Entities
|
|||||||
/// 描述
|
/// 描述
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "Remark")]
|
[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>
|
||||||
/// 头像
|
/// 头像
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Icon { get; set; }
|
public string? Icon { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 昵称
|
/// 昵称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Nick { get; set; }
|
public string? Nick { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 邮箱
|
/// 邮箱
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Email { get; set; }
|
public string? Email { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ip
|
/// Ip
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Ip { get; set; }
|
public string? Ip { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 地址
|
/// 地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
public string Address { get; set; }
|
public string? Address { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 电话
|
/// 电话
|
||||||
@@ -99,12 +99,12 @@ namespace Yi.Furion.Core.Rbac.Entities
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 简介
|
/// 简介
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Introduction { get; set; }
|
public string? Introduction { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备注
|
/// 备注
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Remark { get; set; }
|
public string? Remark { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 性别
|
/// 性别
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<NoWarn>1701;1702;1591</NoWarn>
|
<NoWarn>1701;1702;1591</NoWarn>
|
||||||
<DocumentationFile>Yi.Furion.Core.xml</DocumentationFile>
|
<DocumentationFile>Yi.Furion.Core.xml</DocumentationFile>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ public class SingleFilePublish : ISingleFilePublish
|
|||||||
{
|
{
|
||||||
return new[]
|
return new[]
|
||||||
{
|
{
|
||||||
"Yi.Furion.Rbac.Application",
|
"Yi.Framework.Infrastructure",
|
||||||
"Yi.Furion.Rbac.Core",
|
"Yi.Framework.Module",
|
||||||
"Yi.Furion.Rbac.EntityFramework.Core",
|
"Yi.Furion.Application",
|
||||||
"Yi.Furion.Rbac.Web.Core"
|
"Yi.Furion.Core",
|
||||||
|
"Yi.Furion.Sqlsugar.Core",
|
||||||
|
"Yi.Furion.Core"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,9 +30,6 @@
|
|||||||
<None Update="ip2region.db">
|
<None Update="ip2region.db">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="yi-sqlsugar-dev.db">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
@@ -42,6 +39,17 @@
|
|||||||
<Folder Include="wwwroot\Image\" />
|
<Folder Include="wwwroot\Image\" />
|
||||||
<Folder Include="wwwroot\Thumbnail\" />
|
<Folder Include="wwwroot\Thumbnail\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Update="appsettings.Development.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Update="appsettings.Production.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
<VisualStudio>
|
<VisualStudio>
|
||||||
<UserProperties properties_4launchsettings_1json__JsonSchema="" />
|
<UserProperties properties_4launchsettings_1json__JsonSchema="" />
|
||||||
|
|||||||
@@ -19,20 +19,22 @@
|
|||||||
"DbType": "Sqlite",
|
"DbType": "Sqlite",
|
||||||
"EnabledReadWrite": false,
|
"EnabledReadWrite": false,
|
||||||
"EnabledCodeFirst": false,
|
"EnabledCodeFirst": false,
|
||||||
"EntityAssembly": null,
|
|
||||||
"ReadUrl": [
|
"ReadUrl": [
|
||||||
"DataSource=[xxxx]", //Sqlite
|
"DataSource=[xxxx]", //Sqlite
|
||||||
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]", //Mysql
|
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]", //Mysql
|
||||||
"Data Source=[xxxx];Initial Catalog=[xxxx];User ID=[xxxx];password=[xxxx]" //Sqlserver
|
"Data Source=[xxxx];Initial Catalog=[xxxx];User ID=[xxxx];password=[xxxx]" //Sqlserver
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"EnabledDataSeed": false,
|
||||||
|
|
||||||
"JWTSettings": {
|
"JWTSettings": {
|
||||||
"ValidateIssuerSigningKey": true, // 是否验证密钥,bool 类型,默认true
|
"ValidateIssuerSigningKey": true, // 是否验证密钥,bool 类型,默认true
|
||||||
"IssuerSigningKey": "你的密钥", // 密钥,string 类型,必须是复杂密钥,长度大于16
|
"IssuerSigningKey": "123456qwerty123456qwerty", // 密钥,string 类型,必须是复杂密钥,长度大于16
|
||||||
"ValidateIssuer": true, // 是否验证签发方,bool 类型,默认true
|
"ValidateIssuer": true, // 是否验证签发方,bool 类型,默认true
|
||||||
"ValidIssuer": "签发方", // 签发方,string 类型
|
"ValidIssuer": "ccnetcore", // 签发方,string 类型
|
||||||
"ValidateAudience": true, // 是否验证签收方,bool 类型,默认true
|
"ValidateAudience": true, // 是否验证签收方,bool 类型,默认true
|
||||||
"ValidAudience": "签收方", // 签收方,string 类型
|
"ValidAudience": "ccnetcore", // 签收方,string 类型
|
||||||
"ValidateLifetime": true, // 是否验证过期时间,bool 类型,默认true,建议true
|
"ValidateLifetime": true, // 是否验证过期时间,bool 类型,默认true,建议true
|
||||||
"ExpiredTime": 20, // 过期时间,long 类型,单位分钟,默认20分钟
|
"ExpiredTime": 20, // 过期时间,long 类型,单位分钟,默认20分钟
|
||||||
"ClockSkew": 5, // 过期时间容错值,long 类型,单位秒,默认 5秒
|
"ClockSkew": 5, // 过期时间容错值,long 类型,单位秒,默认 5秒
|
||||||
@@ -46,6 +48,7 @@
|
|||||||
"TemplateCode": "",
|
"TemplateCode": "",
|
||||||
"EnableFeature": false
|
"EnableFeature": false
|
||||||
},
|
},
|
||||||
|
//redis缓存
|
||||||
"CachingConnOptions": {
|
"CachingConnOptions": {
|
||||||
"Host": "",
|
"Host": "",
|
||||||
"DB": "",
|
"DB": "",
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user