diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackRefreshAttach.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackRefreshAttach.cs
index 651e5000..38d01ed5 100644
--- a/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackRefreshAttach.cs
+++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPull/TrackRefreshAttach.cs
@@ -2,18 +2,20 @@ namespace SJZY.Track.Application.Contract.Dtos.TrackPull;
public class TrackRefreshAttach
{
- public TrackRefreshAttach(int serviceProviderId, string serviceProviderName, int subSystemId, int orderType)
+ public TrackRefreshAttach(string serviceProviderCode, string serviceProviderName, string subSystemCode,
+ int subSystemId, int orderType)
{
- ServiceProviderId = serviceProviderId;
+ ServiceProviderCode = serviceProviderCode;
ServiceProviderName = serviceProviderName;
+ SubSystemCode = subSystemCode;
SubSystemId = subSystemId;
OrderType = orderType;
}
///
- /// 服务商id
+ /// 服务商code
///
- public int ServiceProviderId { get; set; }
+ public string ServiceProviderCode { get; set; }
///
/// 服务商name
@@ -25,6 +27,11 @@ public class TrackRefreshAttach
///
public int OrderType { get; set; }
+ ///
+ /// 子系统code
+ ///
+ public string SubSystemCode { get; set; }
+
///
/// 子系统id
///
diff --git a/src/SJZY.Track.Application.Contract/Services/ITrackPullCacheService.cs b/src/SJZY.Track.Application.Contract/Services/ITrackPullCacheService.cs
index d74dea96..da3fb64b 100644
--- a/src/SJZY.Track.Application.Contract/Services/ITrackPullCacheService.cs
+++ b/src/SJZY.Track.Application.Contract/Services/ITrackPullCacheService.cs
@@ -4,31 +4,22 @@ namespace SJZY.Track.Application.Contract.Services;
public interface ITrackPullCacheService
{
- string TrackPullKey(int subSystemId, int serviceProviderId);
- string TrackPullContentKey(int subSystemId, int serviceProviderId);
-
- ///
- /// 获取所有拉取配置
- ///
- ///
- Task> GetAllPullConfigsAsync();
+ string TrackPullKey(string subSystemCode, string serviceProviderCode);
+ string TrackPullContentKey(string subSystemCode, string serviceProviderCode);
///
/// 获取服务商拉取配置
///
- /// 子系统id
- /// 服务商id
+ /// 子系统code
+ /// 服务商code
///
Task
- GetPullParamsWithContentAsync(int subSystemId, int serviceProviderId);
+ GetPullParamsWithContentAsync(string subSystemCode, string serviceProviderCode);
///
/// 设置拉取配置缓存
///
///
- /// 子系统id
- /// 服务商id
///
- Task SetPullConfigAsync(int? id = null, int? subSystemId = null,
- int? serviceProviderId = null);
+ Task SetPullConfigAsync(int id);
}
diff --git a/src/SJZY.Track.Application/CAP/EventHandlers/TrackPushCompletedEventHandler.cs b/src/SJZY.Track.Application/Rabbit/TrackPushCompletedEventHandler.cs
similarity index 75%
rename from src/SJZY.Track.Application/CAP/EventHandlers/TrackPushCompletedEventHandler.cs
rename to src/SJZY.Track.Application/Rabbit/TrackPushCompletedEventHandler.cs
index e10d40fd..348d7a4b 100644
--- a/src/SJZY.Track.Application/CAP/EventHandlers/TrackPushCompletedEventHandler.cs
+++ b/src/SJZY.Track.Application/Rabbit/TrackPushCompletedEventHandler.cs
@@ -1,5 +1,9 @@
-using DotNetCore.CAP;
+using System.Text;
+using BSI.Stack.Rabbit;
+using BSI.Stack.Rabbit.Handler;
using Newtonsoft.Json;
+using RabbitMQ.Client.Events;
+using SJZY.Expand.ABP.Core.Logger;
using SJZY.InterfaceRelay.Application.Contracts;
using SJZY.Track.Application.Contract.Dtos.TrackPush;
using SJZY.Track.Application.Helpers;
@@ -8,23 +12,36 @@ using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Enums;
using Volo.Abp.DependencyInjection;
-namespace SJZY.Track.Application.CAP.EventHandlers;
+namespace SJZY.Track.Application.Rabbit;
-public class TrackPushCompletedEventHandler : ITransientDependency, ICapSubscribe
+public class TrackPushCompletedEventHandler : ITransientDependency, IRabbitHandler
{
private readonly IOrderRepository _orderRepository;
private readonly ITrackPushRecordEsRepository _trackPushRecordEsRepository;
- public TrackPushCompletedEventHandler(ITrackPushRecordEsRepository trackPushRecordEsRepository,
- IOrderRepository orderRepository)
+ public TrackPushCompletedEventHandler(IOrderRepository orderRepository,
+ ITrackPushRecordEsRepository trackPushRecordEsRepository)
{
- _trackPushRecordEsRepository = trackPushRecordEsRepository;
_orderRepository = orderRepository;
+ _trackPushRecordEsRepository = trackPushRecordEsRepository;
}
- [CapSubscribe(GlobalConst.TrackPushCompletedSubscribe, Group = GlobalConst.TrackPushSubscribe)]
- public async Task ConsumerAsync(InterfaceRelayForwardReplayEvent @event)
+ public bool Enable(ConsumeOptions options)
{
+ return options.Queue == GlobalConst.TrackPushCompletedSubscribe;
+ }
+
+ public async Task Handle(IServiceProvider sp, BasicDeliverEventArgs args, ConsumeOptions options)
+ {
+ var msg = Encoding.UTF8.GetString(args.Body.ToArray());
+ var @event = System.Text.Json.JsonSerializer.Deserialize(msg);
+ if (@event == null)
+ {
+ LogHelper.Warn(
+ $"rabbit on queue({options.Queue}) received msg can't convert to {nameof(InterfaceRelayForwardReplayEvent)}");
+ return;
+ }
+
string? logStr = null;
var optionType = Base64Helper.DeSerialize(@event.Attach);
if (optionType == OptionType.新增.ToString())
@@ -47,17 +64,6 @@ public class TrackPushCompletedEventHandler : ITransientDependency, ICapSubscrib
// 往es 写推送日志
await _trackPushRecordEsRepository.AddAsync(log);
- // if (!log.IsSuccess)
- // {
- // // 重试过程中不会去更新订单主表
- // if (@event.RetryNum < 3)
- // {
- // @event.RetryNum++;
- // await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, @event);
- // return;
- // }
- // }
-
// 同步去更新订单主表
await TrackPushAfterUpdateOrderAsync(log);
}
diff --git a/src/SJZY.Track.Application/Rabbit/TrackRefreshEventHandler.cs b/src/SJZY.Track.Application/Rabbit/TrackRefreshEventHandler.cs
index fd31a601..e456bf44 100644
--- a/src/SJZY.Track.Application/Rabbit/TrackRefreshEventHandler.cs
+++ b/src/SJZY.Track.Application/Rabbit/TrackRefreshEventHandler.cs
@@ -79,8 +79,8 @@ public class TrackRefreshEventHandler : ITransientDependency, IRabbitHandler
return;
}
- var config = await _trackPullCacheService.GetPullParamsWithContentAsync(attach.SubSystemId,
- attach.ServiceProviderId);
+ var config = await _trackPullCacheService.GetPullParamsWithContentAsync(attach.SubSystemCode,
+ attach.ServiceProviderCode);
if (config == null)
{
_logger.LogWarning("请求id: {@RequestId},轨迹消费失败,找不到拉取配置:{@Attach}", attach.ToJson(), @event.RequestId);
diff --git a/src/SJZY.Track.Application/SJZY.Track.Application.csproj b/src/SJZY.Track.Application/SJZY.Track.Application.csproj
index cf712237..407f97d8 100644
--- a/src/SJZY.Track.Application/SJZY.Track.Application.csproj
+++ b/src/SJZY.Track.Application/SJZY.Track.Application.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackPullService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackPullService.cs
index 377edd93..59d127e5 100644
--- a/src/SJZY.Track.Application/Services/ProvideServices/TrackPullService.cs
+++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackPullService.cs
@@ -8,6 +8,8 @@ using SJZY.Track.Application.Contract.Dtos.TrackPull;
using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Application.Helpers;
using SJZY.Track.Application.Rabbit;
+using SJZY.Track.Application.Track2InterfaceRelay;
+using SJZY.Track.Domain.Dtos.TrackPull;
using SJZY.Track.Domain.Queries;
using Volo.Abp.Http.Client.DynamicProxying;
@@ -58,6 +60,7 @@ public class TrackPullService : ApplicationService
{
x.ServiceProviderName,
x.SubSystemId,
+ x.SubSystemCode,
x.OrderType
}))
{
@@ -68,14 +71,20 @@ public class TrackPullService : ApplicationService
var serviceProviderCode = group.FirstOrDefault()!.ServiceProviderCode;
var attach = Base64Helper.SerializeObject(group.Key);
- // 批量获取轨迹
- var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
- InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data, GlobalConst.TrackRefreshSubscribe,
- attach);
- if (res.Code != InterfaceRelayConst.SuccessCode)
+ using (Track2InterfaceRelaySubSystemContext.Use(
+ new Track2InterfaceRelaySubSystemContext(group.Key.SubSystemCode)))
{
- LogHelper.Error($"刷新轨迹失败:{res.ToJson()}");
+ // 批量获取轨迹
+ var res = await _httpClientProxy.Service.BatchForwardThenPushToQueueAsync(
+ InterfaceRelayConst.GetTrackInterfaceCode, serviceProviderCode, data,
+ GlobalConst.TrackRefreshSubscribe,
+ attach);
+
+ if (res.Code != InterfaceRelayConst.SuccessCode)
+ {
+ LogHelper.Error($"刷新轨迹失败:{res.ToJson()}");
+ }
}
}
@@ -90,7 +99,7 @@ public class TrackPullService : ApplicationService
[HttpPost("Track/RefreshForTask")]
public async Task RefreshForTaskAsync()
{
- var configs = await _trackPullCacheService.GetAllPullConfigsAsync();
+ var configs = await _provideQueries.GetAllPullConfigsAsync();
foreach (var config in configs)
{
@@ -118,9 +127,9 @@ public class TrackPullService : ApplicationService
return true;
}
- private async Task RefreshForConfigAsync(TrackPullConfigDto config)
+ private async Task RefreshForConfigAsync(TrackPullConfigVo config)
{
- var redisKey = _trackPullCacheService.TrackPullKey(config.SubSystemId, config.ServiceProviderId);
+ var redisKey = _trackPullCacheService.TrackPullKey(config.SubSystemCode, config.ServiceProviderCode);
if (await RedisHelper.Client.ExistsAsync(redisKey))
{
return;
@@ -130,36 +139,38 @@ public class TrackPullService : ApplicationService
{
try
{
- var page = 1;
- var orders = await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, page);
- while (orders.Any())
+ using (Track2InterfaceRelaySubSystemContext.Use(
+ new Track2InterfaceRelaySubSystemContext(config.SubSystemCode)))
{
- var serviceProviderCode = orders.FirstOrDefault()?.ServiceProviderCode;
- var serviceProviderName = orders.FirstOrDefault()?.ServiceProviderName;
-
- foreach (var group in orders.GroupBy(x => new
+ var page = 1;
+ var orders =
+ await _provideQueries.FindOrderWithServiceProviderAsync(config.ServiceProviderId, page);
+ while (orders.Any())
{
- x.SubSystemId,
- x.OrderType
- }))
- {
- var data = new List