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.

675 lines
25 KiB

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