Browse Source

处理冲突

GOIAggregation
sanji 2 years ago
parent
commit
35c61900d0
  1. 26
      SiNan.Business/AggregationBusiness.cs
  2. 56
      SiNan.Business/GOIBusiness.cs
  3. 12
      SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdSkuDaily.cs

26
SiNan.Business/AggregationBusiness.cs

@ -380,7 +380,7 @@ namespace SiNan.Business
.Where((osku, o) => o.OrderState != Enums.OrderState. &&
o.IsGift == false &&
o.StartTime >= startDate &&
o.EndTime <= endDate &&
o.StartTime <= endDate &&
osku.Price > 0 &&
spuList.Contains(osku.ProductId))
.GroupBy((osku, o) => osku.ProductId)
@ -398,7 +398,7 @@ namespace SiNan.Business
.Where((osku, o) => o.OrderState != Enums.OrderState. &&
o.IsGift == false &&
o.StartTime >= startDate &&
o.EndTime <= endDate &&
o.StartTime <= endDate &&
osku.Price > 0 &&
skuList.Contains(osku.SkuId))
.GroupBy((osku, o) => new { osku.SkuId, osku.ProductId })
@ -460,7 +460,7 @@ namespace SiNan.Business
var IsAggregationDateEqualsYesterDay = (DateTime.Now.Date - aggregationDate).TotalDays == 1;
var campaignList = fsql.Select<JDPopularizeCampaign>().Where(c => c.ShopId == shopId && c.Date == aggregationDate)
.WhereIf(campaignId != null, c => c.CampaignId == campaignId)
.WhereIf(campaignId != null && campaignId != 0, c => c.CampaignId == campaignId)
//.GroupBy(c => new { c.CampaignId, c.BusinessType })
.ToList();
@ -625,9 +625,9 @@ namespace SiNan.Business
var IsAggregationDateEqualsYesterDay = (DateTime.Now.Date - aggregationDate).TotalDays == 1;
var adGroupList = fsql.Select<JDPopularizeAdGroup>().Where(c => c.ShopId == shopId && c.Date == aggregationDate)
.WhereIf(adGroupId != null, c => c.AdGroupId == adGroupId)
//.GroupBy(c => new { c.CampaignId, c.BusinessType })
.ToList();
.WhereIf(adGroupId != null && adGroupId != 0, c => c.AdGroupId == adGroupId)
//.GroupBy(c => new { c.CampaignId, c.BusinessType })
.ToList();
var adGroupIdList = adGroupList.Select(j => j.AdGroupId).Distinct().ToArray();
if (adGroupIdList.Count() == 0)
@ -788,7 +788,7 @@ namespace SiNan.Business
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)
.WhereIf(!string.IsNullOrEmpty(skuId), c => c.Sku == skuId)
//.GroupBy(c => new { c.Sku, c.BusinessType })
.ToList();
@ -798,6 +798,7 @@ namespace SiNan.Business
List<AggregationJDPopularizeAdSkuDaily> insertAggregationAdSkuDailyList = new List<AggregationJDPopularizeAdSkuDaily>();
var aggregationDate_PopularizeLevelList = goiBusiness.CalculationAdSkuLevelGOI(adSkuIdList, startDate_aggregationDate, endDate_aggregationDate);
var aggregationDate_ProductLevelList = goiBusiness.CalculationAdSkuProductLevelGOI(adSkuIdList, startDate_aggregationDate, endDate_aggregationDate);
var adSkuIndex = 0;
foreach (var adSku in adSkuList)
@ -805,10 +806,11 @@ namespace SiNan.Business
adSkuIndex++;
Console.WriteLine($"{DateTime.Now} {shopName} SKU聚合 {adSkuIndex}/{adSkuIdList.Count()}");
#region 处理计划每日聚合
#region 处理SKU每日聚合
var adSkuGoi_AggregationDate_PopularizeLevel = aggregationDate_PopularizeLevelList.FirstOrDefault(x => x.Sku == adSku.Sku && x.BusinessType == adSku.BusinessType);
var adSkuGoi_AggregationDate_ProductLevel = aggregationDate_ProductLevelList.FirstOrDefault(x => x.Sku == adSku.Sku && x.BusinessType == adSku.BusinessType);
if (adSkuGoi_AggregationDate_PopularizeLevel != null)
if (adSkuGoi_AggregationDate_PopularizeLevel != null || adSkuGoi_AggregationDate_ProductLevel != null)
{
var adSkuDailyAggregation = new AggregationJDPopularizeAdSkuDaily()
{
@ -819,10 +821,13 @@ namespace SiNan.Business
Cost = adSkuGoi_AggregationDate_PopularizeLevel?.Cost ?? 0M,
PopularizeLevelProfit = adSkuGoi_AggregationDate_PopularizeLevel?.Profit ?? 0M,
PopularizeLevelGOI = adSkuGoi_AggregationDate_PopularizeLevel?.GOI ?? 0M,
ProductLevelProfit = adSkuGoi_AggregationDate_ProductLevel?.Profit ?? 0M,
ProductLevelGOI = adSkuGoi_AggregationDate_ProductLevel?.GOI ?? 0M,
AdGroupId = adSku.AdGroupId,
CampaignId = adSku.CampaignId,
BusinessType = adSku.BusinessType,
SkuId = skuId
SkuId = adSku.Sku,
AdId = adSku.AdId
};
insertAggregationAdSkuDailyList.Add(adSkuDailyAggregation);
}
@ -833,7 +838,6 @@ namespace SiNan.Business
{
fsql.Delete<AggregationJDPopularizeAdSkuDaily>().Where(s => s.Date == aggregationDate && adSkuIdList.Contains(s.SkuId)).ExecuteAffrows();
fsql.Insert(insertAggregationAdSkuDailyList).ExecuteAffrows();
});
}
#endregion

