Browse Source

1

AddValidOverTime
shanji 2 years ago
parent
commit
bf01d30025
  1. 22
      BBWY.Server.Business/PlatformSDK/JDBusiness.cs
  2. 5
      BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
  3. 12
      BBWY.Server.Business/Product/ProductBusiness.cs
  4. 46
      BBWY.Server.Business/Sync/ProductSyncBusiness.cs
  5. 1
      BBWY.Server.Model/Db/Product/ProductSku.cs
  6. 7
      BBWY.Server.Model/Dto/Request/JD/JDQueryCategoryRequest.cs
  7. 13
      BBWY.Server.Model/Dto/Response/Product/ProductCategoryResponse.cs
  8. 11
      JD.API/Controllers/PlatformSDKController.cs

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

@ -182,6 +182,28 @@ namespace BBWY.Server.Business
}
public override ProductCategoryResponse GetCategoryInfo(JDQueryCategoryRequest request)
{
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
var req = new CategoryReadFindByIdRequest();
req.cid = long.Parse(request.CategoryId);
req.field = "fid,id,lev,name";
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
if (res.IsError)
throw new BusinessException(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg);
if (res.Json == null)
res.Json = JObject.Parse(res.Body);
var j = res.Json["jingdong_category_read_findById_responce"]["category"];
return new ProductCategoryResponse()
{
Fid = j.Value<string>("fid"),
Id = j.Value<string>("id"),
Name = j.Value<string>("name"),
Lev = j.Value<string>("lev")
};
}
public override IList<SimpleProductSkuResponse> GetSimpleProductSkuList(SearchProductSkuRequest searchProductSkuRequest)
{
var jdClient = GetJdClient(searchProductSkuRequest.AppKey, searchProductSkuRequest.AppSecret);

5
BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs

@ -43,6 +43,11 @@ namespace BBWY.Server.Business
throw new NotImplementedException();
}
public virtual ProductCategoryResponse GetCategoryInfo(JDQueryCategoryRequest request)
{
throw new NotImplementedException();
}
public virtual IList<JToken> GetOrderList(SearchPlatformOrderRequest searchOrderRequest)
{
throw new NotImplementedException();

12
BBWY.Server.Business/Product/ProductBusiness.cs

@ -40,5 +40,17 @@ namespace BBWY.Server.Business
throw new BusinessException(response.Msg) { Code = response.Code };
return response.Data;
}
public ProductCategoryResponse GetCategoyrInfo(JDQueryCategoryRequest request)
{
var relayAPIHost = GetPlatformRelayAPIHost(request.Platform);
var sendResult = restApiService.SendRequest(relayAPIHost, "api/PlatformSDK/GetCategoryInfo", request, GetYunDingRequestHeader(), HttpMethod.Post);
if (sendResult.StatusCode != System.Net.HttpStatusCode.OK)
throw new BusinessException(sendResult.Content) { Code = (int)sendResult.StatusCode };
var response = JsonConvert.DeserializeObject<ApiResponse<ProductCategoryResponse>>(sendResult.Content);
if (!response.Success)
throw new BusinessException(response.Msg) { Code = response.Code };
return response.Data;
}
}
}

46
BBWY.Server.Business/Sync/ProductSyncBusiness.cs

