fix:轨迹刷新

This commit is contained in:
xiaolipro 2024-08-05 16:08:50 +08:00
parent a3c4199a30
commit 5a90c99f51
2 changed files with 44 additions and 49 deletions

View File

@ -1,5 +1,8 @@
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using SJZY.Expand.ABP.Core; using SJZY.Expand.ABP.Core;
using SJZY.Expand.ABP.Core.Logger;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.InterfaceRelay.Application.Contracts; using SJZY.InterfaceRelay.Application.Contracts;
using SJZY.Track.Application.Contract.Dtos.ProvideServices; using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Dtos.TrackPull; using SJZY.Track.Application.Contract.Dtos.TrackPull;
@ -78,51 +81,44 @@ public class TrackPullService : ApplicationService
/// <returns></returns> /// <returns></returns>
[AllowAnonymous] [AllowAnonymous]
[HttpPost("Track/RefreshForTask")] [HttpPost("Track/RefreshForTask")]
public bool RefreshForTaskAsync() public async Task<bool> RefreshForTaskAsync()
{ {
Task.Run(async () => var configs = await _trackPullCacheService.GetAllPullConfigsAsync();
{ var tasks = configs.Select(RefreshForConfigAsync).ToArray();
var configs = await _trackPullCacheService.GetAllPullConfigsAsync(); await Task.WhenAll(tasks);
foreach (var config in configs)
{
var redisKey = _trackPullCacheService.TrackPullKey(config.SubSystemId, config.ServiceProviderId);
if (await RedisHelper.Client.ExistsAsync(redisKey))
{
continue;
}
var page = 1;
var orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, page);
while (orders.Any())
{
var serviceProviderCode = orders.FirstOrDefault()?.ServiceProviderCode;
var serviceProviderName = orders.FirstOrDefault()?.ServiceProviderName;
foreach (var group in orders.GroupBy(x =>
new { x.SubSystemId, x.OrderType }))
{
var data = group.Select(x => new
{
x.OrderNo
}).ToList();
var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(config.ServiceProviderId,
serviceProviderName!,
group.Key.SubSystemId, group.Key.OrderType));
// 批量获取轨迹
await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data,
GlobalConst.TrackRefreshSubscribe, attach);
}
orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, ++page);
}
await RedisHelper.Client.SetExAsync(redisKey, config.PullInterval * 60, orders.Count);
}
});
return true; return true;
} }
private async Task RefreshForConfigAsync(TrackPullConfigDto config)
{
var redisKey = _trackPullCacheService.TrackPullKey(config.SubSystemId, config.ServiceProviderId);
if (await RedisHelper.Client.ExistsAsync(redisKey))
{
return;
}
var page = 1;
var orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, page, 2000);
while (orders.Any())
{
var serviceProviderCode = orders.FirstOrDefault()?.ServiceProviderCode;
var serviceProviderName = orders.FirstOrDefault()?.ServiceProviderName;
foreach (var group in orders.GroupBy(x => new { x.SubSystemId, x.OrderType }))
{
var data = group.Select(x => new { x.OrderNo }).ToList();
var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(config.ServiceProviderId, serviceProviderName!, group.Key.SubSystemId, group.Key.OrderType));
var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data, GlobalConst.TrackRefreshSubscribe, attach);
if (res.Code != InterfaceRelayConst.SuccessCode)
{
LogHelper.Error($"刷新轨迹失败:{res.ToJson()}");
}
}
orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, ++page);
}
await RedisHelper.Client.SetExAsync(redisKey, config.PullInterval * 60, orders.Count);
}
} }

View File

@ -32,7 +32,6 @@ public class TrackPushService : ApplicationService
_capPublisher = capPublisher; _capPublisher = capPublisher;
_trackPushRecordsRepository = trackPushRecordsRepository; _trackPushRecordsRepository = trackPushRecordsRepository;
_requestCurrentUserService = requestCurrentUserService; _requestCurrentUserService = requestCurrentUserService;
} }
/// <summary> /// <summary>
@ -92,7 +91,7 @@ public class TrackPushService : ApplicationService
[HttpPost("Track/PushWarnForTask")] [HttpPost("Track/PushWarnForTask")]
public async Task<string> PushWarnForTaskAsync() public async Task<string> PushWarnForTaskAsync()
{ {
int total = 0, pageSize = 1000,waitTime = 1000; int total = 0, pageSize = 1000, waitTime = 1000;
var dateTimes = Enumerable.Range(1, 12).Select(val => DateTime.Now.AddHours(-val)).ToList(); var dateTimes = Enumerable.Range(1, 12).Select(val => DateTime.Now.AddHours(-val)).ToList();
foreach (var dateTime in dateTimes) foreach (var dateTime in dateTimes)
@ -101,11 +100,11 @@ public class TrackPushService : ApplicationService
var pageindex = 1; var pageindex = 1;
do do
{ {
rows = await _orderRepository.PushWarnOrdersAsync(pageSize,pageindex,dateTime); rows = await _orderRepository.PushWarnOrdersAsync(pageSize, pageindex, dateTime);
total+=rows; total += rows;
pageindex++; pageindex++;
await Task.Delay(waitTime); await Task.Delay(waitTime);
}while (rows!= pageSize); } while (rows != pageSize);
} }
return $"本次预警扫描了:{total}个订单"; return $"本次预警扫描了:{total}个订单";