|
|
@ -10,6 +10,7 @@ using BBWYB.Server.Model.Db.Mds; |
|
|
|
using BBWYB.Server.Model.Db.MDS; |
|
|
|
using BBWYB.Server.Model.Dto; |
|
|
|
using FreeSql; |
|
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json.Linq; |
|
|
@ -39,6 +40,7 @@ namespace BBWYB.Server.Business |
|
|
|
private Lazy<VenderBusiness> venderBusinessLazy; |
|
|
|
private Lazy<PurchaseSchemeBusiness> purchaseSchemeBusinessLazy; |
|
|
|
private Lazy<TimeLimitRules> timeLimitRulesLazy; |
|
|
|
private Lazy<IMemoryCache> memoryCacheLazy; |
|
|
|
|
|
|
|
private PP_PlatformClientFactory ppPlatformClientFactory => pplatformClientFactoryLazy.Value; |
|
|
|
private TaskSchedulerManager taskSchedulerManager => taskSchedulerManagerLazy.Value; |
|
|
@ -57,8 +59,12 @@ namespace BBWYB.Server.Business |
|
|
|
|
|
|
|
private TimeLimitRules timeLimitRules => timeLimitRulesLazy.Value; |
|
|
|
|
|
|
|
private IMemoryCache memoryCache => memoryCacheLazy.Value; |
|
|
|
|
|
|
|
private IList<Enums.OrderState> cantPurchaseOrderStateList; |
|
|
|
|
|
|
|
private TimeSpan _1688ConcurrentKeyTimeSpan; |
|
|
|
|
|
|
|
public PurchaseOrderBusiness(IFreeSql fsql, |
|
|
|
NLogManager nLogManager, |
|
|
|
IIdGenerator idGenerator, |
|
|
@ -77,12 +83,14 @@ namespace BBWYB.Server.Business |
|
|
|
venderBusinessLazy = new Lazy<VenderBusiness>(() => serviceProvider.GetService<VenderBusiness>()); |
|
|
|
purchaseSchemeBusinessLazy = new Lazy<PurchaseSchemeBusiness>(() => serviceProvider.GetService<PurchaseSchemeBusiness>()); |
|
|
|
timeLimitRulesLazy = new Lazy<TimeLimitRules>(() => serviceProvider.GetService<TimeLimitRules>()); |
|
|
|
memoryCacheLazy = new Lazy<IMemoryCache>(() => serviceProvider.GetService<IMemoryCache>()); |
|
|
|
cantPurchaseOrderStateList = new List<Enums.OrderState>() |
|
|
|
{ |
|
|
|
Enums.OrderState.已取消, |
|
|
|
Enums.OrderState.已完成, |
|
|
|
Enums.OrderState.待付款 |
|
|
|
}; |
|
|
|
_1688ConcurrentKeyTimeSpan = new TimeSpan(0, 1, 0); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -2346,25 +2354,56 @@ namespace BBWYB.Server.Business |
|
|
|
//}
|
|
|
|
|
|
|
|
#region 1688CallBack
|
|
|
|
private string Get1688ConcurrentKey(JObject j) |
|
|
|
{ |
|
|
|
var type = j.Value<string>("type").ToUpper(); |
|
|
|
var poId = string.Empty; |
|
|
|
switch (type) |
|
|
|
{ |
|
|
|
case "ORDER_BUYER_VIEW_PART_PART_SENDGOODS": //部分发货
|
|
|
|
case "ORDER_BUYER_VIEW_ANNOUNCE_SENDGOODS": //发货
|
|
|
|
case "ORDER_BUYER_VIEW_ORDER_PRICE_MODIFY": //订单改价
|
|
|
|
case "LOGISTICS_BUYER_VIEW_TRACE": //物流变更
|
|
|
|
case "ORDER_BUYER_VIEW_ORDER_PAY": //支付
|
|
|
|
poId = j["data"].Value<string>("orderId"); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
if (string.IsNullOrEmpty(poId)) |
|
|
|
return string.Empty; |
|
|
|
|
|
|
|
return $"{type}_{poId}"; |
|
|
|
} |
|
|
|
|
|
|
|
public void CallbackFrom1688(string jsonStr) |
|
|
|
{ |
|
|
|
nLogManager.Default().Info(jsonStr); |
|
|
|
var jObject = JObject.Parse(jsonStr); |
|
|
|
var _1688ConcurrentKey = Get1688ConcurrentKey(jObject); |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_1688ConcurrentKey)) |
|
|
|
{ |
|
|
|
if (memoryCache.TryGetValue<string>(_1688ConcurrentKey, out _)) |
|
|
|
return;//并发key存在,不允执行
|
|
|
|
memoryCache.Set(_1688ConcurrentKey, _1688ConcurrentKey, _1688ConcurrentKeyTimeSpan); |
|
|
|
} |
|
|
|
|
|
|
|
var type = jObject.Value<string>("type").ToUpper(); |
|
|
|
switch (type) |
|
|
|
{ |
|
|
|
case "ORDER_BUYER_VIEW_PART_PART_SENDGOODS": //部分发货
|
|
|
|
case "ORDER_BUYER_VIEW_ANNOUNCE_SENDGOODS": //发货
|
|
|
|
DeliveryCallbackFrom1688(jObject); |
|
|
|
DeliveryCallbackFrom1688(jObject, _1688ConcurrentKey); |
|
|
|
break; |
|
|
|
case "ORDER_BUYER_VIEW_ORDER_PRICE_MODIFY": |
|
|
|
OrderPriceModificationCallbackFrom1688(jObject); //订单改价
|
|
|
|
OrderPriceModificationCallbackFrom1688(jObject, _1688ConcurrentKey); //订单改价
|
|
|
|
break; |
|
|
|
case "LOGISTICS_BUYER_VIEW_TRACE": |
|
|
|
// LogisticsUpdateCallbackFrom1688(jObject);//1688物流信息变更
|
|
|
|
break; |
|
|
|
case "ORDER_BUYER_VIEW_ORDER_PAY": |
|
|
|
OrderPayFrom1688(jObject); |
|
|
|
OrderPayFrom1688(jObject, _1688ConcurrentKey); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
@ -2375,17 +2414,21 @@ namespace BBWYB.Server.Business |
|
|
|
/// 1688发货回调
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="jObject"></param>
|
|
|
|
private void DeliveryCallbackFrom1688(JObject jObject) |
|
|
|
/// <param name="_1688ConcurrentKey">并发key</param>
|
|
|
|
private void DeliveryCallbackFrom1688(JObject jObject, string _1688ConcurrentKey) |
|
|
|
{ |
|
|
|
var purchaseOrderId = jObject["data"].Value<string>("orderId"); |
|
|
|
Task.Factory.StartNew(() => DeliveryCallbackFrom1688(purchaseOrderId), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
Task.Factory.StartNew(() => DeliveryCallbackFrom1688(purchaseOrderId, _1688ConcurrentKey), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 1688发货回调
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="purchaseOrderId">采购单</param>
|
|
|
|
private void DeliveryCallbackFrom1688(string purchaseOrderId) |
|
|
|
/// <param name="purchaseOrderId"></param>
|
|
|
|
/// <param name="_1688ConcurrentKey"></param>
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
|
private void DeliveryCallbackFrom1688(string purchaseOrderId, string _1688ConcurrentKey) |
|
|
|
{ |
|
|
|
string orderId = string.Empty; |
|
|
|
long? shopId = null; |
|
|
@ -2623,22 +2666,28 @@ namespace BBWYB.Server.Business |
|
|
|
{ |
|
|
|
nLogManager.Default().Error(ex, $"DeliveryCallback 回调平台1688,订单号{orderId},采购单号{purchaseOrderId},执行进度[{currentProgress}],采购单物流信息:{wayBillNoResponseInfo}"); |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(_1688ConcurrentKey)) |
|
|
|
memoryCache.Remove(_1688ConcurrentKey); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 1688订单改价回调
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="jObject"></param>
|
|
|
|
private void OrderPriceModificationCallbackFrom1688(JObject jObject) |
|
|
|
/// <param name="_1688ConcurrentKey"></param>
|
|
|
|
private void OrderPriceModificationCallbackFrom1688(JObject jObject, string _1688ConcurrentKey) |
|
|
|
{ |
|
|
|
var purchaseOrderId = jObject["data"].Value<string>("orderId"); |
|
|
|
Task.Factory.StartNew(() => OrderPriceModificationCallback(purchaseOrderId, Enums.Platform.阿里巴巴), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
Task.Factory.StartNew(() => OrderPriceModificationCallback(purchaseOrderId, Enums.Platform.阿里巴巴, _1688ConcurrentKey), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
} |
|
|
|
|
|
|
|
private void OrderPayFrom1688(JObject jObject) |
|
|
|
private void OrderPayFrom1688(JObject jObject, string _1688ConcurrentKey) |
|
|
|
{ |
|
|
|
var purchaseOrderId = jObject["data"].Value<string>("orderId"); |
|
|
|
Task.Factory.StartNew(() => OrderPayCallback(purchaseOrderId, Enums.Platform.阿里巴巴), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
Task.Factory.StartNew(() => OrderPayCallback(purchaseOrderId, Enums.Platform.阿里巴巴, _1688ConcurrentKey), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.PurchaseOrderCallbackTaskScheduler); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
@ -2648,14 +2697,21 @@ namespace BBWYB.Server.Business |
|
|
|
/// </summary>
|
|
|
|
/// <param name="purchaseOrderId"></param>
|
|
|
|
/// <param name="callbackPlatform"></param>
|
|
|
|
private void OrderPriceModificationCallback(string purchaseOrderId, Enums.Platform callbackPlatform) |
|
|
|
/// <param name="concurrentKey"></param>
|
|
|
|
private void OrderPriceModificationCallback(string purchaseOrderId, Enums.Platform callbackPlatform, string concurrentKey) |
|
|
|
{ |
|
|
|
OnSomeOnePurchaseOrderChanged(purchaseOrderId, true); |
|
|
|
OnSomeOnePurchaseOrderChanged(purchaseOrderId, true, concurrentKey); |
|
|
|
} |
|
|
|
|
|
|
|
private void OrderPayCallback(string purchaseOrderId, Enums.Platform callbackPlatform) |
|
|
|
/// <summary>
|
|
|
|
/// 订单支付回调
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="purchaseOrderId"></param>
|
|
|
|
/// <param name="callbackPlatform"></param>
|
|
|
|
/// <param name="concurrentKey"></param>
|
|
|
|
private void OrderPayCallback(string purchaseOrderId, Enums.Platform callbackPlatform, string concurrentKey) |
|
|
|
{ |
|
|
|
OnSomeOnePurchaseOrderChanged(purchaseOrderId, false); |
|
|
|
OnSomeOnePurchaseOrderChanged(purchaseOrderId, false, concurrentKey); |
|
|
|
} |
|
|
|
|
|
|
|
public void KuaiDi100Publish(string param) |
|
|
@ -2927,7 +2983,8 @@ namespace BBWYB.Server.Business |
|
|
|
/// </summary>
|
|
|
|
/// <param name="purchaseOrderId">采购单Id</param>
|
|
|
|
/// <param name="keepRunWhenNoEditOrderPirce">当不需要触发订单改价时是否继续走流程</param>
|
|
|
|
public void OnSomeOnePurchaseOrderChanged(string purchaseOrderId, bool keepRunWhenNoEditOrderPirce) |
|
|
|
/// <param name="concurrentKey">并发key</param>
|
|
|
|
public void OnSomeOnePurchaseOrderChanged(string purchaseOrderId, bool keepRunWhenNoEditOrderPirce, string concurrentKey) |
|
|
|
{ |
|
|
|
bool isEditOrderPrice = true; |
|
|
|
try |
|
|
@ -3182,6 +3239,11 @@ namespace BBWYB.Server.Business |
|
|
|
{ |
|
|
|
nLogManager.Default().Error(ex, $"OrderPriceModificationCallback 采购单号{purchaseOrderId}"); |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(concurrentKey)) |
|
|
|
memoryCache.Remove(concurrentKey); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void SendDingDing(string content) |
|
|
|