You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

744 lines
28 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
7 months ago
4 months ago
2 years ago
1 year ago
4 months ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 months ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
1 year ago
7 months ago
1 year ago
4 months ago
7 months ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
4 months ago
2 years ago
4 months ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 months ago
1 year ago
1 month ago
1 month ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 months ago
2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Cors;
  7. using Microsoft.AspNetCore.Extensions.DependencyInjection;
  8. using Microsoft.Extensions.Configuration;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using Microsoft.Extensions.Hosting;
  11. using Shentun.Peis.EntityFrameworkCore;
  12. using Shentun.Peis.MultiTenancy;
  13. using Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite;
  14. using Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite.Bundling;
  15. using Microsoft.OpenApi.Models;
  16. using OpenIddict.Validation.AspNetCore;
  17. using Volo.Abp;
  18. using Volo.Abp.Account;
  19. using Volo.Abp.Account.Web;
  20. using Volo.Abp.AspNetCore.MultiTenancy;
  21. using Volo.Abp.AspNetCore.Mvc;
  22. using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
  23. using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
  24. using Volo.Abp.AspNetCore.Serilog;
  25. using Volo.Abp.Autofac;
  26. using Volo.Abp.Localization;
  27. using Volo.Abp.Modularity;
  28. using Volo.Abp.Swashbuckle;
  29. using Volo.Abp.UI.Navigation.Urls;
  30. using Volo.Abp.VirtualFileSystem;
  31. using Microsoft.AspNetCore.Mvc;
  32. using Microsoft.Extensions.Options;
  33. using System.Reflection;
  34. using Swashbuckle.AspNetCore.SwaggerGen;
  35. using Microsoft.AspNetCore.Mvc.Filters;
  36. using Volo.Abp.AspNetCore.Mvc.Validation;
  37. using Microsoft.Extensions.DependencyInjection.Extensions;
  38. using Volo.Abp.Identity;
  39. using Microsoft.Extensions.FileProviders;
  40. using Microsoft.AspNetCore.Mvc.ApplicationModels;
  41. using Volo.Abp.Settings;
  42. using Volo.Abp.Identity.Settings;
  43. using Microsoft.AspNetCore.Identity;
  44. using Volo.Abp.AspNetCore.Mvc.AntiForgery;
  45. using Microsoft.AspNetCore.Authentication;
  46. using Nito.Disposables.Internals;
  47. using Volo.Abp.AspNetCore.Mvc.ExceptionHandling;
  48. using static IdentityModel.ClaimComparer;
  49. using Microsoft.AspNetCore.Authorization;
  50. using Microsoft.AspNetCore.Diagnostics;
  51. using Microsoft.AspNetCore.Http;
  52. using Shentun.Peis.Filter;
  53. using Shentun.Peis.VirtualPath;
  54. using System.Text.Encodings.Web;
  55. using System.Text.Unicode;
  56. using Volo.Abp.Json;
  57. using Shentun.Utilities;
  58. using Volo.Abp.SecurityLog;
  59. using Volo.Abp.Auditing;
  60. using Volo.Abp.BackgroundWorkers.Hangfire;
  61. using Hangfire;
  62. using Volo.Abp.BackgroundWorkers;
  63. using Shentun.Peis.Schedulers;
  64. using System.Threading.Tasks;
  65. using Shentun.Peis.ThirdInterfaces;
  66. using OpenIddict.Server;
  67. using Microsoft.IdentityModel.Tokens;
  68. using System.IdentityModel.Tokens.Jwt;
  69. using System.Security.Claims;
  70. using System.Text;
  71. using System.Security.Cryptography;
  72. using Microsoft.AspNetCore.DataProtection;
  73. using Volo.Abp.OpenIddict;
  74. using System.Security.Cryptography.X509Certificates;
  75. using Shentun.Peis.Controllers;
  76. using Hangfire.Redis;
  77. namespace Shentun.Peis;
  78. [DependsOn(
  79. typeof(PeisHttpApiModule),
  80. typeof(AbpAutofacModule),
  81. typeof(AbpAspNetCoreMultiTenancyModule),
  82. typeof(PeisApplicationModule),
  83. typeof(PeisEntityFrameworkCoreModule),
  84. typeof(AbpAspNetCoreMvcUiLeptonXLiteThemeModule),
  85. typeof(AbpAccountWebOpenIddictModule),
  86. typeof(AbpAspNetCoreSerilogModule),
  87. typeof(AbpSwashbuckleModule),
  88. typeof(AbpBackgroundWorkersHangfireModule)
  89. )]
  90. public class PeisHttpApiHostModule : AbpModule
  91. {
  92. public override void PreConfigureServices(ServiceConfigurationContext context)
  93. {
  94. //自定义DataProtection路径
  95. context.Services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(context.Services.GetHostingEnvironment().WebRootPath));
  96. //关闭开发证书
  97. PreConfigure<AbpOpenIddictAspNetCoreOptions>(options =>
  98. {
  99. options.AddDevelopmentEncryptionAndSigningCertificate = false;
  100. });
  101. PreConfigure<OpenIddictBuilder>(builder =>
  102. {
  103. builder.AddValidation(options =>
  104. {
  105. options.AddAudiences("Peis");
  106. options.UseLocalServer();
  107. options.UseAspNetCore();
  108. });
  109. });
  110. //重写定义token失效时间 接口返回的是秒
  111. PreConfigure<OpenIddictServerBuilder>(builder =>
  112. {
  113. //builder.SetAccessTokenLifetime(TimeSpan.FromHours(8)).SetRefreshTokenLifetime(TimeSpan.FromDays(15));
  114. builder.SetAccessTokenLifetime(TimeSpan.FromDays(30)).SetRefreshTokenLifetime(TimeSpan.FromDays(60));
  115. //导入自定义证书,低版本windows要用openssl1.1.1生成
  116. builder.AddEncryptionCertificate(new X509Certificate2(File.ReadAllBytes(context.Services.GetHostingEnvironment().WebRootPath + "\\encryption-certificate.pfx"), "", X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet));
  117. builder.AddSigningCertificate(new X509Certificate2(File.ReadAllBytes(context.Services.GetHostingEnvironment().WebRootPath + "\\signing-certificate.pfx"), "", X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet));
  118. });
  119. }
  120. public override void ConfigureServices(ServiceConfigurationContext context)
  121. {
  122. var configuration = context.Services.GetConfiguration();
  123. var hostingEnvironment = context.Services.GetHostingEnvironment();
  124. ConfigureAuthentication(context);
  125. ConfigureBundles();
  126. ConfigureUrls(configuration);
  127. ConfigureConventionalControllers();
  128. ConfigureLocalization();
  129. ConfigureVirtualFileSystem(context);
  130. ConfigureCors(context, configuration);
  131. ConfigureSwaggerServices(context, configuration);
  132. ConfigureJsonOptions(); //全局配置api返回值中的日期默认格式
  133. //context.Services.AddControllers().AddJsonOptions(configure =>
  134. //{
  135. // configure.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter());
  136. // configure.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
  137. //});
  138. //密码策略配置
  139. context.Services.Configure<IdentityOptions>(opt =>
  140. {
  141. opt.Password.RequireDigit = false;
  142. opt.Password.RequireLowercase = false;
  143. opt.Password.RequireUppercase = false;
  144. opt.Password.RequireNonAlphanumeric = false;
  145. opt.Password.RequiredLength = 1;
  146. });
  147. //context.Services.Configure<IISServerOptions>(opt =>
  148. //{
  149. // opt.MaxRequestBodySize = 52428800;
  150. //});
  151. //context.Services.Configure<KestrelServerOptions>(opt =>
  152. //{
  153. // opt.Limits.MaxRequestBodySize = 52428800;
  154. //});
  155. #region 临时去掉日志
  156. //关闭审计日志
  157. Configure<AbpAuditingOptions>(options =>
  158. {
  159. options.IsEnabled = configuration.GetValue("IsAuditingLog", true);
  160. });
  161. //关闭安全日志
  162. Configure<AbpSecurityLogOptions>(options =>
  163. {
  164. options.IsEnabled = configuration.GetValue("IsSecurityLog", true);
  165. });
  166. #endregion
  167. //防伪令牌
  168. //context.Services.Configure<AbpAntiForgeryOptions>(opt =>
  169. //{
  170. // opt.AutoValidate = false;
  171. //});
  172. context.Services.AddMvc(options =>
  173. {
  174. var filterMetadata = options.Filters.FirstOrDefault(x => x is ServiceFilterAttribute attribute && attribute.ServiceType.Equals(typeof(AbpValidationActionFilter)));
  175. options.Filters.Remove(filterMetadata);
  176. options.Filters.Add(typeof(ValidateFilter));
  177. options.Filters.Add(typeof(CustomerExceptionFilterAttribute));
  178. options.Filters.Add(typeof(CustomerActionFilterAttribute));
  179. // options.Filters.ReplaceOne(x => (x as ServiceFilterAttribute)?.ServiceType?.Name == nameof(ExceptionFilterAttribute), new ServiceFilterAttribute(typeof(ABCExceptionFilterAttribute)));
  180. // options.Filters.ReplaceOne(x => (x as ServiceFilterAttribute)?.ServiceType?.Name == nameof(AbpExceptionFilter), new ServiceFilterAttribute(typeof(MyExceptionFilter)));
  181. });
  182. //context.Services.TryAddTransient<IAuthorizationMiddlewareResultHandler, AuthorizationMiddlewareResultHandler>();
  183. ///解除https限制
  184. context.Services.AddOpenIddict()
  185. .AddServer(option =>
  186. {
  187. string issuerBase = configuration["AuthServer:IssuerBase"];
  188. if (!string.IsNullOrWhiteSpace(issuerBase))
  189. option.SetIssuer(new Uri(issuerBase));
  190. option.UseAspNetCore().DisableTransportSecurityRequirement();
  191. option.AllowCustomFlow("mini_program");
  192. option.AllowCustomFlow("phone_verify");
  193. });
  194. context.Services.AddTransient<MiniProgramTokenController>();
  195. ////虚拟目录
  196. //context.Services.AddSingleton(new MyFileProvider(configuration["VirtualPath:RealPath"], configuration["VirtualPath:Alias"]));
  197. ////Pacs虚拟目录
  198. //context.Services.AddSingleton(new MyFileProvider(configuration["PacsVirtualPath:RealPath"], configuration["PacsVirtualPath:Alias"]));
  199. /*
  200. Configure<AbpAspNetCoreMvcOptions>(options =>
  201. {
  202. options.ConventionalControllers
  203. .Create(typeof(PeisApplicationModule).Assembly, opts =>
  204. {
  205. opts.RootPath = "api/app";
  206. opts.UrlControllerNameNormalizer = (controller) =>
  207. {
  208. return controller.ControllerName;
  209. };
  210. opts.UrlActionNameNormalizer = (action) =>
  211. {
  212. return action.Action.ActionName;
  213. };
  214. });
  215. });
  216. */
  217. //后台计划任务
  218. ConfigureHangfire(context, configuration);
  219. }
  220. /// <summary>
  221. /// 全局转换日期格式
  222. /// </summary>
  223. private void ConfigureJsonOptions()
  224. {
  225. //context.Services.AddControllers().AddJsonOptions(options =>
  226. //{
  227. // options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
  228. // options.JsonSerializerOptions.PropertyNamingPolicy = null;
  229. //});
  230. Configure<JsonOptions>(x =>
  231. {
  232. //x.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
  233. x.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter());
  234. x.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
  235. });
  236. Configure<AbpJsonOptions>(x =>
  237. {
  238. x.DefaultDateTimeFormat = "yyyy-MM-dd HH:mm:ss";
  239. });
  240. }
  241. private void ConfigureAuthentication(ServiceConfigurationContext context)
  242. {
  243. context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
  244. }
  245. private void ConfigureBundles()
  246. {
  247. Configure<AbpBundlingOptions>(options =>
  248. {
  249. options.StyleBundles.Configure(
  250. LeptonXLiteThemeBundles.Styles.Global,
  251. bundle =>
  252. {
  253. bundle.AddFiles("/global-styles.css");
  254. }
  255. );
  256. });
  257. }
  258. private void ConfigureUrls(IConfiguration configuration)
  259. {
  260. Configure<AppUrlOptions>(options =>
  261. {
  262. options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"];
  263. options.RedirectAllowedUrls.AddRange(configuration["App:RedirectAllowedUrls"].Split(','));
  264. options.Applications["Angular"].RootUrl = configuration["App:ClientUrl"];
  265. options.Applications["Angular"].Urls[AccountUrlNames.PasswordReset] = "account/reset-password";
  266. });
  267. }
  268. private void ConfigureVirtualFileSystem(ServiceConfigurationContext context)
  269. {
  270. var hostingEnvironment = context.Services.GetHostingEnvironment();
  271. if (hostingEnvironment.IsDevelopment())
  272. {
  273. Configure<AbpVirtualFileSystemOptions>(options =>
  274. {
  275. options.FileSets.ReplaceEmbeddedByPhysical<PeisDomainSharedModule>(
  276. Path.Combine(hostingEnvironment.ContentRootPath,
  277. $"..{Path.DirectorySeparatorChar}Shentun.Peis.Domain.Shared"));
  278. options.FileSets.ReplaceEmbeddedByPhysical<PeisDomainModule>(
  279. Path.Combine(hostingEnvironment.ContentRootPath,
  280. $"..{Path.DirectorySeparatorChar}Shentun.Peis.Domain"));
  281. options.FileSets.ReplaceEmbeddedByPhysical<PeisApplicationContractsModule>(
  282. Path.Combine(hostingEnvironment.ContentRootPath,
  283. $"..{Path.DirectorySeparatorChar}Shentun.Peis.Application.Contracts"));
  284. options.FileSets.ReplaceEmbeddedByPhysical<PeisApplicationModule>(
  285. Path.Combine(hostingEnvironment.ContentRootPath,
  286. $"..{Path.DirectorySeparatorChar}Shentun.Peis.Application"));
  287. });
  288. }
  289. }
  290. private void ConfigureConventionalControllers()
  291. {
  292. #region 配置隐藏api
  293. Configure<MvcOptions>(options =>
  294. {
  295. options.Conventions.Add(new ApplicationDescription());
  296. });
  297. #endregion
  298. Configure<AbpAspNetCoreMvcOptions>(options =>
  299. {
  300. options.ConventionalControllers.Create(typeof(PeisApplicationModule).Assembly);
  301. });
  302. }
  303. private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration)
  304. {
  305. context.Services.AddAbpSwaggerGenWithOAuth(
  306. configuration["AuthServer:Authority"],
  307. new Dictionary<string, string>
  308. {
  309. {"Peis", "Peis API"}
  310. },
  311. options =>
  312. {
  313. //options.SwaggerDoc("v1", new OpenApiInfo { Title = "Peis API", Version = "v1" });
  314. //options.DocInclusionPredicate((docName, description) => true);
  315. //options.CustomSchemaIds(type => type.FullName);
  316. options.SwaggerDoc("Work", new OpenApiInfo { Title = "业务API", Version = "V1", Description = "业务API" });
  317. options.SwaggerDoc("Sys", new OpenApiInfo { Title = "底层API", Version = "V1", Description = "底层API" });
  318. options.DocInclusionPredicate((docName, description) =>
  319. {
  320. if (!description.TryGetMethodInfo(out MethodInfo method))
  321. {
  322. return false;
  323. }
  324. /*使ApiExplorerSettingsAttribute里面的GroupName进行特性标识
  325. * DeclaringType只能获取controller上的特性
  326. * action的特性为主
  327. * */
  328. var version = method.DeclaringType.GetCustomAttributes(true).OfType<ApiExplorerSettingsAttribute>().Select(m => m.GroupName);
  329. if (version.Any())
  330. {
  331. if (version.Any(v => v == docName))
  332. //选择了sys,并且分组不为User
  333. return true;
  334. }
  335. else
  336. {
  337. if (docName == "Sys")
  338. {
  339. return true;
  340. }
  341. }
  342. //这里获取action的特性
  343. var actionVersion = method.GetCustomAttributes(true).OfType<ApiExplorerSettingsAttribute>().Select(m => m.GroupName);
  344. if (actionVersion.Any())
  345. {
  346. return actionVersion.Any(v => v == docName);
  347. }
  348. return false;
  349. });
  350. });
  351. }
  352. private void ConfigureLocalization()
  353. {
  354. Configure<AbpLocalizationOptions>(options =>
  355. {
  356. options.Languages.Add(new LanguageInfo("ar", "ar", "العربية"));
  357. options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština"));
  358. options.Languages.Add(new LanguageInfo("en", "en", "English"));
  359. options.Languages.Add(new LanguageInfo("en-GB", "en-GB", "English (UK)"));
  360. options.Languages.Add(new LanguageInfo("fi", "fi", "Finnish"));
  361. options.Languages.Add(new LanguageInfo("fr", "fr", "Français"));
  362. options.Languages.Add(new LanguageInfo("hi", "hi", "Hindi", "in"));
  363. options.Languages.Add(new LanguageInfo("is", "is", "Icelandic", "is"));
  364. options.Languages.Add(new LanguageInfo("it", "it", "Italiano", "it"));
  365. options.Languages.Add(new LanguageInfo("hu", "hu", "Magyar"));
  366. options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português"));
  367. options.Languages.Add(new LanguageInfo("ro-RO", "ro-RO", "Română"));
  368. options.Languages.Add(new LanguageInfo("ru", "ru", "Русский"));
  369. options.Languages.Add(new LanguageInfo("sk", "sk", "Slovak"));
  370. options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe"));
  371. options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
  372. options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文"));
  373. options.Languages.Add(new LanguageInfo("de-DE", "de-DE", "Deutsch", "de"));
  374. options.Languages.Add(new LanguageInfo("es", "es", "Español", "es"));
  375. options.Languages.Add(new LanguageInfo("el", "el", "Ελληνικά"));
  376. });
  377. }
  378. private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration)
  379. {
  380. context.Services.AddCors(options =>
  381. {
  382. options.AddDefaultPolicy(builder =>
  383. {
  384. builder
  385. .WithOrigins(
  386. configuration["App:CorsOrigins"]
  387. .Split(",", StringSplitOptions.RemoveEmptyEntries)
  388. .Select(o => o.RemovePostFix("/"))
  389. .ToArray()
  390. )
  391. .WithAbpExposedHeaders()
  392. .SetIsOriginAllowedToAllowWildcardSubdomains()
  393. .AllowAnyHeader()
  394. .AllowAnyMethod()
  395. .AllowCredentials();
  396. });
  397. });
  398. //添加swagger中文注释
  399. context.Services.AddSwaggerGen(options =>
  400. {
  401. //var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
  402. var baseDirectory = AppContext.BaseDirectory;
  403. //Serilog.Log.Information("swagger地址1:" + baseDirectory);
  404. //var baseDirectory2 = Path.GetDirectoryName(typeof(Program).Assembly.Location);
  405. //Serilog.Log.Information("swagger地址2:" + baseDirectory2);
  406. //var baseDirectory3 = AppDomain.CurrentDomain.BaseDirectory;
  407. //Serilog.Log.Information("swagger地址3:" + baseDirectory3);
  408. var commentsFile = Path.Combine(baseDirectory, "Shentun.Peis.Application.xml");
  409. options.IncludeXmlComments(commentsFile, true);
  410. var commentsFileDro = Path.Combine(baseDirectory, "Shentun.Peis.Application.Contracts.xml");
  411. options.IncludeXmlComments(commentsFileDro, true);
  412. var commentsFileapi = Path.Combine(baseDirectory, "Shentun.Peis.HttpApi.xml");
  413. options.IncludeXmlComments(commentsFileapi, true);
  414. });
  415. }
  416. private void ConfigureHangfire(ServiceConfigurationContext context, IConfiguration configuration)
  417. {
  418. //context.Services.AddHangfire(config =>
  419. //{
  420. // config.UsePostgreSqlStorage(configuration.GetConnectionString("Default"));
  421. //});
  422. context.Services.AddHangfire(config =>
  423. {
  424. config.UseRedisStorage(configuration["Hangfire:ConnectionStrings"], new RedisStorageOptions
  425. {
  426. Db = string.IsNullOrWhiteSpace(configuration["Hangfire:Db"]) ? 0 : Convert.ToInt32(configuration["Hangfire:Db"])
  427. });
  428. });
  429. }
  430. public override async void OnApplicationInitialization(ApplicationInitializationContext context)
  431. {
  432. var app = context.GetApplicationBuilder();
  433. var env = context.GetEnvironment();
  434. var configuration = context.GetConfiguration();
  435. //请求错误提示配置
  436. // app.UseErrorHandling();
  437. if (env.IsDevelopment())
  438. {
  439. app.UseDeveloperExceptionPage();
  440. }
  441. app.UseAbpRequestLocalization();
  442. if (!env.IsDevelopment())
  443. {
  444. app.UseErrorPage();
  445. }
  446. //配置是否启用任务面板
  447. var IsEnabledDashboard = Convert.ToBoolean(configuration["Hangfire:IsEnabledDashboard"]);
  448. var IsEnabledHangfire = Convert.ToBoolean(configuration["Hangfire:IsEnabled"]);
  449. if (IsEnabledHangfire && IsEnabledDashboard)
  450. {
  451. app.UseHangfireDashboard("/hangfire", new DashboardOptions
  452. {
  453. Authorization = new[] { new CustomAuthorizeFilter() }
  454. });
  455. }
  456. app.UseCorrelationId();
  457. //var staticFile = new StaticFileOptions();
  458. //var filePath = env.ContentRootPath+"UpLoad\\";
  459. ////var filePath = env.ContentRootPath ;
  460. //staticFile.FileProvider = new PhysicalFileProvider(filePath);
  461. //app.UseStaticFiles(new StaticFileOptions
  462. //{
  463. // FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "UpLoad")),
  464. // RequestPath="/UpLoad"
  465. //});
  466. app.UseStaticFiles();
  467. app.UseStaticFiles(new StaticFileOptions
  468. {
  469. FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "ReportFile")),
  470. RequestPath = "/ReportFile"
  471. });
  472. app.UseStaticFiles(new StaticFileOptions
  473. {
  474. FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "photo")),
  475. RequestPath = "/photo"
  476. });
  477. app.UseStaticFiles(new StaticFileOptions
  478. {
  479. FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "CloudFilm")),
  480. RequestPath = "/CloudFilm"
  481. });
  482. app.UseStaticFiles(new StaticFileOptions
  483. {
  484. FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "UserPhoto")),
  485. RequestPath = "/UserPhoto"
  486. });
  487. app.UseStaticFiles(new StaticFileOptions
  488. {
  489. FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "UserSign")),
  490. RequestPath = "/UserSign"
  491. });
  492. //虚拟目录
  493. app.UseStaticFiles(new StaticFileOptions
  494. {
  495. FileProvider = new PhysicalFileProvider(configuration["VirtualPath:RealPath"]),
  496. RequestPath = configuration["VirtualPath:RequestPath"]
  497. });
  498. //pacs虚拟目录
  499. app.UseStaticFiles(new StaticFileOptions
  500. {
  501. FileProvider = new PhysicalFileProvider(configuration["PacsVirtualPath:RealPath"]),
  502. RequestPath = configuration["PacsVirtualPath:RequestPath"]
  503. });
  504. app.UseRouting();
  505. app.UseCors();
  506. app.UseAuthentication();
  507. app.UseAbpOpenIddictValidation();
  508. if (MultiTenancyConsts.IsEnabled)
  509. {
  510. app.UseMultiTenancy();
  511. }
  512. app.UseUnitOfWork();
  513. app.UseAuthorization();
  514. //app.UseMiddleware(typeof(AuthorizationMiddlewareResultHandler));
  515. //配置是否启用swagger
  516. var IsSwagger = Convert.ToBoolean(configuration["Swagger:IsEnabled"]);
  517. if (IsSwagger)
  518. {
  519. app.UseSwagger();
  520. app.UseAbpSwaggerUI(c =>
  521. {
  522. //c.SwaggerEndpoint("/swagger/v1/swagger.json", "Peis API");
  523. c.SwaggerEndpoint($"/swagger/Work/swagger.json", "业务API"); //分组显示
  524. c.SwaggerEndpoint($"/swagger/Sys/swagger.json", "底层API"); //分组显示
  525. //c.RoutePrefix = string.Empty; // url 中不显示swagger
  526. var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
  527. c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
  528. c.OAuthScopes("Peis");
  529. c.DefaultModelExpandDepth(-1);
  530. });
  531. }
  532. app.UseAuditing();
  533. app.UseAbpSerilogEnrichers();
  534. app.UseConfiguredEndpoints();
  535. if (IsEnabledHangfire)
  536. {
  537. //任务计划
  538. await StartScheduler(context);
  539. }
  540. }
  541. private async Task StartScheduler(ApplicationInitializationContext context)
  542. {
  543. //await context.AddBackgroundWorkerAsync<ChargeRequestInterfaceQueryWorker>();
  544. //RecurringJob.AddOrUpdate<IChargeRequestInterfaceQueryWorker>("收费接口", o => o.DoWorkAsync(new Guid("")), CheckedBills, TimeZoneInfo.Local);
  545. //BackgroundJob.Enqueue<ChargeRequestInterfaceQueryWorker>(x => x.DoWorkWithArgAsync(new Guid("")));
  546. var appServiceHelper = new AppServiceHelper();
  547. await appServiceHelper.LoginAsync();
  548. var ThirdInterfaceDtos = await appServiceHelper.CallAppServiceAsync<object, List<ThirdInterfaceDto>>("api/app/ThirdInterface/GetList", null);
  549. foreach (var thirdInterfaceDto in ThirdInterfaceDtos)
  550. {
  551. if (thirdInterfaceDto.IsActive != 'Y')
  552. {
  553. continue;
  554. }
  555. var parmValue = thirdInterfaceDto.ParmValue;
  556. if (!string.IsNullOrWhiteSpace(parmValue))
  557. {
  558. var configurationBuilder = new ConfigurationBuilder()
  559. .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
  560. IConfigurationRoot interfaceConfig;
  561. try
  562. {
  563. interfaceConfig = configurationBuilder.Build();
  564. }
  565. catch (Exception ex)
  566. {
  567. continue;
  568. }
  569. var isActive = interfaceConfig.GetSection("Interface").GetSection("Scheduler")
  570. .GetSection("IsActive").Value;
  571. var corn = interfaceConfig.GetSection("Interface").GetSection("Scheduler")
  572. .GetSection("Corn").Value;
  573. if (isActive == "Y")
  574. {
  575. if (thirdInterfaceDto.ThirdInterfaceType == "02")
  576. {
  577. RecurringJob.AddOrUpdate<IChargeRequestInterfaceQueryWorker>(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  578. }
  579. else if (thirdInterfaceDto.ThirdInterfaceType == "03")
  580. {
  581. RecurringJob.AddOrUpdate<IImportLisResultInterfaceWorker>(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  582. }
  583. else if (thirdInterfaceDto.ThirdInterfaceType == "04")
  584. {
  585. RecurringJob.AddOrUpdate<IImportPacsResultInterfaceWorker>(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  586. }
  587. else if (thirdInterfaceDto.ThirdInterfaceType == "05")
  588. {
  589. RecurringJob.AddOrUpdate<IImportPatientRegisterInterfaceWorker>(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  590. }
  591. else if (thirdInterfaceDto.ThirdInterfaceType == "06")
  592. {
  593. RecurringJob.AddOrUpdate<ISyncPatientRegisterReportInterfaceWorker>(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  594. }
  595. else if (thirdInterfaceDto.ThirdInterfaceType == "08")
  596. {
  597. //心电图
  598. RecurringJob.AddOrUpdate<IImportElectrocardiogramResultInterfaceWorker>(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  599. }
  600. else if (thirdInterfaceDto.ThirdInterfaceType == "09")
  601. {
  602. //同步组合项目价格
  603. RecurringJob.AddOrUpdate<ISyncAsbitemPriceInterfaceWorker>(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  604. }
  605. else if (thirdInterfaceDto.ThirdInterfaceType == "14")
  606. {
  607. //导入外检检验结果
  608. RecurringJob.AddOrUpdate<IImportOutSendLisResultInterfaceWorker>(thirdInterfaceDto.DisplayName, o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  609. }
  610. }
  611. }
  612. }
  613. }
  614. }