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.

651 lines
24 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
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
1 year 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
2 years ago
2 years ago
2 years ago
1 year ago
2 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
3 years ago
3 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
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
  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 Hangfire.PostgreSql;
  63. using Volo.Abp.BackgroundWorkers;
  64. using Shentun.Peis.Schedulers;
  65. using System.Threading.Tasks;
  66. using Shentun.Peis.ThirdInterfaces;
  67. namespace Shentun.Peis;
  68. [DependsOn(
  69. typeof(PeisHttpApiModule),
  70. typeof(AbpAutofacModule),
  71. typeof(AbpAspNetCoreMultiTenancyModule),
  72. typeof(PeisApplicationModule),
  73. typeof(PeisEntityFrameworkCoreModule),
  74. typeof(AbpAspNetCoreMvcUiLeptonXLiteThemeModule),
  75. typeof(AbpAccountWebOpenIddictModule),
  76. typeof(AbpAspNetCoreSerilogModule),
  77. typeof(AbpSwashbuckleModule),
  78. typeof(AbpBackgroundWorkersHangfireModule)
  79. )]
  80. public class PeisHttpApiHostModule : AbpModule
  81. {
  82. public override void PreConfigureServices(ServiceConfigurationContext context)
  83. {
  84. PreConfigure<OpenIddictBuilder>(builder =>
  85. {
  86. builder.AddValidation(options =>
  87. {
  88. options.AddAudiences("Peis");
  89. options.UseLocalServer();
  90. options.UseAspNetCore();
  91. });
  92. });
  93. //重写定义token失效时间 接口返回的是秒
  94. PreConfigure<OpenIddictServerBuilder>(builder =>
  95. {
  96. //builder.SetAccessTokenLifetime(TimeSpan.FromHours(8)).SetRefreshTokenLifetime(TimeSpan.FromDays(15));
  97. builder.SetAccessTokenLifetime(TimeSpan.FromDays(30)).SetRefreshTokenLifetime(TimeSpan.FromDays(60));
  98. });
  99. }
  100. public override void ConfigureServices(ServiceConfigurationContext context)
  101. {
  102. var configuration = context.Services.GetConfiguration();
  103. var hostingEnvironment = context.Services.GetHostingEnvironment();
  104. ConfigureAuthentication(context);
  105. ConfigureBundles();
  106. ConfigureUrls(configuration);
  107. ConfigureConventionalControllers();
  108. ConfigureLocalization();
  109. ConfigureVirtualFileSystem(context);
  110. ConfigureCors(context, configuration);
  111. ConfigureSwaggerServices(context, configuration);
  112. ConfigureJsonOptions(); //全局配置api返回值中的日期默认格式
  113. //context.Services.AddControllers().AddJsonOptions(configure =>
  114. //{
  115. // configure.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter());
  116. // configure.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
  117. //});
  118. //密码策略配置
  119. context.Services.Configure<IdentityOptions>(opt =>
  120. {
  121. opt.Password.RequireDigit = false;
  122. opt.Password.RequireLowercase = false;
  123. opt.Password.RequireUppercase = false;
  124. opt.Password.RequireNonAlphanumeric = false;
  125. opt.Password.RequiredLength = 1;
  126. });
  127. ////密码策略配置
  128. //context.Services.Configure<IdentityOptions>(opt =>
  129. //{
  130. // opt.Password.RequireDigit = false;
  131. // opt.Password.RequireLowercase = false;
  132. // opt.Password.RequireUppercase = false;
  133. // opt.Password.RequireNonAlphanumeric = false;
  134. // opt.Password.RequiredLength = 1;
  135. //});
  136. #region 临时去掉日志
  137. ////关闭审计日志
  138. //Configure<AbpAuditingOptions>(options =>
  139. //{
  140. // options.IsEnabled = false;
  141. //});
  142. ////关闭安全日志
  143. //Configure<AbpSecurityLogOptions>(options =>
  144. //{
  145. // options.IsEnabled = false;
  146. //});
  147. #endregion
  148. //防伪令牌
  149. //context.Services.Configure<AbpAntiForgeryOptions>(opt =>
  150. //{
  151. // opt.AutoValidate = false;
  152. //});
  153. context.Services.AddMvc(options =>
  154. {
  155. var filterMetadata = options.Filters.FirstOrDefault(x => x is ServiceFilterAttribute attribute && attribute.ServiceType.Equals(typeof(AbpValidationActionFilter)));
  156. options.Filters.Remove(filterMetadata);
  157. options.Filters.Add(typeof(ValidateFilter));
  158. options.Filters.Add(typeof(CustomerExceptionFilterAttribute));
  159. options.Filters.Add(typeof(CustomerActionFilterAttribute));
  160. // options.Filters.ReplaceOne(x => (x as ServiceFilterAttribute)?.ServiceType?.Name == nameof(ExceptionFilterAttribute), new ServiceFilterAttribute(typeof(ABCExceptionFilterAttribute)));
  161. // options.Filters.ReplaceOne(x => (x as ServiceFilterAttribute)?.ServiceType?.Name == nameof(AbpExceptionFilter), new ServiceFilterAttribute(typeof(MyExceptionFilter)));
  162. });
  163. //context.Services.TryAddTransient<IAuthorizationMiddlewareResultHandler, AuthorizationMiddlewareResultHandler>();
  164. ///解除https限制
  165. context.Services.AddOpenIddict()
  166. .AddServer(option =>
  167. {
  168. option.UseAspNetCore().DisableTransportSecurityRequirement();
  169. });
  170. //虚拟目录
  171. context.Services.AddSingleton(new MyFileProvider(configuration["VirtualPath:RealPath"], configuration["VirtualPath:Alias"]));
  172. /*
  173. Configure<AbpAspNetCoreMvcOptions>(options =>
  174. {
  175. options.ConventionalControllers
  176. .Create(typeof(PeisApplicationModule).Assembly, opts =>
  177. {
  178. opts.RootPath = "api/app";
  179. opts.UrlControllerNameNormalizer = (controller) =>
  180. {
  181. return controller.ControllerName;
  182. };
  183. opts.UrlActionNameNormalizer = (action) =>
  184. {
  185. return action.Action.ActionName;
  186. };
  187. });
  188. });
  189. */
  190. //后台计划任务
  191. ConfigureHangfire(context, configuration);
  192. }
  193. /// <summary>
  194. /// 全局转换日期格式
  195. /// </summary>
  196. private void ConfigureJsonOptions()
  197. {
  198. //context.Services.AddControllers().AddJsonOptions(options =>
  199. //{
  200. // options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
  201. // options.JsonSerializerOptions.PropertyNamingPolicy = null;
  202. //});
  203. //Configure<JsonOptions>(x =>
  204. //{
  205. // //x.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
  206. // x.JsonSerializerOptions.Converters.Add(new DateTimeJsonConverter());
  207. // x.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
  208. //});
  209. Configure<AbpJsonOptions>(x =>
  210. {
  211. x.DefaultDateTimeFormat = "yyyy-MM-dd HH:mm:ss";
  212. });
  213. }
  214. private void ConfigureAuthentication(ServiceConfigurationContext context)
  215. {
  216. context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
  217. }
  218. private void ConfigureBundles()
  219. {
  220. Configure<AbpBundlingOptions>(options =>
  221. {
  222. options.StyleBundles.Configure(
  223. LeptonXLiteThemeBundles.Styles.Global,
  224. bundle =>
  225. {
  226. bundle.AddFiles("/global-styles.css");
  227. }
  228. );
  229. });
  230. }
  231. private void ConfigureUrls(IConfiguration configuration)
  232. {
  233. Configure<AppUrlOptions>(options =>
  234. {
  235. options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"];
  236. options.RedirectAllowedUrls.AddRange(configuration["App:RedirectAllowedUrls"].Split(','));
  237. options.Applications["Angular"].RootUrl = configuration["App:ClientUrl"];
  238. options.Applications["Angular"].Urls[AccountUrlNames.PasswordReset] = "account/reset-password";
  239. });
  240. }
  241. private void ConfigureVirtualFileSystem(ServiceConfigurationContext context)
  242. {
  243. var hostingEnvironment = context.Services.GetHostingEnvironment();
  244. if (hostingEnvironment.IsDevelopment())
  245. {
  246. Configure<AbpVirtualFileSystemOptions>(options =>
  247. {
  248. options.FileSets.ReplaceEmbeddedByPhysical<PeisDomainSharedModule>(
  249. Path.Combine(hostingEnvironment.ContentRootPath,
  250. $"..{Path.DirectorySeparatorChar}Shentun.Peis.Domain.Shared"));
  251. options.FileSets.ReplaceEmbeddedByPhysical<PeisDomainModule>(
  252. Path.Combine(hostingEnvironment.ContentRootPath,
  253. $"..{Path.DirectorySeparatorChar}Shentun.Peis.Domain"));
  254. options.FileSets.ReplaceEmbeddedByPhysical<PeisApplicationContractsModule>(
  255. Path.Combine(hostingEnvironment.ContentRootPath,
  256. $"..{Path.DirectorySeparatorChar}Shentun.Peis.Application.Contracts"));
  257. options.FileSets.ReplaceEmbeddedByPhysical<PeisApplicationModule>(
  258. Path.Combine(hostingEnvironment.ContentRootPath,
  259. $"..{Path.DirectorySeparatorChar}Shentun.Peis.Application"));
  260. });
  261. }
  262. }
  263. private void ConfigureConventionalControllers()
  264. {
  265. #region 配置隐藏api
  266. Configure<MvcOptions>(options =>
  267. {
  268. options.Conventions.Add(new ApplicationDescription());
  269. });
  270. #endregion
  271. Configure<AbpAspNetCoreMvcOptions>(options =>
  272. {
  273. options.ConventionalControllers.Create(typeof(PeisApplicationModule).Assembly);
  274. });
  275. }
  276. private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration)
  277. {
  278. context.Services.AddAbpSwaggerGenWithOAuth(
  279. configuration["AuthServer:Authority"],
  280. new Dictionary<string, string>
  281. {
  282. {"Peis", "Peis API"}
  283. },
  284. options =>
  285. {
  286. //options.SwaggerDoc("v1", new OpenApiInfo { Title = "Peis API", Version = "v1" });
  287. //options.DocInclusionPredicate((docName, description) => true);
  288. //options.CustomSchemaIds(type => type.FullName);
  289. options.SwaggerDoc("Work", new OpenApiInfo { Title = "业务API", Version = "V1", Description = "业务API" });
  290. options.SwaggerDoc("Sys", new OpenApiInfo { Title = "底层API", Version = "V1", Description = "底层API" });
  291. options.DocInclusionPredicate((docName, description) =>
  292. {
  293. if (!description.TryGetMethodInfo(out MethodInfo method))
  294. {
  295. return false;
  296. }
  297. /*使ApiExplorerSettingsAttribute里面的GroupName进行特性标识
  298. * DeclaringType只能获取controller上的特性
  299. * action的特性为主
  300. * */
  301. var version = method.DeclaringType.GetCustomAttributes(true).OfType<ApiExplorerSettingsAttribute>().Select(m => m.GroupName);
  302. if (version.Any())
  303. {
  304. if (version.Any(v => v == docName))
  305. //选择了sys,并且分组不为User
  306. return true;
  307. }
  308. else
  309. {
  310. if (docName == "Sys")
  311. {
  312. return true;
  313. }
  314. }
  315. //这里获取action的特性
  316. var actionVersion = method.GetCustomAttributes(true).OfType<ApiExplorerSettingsAttribute>().Select(m => m.GroupName);
  317. if (actionVersion.Any())
  318. {
  319. return actionVersion.Any(v => v == docName);
  320. }
  321. return false;
  322. });
  323. });
  324. }
  325. private void ConfigureLocalization()
  326. {
  327. Configure<AbpLocalizationOptions>(options =>
  328. {
  329. options.Languages.Add(new LanguageInfo("ar", "ar", "العربية"));
  330. options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština"));
  331. options.Languages.Add(new LanguageInfo("en", "en", "English"));
  332. options.Languages.Add(new LanguageInfo("en-GB", "en-GB", "English (UK)"));
  333. options.Languages.Add(new LanguageInfo("fi", "fi", "Finnish"));
  334. options.Languages.Add(new LanguageInfo("fr", "fr", "Français"));
  335. options.Languages.Add(new LanguageInfo("hi", "hi", "Hindi", "in"));
  336. options.Languages.Add(new LanguageInfo("is", "is", "Icelandic", "is"));
  337. options.Languages.Add(new LanguageInfo("it", "it", "Italiano", "it"));
  338. options.Languages.Add(new LanguageInfo("hu", "hu", "Magyar"));
  339. options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português"));
  340. options.Languages.Add(new LanguageInfo("ro-RO", "ro-RO", "Română"));
  341. options.Languages.Add(new LanguageInfo("ru", "ru", "Русский"));
  342. options.Languages.Add(new LanguageInfo("sk", "sk", "Slovak"));
  343. options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe"));
  344. options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
  345. options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文"));
  346. options.Languages.Add(new LanguageInfo("de-DE", "de-DE", "Deutsch", "de"));
  347. options.Languages.Add(new LanguageInfo("es", "es", "Español", "es"));
  348. options.Languages.Add(new LanguageInfo("el", "el", "Ελληνικά"));
  349. });
  350. }
  351. private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration)
  352. {
  353. context.Services.AddCors(options =>
  354. {
  355. options.AddDefaultPolicy(builder =>
  356. {
  357. builder
  358. .WithOrigins(
  359. configuration["App:CorsOrigins"]
  360. .Split(",", StringSplitOptions.RemoveEmptyEntries)
  361. .Select(o => o.RemovePostFix("/"))
  362. .ToArray()
  363. )
  364. .WithAbpExposedHeaders()
  365. .SetIsOriginAllowedToAllowWildcardSubdomains()
  366. .AllowAnyHeader()
  367. .AllowAnyMethod()
  368. .AllowCredentials();
  369. });
  370. });
  371. //添加swagger中文注释
  372. context.Services.AddSwaggerGen(options =>
  373. {
  374. //var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
  375. var baseDirectory = AppContext.BaseDirectory;
  376. //Serilog.Log.Information("swagger地址1:" + baseDirectory);
  377. //var baseDirectory2 = Path.GetDirectoryName(typeof(Program).Assembly.Location);
  378. //Serilog.Log.Information("swagger地址2:" + baseDirectory2);
  379. //var baseDirectory3 = AppDomain.CurrentDomain.BaseDirectory;
  380. //Serilog.Log.Information("swagger地址3:" + baseDirectory3);
  381. var commentsFile = Path.Combine(baseDirectory, "Shentun.Peis.Application.xml");
  382. options.IncludeXmlComments(commentsFile, true);
  383. var commentsFileDro = Path.Combine(baseDirectory, "Shentun.Peis.Application.Contracts.xml");
  384. options.IncludeXmlComments(commentsFileDro, true);
  385. var commentsFileapi = Path.Combine(baseDirectory, "Shentun.Peis.HttpApi.xml");
  386. options.IncludeXmlComments(commentsFileapi, true);
  387. });
  388. }
  389. private void ConfigureHangfire(ServiceConfigurationContext context, IConfiguration configuration)
  390. {
  391. context.Services.AddHangfire(config =>
  392. {
  393. config.UsePostgreSqlStorage(configuration.GetConnectionString("Default"));
  394. });
  395. //context.Services.AddHangfireServer();
  396. }
  397. public override async void OnApplicationInitialization(ApplicationInitializationContext context)
  398. {
  399. var app = context.GetApplicationBuilder();
  400. var env = context.GetEnvironment();
  401. var configuration = context.GetConfiguration();
  402. //请求错误提示配置
  403. // app.UseErrorHandling();
  404. if (env.IsDevelopment())
  405. {
  406. app.UseDeveloperExceptionPage();
  407. }
  408. app.UseAbpRequestLocalization();
  409. if (!env.IsDevelopment())
  410. {
  411. app.UseErrorPage();
  412. }
  413. app.UseHangfireDashboard("/hangfire", new DashboardOptions
  414. {
  415. Authorization = new[] { new CustomAuthorizeFilter() }
  416. });
  417. app.UseCorrelationId();
  418. //var staticFile = new StaticFileOptions();
  419. //var filePath = env.ContentRootPath+"UpLoad\\";
  420. ////var filePath = env.ContentRootPath ;
  421. //staticFile.FileProvider = new PhysicalFileProvider(filePath);
  422. //app.UseStaticFiles(new StaticFileOptions
  423. //{
  424. // FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "UpLoad")),
  425. // RequestPath="/UpLoad"
  426. //});
  427. app.UseStaticFiles();
  428. app.UseStaticFiles(new StaticFileOptions
  429. {
  430. FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "ReportFile")),
  431. RequestPath = "/ReportFile"
  432. });
  433. app.UseStaticFiles(new StaticFileOptions
  434. {
  435. FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "photo")),
  436. RequestPath = "/photo"
  437. });
  438. app.UseStaticFiles(new StaticFileOptions
  439. {
  440. FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "UserPhoto")),
  441. RequestPath = "/UserPhoto"
  442. });
  443. app.UseStaticFiles(new StaticFileOptions
  444. {
  445. FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "UserSign")),
  446. RequestPath = "/UserSign"
  447. });
  448. //虚拟目录
  449. app.UseStaticFiles(new StaticFileOptions
  450. {
  451. FileProvider = new PhysicalFileProvider(configuration["VirtualPath:RealPath"]),
  452. RequestPath = configuration["VirtualPath:RequestPath"]
  453. });
  454. app.UseRouting();
  455. app.UseCors();
  456. app.UseAuthentication();
  457. app.UseAbpOpenIddictValidation();
  458. if (MultiTenancyConsts.IsEnabled)
  459. {
  460. app.UseMultiTenancy();
  461. }
  462. app.UseUnitOfWork();
  463. app.UseAuthorization();
  464. //app.UseMiddleware(typeof(AuthorizationMiddlewareResultHandler));
  465. app.UseSwagger();
  466. app.UseAbpSwaggerUI(c =>
  467. {
  468. //c.SwaggerEndpoint("/swagger/v1/swagger.json", "Peis API");
  469. c.SwaggerEndpoint($"/swagger/Work/swagger.json", "业务API"); //分组显示
  470. c.SwaggerEndpoint($"/swagger/Sys/swagger.json", "底层API"); //分组显示
  471. //c.RoutePrefix = string.Empty; // url 中不显示swagger
  472. var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
  473. c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
  474. c.OAuthScopes("Peis");
  475. c.DefaultModelExpandDepth(-1);
  476. });
  477. app.UseAuditing();
  478. app.UseAbpSerilogEnrichers();
  479. app.UseConfiguredEndpoints();
  480. //任务计划
  481. await StartScheduler(context);
  482. }
  483. private async Task StartScheduler(ApplicationInitializationContext context)
  484. {
  485. //await context.AddBackgroundWorkerAsync<ChargeRequestInterfaceQueryWorker>();
  486. //RecurringJob.AddOrUpdate<IChargeRequestInterfaceQueryWorker>("收费接口", o => o.DoWorkAsync(new Guid("")), CheckedBills, TimeZoneInfo.Local);
  487. //BackgroundJob.Enqueue<ChargeRequestInterfaceQueryWorker>(x => x.DoWorkWithArgAsync(new Guid("")));
  488. var appServiceHelper = new AppServiceHelper();
  489. await appServiceHelper.LoginAsync();
  490. var thirdInterFaceForHostOutDto = await appServiceHelper.CallAppServiceAsync<object, ThirdInterFaceForHostOutDto>("api/app/ThirdInterface/GetList", null);
  491. if (thirdInterFaceForHostOutDto != null)
  492. {
  493. foreach (var thirdInterfaceDto in thirdInterFaceForHostOutDto.Data)
  494. {
  495. if (thirdInterfaceDto.IsActive != 'Y')
  496. {
  497. continue;
  498. }
  499. var parmValue = thirdInterfaceDto.ParmValue;
  500. if (!string.IsNullOrWhiteSpace(parmValue))
  501. {
  502. var configurationBuilder = new ConfigurationBuilder()
  503. .AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
  504. IConfigurationRoot interfaceConfig;
  505. try
  506. {
  507. interfaceConfig = configurationBuilder.Build();
  508. }
  509. catch (Exception ex)
  510. {
  511. continue;
  512. }
  513. var isActive = interfaceConfig.GetSection("Interface").GetSection("Scheduler")
  514. .GetSection("IsActive").Value;
  515. var corn = interfaceConfig.GetSection("Interface").GetSection("Scheduler")
  516. .GetSection("Corn").Value;
  517. if (isActive == "Y")
  518. {
  519. if (thirdInterfaceDto.ThirdInterfaceType == "02")
  520. {
  521. RecurringJob.AddOrUpdate<IChargeRequestInterfaceQueryWorker>("收费接口", o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  522. }
  523. else if (thirdInterfaceDto.ThirdInterfaceType == "03")
  524. {
  525. RecurringJob.AddOrUpdate<IImportLisResultInterfaceWorker>("导入检验结果接口", o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  526. }
  527. else if (thirdInterfaceDto.ThirdInterfaceType == "04")
  528. {
  529. RecurringJob.AddOrUpdate<IImportPacsResultInterfaceWorker>("导入Pacs结果接口", o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  530. }
  531. else if (thirdInterfaceDto.ThirdInterfaceType == "05")
  532. {
  533. RecurringJob.AddOrUpdate<IImportPatientRegisterInterfaceWorker>("导入人员登记信息结果接口", o => o.DoWork(thirdInterfaceDto.Id), corn, TimeZoneInfo.Local);
  534. }
  535. }
  536. }
  537. }
  538. }
  539. }
  540. }