You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
5.3 KiB

2 years ago
using FreeSql;
using SiNan.Common.Log;
using SiNan.Common.Models;
using SiNan.Model.Db;
using SiNan.Model.Dto;
using Yitter.IdGenerator;
namespace SiNan.Business
{
public class AggregationBusiness : BaseBusiness, IDenpendency
{
private VenderBusiness venderBusiness;
private GOIBusiness goiBusiness;
private TaskSchedulerManager taskSchedulerManager;
public AggregationBusiness(IFreeSql fsql,
NLogManager nLogManager,
IIdGenerator idGenerator,
VenderBusiness venderBusiness,
GOIBusiness goiBusiness,
TaskSchedulerManager taskSchedulerManager) : base(fsql, nLogManager, idGenerator)
{
this.venderBusiness = venderBusiness;
this.goiBusiness = goiBusiness;
this.taskSchedulerManager = taskSchedulerManager;
}
#region SPU聚合任务
public void StartSpuAggregationTask()
{
StartSpuAggregationTaskByCondition(new SpuAggregationRequest()
{
AggregationDate = DateTime.Now.Date.AddDays(-1),
ShopId = null,
Spu = string.Empty
});
}
public void StartSpuAggregationTaskByCondition(SpuAggregationRequest request)
{
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);
}
}
private void SpuAggregation(long shopId, string spu, DateTime aggregationDate)
{
var aggregationStartDate = aggregationDate.Date;
var aggregationEndDate = aggregationDate.Date.AddDays(1).AddSeconds(-1);
var spuIdList = fsql.Select<Model.Db.Product>().Where(p => p.ShopId == shopId && p.State == 8)
.WhereIf(!string.IsNullOrEmpty(spu), p => p.Id == spu)
.OrderBy(p => p.CreateTime)
.ToList(p => p.Id);
var skuList = fsql.Select<Model.Db.ProductSku>().Where(ps => ps.ShopId == shopId && ps.State == 1)
.WhereIf(!string.IsNullOrEmpty(spu), ps => ps.ProductId == spu)
.OrderBy(ps => ps.CreateTime)
.ToList(ps => new
{
ps.ProductId,
ps.Id
});
var dbAggregationJDPopularizeSpuList = fsql.Select<AggregationJDPopularizeSpu, Product>()
.InnerJoin((aspu, p) => aspu.Id == p.Id)
.Where((aspu, p) => p.ShopId == shopId && p.State == 8)
.WhereIf(!string.IsNullOrEmpty(spu), (aspu, p) => p.Id == spu)
.ToList();
var i = 0;
var spuGroups = from s in spuIdList
let num = i++
group s by num / 10 into g
select g.ToArray(); //10个spu为一组
foreach (var spuGroup in spuGroups)
{
var currentGroupSkuList = skuList.Where(s => spuGroup.Contains(s.ProductId)).ToList();
var currentGroupSkuIdList = currentGroupSkuList.Select(ps => ps.Id).ToList();
List<AggregationJDPopularizeSpuDaily> insertAggregationSpuDailyList = new List<AggregationJDPopularizeSpuDaily>();
List<AggregationJDPopularizeSkuDaily> insertAggregationSkuDailyList = new List<AggregationJDPopularizeSkuDaily>();
List<AggregationJDPopularizeSpu> insertAggregationSpuList = new List<AggregationJDPopularizeSpu>();
List<AggregationJDPopularizeSku> insertAggregationSkuList = new List<AggregationJDPopularizeSku>();
IDictionary<string, IUpdate<AggregationJDPopularizeSpu>> updateAggregationSpuDictionary = new Dictionary<string, IUpdate<AggregationJDPopularizeSpu>>();
IDictionary<string, IUpdate<AggregationJDPopularizeSku>> updateAggregationSkuDictionary = new Dictionary<string, IUpdate<AggregationJDPopularizeSku>>();
var aggregationDate_ProductLevelList = goiBusiness.StatisticsProductLevelGOI(currentGroupSkuIdList, aggregationStartDate, aggregationEndDate);
var aggregationDate_PopularizeLevelList = goiBusiness.StatisticsPopularizeLevelGOI(currentGroupSkuIdList, aggregationStartDate, aggregationEndDate);
if ((DateTime.Now.Date - aggregationStartDate).TotalDays <= 31)
{
}
#region 处理sku
#endregion
}
}
#endregion
}
}