review
This commit is contained in:
parent
d41c5e444f
commit
73422ba703
@ -5,8 +5,4 @@ public struct OrderIdentifier
|
||||
public int OrderId { get; set; }
|
||||
public string OrderNo { get; set; }
|
||||
public int OrderType { get; set; }
|
||||
|
||||
public int CustomId { get; set; }
|
||||
|
||||
public bool IsTrigger { get; set; }
|
||||
}
|
||||
@ -2,6 +2,16 @@
|
||||
|
||||
public class TrackChangeAfterUpdateOrderEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// 子系统id
|
||||
/// </summary>
|
||||
public int SubSystemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 客户id
|
||||
/// </summary>
|
||||
public int CustomId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单Id
|
||||
/// </summary>
|
||||
|
||||
@ -3,10 +3,15 @@
|
||||
public class TrackUpsertEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// 子系统id(操作的订单都是相同子系统下的)
|
||||
/// 子系统id
|
||||
/// </summary>
|
||||
public int SubSystemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 客户id
|
||||
/// </summary>
|
||||
public int CustomId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单id
|
||||
/// </summary>
|
||||
|
||||
@ -4,5 +4,19 @@ namespace SJZY.Track.Application.Contract.Services;
|
||||
|
||||
public interface IForewarningCacheService
|
||||
{
|
||||
Task<List<ForewarningRuleCacheEntry>> GetRulesAsync(int subSystemId);
|
||||
/// <summary>
|
||||
/// 获取预警规则,如果没有则返回null
|
||||
/// </summary>
|
||||
/// <param name="subSystemId">子系统id</param>
|
||||
/// <param name="customerId">客户id</param>
|
||||
/// <returns></returns>
|
||||
Task<List<ForewarningRuleCacheEntry>?> GetRulesAsync(int subSystemId, int customerId);
|
||||
|
||||
/// <summary>
|
||||
/// 删除规则
|
||||
/// </summary>
|
||||
/// <param name="subSystemId"></param>
|
||||
/// <param name="customerId"></param>
|
||||
/// <returns></returns>
|
||||
Task DeleteRulesAsync(int subSystemId, int customerId);
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
namespace SJZY.Track.Application.Contract.Services;
|
||||
|
||||
public interface INotifyService
|
||||
{
|
||||
void SendNotification(string body);
|
||||
}
|
||||
@ -67,7 +67,7 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa
|
||||
});
|
||||
|
||||
// 预警计算
|
||||
var warningOrders = orders.Select(order => MapWarningOrderDto(order, @event.TrackStatusId)).ToList();
|
||||
var warningOrders = orders.Select(order => MapWarningOrderDto(order, @event)).ToList();
|
||||
|
||||
_forewarningNotifyService.WarningCalculateAsync(warningOrders);
|
||||
}
|
||||
@ -77,8 +77,6 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa
|
||||
return new OrderEntity
|
||||
{
|
||||
Id = order.Id,
|
||||
SubSystemId = order.SubSystemId,
|
||||
CustomId = order.CustomId,
|
||||
|
||||
// 轨迹
|
||||
IsCompleted = order.IsCompleted,
|
||||
@ -101,14 +99,14 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa
|
||||
};
|
||||
}
|
||||
|
||||
private WarningOrderDto MapWarningOrderDto(OrderEntity order, int trackStatusId)
|
||||
private WarningOrderDto MapWarningOrderDto(OrderEntity order, TrackChangeAfterUpdateOrderEvent @event)
|
||||
{
|
||||
return new WarningOrderDto
|
||||
{
|
||||
Id = order.Id,
|
||||
TrackStatusId = trackStatusId,
|
||||
SubSystemId = order.SubSystemId,
|
||||
CustomerId = order.CustomId,
|
||||
TrackStatusId = @event.TrackStatusId,
|
||||
SubSystemId = @event.SubSystemId,
|
||||
CustomerId = @event.CustomId,
|
||||
|
||||
CargoType = order.CargoType,
|
||||
Month = order.CreateTime.Month,
|
||||
|
||||
@ -235,7 +235,6 @@ public class TrackRefreshEventHandler : ITransientDependency, ICapSubscribe
|
||||
OrderId = context.OrderId,
|
||||
OrderNo = context.OrderNo,
|
||||
OrderType = context.OrderType,
|
||||
CustomId = context.CustomId
|
||||
}
|
||||
},
|
||||
TrackRefreshData = new TrackRefreshStruct
|
||||
|
||||
@ -58,6 +58,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
||||
var nextEvent = @event.DeepCopy();
|
||||
nextEvent.Visited.AddRange(orderIds);
|
||||
nextEvent.SubSystemId = group.Key.SubSystemId;
|
||||
nextEvent.CustomId = group.Key.CustomId;
|
||||
nextEvent.TrackRefreshData = new TrackRefreshStruct
|
||||
{
|
||||
ServiceProviderName = @event.TrackRefreshData.ServiceProviderName,
|
||||
@ -88,7 +89,6 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
||||
OrderId = x.OrderId,
|
||||
OrderNo = x.OrderNo,
|
||||
OrderType = x.OrderType,
|
||||
CustomId = x.CustomId
|
||||
}).ToList();
|
||||
var idx = 0;
|
||||
while (idx < identifiers.Count)
|
||||
@ -181,6 +181,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
||||
if(!providerDic.TryGetValue(order.OrderId,out var provider))
|
||||
continue;
|
||||
|
||||
// todo:不要在upsert事件计算order的状态
|
||||
var config =
|
||||
await _trackPullCacheService.GetPullParamWithContentConfigAsync(provider.SubSystemId,
|
||||
provider.ServiceProviderId);
|
||||
@ -199,6 +200,8 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
||||
await _capPublisher.PublishAsync(GlobalConst.TrackChangeAfterUpdateOrderSubscribe,
|
||||
new TrackChangeAfterUpdateOrderEvent
|
||||
{
|
||||
SubSystemId = @event.SubSystemId,
|
||||
CustomId = @event.CustomId,
|
||||
OrderIds = canNextOrderIds.ToArray(),
|
||||
IsCompleted = @event.TrackRefreshData.IsCompleted,
|
||||
TrackContent = content.TrackContent,
|
||||
@ -211,16 +214,12 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
||||
});
|
||||
|
||||
// 触发轨迹推送事件(异步)
|
||||
foreach (var group in @event.OrderIdentifiers
|
||||
.Where(x => x.OrderId.IsIn(canNextOrderIds))
|
||||
.GroupBy(x => x.CustomId))
|
||||
{
|
||||
var trackPushEvent = new TrackPushEvent
|
||||
{
|
||||
OptionType = @event.IsAdd ? OptionType.新增 : OptionType.修改,
|
||||
SubSystemId = @event.SubSystemId,
|
||||
CustomId = group.Key,
|
||||
OrderIds = group.Select(x => x.OrderId).ToArray(),
|
||||
CustomId = @event.CustomId,
|
||||
OrderIds = canNextOrderIds.ToArray(),
|
||||
TrackCode = @event.TrackCode,
|
||||
SystemPushInfo = new SystemPushStruct
|
||||
{
|
||||
@ -233,7 +232,6 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
||||
};
|
||||
await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, trackPushEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务商字典
|
||||
|
||||
@ -6,8 +6,29 @@ namespace SJZY.Track.Application.Services.ForewarningServices;
|
||||
|
||||
public class ForewarningCacheService: IForewarningCacheService, ISingletonDependency
|
||||
{
|
||||
public Task<List<ForewarningRuleCacheEntry>> GetRulesAsync(int subSystemId)
|
||||
private Dictionary<string, List<ForewarningRuleCacheEntry>> _rules = new();
|
||||
string AreaKey(int subSystemId) => $"TrackArea:{subSystemId}";
|
||||
string WarningKey(int subSystemId, int customerId) => $"TrackWarning:{subSystemId}:{customerId}";
|
||||
|
||||
// 30w => 1w => local
|
||||
public async Task<List<ForewarningRuleCacheEntry>?> GetRulesAsync(int subSystemId, int customerId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var rules = _rules.GetValueOrDefault(WarningKey(subSystemId, customerId));
|
||||
|
||||
if (rules == null)
|
||||
{
|
||||
// todo: 写入缓存 set str
|
||||
await Task.Delay(1);
|
||||
}
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
// a b c del local cusomer 3 del redis cache pub del redis cache
|
||||
public Task DeleteRulesAsync(int subSystemId, int customerId)
|
||||
{
|
||||
_rules.Remove(WarningKey(subSystemId, customerId));
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,8 @@
|
||||
using FreeRedis;
|
||||
using SJZY.Expand.ABP.Core;
|
||||
using SJZY.Track.Application.Contract.Services;
|
||||
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
||||
using SJZY.Track.Domain.Consts;
|
||||
using SJZY.Track.Domain.Dtos.Forewarning;
|
||||
using SJZY.Track.Domain.Enums;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ForewarningServices;
|
||||
@ -14,16 +12,12 @@ namespace SJZY.Track.Application.Services.ForewarningServices;
|
||||
/// </summary>
|
||||
public class ForewarningNotifyService : IForewarningNotifyService, ITransientDependency
|
||||
{
|
||||
IReadOnlyDictionary<string, List<ForewarningRuleItem>> _ruleGroupDict;
|
||||
IReadOnlyDictionary<string, List<RuleFactor>> _factorDict;
|
||||
private IReadOnlyDictionary<int, ForewarningRuleItem> _rules;
|
||||
readonly INotifyService _notifyService;
|
||||
private readonly ForewarningCacheService _cacheService;
|
||||
|
||||
public ForewarningNotifyService(INotifyService notifyService)
|
||||
public ForewarningNotifyService(ForewarningCacheService cacheService)
|
||||
{
|
||||
_notifyService = notifyService;
|
||||
_cacheService = cacheService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建预警通知
|
||||
/// </summary>
|
||||
@ -31,7 +25,7 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
|
||||
/// <returns>创建的通知总量,0表示没有规则</returns>
|
||||
public async Task WarningCalculateAsync(List<WarningOrderDto> order)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var rules = await _cacheService.GetRulesAsync(order[0].SubSystemId, order[0].CustomerId);
|
||||
}
|
||||
|
||||
public Task<int> DeleteForewarningNotify(WarningOrderDto order)
|
||||
@ -50,21 +44,9 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
|
||||
var notifyValues = notifyMembers.Select(val => new RuleNotifyValue(val));
|
||||
foreach (var notifyValue in notifyValues)
|
||||
{
|
||||
if (!_rules.TryGetValue(notifyValue.RuleId, out var rule))
|
||||
continue;
|
||||
|
||||
//todo 发送通知
|
||||
_notifyService.SendNotification("");
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearCache()
|
||||
{
|
||||
_ruleGroupDict = null;
|
||||
_factorDict = null;
|
||||
_rules = null;
|
||||
}
|
||||
|
||||
private List<string> DeleteNotifyValue(ForewarningRuleItem ruleItem, int orderId)
|
||||
{
|
||||
var members = new List<string>();
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
using SJZY.Track.Application.Contract.Services;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace SJZY.Track.Application.Services.Notifies;
|
||||
|
||||
public class NotifyService:INotifyService, ITransientDependency
|
||||
{
|
||||
public void SendNotification(string body)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@ -101,7 +101,6 @@ public partial class OrderService
|
||||
OrderId = x.Id,
|
||||
OrderNo = x.OrderNo,
|
||||
OrderType = x.OrderType,
|
||||
CustomId = x.CustomId
|
||||
}).ToArray(),
|
||||
TrackCode = track.TrackCode,
|
||||
TrackPlace = track.TrackPlace,
|
||||
|
||||
@ -73,7 +73,6 @@ public partial class TrackService : ApplicationService, ITrackService
|
||||
OrderId = order.Id,
|
||||
OrderNo = order.OrderNo,
|
||||
OrderType = order.OrderType,
|
||||
CustomId = order.CustomId
|
||||
}
|
||||
};
|
||||
@event.OperationMan = name;
|
||||
@ -111,18 +110,19 @@ public partial class TrackService : ApplicationService, ITrackService
|
||||
|
||||
var name = userInfo.Data.UserName;
|
||||
|
||||
foreach (var group in orders.GroupBy(x => x.SubSystemId))
|
||||
foreach (var group in orders.GroupBy(x => new { x.SubSystemId, x.CustomId }))
|
||||
{
|
||||
// 新增/更新轨迹
|
||||
var @event = new TrackUpsertEvent
|
||||
{
|
||||
SubSystemId = group.Key,
|
||||
SubSystemId = group.Key.SubSystemId,
|
||||
CustomId = group.Key.CustomId,
|
||||
|
||||
OrderIdentifiers = group.Select(order => new OrderIdentifier
|
||||
{
|
||||
OrderId = order.Id,
|
||||
OrderNo = order.OrderNo,
|
||||
OrderType = input.OrderType,
|
||||
CustomId = order.CustomId
|
||||
}).ToArray(),
|
||||
IsAdd = input.IsAdd,
|
||||
TrackCode = input.TrackCode,
|
||||
|
||||
@ -22,10 +22,6 @@ public partial class GlobalConst
|
||||
/// </summary>
|
||||
public const string TrackPullContentKeyPrefix = "TrackPullContent";
|
||||
|
||||
/// <summary>
|
||||
/// 规则因素缓存redis key前缀
|
||||
/// </summary>
|
||||
public const string RuleFactorKeyPrefix = "RuleFactor";
|
||||
|
||||
/// <summary>
|
||||
/// 预警通知redis key前缀
|
||||
|
||||
Loading…
Reference in New Issue
Block a user