From 2ea23c01dd82f90da3638158ce852086ae1d4b96 Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Sun, 19 Nov 2023 03:27:17 +0800 Subject: [PATCH] =?UTF-8?q?spu=E7=BB=B4=E5=BA=A6=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SiNan.Business/AggregationBusiness.cs | 106 ++++++++++ SiNan.Business/GOIBusiness.cs | 4 +- SiNan.Business/TaskSchedulerManager.cs | 9 +- SiNan.Business/VenderBusiness.cs | 22 ++ .../AggregationJDPopularizeAdGroup.cs} | 6 + .../AggregationJDPopularizeAdGroupDaily.cs} | 0 .../AggregationJDPopularizeAdSku.cs | 6 + .../AggregationJDPopularizeAdSkuDaily.cs | 0 .../AggregationJDPopularizeCampaign.cs} | 6 + .../AggregationJDPopularizeCampaignDaily.cs} | 0 .../AggregationJDPopularizeSku.cs} | 6 + .../AggregationJDPopularizeSkuDaily.cs} | 0 .../AggregationJDPopularizeSpu.cs} | 6 + .../AggregationJDPopularizeSpuDaily.cs} | 0 SiNan.Model/Db/Mds/Shops.cs | 192 ++++++++++++++++++ .../Aggregation/SpuAggregationRequest.cs | 17 ++ 16 files changed, 371 insertions(+), 9 deletions(-) create mode 100644 SiNan.Business/AggregationBusiness.cs create mode 100644 SiNan.Business/VenderBusiness.cs rename SiNan.Model/Db/{GOI/Aggregationjdpopularizeadgroup.cs => Aggregation/AggregationJDPopularizeAdGroup.cs} (94%) rename SiNan.Model/Db/{GOI/Aggregationjdpopularizeadgroupdaily.cs => Aggregation/AggregationJDPopularizeAdGroupDaily.cs} (100%) rename SiNan.Model/Db/{GOI => Aggregation}/AggregationJDPopularizeAdSku.cs (95%) rename SiNan.Model/Db/{GOI => Aggregation}/AggregationJDPopularizeAdSkuDaily.cs (100%) rename SiNan.Model/Db/{GOI/Aggregationjdpopularizecampaign.cs => Aggregation/AggregationJDPopularizeCampaign.cs} (94%) rename SiNan.Model/Db/{GOI/Aggregationjdpopularizecampaigndaily.cs => Aggregation/AggregationJDPopularizeCampaignDaily.cs} (100%) rename SiNan.Model/Db/{GOI/Aggregationjdpopularizesku.cs => Aggregation/AggregationJDPopularizeSku.cs} (95%) rename SiNan.Model/Db/{GOI/Aggregationjdpopularizeskudaily.cs => Aggregation/AggregationJDPopularizeSkuDaily.cs} (100%) rename SiNan.Model/Db/{GOI/Aggregationjdpopularizespu.cs => Aggregation/AggregationJDPopularizeSpu.cs} (95%) rename SiNan.Model/Db/{GOI/Aggregationjdpopularizespudaily.cs => Aggregation/AggregationJDPopularizeSpuDaily.cs} (100%) create mode 100644 SiNan.Model/Db/Mds/Shops.cs create mode 100644 SiNan.Model/Dto/Request/Aggregation/SpuAggregationRequest.cs diff --git a/SiNan.Business/AggregationBusiness.cs b/SiNan.Business/AggregationBusiness.cs new file mode 100644 index 0000000..baa4fda --- /dev/null +++ b/SiNan.Business/AggregationBusiness.cs @@ -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().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().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() + .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 insertAggregationSpuDailyList = new List(); + List insertAggregationSkuDailyList = new List(); + List insertAggregationSpuList = new List(); + List insertAggregationSkuList = new List(); + IDictionary> updateAggregationSpuDictionary = new Dictionary>(); + IDictionary> updateAggregationSkuDictionary = new Dictionary>(); + + 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 + } +} diff --git a/SiNan.Business/GOIBusiness.cs b/SiNan.Business/GOIBusiness.cs index 652aeed..48c3d65 100644 --- a/SiNan.Business/GOIBusiness.cs +++ b/SiNan.Business/GOIBusiness.cs @@ -20,7 +20,7 @@ namespace SiNan.Business this.freeSqlMultiDBManager = freeSqlMultiDBManager; } - private IList StatisticsProductLevelGOI(IList skuIdList, DateTime startDate, DateTime endDate) + public IList StatisticsProductLevelGOI(IList skuIdList, DateTime startDate, DateTime endDate) { var costs = fsql.Select() .Where(jas => skuIdList.Contains(jas.Sku) && jas.Date >= startDate && jas.Date <= endDate) @@ -56,7 +56,7 @@ namespace SiNan.Business return list; } - private IList StatisticsPopularizeLevelGOI(IList skuIdList, DateTime? startDate, DateTime? endDate) + public IList StatisticsPopularizeLevelGOI(IList skuIdList, DateTime? startDate, DateTime? endDate) { IList list = new List(); diff --git a/SiNan.Business/TaskSchedulerManager.cs b/SiNan.Business/TaskSchedulerManager.cs index 6ba4071..4cddd88 100644 --- a/SiNan.Business/TaskSchedulerManager.cs +++ b/SiNan.Business/TaskSchedulerManager.cs @@ -4,17 +4,12 @@ namespace SiNan.Business { public class TaskSchedulerManager { - public LimitedConcurrencyLevelTaskScheduler SyncProductTaskScheduler { get; private set; } - public LimitedConcurrencyLevelTaskScheduler SyncOrderTaskScheduler { get; private set; } - - public LimitedConcurrencyLevelTaskScheduler PurchaseOrderCallbackTaskScheduler { get; private set; } + public LimitedConcurrencyLevelTaskScheduler AggregationSpuGOIScheduler { get; private set; } public TaskSchedulerManager() { - SyncOrderTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(10); - PurchaseOrderCallbackTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(10); - SyncProductTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(10); + AggregationSpuGOIScheduler = new LimitedConcurrencyLevelTaskScheduler(5); } } } diff --git a/SiNan.Business/VenderBusiness.cs b/SiNan.Business/VenderBusiness.cs new file mode 100644 index 0000000..663437d --- /dev/null +++ b/SiNan.Business/VenderBusiness.cs @@ -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 GetShopList(long? shopId = null) + { + return freeSqlMultiDBManager.MDSfsql.Select().Where(s => !string.IsNullOrEmpty(s.ShopId)) + .WhereIf(shopId != null, s => s.ShopId == shopId.ToString()) + .Where(s => s.IsEnabled == true) + .ToList(); + } + } +} diff --git a/SiNan.Model/Db/GOI/Aggregationjdpopularizeadgroup.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdGroup.cs similarity index 94% rename from SiNan.Model/Db/GOI/Aggregationjdpopularizeadgroup.cs rename to SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdGroup.cs index b1ca892..49ba8d5 100644 --- a/SiNan.Model/Db/GOI/Aggregationjdpopularizeadgroup.cs +++ b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdGroup.cs @@ -24,6 +24,12 @@ namespace SiNan.Model.Db [Column(DbType = "datetime")] public DateTime? CreateTime { get; set; } + /// + /// 数据日期 + /// + [Column(DbType = "datetime")] + public DateTime? Date { get; set; } + /// /// 近30天推广花费 /// diff --git a/SiNan.Model/Db/GOI/Aggregationjdpopularizeadgroupdaily.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdGroupDaily.cs similarity index 100% rename from SiNan.Model/Db/GOI/Aggregationjdpopularizeadgroupdaily.cs rename to SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdGroupDaily.cs diff --git a/SiNan.Model/Db/GOI/AggregationJDPopularizeAdSku.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdSku.cs similarity index 95% rename from SiNan.Model/Db/GOI/AggregationJDPopularizeAdSku.cs rename to SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdSku.cs index a8a8d46..704b720 100644 --- a/SiNan.Model/Db/GOI/AggregationJDPopularizeAdSku.cs +++ b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdSku.cs @@ -106,6 +106,12 @@ namespace SiNan.Model.Db [Column(DbType = "decimal(18,2)")] public decimal? YestodayPopularizeLevelProfit { get; set; } + /// + /// 数据日期 + /// + [Column(DbType = "datetime")] + public DateTime? Date { get; set; } + } } diff --git a/SiNan.Model/Db/GOI/AggregationJDPopularizeAdSkuDaily.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdSkuDaily.cs similarity index 100% rename from SiNan.Model/Db/GOI/AggregationJDPopularizeAdSkuDaily.cs rename to SiNan.Model/Db/Aggregation/AggregationJDPopularizeAdSkuDaily.cs diff --git a/SiNan.Model/Db/GOI/Aggregationjdpopularizecampaign.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeCampaign.cs similarity index 94% rename from SiNan.Model/Db/GOI/Aggregationjdpopularizecampaign.cs rename to SiNan.Model/Db/Aggregation/AggregationJDPopularizeCampaign.cs index 2527111..0e16e39 100644 --- a/SiNan.Model/Db/GOI/Aggregationjdpopularizecampaign.cs +++ b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeCampaign.cs @@ -85,6 +85,12 @@ namespace SiNan.Model.Db [Column(DbType = "decimal(18,2)")] public decimal? YestodayPopularizeLevelProfit { get; set; } + /// + /// 数据日期 + /// + [Column(DbType = "datetime")] + public DateTime? Date { get; set; } + } } diff --git a/SiNan.Model/Db/GOI/Aggregationjdpopularizecampaigndaily.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeCampaignDaily.cs similarity index 100% rename from SiNan.Model/Db/GOI/Aggregationjdpopularizecampaigndaily.cs rename to SiNan.Model/Db/Aggregation/AggregationJDPopularizeCampaignDaily.cs diff --git a/SiNan.Model/Db/GOI/Aggregationjdpopularizesku.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeSku.cs similarity index 95% rename from SiNan.Model/Db/GOI/Aggregationjdpopularizesku.cs rename to SiNan.Model/Db/Aggregation/AggregationJDPopularizeSku.cs index 63084a0..5c363ca 100644 --- a/SiNan.Model/Db/GOI/Aggregationjdpopularizesku.cs +++ b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeSku.cs @@ -114,6 +114,12 @@ namespace SiNan.Model.Db [Column(DbType = "decimal(18,2)")] public decimal? YestodayProductLevelProfit { get; set; } + /// + /// 数据日期 + /// + [Column(DbType = "datetime")] + public DateTime? Date { get; set; } + } } diff --git a/SiNan.Model/Db/GOI/Aggregationjdpopularizeskudaily.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeSkuDaily.cs similarity index 100% rename from SiNan.Model/Db/GOI/Aggregationjdpopularizeskudaily.cs rename to SiNan.Model/Db/Aggregation/AggregationJDPopularizeSkuDaily.cs diff --git a/SiNan.Model/Db/GOI/Aggregationjdpopularizespu.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeSpu.cs similarity index 95% rename from SiNan.Model/Db/GOI/Aggregationjdpopularizespu.cs rename to SiNan.Model/Db/Aggregation/AggregationJDPopularizeSpu.cs index f1216da..2b2a763 100644 --- a/SiNan.Model/Db/GOI/Aggregationjdpopularizespu.cs +++ b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeSpu.cs @@ -111,6 +111,12 @@ namespace SiNan.Model.Db [Column(DbType = "decimal(18,2)")] public decimal? YestodayProductLevelProfit { get; set; } + /// + /// 数据日期 + /// + [Column(DbType = "datetime")] + public DateTime? Date { get; set; } + } } diff --git a/SiNan.Model/Db/GOI/Aggregationjdpopularizespudaily.cs b/SiNan.Model/Db/Aggregation/AggregationJDPopularizeSpuDaily.cs similarity index 100% rename from SiNan.Model/Db/GOI/Aggregationjdpopularizespudaily.cs rename to SiNan.Model/Db/Aggregation/AggregationJDPopularizeSpuDaily.cs diff --git a/SiNan.Model/Db/Mds/Shops.cs b/SiNan.Model/Db/Mds/Shops.cs new file mode 100644 index 0000000..e72bc6b --- /dev/null +++ b/SiNan.Model/Db/Mds/Shops.cs @@ -0,0 +1,192 @@ +using FreeSql.DataAnnotations; +using System; + +namespace SiNan.Model.Db.Mds +{ + + [Table(Name = "shops", DisableSyncStructure = true)] + public partial class Shops + { + + /// + /// Id + /// + [Column(StringLength = 50, IsPrimary = true, IsNullable = false)] + public string Id { get; set; } + + /// + /// 店铺Key + /// + + public string AppKey { get; set; } + + /// + /// 店铺Secret + /// + + public string AppSecret { get; set; } + + /// + /// 店铺Token + /// + + public string AppToken { get; set; } + + /// + /// 店铺Key 暂定商品管理Key + /// + + public string AppKey2 { get; set; } + + /// + /// 店铺Secret 暂定商品管理Secret + /// + + public string AppSecret2 { get; set; } + + /// + /// 店铺Token + /// + + public string AppToken2 { get; set; } + + /// + /// 创建时间 + /// + [Column(DbType = "datetime")] + public DateTime CreateTime { get; set; } + + /// + /// 创建人Id + /// + [Column(StringLength = 50)] + public string CreatorId { get; set; } + + /// + /// 创建人 + /// + [Column(StringLength = 50, IsNullable = false)] + public string CreatorRealName { get; set; } + + /// + /// 0淘宝,1京东,2阿里巴巴 + /// + + public int? PlatformId { get; set; } + + /// + /// 平台名称 + /// + [Column(StringLength = 50)] + public string PlatformName { get; set; } + + + public string PurchaseAppKey { get; set; } + + + public string PurchaseAppSecret { get; set; } + + /// + /// 采购平台 + /// + [Column(StringLength = 50)] + public string PurchasePlatformId { get; set; } + + + /// + /// 商家编号 + /// + public string VenderId { get; set; } + + /// + /// 店铺ID + /// + + public string ShopId { get; set; } + + + public string ShopName { get; set; } + + /// + /// 店铺账号 + /// + + public string ShopNick { get; set; } + + /// + /// 店铺类型 + /// + + public string ShopType { get; set; } + + public string ManagePwd { get; set; } + + [Column(DbType = "decimal(11,2)")] + public decimal? PlatformCommissionRatio { get; set; } + + /// + /// SKU库存安全周转天数 + /// + public int SkuSafeTurnoverDays { get; set; } + + /// + /// 钉钉WebHook地址 + /// + [Column(StringLength = 255)] + public string DingDingWebHook { get; set; } + + /// + /// 钉钉密钥 + /// + [Column(StringLength = 100)] + public string DingDingKey { get; set; } + + + /// + /// 司南策略等级 + /// + public int SiNanPolicyLevel { get; set; } + + /// + /// 司南钉钉WebHook地址 + /// + [Column(StringLength = 255)] + public string SiNanDingDingWebHook { get; set; } + + /// + /// 司南钉钉密钥 + /// + [Column(StringLength = 100)] + public string SiNanDingDingKey { get; set; } + + /// + /// PJZS钉钉WebHook地址 + /// + [Column(StringLength = 255)] + public string PJZSDingDingWebHook { get; set; } + + /// + /// PJZS钉钉密钥 + /// + [Column(StringLength = 100)] + public string PJZSDingDingKey { get; set; } + + + + /// + /// 齐库钉钉WebHook地址 + /// + [Column(StringLength = 255)] + public string QiKuDingDingWebHook { get; set; } + + /// + /// 齐库钉钉密钥 + /// + [Column(StringLength = 100)] + public string QiKuDingDingKey { get; set; } + + [Column(DbType = "bit", IsNullable = true)] + public bool? IsEnabled { get; set; } = true; + } + +} diff --git a/SiNan.Model/Dto/Request/Aggregation/SpuAggregationRequest.cs b/SiNan.Model/Dto/Request/Aggregation/SpuAggregationRequest.cs new file mode 100644 index 0000000..126da2b --- /dev/null +++ b/SiNan.Model/Dto/Request/Aggregation/SpuAggregationRequest.cs @@ -0,0 +1,17 @@ +namespace SiNan.Model.Dto +{ + public class SpuAggregationRequest + { + /// + /// ShopId可空 + /// + public long? ShopId { get; set; } + + public DateTime AggregationDate { get; set; } + + /// + /// Spu可空 + /// + public string Spu { get; set; } + } +}