From e85e5079db86ecb2110c26bfee493d75912ac011 Mon Sep 17 00:00:00 2001 From: shanji <18996038927@163.com> Date: Wed, 1 Feb 2023 18:14:13 +0800 Subject: [PATCH] 1 --- .../EvaluationAssistantBusiness.cs | 35 ++++++++++++++++++- BBWY.Server.Business/TaskSchedulerManager.cs | 3 ++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs index daf67d1b..dc969838 100644 --- a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs +++ b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs @@ -11,6 +11,8 @@ using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; using Yitter.IdGenerator; namespace BBWY.Server.Business @@ -21,10 +23,16 @@ namespace BBWY.Server.Business private IIdGenerator idGenerator; - public EvaluationAssistantBusiness(RestApiService restApiService, IOptions options, YunDingBusiness yunDingBusiness, IFreeSql fsql, IIdGenerator idGenerator) : base(restApiService, options, yunDingBusiness) + private TaskSchedulerManager taskSchedulerManager; + + private VenderBusiness venderBusiness; + + public EvaluationAssistantBusiness(RestApiService restApiService, IOptions options, YunDingBusiness yunDingBusiness, IFreeSql fsql, IIdGenerator idGenerator, TaskSchedulerManager taskSchedulerManager, VenderBusiness venderBusiness) : base(restApiService, options, yunDingBusiness) { this.fsql = fsql; this.idGenerator = idGenerator; + this.taskSchedulerManager = taskSchedulerManager; + this.venderBusiness = venderBusiness; } #region 赠品模板 @@ -475,5 +483,30 @@ namespace BBWY.Server.Business fsql.Update(request.Id).Set(pt => pt.Status, Enums.PromitionTaskStatus.已停止).ExecuteAffrows(); } #endregion + + public void StartMonitor(long? shopId) + { + var shopList = venderBusiness.GetShopList(shopId, Enums.Platform.京东); + + foreach (var shop in shopList) + { + Task.Factory.StartNew(() => MonitorTaskCore(shop), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionMonitorTaskScheduler); + } + } + + #region 自动任务 + private void MonitorTaskCore(ShopResponse shop) + { + var shopId = long.Parse(shop.ShopId); + + #region 查询正在进行的任务 + var runningTaskList = fsql.Select().Where(pt => pt.ShopId == shopId && pt.Status == Enums.PromitionTaskStatus.进行中).ToList(); + if (runningTaskList == null || runningTaskList.Count() == 0) + return; + + + #endregion + } + #endregion } } diff --git a/BBWY.Server.Business/TaskSchedulerManager.cs b/BBWY.Server.Business/TaskSchedulerManager.cs index 70d65ac2..2b5c2370 100644 --- a/BBWY.Server.Business/TaskSchedulerManager.cs +++ b/BBWY.Server.Business/TaskSchedulerManager.cs @@ -24,6 +24,8 @@ namespace BBWY.Server.Business public LimitedConcurrencyLevelTaskScheduler JDPromotionDelayTaskScheduler { get; private set; } + public LimitedConcurrencyLevelTaskScheduler JDPromotionMonitorTaskScheduler { get; private set; } + public TaskSchedulerManager() { SyncOrderTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(10); @@ -39,6 +41,7 @@ namespace BBWY.Server.Business GOIWarningTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(10); JDPromotionDelayTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(10); + JDPromotionMonitorTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(10); } } }