From 3af5187c3914304e85c106bb3e8e3fc857a3c8cc Mon Sep 17 00:00:00 2001 From: shanji <18996038927@163.com> Date: Wed, 22 Feb 2023 22:35:57 +0800 Subject: [PATCH] 1 --- .../Controllers/OrderSyncController.cs | 14 ++++ .../Sync/OrderSyncBusiness.cs | 27 ++++++++ BBWY.Test/Program.cs | 68 ++++++++++--------- 3 files changed, 76 insertions(+), 33 deletions(-) diff --git a/BBWY.Server.API/Controllers/OrderSyncController.cs b/BBWY.Server.API/Controllers/OrderSyncController.cs index 4f802c36..30ce2de9 100644 --- a/BBWY.Server.API/Controllers/OrderSyncController.cs +++ b/BBWY.Server.API/Controllers/OrderSyncController.cs @@ -2,6 +2,7 @@ using BBWY.Server.Model.Dto; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; namespace BBWY.Server.API.Controllers { @@ -34,6 +35,19 @@ namespace BBWY.Server.API.Controllers orderSyncBusiness.ManualSyncOrder(shopId, orderId, null, null); } + + /// + /// 订单同步 + /// + /// + /// + [HttpPost("{shopId}")] + public void SyncOrders([FromRoute] long shopId, [FromBody] IList orderIds) + { + orderSyncBusiness.ManualSyncOrder(shopId, orderIds, null, null); + } + + /// /// 根据日期同步 /// diff --git a/BBWY.Server.Business/Sync/OrderSyncBusiness.cs b/BBWY.Server.Business/Sync/OrderSyncBusiness.cs index a7b5986b..5e79ba99 100644 --- a/BBWY.Server.Business/Sync/OrderSyncBusiness.cs +++ b/BBWY.Server.Business/Sync/OrderSyncBusiness.cs @@ -16,6 +16,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Net.Http; +using System.Threading; using System.Threading.Tasks; using Yitter.IdGenerator; @@ -63,6 +64,32 @@ namespace BBWY.Server.Business SyncOrder(shop, orderId, startTime, endTime, isAuto: false, Enums.SortTimeType.StartTime); } + /// + /// 手动同步订单 + /// + /// + /// + /// + /// + public void ManualSyncOrder(long shopId, IList orderIds, DateTime? startTime = null, DateTime? endTime = null) + { + var shop = venderBusiness.GetShopByShopId(shopId.ToString()); + Task.Factory.StartNew(() => + { + var i = 1; + foreach (var orderId in orderIds) + { + SyncOrder(shop, orderId, startTime, endTime, isAuto: false, Enums.SortTimeType.StartTime); + Thread.Sleep(500); + i++; + Console.WriteLine(); + Console.WriteLine($"Sync Order {orderId}, {i}"); + } + Console.WriteLine("job done"); + }, System.Threading.CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.SyncOrderTaskScheduler); + + } + private void SyncOrder(ShopResponse shop, string orderId, DateTime? startTime = null, DateTime? endTime = null, bool isAuto = false, Enums.SortTimeType? sortTimeType = null) { try diff --git a/BBWY.Test/Program.cs b/BBWY.Test/Program.cs index 1315d04d..b5c38256 100644 --- a/BBWY.Test/Program.cs +++ b/BBWY.Test/Program.cs @@ -45,42 +45,44 @@ namespace BBWY.Test //var token = "44c19a1c1fbd4641957e6e8985ed1358jmtl"; //森王玩具 - var qtAppId = "BBWY2023022001"; - var qtAppSecret = "908e131365d5448ca651ba20ed7ddefe"; - var url = "https://qt.qiyue666.com/api/platform/product/spu/208"; - var callTime = DateTime.Now.ToString("yyyyMMddHHmmss"); - var randomNum = new Random().Next(100000, 999999).ToString(); - var p = new object[] { }; + //var qtAppId = "BBWY2023022001"; + //var qtAppSecret = "908e131365d5448ca651ba20ed7ddefe"; + //var url = "https://qt.qiyue666.com/api/platform/product/spu/208"; + //var callTime = DateTime.Now.ToString("yyyyMMddHHmmss"); + //var randomNum = new Random().Next(100000, 999999).ToString(); + //var p = new object[] { }; - var jmStr = JsonConvert.SerializeObject(new QuanTanSignParam() - { - appId = qtAppId, - appSecret = qtAppSecret, - callTime = callTime, - _params = JsonConvert.SerializeObject(p), - randomNum = randomNum - }); - var md5Str = Md5Encrypt(jmStr); - var qtToken = $"{qtAppId}-{callTime}-{md5Str}-{randomNum}"; + //var jmStr = JsonConvert.SerializeObject(new QuanTanSignParam() + //{ + // appId = qtAppId, + // appSecret = qtAppSecret, + // callTime = callTime, + // _params = JsonConvert.SerializeObject(p), + // randomNum = randomNum + //}); + //var md5Str = Md5Encrypt(jmStr); + //var qtToken = $"{qtAppId}-{callTime}-{md5Str}-{randomNum}"; - var qtRequestParam = new QuanTanRequestParam() - { - Params = p, - token = qtToken - }; - using (var httpClient = new HttpClient()) - { - using (var request = new HttpRequestMessage(HttpMethod.Post, url)) - { - request.Content = new StringContent(JsonConvert.SerializeObject(qtRequestParam), Encoding.UTF8, "application/json"); + //var qtRequestParam = new QuanTanRequestParam() + //{ + // Params = p, + // token = qtToken + //}; + //using (var httpClient = new HttpClient()) + //{ + // using (var request = new HttpRequestMessage(HttpMethod.Post, url)) + // { + // request.Content = new StringContent(JsonConvert.SerializeObject(qtRequestParam), Encoding.UTF8, "application/json"); - using (var response = httpClient.SendAsync(request).Result) - { - var result = response.Content.ReadAsStringAsync().Result; - Console.WriteLine(result); - } - } - } + // using (var response = httpClient.SendAsync(request).Result) + // { + // var result = response.Content.ReadAsStringAsync().Result; + // Console.WriteLine(result); + // } + // } + //} + + Console.ReadKey(); }