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.

919 lines
35 KiB

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