56
SiNan.Business/GOIBusiness.cs

@ -253,6 +253,62 @@ namespace SiNan.Business
return list;
}
public IList<GOIByAdSku> CalculationAdSkuProductLevelGOI(IList<string> skuIdList, DateTime startDate, DateTime endDate)
{
var costs = fsql.Select<JDPopularizeAdSku>()
.Where(jas => skuIdList.Contains(jas.Sku) && jas.Date >= startDate && jas.Date <= endDate)
.GroupBy(jas => new { jas.Sku, jas.BusinessType })
.ToList(g => new
{
Cost = g.Sum(g.Value.Cost),
Sku = g.Key.Sku,
BusinessType = g.Key.BusinessType
});
var profits = fsql.Select<OrderCostDetail, Order>()
.InnerJoin((ocd, o) => ocd.OrderId == o.Id)
.Where((ocd, o) => skuIdList.Contains(ocd.SkuId) &&
ocd.IsEnabled &&
o.StartTime >= startDate &&
o.StartTime <= endDate &&
o.OrderState != Enums.OrderState. &&
o.IsGift == false)
.GroupBy((ocd, o) => ocd.SkuId)
.ToList(g => new
{
Profit = g.Sum(g.Value.Item1.SkuGrossProfit),
Sku = g.Key
});
IList<GOIByAdSku> list = new List<GOIByAdSku>();
foreach (var skuId in skuIdList)
{
{
var cost = costs.FirstOrDefault(x => x.Sku == skuId && x.BusinessType == 2)?.Cost ?? 0M;
var profit = profits.FirstOrDefault(x => x.Sku == skuId)?.Profit ?? 0M;
if (cost != 0 || profit != 0)
{
var adskuGoi = new GOIByAdSku() { Sku = skuId, Cost = cost, Profit = profit, BusinessType = 2 };
list.Add(adskuGoi);
}
}
{
var cost = costs.FirstOrDefault(x => x.Sku == skuId && x.BusinessType == 134217728)?.Cost ?? 0M;
var profit = profits.FirstOrDefault(x => x.Sku == skuId)?.Profit ?? 0M;
if (cost != 0 || profit != 0)
{
var adskuGoi = new GOIByAdSku() { Sku = skuId, Cost = cost, Profit = profit, BusinessType = 134217728 };
list.Add(adskuGoi);
}
}
}
return list;
}
//public ListResponse<ProductGOIResponse> QueryProductGOI(QueryProductGOIRequest request)
//{
// if (request.ShopId == 0)

12
SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdSkuDaily.cs

@ -61,6 +61,18 @@ namespace SiNan.Model.Db
[Column(DbType = "decimal(18,2)")]
public decimal? PopularizeLevelProfit { get; set; }
/// <summary>
/// 产品维度GOI
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? ProductLevelGOI { get; set; }
/// <summary>
/// 产品维度毛利
/// </summary>
[Column(DbType = "decimal(18,2)")]
public decimal? ProductLevelProfit { get; set; }
[Column(DbType = "bigint")]
public long? ShopId { get; set; }

Loading…
Cancel
Save