@ -13,6 +13,7 @@ using System.Collections.Generic;
using Newtonsoft.Json;
using FreeSql;
using System.Threading;
using System.Collections.Concurrent;
namespace BBWY.Server.Business.Sync
{
@ -20,6 +21,8 @@ namespace BBWY.Server.Business.Sync
{
private ProductBusiness productBusiness;
private ConcurrentDictionary<string, string> categoryCache;
public ProductSyncBusiness(RestApiService restApiService,
IOptions<GlobalConfig> options,
NLogManager nLogManager,
@ -38,6 +41,7 @@ namespace BBWY.Server.Business.Sync
yunDingBusiness)
{
this.productBusiness = productBusiness;
this.categoryCache = new ConcurrentDictionary<string, string>();
}
private string GetMainSkuId(IList<ProductSkuResponse> skuList)
@ -292,7 +296,8 @@ namespace BBWY.Server.Business.Sync
Logo = p.Logo,
ProductId = p.ProductId,
Price = p.Price,
CategoryId = p.Source.Value<int>("categoryId")
CategoryId = p.Source.Value<int>("categoryId"),
CategoryName = GetCategoryName(shop, p.Source.Value<string>("categoryId"))
}));
}
#endregion
@ -309,6 +314,19 @@ namespace BBWY.Server.Business.Sync
}
#endregion
#region 找出缺少类目的sku
var noCategoryProductList = productSkuList.Where(p => dbProductSkuList.Any(dp => dp.Id == p.Id && string.IsNullOrEmpty(dp.CategoryName))).ToList();
if (noCategoryProductList.Count() > 0)
{
foreach (var productSku in noCategoryProductList)
{
var categoryName = GetCategoryName(shop, productSku.Source.Value<string>("categoryId"));
var update = fsql.Update<ProductSku>(productSku.Id).Set(p => p.CategoryName, categoryName);
updateProductSkuList.Add(update);
}
}
#endregion
#region 找出接口查不出的SKU
var goneProductSkuList = dbProductSkuList.Where(dp => !productSkuList.Any(p => p.Id == dp.Id)).ToList();
if (goneProductSkuList.Count() > 0)
@ -366,12 +384,36 @@ namespace BBWY.Server.Business.Sync
public void SyncAllShopAllProduct()
{
var shopList = venderBusiness.GetShopList(platform: Enums.Platform.);
//SyncProduct(shopList.FirstOrDefault(s => s.ShopName == "熊玩具专营店"), true);
//SyncProduct(shopList.FirstOrDefault(s => s.ShopName == "披风熊玩具专营店"), true);
foreach (var shop in shopList)
{
Task.Factory.StartNew(() => SyncProduct(shop, true), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.ProductSyncTaskScheduler);
}
}
private string GetCategoryName(ShopResponse shop, string categoryId)
{
if (categoryCache.TryGetValue(categoryId, out string name))
return name;
try
{
var res = productBusiness.GetCategoyrInfo(new JDQueryCategoryRequest()
{
AppKey = shop.AppKey,
CategoryId = categoryId,
AppSecret = shop.AppSecret,
AppToken = shop.AppToken,
Platform = shop.PlatformId
});
categoryCache.TryAdd(categoryId, res.Name);
name = res.Name;
}
catch
{
}
return name;
}
}
}

1
BBWY.Server.Model/Db/Product/ProductSku.cs

@ -51,6 +51,7 @@ namespace BBWY.Server.Model.Db
/// </summary>
public int? CategoryId { get; set; }
public string CategoryName { get; set; }
}
}

7
BBWY.Server.Model/Dto/Request/JD/JDQueryCategoryRequest.cs

@ -0,0 +1,7 @@
namespace BBWY.Server.Model.Dto
{
public class JDQueryCategoryRequest:PlatformRequest
{
public string CategoryId { get; set; }
}
}

13
BBWY.Server.Model/Dto/Response/Product/ProductCategoryResponse.cs

@ -0,0 +1,13 @@
namespace BBWY.Server.Model.Dto
{
public class ProductCategoryResponse
{
public string Id { get; set; }
public string Name { get; set; }
public string Fid { get; set; }
public string Lev { get; set; }
}
}

11
JD.API/Controllers/PlatformSDKController.cs

@ -58,6 +58,17 @@ namespace JD.API.API.Controllers
return platformSDKBusinessList.FirstOrDefault(p => p.Platform == searchProductSkuRequest.Platform).GetProductSkuList(searchProductSkuRequest);
}
/// <summary>
/// 查询商品类目
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
public ProductCategoryResponse GetCategoryInfo([FromBody] JDQueryCategoryRequest request)
{
return platformSDKBusinessList.FirstOrDefault(p => p.Platform == request.Platform).GetCategoryInfo(request);
}
/// <summary>
/// 获取简单Sku列表 只包含SkuId和图片
/// </summary>

Loading…
Cancel
Save