|
|
@ -574,7 +574,7 @@ namespace SiNan.Business |
|
|
|
var shopList = venderBusiness.GetShopList(request.ShopId); |
|
|
|
foreach (var shop in shopList) |
|
|
|
{ |
|
|
|
Task.Factory.StartNew(() => AdGroupAggregation(shop.ShopName, long.Parse(shop.ShopId), request.AdGroupId, request.AggregationStartDate, request.AggregationEndDate), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.AggregationCampaignGOIScheduler); |
|
|
|
Task.Factory.StartNew(() => AdGroupAggregation(shop.ShopName, long.Parse(shop.ShopId), request.AdGroupId, request.AggregationStartDate, request.AggregationEndDate), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.AggregationAdGroupGOIScheduler); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -721,12 +721,100 @@ namespace SiNan.Business |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region SKU创意维度聚合任务
|
|
|
|
#region SKU创意/推广维度聚合任务
|
|
|
|
public void StartAdSkuAggregationTask() |
|
|
|
{ |
|
|
|
StartAdSkuAggregationTaskByCondition(new AdSkuAggregationRequest() |
|
|
|
{ |
|
|
|
AggregationStartDate = DateTime.Now.Date.AddDays(-1), |
|
|
|
AggregationEndDate = DateTime.Now.Date.AddDays(-1), |
|
|
|
ShopId = null |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
public void StartAdSkuAggregationTaskByCondition(AdSkuAggregationRequest request) |
|
|
|
{ |
|
|
|
var shopList = venderBusiness.GetShopList(request.ShopId); |
|
|
|
foreach (var shop in shopList) |
|
|
|
{ |
|
|
|
Task.Factory.StartNew(() => AdSkuAggregation(shop.ShopName, long.Parse(shop.ShopId), request.SkuId, request.AggregationStartDate, request.AggregationEndDate), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.AggregationCampaignGOIScheduler); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void AdSkuAggregation(string shopName, long shopId, string skuId, DateTime aggregationStartDate, DateTime aggregationEndDate) |
|
|
|
{ |
|
|
|
DateTime startDate = aggregationStartDate.Date; |
|
|
|
aggregationEndDate = aggregationEndDate.Date; |
|
|
|
try |
|
|
|
{ |
|
|
|
while (startDate <= aggregationEndDate) |
|
|
|
{ |
|
|
|
Console.WriteLine($"{DateTime.Now} {shopName} SKU聚合 聚合日期{startDate}"); |
|
|
|
AdSkuAggregation(shopName, shopId, skuId, startDate, startDate == aggregationEndDate); |
|
|
|
startDate = startDate.AddDays(1); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
nLogManager.Default().Error(ex.Message, $"ShopId {shopId} AdGroup聚合失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#region SKU智能投放维度聚合任务
|
|
|
|
private void AdSkuAggregation(string shopName, long shopId, string skuId, DateTime aggregationDate, bool isLastDate) |
|
|
|
{ |
|
|
|
aggregationDate = aggregationDate.Date; |
|
|
|
var startDate_aggregationDate = aggregationDate; |
|
|
|
var endDate_aggregationDate = aggregationDate.AddDays(1).AddSeconds(-1); |
|
|
|
var IsAggregationDateEqualsYesterDay = (DateTime.Now.Date - aggregationDate).TotalDays == 1; |
|
|
|
|
|
|
|
var adSkuList = fsql.Select<JDPopularizeAdSku>().Where(c => c.ShopId == shopId && c.Date == aggregationDate) |
|
|
|
.WhereIf(skuId != null, c => c.Sku == skuId) |
|
|
|
//.GroupBy(c => new { c.Sku, c.BusinessType })
|
|
|
|
.ToList(); |
|
|
|
|
|
|
|
var adSkuIdList = adSkuList.Select(j => j.Sku).Distinct().ToArray(); |
|
|
|
if (adSkuIdList.Count() == 0) |
|
|
|
return; |
|
|
|
|
|
|
|
List<AggregationJDPopularizeAdSkuDaily> insertAggregationAdSkuDailyList = new List<AggregationJDPopularizeAdSkuDaily>(); |
|
|
|
var aggregationDate_PopularizeLevelList = goiBusiness.CalculationAdSkuLevelGOI(adSkuIdList, startDate_aggregationDate, endDate_aggregationDate); |
|
|
|
|
|
|
|
var adSkuIndex = 0; |
|
|
|
foreach (var adSku in adSkuList) |
|
|
|
{ |
|
|
|
adSkuIndex++; |
|
|
|
Console.WriteLine($"{DateTime.Now} {shopName} SKU聚合 {adSkuIndex}/{adSkuIdList.Count()}"); |
|
|
|
|
|
|
|
#region 处理计划每日聚合
|
|
|
|
var adSkuGoi_AggregationDate_PopularizeLevel = aggregationDate_PopularizeLevelList.FirstOrDefault(x => x.Sku == adSku.Sku && x.BusinessType == adSku.BusinessType); |
|
|
|
|
|
|
|
if (adSkuGoi_AggregationDate_PopularizeLevel != null) |
|
|
|
{ |
|
|
|
var adSkuDailyAggregation = new AggregationJDPopularizeAdSkuDaily() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
Date = aggregationDate, |
|
|
|
ShopId = shopId, |
|
|
|
Cost = adSkuGoi_AggregationDate_PopularizeLevel?.Cost ?? 0M, |
|
|
|
PopularizeLevelProfit = adSkuGoi_AggregationDate_PopularizeLevel?.Profit ?? 0M, |
|
|
|
PopularizeLevelGOI = adSkuGoi_AggregationDate_PopularizeLevel?.GOI ?? 0M, |
|
|
|
AdGroupId = adSku.AdGroupId, |
|
|
|
CampaignId = adSku.CampaignId, |
|
|
|
BusinessType = adSku.BusinessType |
|
|
|
}; |
|
|
|
insertAggregationAdSkuDailyList.Add(adSkuDailyAggregation); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
fsql.Delete<AggregationJDPopularizeAdSkuDaily>().Where(s => s.Date == aggregationDate && adSkuIdList.Contains(s.SkuId)).ExecuteAffrows(); |
|
|
|
fsql.Insert(insertAggregationAdSkuDailyList).ExecuteAffrows(); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |
|
|
|