Browse Source

同步所有店铺订单

qianyi
shanji 3 years ago
parent
commit
cee8f9a0d0
  1. 13
      BBWY.Server.API/Controllers/OrderController.cs
  2. 25
      BBWY.Server.Business/Order/OrderBusiness.cs
  3. 5
      BBWY.Server.Business/Vender/VenderBusiness.cs

13
BBWY.Server.API/Controllers/OrderController.cs

@ -107,7 +107,7 @@ namespace BBWY.Server.API.Controllers
/// </summary> /// </summary>
/// <param name="relationPurchaseOrderRequestV2"></param> /// <param name="relationPurchaseOrderRequestV2"></param>
[HttpPost] [HttpPost]
public void RelationPurchaseOrderV2([FromBody]RelationPurchaseOrderRequestV2 relationPurchaseOrderRequestV2) public void RelationPurchaseOrderV2([FromBody] RelationPurchaseOrderRequestV2 relationPurchaseOrderRequestV2)
{ {
orderBusiness.RelationPurchaseOrderV2(relationPurchaseOrderRequestV2); orderBusiness.RelationPurchaseOrderV2(relationPurchaseOrderRequestV2);
} }
@ -142,6 +142,7 @@ namespace BBWY.Server.API.Controllers
orderBusiness.SyncOrderByDate(syncOrderByDateRequest); orderBusiness.SyncOrderByDate(syncOrderByDateRequest);
} }
/*
/// <summary> /// <summary>
/// 订单同步 /// 订单同步
/// </summary> /// </summary>
@ -151,6 +152,16 @@ namespace BBWY.Server.API.Controllers
{ {
Task.Factory.StartNew(() => orderBusiness.SyncOrder(shopId, string.Empty), System.Threading.CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.SyncOrderTaskScheduler); Task.Factory.StartNew(() => orderBusiness.SyncOrder(shopId, string.Empty), System.Threading.CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.SyncOrderTaskScheduler);
} }
*/
/// <summary>
/// 同步所有店铺订单
/// </summary>
[HttpPost]
public void SyncAllShopOrder()
{
orderBusiness.SyncAllShopOrder();
}
/// <summary> /// <summary>
/// 订单同步 /// 订单同步

25
BBWY.Server.Business/Order/OrderBusiness.cs

@ -29,6 +29,7 @@ namespace BBWY.Server.Business
private IIdGenerator idGenerator; private IIdGenerator idGenerator;
private TaskSchedulerManager taskSchedulerManager; private TaskSchedulerManager taskSchedulerManager;
private MDSBusiness mdsBusiness; private MDSBusiness mdsBusiness;
private VenderBusiness venderBusiness;
private Lazy<FreeSqlMultiDBManager> freeSqlMultiDBManagerLazy; private Lazy<FreeSqlMultiDBManager> freeSqlMultiDBManagerLazy;
private FreeSqlMultiDBManager freeSqlMultiDBManager => freeSqlMultiDBManagerLazy.Value; private FreeSqlMultiDBManager freeSqlMultiDBManager => freeSqlMultiDBManagerLazy.Value;
@ -39,6 +40,7 @@ namespace BBWY.Server.Business
IOptions<GlobalConfig> options, IOptions<GlobalConfig> options,
TaskSchedulerManager taskSchedulerManager, TaskSchedulerManager taskSchedulerManager,
MDSBusiness mdsBusiness, MDSBusiness mdsBusiness,
VenderBusiness venderBusiness,
IServiceProvider serviceProvider) : base(restApiService, options) IServiceProvider serviceProvider) : base(restApiService, options)
{ {
this.logger = logger; this.logger = logger;
@ -50,6 +52,7 @@ namespace BBWY.Server.Business
{ Enums.Platform., SyncJDOrder } { Enums.Platform., SyncJDOrder }
}; };
this.mdsBusiness = mdsBusiness; this.mdsBusiness = mdsBusiness;
this.venderBusiness = venderBusiness;
freeSqlMultiDBManagerLazy = new Lazy<FreeSqlMultiDBManager>(() => serviceProvider.GetService<FreeSqlMultiDBManager>()); freeSqlMultiDBManagerLazy = new Lazy<FreeSqlMultiDBManager>(() => serviceProvider.GetService<FreeSqlMultiDBManager>());
} }
@ -980,11 +983,17 @@ namespace BBWY.Server.Business
public void SyncOrder(long shopId, string orderId, DateTime? startTime = null, DateTime? endTime = null) public void SyncOrder(long shopId, string orderId, DateTime? startTime = null, DateTime? endTime = null)
{ {
var shop = mdsBusiness.GetShopInfoByShopId(shopId); var shop = mdsBusiness.GetShopInfoByShopId(shopId);
SyncOrder(shop, orderId, startTime, endTime);
}
private void SyncOrder(ShopResponse shop, string orderId, DateTime? startTime = null, DateTime? endTime = null, bool isAuto = false)
{
try try
{ {
logger.Info($"订单同步 {shop.ShopName} isAuto {isAuto}");
if (!syncOrderMethodDic.ContainsKey(shop.PlatformId)) if (!syncOrderMethodDic.ContainsKey(shop.PlatformId))
throw new Exception("不支持的平台"); throw new Exception("不支持的平台");
var shopId = long.Parse(shop.ShopId);
var relayAPIHost = GetPlatformRelayAPIHost(shop.PlatformId); var relayAPIHost = GetPlatformRelayAPIHost(shop.PlatformId);
var orderListApiResult = restApiService.SendRequest(relayAPIHost, "api/PlatformSDK/GetOrderList", new SearchPlatformOrderRequest() var orderListApiResult = restApiService.SendRequest(relayAPIHost, "api/PlatformSDK/GetOrderList", new SearchPlatformOrderRequest()
{ {
@ -997,7 +1006,7 @@ namespace BBWY.Server.Business
PageSize = 100, PageSize = 100,
Platform = shop.PlatformId, Platform = shop.PlatformId,
JDColType = string.IsNullOrEmpty(shop.ShopType) ? "0" : shop.ShopType, JDColType = string.IsNullOrEmpty(shop.ShopType) ? "0" : shop.ShopType,
SaveResponseLog = true, //SaveResponseLog = true,
OrderId = orderId OrderId = orderId
}, null, HttpMethod.Post); }, null, HttpMethod.Post);
if (orderListApiResult.StatusCode != System.Net.HttpStatusCode.OK) if (orderListApiResult.StatusCode != System.Net.HttpStatusCode.OK)
@ -1509,5 +1518,17 @@ namespace BBWY.Server.Business
} }
}); });
} }
/// <summary>
/// 同步所有店铺的订单
/// </summary>
public void SyncAllShopOrder()
{
var shopList = venderBusiness.GetShopList();
foreach (var shop in shopList)
{
Task.Factory.StartNew(() => SyncOrder(shop, string.Empty, isAuto: true), System.Threading.CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.SyncOrderTaskScheduler);
}
}
} }
} }

5
BBWY.Server.Business/Vender/VenderBusiness.cs

@ -219,5 +219,10 @@ namespace BBWY.Server.Business
} }
return departmentList; return departmentList;
} }
public IList<ShopResponse> GetShopList()
{
return freeSqlMultiDBManager.MDSfsql.Select<Shops>().Where(s => !string.IsNullOrEmpty(s.ShopId)).ToList<ShopResponse>();
}
} }
} }

Loading…
Cancel
Save