|
|
@ -31,7 +31,8 @@ namespace SiNan.Business |
|
|
|
{ |
|
|
|
StartSpuAggregationTaskByCondition(new SpuAggregationRequest() |
|
|
|
{ |
|
|
|
AggregationDate = DateTime.Now.Date.AddDays(-1), |
|
|
|
AggregationStartDate = DateTime.Now.Date.AddDays(-1), |
|
|
|
AggregationEndDate = DateTime.Now.Date.AddDays(-1), |
|
|
|
ShopId = null, |
|
|
|
Spu = string.Empty |
|
|
|
}); |
|
|
@ -42,11 +43,30 @@ namespace SiNan.Business |
|
|
|
var shopList = venderBusiness.GetShopList(request.ShopId); |
|
|
|
foreach (var shop in shopList) |
|
|
|
{ |
|
|
|
Task.Factory.StartNew(() => SpuAggregation(long.Parse(shop.ShopId), request.Spu, request.AggregationDate), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.AggregationSpuGOIScheduler); |
|
|
|
Task.Factory.StartNew(() => SpuAggregation(shop.ShopName, long.Parse(shop.ShopId), request.Spu, request.AggregationStartDate, request.AggregationEndDate), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.AggregationSpuGOIScheduler); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void SpuAggregation(long shopId, string querySpu, DateTime aggregationDate) |
|
|
|
private void SpuAggregation(string shopName, long shopId, string querySpu, DateTime aggregationStartDate, DateTime aggregationEndDate) |
|
|
|
{ |
|
|
|
DateTime startDate = aggregationStartDate.Date; |
|
|
|
aggregationEndDate = aggregationEndDate.Date; |
|
|
|
try |
|
|
|
{ |
|
|
|
while (startDate <= aggregationEndDate) |
|
|
|
{ |
|
|
|
Console.WriteLine($"{DateTime.Now} {shopName} SPU聚合 聚合日期{startDate}"); |
|
|
|
SpuAggregation(shopName, shopId, querySpu, startDate, startDate == aggregationEndDate); |
|
|
|
startDate = startDate.AddDays(1); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
nLogManager.Default().Error(ex.Message, $"ShopId {shopId} SPU聚合失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void SpuAggregation(string shopName, long shopId, string querySpu, DateTime aggregationDate, bool isLastDate) |
|
|
|
{ |
|
|
|
aggregationDate = aggregationDate.Date; |
|
|
|
var startDate_aggregationDate = aggregationDate; |
|
|
@ -83,8 +103,13 @@ namespace SiNan.Business |
|
|
|
group s by num / 10 into g |
|
|
|
select g.ToArray(); //10个spu为一组
|
|
|
|
|
|
|
|
var spuGroupCount = spuGroups.Count(); |
|
|
|
var spuGroupIndex = 0; |
|
|
|
|
|
|
|
foreach (var spuGroup in spuGroups) |
|
|
|
{ |
|
|
|
spuGroupIndex++; |
|
|
|
Console.WriteLine($"{DateTime.Now} {shopName} SPU聚合 {spuGroupIndex}/{spuGroupCount}"); |
|
|
|
var currentGroupSkuList = skuList.Where(s => spuGroup.Contains(s.ProductId)).ToList(); |
|
|
|
var currentGroupSkuIdList = currentGroupSkuList.Select(ps => ps.Id).ToList(); |
|
|
|
|
|
|
@ -103,8 +128,10 @@ namespace SiNan.Business |
|
|
|
IList<GOIBySku> recent30d_PopularizeLevelList = null; |
|
|
|
|
|
|
|
|
|
|
|
if ((DateTime.Now.Date - startDate_aggregationDate).TotalDays <= 31) |
|
|
|
if (isLastDate && (DateTime.Now.Date - startDate_aggregationDate).TotalDays <= 31) |
|
|
|
{ |
|
|
|
Console.WriteLine($"{DateTime.Now} {shopName} SPU聚合 最后最日且小于31天,聚合近7天和近30天数据"); |
|
|
|
|
|
|
|
var startDate_Recent7day = DateTime.Now.Date.AddDays(-7); |
|
|
|
var endDate_Recent7day = DateTime.Now.Date.AddSeconds(-1); |
|
|
|
var startDate_Recent30day = DateTime.Now.Date.AddDays(-30); |
|
|
@ -350,7 +377,8 @@ namespace SiNan.Business |
|
|
|
{ |
|
|
|
StartCampaginAggregationTaskByCondition(new CampaignAggregationRequest() |
|
|
|
{ |
|
|
|
AggregationDate = DateTime.Now.Date.AddDays(-1), |
|
|
|
AggregationStartDate = DateTime.Now.Date.AddDays(-1), |
|
|
|
AggregationEndDate = DateTime.Now.Date.AddDays(-1), |
|
|
|
ShopId = null, |
|
|
|
CampaignId = null |
|
|
|
}); |
|
|
@ -361,11 +389,30 @@ namespace SiNan.Business |
|
|
|
var shopList = venderBusiness.GetShopList(request.ShopId); |
|
|
|
foreach (var shop in shopList) |
|
|
|
{ |
|
|
|
Task.Factory.StartNew(() => CampaignAggregation(long.Parse(shop.ShopId), request.CampaignId, request.AggregationDate), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.AggregationCampaignGOIScheduler); |
|
|
|
Task.Factory.StartNew(() => CampaignAggregation(shop.ShopName, long.Parse(shop.ShopId), request.CampaignId, request.AggregationStartDate, request.AggregationEndDate), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.AggregationCampaignGOIScheduler); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CampaignAggregation(long shopId, long? campaignId, DateTime aggregationDate) |
|
|
|
private void CampaignAggregation(string shopName, long shopId, long? campaignId, DateTime aggregationStartDate, DateTime aggregationEndDate) |
|
|
|
{ |
|
|
|
DateTime startDate = aggregationStartDate.Date; |
|
|
|
aggregationEndDate = aggregationEndDate.Date; |
|
|
|
try |
|
|
|
{ |
|
|
|
while (startDate <= aggregationEndDate) |
|
|
|
{ |
|
|
|
Console.WriteLine($"{DateTime.Now} {shopName} 计划聚合 聚合日期{startDate}"); |
|
|
|
CampaignAggregation(shopName, shopId, campaignId, startDate, startDate == aggregationEndDate); |
|
|
|
startDate = startDate.AddDays(1); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
nLogManager.Default().Error(ex.Message, $"ShopId {shopId} Campaign聚合失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CampaignAggregation(string shopName, long shopId, long? campaignId, DateTime aggregationDate, bool isLastDate) |
|
|
|
{ |
|
|
|
aggregationDate = aggregationDate.Date; |
|
|
|
var startDate_aggregationDate = aggregationDate; |
|
|
@ -391,7 +438,7 @@ namespace SiNan.Business |
|
|
|
IList<GOIByLevel> recent7d_PopularizeLevelList = null; |
|
|
|
IList<GOIByLevel> recent30d_PopularizeLevelList = null; |
|
|
|
|
|
|
|
if ((DateTime.Now.Date - startDate_aggregationDate).TotalDays <= 31) |
|
|
|
if (isLastDate && (DateTime.Now.Date - startDate_aggregationDate).TotalDays <= 31) |
|
|
|
{ |
|
|
|
var startDate_Recent7day = DateTime.Now.Date.AddDays(-7); |
|
|
|
var endDate_Recent7day = DateTime.Now.Date.AddSeconds(-1); |
|
|
@ -402,8 +449,12 @@ namespace SiNan.Business |
|
|
|
recent30d_PopularizeLevelList = goiBusiness.CalculationCampaignLevelGOI(campaignIdList, startDate_Recent30day, endDate_Recent30day); |
|
|
|
} |
|
|
|
|
|
|
|
var campaignIndex = 0; |
|
|
|
foreach (var campaign in campaignList) |
|
|
|
{ |
|
|
|
campaignIndex++; |
|
|
|
Console.WriteLine($"{DateTime.Now} {shopName} 计划聚合 {campaignIndex}/{campaignList.Count()}"); |
|
|
|
|
|
|
|
#region 处理计划每日聚合
|
|
|
|
var campaginGoi_AggregationDate_PopularizeLevel = aggregationDate_PopularizeLevelList.FirstOrDefault(x => x.LevelId == campaign.CampaignId); |
|
|
|
if (campaginGoi_AggregationDate_PopularizeLevel != null) |
|
|
@ -491,7 +542,8 @@ namespace SiNan.Business |
|
|
|
{ |
|
|
|
StartAdGroupAggregationTaskByCondition(new AdGroupAggregationRequest() |
|
|
|
{ |
|
|
|
AggregationDate = DateTime.Now.Date.AddDays(-1), |
|
|
|
AggregationStartDate = DateTime.Now.Date.AddDays(-1), |
|
|
|
AggregationEndDate = DateTime.Now.Date.AddDays(-1), |
|
|
|
ShopId = null, |
|
|
|
AdGroupId = null |
|
|
|
}); |
|
|
@ -502,11 +554,30 @@ namespace SiNan.Business |
|
|
|
var shopList = venderBusiness.GetShopList(request.ShopId); |
|
|
|
foreach (var shop in shopList) |
|
|
|
{ |
|
|
|
Task.Factory.StartNew(() => AdGroupAggregation(long.Parse(shop.ShopId), request.AdGroupId, request.AggregationDate), 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.AggregationCampaignGOIScheduler); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void AdGroupAggregation(long shopId, long? adGroupId, DateTime aggregationDate) |
|
|
|
private void AdGroupAggregation(string shopName, long shopId, long? adGroupId, DateTime aggregationStartDate, DateTime aggregationEndDate) |
|
|
|
{ |
|
|
|
DateTime startDate = aggregationStartDate.Date; |
|
|
|
aggregationEndDate = aggregationEndDate.Date; |
|
|
|
try |
|
|
|
{ |
|
|
|
while (startDate <= aggregationEndDate) |
|
|
|
{ |
|
|
|
Console.WriteLine($"{DateTime.Now} {shopName} 单元聚合 聚合日期{startDate}"); |
|
|
|
AdGroupAggregation(shopName, shopId, adGroupId, startDate, startDate == aggregationEndDate); |
|
|
|
startDate = startDate.AddDays(1); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
nLogManager.Default().Error(ex.Message, $"ShopId {shopId} AdGroup聚合失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void AdGroupAggregation(string shopName, long shopId, long? adGroupId, DateTime aggregationDate, bool isLastDate) |
|
|
|
{ |
|
|
|
aggregationDate = aggregationDate.Date; |
|
|
|
var startDate_aggregationDate = aggregationDate; |
|
|
@ -532,7 +603,7 @@ namespace SiNan.Business |
|
|
|
IList<GOIByLevel> recent7d_PopularizeLevelList = null; |
|
|
|
IList<GOIByLevel> recent30d_PopularizeLevelList = null; |
|
|
|
|
|
|
|
if ((DateTime.Now.Date - startDate_aggregationDate).TotalDays <= 31) |
|
|
|
if (isLastDate && (DateTime.Now.Date - startDate_aggregationDate).TotalDays <= 31) |
|
|
|
{ |
|
|
|
var startDate_Recent7day = DateTime.Now.Date.AddDays(-7); |
|
|
|
var endDate_Recent7day = DateTime.Now.Date.AddSeconds(-1); |
|
|
@ -543,8 +614,12 @@ namespace SiNan.Business |
|
|
|
recent30d_PopularizeLevelList = goiBusiness.CalculationAdGroupLevelGOI(adGroupIdList, startDate_Recent30day, endDate_Recent30day); |
|
|
|
} |
|
|
|
|
|
|
|
var adGroupIndex = 0; |
|
|
|
foreach (var adGroup in adGroupList) |
|
|
|
{ |
|
|
|
adGroupIndex++; |
|
|
|
Console.WriteLine($"{DateTime.Now} {shopName} 单元聚合 {adGroupIndex}/{adGroupList.Count()}"); |
|
|
|
|
|
|
|
#region 处理计划每日聚合
|
|
|
|
var adGroupGoi_AggregationDate_PopularizeLevel = aggregationDate_PopularizeLevelList.FirstOrDefault(x => x.LevelId == adGroup.CampaignId); |
|
|
|
if (adGroupGoi_AggregationDate_PopularizeLevel != null) |
|
|
|