shanji 3 years ago
parent
commit
68951377f8
  1. 2
      BBWY.Server.Business/PlatformSDK/JDBusiness.cs
  2. 25
      BBWY.Server.Business/Sync/JDPopularizeSyncBusiness.cs
  3. 2
      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(); var req = new DspPlatformFinanceOpenapiQuerycostdetailsRequest();
req.beginDate = syncShopPopularizeRequest.StartDate.ToString("yyyy-MM-dd"); req.beginDate = syncShopPopularizeRequest.StartDate.ToString("yyyy-MM-dd");
req.endDate = syncShopPopularizeRequest.EndDate.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.pageSize = 100;
req.moneyType = 1; req.moneyType = 1;

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

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

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

@ -9,5 +9,7 @@ namespace BBWY.Server.Model.Dto
public DateTime StartDate { get; set; } public DateTime StartDate { get; set; }
public DateTime EndDate { 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 Newtonsoft.Json.Linq;
using System; using System;
using System.Linq; using System.Linq;
using System.Threading;
namespace BBWY.Test namespace BBWY.Test
{ {
@ -27,21 +28,33 @@ namespace BBWY.Test
var appSecret = "866a9877f5f24b03b537483b4defe75d"; var appSecret = "866a9877f5f24b03b537483b4defe75d";
var token = "2ace3023200c4ea9aa682bbf8bffee18jztm"; var token = "2ace3023200c4ea9aa682bbf8bffee18jztm";
var startDate = DateTime.Parse("2022-08-01");
var endDate = DateTime.Parse("2022-08-31");
var jdClient = GetJdClient(appkey, appSecret); var jdClient = GetJdClient(appkey, appSecret);
var req = new DspPlatformFinanceOpenapiQuerycostdetailsRequest(); var pageIndex = 1;
//req.accessPin = "abc"; while (true)
//req.authType = "abc"; {
//req.operatorPin = "abc"; var req = new DspPlatformFinanceOpenapiQuerycostdetailsRequest();
req.beginDate = "2022-09-21"; req.beginDate = startDate.ToString("yyyy-MM-dd");
req.endDate = "2022-09-27"; req.endDate = endDate.ToString("yyyy-MM-dd");
req.pageNo = 1; req.pageNo = pageIndex;
req.pageSize = 100; req.pageSize = 100;
req.moneyType = 1; req.moneyType = 1;
//req.subPin = "abc";
DspPlatformFinanceOpenapiQuerycostdetailsResponse response = jdClient.Execute(req, token, DateTime.Now.ToLocalTime()); var response = jdClient.Execute(req, token, DateTime.Now.ToLocalTime());
Console.WriteLine(JsonConvert.SerializeObject(response)); 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(); Console.ReadKey();
} }
} }

Loading…
Cancel
Save