Merge branch 'S07' into test
This commit is contained in:
commit
9440670511
@ -100,6 +100,7 @@ public class WarningTaskService : IWarningTaskService, ITransientDependency
|
||||
items = updateInputs.Cast<dynamic>().ToList();
|
||||
}
|
||||
|
||||
var retryCountChanged = false;
|
||||
// 2.请求
|
||||
try
|
||||
{
|
||||
@ -124,6 +125,7 @@ public class WarningTaskService : IWarningTaskService, ITransientDependency
|
||||
|
||||
// 处理调用接口通失败,直接处于完结状态
|
||||
await HandlerCallBusinessException(task, msg);
|
||||
retryCountChanged = true;
|
||||
throw new BusinessException(message: msg);
|
||||
}
|
||||
}
|
||||
@ -136,8 +138,11 @@ public class WarningTaskService : IWarningTaskService, ITransientDependency
|
||||
finally
|
||||
{
|
||||
// 3.维护回传预警明细的重试次数
|
||||
var warningDetailsIds = task.WarningDetailIds.Split(',').ToHashSet();
|
||||
await _warningDetailsEsRepository.ReturnWarningDetailsRetryIncrementAsync(warningDetailsIds);
|
||||
if (!retryCountChanged)
|
||||
{
|
||||
var warningDetailsIds = task.WarningDetailIds.Split(',').ToHashSet();
|
||||
await _warningDetailsEsRepository.ReturnWarningDetailsRetryIncrementAsync(warningDetailsIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,6 +159,8 @@ public class WarningTaskService : IWarningTaskService, ITransientDependency
|
||||
var addNotifyTasks = new List<WarningNotifyTaskEntity>();
|
||||
foreach (var detail in warningDetails)
|
||||
{
|
||||
// 重试次数+1
|
||||
detail.RetryCount++;
|
||||
if (detail.Status == ReturnWarningStatus.已关闭.GetHashCode())
|
||||
continue;
|
||||
|
||||
|
||||
@ -67,19 +67,47 @@ public sealed class CompleteWarningHandler : ICompleteWarningHandler, ITransient
|
||||
});
|
||||
if (warningDetails.Count == 0) return;
|
||||
|
||||
// 查询规则项目
|
||||
var ruleItemIds = warningDetails.Select(x => x.CompleteWarningRuleItemId).ToHashSet();
|
||||
var ruleItems = await _warningRuleRepository.GetCompleteRuleItemsAsync(ruleItemIds);
|
||||
var ruleItemDict = ruleItems.ToDictionary(x => x.Id);
|
||||
|
||||
// 4.处理明细
|
||||
var closeDetailIds = new HashSet<string>();
|
||||
foreach (var details in warningDetails)
|
||||
var updateDetails = new List<CompleteWarningDetailsIndex>();
|
||||
foreach (var detail in warningDetails)
|
||||
{
|
||||
var trackStatusIds = orderIdTrackStatusGroupsDict.GetValueOrDefault(details.OrderId);
|
||||
// 订单无任何轨迹,或者不存在检查点状态轨迹
|
||||
if (trackStatusIds == null || !trackStatusIds.ContainsKey(details.CheckPointTrackStatusId))
|
||||
var ruleItem = ruleItemDict.GetValueOrDefault(detail.CompleteWarningRuleItemId);
|
||||
// 规则配置不存在直接关闭
|
||||
if (ruleItem == null)
|
||||
{
|
||||
closeDetailIds.Add(details.Id);
|
||||
closeDetailIds.Add(detail.Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
var trackStatusIdDict = orderIdTrackStatusGroupsDict.GetValueOrDefault(detail.OrderId);
|
||||
// 订单无任何轨迹,或者不存在检查点状态轨迹
|
||||
if (trackStatusIdDict == null || !trackStatusIdDict.ContainsKey(detail.CheckPointTrackStatusId))
|
||||
{
|
||||
closeDetailIds.Add(detail.Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 查看缺失轨迹状态表达式是否有变化,如果有则更新
|
||||
var trackStatusIds = trackStatusIdDict.Keys.ToHashSet();
|
||||
var expression = BuildMissingTrackStatusIdExpression(ruleItem, trackStatusIds);
|
||||
if (!string.Equals(detail.MissingTrackStatusIds, expression))
|
||||
{
|
||||
detail.MissingTrackStatusIds = expression;
|
||||
updateDetails.Add(detail);
|
||||
}
|
||||
|
||||
// todo:需要处理要求轨迹完整的情况?
|
||||
}
|
||||
|
||||
if (updateDetails.Count > 0)
|
||||
await _warningDetailsEsRepository.BulkUpdateCompleteWarningDetailsAsync(updateDetails);
|
||||
|
||||
if (closeDetailIds.Count == 0) return;
|
||||
|
||||
// 5.预警信息状态修改为【已关闭】
|
||||
@ -166,7 +194,7 @@ public sealed class CompleteWarningHandler : ICompleteWarningHandler, ITransient
|
||||
// 生成预警明细
|
||||
var needAddDetails = hitRuleItems
|
||||
.Where(x => hitRuleItemIds.Contains(x.Id))
|
||||
.Select(x => BuildCompleteWarningDetails(order, x, rule.Version));
|
||||
.Select(x => BuildCompleteWarningDetails(order, trackStatusIds, x, rule.Version));
|
||||
|
||||
addDetails.AddRange(needAddDetails);
|
||||
}
|
||||
@ -185,7 +213,7 @@ public sealed class CompleteWarningHandler : ICompleteWarningHandler, ITransient
|
||||
await _warningTaskRepository.BulkInsertWarningNotifyTaskAsync(notifyTasks);
|
||||
}
|
||||
|
||||
private static CompleteWarningDetailsIndex BuildCompleteWarningDetails(OrderEntity order, CompleteWarningRuleItemEntity ruleItem, string version)
|
||||
private static CompleteWarningDetailsIndex BuildCompleteWarningDetails(OrderEntity order, HashSet<int> trackStatusIds, CompleteWarningRuleItemEntity ruleItem, string version)
|
||||
{
|
||||
return new CompleteWarningDetailsIndex()
|
||||
{
|
||||
@ -197,7 +225,7 @@ public sealed class CompleteWarningHandler : ICompleteWarningHandler, ITransient
|
||||
// NotifyModes = ruleItem.NotifyModes,
|
||||
NotifyUsers = ruleItem.NotifyUsers,
|
||||
CheckPointTrackStatusId = ruleItem.CheckPointTrackStatusId,
|
||||
MissingTrackStatusIds = ruleItem.RequireTrackStatusIdExpression, //tips:是否需要明确缺失哪个状态?
|
||||
MissingTrackStatusIds = BuildMissingTrackStatusIdExpression(ruleItem, trackStatusIds),
|
||||
|
||||
SubSystemId = order.SubSystemId,
|
||||
CustomId = order.CustomId,
|
||||
@ -226,6 +254,21 @@ public sealed class CompleteWarningHandler : ICompleteWarningHandler, ITransient
|
||||
).ToList();
|
||||
}
|
||||
|
||||
// 根据规则和已有轨迹,构建缺失轨迹状态表达式
|
||||
private static string BuildMissingTrackStatusIdExpression(CompleteWarningRuleItemEntity ruleItem, HashSet<int> trackStatusIds)
|
||||
{
|
||||
// 构建实际缺失的状态
|
||||
var missingGroups = new List<HashSet<int>>();
|
||||
foreach (var group in ruleItem.GetRequireTrackStatusIdGroups())
|
||||
{
|
||||
if (group.Intersect(trackStatusIds).Any())
|
||||
continue;
|
||||
missingGroups.Add(group);
|
||||
}
|
||||
|
||||
return string.Join(',', missingGroups.Select(sub => string.Join('/', sub)));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region todo-test: 预警主体关闭
|
||||
|
||||
Loading…
Reference in New Issue
Block a user