commit 32cacd58d711478b3daa518f51719b95800934a5 Author: SummmerLost <1449109960@qq.com> Date: Fri Nov 11 10:23:50 2022 +0800 体检系统架构设计 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5fa7bab --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.csproj +bin/ +obj/ diff --git a/.vs/PEIS/DesignTimeBuild/.dtbcache.v2 b/.vs/PEIS/DesignTimeBuild/.dtbcache.v2 new file mode 100644 index 0000000..2c63a81 Binary files /dev/null and b/.vs/PEIS/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/PEIS/FileContentIndex/18f8b207-681a-46c7-b102-0d555eaac6c9.vsidx b/.vs/PEIS/FileContentIndex/18f8b207-681a-46c7-b102-0d555eaac6c9.vsidx new file mode 100644 index 0000000..51651b5 Binary files /dev/null and b/.vs/PEIS/FileContentIndex/18f8b207-681a-46c7-b102-0d555eaac6c9.vsidx differ diff --git a/.vs/PEIS/FileContentIndex/45cfb924-1f5b-4699-9ce3-01639a41461c.vsidx b/.vs/PEIS/FileContentIndex/45cfb924-1f5b-4699-9ce3-01639a41461c.vsidx new file mode 100644 index 0000000..9f2c3fb Binary files /dev/null and b/.vs/PEIS/FileContentIndex/45cfb924-1f5b-4699-9ce3-01639a41461c.vsidx differ diff --git a/.vs/PEIS/FileContentIndex/546d0b0f-54c2-4958-87c9-6686f02224b4.vsidx b/.vs/PEIS/FileContentIndex/546d0b0f-54c2-4958-87c9-6686f02224b4.vsidx new file mode 100644 index 0000000..1613692 Binary files /dev/null and b/.vs/PEIS/FileContentIndex/546d0b0f-54c2-4958-87c9-6686f02224b4.vsidx differ diff --git a/.vs/PEIS/FileContentIndex/ff0fe4f2-e687-4bef-be6b-2d8ed79a8e63.vsidx b/.vs/PEIS/FileContentIndex/ff0fe4f2-e687-4bef-be6b-2d8ed79a8e63.vsidx new file mode 100644 index 0000000..7a37925 Binary files /dev/null and b/.vs/PEIS/FileContentIndex/ff0fe4f2-e687-4bef-be6b-2d8ed79a8e63.vsidx differ diff --git a/.vs/PEIS/FileContentIndex/read.lock b/.vs/PEIS/FileContentIndex/read.lock new file mode 100644 index 0000000..e69de29 diff --git a/.vs/PEIS/v17/.suo b/.vs/PEIS/v17/.suo new file mode 100644 index 0000000..2f42103 Binary files /dev/null and b/.vs/PEIS/v17/.suo differ diff --git a/PEIS.Common b/PEIS.Common new file mode 160000 index 0000000..d276266 --- /dev/null +++ b/PEIS.Common @@ -0,0 +1 @@ +Subproject commit d276266da5d8f4b9bb4b5dc9e88ddd2e21c62f94 diff --git a/PEIS.EF/IService/ISampleService.cs b/PEIS.EF/IService/ISampleService.cs new file mode 100644 index 0000000..d957a2a --- /dev/null +++ b/PEIS.EF/IService/ISampleService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace PEIS.Service.IService +{ + interface ISampleService + { + + } + +} diff --git a/PEIS.EF/Service/SampleService.cs b/PEIS.EF/Service/SampleService.cs new file mode 100644 index 0000000..3a5ad78 --- /dev/null +++ b/PEIS.EF/Service/SampleService.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.EntityFrameworkCore; +using PEIS.Repositories; +using PEIS.Repositories.Models; +using PEIS.Service.IService; + +namespace PEIS.Service.Service +{ + public class SampleService:Repository,ISampleService + { + public SampleService(DbContext context) : base(context) + { + } + + + } +} diff --git a/PEIS.Interface/Program.cs b/PEIS.Interface/Program.cs new file mode 100644 index 0000000..9d55eb4 --- /dev/null +++ b/PEIS.Interface/Program.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using NLog.Web; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace PEIS.Interface +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).UseNLog().Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/PEIS.Interface/Properties/launchSettings.json b/PEIS.Interface/Properties/launchSettings.json new file mode 100644 index 0000000..2fdca48 --- /dev/null +++ b/PEIS.Interface/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:57770", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "PEIS.Interface": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/PEIS.Interface/Startup.cs b/PEIS.Interface/Startup.cs new file mode 100644 index 0000000..7be2eb6 --- /dev/null +++ b/PEIS.Interface/Startup.cs @@ -0,0 +1,167 @@ +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.IdentityModel.Tokens; +using Microsoft.OpenApi.Models; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Text; +using PEIS.Common.Helper.Encryption; +using PEIS.Common.Middleware; + +namespace PEIS.Interface +{ + public class Startup + { + + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + private readonly bool _swagger = AppSettingJsonHelper.GetSection("Swagger", "Using") == "true"; + public IConfiguration Configuration { get; } + + /// + /// Õâ¸ö·½·¨±»ÔËÐÐʱµ÷ÓᣠʹÓô˷½·¨ÏòÈÝÆ÷Ìí¼Ó·þÎñ + /// + /// + public void ConfigureServices(IServiceCollection services) + { + services.AddControllers(); + services.AddControllersWithViews() + .AddNewtonsoftJson(options => + options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore + ); + // swagger ÅäÖà + if (_swagger) + { + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "OutCollect", Version = "v1" }); + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + c.IncludeXmlComments(xmlPath, true); + + //Ìí¼ÓAuthorization + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + Description = "JWT Authorization header using the Bearer scheme.", + Name = "Authorization", + In = ParameterLocation.Header, + Scheme = "bearer", + Type = SecuritySchemeType.Http, + BearerFormat = "JWT" + }); + //°ÑËùÓз½·¨ÅäÖÃΪÔö¼ÓbearerÍ·²¿ÐÅÏ¢; + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "bearerAuth" + } + }, + new string[] {} + } + }); + + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } + }, + new List() + } + }); + }); + } + // jwt ÅäÖà + services.AddAuthentication(options => + { + // ÉèÖÃĬÈÏʹÓÃjwtÑéÖ¤·½Ê½ + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + }).AddJwtBearer(options => + { + var confSection = Configuration.GetSection("Authentication"); + options.TokenValidationParameters = new TokenValidationParameters() + { + // ÑéÖ¤½ÓÊÕÕß + ValidateAudience = true, + // ÑéÖ¤·¢²¼Õß //ÊÇ·ñÑéÖ¤·¢ÐÐÈË£¬¾ÍÊÇÑéÖ¤ÔØºÉÖеÄIssÊÇ·ñ¶ÔÓ¦ValidIssuer²ÎÊý + ValidateIssuer = true, + // ÑéÖ¤¹ýÆÚʱ¼ä//ÊÇ·ñÑéÖ¤¹ýÆÚʱ¼ä£¬¹ýÆÚÁ˾;ܾø·ÃÎÊ + ValidateLifetime = true, + // ÑéÖ¤ÃØÔ¿ //ÊÇ·ñÑé֤ǩÃû,²»ÑéÖ¤µÄ»­¿ÉÒÔ´Û¸ÄÊý¾Ý£¬²»°²È« + ValidateIssuerSigningKey = true, + // ¶ÁÅäÖÃIssuer//·¢ÐÐÈË + ValidIssuer = confSection["IsSure"], + // ¶ÁÅäÖÃAudience//¶©ÔÄÈË + ValidAudience = confSection["Audience"], + // ÉèÖÃÉú³ÉtokenµÄÃØÔ¿ //½âÃܵÄÃÜÔ¿ + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(confSection["SecurityKey"])) + }; + }); + + } + + + /// + /// ´Ë·½·¨ÓÉÔËÐÐʱµ÷ÓᣠʹÓô˷½·¨ÅäÖà HTTP ÇëÇó¹ÜµÀ + /// + /// + /// + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseExceptionHandler("/error"); + } + + if (_swagger) + { + app.UseSwagger(); + // Enable middleware to serve generated Swagger as a JSON endpoint. + app.UseSwagger(c => + { + c.SerializeAsV2 = true; + }); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "debug NetFL v1"); + }); + + } + + app.UseHttpsRedirection(); + app.UseRouting(); + + + // custom jwt auth middleware + app.UseMiddleware(); + // jwt + app.UseAuthentication(); + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/PEIS.Interface/appsettings.Development.json b/PEIS.Interface/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/PEIS.Interface/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/PEIS.Interface/appsettings.json b/PEIS.Interface/appsettings.json new file mode 100644 index 0000000..ce4ff7b --- /dev/null +++ b/PEIS.Interface/appsettings.json @@ -0,0 +1,18 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "Authentication": { + "IsSure": "OutCollect", + "Audience": "OutCollectColoud", + "SecurityKey": "4C6A8A8B-1B9F-12E7-60C4-123BC0BB5D25" + }, + "Swagger": { + "Using": "true" + } +} diff --git a/PEIS.Repositories/IRepository.cs b/PEIS.Repositories/IRepository.cs new file mode 100644 index 0000000..e724e5f --- /dev/null +++ b/PEIS.Repositories/IRepository.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; + +namespace PEIS.Repositories +{ + public interface IRepository where TEntity :class + { + TEntity Get(int id); + IEnumerable GetAll(); + IEnumerable Find(Expression> predicate); + void Add(TEntity entity); + void AddRange(IEnumerable entities); + + void Remove(TEntity entity); + void RemoveRange(IEnumerable entities); + } +} diff --git a/PEIS.Repositories/Models/Sample.cs b/PEIS.Repositories/Models/Sample.cs new file mode 100644 index 0000000..3bbbee4 --- /dev/null +++ b/PEIS.Repositories/Models/Sample.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace PEIS.Repositories.Models +{ + public class Sample + { + } +} diff --git a/PEIS.Repositories/Repository.cs b/PEIS.Repositories/Repository.cs new file mode 100644 index 0000000..3a8c905 --- /dev/null +++ b/PEIS.Repositories/Repository.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using Microsoft.EntityFrameworkCore; + +namespace PEIS.Repositories +{ + public class Repository :IRepository where TEntity:class + { + public readonly DbContext Context; + + public Repository(DbContext context) + { + Context = context; + } + + public TEntity Get(int id) + { + return Context.Set().Find(id); + } + + public IEnumerable GetAll() + { + return Context.Set().ToList(); + } + + public IEnumerable Find(Expression> predicate) + { + return Context.Set().Where(predicate); + } + + public void Add(TEntity entity) + { + Context.Set().Add(entity); + } + + public void AddRange(IEnumerable entities) + { + Context.Set().AddRange(entities); + } + + public void Remove(TEntity entity) + { + Context.Set().Remove(entity); + } + + public void RemoveRange(IEnumerable entities) + { + Context.Set().RemoveRange(entities); + } + } +} diff --git a/PEIS.sln b/PEIS.sln new file mode 100644 index 0000000..7fd0dcc --- /dev/null +++ b/PEIS.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32825.248 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PEIS.Cloud", "PEIS.Interface\PEIS.Cloud.csproj", "{4154E9CB-D701-49D0-92B5-EC2F8E055CD2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PEIS.Common", "PEIS.Common\PEIS.Common.csproj", "{13B248F1-75F7-4358-9579-CF51BCA6E75B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PEIS.Repositories", "PEIS.Repositories\PEIS.Repositories.csproj", "{84CA4853-1143-4DE3-8477-14BD7811EF90}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PEIS.Service", "PEIS.EF\PEIS.Service.csproj", "{70A000EA-EDB6-4719-8195-06E06384B336}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4154E9CB-D701-49D0-92B5-EC2F8E055CD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4154E9CB-D701-49D0-92B5-EC2F8E055CD2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4154E9CB-D701-49D0-92B5-EC2F8E055CD2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4154E9CB-D701-49D0-92B5-EC2F8E055CD2}.Release|Any CPU.Build.0 = Release|Any CPU + {13B248F1-75F7-4358-9579-CF51BCA6E75B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {13B248F1-75F7-4358-9579-CF51BCA6E75B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {13B248F1-75F7-4358-9579-CF51BCA6E75B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {13B248F1-75F7-4358-9579-CF51BCA6E75B}.Release|Any CPU.Build.0 = Release|Any CPU + {84CA4853-1143-4DE3-8477-14BD7811EF90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84CA4853-1143-4DE3-8477-14BD7811EF90}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84CA4853-1143-4DE3-8477-14BD7811EF90}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84CA4853-1143-4DE3-8477-14BD7811EF90}.Release|Any CPU.Build.0 = Release|Any CPU + {70A000EA-EDB6-4719-8195-06E06384B336}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {70A000EA-EDB6-4719-8195-06E06384B336}.Debug|Any CPU.Build.0 = Debug|Any CPU + {70A000EA-EDB6-4719-8195-06E06384B336}.Release|Any CPU.ActiveCfg = Release|Any CPU + {70A000EA-EDB6-4719-8195-06E06384B336}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3615424A-8F6D-4912-B462-23042E651E6E} + EndGlobalSection +EndGlobal