From 60571b3224fea1e129a437a83742ca34e4d670be Mon Sep 17 00:00:00 2001
From: xiaolipro <2357729423@qq.com>
Date: Wed, 9 Oct 2024 11:52:04 +0800
Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E6=A0=B9=E6=8D=AE=E8=AE=A2?=
=?UTF-8?q?=E5=8D=95=E5=8F=B7=E6=9F=A5=E8=AF=A2=E6=97=B6=E6=95=88=E9=A2=84?=
=?UTF-8?q?=E8=AD=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Dtos/Forewarning/WarningOrderDto.cs | 5 +++++
.../Events/TrackWarningCalcEvent.cs | 2 +-
.../CAP/EventHandlers/TrackUpsertEventHandler.cs | 2 +-
.../EventHandlers/TrackWarningCalcEventHandler.cs | 1 +
.../ForewarningNotifyService.cs | 6 +++++-
.../Services/TrackOrders/OrderWarningService.cs | 4 +---
.../ForewarningAggregate/WarningRecordIndex.cs | 5 +++++
src/SJZY.Track.Domain/Queries/IWarningQueries.cs | 8 ++++++++
.../Queries/WarningQueries.cs | 14 ++++++++++++++
.../Repositories/WarningRecordEsRepository.cs | 2 +-
10 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningOrderDto.cs b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningOrderDto.cs
index 198686e0..0fa46590 100644
--- a/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningOrderDto.cs
+++ b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningOrderDto.cs
@@ -7,6 +7,11 @@ public class WarningOrderDto
///
public int Id { get; set; }
+ ///
+ /// 订单号
+ ///
+ public string OrderNo { get; set; } = null!;
+
///
/// 轨迹发生时间
///
diff --git a/src/SJZY.Track.Application.Contract/Events/TrackWarningCalcEvent.cs b/src/SJZY.Track.Application.Contract/Events/TrackWarningCalcEvent.cs
index 3808ab2e..f2031f12 100644
--- a/src/SJZY.Track.Application.Contract/Events/TrackWarningCalcEvent.cs
+++ b/src/SJZY.Track.Application.Contract/Events/TrackWarningCalcEvent.cs
@@ -20,7 +20,7 @@ public class TrackWarningCalcEvent
///
/// 订单id
///
- public int[] OrderIds { get; set; } = null!;
+ public int[] OrderIds { get; set; }
///
/// 轨迹发生时间
diff --git a/src/SJZY.Track.Application/CAP/EventHandlers/TrackUpsertEventHandler.cs b/src/SJZY.Track.Application/CAP/EventHandlers/TrackUpsertEventHandler.cs
index 25af80ba..f30f51fc 100644
--- a/src/SJZY.Track.Application/CAP/EventHandlers/TrackUpsertEventHandler.cs
+++ b/src/SJZY.Track.Application/CAP/EventHandlers/TrackUpsertEventHandler.cs
@@ -154,7 +154,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
{
SubSystemId = @event.SubSystemId,
CustomId = @event.CustomId,
- OrderIds = canNextOrderIds.ToArray(),
+ OrderIds = insertTracks.Select(x => x.OrderId).ToArray(),
TrackStatusId = trackContent.TrackStatusId,
TrackTime = @event.TrackTime,
});
diff --git a/src/SJZY.Track.Application/CAP/EventHandlers/TrackWarningCalcEventHandler.cs b/src/SJZY.Track.Application/CAP/EventHandlers/TrackWarningCalcEventHandler.cs
index acefee10..0acde53b 100644
--- a/src/SJZY.Track.Application/CAP/EventHandlers/TrackWarningCalcEventHandler.cs
+++ b/src/SJZY.Track.Application/CAP/EventHandlers/TrackWarningCalcEventHandler.cs
@@ -59,6 +59,7 @@ public class TrackWarningCalcEventHandler : ITransientDependency, ICapSubscribe
Orders = orders.Select(order => new WarningOrderDto
{
Id = order.Id,
+ OrderNo = order.OrderNo,
TrackTime = @event.TrackTime,
CargoType = order.CargoType,
Month = order.CreateTime.Month,
diff --git a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs
index c6019cfd..2bccdb60 100644
--- a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs
+++ b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs
@@ -148,7 +148,9 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
private async Task> WriteWarningRecordAsync(List entries,
List notifyRules)
{
- // todo:重复校验
+ var orders = await _warningQueries.GetOrderNoByIdsAsync(entries.Select(x => x.OrderId).ToArray());
+ var orderNoDict = orders.ToDictionary(x => x.Id, x => x.Name);
+
var warningRecords = new List();
foreach (var entry in entries)
{
@@ -169,6 +171,7 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
Counter = entry.Counter,
IsLast = rule.WarnCount == entry.Counter,
OrderId = entry.OrderId,
+ OrderNo = orderNoDict[entry.OrderId],
WarningStatus = WarningStatus.UnProcessed,
NotifyUserId = notifyUser.UserId,
NotifyUserName = notifyUser.UserName,
@@ -177,6 +180,7 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
}
}
+ // 批量写入es
await _warningRecordEsRepository.BulkInsertAsync(warningRecords);
return warningRecords;
}
diff --git a/src/SJZY.Track.Application/Services/TrackOrders/OrderWarningService.cs b/src/SJZY.Track.Application/Services/TrackOrders/OrderWarningService.cs
index 3afedec2..f4ed6560 100644
--- a/src/SJZY.Track.Application/Services/TrackOrders/OrderWarningService.cs
+++ b/src/SJZY.Track.Application/Services/TrackOrders/OrderWarningService.cs
@@ -39,8 +39,7 @@ public class OrderWarningService : ApplicationService
x.Id,
x.LatestTrackContent,
x.LatestTrackTime,
- x.LatestTrackPlace,
- x.OrderNo
+ x.LatestTrackPlace
});
var list = new List();
@@ -61,7 +60,6 @@ public class OrderWarningService : ApplicationService
};
var order = orders.FirstOrDefault(o => o.Id == x.OrderId);
if (order == default) return;
- item.OrderNo = order.OrderNo;
item.LatestTrackTime = order.LatestTrackTime;
item.LatestTrackPlace = order.LatestTrackPlace;
item.LatestTrackContent = order.LatestTrackContent;
diff --git a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRecordIndex.cs b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRecordIndex.cs
index c7305d1c..4b700010 100644
--- a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRecordIndex.cs
+++ b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRecordIndex.cs
@@ -47,6 +47,11 @@ public class WarningRecordIndex : IdBaseIndex
///
public int OrderId { get; set; }
+ ///
+ /// 订单号
+ ///
+ public string OrderNo { get; set; } = null!;
+
///
/// 预警规则
///
diff --git a/src/SJZY.Track.Domain/Queries/IWarningQueries.cs b/src/SJZY.Track.Domain/Queries/IWarningQueries.cs
index e6a7ce00..ce4ecb0e 100644
--- a/src/SJZY.Track.Domain/Queries/IWarningQueries.cs
+++ b/src/SJZY.Track.Domain/Queries/IWarningQueries.cs
@@ -1,3 +1,4 @@
+using SJZY.Track.Domain.Dtos.Common;
using SJZY.Track.Domain.Dtos.Forewarning;
namespace SJZY.Track.Domain.Queries;
@@ -24,4 +25,11 @@ public interface IWarningQueries
///
///
Task> GetWarningRuleByAreaId(int areaId);
+
+ ///
+ /// 订单id换name
+ ///
+ ///
+ ///
+ Task> GetOrderNoByIdsAsync(int[] orderIds);
}
diff --git a/src/SJZY.Track.Repository/Queries/WarningQueries.cs b/src/SJZY.Track.Repository/Queries/WarningQueries.cs
index 7554e5f7..6171244d 100644
--- a/src/SJZY.Track.Repository/Queries/WarningQueries.cs
+++ b/src/SJZY.Track.Repository/Queries/WarningQueries.cs
@@ -1,6 +1,8 @@
using Newtonsoft.Json;
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
using SJZY.Track.Domain.Aggregates.KPIAreaAggregate;
+using SJZY.Track.Domain.Aggregates.OrderAggregate;
+using SJZY.Track.Domain.Dtos.Common;
using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.Queries;
using SJZY.Track.Domain.VEntities;
@@ -93,4 +95,16 @@ public class WarningQueries : ISugarRepository, IWarningQueries,
})
.ToListAsync();
}
+
+ public async Task> GetOrderNoByIdsAsync(int[] orderIds)
+ {
+ return await Context.Queryable()
+ .Where(x => orderIds.Contains(x.Id))
+ .Select(x => new IdWithNameDto
+ {
+ Id = x.Id,
+ Name = x.OrderNo
+ })
+ .ToListAsync();
+ }
}
diff --git a/src/SJZY.Track.Repository/Repositories/WarningRecordEsRepository.cs b/src/SJZY.Track.Repository/Repositories/WarningRecordEsRepository.cs
index 04db2769..5911da19 100644
--- a/src/SJZY.Track.Repository/Repositories/WarningRecordEsRepository.cs
+++ b/src/SJZY.Track.Repository/Repositories/WarningRecordEsRepository.cs
@@ -74,7 +74,7 @@ public class WarningRecordEsRepository : ElasticSearchContextAbstract f.SubSystemId, input.SubSystemId) : null)
&& (!input.OrderNos.IsNullOrEmpty()
? q.Terms(t => t
- .Field(f => f.OrderId.Suffix("keyword"))
+ .Field(f => f.OrderNo.Suffix("keyword"))
.Terms(input.OrderNos))
: null)
&& (input.WarningStatus.HasValue ? q.Term(f => f.WarningStatus, input.WarningStatus) : null)