【优化】调整佣金结算消息队列为延迟消息队列,防止定时任务并发下导致数据同步问题。

pull/123/head
JianWeie 3 years ago
parent b4fde8254b
commit db4e141a67

@ -130,5 +130,14 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
/// <returns></returns>
Task ListClearAsync(string redisKey);
/// <summary>
/// 有序集合/定时任务延迟队列用的多
/// </summary>
/// <param name="redisKey">key</param>
/// <param name="redisValue">元素</param>
/// <param name="score">分数</param>
Task SortedSetAddAsync(string redisKey, string redisValue, double score);
}
}

@ -226,5 +226,18 @@ namespace CoreCms.Net.Caching.AutoMate.RedisCache
{
await _database.ListTrimAsync(redisKey, 1, 0);
}
/// <summary>
/// 有序集合/定时任务延迟队列用的多
/// </summary>
/// <param name="redisKey">key</param>
/// <param name="redisValue">元素</param>
/// <param name="score">分数</param>
public async Task SortedSetAddAsync(string redisKey, string redisValue, double score)
{
await _database.SortedSetAddAsync(redisKey, redisValue, score);
}
}
}

@ -206,14 +206,14 @@ namespace CoreCms.Net.IServices
int storeId = 0, int shipAreaId = 0, string deliveryCompanyId = "");
/// <summary>
/// 后台完成订单
/// </summary>
/// <param name="orderId"></param>
/// <param name="score">有序队列积分</param>
/// <param name="remark"></param>
/// <returns></returns>
Task<WebApiCallBack> CompleteOrder(string orderId, string remark = "后台订单完成操作");
Task<WebApiCallBack> CompleteOrder(string orderId, int score = 0, string remark = "后台订单完成操作");
/// <summary>
/// 确认签收订单

@ -40,11 +40,11 @@ namespace CoreCms.Net.RedisMQ.Subscribe
}
/// <summary>
/// 订单完成时,结算该订单
/// 订单完成时,结算该订单|延迟队列
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
[Subscribe(RedisMessageQueueKey.OrderFinishCommand)]
[SubscribeDelay(RedisMessageQueueKey.OrderFinishCommand)]
private async Task OrderFinishCommand(string msg)
{
@ -57,11 +57,11 @@ namespace CoreCms.Net.RedisMQ.Subscribe
}
else
{
await _distributionOrderServices.FinishOrder(msg);
await _agentOrderServices.FinishOrder(msg);
NLogUtil.WriteAll(NLog.LogLevel.Info, LogType.RedisMessageQueue, "订单完结结佣", "订单编号获取正常:" + msg);
}
await _distributionOrderServices.FinishOrder(msg);
await _agentOrderServices.FinishOrder(msg);
}
catch (Exception ex)
{

@ -1845,12 +1845,15 @@ namespace CoreCms.Net.Services
#region 完成订单
/// <summary>
/// 完成订单
/// </summary>
/// <param name="orderId"></param>
/// <param name="score">有序队列积分</param>
/// <param name="remark"></param>
/// <returns></returns>
public async Task<WebApiCallBack> CompleteOrder(string orderId, string remark = "后台订单完成操作")
public async Task<WebApiCallBack> CompleteOrder(string orderId, int score = 0, string remark = "后台订单完成操作")
{
var jm = new WebApiCallBack();
@ -1911,7 +1914,7 @@ namespace CoreCms.Net.Services
await _orderLogServices.InsertAsync(orderLog);
//订单完成结算订单
await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.OrderFinishCommand, orderInfo.orderId);
await _redisOperationRepository.SortedSetAddAsync(RedisMessageQueueKey.OrderFinishCommand, orderInfo.orderId, score);
jm.status = true;
jm.msg = "订单完成";
@ -2127,9 +2130,11 @@ namespace CoreCms.Net.Services
if (orderInfos != null && orderInfos.Any())
{
foreach (var item in orderInfos)
for (var i = 0; i < orderInfos.Count; i++)
{
await CompleteOrder(item.orderId, "定时任务操作");
var item = orderInfos[i];
var score = 2 * (i + 1);
await CompleteOrder(item.orderId, score, "定时任务操作");
}
}
//插入日志

Loading…
Cancel
Save