shanji 2 years ago
parent
commit
4e3a6f6b74
  1. 97
      BBWY.Server.Business/Sync/JD/JDServiceOrderSyncBusiness.cs

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

@ -0,0 +1,97 @@
using BBWY.Common.Http;
using BBWY.Common.Models;
using BBWY.Server.Model;
using BBWY.Server.Model.Dto;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Yitter.IdGenerator;
namespace BBWY.Server.Business.Sync
{
public class JDServiceOrderSyncBusiness : BaseSyncBusiness, IDenpendency
{
public JDServiceOrderSyncBusiness(RestApiService restApiService, IOptions<GlobalConfig> options, NLogManager nLogManager, IFreeSql fsql, IIdGenerator idGenerator, TaskSchedulerManager taskSchedulerManager, VenderBusiness venderBusiness, YunDingBusiness yunDingBusiness) : base(restApiService, options, nLogManager, fsql, idGenerator, taskSchedulerManager, venderBusiness, yunDingBusiness)
{
}
public void SyncAllShopServiceOrder()
{
var shopList = venderBusiness.GetShopList(platform: Enums.Platform.);
//SyncAfterOrder(shopList.FirstOrDefault(s => s.ShopName == "布莱特玩具专营店"), string.Empty, isAuto: true);
foreach (var shop in shopList)
{
Task.Factory.StartNew(() => SyncServiceOrder(shop, string.Empty, isAuto: true),
System.Threading.CancellationToken.None,
TaskCreationOptions.LongRunning,
taskSchedulerManager.SyncAfterOrderTaskScheduler);
}
}
private void SyncServiceOrder(ShopResponse shop, JArray jArray)
{
}
private void SyncServiceOrder(ShopResponse shop, string orderId, DateTime? startTime = null, DateTime? endTime = null, bool isAuto = false)
{
/*
:
: 10001
: 10002
: 10012
: 10005
: 10011
: 10004
: 10009
: 10010
:
: 10007
:7060
:7023
线:7090
: 13000
*/
try
{
var shopId = long.Parse(shop.ShopId);
var relayAPIHost = GetPlatformRelayAPIHost(shop.PlatformId);
var _10005ServiceOrderListApiResult = restApiService.SendRequest(relayAPIHost, "api/PlatformSDK/GetServiceOrderList", new QueryServiceOrderRequest()
{
UpdateTimeBegin = startTime ?? DateTime.Now.Date.AddDays(-3),
UpdateTimeEnd = endTime ?? DateTime.Now,
AppKey = shop.AppKey,
AppSecret = shop.AppSecret,
AppToken = shop.AppToken,
PageIndex = 1,
PageSize = 50,
Platform = shop.PlatformId,
SaveResponseLog = true,
OrderId = orderId,
VenderId = shop.VenderId,
ServiceStatus = 10005
}, GetYunDingRequestHeader(), HttpMethod.Post);
if (_10005ServiceOrderListApiResult.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception($"获取服务单失败 {_10005ServiceOrderListApiResult.Content}");
var serviceOrderListResponse = JsonConvert.DeserializeObject<ApiResponse<JArray>>(_10005ServiceOrderListApiResult.Content);
if (!serviceOrderListResponse.Success)
throw new Exception($"获取服务单失败 {serviceOrderListResponse.Msg}");
//SyncServiceOrder(shop, serviceOrderListResponse.Data);
}
catch (Exception ex)
{
var shopData = JsonConvert.SerializeObject(shop);
nLogManager.Default().Error(ex, $"SyncServiceOrder ShopData:{shopData}");
}
}
}
}
Loading…
Cancel
Save