16 changed files with 371 additions and 9 deletions
@ -0,0 +1,106 @@ |
|||||
|
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
|
||||
|
} |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
using SiNan.Common.Models; |
||||
|
using SiNan.Model.Db.Mds; |
||||
|
|
||||
|
namespace SiNan.Business |
||||
|
{ |
||||
|
public class VenderBusiness : IDenpendency |
||||
|
{ |
||||
|
private FreeSqlMultiDBManager freeSqlMultiDBManager; |
||||
|
public VenderBusiness(FreeSqlMultiDBManager freeSqlMultiDBManager) |
||||
|
{ |
||||
|
this.freeSqlMultiDBManager = freeSqlMultiDBManager; |
||||
|
} |
||||
|
|
||||
|
public IList<Shops> GetShopList(long? shopId = null) |
||||
|
{ |
||||
|
return freeSqlMultiDBManager.MDSfsql.Select<Shops>().Where(s => !string.IsNullOrEmpty(s.ShopId)) |
||||
|
.WhereIf(shopId != null, s => s.ShopId == shopId.ToString()) |
||||
|
.Where(s => s.IsEnabled == true) |
||||
|
.ToList(); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,192 @@ |
|||||
|
using FreeSql.DataAnnotations; |
||||
|
using System; |
||||
|
|
||||
|
namespace SiNan.Model.Db.Mds |
||||
|
{ |
||||
|
|
||||
|
[Table(Name = "shops", DisableSyncStructure = true)] |
||||
|
public partial class Shops |
||||
|
{ |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Id
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 50, IsPrimary = true, IsNullable = false)] |
||||
|
public string Id { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 店铺Key
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string AppKey { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 店铺Secret
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string AppSecret { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 店铺Token
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string AppToken { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 店铺Key 暂定商品管理Key
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string AppKey2 { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 店铺Secret 暂定商品管理Secret
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string AppSecret2 { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 店铺Token
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string AppToken2 { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建时间
|
||||
|
/// </summary>
|
||||
|
[Column(DbType = "datetime")] |
||||
|
public DateTime CreateTime { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建人Id
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 50)] |
||||
|
public string CreatorId { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建人
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 50, IsNullable = false)] |
||||
|
public string CreatorRealName { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 0淘宝,1京东,2阿里巴巴
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public int? PlatformId { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 平台名称
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 50)] |
||||
|
public string PlatformName { get; set; } |
||||
|
|
||||
|
|
||||
|
public string PurchaseAppKey { get; set; } |
||||
|
|
||||
|
|
||||
|
public string PurchaseAppSecret { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 采购平台
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 50)] |
||||
|
public string PurchasePlatformId { get; set; } |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 商家编号
|
||||
|
/// </summary>
|
||||
|
public string VenderId { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 店铺ID
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string ShopId { get; set; } |
||||
|
|
||||
|
|
||||
|
public string ShopName { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 店铺账号
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string ShopNick { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 店铺类型
|
||||
|
/// </summary>
|
||||
|
|
||||
|
public string ShopType { get; set; } |
||||
|
|
||||
|
public string ManagePwd { get; set; } |
||||
|
|
||||
|
[Column(DbType = "decimal(11,2)")] |
||||
|
public decimal? PlatformCommissionRatio { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// SKU库存安全周转天数
|
||||
|
/// </summary>
|
||||
|
public int SkuSafeTurnoverDays { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 钉钉WebHook地址
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 255)] |
||||
|
public string DingDingWebHook { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 钉钉密钥
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 100)] |
||||
|
public string DingDingKey { get; set; } |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 司南策略等级
|
||||
|
/// </summary>
|
||||
|
public int SiNanPolicyLevel { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 司南钉钉WebHook地址
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 255)] |
||||
|
public string SiNanDingDingWebHook { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 司南钉钉密钥
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 100)] |
||||
|
public string SiNanDingDingKey { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// PJZS钉钉WebHook地址
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 255)] |
||||
|
public string PJZSDingDingWebHook { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// PJZS钉钉密钥
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 100)] |
||||
|
public string PJZSDingDingKey { get; set; } |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 齐库钉钉WebHook地址
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 255)] |
||||
|
public string QiKuDingDingWebHook { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 齐库钉钉密钥
|
||||
|
/// </summary>
|
||||
|
[Column(StringLength = 100)] |
||||
|
public string QiKuDingDingKey { get; set; } |
||||
|
|
||||
|
[Column(DbType = "bit", IsNullable = true)] |
||||
|
public bool? IsEnabled { get; set; } = true; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
namespace SiNan.Model.Dto |
||||
|
{ |
||||
|
public class SpuAggregationRequest |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// ShopId可空
|
||||
|
/// </summary>
|
||||
|
public long? ShopId { get; set; } |
||||
|
|
||||
|
public DateTime AggregationDate { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Spu可空
|
||||
|
/// </summary>
|
||||
|
public string Spu { get; set; } |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue