diff --git a/src/SJZY.Track.Application/BackgroundServices/OrderPullStatusScanner.cs b/src/SJZY.Track.Application/BackgroundServices/OrderPullStatusScanner.cs index f334db45..e2fb7bd0 100644 --- a/src/SJZY.Track.Application/BackgroundServices/OrderPullStatusScanner.cs +++ b/src/SJZY.Track.Application/BackgroundServices/OrderPullStatusScanner.cs @@ -1,5 +1,8 @@ +using System.Diagnostics; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; using SJZY.Expand.ABP.Core.Logger; +using SJZY.Track.Application.Options; using SJZY.Track.Domain.Aggregates.OrderAggregate; namespace SJZY.Track.Application.BackgroundServices; @@ -9,25 +12,25 @@ namespace SJZY.Track.Application.BackgroundServices; /// public class OrderPullStatusScanner : BackgroundService { + private readonly IOptionsMonitor _options; private readonly IOrderRepository _orderRepository; - public OrderPullStatusScanner(IOrderRepository orderRepository) + public OrderPullStatusScanner(IOrderRepository orderRepository, IOptionsMonitor options) { _orderRepository = orderRepository; + _options = options; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - var count = await _orderRepository.UpdatePullStatusBySilenceAsync(); - if (count > 0) - { - LogHelper.Info($"{nameof(OrderPullStatusScanner)}本次扫描更新了{count}条订单拉取状态"); - } - + var stopwatch = Stopwatch.StartNew(); + var count1 = await _orderRepository.UpdatePullStatusBySilenceAsync(); // real del - count = await _orderRepository.ClearPullStatusAsync(); - LogHelper.Info($"{nameof(OrderPullStatusScanner)}本次扫描删除了{count}条订单拉取状态"); + var count2 = await _orderRepository.ClearPullStatusAsync(); + stopwatch.Stop(); + LogHelper.Info( + $"{nameof(OrderPullStatusScanner)}本次扫描更新了{count1}条,删除了{count2}条订单拉取状态,耗时{stopwatch.ElapsedMilliseconds}ms"); - await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken); + await Task.Delay(TimeSpan.FromSeconds(_options.CurrentValue.OrderPullStatusScanInterval), stoppingToken); } } diff --git a/src/SJZY.Track.Application/BackgroundServices/TrackButtonUpScanner.cs b/src/SJZY.Track.Application/BackgroundServices/TrackButtomUpScanner.cs similarity index 93% rename from src/SJZY.Track.Application/BackgroundServices/TrackButtonUpScanner.cs rename to src/SJZY.Track.Application/BackgroundServices/TrackButtomUpScanner.cs index 2fc53b30..bce80945 100644 --- a/src/SJZY.Track.Application/BackgroundServices/TrackButtonUpScanner.cs +++ b/src/SJZY.Track.Application/BackgroundServices/TrackButtomUpScanner.cs @@ -1,8 +1,10 @@ using System.Linq.Expressions; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; using Newtonsoft.Json.Linq; using SJZY.Track.Application.Contract.Dtos.TrackPull; using SJZY.Track.Application.Helpers; +using SJZY.Track.Application.Options; using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Enums; using SJZY.Track.Domain.Queries; @@ -10,17 +12,20 @@ using SJZY.Track.Domain.Queries; namespace SJZY.Track.Application.BackgroundServices; /// -/// 轨迹兜底扫描 +/// 轨迹(发生地时区)兜底扫描 /// -public class TrackButtonUpScanner : BackgroundService +public class TrackButtomUpScanner : BackgroundService { + private readonly IOptionsMonitor _options; private readonly IOrderRepository _orderRepository; private readonly ITimezoneQueries _timezoneQueries; - public TrackButtonUpScanner(ITimezoneQueries timezoneQueries, IOrderRepository orderRepository) + public TrackButtomUpScanner(ITimezoneQueries timezoneQueries, IOrderRepository orderRepository, + IOptionsMonitor options) { _timezoneQueries = timezoneQueries; _orderRepository = orderRepository; + _options = options; } protected override Task ExecuteAsync(CancellationToken stoppingToken) diff --git a/src/SJZY.Track.Application/Options/TrackAppOptions.cs b/src/SJZY.Track.Application/Options/TrackAppOptions.cs new file mode 100644 index 00000000..423e3fc2 --- /dev/null +++ b/src/SJZY.Track.Application/Options/TrackAppOptions.cs @@ -0,0 +1,19 @@ +namespace SJZY.Track.Application.Options; + +public class TrackAppOptions +{ + /// + /// 轨迹刷新并发度 + /// + public int TrackRefreshFetchCount { get; set; } + + /// + /// 订单拉取状态扫描间隔(秒) + /// + public int OrderPullStatusScanInterval { get; set; } + + /// + /// 轨迹兜底扫描间隔(秒) + /// + public int TrackButtomUpScanInterval { get; set; } +} diff --git a/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs b/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs index 1ea550bc..0462b016 100644 --- a/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs +++ b/src/SJZY.Track.Application/SjzyTrackApplicationModule.cs @@ -12,6 +12,7 @@ using SJZY.Track.Application.BackgroundServices; using SJZY.Track.Application.CAP; using SJZY.Track.Application.Contract; using SJZY.Track.Application.Localization; +using SJZY.Track.Application.Options; using SJZY.Track.Application.Track2InterfaceRelay; using SJZY.UserCenter.Contracts; using SJZY.UserCenter.SharedModel; @@ -138,7 +139,7 @@ public class SjzyTrackApplicationModule : AbpModule new() { Queue = GlobalConst.TrackRefreshSubscribe, - FetchCount = configuration.GetValue("RabbitMQ:TrackRefreshFetchCount"), + FetchCount = configuration.GetValue("TrackApp:TrackRefreshFetchCount"), FailedRequeue = false, Declaration = o => { @@ -151,8 +152,9 @@ public class SjzyTrackApplicationModule : AbpModule }; }, typeof(SjzyTrackApplicationModule).Assembly); + context.Services.Configure(configuration.GetSection("TrackApp")); context.Services.AddHostedService(); - context.Services.AddHostedService(); + context.Services.AddHostedService(); } public override void PreConfigureServices(ServiceConfigurationContext context) diff --git a/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs b/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs index eb6ad9f1..09644e01 100644 --- a/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs @@ -169,11 +169,11 @@ public class TrackDetailsEsRepository : ElasticSearchContextAbstract s .Source(@" - ctx._source.TrackPlace = params.trackPlace; - ctx._source.TrackTime = params.trackTime; - ctx._source.TrackTimeZone = params.trackTimeZone; - ctx._source.UpdateUser = params.updateUser; - ctx._source.UpdateTime = params.updateTime; + ctx._source.trackPlace = params.trackPlace; + ctx._source.trackTime = params.trackTime; + ctx._source.trackTimeZone = params.trackTimeZone; + ctx._source.updateUser = params.updateUser; + ctx._source.updateTime = params.updateTime; ") .Params(p => p .Add("trackPlace", track.TrackPlace)