diff --git a/BBWY.Server.API/Controllers/EvaluationAssistantController.cs b/BBWY.Server.API/Controllers/EvaluationAssistantController.cs index 38f34006..f100217f 100644 --- a/BBWY.Server.API/Controllers/EvaluationAssistantController.cs +++ b/BBWY.Server.API/Controllers/EvaluationAssistantController.cs @@ -139,6 +139,16 @@ namespace BBWY.Server.API.Controllers evaluationAssistantBusiness.StopPromotionTask(request); } + /// + /// 修改评价助手店铺设置 + /// + /// + [HttpPost] + public void EditPJZSSettings([FromBody] PJZSShopSettingRequest request) + { + evaluationAssistantBusiness.EditPJZSSettings(request); + } + /// /// 开始监控 /// diff --git a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs index 0c35f6cf..a90fdde7 100644 --- a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs +++ b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs @@ -28,10 +28,13 @@ namespace BBWY.Server.Business private List validOrderStateList; private List preTaskStateList; private ProductBusiness productBusiness; + private FreeSqlMultiDBManager freeSqlMultiDBManager; + 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) : base(restApiService, options, yunDingBusiness) + 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) { + this.fsql = fsql; this.idGenerator = idGenerator; this.taskSchedulerManager = taskSchedulerManager; @@ -39,6 +42,7 @@ namespace BBWY.Server.Business this.dingDingBusiness = dingDingBusiness; this.nLogManager = nLogManager; this.productBusiness = productBusiness; + this.freeSqlMultiDBManager = freeSqlMultiDBManager; validOrderStateList = new List() { Enums.OrderState.待出库, @@ -303,6 +307,9 @@ namespace BBWY.Server.Business if (pt == null) throw new BusinessException($"{request.TaskId}任务不存在"); + if (pt.Status != Enums.PromitionTaskStatus.等待) + throw new BusinessException("任务状态必须为等待"); + if (request.PreTaskId != -1) { var prpt = fsql.Select(request.PreTaskId).ToOne(); @@ -312,9 +319,6 @@ namespace BBWY.Server.Business if (pt.Id == prpt.Id) throw new BusinessException("前置任务不能设置为自己"); - if (pt.Status != Enums.PromitionTaskStatus.等待) - throw new BusinessException("任务状态必须为等待"); - if (prpt.Status != Enums.PromitionTaskStatus.等待 && prpt.Status != Enums.PromitionTaskStatus.进行中) throw new BusinessException("前置任务状态必须为等待或进行中"); @@ -563,7 +567,7 @@ namespace BBWY.Server.Business fsql.Update(id).Set(pt => pt.Status, Enums.PromitionTaskStatus.已停止) .Set(pt => pt.ErrorMsg, errorMsg) .ExecuteAffrows(); - Error(shop, $"评价助手-{shop.ShopName}", $"开始任务延迟任务-任务Id {request.Id}", new Exception(errorMsg)); + Error(shop, $"评价助手-{shop.ShopName}", $"开始任务-延迟任务-任务Id {request.Id}", new Exception(errorMsg)); }); if (httpApiResult.StatusCode != System.Net.HttpStatusCode.OK) { @@ -691,6 +695,15 @@ namespace BBWY.Server.Business throw new BusinessException(response.Msg); fsql.Update(request.Id).Set(pt => pt.Status, Enums.PromitionTaskStatus.已停止).ExecuteAffrows(); } + + public void EditPJZSSettings(PJZSShopSettingRequest request) + { + var shopId = request.ShopId.ToString(); + freeSqlMultiDBManager.MDSfsql.Update().Set(s => s.PJZSDingDingKey, request.PJZSDingDingKey) + .Set(s => s.PJZSDingDingWebHook, request.PJZSDingDingWebHook) + .Where(s => s.ShopId == shopId) + .ExecuteAffrows(); + } #endregion #region 自动任务 @@ -700,6 +713,22 @@ namespace BBWY.Server.Business //查询店铺 var shopList = venderBusiness.GetShopList(shopId, Enums.Platform.京东); + //开始下一轮开始任务 + var nextPromotionTaskList = fsql.Select().WhereIf(shopId != null, pt => pt.ShopId == shopId) + .Where(pt => pt.Status == Enums.PromitionTaskStatus.等待 && pt.PreTaskId == -1) + .ToList(pt => new { Id = pt.Id, ShopId = pt.ShopId }); + if (nextPromotionTaskList.Count() > 0) + { + foreach (var nextTask in nextPromotionTaskList) + { + var shop = shopList.FirstOrDefault(s => s.ShopId == nextTask.ShopId.ToString()); + if (shop != null) + { + Task.Factory.StartNew(() => AutoStart(nextTask.Id, shop), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionAutoStartTaskScheduler); + } + } + } + //查询正在进行的任务 var runningTaskList = fsql.Select() .WhereIf(shopId != null, pt => pt.ShopId == shopId) @@ -898,30 +927,19 @@ namespace BBWY.Server.Business #region 开始后续任务 //下一轮开始任务 - var nextPromotionTaskList = new List(); - var noPrePromotionTaskList = fsql.Select().Where(pt => pt.ShopId == shopId && - pt.Status == Enums.PromitionTaskStatus.等待 && - pt.PreTaskId == -1).ToList(pt => pt.Id); - if (noPrePromotionTaskList.Count() > 0) - nextPromotionTaskList.AddRange(noPrePromotionTaskList); - if (jobDoneTaskIdList.Count() > 0) { var childTaskList = fsql.Select().Where(pt => pt.ShopId == shopId && - pt.Status == Enums.PromitionTaskStatus.等待 && - jobDoneTaskIdList.Contains(pt.PreTaskId.Value)).ToList(pt => pt.Id); + pt.Status == Enums.PromitionTaskStatus.等待 && + jobDoneTaskIdList.Contains(pt.PreTaskId.Value)).ToList(pt => pt.Id); if (childTaskList.Count() > 0) - nextPromotionTaskList.AddRange(childTaskList); - } - - if (nextPromotionTaskList.Count() > 0) - { - foreach (var taskId in nextPromotionTaskList) { - Task.Factory.StartNew(() => AutoStart(taskId, shop), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionAutoStartTaskScheduler); + foreach (var taskId in childTaskList) + { + Task.Factory.StartNew(() => AutoStart(taskId, shop), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionAutoStartTaskScheduler); + } } } - #endregion } @@ -945,13 +963,13 @@ namespace BBWY.Server.Business } } - private void Error(ShopResponse shop, string loggerName, string message, Exception ex) { 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}"); } #endregion } diff --git a/BBWY.Server.Business/Vender/VenderBusiness.cs b/BBWY.Server.Business/Vender/VenderBusiness.cs index 9c779eb7..05196c33 100644 --- a/BBWY.Server.Business/Vender/VenderBusiness.cs +++ b/BBWY.Server.Business/Vender/VenderBusiness.cs @@ -226,7 +226,9 @@ namespace BBWY.Server.Business s.SkuSafeTurnoverDays, s.SiNanDingDingKey, s.SiNanDingDingWebHook, - s.SiNanPolicyLevel + s.SiNanPolicyLevel, + s.PJZSDingDingWebHook, + s.PJZSDingDingKey }).GroupBy(x => x.DepartmentId); if (relationGroups.Count() == 0) return null; @@ -259,7 +261,9 @@ namespace BBWY.Server.Business SkuSafeTurnoverDays = x.SkuSafeTurnoverDays, SiNanDingDingKey = x.SiNanDingDingKey, SiNanDingDingWebHook = x.SiNanDingDingWebHook, - SiNanPolicyLevel = x.SiNanPolicyLevel + SiNanPolicyLevel = x.SiNanPolicyLevel, + PJZSDingDingKey = x.PJZSDingDingKey, + PJZSDingDingWebHook = x.PJZSDingDingWebHook }).ToList() }; departmentList.Add(department); diff --git a/BBWY.Server.Model/Db/Mds/Shops.cs b/BBWY.Server.Model/Db/Mds/Shops.cs index e3557801..57d133c9 100644 --- a/BBWY.Server.Model/Db/Mds/Shops.cs +++ b/BBWY.Server.Model/Db/Mds/Shops.cs @@ -158,6 +158,18 @@ namespace BBWY.Server.Model.Db.Mds /// [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; } } } diff --git a/BBWY.Server.Model/Dto/Request/PromotionTask/PJZSShopSettingRequest.cs b/BBWY.Server.Model/Dto/Request/PromotionTask/PJZSShopSettingRequest.cs new file mode 100644 index 00000000..f4948ef5 --- /dev/null +++ b/BBWY.Server.Model/Dto/Request/PromotionTask/PJZSShopSettingRequest.cs @@ -0,0 +1,20 @@ +namespace BBWY.Server.Model.Dto +{ + public class PJZSShopSettingRequest + { + /// + /// 店铺Id,Shop对象的ShopId (注意不是Shop对象的主键) + /// + public long ShopId { get; set; } + + /// + /// 评价助手的钉钉地址 + /// + public string PJZSDingDingWebHook { get; set; } + + /// + /// 评价助手的钉钉密钥 + /// + public string PJZSDingDingKey { get; set; } + } +} diff --git a/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs b/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs index 17ff7c4a..7f654191 100644 --- a/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs +++ b/BBWY.Server.Model/Dto/Response/Vender/ShopResponse.cs @@ -71,6 +71,16 @@ namespace BBWY.Server.Model.Dto /// 司南钉钉密钥 /// public string SiNanDingDingKey { get; set; } + + /// + /// PJZS钉钉WebHook地址 + /// + public string PJZSDingDingWebHook { get; set; } + + /// + /// PJZS钉钉密钥 + /// + public string PJZSDingDingKey { get; set; } } public class PurchaseAccountResponse diff --git a/PJZS/MainWindow.xaml b/PJZS/MainWindow.xaml index 04017908..38c08293 100644 --- a/PJZS/MainWindow.xaml +++ b/PJZS/MainWindow.xaml @@ -27,7 +27,7 @@ - + diff --git a/PJZS/MainWindow.xaml.cs b/PJZS/MainWindow.xaml.cs index 5602862c..edc8c189 100644 --- a/PJZS/MainWindow.xaml.cs +++ b/PJZS/MainWindow.xaml.cs @@ -176,6 +176,8 @@ namespace PJZS shop.AppKey2 = s2.AppKey2; shop.AppSecret2 = s2.AppSecret2; shop.AppToken2 = s2.AppToken2; + shop.PJZSDingDingKey = s2.PJZSDingDingKey; + shop.PJZSDingDingWebHook = s2.PJZSDingDingWebHook; } } } diff --git a/PJZS/Models/APIModel/Shop/ShopResponse.cs b/PJZS/Models/APIModel/Shop/ShopResponse.cs index 5e5fde8a..71894398 100644 --- a/PJZS/Models/APIModel/Shop/ShopResponse.cs +++ b/PJZS/Models/APIModel/Shop/ShopResponse.cs @@ -56,6 +56,16 @@ namespace PJZS.Models /// 司南钉钉密钥 /// public string SiNanDingDingKey { get; set; } + + /// + /// PJZS钉钉WebHook地址 + /// + public string PJZSDingDingWebHook { get; set; } + + /// + /// PJZS钉钉密钥 + /// + public string PJZSDingDingKey { get; set; } } public class DepartmentResponse diff --git a/PJZS/Models/Shop/Shop.cs b/PJZS/Models/Shop/Shop.cs index a52dac43..f0c25115 100644 --- a/PJZS/Models/Shop/Shop.cs +++ b/PJZS/Models/Shop/Shop.cs @@ -71,6 +71,16 @@ namespace PJZS /// public string SiNanDingDingKey { get; set; } + /// + /// PJZS钉钉WebHook地址 + /// + public string PJZSDingDingWebHook { get; set; } + + /// + /// PJZS钉钉密钥 + /// + public string PJZSDingDingKey { get; set; } + public override string ToString() { return ShopName;