fix:预警计算-时间单位是小时

This commit is contained in:
xiaolipro 2024-09-30 17:53:45 +08:00
parent 7cebc4ee37
commit 276263f85b

View File

@ -64,12 +64,12 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
).ForEach(rule =>
{
var interval = (rule.TotalTimeSpan - rule.WarnTimeSpan) / rule.WarnCount;
var startTime = order.TrackTime.AddMinutes(rule.WarnTimeSpan);
var startTime = order.TrackTime.AddHours(rule.WarnTimeSpan);
for (var i = 0; i < rule.WarnCount; i++)
{
var timestamp = GetTimestamp(startTime);
startTime = startTime.AddMinutes(interval);
startTime = startTime.AddHours(interval);
// 计算预警时间戳,作为排序依据
adds.Add((rule.Id, order.Id, i, timestamp));
@ -92,10 +92,8 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
var redisKey = GetForewarningNotifySetKeyRedisKey(dto.SubSystemId);
long addCounter, delCounter = 0;
var tran = RedisHelper.Client.Multi();
// 左区间加入预警队列,【只有第一次发生的才会被加入】
addCounter = await tran.ZAddNxAsync(redisKey, adds.Select(x =>
addCounter = await RedisHelper.Client.ZAddNxAsync(redisKey, adds.Select(x =>
{
var entry = new WarningNotifyCacheEntry(x.ruleId, x.orderId, x.counter);
return new ZMember(entry.ToString(), x.ts);
@ -105,11 +103,9 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
var right = dels.Select(x => new WarningNotifyCacheEntry(x.ruleId, x.orderId, x.counter)).ToList();
if (!right.IsNullOrEmpty())
{
delCounter = await tran.ZRemAsync(redisKey, right.Select(x => x.ToString()).ToArray());
delCounter = await RedisHelper.Client.ZRemAsync(redisKey, right.Select(x => x.ToString()).ToArray());
}
tran.Exec();
LogHelper.Info($"本次共计产生{addCounter}条预警,移除{delCounter}条预警,触发缘由是{dto}");
await _warningRecordEsRepository.BulkUpdateAsync(dels); // 标记处理完成
@ -146,6 +142,7 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
private async Task<List<WarningRecordIndex>> WriteWarningRecordAsync(List<WarningNotifyCacheEntry> entries,
List<GetWarningNotifiesVo> notifyRules)
{
// todo:重复校验
var warningRecords = new List<WarningRecordIndex>();
foreach (var entry in entries)
{