shanji 3 years ago
parent
commit
bcc7b54e47
  1. 62
      BBWY.Server.Business/EarlyWarning/StoreHouseWarningBusiness.cs
  2. 17
      BBWY.Server.Business/PlatformSDK/JDBusiness.cs
  3. 5
      BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
  4. 8
      BBWY.Server.Business/Vender/VenderBusiness.cs
  5. 16
      BBWY.Server.Model/Db/Mds/Shops.cs
  6. 15
      BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs
  7. 11
      JD.API/Controllers/PlatformSDKController.cs

62
BBWY.Server.Business/EarlyWarning/StoreHouseWarningBusiness.cs

@ -0,0 +1,62 @@
using BBWY.Common.Http;
using BBWY.Common.Models;
using BBWY.Server.Model;
using BBWY.Server.Model.Db;
using BBWY.Server.Model.Dto;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using Yitter.IdGenerator;
namespace BBWY.Server.Business
{
public class StoreHouseWarningBusiness : BaseSyncBusiness, IDenpendency
{
private IList<Enums.StorageType> validStorageTypeList;
public StoreHouseWarningBusiness(RestApiService restApiService, IOptions<GlobalConfig> options, NLogManager nLogManager, IFreeSql fsql, IIdGenerator idGenerator, TaskSchedulerManager taskSchedulerManager, VenderBusiness venderBusiness, YunDingBusiness yunDingBusiness) : base(restApiService, options, nLogManager, fsql, idGenerator, taskSchedulerManager, venderBusiness, yunDingBusiness)
{
validStorageTypeList = new List<Enums.StorageType>() {
Enums.StorageType.,
Enums.StorageType.,
Enums.StorageType.
};
}
public void StartCheckStockNum()
{
var shopList = venderBusiness.GetShopList(filterTurnoverDays: true);
foreach (var shop in shopList)
{
CheckStockNum(shop);
}
}
private void CheckStockNum(ShopResponse shop)
{
long shopId = long.Parse(shop.ShopId);
var yesterDayDate = DateTime.Now.Date.AddDays(-1);
var ysterDayTime = DateTime.Now.Date.AddSeconds(-1);
var yesterDaySkuIds = fsql.Select<SkuDailySalesDetail, OrderSku, Order>()
.InnerJoin((s, osku, o) => s.Sku == osku.SkuId)
.InnerJoin((s, osku, o) => osku.OrderId == o.Id)
.Where((s, osku, o) => s.ShopId == shopId &&
s.Date == yesterDayDate &&
s.IsGift == false &&
s.ItemTotal > s.CancelItemTotal &&
o.StartTime >= yesterDayDate &&
o.StartTime <= ysterDayTime &&
validStorageTypeList.Contains(o.StorageType.Value))
.Distinct()
.ToList((s, osku, o) => s.Sku);
var queryStartDate = DateTime.Now.Date.AddDays(-9);
var skuSaleDailyList = fsql.Select<SkuDailySalesDetail>()
.Where(s => s.Date >= queryStartDate && s.Date <= yesterDayDate)
.Where(s => yesterDaySkuIds.Contains(s.Sku))
.ToList();
}
}
}

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

@ -622,5 +622,22 @@ namespace BBWY.Server.Business
return (JArray)res.Json["jingdong_store_findPartitionWhByIdAndStatus_responce"]["find_Partition_Warehouse_Result"]["result"];
}
public override JArray GetStockNumBySku(SearchProductSkuRequest request)
{
var jdClient = GetJdClient(request.AppKey, request.AppSecret);
var req = new StockReadFindSkuStockRequest();
req.skuId = long.Parse(request.Sku); // 10036238533172; //京仓sku
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
if (res.IsError)
throw new BusinessException($"获取sku库存出错 {(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
if (res.Json == null)
res.Json = JsonConvert.DeserializeObject<JObject>(res.Body);
return (JArray)res.Json["jingdong_stock_read_findSkuStock_responce"]["skuStocks"];
}
}
}

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

@ -142,5 +142,10 @@ namespace BBWY.Server.Business
{
throw new NotImplementedException();
}
public virtual JArray GetStockNumBySku(SearchProductSkuRequest request)
{
throw new NotImplementedException();
}
}
}

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

@ -22,7 +22,7 @@ namespace BBWY.Server.Business
public VenderBusiness(FreeSqlMultiDBManager freeSqlMultiDBManager,
RestApiService restApiService,
IOptions<GlobalConfig> options,
IIdGenerator idGenerator,YunDingBusiness yunDingBusiness) : base(restApiService, options, yunDingBusiness)
IIdGenerator idGenerator, YunDingBusiness yunDingBusiness) : base(restApiService, options, yunDingBusiness)
{
this.freeSqlMultiDBManager = freeSqlMultiDBManager;
this.idGenerator = idGenerator;
@ -222,11 +222,13 @@ namespace BBWY.Server.Business
return departmentList;
}
public IList<ShopResponse> GetShopList(long? shopId = null, Enums.Platform? platform = null)
public IList<ShopResponse> GetShopList(long? shopId = null, Enums.Platform? platform = null, bool filterTurnoverDays = false)
{
return freeSqlMultiDBManager.MDSfsql.Select<Shops>().Where(s => !string.IsNullOrEmpty(s.ShopId))
.WhereIf(shopId != null, s => s.ShopId == shopId.ToString())
.WhereIf(platform != null, s => s.PlatformId == (int)platform).ToList<ShopResponse>();
.WhereIf(platform != null, s => s.PlatformId == (int)platform)
.WhereIf(filterTurnoverDays, s => s.SkuSafeTurnoverDays != 0)
.ToList<ShopResponse>();
}
public ShopResponse GetShopByShopId(string shopId)

16
BBWY.Server.Model/Db/Mds/Shops.cs

@ -106,6 +106,22 @@ namespace BBWY.Server.Model.Db.Mds
[Column(DbType = "decimal(11,2)")]
public decimal? PlatformCommissionRatio { get; set; }
/// <summary>
/// SKU库存安全周转天数
/// </summary>
public int SkuSafeTurnoverDays { get; set; }
/// <summary>
/// 钉钉WebHook地址
/// </summary>
[Column(StringLength = 255)]
public string DingDingWebHook { get; set; }
/// <summary>
/// 钉钉密钥
/// </summary>
[Column(StringLength = 100)]
public string DingDingKey { get; set; }
}
}

15
BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs

@ -35,6 +35,21 @@ namespace BBWY.Server.Model.Dto
public decimal? PlatformCommissionRatio { get; set; }
public IList<PurchaseAccountResponse> PurchaseList { get; set; }
/// <summary>
/// SKU库存安全周转天数
/// </summary>
public int SkuSafeTurnoverDays { get; set; }
/// <summary>
/// 钉钉WebHook地址
/// </summary>
public string DingDingWebHook { get; set; }
/// <summary>
/// 钉钉密钥
/// </summary>
public string DingDingKey { get; set; }
}
public class PurchaseAccountResponse

11
JD.API/Controllers/PlatformSDKController.cs

@ -265,5 +265,16 @@ namespace JD.API.API.Controllers
{
return platformSDKBusinessList.FirstOrDefault(p => p.Platform == request.Platform).GetStoreHouseList(request);
}
/// <summary>
/// 查询单个sku库存
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
public JArray GetStockNumBySku([FromBody] SearchProductSkuRequest request)
{
return platformSDKBusinessList.FirstOrDefault(p => p.Platform == request.Platform).GetStockNumBySku(request);
}
}
}

Loading…
Cancel
Save