diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Controllers/HomeController.cs b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Controllers/HomeController.cs index 98f7010f..b234e987 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Controllers/HomeController.cs +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Controllers/HomeController.cs @@ -1,14 +1,29 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.SignalR; +using SettleAccount.Job.SignalR; using Volo.Abp.AspNetCore.Mvc; namespace Win.Sfs.SettleAccount.Controllers { public class HomeController : AbpController { + private readonly IHubContext _hubContext; + + public HomeController(IHubContext hubContext) + { + this._hubContext = hubContext; + } + [ResponseCache(NoStore = true)] public ActionResult Index() { return File("~/index.html", "text/html"); } + + public IActionResult Test() + { + this._hubContext.Clients.All.ServerToClient("test", "hello", ""); + return Json("ok"); + } } } diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Program.cs b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Program.cs index 90ac0bf8..a17adf98 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Program.cs +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Program.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.IO; +using Magicodes.ExporterAndImporter.Excel.Utility.TemplateExport; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -39,10 +40,10 @@ namespace Win.Sfs.SettleAccount Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) + .WriteTo.Async(c => c.Console()) .CreateLogger(); - try { Log.Information("Starting web host."); diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/SettleAccount.HttpApi.Host.csproj b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/SettleAccount.HttpApi.Host.csproj index a3fa5f85..fa4ebe42 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/SettleAccount.HttpApi.Host.csproj +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/SettleAccount.HttpApi.Host.csproj @@ -20,6 +20,7 @@ + diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Startup.cs b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Startup.cs index 3f07a301..69545588 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Startup.cs +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Startup.cs @@ -1,4 +1,8 @@ -using Microsoft.AspNetCore.Builder; +using System; +using System.Linq; +using System.Text.RegularExpressions; +using Coravel; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Routing; @@ -6,47 +10,100 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using System.Text.RegularExpressions; +using NUglify.Helpers; +using SettleAccount.Job.SignalR; +using Win.Sfs.SettleAccount.Entities.BQ.Vmi; + +namespace Win.Sfs.SettleAccount; -namespace Win.Sfs.SettleAccount +public class Startup { - public class Startup + public void ConfigureServices(IServiceCollection services) { - public void ConfigureServices(IServiceCollection services) + services.AddSignalR(o => o.EnableDetailedErrors=true); + AppDomain.CurrentDomain.GetAssemblies().SelectMany(o => o.GetTypes()) + .Where(o => o.IsClass && !o.IsAbstract && o.IsAssignableTo(typeof(IJobService))) + .ForEach(o => services.AddTransient(o)); + services.AddScheduler(); + services.AddRouting(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); + services.AddMvc(options => options.Conventions.Add(new RouteTokenTransformerConvention(new SlugifyParameterTransformer()))); + services.AddApplication(); + services.Configure(options => { - services.AddRouting(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer)); - services.AddMvc(options => options.Conventions.Add(new RouteTokenTransformerConvention(new SlugifyParameterTransformer()))); - services.AddApplication(); - services.Configure(options => - { - // Set the limit to 256 MB - options.Limits.MaxRequestBodySize = 268435456; - }); - //上传文件大小限制IIS设置 - services.Configure(options => - { - options.MaxRequestBodySize = 268435456; - options.AllowSynchronousIO = true; - }); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) + // Set the limit to 256 MB + options.Limits.MaxRequestBodySize = 268435456; + }); + //上传文件大小限制IIS设置 + services.Configure(options => { - var contentTypeProvider = new FileExtensionContentTypeProvider(); - contentTypeProvider.Mappings.Add(".mjs", "text/javascript"); - app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = contentTypeProvider }); - app.InitializeApplication(); - } + options.MaxRequestBodySize = 268435456; + options.AllowSynchronousIO = true; + }); + } - public class SlugifyParameterTransformer : IOutboundParameterTransformer + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) + { + app.UseRouting(); + app.UseEndpoints(endpoints => endpoints.MapHub("/api/hub")); + app.ApplicationServices.UseScheduler(scheduler => { - public string TransformOutbound(object value) + using var scope = app.ApplicationServices.CreateScope(); + var jobs = scope.ServiceProvider.GetService().Set().ToList(); + jobs?.ForEach(job => { - if (value == null) { return null; } - var str = value.ToString(); - if (string.IsNullOrEmpty(str)) { return null; } - return Regex.Replace(str?.ToString(), "([a-z])([A-Z])", "$1-$2").ToLowerInvariant(); - } + var jobId = job.Id; + using var scope = app.ApplicationServices.CreateScope(); + var serviceType = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).FirstOrDefault(o => o.FullName == job.Service); + if (serviceType != null) + { + if (scope.ServiceProvider.GetService(serviceType) is IJobService jobService) + { + scheduler.Schedule(() => + { + using var scope = app.ApplicationServices.CreateScope(); + var db = scope.ServiceProvider.GetService(); + var jobItemRepository = db.Set(); + var jobLogRepository = db.Set(); + var jobItem = jobItemRepository.FirstOrDefault(o => o.Id == jobId); + jobItem.IsRunning = true; + db.SaveChanges(); + var jobLog = new JobLog { JobId = jobId, Start = DateTime.Now }; + try + { + jobService.Invoke(); + jobLog.Success = true; + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + jobLog.Exception = ex.ToString(); + } + finally + { + jobLog.End = DateTime.Now; + jobLogRepository.Add(jobLog); + jobItem.IsRunning = false; + db.SaveChanges(); + } + }).Cron(job.Cron); + } + } + }); + }); + var contentTypeProvider = new FileExtensionContentTypeProvider(); + contentTypeProvider.Mappings.Add(".mjs", "text/javascript"); + app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = contentTypeProvider }); + app.InitializeApplication(); + } + + public class SlugifyParameterTransformer : IOutboundParameterTransformer + { + public string TransformOutbound(object value) + { + if (value == null) { return null; } + var str = value.ToString(); + if (string.IsNullOrEmpty(str)) { return null; } + return Regex.Replace(str?.ToString(), "([a-z])([A-Z])", "$1-$2").ToLowerInvariant(); } } -} \ No newline at end of file +} diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/appsettings.json b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/appsettings.json index f10a45c0..d71a2bda 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/appsettings.json +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/appsettings.json @@ -1,4 +1,4 @@ -{ +{ "App": { "CorsOrigins": "https://*.abc.com,http://localhost:9527,http://149.223.116.5:8088" }, diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/list/index.js b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/list/index.js index 481d2f9c..ef2dc6d7 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/list/index.js +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/list/index.js @@ -33,7 +33,7 @@ export default { :hideButton="true" :isQueryForm="true" > -