From c10388b5f24f4304a288031488977da0d4f19448 Mon Sep 17 00:00:00 2001 From: ky_xiaz <574434302@qq.com> Date: Wed, 12 May 2021 17:28:23 +0800 Subject: [PATCH] =?UTF-8?q?Update=20Ras=20=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Api/Ewide.Application/Ewide.Application.xml | 6 - .../HouseProjectInfoService.cs | 46 -------- Api/Ewide.Core/Entity/SysEmpExtOrgPos.cs | 24 ++-- Api/Ewide.Core/Ewide.Core.xml | 111 ++++++++++++++++-- Api/Ewide.Core/Service/Auth/AuthService.cs | 6 +- Api/Ewide.Core/Util/RSAHandler.cs | 97 +++++++++++++++ .../DbContexts/DefaultDbContext.cs | 5 +- .../dbsettings.Development.json | 6 + Api/Ewide.Web.Core/Ewide.Web.Core.xml | 6 + Api/Ewide.Web.Core/Service/DBqueryService.cs | 67 +++++++++++ 10 files changed, 296 insertions(+), 78 deletions(-) create mode 100644 Api/Ewide.Core/Util/RSAHandler.cs create mode 100644 Api/Ewide.EntityFramework.Core/dbsettings.Development.json create mode 100644 Api/Ewide.Web.Core/Service/DBqueryService.cs diff --git a/Api/Ewide.Application/Ewide.Application.xml b/Api/Ewide.Application/Ewide.Application.xml index 46d1c55..4a7d351 100644 --- a/Api/Ewide.Application/Ewide.Application.xml +++ b/Api/Ewide.Application/Ewide.Application.xml @@ -4,12 +4,6 @@ Ewide.Application - - - 读取数据库的所有表 并拿到数据 - - - 项目管理相关服务 diff --git a/Api/Ewide.Application/Service/HouseProjectInfo/HouseProjectInfoService.cs b/Api/Ewide.Application/Service/HouseProjectInfo/HouseProjectInfoService.cs index a94956c..a8be890 100644 --- a/Api/Ewide.Application/Service/HouseProjectInfo/HouseProjectInfoService.cs +++ b/Api/Ewide.Application/Service/HouseProjectInfo/HouseProjectInfoService.cs @@ -28,52 +28,6 @@ using System.Threading.Tasks; namespace Ewide.Application.Service.HouseProjectInfo { - [ApiDescriptionSettings(Name = "xml", Order = 3)] - public class XMLHandler : IDynamicApiController, ITransient - { - private readonly DefaultDbContext _db; - - public XMLHandler(DefaultDbContext db) - { - _db = db; - } - [HttpGet("/xml/detail")] - public async Task XMLDoneAsync() - { - XmlSerializerUtil xmlHandler = new XmlSerializerUtil(); - xmlHandler.WriteDataSeed(); - //拿到数据保存到 XML文件 - //Dictionary dicDataBase = await GetDataBase(); - //foreach (KeyValuePair item in dicDataBase) - //{ - // xmlHandler.WriteXML(item.Value.GetType(), item.Value, item.Key); - //} - } - /// - /// 读取数据库的所有表 并拿到数据 - /// - /// - private async Task> GetDataBase() - { - Dictionary dicDataBase = new Dictionary(); - var defaultConnection = App.Configuration["ConnectionStrings:DefaultConnection"]; - //获取 所有继承 IEntity 接口的表 - IEnumerable entityTypedb = _db.Model.GetEntityTypes().Where(x => typeof(IEntity).IsAssignableFrom(x.ClrType)).ToList(); - - foreach (IEntityType item in entityTypedb) - { - MethodInfo mi = _db.GetType().GetMethods().FirstOrDefault(s => s.Name == "Set"); - MethodInfo miConstructed = mi.MakeGenericMethod(item.ClrType); - object objList = miConstructed.Invoke(_db, null); - var objsource = item.ClrType.MakeList(objList); - dicDataBase.Add(item.ClrType.Name, objsource); - } - await _db.Database.CloseConnectionAsync(); - return dicDataBase; - } - } - - /// /// 项目管理相关服务 /// diff --git a/Api/Ewide.Core/Entity/SysEmpExtOrgPos.cs b/Api/Ewide.Core/Entity/SysEmpExtOrgPos.cs index 8cb388a..a5bed99 100644 --- a/Api/Ewide.Core/Entity/SysEmpExtOrgPos.cs +++ b/Api/Ewide.Core/Entity/SysEmpExtOrgPos.cs @@ -13,7 +13,7 @@ namespace Ewide.Core /// [Table("sys_emp_ext_org_pos")] [Comment("员工附属机构职位表")] - public class SysEmpExtOrgPos : IEntity, IEntityTypeBuilder, IEntitySeedData + public class SysEmpExtOrgPos : IEntity, IEntityTypeBuilder { /// /// 员工Id @@ -59,16 +59,16 @@ namespace Ewide.Core entityBuilder.HasKey(c => new { c.SysEmpId, c.SysOrgId, c.SysPosId }); } - public IEnumerable HasData(DbContext dbContext, Type dbContextLocator) - { - return new[] - { - new SysEmpExtOrgPos { SysEmpId = "d0ead3dc-5096-4e15-bc6d-f640be5301ec", SysOrgId = "12d888de-f55d-4c88-b0a0-7c3510664d97", SysPosId = "269236c4-d74e-4e54-9d50-f6f61580a197" }, - new SysEmpExtOrgPos { SysEmpId = "d0ead3dc-5096-4e15-bc6d-f640be5301ec", SysOrgId = "8a2271d6-5bda-4544-bdd3-27e53a8b418e", SysPosId = "46c68a62-f119-4ff7-b621-0bbd77504538" }, - new SysEmpExtOrgPos { SysEmpId = "d0ead3dc-5096-4e15-bc6d-f640be5301ec", SysOrgId = "127c0a5d-43ac-4370-b313-082361885aca", SysPosId = "5bd8c466-2bca-4386-a551-daac78e3cee8" }, - new SysEmpExtOrgPos { SysEmpId = "d0ead3dc-5096-4e15-bc6d-f640be5301ec", SysOrgId = "f236ab2d-e1b5-4e9d-844f-a59ec32c20e4", SysPosId = "d89a3afe-e6ba-4018-bdae-3c98bb47ad66" }, - new SysEmpExtOrgPos { SysEmpId = "16a74726-e156-499f-9942-0e0e24ad0c3f", SysOrgId = "f236ab2d-e1b5-4e9d-844f-a59ec32c20e4", SysPosId = "269236c4-d74e-4e54-9d50-f6f61580a197" } - }; - } + //public IEnumerable HasData(DbContext dbContext, Type dbContextLocator) + //{ + // return new[] + // { + // new SysEmpExtOrgPos { SysEmpId = "d0ead3dc-5096-4e15-bc6d-f640be5301ec", SysOrgId = "12d888de-f55d-4c88-b0a0-7c3510664d97", SysPosId = "269236c4-d74e-4e54-9d50-f6f61580a197" }, + // new SysEmpExtOrgPos { SysEmpId = "d0ead3dc-5096-4e15-bc6d-f640be5301ec", SysOrgId = "8a2271d6-5bda-4544-bdd3-27e53a8b418e", SysPosId = "46c68a62-f119-4ff7-b621-0bbd77504538" }, + // new SysEmpExtOrgPos { SysEmpId = "d0ead3dc-5096-4e15-bc6d-f640be5301ec", SysOrgId = "127c0a5d-43ac-4370-b313-082361885aca", SysPosId = "5bd8c466-2bca-4386-a551-daac78e3cee8" }, + // new SysEmpExtOrgPos { SysEmpId = "d0ead3dc-5096-4e15-bc6d-f640be5301ec", SysOrgId = "f236ab2d-e1b5-4e9d-844f-a59ec32c20e4", SysPosId = "d89a3afe-e6ba-4018-bdae-3c98bb47ad66" }, + // new SysEmpExtOrgPos { SysEmpId = "16a74726-e156-499f-9942-0e0e24ad0c3f", SysOrgId = "f236ab2d-e1b5-4e9d-844f-a59ec32c20e4", SysPosId = "269236c4-d74e-4e54-9d50-f6f61580a197" } + // }; + //} } } diff --git a/Api/Ewide.Core/Ewide.Core.xml b/Api/Ewide.Core/Ewide.Core.xml index ee9bdb5..01ad01d 100644 --- a/Api/Ewide.Core/Ewide.Core.xml +++ b/Api/Ewide.Core/Ewide.Core.xml @@ -7018,6 +7018,109 @@ + + + 生成公私钥 + + + + + + + 创建公钥文件 + + + + + + + 创建私钥文件 + + + + + + + RSA加密 + + + + + + + RSA解密 + + + + + + + + + + XML 要读取的路径 + + + + + 当前程序集 + + + + + 读取文件夹下所有XML + add-migration init -c defaultDbContext 备用数据 + + + + + + 反序列化 + + + XML内容 + + + + + 数据流读取 + + + + + + + 反射 根据类名 反射整个类 得到实例 + + + + + + + 写入XML到磁盘 + + 类型 + 数据 + XML名称 + + + + 要操作的文件夹目录 + + + + + + 根据类名 创建一个XML文件 写入数据 + + + + + + + 写入种子数据 --不常用 + + 树基类 @@ -7067,13 +7170,5 @@ - - - 写入XML到磁盘 - - 类型 - 数据 - XML名称 - diff --git a/Api/Ewide.Core/Service/Auth/AuthService.cs b/Api/Ewide.Core/Service/Auth/AuthService.cs index 0ff2a2c..b9b3773 100644 --- a/Api/Ewide.Core/Service/Auth/AuthService.cs +++ b/Api/Ewide.Core/Service/Auth/AuthService.cs @@ -1,4 +1,5 @@ -using Furion; +using Ewide.Core.Util; +using Furion; using Furion.DatabaseAccessor; using Furion.DatabaseAccessor.Extensions; using Furion.DataEncryption; @@ -69,8 +70,9 @@ namespace Ewide.Core.Service [AllowAnonymous] public async Task LoginAsync([Required] LoginInput input) { + string pwd = RSAHandler.RSADecrypt(input.Password); // 获取加密后的密码 - var encryptPasswod = MD5Encryption.Encrypt(input.Password); + var encryptPasswod = MD5Encryption.Encrypt(pwd); // 判断用户名和密码是否正确 var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Account.Equals(input.Account) && u.Password.Equals(encryptPasswod)); diff --git a/Api/Ewide.Core/Util/RSAHandler.cs b/Api/Ewide.Core/Util/RSAHandler.cs new file mode 100644 index 0000000..c443491 --- /dev/null +++ b/Api/Ewide.Core/Util/RSAHandler.cs @@ -0,0 +1,97 @@ +using Furion.FriendlyException; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace Ewide.Core.Util +{ + public static class RSAHandler + { + + /// + /// 生成公私钥 + /// + /// + /// + public static void RSAKey(string PrivateKeyPath, string PublicKeyPath) + { + RSACryptoServiceProvider provider = new RSACryptoServiceProvider(); + CreatePrivateKeyXML(PrivateKeyPath, provider.ToXmlString(true)); + CreatePublicKeyXML(PublicKeyPath, provider.ToXmlString(false)); + } + /// + /// 创建公钥文件 + /// + /// + /// + public static void CreatePublicKeyXML(string path, string publickey) + { + using (FileStream publickeyxml = new FileStream(path, FileMode.Create)) + { + using (StreamWriter sw = new StreamWriter(publickeyxml)) + { + sw.WriteLine(publickey); + } + } + } + + /// + /// 创建私钥文件 + /// + /// + /// + public static void CreatePrivateKeyXML(string path, string privatekey) + { + using (FileStream privatekeyxml = new FileStream(path, FileMode.Create)) + { + using (StreamWriter sw = new StreamWriter(privatekeyxml)) + { + sw.WriteLine(privatekey); + } + } + } + + /// + /// RSA加密 + /// + /// + /// + public static string RSAEncrypt(string content) + { + string publickey = @"tu98wMoo297l+juulU4a3Xx7c2SZ93f0gTPKohE0uz4o8jWN8zXnAAfhf6MMTlkgf+qIwaORLtBQohDcX6Xp02Qe7Cq2LujVR+YJHxy2uo8+KTc5Rj/d0OkTjeCozGaJQH0XrwUO7w+rDnyXzA52IvMZPnUV3KnOj1mPH0IhrOU=AQAB"; + + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); + byte[] cipherbytes; + rsa.FromXmlString(publickey); + cipherbytes = rsa.Encrypt(Encoding.UTF8.GetBytes(content), false); + return Convert.ToBase64String(cipherbytes); + } + + /// + /// RSA解密 + /// + /// + /// + public static string RSADecrypt(string content) + { + string privatekey = @"tu98wMoo297l+juulU4a3Xx7c2SZ93f0gTPKohE0uz4o8jWN8zXnAAfhf6MMTlkgf+qIwaORLtBQohDcX6Xp02Qe7Cq2LujVR+YJHxy2uo8+KTc5Rj/d0OkTjeCozGaJQH0XrwUO7w+rDnyXzA52IvMZPnUV3KnOj1mPH0IhrOU=AQAB

7yKLJO9dobe7pNW3ob+Vse8kvlA+PObDrZNqFxUTLyXoAeHDnwz3BjJ2EVUPNJHV5F1/KPLTvADIjDrdB1qcbw==

w9ZK0SHBddtE91skFFS72YDmxzmXumSuUyREStVul9ke0oU2HjcZA915bmR0Zrh1RzO3y1w9zXVn+GdZGjyd6w==ncA67E2fhcwv0+hMcD5zYOLyaT2EISbWFQ43ISz879BgwcUOCEFEP+lP69Uh57sAz9pBxWCS/uXBZoh6QJysrw==vbC8F4YS1g3l55Koh+jra+qnnyHyDeGn2XCvlazWys7MRC40FWBZIp1MGdnDxhu1vZoi1SAr3O90HfA9JmTAsQ==00v2vMCcgXy78eMby7R6zfZzacVnVFO2WeyxYF7pjrXYYP+C4JSJkWpy6JGLWbgZrK8HAuRguJmdRi8K2KiYWg==rV3nb9nmwQDMGMrI2GyN30uivygfFj0TdgK8Tb1aqPzu1yRT46M4yXmuhkTiW7nxp+iANGssIx5+3Ch4gRj+r6BgBPldWNErK95a2v2Ae1+EzfVf21ybguBYeUVnV9c8qwoodZSVOajZapOgoS6s5TEOxHWRcF22AiFuaD1Tl90=
"; + + RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); + byte[] cipherbytes; + try + { //很有可能是报文被修改 情况很小 + rsa.FromXmlString(privatekey); + cipherbytes = rsa.Decrypt(Convert.FromBase64String(content), false); + return Encoding.UTF8.GetString(cipherbytes); + } + catch + { + throw Oops.Oh(ErrorCode.D1000); + } + } + } +} diff --git a/Api/Ewide.EntityFramework.Core/DbContexts/DefaultDbContext.cs b/Api/Ewide.EntityFramework.Core/DbContexts/DefaultDbContext.cs index e7b4403..ff319ea 100644 --- a/Api/Ewide.EntityFramework.Core/DbContexts/DefaultDbContext.cs +++ b/Api/Ewide.EntityFramework.Core/DbContexts/DefaultDbContext.cs @@ -179,10 +179,7 @@ namespace Ewide.EntityFramework.Core data.Add(obj); } } - if (data.Count>0) - { - modelBuilder.Entity(item.Key).HasData(data); - } + modelBuilder.Entity(item.Key).HasData(data); } } } diff --git a/Api/Ewide.EntityFramework.Core/dbsettings.Development.json b/Api/Ewide.EntityFramework.Core/dbsettings.Development.json new file mode 100644 index 0000000..efb30cd --- /dev/null +++ b/Api/Ewide.EntityFramework.Core/dbsettings.Development.json @@ -0,0 +1,6 @@ +{ + "ConnectionStrings": { + //"DefaultConnection": "Data Source=./Ewide.db", + "DefaultConnection": "Data Source=localhost;Database=ewide;User ID=root;Password=root;pooling=true;port=3306;sslmode=none;CharSet=utf8;" + } +} \ No newline at end of file diff --git a/Api/Ewide.Web.Core/Ewide.Web.Core.xml b/Api/Ewide.Web.Core/Ewide.Web.Core.xml index fef9f8d..4fcd31e 100644 --- a/Api/Ewide.Web.Core/Ewide.Web.Core.xml +++ b/Api/Ewide.Web.Core/Ewide.Web.Core.xml @@ -26,5 +26,11 @@ + + + 读取数据库的所有表 并拿到数据 + + + diff --git a/Api/Ewide.Web.Core/Service/DBqueryService.cs b/Api/Ewide.Web.Core/Service/DBqueryService.cs new file mode 100644 index 0000000..19c255d --- /dev/null +++ b/Api/Ewide.Web.Core/Service/DBqueryService.cs @@ -0,0 +1,67 @@ +using Ewide.Core.Util; +using Ewide.EntityFramework.Core; +using Furion; +using Furion.DatabaseAccessor; +using Furion.DependencyInjection; +using Furion.DynamicApiController; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Ewide.Web.Core.Service +{ + [ApiDescriptionSettings(Name = "DBHandler", Order = 3)] + public class DBqueryService : IDynamicApiController, ITransient + { + private readonly DefaultDbContext _db; + + public DBqueryService(DefaultDbContext db) + { + _db = db; + } + [HttpGet("/DBreader/detail")] + [AllowAnonymous] + public async Task XMLDoneAsync() + { +#if DEBUG + XmlSerializerUtil xmlHandler = new XmlSerializerUtil(); + xmlHandler.WriteDataSeed(); + //拿到数据保存到 XML文件 + Dictionary dicDataBase = await GetDataBase(); + foreach (KeyValuePair item in dicDataBase) + { + xmlHandler.WriteXML(item.Value.GetType(), item.Value, item.Key); + } +#endif + } + /// + /// 读取数据库的所有表 并拿到数据 + /// + /// + private async Task> GetDataBase() + { + Dictionary dicDataBase = new Dictionary(); + var defaultConnection = App.Configuration["ConnectionStrings:DefaultConnection"]; + //获取 所有继承 IEntity 接口的表 + IEnumerable entityTypedb = _db.Model.GetEntityTypes().Where(x => typeof(IEntity).IsAssignableFrom(x.ClrType)).ToList(); + + foreach (IEntityType item in entityTypedb) + { + MethodInfo mi = _db.GetType().GetMethods().FirstOrDefault(s => s.Name == "Set"); + MethodInfo miConstructed = mi.MakeGenericMethod(item.ClrType); + object objList = miConstructed.Invoke(_db, null); + var objsource = item.ClrType.MakeList(objList); + dicDataBase.Add(item.ClrType.Name, objsource); + } + await _db.Database.CloseConnectionAsync(); + return dicDataBase; + } + } +}