shanji 3 years ago
parent
commit
68951377f8
  1. 2
      BBWY.Server.Business/PlatformSDK/JDBusiness.cs
  2. 25
      BBWY.Server.Business/Sync/JDPopularizeSyncBusiness.cs
  3. 4
      BBWY.Server.Model/Dto/Request/Sync/SyncShopPopularizeRequest.cs
  4. 33
      BBWY.Test/Program.cs

2
BBWY.Server.Business/PlatformSDK/JDBusiness.cs

@ -477,7 +477,7 @@ namespace BBWY.Server.Business
var req = new DspPlatformFinanceOpenapiQuerycostdetailsRequest();
req.beginDate = syncShopPopularizeRequest.StartDate.ToString("yyyy-MM-dd");
req.endDate = syncShopPopularizeRequest.EndDate.ToString("yyyy-MM-dd");
req.pageNo = 1;
req.pageNo = syncShopPopularizeRequest.PageIndex == 0 ? 1 : syncShopPopularizeRequest.PageIndex;
req.pageSize = 100;
req.moneyType = 1;

25
BBWY.Server.Business/Sync/JDPopularizeSyncBusiness.cs

@ -15,6 +15,7 @@ using System.Threading.Tasks;
using Yitter.IdGenerator;
using BBWY.Common.Extensions;
using BBWY.Server.Model.Db;
using System.Threading;
namespace BBWY.Server.Business.Sync
{
@ -67,8 +68,9 @@ namespace BBWY.Server.Business.Sync
fsql.Insert(insertList).ExecuteAffrows();
}
private void SyncShopPopularizeRecord(ShopResponse shop, DateTime startDate, DateTime endDate)
private void SyncShopPopularizeRecord(ShopResponse shop, DateTime startDate, DateTime endDate, int pageIndex, out int currentCount)
{
currentCount = 0;
try
{
var relayAPIHost = GetPlatformRelayAPIHost(shop.PlatformId);
@ -80,6 +82,7 @@ namespace BBWY.Server.Business.Sync
EndDate = endDate,
StartDate = startDate,
Platform = shop.PlatformId,
PageIndex = pageIndex
}, null, HttpMethod.Post);
if (httpResult.StatusCode != System.Net.HttpStatusCode.OK)
throw new Exception($"获取JD推广费用失败 {httpResult.Content}");
@ -89,6 +92,7 @@ namespace BBWY.Server.Business.Sync
throw new Exception($"获取JD推广费用失败 {presponse.Msg}");
SyncShopPopularizeRecord(long.Parse(shop.ShopId), presponse.Data);
currentCount = presponse.Data?.Count() ?? 0;
}
catch (Exception ex)
{
@ -97,21 +101,16 @@ namespace BBWY.Server.Business.Sync
}
}
/// <summary>
/// 俺也书
/// </summary>
/// <param name="shop"></param>
/// <param name="startDate"></param>
/// <param name="endDate"></param>
private void SyncAllShopPopularizeRecordByDate(ShopResponse shop, DateTime startDate, DateTime endDate)
{
var currentDate = startDate;
var pageIndex = 1;
while (true)
{
SyncShopPopularizeRecord(shop, currentDate, currentDate);
currentDate = currentDate.AddDays(1);
if (currentDate > endDate)
SyncShopPopularizeRecord(shop, startDate, endDate, pageIndex, out int count);
if (count < 100)
break;
pageIndex++;
Thread.Sleep(3000);
}
}
@ -128,7 +127,7 @@ namespace BBWY.Server.Business.Sync
DeleteOldData(shopList, date, date);
foreach (var shop in shopList)
{
Task.Factory.StartNew(() => SyncShopPopularizeRecord(shop, date, date),
Task.Factory.StartNew(() => SyncShopPopularizeRecord(shop, date, date, 1, out _),
System.Threading.CancellationToken.None,
TaskCreationOptions.LongRunning,
taskSchedulerManager.JDPopularizeTaskScheduler);
@ -149,7 +148,5 @@ namespace BBWY.Server.Business.Sync
taskSchedulerManager.JDPopularizeTaskScheduler);
}
}
}
}

4
BBWY.Server.Model/Dto/Request/Sync/SyncShopPopularizeRequest.cs

@ -4,10 +4,12 @@ using System.Text;
namespace BBWY.Server.Model.Dto
{
public class SyncShopPopularizeRequest:PlatformRequest
public class SyncShopPopularizeRequest : PlatformRequest
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int PageIndex { get; set; }
}
}

33
BBWY.Test/Program.cs

@ -11,6 +11,7 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using System.Threading;
namespace BBWY.Test
{
@ -27,21 +28,33 @@ namespace BBWY.Test
var appSecret = "866a9877f5f24b03b537483b4defe75d";
var token = "2ace3023200c4ea9aa682bbf8bffee18jztm";
var startDate = DateTime.Parse("2022-08-01");
var endDate = DateTime.Parse("2022-08-31");
var jdClient = GetJdClient(appkey, appSecret);
var req = new DspPlatformFinanceOpenapiQuerycostdetailsRequest();
var pageIndex = 1;
//req.accessPin = "abc";
//req.authType = "abc";
//req.operatorPin = "abc";
req.beginDate = "2022-09-21";
req.endDate = "2022-09-27";
req.pageNo = 1;
while (true)
{
var req = new DspPlatformFinanceOpenapiQuerycostdetailsRequest();
req.beginDate = startDate.ToString("yyyy-MM-dd");
req.endDate = endDate.ToString("yyyy-MM-dd");
req.pageNo = pageIndex;
req.pageSize = 100;
req.moneyType = 1;
//req.subPin = "abc";
DspPlatformFinanceOpenapiQuerycostdetailsResponse response = jdClient.Execute(req, token, DateTime.Now.ToLocalTime());
Console.WriteLine(JsonConvert.SerializeObject(response));
var response = jdClient.Execute(req, token, DateTime.Now.ToLocalTime());
Console.WriteLine($"pageIndex:{pageIndex}\r\n{JsonConvert.SerializeObject(response)}");
Console.WriteLine();
if (response.Json == null)
response.Json = JsonConvert.DeserializeObject<JObject>(response.Body);
var j = (JArray)response.Json["jingdong_dsp_platform_finance_openapi_querycostdetails_responce"]["returnType"]["data"]["page"]["data"];
if (j == null || !j.HasValues || j.Count < 100)
break;
pageIndex++;
Thread.Sleep(2000);
}
Console.ReadKey();
}
}

Loading…
Cancel
Save