fix:订单仓储,修复缓存过期时间设置错误,导致过期时间非常长,从而带来较长时间的数据不一致
refactor:TrackUpsert,补充log解释说明轨迹更新失败原因
This commit is contained in:
parent
8deabef406
commit
204c8fc7b5
@ -144,8 +144,6 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: 在这里,判断存在性
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +155,7 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
{
|
{
|
||||||
// 找不到轨迹内容,直接结束
|
// 找不到轨迹内容,直接结束
|
||||||
LogHelper.Warn($"找不到轨迹内容:{@event}", true);
|
LogHelper.Warn($"找不到轨迹内容:{@event}", true);
|
||||||
return default;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//#7001:未来潜在需求,当轨迹内容匹配预设,记录一个标记,保证下刷过程都是使用预设内容
|
//#7001:未来潜在需求,当轨迹内容匹配预设,记录一个标记,保证下刷过程都是使用预设内容
|
||||||
@ -302,13 +300,15 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
{
|
{
|
||||||
if (existTracks.Count > 1)
|
if (existTracks.Count > 1)
|
||||||
{
|
{
|
||||||
// todo: 所有的event handle 多写log,取缔注释,特别是continue,return,这种跳出的地方,方便排查问题
|
|
||||||
_logger.LogInformation("订单存在多条轨迹不允许修改:{@event}", @event);
|
_logger.LogInformation("订单存在多条轨迹不允许修改:{@event}", @event);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo:例如这里
|
if (track == null)
|
||||||
if (track == null) continue; // 不存在不让改
|
{
|
||||||
|
_logger.LogInformation("订单不存在轨迹不允许修改:{@event}", @event);
|
||||||
|
continue; // 不存在不让改
|
||||||
|
}
|
||||||
|
|
||||||
updateTracks.Add(BuiltUpdateTrack(@event, track, order, trackContent));
|
updateTracks.Add(BuiltUpdateTrack(@event, track, order, trackContent));
|
||||||
operationRecords.Add(BuildOrderOperationRecord(@event, track, order));
|
operationRecords.Add(BuildOrderOperationRecord(@event, track, order));
|
||||||
@ -316,7 +316,11 @@ public class TrackUpsertEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 不允许重复轨迹,跳过
|
// 不允许重复轨迹,跳过
|
||||||
if (!trackContent.IsRepeatable && existTracks.Count > 0) continue;
|
if (!trackContent.IsRepeatable && existTracks.Count > 0)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("订单已经存在不允许重复的轨迹,不允许重复添加:{@event}", @event);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
insertTracks.Add(BuiltNewTrack(@event, order, trackContent));
|
insertTracks.Add(BuiltNewTrack(@event, order, trackContent));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,10 +15,10 @@ public interface IOrderRepository : IBasicRepository<OrderEntity>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通过三方平台和三方单号查询订单
|
/// 通过三方平台和三方单号查询订单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="serviceProvidrCode">三方平台</param>
|
/// <param name="serviceProviderCode">三方平台</param>
|
||||||
/// <param name="orderNo">三方平台单号</param>
|
/// <param name="orderNo">三方平台单号</param>
|
||||||
/// <returns>(主单号id,客户id)</returns>
|
/// <returns>(主单号id,客户id)</returns>
|
||||||
Task<(int MainOrderId, int CustomId)> GetTrackOrderByProviderAndOrderNo(string serviceProvidrCode, string orderNo);
|
Task<(int MainOrderId, int CustomId)> GetTrackOrderByProviderAndOrderNo(string serviceProviderCode, string orderNo);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建订单
|
/// 创建订单
|
||||||
|
|||||||
@ -11,12 +11,13 @@ namespace SJZY.Track.Repository.Repositories;
|
|||||||
|
|
||||||
public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, ITransientDependency
|
public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, ITransientDependency
|
||||||
{
|
{
|
||||||
|
//tips:后期提供缓存清理接口
|
||||||
//MemoryCache本身线程安全简单使用,短暂数据不一致可以容忍,每过固定时间强制清除缓存
|
//MemoryCache本身线程安全简单使用,短暂数据不一致可以容忍,每过固定时间强制清除缓存
|
||||||
private static readonly MemoryCache _memoryCache = new(new MemoryCacheOptions());
|
private static readonly MemoryCache _memoryCache = new(new MemoryCacheOptions());
|
||||||
private static readonly Dictionary<int, string> _empty = new();
|
private static readonly Dictionary<int, string> _empty = new();
|
||||||
private static readonly Dictionary<string, Dictionary<int, string>> _empty2 = new();
|
private static readonly Dictionary<string, Dictionary<int, string>> _empty2 = new();
|
||||||
private const int ThirdPartyOrderNumberCacheTimeSpan = 3 * 60;
|
private static readonly TimeSpan _thirdPartyOrderNumberCacheTimeSpan = TimeSpan.FromMinutes(3);
|
||||||
private const int MainDataEnumCacheTimeSpan = 5 * 60;
|
private static readonly TimeSpan _mainDataEnumCacheTimeSpan = TimeSpan.FromMinutes(5);
|
||||||
|
|
||||||
private async Task<Dictionary<int, string>> GetThirdPartyOrderNumberForCacheAsync(int[] orderIds)
|
private async Task<Dictionary<int, string>> GetThirdPartyOrderNumberForCacheAsync(int[] orderIds)
|
||||||
{
|
{
|
||||||
@ -48,7 +49,7 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
|
|||||||
|
|
||||||
_memoryCache.Set(key, dict, new MemoryCacheEntryOptions
|
_memoryCache.Set(key, dict, new MemoryCacheEntryOptions
|
||||||
{
|
{
|
||||||
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(ThirdPartyOrderNumberCacheTimeSpan),
|
AbsoluteExpirationRelativeToNow = _thirdPartyOrderNumberCacheTimeSpan,
|
||||||
Size = dict.Count
|
Size = dict.Count
|
||||||
});
|
});
|
||||||
return dict;
|
return dict;
|
||||||
@ -92,7 +93,7 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
|
|||||||
|
|
||||||
_memoryCache.Set(key, dict, new MemoryCacheEntryOptions
|
_memoryCache.Set(key, dict, new MemoryCacheEntryOptions
|
||||||
{
|
{
|
||||||
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(MainDataEnumCacheTimeSpan),
|
AbsoluteExpirationRelativeToNow = _mainDataEnumCacheTimeSpan,
|
||||||
Size = dict.Count
|
Size = dict.Count
|
||||||
});
|
});
|
||||||
return dict;
|
return dict;
|
||||||
@ -247,12 +248,12 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
|
|||||||
return pageList;
|
return pageList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<(int MainOrderId, int CustomId)> GetTrackOrderByProviderAndOrderNo(string serviceProvidrCode, string orderNo)
|
public async Task<(int MainOrderId, int CustomId)> GetTrackOrderByProviderAndOrderNo(string serviceProviderCode, string orderNo)
|
||||||
{
|
{
|
||||||
var orderList = await Context.Queryable<OrderEntity>()
|
var orderList = await Context.Queryable<OrderEntity>()
|
||||||
.LeftJoin<OrderPlatformNumberEntity>((a, b) => a.Id == b.OrderId && b.IsDeleted == false)
|
.LeftJoin<OrderPlatformNumberEntity>((a, b) => a.Id == b.OrderId && b.IsDeleted == false)
|
||||||
.Where((a, b) => a.OrderNo == orderNo
|
.Where((a, b) => a.OrderNo == orderNo
|
||||||
|| (b.Platform == serviceProvidrCode && b.OrderNumber == orderNo))
|
|| (b.Platform == serviceProviderCode && b.OrderNumber == orderNo))
|
||||||
.Select((a, b) => new
|
.Select((a, b) => new
|
||||||
{
|
{
|
||||||
a.Id,
|
a.Id,
|
||||||
@ -269,7 +270,7 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
|
|||||||
|
|
||||||
var order = orderList.First();
|
var order = orderList.First();
|
||||||
//当出现了多条记录匹配,优先使用外部单匹配提升精确度
|
//当出现了多条记录匹配,优先使用外部单匹配提升精确度
|
||||||
var matchOrder = orderList.FirstOrDefault(x => x.Platform == serviceProvidrCode && x.OrderNumber == orderNo);
|
var matchOrder = orderList.FirstOrDefault(x => x.Platform == serviceProviderCode && x.OrderNumber == orderNo);
|
||||||
return matchOrder != null
|
return matchOrder != null
|
||||||
? (matchOrder.Id, matchOrder.CustomId)
|
? (matchOrder.Id, matchOrder.CustomId)
|
||||||
: (order.Id, order.CustomId);
|
: (order.Id, order.CustomId);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user