郑州市第一人民医院

Startup.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.DependencyInjection;
  9. using Microsoft.Extensions.Logging;
  10. using Microsoft.Extensions.Options;
  11. using Microsoft.AspNetCore.Authorization;
  12. using Api.SignToken;
  13. using Microsoft.IdentityModel.Tokens;
  14. using System.Text;
  15. using System.Security.Claims;
  16. using Microsoft.AspNetCore.Authentication.JwtBearer;
  17. using System.IdentityModel.Tokens.Jwt;
  18. using Pivotal.Discovery.Client;
  19. using NLog.Extensions.Logging;
  20. using NLog.Web;
  21. using Microsoft.AspNetCore.Mvc.Versioning;
  22. using MadRunFabric.Common.Options;
  23. using AutoMapper;
  24. using TestUserTypeApi.IRepositories;
  25. using TestUserTypeApi.Repositories;
  26. using MadRunFabric.Common;
  27. using MadRunFabric.Common.DbContext;
  28. namespace TestUserTypeApi
  29. {
  30. public class Startup
  31. {
  32. public Startup(IHostingEnvironment env)
  33. {
  34. //Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
  35. Configuration = new ConfigurationBuilder()
  36. .SetBasePath(env.ContentRootPath)
  37. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  38. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
  39. .AddEnvironmentVariables()
  40. .Build();
  41. }
  42. public IConfiguration Configuration { get; }
  43. // This method gets called by the runtime. Use this method to add services to the container.
  44. public void ConfigureServices(IServiceCollection services)
  45. {
  46. #region Cors 配置
  47. ////生产环境 的cors
  48. //services.AddCors(options =>
  49. //{
  50. // options.AddPolicy("CorsProd",
  51. // builder => builder.AllowAnyOrigin()
  52. // //builder => builder.WithOrigins(Configuration["Cors"].Split(','))
  53. // .AllowAnyMethod()
  54. // .AllowAnyHeader()
  55. // .AllowCredentials().SetPreflightMaxAge(TimeSpan.FromMinutes(60)));
  56. //});
  57. ////开发环境的cors
  58. //services.AddCors(options =>
  59. //{
  60. // options.AddPolicy("CorsDev",
  61. // builder => builder.AllowAnyOrigin()
  62. // .AllowAnyMethod()
  63. // .AllowAnyHeader()
  64. // .AllowCredentials().SetPreflightMaxAge(TimeSpan.FromMinutes(60)));
  65. //});
  66. #endregion
  67. #region Cors 配置
  68. //生产环境 的cors
  69. services.AddCors(options =>
  70. {
  71. options.AddPolicy("CorsProd",
  72. builder => builder.AllowAnyOrigin()
  73. //builder => builder.WithOrigins(Configuration["Cors"].Split(','))
  74. .AllowAnyMethod()
  75. .AllowAnyHeader()
  76. .AllowCredentials().SetPreflightMaxAge(TimeSpan.FromMinutes(40)));
  77. });
  78. //开发环境的cors
  79. services.AddCors(options =>
  80. {
  81. options.AddPolicy("CorsDev",
  82. builder => builder.AllowAnyOrigin()
  83. .AllowAnyMethod()
  84. .AllowAnyHeader()
  85. .AllowCredentials().SetPreflightMaxAge(TimeSpan.FromMinutes(40)));
  86. });
  87. #endregion
  88. services.AddCors();
  89. #region 授权配置
  90. ////读取jwt配置文件
  91. //var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"].ToString()));
  92. //var tokenValidationParameters = new TokenValidationParameters
  93. //{
  94. // ValidateIssuerSigningKey = true,
  95. // IssuerSigningKey = signingKey,
  96. // ValidateIssuer = true,
  97. // ValidIssuer = Configuration["Jwt:Issuer"].ToString(),//发行人
  98. // ValidateAudience = true,
  99. // ValidAudience = Configuration["Jwt:Audience"].ToString(),//订阅人
  100. // ValidateLifetime = true,
  101. // ClockSkew = TimeSpan.Zero,
  102. // RequireExpirationTime = true,
  103. //};
  104. //services.AddAuthentication(options =>
  105. //{
  106. // options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
  107. // options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
  108. //})
  109. //.AddJwtBearer(o =>
  110. //{
  111. // o.RequireHttpsMetadata = false;
  112. // o.TokenValidationParameters = tokenValidationParameters;
  113. // o.Events = new JwtBearerEvents
  114. // {
  115. // OnTokenValidated = context =>
  116. // {
  117. // if (context.Request.Path.Value.ToString() == "/api/logout")
  118. // {
  119. // var token = ((context as TokenValidatedContext).SecurityToken as JwtSecurityToken).RawData;
  120. // }
  121. // return Task.CompletedTask;
  122. // }
  123. // };
  124. //});
  125. #endregion
  126. #region configuration
  127. services.AddSingleton<IConfiguration>(Configuration);
  128. #endregion
  129. #region steeltoe
  130. services.AddDiscoveryClient(Configuration);
  131. #endregion
  132. #region redis配置
  133. services.AddDistributedRedisCache(options =>
  134. {
  135. options.InstanceName = Configuration["Redis:InstanceName"].ToString();
  136. options.Configuration = $"{Configuration["Redis:HostName"].ToString()}:{Configuration["Redis:Port"].ToString()},allowAdmin=true,password={Configuration["Redis:Password"].ToString()},defaultdatabase={Configuration["Redis:Defaultdatabase"].ToString()}";
  137. });
  138. #endregion
  139. services.AddSingleton<IConfiguration>(Configuration);
  140. //注入授权Handler
  141. services.AddSingleton<IAuthorizationHandler, PermissionAuthorizationHandler>();
  142. services.AddSingleton<IPermissionService, PermissionService>();
  143. services.AddSingleton<ISignTokenService, SignTokenService>();
  144. #region 版本控制
  145. services.AddApiVersioning(Options =>
  146. {
  147. Options.ReportApiVersions = true;//可选,为true API返回响应标头中支持的版本信息
  148. Options.ApiVersionReader = new QueryStringApiVersionReader(parameterName: "api-version");
  149. Options.AssumeDefaultVersionWhenUnspecified = true;
  150. Options.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(6, 0);
  151. });
  152. #endregion
  153. #region AutoMapper
  154. services.AddAutoMapper();
  155. #endregion
  156. services.AddMvc(options =>
  157. {
  158. options.Filters.Add<ActionFilter>();
  159. options.Filters.Add<ExceptionFilter>();
  160. }).AddJsonOptions(op => op.SerializerSettings.ContractResolver =
  161. new Newtonsoft.Json.Serialization.DefaultContractResolver());
  162. #region Mongodb配置
  163. services.Configure<MongodbOptions>(options =>
  164. {
  165. options.ConnectionString = Configuration.GetSection("MongoConnection:ConnectionString").Value;
  166. options.Database = Configuration.GetSection("MongoConnection:Database").Value;
  167. });
  168. BaseOracleContext.DB_ConnectionString = Configuration.GetConnectionString("OracleConnection");
  169. BaseOracleiihContext.DB_ConnectionString = Configuration.GetConnectionString("OracleConnectioniih");
  170. #endregion
  171. #region steeltoe
  172. services.AddDiscoveryClient(Configuration);
  173. #endregion
  174. #region 添加仓储访问服务
  175. services.AddTransient<ItestusertypeRepository, TestusertypeRepository>();
  176. services.AddTransient<ItesttypeRepository, TesttypeRepository>();
  177. services.AddTransient<IUserDoTestRepository, UserDoTestRepository>();
  178. services.AddTransient<IUserTestRepository, UserTestRepository>();
  179. services.AddTransient<IMassageInfoRepository, MassageInfoRepository>();
  180. services.AddTransient<ItestquestionRepository, testquestionRepository>();
  181. services.AddTransient<IMassageTypeRepository, MassageTypeRepository>();
  182. services.AddTransient<ImsgonlinemapRepository, msgonlinemapRepository>();//聊天记录是否已读关联表
  183. services.AddTransient<ImsgonlineRepository, msgonlineRepository>();//聊天记录表
  184. services.AddTransient<IdiagnosisinfoRepository, diagnosisinfoRepository>();//会诊
  185. services.AddTransient<IpatientRepository, patientRepository>();//患者
  186. services.AddTransient<IdiagnosisinbasesRepository, diagnosisinbasesRepository>();//会诊人员信息
  187. services.AddTransient<IequipmentmanagementsRepository, equipmentmanagementsRepository>();//设备调配设备表
  188. services.AddTransient<IequipmentmanagementlistRepository, equipmentmanagementlistRepository>();//设备调配记录表
  189. services.AddTransient<ISzzysRepository, SzzysRepository>();//上转住院
  190. services.AddTransient<IHzjbxxRepository, HzjbxxRepository>();//患者信息
  191. services.AddTransient<ISzmzsRepository, SzmzsRepository>();//上转门诊
  192. services.AddTransient<ISzjcsRepository, SzjcsRepository>(); //上转检查
  193. services.AddTransient<IXzzlsRepository, XzzlsRepository>(); //下转治疗
  194. services.AddTransient<IXzzysRepository, XzzysRepository>();//下转住院
  195. services.AddTransient<IWjzqjsRepository, WjzqjsRepository>();//急危重抢救
  196. services.AddTransient<IBbsqsRepository, BbsqsRepository>();//标本收取
  197. services.AddTransient<IHzapsRepository, HzapsRepository>();//会诊安排
  198. services.AddTransient<IGzlrbsRepository, GzlrbsRepository>();//工作量日报
  199. services.AddTransient<IYyzlsRepository, YyzlsRepository>();//预约诊疗
  200. services.AddTransient<IFxdjtabsRepository, FxdjtabsRepository>();//风险等级
  201. services.AddTransient<IFxqytabsRepository, FxqytabsRepository>();//风险区域
  202. services.AddTransient<IYhpctabsRepository, YhpctabsRepository>();//隐患排查
  203. services.AddTransient<IdxsfjlsRepository, dxsfjlsRepository>();//患者出院信息
  204. services.AddTransient<ISys_User_AccountRepository, Sys_User_AccountRepository>();
  205. services.AddTransient<ITSys_AreaRepository, TSys_AreaRepository>();//测试调用oracle
  206. services.AddTransient<Iv_csm_zhuyuanRepository, v_csm_zhuyuanRepository>();//出院患者信息
  207. services.AddTransient<IGhcodesRepository, GhcodesRepository>();//工号表
  208. services.AddTransient<IHzsfMassagesRepository, HzsfMassagesRepository>();//住院患者发送短信记录表
  209. services.AddTransient<ImzhzmassagesRepository, mzhzmassagesRepository>();//门诊患者信息表
  210. services.AddTransient<IyltdeptmanageRepository, yltdeptmanageRepository>();//医联体单位管理
  211. services.AddTransient<IMassmodellistsRepository, MassmodellistsRepository>();//在线客服消息回复模板
  212. services.AddTransient<IOnlineServerIfhaveRepository, OnlineServerIfhaveRepository>();//在线客服是否有新消息
  213. services.AddTransient<IOnlineserTypeRepository, OnlineserTypeRepository>();//客服服务类型
  214. services.AddTransient<ICallComeTpwodeRepository, CallComeTpwodeRepository>();//来电弹屏工单
  215. services.AddTransient<ICallComeDeptorPeoRepository, CallComeDeptorPeoRepository>();//科室及对应科室负责人数据维护
  216. services.AddTransient<Iyjpt_jcxxRepository, yjpt_jcxxRepository>();//检查信息iih数据
  217. services.AddTransient<IyyjlinfolistRepository, yyjlinfolistRepository>();//预约记录信息表
  218. services.AddTransient<IFpzxinfosRepository, FpzxinfosRepository>();//分配在线客服表
  219. services.AddTransient<IimportmassageRepository, importmassageRepository>();//通知公告信息表管理
  220. services.AddTransient<IYytxluinfoRepository, YytxluinfoRepository>();//第三方通话通讯录
  221. #endregion
  222. //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
  223. }
  224. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  225. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  226. {
  227. if (env.IsProduction())
  228. {
  229. app.UseCors("CorsProd");
  230. }
  231. else
  232. {
  233. app.UseCors("CorsDev");
  234. app.UseDeveloperExceptionPage();
  235. app.UseDatabaseErrorPage();
  236. app.UseBrowserLink();
  237. }
  238. app.UseCors(builder => builder
  239. .AllowAnyOrigin()
  240. .AllowAnyMethod()
  241. .AllowAnyHeader()
  242. .AllowCredentials());
  243. app.UseAuthentication();
  244. app.UseMvc();
  245. #region steeltoe
  246. app.UseDiscoveryClient();
  247. #endregion
  248. #region Nlog 引入
  249. loggerFactory.AddNLog();//添加NLog
  250. env.ConfigureNLog("nlog.config");//读取Nlog配置文件
  251. app.AddNLogWeb();
  252. #endregion
  253. }
  254. }
  255. }