diff --git a/BBWY.Server.API/Controllers/EvaluationAssistantController.cs b/BBWY.Server.API/Controllers/EvaluationAssistantController.cs index a9526ceb..a336dc58 100644 --- a/BBWY.Server.API/Controllers/EvaluationAssistantController.cs +++ b/BBWY.Server.API/Controllers/EvaluationAssistantController.cs @@ -2,6 +2,7 @@ using BBWY.Server.Model.Dto; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using System; using System.Collections.Generic; namespace BBWY.Server.API.Controllers @@ -106,7 +107,7 @@ namespace BBWY.Server.API.Controllers [HttpPost] public void StartPromotionTask([FromBody] StartPromotionTaskRequest request) { - evaluationAssistantBusiness.StartPromotionTask(request); + evaluationAssistantBusiness.StartPromotionTask(request, null); } /// @@ -124,7 +125,7 @@ namespace BBWY.Server.API.Controllers /// /// [HttpDelete("{pjzsTaskId}")] - public void DeletePromotionTask([FromRoute]long pjzsTaskId) + public void DeletePromotionTask([FromRoute] long pjzsTaskId) { evaluationAssistantBusiness.DeletePromotionTask(pjzsTaskId); } diff --git a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs index 9276b1d2..c42b544a 100644 --- a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs +++ b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs @@ -5,6 +5,8 @@ using BBWY.Server.Model; using BBWY.Server.Model.Db; using BBWY.Server.Model.Dto; using FreeSql; +using Jd.Api.Domain; + //using Jd.Api.Domain; using Microsoft.Extensions.Options; using Newtonsoft.Json; @@ -27,7 +29,8 @@ namespace BBWY.Server.Business private IIdGenerator idGenerator; private TaskSchedulerManager taskSchedulerManager; private VenderBusiness venderBusiness; - private DingDingBusiness dingDingBusiness; + //private DingDingBusiness dingDingBusiness; + private QYMessageCenterBusiness qyMessageCenterBusiness; private NLogManager nLogManager; private List validOrderStateList; private List preTaskStateList; @@ -36,14 +39,15 @@ namespace BBWY.Server.Business private char[] spliter; - public EvaluationAssistantBusiness(RestApiService restApiService, IOptions options, YunDingBusiness yunDingBusiness, IFreeSql fsql, IIdGenerator idGenerator, TaskSchedulerManager taskSchedulerManager, VenderBusiness venderBusiness, DingDingBusiness dingDingBusiness, NLogManager nLogManager, ProductBusiness productBusiness, FreeSqlMultiDBManager freeSqlMultiDBManager) : base(restApiService, options, yunDingBusiness) + public EvaluationAssistantBusiness(RestApiService restApiService, IOptions options, YunDingBusiness yunDingBusiness, IFreeSql fsql, IIdGenerator idGenerator, TaskSchedulerManager taskSchedulerManager, VenderBusiness venderBusiness, QYMessageCenterBusiness qyMessageCenterBusiness, NLogManager nLogManager, ProductBusiness productBusiness, FreeSqlMultiDBManager freeSqlMultiDBManager) : base(restApiService, options, yunDingBusiness) { this.fsql = fsql; this.idGenerator = idGenerator; this.taskSchedulerManager = taskSchedulerManager; this.venderBusiness = venderBusiness; - this.dingDingBusiness = dingDingBusiness; + //this.dingDingBusiness = dingDingBusiness; + this.qyMessageCenterBusiness = qyMessageCenterBusiness; this.nLogManager = nLogManager; this.productBusiness = productBusiness; this.freeSqlMultiDBManager = freeSqlMultiDBManager; @@ -504,7 +508,8 @@ namespace BBWY.Server.Business /// /// /// - public void StartPromotionTask(StartPromotionTaskRequest request, ShopResponse shop = null) + /// + public PromotionTask StartPromotionTask(StartPromotionTaskRequest request, ShopResponse shop = null) { var dbPromotionTask = fsql.Select(request.Id).ToOne(); @@ -657,13 +662,6 @@ namespace BBWY.Server.Business startResponse.DeleteGiftSkuList.Count() != 0) dbPromotionTask.GiftTemplatePutNewSku = string.Join(",", startResponse.DeleteGiftSkuList); - //try - //{ - // if (!string.IsNullOrEmpty(shop.PJZSDingDingKey) && !string.IsNullOrEmpty(shop.PJZSDingDingWebHook)) - // dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"任务[{dbPromotionTask.ActivityName}]已开始,请及时查看任务是否正常进行"); - //} - //catch { } - fsql.Update(request.Id).Set(pt => pt.PromotionId, startResponse.JDPromotionId) .SetIf(!string.IsNullOrEmpty(dbPromotionTask.GiftTemplatePutNewSku), pt => pt.GiftTemplatePutNewSku, dbPromotionTask.GiftTemplatePutNewSku) .Set(pt => pt.StartTime, DateTime.Now) @@ -674,6 +672,7 @@ namespace BBWY.Server.Business //joinSkuCount = joinSkuNoGiftList.Distinct().Count(); joinSkuNoGiftList = joinSkuNoGiftList.Distinct().ToList(); Task.Factory.StartNew(() => StartPromotionDelayTask(request, startResponse, dbPromotionTask, shop, joinSkuNoGiftList), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionDelayTaskScheduler); + return dbPromotionTask; } private void StartPromotionDelayTask(StartPromotionTaskRequest request, StartPromotionTaskResponse startResponse, PromotionTask promotionTask, ShopResponse shop, List joinSkuList) @@ -728,14 +727,20 @@ namespace BBWY.Server.Business pt.PreTaskId == -1)).Any(); if (!haveNextTask) { - if (!string.IsNullOrEmpty(shop.PJZSDingDingKey) && !string.IsNullOrEmpty(shop.PJZSDingDingWebHook)) + //if (!string.IsNullOrEmpty(shop.PJZSDingDingKey) && !string.IsNullOrEmpty(shop.PJZSDingDingWebHook)) + //{ + // try + // { + // dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"评价助手\n店铺:{shop.ShopName}\n任务列表无后续任务,为避免空档请及时设置后续任务"); + // } + // catch { } + //} + + try { - try - { - dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"评价助手\n店铺:{shop.ShopName}\n任务列表无后续任务,为避免空档请及时设置后续任务"); - } - catch { } + qyMessageCenterBusiness.SendMessage(shop.TeamId, shop.TeamId, shop.ShopId, "PJZS", shop.ShopName, "任务列表无后续任务,为避免空档请及时设置后续任务", "PZJS API", string.Empty); } + catch { } } #endregion } @@ -1096,26 +1101,19 @@ namespace BBWY.Server.Business }, GetYunDingRequestHeader(), HttpMethod.Post); + if (httpResult.StatusCode != System.Net.HttpStatusCode.OK) { - var msgBuilder = new StringBuilder(); - msgBuilder.AppendLine($"店铺名称:{shop.ShopName}"); - msgBuilder.AppendLine($"活动名称:{promotionTask.ActivityName}"); - msgBuilder.AppendLine($"错误原因:{httpResult.Content}"); - msgBuilder.AppendLine("删除活动失败,请手动到后台删除,并通知技术员分析失败原因"); - dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"任务[{promotionTask.ActivityName}]删除任务失败,{httpResult.Content}"); + //dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"任务[{promotionTask.ActivityName}]删除任务失败,{httpResult.Content}"); + qyMessageCenterBusiness.SendMessage(shop.TeamId, shop.TeamId, shop.ShopId, "PZJS", shop.ShopName, $"任务[{promotionTask.ActivityName}]删除任务失败,{httpResult.Content}", "PJZS API", string.Empty); } else { var res = JsonConvert.DeserializeObject(httpResult.Content); if (!res.Success) { - var msgBuilder = new StringBuilder(); - msgBuilder.AppendLine($"店铺名称:{shop.ShopName}"); - msgBuilder.AppendLine($"活动名称:{promotionTask.ActivityName}"); - msgBuilder.AppendLine($"错误原因:{httpResult.Content}"); - msgBuilder.AppendLine("删除活动失败,请手动到后台删除,并通知技术员分析失败原因"); - dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"任务[{promotionTask.ActivityName}]删除任务失败,{res.Msg}"); + //dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"任务[{promotionTask.ActivityName}]删除任务失败,{res.Msg}"); + qyMessageCenterBusiness.SendMessage(shop.TeamId, shop.TeamId, shop.ShopId, "PZJS", shop.ShopName, $"任务[{promotionTask.ActivityName}]删除任务失败,{res.Msg}", "PJZS API", string.Empty); } } @@ -1196,7 +1194,8 @@ namespace BBWY.Server.Business { try { - dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"任务[{jobDoneTask.ActivityName}]已结束"); + //dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"任务[{jobDoneTask.ActivityName}]已结束"); + qyMessageCenterBusiness.SendMessage(shop.TeamId, shop.TeamId, shop.ShopId, "PZJS", shop.ShopName, $"任务[{jobDoneTask.ActivityName}]已结束", "PJZS API", string.Empty); } catch { } } @@ -1222,7 +1221,9 @@ namespace BBWY.Server.Business { try { - dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"评价助手\n店铺:{shop.ShopName}\n任务全部执行完成,请及时设置后续任务!!"); + //dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"评价助手\n店铺:{shop.ShopName}\n任务全部执行完成,请及时设置后续任务!!"); + + qyMessageCenterBusiness.SendMessage(shop.TeamId, shop.TeamId, shop.ShopId, "PZJS", shop.ShopName, "任务全部执行完成,请及时设置后续任务", "PJZS API", string.Empty); } catch { } } @@ -1256,9 +1257,10 @@ namespace BBWY.Server.Business private void AutoStart(long taskId, string taskName, ShopResponse shop) { var loggerName = $"评价助手-{shop.ShopName}"; + PromotionTask task = null; try { - StartPromotionTask(new StartPromotionTaskRequest() + task = StartPromotionTask(new StartPromotionTaskRequest() { Id = taskId, AppKey = shop.AppKey2, @@ -1269,7 +1271,21 @@ namespace BBWY.Server.Business } catch (Exception ex) { - Error(shop, loggerName, $"AutoStart 任务[{taskName}]", ex); + if (task != null) + { + nLogManager.GetLogger(loggerName).Error(ex, $"AutoStart 任务[{task.ActivityName}]"); + qyMessageCenterBusiness.SendMessage(shop.TeamId, shop.TeamId, shop.ShopId, "PJZS", shop.ShopName, new + { + task.ActivityName, + task.MainProductSpu, + task.SpuLogo, + ErrorMsg = ex.Message + }, "SHANGJIASHIBAI", "PJZS API", string.Empty); + } + else + { + Error(shop, loggerName, $"AutoStart 任务[{taskName}]", ex); + } } } @@ -1277,9 +1293,15 @@ namespace BBWY.Server.Business { nLogManager.GetLogger(loggerName).Error(ex, message); - //send dingding - if (!string.IsNullOrEmpty(shop.PJZSDingDingKey) && !string.IsNullOrEmpty(shop.PJZSDingDingWebHook)) - dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"评价助手\n{shop.ShopName}\n{message}\n{ex.Message}"); + ////send dingding + //if (!string.IsNullOrEmpty(shop.PJZSDingDingKey) && !string.IsNullOrEmpty(shop.PJZSDingDingWebHook)) + // dingDingBusiness.SendDingDingBotMessage(shop.PJZSDingDingKey, shop.PJZSDingDingWebHook, $"评价助手\n{shop.ShopName}\n{message}\n{ex.Message}"); + + try + { + qyMessageCenterBusiness.SendMessage(shop.TeamId, shop.TeamId, shop.ShopId, "PJZS", shop.ShopName, $"{message} {ex.Message}", "PJZS API", string.Empty); + } + catch { } } #endregion } diff --git a/BBWY.Server.Business/QYMessageCenterBusiness.cs b/BBWY.Server.Business/QYMessageCenterBusiness.cs new file mode 100644 index 00000000..c2531a2b --- /dev/null +++ b/BBWY.Server.Business/QYMessageCenterBusiness.cs @@ -0,0 +1,49 @@ +using BBWY.Common.Http; +using BBWY.Common.Models; +using Newtonsoft.Json; +using System.Net.Http; + +namespace BBWY.Server.Business +{ + public class QYMessageCenterBusiness : IDenpendency + { + + private RestApiService restApiService; + public QYMessageCenterBusiness(RestApiService restApiService) + { + this.restApiService = restApiService; + } + + public void SendMessage(string channel, string teamId, string shopId, string appCode, string title, string content, string senderId, string recevierId) + { + SendMessage(channel, teamId, shopId, appCode, title, content, string.Empty, senderId, recevierId, false); + } + + public void SendMessage(string channel, string teamId, string shopId, string appCode, string title, object jsonContent, string customTypeCode, string senderId, string recevierId) + { + SendMessage(channel, teamId, shopId, appCode, title, JsonConvert.SerializeObject(jsonContent), customTypeCode, senderId, recevierId, true); + } + + private void SendMessage(string channel, string teamId, string shopId, string appCode, string title, string content, string customTypeCode, string senderId, string recevierId, bool isJsonMsg) + { + var httpResult = restApiService.SendRequest("http://api.msg.qiyue666.com", "api/message/send", new + { + appCode, + channel, + teamId, + shopId, + title, + content, + customTypeCode, + senderId, + recevierId, + isJsonMsg + }, null, HttpMethod.Post); + if ((httpResult.StatusCode != System.Net.HttpStatusCode.OK)) + throw new BusinessException($"QYMessageCenterBusiness SendMessage HttpCode {httpResult.StatusCode}"); + var response = JsonConvert.DeserializeObject(httpResult.Content); + if (!response.Success) + throw new BusinessException($"QYMessageCenterBusiness SendMessage {response.Msg}"); + } + } +} diff --git a/BBWY.Server.Business/Vender/VenderBusiness.cs b/BBWY.Server.Business/Vender/VenderBusiness.cs index 9eb61897..82ea955a 100644 --- a/BBWY.Server.Business/Vender/VenderBusiness.cs +++ b/BBWY.Server.Business/Vender/VenderBusiness.cs @@ -295,13 +295,42 @@ namespace BBWY.Server.Business public IList GetShopList(long? shopId = null, Enums.Platform? platform = null, bool filterTurnoverDays = false, bool filterSiNan = false, bool? isEnabled = true) { - return freeSqlMultiDBManager.MDSfsql.Select().Where(s => !string.IsNullOrEmpty(s.ShopId)) - .WhereIf(shopId != null, s => s.ShopId == shopId.ToString()) - .WhereIf(platform != null, s => s.PlatformId == (int)platform) - .WhereIf(filterTurnoverDays, s => s.SkuSafeTurnoverDays != 0) - .WhereIf(filterSiNan, s => !string.IsNullOrEmpty(s.SiNanDingDingWebHook)) - .WhereIf(isEnabled != null, s => s.IsEnabled == isEnabled) - .ToList(); + return freeSqlMultiDBManager.MDSfsql.Select() + .InnerJoin((s, sd) => s.Id == sd.ShopId) + .Where((s, sd) => !string.IsNullOrEmpty(s.ShopId)) + .WhereIf(shopId != null, (s, sd) => s.ShopId == shopId.ToString()) + .WhereIf(platform != null, (s, sd) => s.PlatformId == (int)platform) + .WhereIf(filterTurnoverDays, (s, sd) => s.SkuSafeTurnoverDays != 0) + .WhereIf(filterSiNan, (s, sd) => !string.IsNullOrEmpty(s.SiNanDingDingWebHook)) + .WhereIf(isEnabled != null, (s, sd) => s.IsEnabled == isEnabled) + .ToList((s, sd) => new ShopResponse + { + Id = s.Id, + AppKey = s.AppKey, + ShopId = s.ShopId, + AppKey2 = s.AppKey2, + AppSecret = s.AppSecret, + AppSecret2 = s.AppSecret2, + AppToken = s.AppToken, + AppToken2 = s.AppToken2, + DingDingKey = s.DingDingKey, + DingDingWebHook = s.DingDingWebHook, + ManagePwd = s.ManagePwd, + PJZSDingDingKey = s.PJZSDingDingKey, + PJZSDingDingWebHook = s.PJZSDingDingWebHook, + PlatformCommissionRatio = s.PlatformCommissionRatio, + PlatformId = (Enums.Platform)s.PlatformId, + QiKuDingDingKey = s.QiKuDingDingKey, + QiKuDingDingWebHook = s.QiKuDingDingWebHook, + ShopName = s.ShopName, + ShopType = s.ShopType, + SiNanDingDingKey = s.SiNanDingDingKey, + SiNanDingDingWebHook = s.SiNanDingDingWebHook, + SiNanPolicyLevel = s.SiNanPolicyLevel, + SkuSafeTurnoverDays = s.SkuSafeTurnoverDays, + VenderId = s.VenderId, + TeamId = sd.DepartmentId + }); } public ShopResponse GetShopByVenderId(string venderId) diff --git a/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs b/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs index 14d0a2ee..c3fe387d 100644 --- a/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs +++ b/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs @@ -92,6 +92,11 @@ namespace BBWY.Server.Model.Dto /// 齐库钉钉密钥 /// public string QiKuDingDingKey { get; set; } + + /// + /// 所属团队Id + /// + public string TeamId { get; set; } } public class PurchaseAccountResponse