fix:根据订单号查询时效预警

This commit is contained in:
xiaolipro 2024-10-09 11:52:04 +08:00
parent ec04a43d44
commit 60571b3224
10 changed files with 42 additions and 7 deletions

View File

@ -7,6 +7,11 @@ public class WarningOrderDto
/// </summary>
public int Id { get; set; }
/// <summary>
/// 订单号
/// </summary>
public string OrderNo { get; set; } = null!;
/// <summary>
/// 轨迹发生时间
/// </summary>

View File

@ -20,7 +20,7 @@ public class TrackWarningCalcEvent
/// <summary>
/// 订单id
/// </summary>
public int[] OrderIds { get; set; } = null!;
public int[] OrderIds { get; set; }
/// <summary>
/// 轨迹发生时间

View File

@ -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,
});

View File

@ -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,

View File

@ -148,7 +148,9 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
private async Task<List<WarningRecordIndex>> WriteWarningRecordAsync(List<WarningNotifyCacheEntry> entries,
List<GetWarningNotifiesVo> 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<WarningRecordIndex>();
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;
}

View File

@ -39,8 +39,7 @@ public class OrderWarningService : ApplicationService
x.Id,
x.LatestTrackContent,
x.LatestTrackTime,
x.LatestTrackPlace,
x.OrderNo
x.LatestTrackPlace
});
var list = new List<GetOrderWarningPageOutput>();
@ -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;

View File

@ -47,6 +47,11 @@ public class WarningRecordIndex : IdBaseIndex
/// </summary>
public int OrderId { get; set; }
/// <summary>
/// 订单号
/// </summary>
public string OrderNo { get; set; } = null!;
/// <summary>
/// 预警规则
/// </summary>

View File

@ -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
/// <param name="areaId"></param>
/// <returns></returns>
Task<List<RuleAreaBaseInfoVo>> GetWarningRuleByAreaId(int areaId);
/// <summary>
/// 订单id换name
/// </summary>
/// <param name="orderIds"></param>
/// <returns></returns>
Task<List<IdWithNameDto>> GetOrderNoByIdsAsync(int[] orderIds);
}

View File

@ -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<List<IdWithNameDto>> GetOrderNoByIdsAsync(int[] orderIds)
{
return await Context.Queryable<OrderEntity>()
.Where(x => orderIds.Contains(x.Id))
.Select(x => new IdWithNameDto
{
Id = x.Id,
Name = x.OrderNo
})
.ToListAsync();
}
}

View File

@ -74,7 +74,7 @@ public class WarningRecordEsRepository : ElasticSearchContextAbstract<WarningRec
(input.SubSystemId.HasValue ? q.Term(f => 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)