shanji 3 years ago
parent
commit
05f9dbd2d7
  1. 143
      BBWY.Server.Business/EarlyWarning/JD/JDStockNumWarningBusiness.cs
  2. 1
      BBWY.Server.Business/Statistics/JDReportFormStatisticsBusiness.cs
  3. 1
      BBWY.Server.Business/Sync/JD/JDPopularizeReportFormOrderLevelSyncBusiness.cs

143
BBWY.Server.Business/EarlyWarning/JD/JDStockNumWarningBusiness.cs

@ -46,6 +46,7 @@ namespace BBWY.Server.Business
{
try
{
var loggerName = $"库存预警-{shop.ShopName}";
long shopId = long.Parse(shop.ShopId);
var yesterDayDate = DateTime.Now.Date.AddDays(-1);
var ysterDayTime = DateTime.Now.Date.AddSeconds(-1);
@ -105,6 +106,11 @@ namespace BBWY.Server.Business
var _2Ratio = firstCycleItemTotal == 0 ? 0 : 1.0 * secondCycleItemTotal / firstCycleItemTotal - 1;
var _3Ratio = secondCycleItemTotal == 0 ? 0 : 1.0 * thirdCycleItemTotal / secondCycleItemTotal - 1;
var _7dAvgSaleList = skuSaleDailyList.Where(s => s.Sku == sku && s.Date >= _7dAvgStartDate && s.Date <= yesterDayDate);
var _7dItemTotal = _7dAvgSaleList.Sum(s => s.ItemTotal - s.CancelItemTotal);
var _7dAvgItemTotal = 1.0 * _7dItemTotal / 7; //近7天日均销量
Enums.SkuStockNumCycleType skuStockNumCycleType = Enums.SkuStockNumCycleType.;
if (_2Ratio >= 0.2 && _3Ratio >= 0.2)
skuStockNumCycleType = Enums.SkuStockNumCycleType.;
@ -113,8 +119,27 @@ namespace BBWY.Server.Business
else if (_2Ratio < -0.2 && _3Ratio < -0.2)
skuStockNumCycleType = Enums.SkuStockNumCycleType.退;
var logContentBuilder = new StringBuilder();
logContentBuilder.AppendLine($"SKU:{sku}");
logContentBuilder.AppendLine($"商品状态:{skuStockNumCycleType}");
logContentBuilder.AppendLine($"第一周销量:{firstCycleItemTotal}");
logContentBuilder.AppendLine($"第二周期销量:{secondCycleItemTotal}, 相比第一周幅度:{_2Ratio}%");
logContentBuilder.AppendLine($"第三周期销量:{thirdCycleItemTotal}, 相比第二周幅度:{_3Ratio}%");
logContentBuilder.AppendLine($"近7天销量:{_7dItemTotal}");
logContentBuilder.AppendLine($"7天日均销量:{_7dAvgItemTotal}");
//dingdingContentBuilder.Append($"SKU:{sku}\n");
//dingdingContentBuilder.Append($"商品状态:{skuStockNumCycleType}\n");
//dingdingContentBuilder.Append($"近7天销量:{_7dItemTotal}\n");
//dingdingContentBuilder.Append($"7天日均销量:{_7dItemTotal}\n");
if (skuStockNumCycleType == Enums.SkuStockNumCycleType.)
{
logContentBuilder.AppendLine();
nLogManager.GetLogger(loggerName).Info(logContentBuilder);
continue;
}
Thread.Sleep(1000);
var restApiResult = restApiService.SendRequest(GetPlatformRelayAPIHost(shop.PlatformId), "api/platformsdk/GetStockNumBySku", new SearchProductSkuRequest()
@ -129,7 +154,13 @@ namespace BBWY.Server.Business
throw new Exception($"{sku} {restApiResult.Content}");
var response = JsonConvert.DeserializeObject<ApiResponse<JArray>>(restApiResult.Content);
if (response.Data == null || response.Data.Count() == 0)
{
logContentBuilder.AppendLine("未查询到JD库存数据");
logContentBuilder.AppendLine();
nLogManager.GetLogger(loggerName).Info(logContentBuilder);
continue;
}
var skuStockNumList = response.Data.Select(j => new
{
StockNum = j.Value<int>("stockNum"),
@ -138,73 +169,75 @@ namespace BBWY.Server.Business
SkuId = sku
});
var _7dAvgSaleList = skuSaleDailyList.Where(s => s.Sku == sku && s.Date >= _7dAvgStartDate && s.Date <= yesterDayDate);
var _7dItemTotal = _7dAvgSaleList.Sum(s => s.ItemTotal - s.CancelItemTotal);
var _7dAvgItemTotal = 1.0 * _7dItemTotal / 7; //近7天日均销量
var totalStockNum = skuStockNumList.Sum(s => s.StockNum); //总库存
var lessDay = _7dAvgItemTotal == 0 ? 0 : totalStockNum / _7dAvgItemTotal; //剩余天数
bool isWarning = false; //是否触发提醒
int suggestStockNum = 0; //建议备货量
if (skuStockNumCycleType == Enums.SkuStockNumCycleType.)
var skuStockNumGroups = skuStockNumList.GroupBy(s => s.Store?.Type ?? Enums.StockType.); //按仓库类型算库存
foreach (var skuStockNumGroup in skuStockNumGroups)
{
if (lessDay < 15)
var totalStockNum = skuStockNumGroup.Sum(s => s.StockNum); //总库存
var lessDay = _7dAvgItemTotal == 0 ? 0 : totalStockNum / _7dAvgItemTotal; //剩余天数
bool isWarning = false; //是否触发提醒
int suggestStockNum = 0; //建议备货量
if (skuStockNumCycleType == Enums.SkuStockNumCycleType.)
{
isWarning = true;
if (shop.SkuSafeTurnoverDays == 28)
suggestStockNum = (int)Math.Ceiling(_7dItemTotal * 4 * 1.5);
else if (shop.SkuSafeTurnoverDays == 21)
suggestStockNum = (int)Math.Ceiling(_7dItemTotal * 3 * 1.5);
else if (shop.SkuSafeTurnoverDays == 14)
suggestStockNum = (int)Math.Ceiling(_7dItemTotal * 2 * 1.5);
if (lessDay < 15)
{
isWarning = true;
if (shop.SkuSafeTurnoverDays == 28)
suggestStockNum = (int)Math.Ceiling(_7dItemTotal * 4 * 1.5);
else if (shop.SkuSafeTurnoverDays == 21)
suggestStockNum = (int)Math.Ceiling(_7dItemTotal * 3 * 1.5);
else if (shop.SkuSafeTurnoverDays == 14)
suggestStockNum = (int)Math.Ceiling(_7dItemTotal * 2 * 1.5);
}
}
}
else if (skuStockNumCycleType == Enums.SkuStockNumCycleType.)
{
if (lessDay < 8)
else if (skuStockNumCycleType == Enums.SkuStockNumCycleType.)
{
isWarning = true;
if (shop.SkuSafeTurnoverDays == 28)
suggestStockNum = _7dItemTotal * 4;
else if (shop.SkuSafeTurnoverDays == 21)
suggestStockNum = _7dItemTotal * 3;
else if (shop.SkuSafeTurnoverDays == 14)
suggestStockNum = _7dItemTotal * 2;
if (lessDay < 8)
{
isWarning = true;
if (shop.SkuSafeTurnoverDays == 28)
suggestStockNum = _7dItemTotal * 4;
else if (shop.SkuSafeTurnoverDays == 21)
suggestStockNum = _7dItemTotal * 3;
else if (shop.SkuSafeTurnoverDays == 14)
suggestStockNum = _7dItemTotal * 2;
}
}
}
else if (skuStockNumCycleType == Enums.SkuStockNumCycleType.退)
{
if (lessDay < 8)
else if (skuStockNumCycleType == Enums.SkuStockNumCycleType.退)
{
isWarning = true;
suggestStockNum = 0;
if (lessDay < 8)
{
isWarning = true;
suggestStockNum = 0;
}
}
}
#region 预警检查结果日志
nLogManager.GetLogger($"库存预警-{shop.ShopName}").Info($"sku {sku}, 周期 {skuStockNumCycleType}, 7天总销量 {_7dItemTotal}, 7天日均销量 {_7dAvgItemTotal}, 总库存 {totalStockNum}, 预估销售剩余天数 {lessDay}, 是否触发预警 {isWarning}");
#endregion
if (isWarning)
{
isSendDingTalk = true;
#region 拼接提醒内容
dingdingContentBuilder.Append($"SKU:{sku}\n");
dingdingContentBuilder.Append($"商品状态:{skuStockNumCycleType}\n");
dingdingContentBuilder.Append($"近7天销量:{_7dItemTotal}\n");
foreach (var stockNumInfo in skuStockNumList)
if (isWarning)
{
if (stockNumInfo.Store != null)
dingdingContentBuilder.Append($"{stockNumInfo.Store.Name}:{stockNumInfo.StockNum}件\n");
else
dingdingContentBuilder.Append($"{stockNumInfo.StoreId}:{stockNumInfo.StockNum}件\n");
isSendDingTalk = true;
dingdingContentBuilder.Append($"SKU:{sku}\n");
dingdingContentBuilder.Append($"商品状态:{skuStockNumCycleType}\n");
dingdingContentBuilder.Append($"近7天销量:{_7dItemTotal}\n");
foreach (var stockNumInfo in skuStockNumGroup)
dingdingContentBuilder.Append($"{stockNumInfo.Store?.Name ?? stockNumInfo.StoreId}:{stockNumInfo.StockNum}件");
if (skuStockNumCycleType == Enums.SkuStockNumCycleType. || skuStockNumCycleType == Enums.SkuStockNumCycleType.)
dingdingContentBuilder.Append($"低于安全周转天数,建议备货{suggestStockNum}件");
else if (skuStockNumCycleType == Enums.SkuStockNumCycleType.退)
dingdingContentBuilder.Append("商品进入衰退期,建议暂停备货,采购代发");
dingdingContentBuilder.AppendLine();
}
if (skuStockNumCycleType == Enums.SkuStockNumCycleType. || skuStockNumCycleType == Enums.SkuStockNumCycleType.)
dingdingContentBuilder.Append($"低于安全周转天数,建议备货{suggestStockNum}件");
else if (skuStockNumCycleType == Enums.SkuStockNumCycleType.退)
dingdingContentBuilder.Append("商品进入衰退期,建议暂停备货,采购代发");
#region 拼接sku在当前类型仓库的日志
logContentBuilder.AppendLine($"仓库类型:{skuStockNumGroup.Key}");
logContentBuilder.AppendLine($"总库存:{totalStockNum}");
logContentBuilder.AppendLine($"剩余天数:{lessDay}");
logContentBuilder.AppendLine($"建议备货量:{suggestStockNum}");
logContentBuilder.AppendLine($"是否触发预警:{isWarning}");
#endregion
}
logContentBuilder.AppendLine();
nLogManager.GetLogger(loggerName).Info(logContentBuilder);
}
if (isSendDingTalk)

1
BBWY.Server.Business/Statistics/JDReportFormStatisticsBusiness.cs

@ -1046,7 +1046,6 @@ namespace BBWY.Server.Business.Statistics
var customEndTime = gOIRequest.EndDate.AddDays(1).AddSeconds(-1);
var _7dCosts = fsql.Select<JDPopularizeAdSku, JDPopularizeAdSku>()
.InnerJoin((jas1, jas2) => jas1.Sku == jas2.Sku)
.Where((jas1, jas2) => gOIRequest.LevelIdList.Contains(jas1.AdId.Value) &&

1
BBWY.Server.Business/Sync/JD/JDPopularizeReportFormOrderLevelSyncBusiness.cs

@ -42,6 +42,7 @@ namespace BBWY.Server.Business.Sync
private void DeleteOldData(IList<ShopResponse> shops, DateTime startDate, DateTime endDate)
{
var shopIds = shops.Select(s => Convert.ToInt64(s.ShopId)).ToList();
endDate = endDate.Date.AddDays(1).AddSeconds(-1);
fsql.Delete<JDOrderPopularizeRelation>().Where(s => shopIds.Contains(s.ShopId.Value) &&
s.CookieTime >= startDate && s.CookieTime <= endDate).ExecuteAffrows();
}

Loading…
Cancel
Save