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 NLog; using System; using System.Collections.Generic; using System.Net.Http; using System.Text; using System.Threading.Tasks; using Yitter.IdGenerator; namespace BBWY.Server.Business.Sync { public class JDPopularizeSyncBusiness : BaseSyncBusiness, IDenpendency { public JDPopularizeSyncBusiness(RestApiService restApiService, IOptions options, ILogger logger, IFreeSql fsql, IIdGenerator idGenerator, TaskSchedulerManager taskSchedulerManager, VenderBusiness venderBusiness) : base(restApiService, options, logger, fsql, idGenerator, taskSchedulerManager, venderBusiness) { } private void SyncShopPopularizeRecord(long shopId, JArray jArray) { } private void SyncShopPopularizeRecord(ShopResponse shop, DateTime startDate, DateTime endDate) { try { var relayAPIHost = GetPlatformRelayAPIHost(shop.PlatformId); var httpResult = restApiService.SendRequest(relayAPIHost, "Api/PlatformSDK/GetJDShopSopularizeRecordList", new SyncShopPopularizeRequest() { AppKey = shop.AppKey, AppSecret = shop.AppSecret, AppToken = shop.AppToken, EndDate = endDate, StartDate = startDate, Platform = shop.PlatformId, }, null, HttpMethod.Post); if (httpResult.StatusCode != System.Net.HttpStatusCode.OK) throw new Exception($"获取JD推广费用失败 {httpResult.Content}"); var presponse = JsonConvert.DeserializeObject>(httpResult.Content); if (!presponse.Success) throw new Exception($"获取JD推广费用失败 {presponse.Msg}"); SyncShopPopularizeRecord(long.Parse(shop.ShopId), presponse.Data); } catch (Exception ex) { var shopData = JsonConvert.SerializeObject(shop); logger.Error(ex, $"SyncOrder ShopData:{shopData}"); } } public void SyncAllShopPopularizeRecord() { var shopList = venderBusiness.GetShopList(); foreach (var shop in shopList) { Task.Factory.StartNew(() => SyncShopPopularizeRecord(shop, DateTime.Now.Date.AddDays(-1), DateTime.Now.Date.AddDays(-1)), System.Threading.CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPopularizeTaskScheduler); } } } }