From fb886aad89717ba002c19bf524accee8bd67f3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E8=81=AA?= Date: Sat, 30 Sep 2023 03:49:13 +0800 Subject: [PATCH] =?UTF-8?q?pjzs=E9=AA=8C=E8=AF=81=E6=9C=BA=E5=88=B6?= =?UTF-8?q?=E6=94=B9=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EvaluationAssistantBusiness.cs | 6 ++- .../PlatformSDK/JDBusiness.cs | 54 +++++++++++++++---- JD.API/Startup.cs | 1 + 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs index 846d3f84..478cdfc5 100644 --- a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs +++ b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs @@ -526,6 +526,7 @@ namespace BBWY.Server.Business } var joinSkuCount = 0; + var joinSkuNoGiftList = new List(); var host = GetPlatformRelayAPIHost(Enums.Platform.京东); var haveGiftTemplateSku = giftTemplateSkuList != null && giftTemplateSkuList.Count() > 0; string barCode = string.Empty, categoryId = string.Empty; @@ -546,10 +547,10 @@ namespace BBWY.Server.Business var mainSkuListResponse = JsonConvert.DeserializeObject>>(mainSkuResult.Content); if (!mainSkuListResponse.Success) throw new BusinessException($"获取主商品sku失败 {mainSkuListResponse.Msg}"); - joinSkuCount = mainSkuListResponse.Data.Count(); + joinSkuNoGiftList.AddRange(mainSkuListResponse.Data.Select(s => s.Id)); //开启延迟任务 if (!string.IsNullOrEmpty(dbPromotionTask.CustomMotherSku)) - joinSkuCount += dbPromotionTask.CustomMotherSku.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Count(); + joinSkuNoGiftList.AddRange(dbPromotionTask.CustomMotherSku.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); if (haveGiftTemplateSku) { @@ -638,6 +639,7 @@ namespace BBWY.Server.Business .Set(pt => pt.Status, Enums.PromitionTaskStatus.进行中) .ExecuteAffrows(); + joinSkuCount = joinSkuNoGiftList.Distinct().Count(); Task.Factory.StartNew(() => StartPromotionDelayTask(request, startResponse, dbPromotionTask, shop, joinSkuCount), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionDelayTaskScheduler); } diff --git a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs index 4f850cec..7593f9eb 100644 --- a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs @@ -21,6 +21,7 @@ namespace BBWY.Server.Business { public class JDBusiness : PlatformSDKBusiness { + private DingDingBusiness dingDingBusiness; public override Enums.Platform Platform => Enums.Platform.京东; private readonly string searchFields = "orderId,venderId,orderType,payType,orderTotalPrice,orderSellerPrice,orderPayment,freightPrice,orderState,orderStateRemark,orderRemark,orderStartTime,orderEndTime,modified,consigneeInfo,itemInfoList,couponDetailList,taxFee,venderRemark,pin,waybill,storeOrder,storeId,sellerDiscount"; @@ -36,7 +37,10 @@ namespace BBWY.Server.Business }; - public JDBusiness(IMemoryCache memoryCache, NLogManager nLogManager) : base(memoryCache, nLogManager) { } + public JDBusiness(IMemoryCache memoryCache, NLogManager nLogManager, DingDingBusiness dingDingBusiness) : base(memoryCache, nLogManager) + { + this.dingDingBusiness = dingDingBusiness; + } private IJdClient GetJdClient(string appKey, string appSecret) { @@ -1294,7 +1298,7 @@ namespace BBWY.Server.Business } } - public override void StartJDPromotionDelayTask(StartPromotionTaskDelayRequest request + public override void StartJDPromotionDelayTask(StartPromotionTaskDelayRequest request) { Thread.Sleep(60 * 1000); try @@ -1307,23 +1311,53 @@ namespace BBWY.Server.Business throw; } - Thread.Sleep(30 * 1000); + Thread.Sleep(10000); #region 检查奶妈sku是否完全生效 + var lastQueryJoinCount = 0; + var isJoinCompleted = false; { - var i = 0; - while (i < 2) + var repeatCount = 0; + while (true) { - i++; var promotionTaskSkuList = GetPromotionTaskSku(request.AppKey, request.AppSecret, request.AppToken, request.JDPromotionId); - if (promotionTaskSkuList.Any(s => s.Value("bind_type") == 1 && s.Value("sku_status") == 0)) + var currentQueryJoinCount = promotionTaskSkuList.Count(s => s.Value("bind_type") == 1 && s.Value("sku_status") == 1); + if (currentQueryJoinCount == request.JoinSkuCount) { - Thread.Sleep(30000); - continue; + isJoinCompleted = true; + break; } - break; + + if (lastQueryJoinCount == 0) + lastQueryJoinCount = currentQueryJoinCount; + else if (lastQueryJoinCount == currentQueryJoinCount) + { + repeatCount++; + if (repeatCount > 2) + break; + } + lastQueryJoinCount = currentQueryJoinCount; + Thread.Sleep(30000); + } + } + #endregion + + #region 发送钉钉消息 + try + { + var ddMsg = new StringBuilder(); + ddMsg.AppendLine($"活动名称:{request.ActivityName}"); + ddMsg.AppendLine("任务状态:开始"); + if (!isJoinCompleted) + { + ddMsg.AppendLine($"任务奶妈数:{request.JoinSkuCount}"); + ddMsg.AppendLine($"参与奶妈数:{lastQueryJoinCount}"); + ddMsg.AppendLine("参与任务的奶妈数异常请检查"); } + if (!string.IsNullOrEmpty(request.PJZSDingDingKey) && !string.IsNullOrEmpty(request.PJZSDingDingWebHook)) + dingDingBusiness.SendDingDingBotMessage(request.PJZSDingDingKey, request.PJZSDingDingWebHook, ddMsg.ToString()); } + catch { } #endregion RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, request.DeleteGiftSkuList, request.MainProductSpu, request.FullTitle, request.BrandName, true); diff --git a/JD.API/Startup.cs b/JD.API/Startup.cs index 171f7ff1..6e3f8762 100644 --- a/JD.API/Startup.cs +++ b/JD.API/Startup.cs @@ -67,6 +67,7 @@ namespace JD.API }); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton();