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