diff --git a/Yi.Furion.Net6/Yi.Framework.Infrastructure/Data/DataSeeds/DataSeedExtensions.cs b/Yi.Furion.Net6/Yi.Framework.Infrastructure/Data/DataSeeds/DataSeedExtensions.cs index a83a8155..292d1270 100644 --- a/Yi.Furion.Net6/Yi.Framework.Infrastructure/Data/DataSeeds/DataSeedExtensions.cs +++ b/Yi.Furion.Net6/Yi.Framework.Infrastructure/Data/DataSeeds/DataSeedExtensions.cs @@ -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(); + return builder; } } } diff --git a/Yi.Furion.Net6/Yi.Framework.Infrastructure/Sqlsugar/SqlsugarCodeFirstExtensions.cs b/Yi.Furion.Net6/Yi.Framework.Infrastructure/Sqlsugar/SqlsugarCodeFirstExtensions.cs new file mode 100644 index 00000000..20582d9f --- /dev/null +++ b/Yi.Furion.Net6/Yi.Framework.Infrastructure/Sqlsugar/SqlsugarCodeFirstExtensions.cs @@ -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(); + var options = app.ApplicationServices.GetRequiredService>(); + + if (options.Value.EnabledCodeFirst == false) return; + + db.DbMaintenance.CreateDatabase(); + var assemblys = new List(); + + //全盘加载 + 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 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);//这样一个表就能成功创建了 + } + } + } + } +} diff --git a/Yi.Furion.Net6/Yi.Framework.Infrastructure/Startup.cs b/Yi.Furion.Net6/Yi.Framework.Infrastructure/Startup.cs index b391068b..c5d439a9 100644 --- a/Yi.Furion.Net6/Yi.Framework.Infrastructure/Startup.cs +++ b/Yi.Furion.Net6/Yi.Framework.Infrastructure/Startup.cs @@ -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(); services.AddSingleton(); - services.AddControllers(options => { + services.AddControllers(options => + { options.Filters.Add(); }); } - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + public async void Configure(IApplicationBuilder app, IWebHostEnvironment env) { + app.UseSqlsugarCodeFirstServer(); + await app.UseDataSeedServer(); app.UseDataFiterServer(); + } } diff --git a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/DataSeeds/MenuDataSeed.cs b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/DataSeeds/MenuDataSeed.cs index 7ccbe18f..512650c2 100644 --- a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/DataSeeds/MenuDataSeed.cs +++ b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/DataSeeds/MenuDataSeed.cs @@ -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; } } diff --git a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/DeptEntity.cs b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/DeptEntity.cs index 3feaae8c..e593c928 100644 --- a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/DeptEntity.cs +++ b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/DeptEntity.cs @@ -69,7 +69,7 @@ namespace Yi.Furion.Core.Rbac.Entities /// 负责人 /// [SugarColumn(ColumnName = "Leader")] - public string Leader { get; set; } + public string? Leader { get; set; } /// /// 父级id /// @@ -80,6 +80,6 @@ namespace Yi.Furion.Core.Rbac.Entities /// 描述 /// [SugarColumn(ColumnName = "Remark")] - public string Remark { get; set; } + public string? Remark { get; set; } } } diff --git a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/MenuEntity.cs b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/MenuEntity.cs index de726a14..ba87a20c 100644 --- a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/MenuEntity.cs +++ b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/MenuEntity.cs @@ -71,7 +71,7 @@ namespace Yi.Furion.Core.Rbac.Entities /// /// [SugarColumn(ColumnName = "PermissionCode")] - public string PermissionCode { get; set; } + public string? PermissionCode { get; set; } /// /// /// @@ -82,12 +82,12 @@ namespace Yi.Furion.Core.Rbac.Entities /// 菜单图标 /// [SugarColumn(ColumnName = "MenuIcon")] - public string MenuIcon { get; set; } + public string? MenuIcon { get; set; } /// /// 菜单组件路由 /// [SugarColumn(ColumnName = "Router")] - public string Router { get; set; } + public string? Router { get; set; } /// /// 是否为外部链接 /// @@ -108,17 +108,17 @@ namespace Yi.Furion.Core.Rbac.Entities /// 描述 /// [SugarColumn(ColumnName = "Remark")] - public string Remark { get; set; } + public string? Remark { get; set; } /// /// 组件路径 /// [SugarColumn(ColumnName = "Component")] - public string Component { get; set; } + public string? Component { get; set; } /// /// 路由参数 /// [SugarColumn(ColumnName = "Query")] - public string Query { get; set; } + public string? Query { get; set; } [SugarColumn(IsIgnore = true)] public List Children { get; set; } diff --git a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/PostEntity.cs b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/PostEntity.cs index 5e2d5426..7e04e9a4 100644 --- a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/PostEntity.cs +++ b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/PostEntity.cs @@ -69,6 +69,6 @@ namespace Yi.Furion.Core.Rbac.Entities /// 描述 /// [SugarColumn(ColumnName = "Remark")] - public string Remark { get; set; } + public string? Remark { get; set; } } } diff --git a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/UserEntity.cs b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/UserEntity.cs index c7c7675a..fa40343a 100644 --- a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/UserEntity.cs +++ b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Entities/UserEntity.cs @@ -68,28 +68,28 @@ namespace Yi.Furion.Core.Rbac.Entities /// /// 头像 /// - public string Icon { get; set; } + public string? Icon { get; set; } /// /// 昵称 /// - public string Nick { get; set; } + public string? Nick { get; set; } /// /// 邮箱 /// - public string Email { get; set; } + public string? Email { get; set; } /// /// Ip /// - public string Ip { get; set; } + public string? Ip { get; set; } /// /// 地址 /// - public string Address { get; set; } + public string? Address { get; set; } /// /// 电话 @@ -99,12 +99,12 @@ namespace Yi.Furion.Core.Rbac.Entities /// /// 简介 /// - public string Introduction { get; set; } + public string? Introduction { get; set; } /// /// 备注 /// - public string Remark { get; set; } + public string? Remark { get; set; } /// /// 性别 diff --git a/Yi.Furion.Net6/Yi.Furion.Core/Yi.Furion.Core.csproj b/Yi.Furion.Net6/Yi.Furion.Core/Yi.Furion.Core.csproj index b40a0b65..8dc398d3 100644 --- a/Yi.Furion.Net6/Yi.Furion.Core/Yi.Furion.Core.csproj +++ b/Yi.Furion.Net6/Yi.Furion.Core/Yi.Furion.Core.csproj @@ -4,6 +4,7 @@ net6.0 1701;1702;1591 Yi.Furion.Core.xml + enable diff --git a/Yi.Furion.Net6/Yi.Furion.Web.Entry/SingleFilePublish.cs b/Yi.Furion.Net6/Yi.Furion.Web.Entry/SingleFilePublish.cs index e34ffe45..91494e2b 100644 --- a/Yi.Furion.Net6/Yi.Furion.Web.Entry/SingleFilePublish.cs +++ b/Yi.Furion.Net6/Yi.Furion.Web.Entry/SingleFilePublish.cs @@ -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" }; } } \ No newline at end of file diff --git a/Yi.Furion.Net6/Yi.Furion.Web.Entry/Yi.Furion.Web.Entry.csproj b/Yi.Furion.Net6/Yi.Furion.Web.Entry/Yi.Furion.Web.Entry.csproj index de877f78..5207c039 100644 --- a/Yi.Furion.Net6/Yi.Furion.Web.Entry/Yi.Furion.Web.Entry.csproj +++ b/Yi.Furion.Net6/Yi.Furion.Web.Entry/Yi.Furion.Web.Entry.csproj @@ -30,9 +30,6 @@ Always - - Always - @@ -42,6 +39,17 @@ + + + + + + Always + + + Always + + diff --git a/Yi.Furion.Net6/Yi.Furion.Web.Entry/appsettings.json b/Yi.Furion.Net6/Yi.Furion.Web.Entry/appsettings.json index 7514d8c2..62fe5d64 100644 --- a/Yi.Furion.Net6/Yi.Furion.Web.Entry/appsettings.json +++ b/Yi.Furion.Net6/Yi.Furion.Web.Entry/appsettings.json @@ -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": "", diff --git a/Yi.Furion.Net6/Yi.Furion.Web.Entry/yi-sqlsugar-dev.db b/Yi.Furion.Net6/Yi.Furion.Web.Entry/yi-sqlsugar-dev.db index e69de29b..5917a2f8 100644 Binary files a/Yi.Furion.Net6/Yi.Furion.Web.Entry/yi-sqlsugar-dev.db and b/Yi.Furion.Net6/Yi.Furion.Web.Entry/yi-sqlsugar-dev.db differ