From df432b134a611677458f0702cabd8816875773e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=C2=B7=C3=A6?= <279202647@qq.com> Date: Sat, 4 Sep 2021 18:03:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8F=90=E7=A4=BA=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JdShopListener/MainWindowViewModel.cs | 91 ++++++++++++++++--- 1 file changed, 77 insertions(+), 14 deletions(-) diff --git a/JdShopListener/JdShopListener/MainWindowViewModel.cs b/JdShopListener/JdShopListener/MainWindowViewModel.cs index 3688b73..57c9522 100644 --- a/JdShopListener/JdShopListener/MainWindowViewModel.cs +++ b/JdShopListener/JdShopListener/MainWindowViewModel.cs @@ -556,6 +556,7 @@ namespace JdShopListener { item.NewCoupons = "[]"; } + change.OldProList = Newtonsoft.Json.JsonConvert.DeserializeObject>(item.OldCoupons); change.NewProList = Newtonsoft.Json.JsonConvert.DeserializeObject>(item.NewCoupons); @@ -702,6 +703,23 @@ namespace JdShopListener } + private string GetProTitle(string json) + { + if (json == null) + return string.Empty; + if (json.StartsWith("[")) + { + var data = Newtonsoft.Json.JsonConvert.DeserializeObject>(json); + + var arr= data.Select(c => c.Title).ToArray(); + + + return string.Join(",", arr); + } + + return json; + } + /// /// 根据Sku获取详情 /// @@ -903,50 +921,99 @@ namespace JdShopListener bool isChange = false; StringBuilder sbMsg = new StringBuilder(); - sbMsg.AppendLine("监控竞品发生变化:"); if (lastSku.NewSkus != item.NewSkus) { + sbMsg.AppendLine("监控竞品发生变化:"); sbMsg.AppendLine("Sku"); - sbMsg.AppendLine($"原:{lastSku.NewSkus}"); - sbMsg.AppendLine($"新:{item.NewSkus}"); + sbMsg.AppendLine($"原:{GetProTitle(lastSku.NewSkus)}"); + sbMsg.AppendLine($"新:{GetProTitle(item.NewSkus)}"); + sbMsg.AppendLine($"商品链接:https://item.jd.com/{item.SkuId}.html"); + + if (IsUseDingDing && !string.IsNullOrEmpty(lastSku.SkuId)) + { + dingApi.SendNotify(sbMsg.ToString().Replace("\r\n", "\n")); + + } + + sbMsg.Clear(); isChange = true; } if (lastSku.NewActive != item.NewActive) { + sbMsg.AppendLine("监控竞品发生变化:"); sbMsg.AppendLine("活动"); - sbMsg.AppendLine($"原:{lastSku.NewActive}"); - sbMsg.AppendLine($"新:{item.NewActive}"); + sbMsg.AppendLine($"原:{GetProTitle(lastSku.NewActive)}"); + sbMsg.AppendLine($"新:{GetProTitle(item.NewActive)}"); + sbMsg.AppendLine($"商品链接:https://item.jd.com/{item.SkuId}.html"); + + if (IsUseDingDing && !string.IsNullOrEmpty(lastSku.SkuId)) + { + dingApi.SendNotify(sbMsg.ToString().Replace("\r\n", "\n")); + + } + + sbMsg.Clear(); isChange = true; } if (lastSku.NewCoupons != item.NewCoupons) { + sbMsg.AppendLine("监控竞品发生变化:"); sbMsg.AppendLine("优惠券"); - sbMsg.AppendLine($"原:{lastSku.NewCoupons}"); - sbMsg.AppendLine($"新:{item.NewCoupons}"); + sbMsg.AppendLine($"原:{GetProTitle(lastSku.NewCoupons)}"); + sbMsg.AppendLine($"新:{GetProTitle(item.NewCoupons)}"); + sbMsg.AppendLine($"商品链接:https://item.jd.com/{item.SkuId}.html"); + + if (IsUseDingDing && !string.IsNullOrEmpty(lastSku.SkuId)) + { + dingApi.SendNotify(sbMsg.ToString().Replace("\r\n", "\n")); + + } + + sbMsg.Clear(); isChange = true; } if (lastSku.NewPrice != item.NewPrice) { + sbMsg.AppendLine("监控竞品发生变化:"); sbMsg.AppendLine("价格"); sbMsg.AppendLine($"原:{lastSku.NewPrice}"); sbMsg.AppendLine($"新:{item.NewPrice}"); + sbMsg.AppendLine($"商品链接:https://item.jd.com/{item.SkuId}.html"); + + if (IsUseDingDing && !string.IsNullOrEmpty(lastSku.SkuId)) + { + dingApi.SendNotify(sbMsg.ToString().Replace("\r\n", "\n")); + + } + + sbMsg.Clear(); isChange = true; } if (lastSku.NewPromotion != item.NewPromotion) { + sbMsg.AppendLine("监控竞品发生变化:"); sbMsg.AppendLine("促销"); - sbMsg.AppendLine($"原:{lastSku.NewPromotion}"); - sbMsg.AppendLine($"新:{item.NewPromotion}"); + sbMsg.AppendLine($"原:{GetProTitle(lastSku.NewPromotion)}"); + sbMsg.AppendLine($"新:{GetProTitle(item.NewPromotion)}"); + sbMsg.AppendLine($"商品链接:https://item.jd.com/{item.SkuId}.html"); + + + if (IsUseDingDing&&!string.IsNullOrEmpty( lastSku.SkuId)) + { + dingApi.SendNotify(sbMsg.ToString().Replace("\r\n", "\n")); + } + + sbMsg.Clear(); + isChange = true; } - sbMsg.AppendLine($"商品链接:https://item.jd.com/{lastSku.SkuId}.html"); //判断是否有变化 if (isChange) @@ -959,10 +1026,6 @@ namespace JdShopListener DbHelper.Db.AddItemChangeModel(item); - if (IsUseDingDing) - { - dingApi.SendNotify(sbMsg.ToString()); - } AddLog($"{sku.SkuId}监控完成!已产生变化记录"); }