From 6e0ff2961433f6c50342868cc7c30d630e51a41b Mon Sep 17 00:00:00 2001
From: hardstylewyl <827778732@qq.com>
Date: Mon, 30 Dec 2024 09:41:56 +0800
Subject: [PATCH] =?UTF-8?q?update:=E5=B9=BF=E6=92=AD=E6=9C=8D=E5=8A=A1?=
=?UTF-8?q?=E6=8A=BD=E8=B1=A1=E5=87=BA=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Dtos/TrackPush/TrackPushRecordDto.cs | 89 +++++++++++++++++++
.../Services/IBroadcastingService.cs | 22 +++++
.../EventHandlers/TrackUpsertEventHandler.cs | 9 +-
.../Rabbit/TrackPushCompletedEventHandler.cs | 32 ++++++-
.../Broadcasting/BroadcastingService.cs | 24 ++---
.../Dtos/TrackContents/TrackContentVO.cs | 5 ++
.../Queries/IProvideQueries.cs | 8 ++
.../Queries/ProvideQueries.cs | 24 +++++
8 files changed, 192 insertions(+), 21 deletions(-)
create mode 100644 src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushRecordDto.cs
create mode 100644 src/SJZY.Track.Application.Contract/Services/IBroadcastingService.cs
diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushRecordDto.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushRecordDto.cs
new file mode 100644
index 00000000..7bb84c1c
--- /dev/null
+++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/TrackPushRecordDto.cs
@@ -0,0 +1,89 @@
+namespace SJZY.Track.Application.Contract.Dtos.TrackPush;
+
+public class TrackPushRecordDto
+{
+ ///
+ /// 子系统代码
+ ///
+ public string SubSystemCode { get; set; }
+
+ ///
+ /// 是否为手动推送
+ ///
+ public bool IsManualPush { get; set; }
+
+ ///
+ /// 推送时间
+ ///
+ public DateTime PushTime { get; set; }
+
+ ///
+ /// 操作人
+ ///
+ public string? OperationMan { get; set; }
+
+ ///
+ /// 订单号
+ ///
+ public string OrderNo { get; set; } = null!;
+
+ ///
+ /// 接口通请求Id
+ ///
+ public Guid RequestId { get; set; }
+
+ ///
+ /// 信息
+ ///
+ public string Message { get; set; } = null!;
+
+ ///
+ /// 操作类型
+ ///
+ public string OptionType { get; set; } = null!;
+
+ ///
+ /// 轨迹状态
+ ///
+ public string TrackStatus { get; set; } = null!;
+
+ ///
+ /// 轨迹内容代码
+ ///
+ public string TrackCode { get; set; } = null!;
+
+ ///
+ /// 轨迹内容
+ ///
+ public string TrackContent { get; set; } = null!;
+
+ ///
+ /// 轨迹发生地
+ ///
+ public string TrackPlace { get; set; } = null!;
+
+ ///
+ /// 轨迹发生时间
+ ///
+ public DateTime TrackTime { get; set; }
+
+ ///
+ /// 轨迹发生时区
+ ///
+ public float TrackTimeZone { get; set; }
+
+ ///
+ /// 是否成功
+ ///
+ public bool IsSuccess { get; set; }
+
+ ///
+ /// 推送内容(json)
+ ///
+ public string PushContent { get; set; } = null!;
+
+ ///
+ /// 轨迹的额外新
+ ///
+ public string? Extra { get; set; }
+}
diff --git a/src/SJZY.Track.Application.Contract/Services/IBroadcastingService.cs b/src/SJZY.Track.Application.Contract/Services/IBroadcastingService.cs
new file mode 100644
index 00000000..1b2fdbd9
--- /dev/null
+++ b/src/SJZY.Track.Application.Contract/Services/IBroadcastingService.cs
@@ -0,0 +1,22 @@
+using SJZY.Track.Application.Contract.Dtos.TrackPush;
+using SJZY.Track.Application.Contract.Events;
+using Volo.Abp.DependencyInjection;
+
+namespace SJZY.Track.Application.Contract.Services;
+
+public interface IBroadcastingService :ITransientDependency
+{
+ ///
+ /// 轨迹变更广播
+ ///
+ ///
+ ///
+ ///
+ void TrackChangePublicTopicAsync(TrackUpsertEvent eto, string subSystemCode, string trackStatusCode);
+
+ ///
+ /// 轨迹推送完成广播
+ ///
+ ///
+ void TrackPushCompletedPublicTopicAsync(TrackPushRecordDto log);
+}
diff --git a/src/SJZY.Track.Application/CAP/EventHandlers/TrackUpsertEventHandler.cs b/src/SJZY.Track.Application/CAP/EventHandlers/TrackUpsertEventHandler.cs
index f1f3747d..85266ae1 100644
--- a/src/SJZY.Track.Application/CAP/EventHandlers/TrackUpsertEventHandler.cs
+++ b/src/SJZY.Track.Application/CAP/EventHandlers/TrackUpsertEventHandler.cs
@@ -2,7 +2,7 @@ using DotNetCore.CAP;
using SJZY.Expand.ABP.Core.Logger;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Application.Contract.Events;
-using SJZY.Track.Application.Services.Broadcasting;
+using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
using SJZY.Track.Domain.Dtos.TrackContents;
@@ -19,7 +19,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
private readonly IOrderRepository _orderRepository;
private readonly IProvideQueries _provideQueries;
private readonly ITrackDetailsEsRepository _trackDetailsEsRepository;
- private readonly BroadcastingService _broadcastingService;
+ private readonly IBroadcastingService _broadcastingService;
private readonly IOrderOperationRecordEsRepository _orderOperationRecordEsRepository;
public TrackUpsertEventHandler(
@@ -28,7 +28,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
IProvideQueries provideQueries,
ITrackDetailsEsRepository trackDetailsEsRepository,
IOrderOperationRecordEsRepository orderOperationRecordEsRepository,
- BroadcastingService broadcastingService)
+ IBroadcastingService broadcastingService)
{
_orderRepository = orderRepository;
_capPublisher = capPublisher;
@@ -50,8 +50,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
// 处理广播事件
if (content != null && (content.IsToMq || @event.IsToMq))
- // todo: review BroadcastingService抽一层接口,面向抽象编程
- _broadcastingService.TrackChangePublicTopicAsync(@event, content);
+ _broadcastingService.TrackChangePublicTopicAsync(@event, content.SubSystemCode, content.TrackStatusCode);
if (canNextOrderIds.Count == 0) return;
// 根据订单关联关系异步向下刷(异步)
diff --git a/src/SJZY.Track.Application/Rabbit/TrackPushCompletedEventHandler.cs b/src/SJZY.Track.Application/Rabbit/TrackPushCompletedEventHandler.cs
index 471ea081..8144eb1c 100644
--- a/src/SJZY.Track.Application/Rabbit/TrackPushCompletedEventHandler.cs
+++ b/src/SJZY.Track.Application/Rabbit/TrackPushCompletedEventHandler.cs
@@ -6,8 +6,8 @@ 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.Contract.Services;
using SJZY.Track.Application.Helpers;
-using SJZY.Track.Application.Services.Broadcasting;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Enums;
@@ -19,11 +19,11 @@ public class TrackPushCompletedEventHandler : ITransientDependency, IRabbitHandl
{
private readonly IOrderRepository _orderRepository;
private readonly ITrackPushRecordEsRepository _trackPushRecordEsRepository;
- private readonly BroadcastingService _broadcastingService;
+ private readonly IBroadcastingService _broadcastingService;
public TrackPushCompletedEventHandler(IOrderRepository orderRepository,
ITrackPushRecordEsRepository trackPushRecordEsRepository,
- BroadcastingService broadcastingService)
+ IBroadcastingService broadcastingService)
{
_orderRepository = orderRepository;
_trackPushRecordEsRepository = trackPushRecordEsRepository;
@@ -70,7 +70,7 @@ public class TrackPushCompletedEventHandler : ITransientDependency, IRabbitHandl
// 推送广播
if (log.IsToMq)
- _broadcastingService.TrackPushCompletedPublicTopicAsync(log);
+ _broadcastingService.TrackPushCompletedPublicTopicAsync(BuildDto(log));
// 往es 写推送日志
await _trackPushRecordEsRepository.AddAsync(log);
@@ -119,4 +119,28 @@ public class TrackPushCompletedEventHandler : ITransientDependency, IRabbitHandl
});
}
}
+
+ private TrackPushRecordDto BuildDto(TrackPushRecordIndex log)
+ {
+ return new TrackPushRecordDto
+ {
+ SubSystemCode = log.SubSystemCode,
+ RequestId = log.RequestId,
+ IsSuccess = log.IsSuccess,
+ Message = log.Message,
+ OperationMan = log.CreateUser,
+ PushTime = DateTime.Now,
+ OptionType = log.OptionType,
+ IsManualPush = !string.Equals(log.CreateUser, GlobalConst.SystemUser), //操作人不为系统用户,则认为是仍推送
+ PushContent = log.PushContent,
+ OrderNo = log.OrderNo,
+ TrackStatus = log.TrackStatus,
+ TrackContent = log.TrackContent,
+ TrackTimeZone = log.TrackTimeZone,
+ TrackTime = log.TrackTime,
+ TrackPlace = log.TrackPlace,
+ TrackCode = log.TrackCode,
+ Extra = log.Extra
+ };
+ }
}
diff --git a/src/SJZY.Track.Application/Services/Broadcasting/BroadcastingService.cs b/src/SJZY.Track.Application/Services/Broadcasting/BroadcastingService.cs
index 7e02475e..1fc0f24a 100644
--- a/src/SJZY.Track.Application/Services/Broadcasting/BroadcastingService.cs
+++ b/src/SJZY.Track.Application/Services/Broadcasting/BroadcastingService.cs
@@ -1,17 +1,16 @@
using System.Text;
using BSI.Stack.Rabbit;
using SJZY.Expand.ABP.Core.PublicMethords;
+using SJZY.Track.Application.Contract.Dtos.TrackPush;
using SJZY.Track.Application.Contract.Events;
-using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
-using SJZY.Track.Domain.Dtos.TrackContents;
-using Volo.Abp.DependencyInjection;
+using SJZY.Track.Application.Contract.Services;
namespace SJZY.Track.Application.Services.Broadcasting;
///
/// 广播服务
///
-public class BroadcastingService : ITransientDependency
+public class BroadcastingService : IBroadcastingService
{
private readonly RabbitClientBus _rabbitClientBus;
@@ -24,9 +23,10 @@ public class BroadcastingService : ITransientDependency
/// 轨迹变更广播
///
///
- ///
+ /// 子系统代码
+ /// 轨迹状态代码
///
- public void TrackChangePublicTopicAsync(TrackUpsertEvent eto, TrackContentVO content)
+ public void TrackChangePublicTopicAsync(TrackUpsertEvent eto, string subSystemCode, string trackStatusCode)
{
var data = new TrackChangeEto
{
@@ -45,7 +45,7 @@ public class BroadcastingService : ITransientDependency
TrackTimeZone = eto.TrackTimeZone,
TrackTime = eto.TrackTime,
TrackPlace = eto.TrackPlace,
- TrackStatusCode = content.TrackStatusCode,
+ TrackStatusCode = trackStatusCode,
EnStatus = eto.EnStatus,
Content = eto.Content,
TrackCode = eto.TrackCode,
@@ -61,7 +61,7 @@ public class BroadcastingService : ITransientDependency
else
data.Option = 3;
- _rabbitClientBus.Publish(GlobalConst.TrackChangeExchange, $"TrackChange.{content.SubSystemCode}",
+ _rabbitClientBus.Publish(GlobalConst.TrackChangeExchange, $"TrackChange.{subSystemCode}",
Encoding.UTF8.GetBytes(data.ToJson()));
}
@@ -70,17 +70,17 @@ public class BroadcastingService : ITransientDependency
///
///
///
- public void TrackPushCompletedPublicTopicAsync(TrackPushRecordIndex log)
+ public void TrackPushCompletedPublicTopicAsync(TrackPushRecordDto log)
{
var data = new TrackPushCompletedEvent
{
RequestId = log.RequestId,
IsSuccess = log.IsSuccess,
Message = log.Message,
- OperationMan = log.CreateUser,
- PushTime = DateTime.Now,
+ OperationMan = log.OperationMan,
+ PushTime = log.PushTime,
OptionType = log.OptionType,
- IsManualPush = !string.Equals(log.CreateUser, GlobalConst.SystemUser), //操作人不为系统用户,则认为是仍推送
+ IsManualPush = log.IsManualPush, //操作人不为系统用户,则认为是仍推送
PushContent = log.PushContent,
OrderNo = log.OrderNo,
TrackStatus = log.TrackStatus,
diff --git a/src/SJZY.Track.Domain/Dtos/TrackContents/TrackContentVO.cs b/src/SJZY.Track.Domain/Dtos/TrackContents/TrackContentVO.cs
index 07982ec1..374787e5 100644
--- a/src/SJZY.Track.Domain/Dtos/TrackContents/TrackContentVO.cs
+++ b/src/SJZY.Track.Domain/Dtos/TrackContents/TrackContentVO.cs
@@ -2,6 +2,11 @@ namespace SJZY.Track.Domain.Dtos.TrackContents;
public class TrackContentVO
{
+ ///
+ /// 子系统Id
+ ///
+ public int SubSystemId { get; set; }
+
///
/// 子系统代码
///
diff --git a/src/SJZY.Track.Domain/Queries/IProvideQueries.cs b/src/SJZY.Track.Domain/Queries/IProvideQueries.cs
index 351224c5..d955ffda 100644
--- a/src/SJZY.Track.Domain/Queries/IProvideQueries.cs
+++ b/src/SJZY.Track.Domain/Queries/IProvideQueries.cs
@@ -52,6 +52,14 @@ public interface IProvideQueries
///
Task GetTrackContentAsync(int subSystemId, string trackCode);
+ ///
+ /// 获取轨迹内容
+ ///
+ /// 子系统ids
+ /// 轨迹代码集合
+ ///
+ Task> GetTrackContentsAsync(int[] subSystemIds, string[] trackCodes);
+
///
/// 获取所有拉取配置
///
diff --git a/src/SJZY.Track.Repository/Queries/ProvideQueries.cs b/src/SJZY.Track.Repository/Queries/ProvideQueries.cs
index b59a308d..d60f5cf0 100644
--- a/src/SJZY.Track.Repository/Queries/ProvideQueries.cs
+++ b/src/SJZY.Track.Repository/Queries/ProvideQueries.cs
@@ -117,6 +117,30 @@ public class ProvideQueries : ISugarRepository, IProvideQueries, ITransientDepen
.FirstAsync();
}
+ public async Task> GetTrackContentsAsync(int[] subSystemIds, string[] trackCodes)
+ {
+ return await Context.Queryable()
+ .LeftJoin((x, y) => x.TrackStatusId == y.Id)
+ .LeftJoin((x, y, z) => x.SubSystemId == z.Id)
+ .Where(x => subSystemIds.Contains(x.SubSystemId) && trackCodes.Contains(x.Code))
+ .Select((x, y, z) => new TrackContentVO
+ {
+ SubSystemId = x.SubSystemId,
+ SubSystemCode = z.Key,
+ TrackStatusId = x.TrackStatusId,
+ TrackStatus = y.Status,
+ TrackStatusCode = y.Code,
+ TrackContent = x.Content,
+ TrackEnContent = x.EnContent,
+ IsCompleted = y.IsCompleted,
+ IsRepeatable = x.IsRepeatable,
+ IsAllowManuallyUpdate = x.IsAllowManuallyUpdate,
+ IsAllowManuallyCreate = x.IsAllowManuallyCreate,
+ IsToMq = y.IsToMq,
+ })
+ .ToListAsync();
+ }
+
public async Task> GetAllPullConfigsAsync()
{
return await Context.Queryable()