Browse Source

修改提示格式

master
С·æ 4 years ago
parent
commit
df432b134a
  1. 91
      JdShopListener/JdShopListener/MainWindowViewModel.cs

91
JdShopListener/JdShopListener/MainWindowViewModel.cs

@ -556,6 +556,7 @@ namespace JdShopListener
{
item.NewCoupons = "[]";
}
change.OldProList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ProListModel>>(item.OldCoupons);
change.NewProList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ProListModel>>(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<List<ProListModel>>(json);
var arr= data.Select(c => c.Title).ToArray();
return string.Join(",", arr);
}
return json;
}
/// <summary>
/// 根据Sku获取详情
/// </summary>
@ -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}监控完成!已产生变化记录");
}

Loading…
Cancel
Save