shanji 2 years ago
parent
commit
3ede08ee50
  1. 104
      BBWY.Server.Business/Sync/JD/JDServiceOrderSyncBusiness.cs

104
BBWY.Server.Business/Sync/JD/JDServiceOrderSyncBusiness.cs

@ -238,23 +238,107 @@ namespace BBWY.Server.Business.Sync
} }
} }
public void SubscribeKuaiDi100(long shopId)
{
var shop = venderBusiness.GetShopList(shopId).FirstOrDefault();
Task.Factory.StartNew(() => SyncServiceOrder(shop, string.Empty, isAuto: true),
System.Threading.CancellationToken.None,
TaskCreationOptions.LongRunning,
taskSchedulerManager.SyncServiceOrderTaskScheduler);
}
private void SubscribeKuaiDi100(ShopResponse shop) private void SubscribeKuaiDi100(ShopResponse shop)
{ {
var serviceOrderList = fsql.Select<ServiceOrder>().Where(s => s.ShopId == shop.Id && var loggerName = $"订阅快递100-{shop.ShopName}";
s.IsNeedSubscribeKuaiDi100 == true && try
s.IsSubscribeKuaiDi100 == false)
.Page(1, 50)
.ToList();
foreach (var serviceOrder in serviceOrderList)
{ {
if (string.IsNullOrEmpty(serviceOrder.WaybillNo) || string.IsNullOrEmpty(serviceOrder.ExpressName)) var relayAPIHost = GetPlatformRelayAPIHost(shop.PlatformId);
var serviceOrderList = fsql.Select<ServiceOrder>().Where(s => s.ShopId == shop.Id &&
s.IsNeedSubscribeKuaiDi100 == true &&
s.IsSubscribeKuaiDi100 == false)
.Page(1, 50)
.ToList();
List<IUpdate<ServiceOrder>> updateSerivceOrderList = new List<IUpdate<ServiceOrder>>();
foreach (var serviceOrder in serviceOrderList)
{ {
#region 查询服务单运单详情 bool isUpdateDelivery = false, isUpdateSubscribe = false;
if (string.IsNullOrEmpty(serviceOrder.WaybillNo) || string.IsNullOrEmpty(serviceOrder.ExpressName))
{
#endregion try
} {
#region 查询服务单运单详情
var serviceOrderDeliveryResult = restApiService.SendRequest(relayAPIHost, "api/PlatformSDK/GetServiceOrderDeliveryDetail", new QueryServiceOrderDetailRequest()
{
AppKey = shop.AppKey,
AppSecret = shop.AppSecret,
AppToken = shop.AppToken,
OrderId = serviceOrder.OrderId,
ServiceId = serviceOrder.ServiceId,
Platform = Enums.Platform.,
VenderId = shop.VenderId
}, GetYunDingRequestHeader(), HttpMethod.Post);
if (serviceOrderDeliveryResult.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception($"获取服务单运单详情失败 {serviceOrderDeliveryResult.Content}");
var serviceOrderDeliveryResponse = JsonConvert.DeserializeObject<ApiResponse<JToken>>(serviceOrderDeliveryResult.Content);
if (!serviceOrderDeliveryResponse.Success)
throw new Exception($"获取服务单运单详情失败 {serviceOrderDeliveryResponse.Msg}");
if (serviceOrderDeliveryResponse.Data != null)
{
var wayBillNo = serviceOrderDeliveryResponse.Data.Value<string>("expressCode");
var expressName = serviceOrderDeliveryResponse.Data.Value<string>("expressCompany");
if (!string.IsNullOrEmpty(wayBillNo) && !string.IsNullOrEmpty(expressName))
{
serviceOrder.WaybillNo = wayBillNo;
serviceOrder.ExpressName = expressName;
isUpdateDelivery = true;
//var update = fsql.Update<ServiceOrder>(serviceOrder.Id).Set(s => s.WaybillNo, wayBillNo)
// .Set(s => s.ExpressName, expressName);
}
}
#endregion
}
catch (Exception ex)
{
nLogManager.GetLogger(loggerName).Error(ex, $"SubscribeKuaiDi100 ShopName:{shop.ShopName} ShopId:{shop.ShopId} ServiceId:{serviceOrder.ServiceId}");
}
}
if (!string.IsNullOrEmpty(serviceOrder.WaybillNo) && !string.IsNullOrEmpty(serviceOrder.ExpressName))
{
#region 订阅快递100
isUpdateSubscribe = true;
#endregion
}
if (isUpdateDelivery || isUpdateSubscribe)
{
var update = fsql.Update<ServiceOrder>(serviceOrder.Id).SetIf(isUpdateDelivery, s => s.WaybillNo, serviceOrder.WaybillNo)
.SetIf(isUpdateDelivery, s => s.ExpressName, serviceOrder.ExpressName)
.SetIf(isUpdateSubscribe, s => s.IsSubscribeKuaiDi100, true);
updateSerivceOrderList.Add(update);
}
}
if (updateSerivceOrderList.Count() > 0)
{
fsql.Transaction(() =>
{
foreach (var update in updateSerivceOrderList)
update.ExecuteAffrows();
});
}
}
catch (Exception ex)
{
nLogManager.GetLogger(loggerName).Error(ex, $"SubscribeKuaiDi100 ShopName:{shop.ShopName} ShopId:{shop.ShopId}");
} }
} }
} }

Loading…
Cancel
Save