commit 6cfd7deaf2378221fc66287f0d3a56dbdc69fac2
Author: С·æ <279202647@qq.com>
Date: Mon Apr 12 18:50:03 2021 +0800
完成数据结构设计
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4322f6b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/JdShopListener/JdShopListener/obj
+/JdShopListener/JdShopListener/bin
+/JdShopListener/.vs
diff --git a/JdShopListener/JdShopListener.sln b/JdShopListener/JdShopListener.sln
new file mode 100644
index 0000000..2aa4823
--- /dev/null
+++ b/JdShopListener/JdShopListener.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30804.86
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JdShopListener", "JdShopListener\JdShopListener.csproj", "{ED16D55D-BE5B-4206-8A0D-6C91A7A583B1}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {ED16D55D-BE5B-4206-8A0D-6C91A7A583B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {ED16D55D-BE5B-4206-8A0D-6C91A7A583B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {ED16D55D-BE5B-4206-8A0D-6C91A7A583B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {ED16D55D-BE5B-4206-8A0D-6C91A7A583B1}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {17EF939B-B35E-4DD1-98F5-A6A9829CE9BA}
+ EndGlobalSection
+EndGlobal
diff --git a/JdShopListener/JdShopListener/App.xaml b/JdShopListener/JdShopListener/App.xaml
new file mode 100644
index 0000000..7c0b171
--- /dev/null
+++ b/JdShopListener/JdShopListener/App.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/JdShopListener/JdShopListener/App.xaml.cs b/JdShopListener/JdShopListener/App.xaml.cs
new file mode 100644
index 0000000..e9ec8ba
--- /dev/null
+++ b/JdShopListener/JdShopListener/App.xaml.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace JdShopListener
+{
+ ///
+ /// Interaction logic for App.xaml
+ ///
+ public partial class App : Application
+ {
+ }
+}
diff --git a/JdShopListener/JdShopListener/AssemblyInfo.cs b/JdShopListener/JdShopListener/AssemblyInfo.cs
new file mode 100644
index 0000000..8b5504e
--- /dev/null
+++ b/JdShopListener/JdShopListener/AssemblyInfo.cs
@@ -0,0 +1,10 @@
+using System.Windows;
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
diff --git a/JdShopListener/JdShopListener/JdDBContext.cs b/JdShopListener/JdShopListener/JdDBContext.cs
new file mode 100644
index 0000000..ee629de
--- /dev/null
+++ b/JdShopListener/JdShopListener/JdDBContext.cs
@@ -0,0 +1,20 @@
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace JdShopListener
+{
+ public class JdDBContext: DbContext
+ {
+ public DbSet SkuItems { get; set; }
+
+ public DbSet ItemChanges { get; set; }
+
+
+ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+ {
+ optionsBuilder.UseSqlite("Data Source=db/items.db");
+ }
+ }
+}
diff --git a/JdShopListener/JdShopListener/JdShopListener.csproj b/JdShopListener/JdShopListener/JdShopListener.csproj
new file mode 100644
index 0000000..a88495c
--- /dev/null
+++ b/JdShopListener/JdShopListener/JdShopListener.csproj
@@ -0,0 +1,14 @@
+
+
+
+ WinExe
+ netcoreapp3.1
+ true
+
+
+
+
+
+
+
+
diff --git a/JdShopListener/JdShopListener/JdShopListener.csproj.user b/JdShopListener/JdShopListener/JdShopListener.csproj.user
new file mode 100644
index 0000000..644b0a6
--- /dev/null
+++ b/JdShopListener/JdShopListener/JdShopListener.csproj.user
@@ -0,0 +1,14 @@
+
+
+
+
+
+ Designer
+
+
+
+
+ Designer
+
+
+
\ No newline at end of file
diff --git a/JdShopListener/JdShopListener/MainWindow.xaml b/JdShopListener/JdShopListener/MainWindow.xaml
new file mode 100644
index 0000000..9f3d4c1
--- /dev/null
+++ b/JdShopListener/JdShopListener/MainWindow.xaml
@@ -0,0 +1,303 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/JdShopListener/JdShopListener/MainWindow.xaml.cs b/JdShopListener/JdShopListener/MainWindow.xaml.cs
new file mode 100644
index 0000000..c45214d
--- /dev/null
+++ b/JdShopListener/JdShopListener/MainWindow.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace JdShopListener
+{
+ ///
+ /// Interaction logic for MainWindow.xaml
+ ///
+ public partial class MainWindow : Window
+ {
+ public MainWindow()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/JdShopListener/JdShopListener/MainWindowViewModel.cs b/JdShopListener/JdShopListener/MainWindowViewModel.cs
new file mode 100644
index 0000000..5cddd4d
--- /dev/null
+++ b/JdShopListener/JdShopListener/MainWindowViewModel.cs
@@ -0,0 +1,237 @@
+using GalaSoft.MvvmLight;
+using GalaSoft.MvvmLight.Command;
+using JdShopListener.Models;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Net;
+using System.Net.Http;
+
+namespace JdShopListener
+{
+ public class MainWindowViewModel : ViewModelBase
+ {
+ private static MainWindowViewModel _mainWindowViewModel = new MainWindowViewModel();
+ public MainWindow Window;
+ public static MainWindowViewModel MainViewModel
+ {
+ get
+ {
+ return _mainWindowViewModel;
+ }
+ }
+
+ public MainWindowViewModel() {
+ ProList = new System.Collections.ObjectModel.ObservableCollection() {
+ new ProModel(){ Name="价格" , Type= ProType.Price},
+ new ProModel(){ Name="活动" , Type= ProType.Active},
+ new ProModel(){ Name="促销" , Type= ProType.Promotion},
+ new ProModel(){ Name="优惠券" , Type= ProType.Coupons}
+ };
+
+ DateList = new System.Collections.ObjectModel.ObservableCollection() {
+ new DateModel(){ Name="今天",Day=0 },
+ new DateModel(){ Name="昨天",Day=-1 },
+ new DateModel(){ Name="前天",Day=-2 }
+ };
+
+ Btn_Add = new RelayCommand(Add);
+ Btn_ShowList = new RelayCommand(ShowList);
+ Btn_Start = new RelayCommand(Start);
+
+ ItemList = new System.Collections.ObjectModel.ObservableCollection() {
+ new ItemData(){ Desc="测试", OldPro="100",NewPro="120",SkuId="123123",OldProList=new List(){ "满额返券","换购" } ,NewProList =new List(){ "满额返券", "多买优惠" } },
+ new ItemData(){Desc="测试", OldPro="120",NewPro="111",SkuId="123123",OldProList=new List(){ "满额返券","换购" } ,NewProList =new List(){ "满额返券", "多买优惠", "换购" } }
+ };
+
+ SkuList = new System.Collections.ObjectModel.ObservableCollection();
+ }
+
+ private System.Collections.ObjectModel.ObservableCollection _ProList;
+
+ ///
+ /// 属性列表
+ ///
+ public System.Collections.ObjectModel.ObservableCollection ProList
+ {
+ get { return _ProList; }
+ set { Set(ref _ProList, value); }
+ }
+
+ private System.Collections.ObjectModel.ObservableCollection _DateList;
+
+ ///
+ /// 日期
+ ///
+ public System.Collections.ObjectModel.ObservableCollection DateList
+ {
+ get { return _DateList; }
+ set { Set(ref _DateList, value); }
+ }
+
+ private ProModel _SelectPro;
+ ///
+ /// 选中的属性
+ ///
+ public ProModel SelectPro
+ {
+ get { return _SelectPro; }
+ set { Set(ref _SelectPro, value); }
+ }
+
+
+ private DateModel _SelectDate;
+ ///
+ /// 选中的日期
+ ///
+ public DateModel SelectDate
+ {
+ get { return _SelectDate; }
+ set { Set(ref _SelectDate, value); }
+ }
+
+ private System.Collections.ObjectModel.ObservableCollection _ItemList;
+ ///
+ /// 商品变化列表
+ ///
+ public System.Collections.ObjectModel.ObservableCollection ItemList
+ {
+ get { return _ItemList; }
+ set { Set(ref _ItemList, value); }
+ }
+
+ private System.Collections.ObjectModel.ObservableCollection _SkuList;
+ ///
+ /// sku监控列表
+ ///
+ public System.Collections.ObjectModel.ObservableCollection SkuList
+ {
+ get { return _SkuList; }
+ set { Set(ref _SkuList, value); }
+ }
+
+ private string _Sku;
+ ///
+ /// 添加的Sku
+ ///
+ public string Sku
+ {
+ get { return _Sku; }
+ set { Set(ref _Sku, value); }
+ }
+
+ private string _Desc;
+ ///
+ /// 添加的备注
+ ///
+ public string Desc
+ {
+ get { return _Desc; }
+ set { Set(ref _Desc, value); }
+ }
+
+
+ ///
+ /// 添加事件
+ ///
+ public RelayCommand Btn_Add { get; set; }
+
+ ///
+ /// 打开监控列表
+ ///
+ public RelayCommand Btn_ShowList { get; set; }
+
+ ///
+ /// 开始
+ ///
+ public RelayCommand Btn_Start { get; set; }
+
+
+ ///
+ /// 添加
+ ///
+ public void Add()
+ {
+ var detail= GetItemDetail("69920799280");
+
+ var list = detail.product.colorSize;
+
+ //spuId
+ string spuId = detail.product.mainSkuId;
+
+ //主图
+ string src = detail.product.src;
+ //标题
+ string title = detail.product.name;
+
+ foreach (var sku in list)
+ {
+ SkuModel model = new SkuModel()
+ {
+ Desc = Desc,
+ SkuId = sku.skuId,
+ SpuId=spuId
+ };
+
+ //加入本地数据库
+
+ SkuList.Add(model);
+ }
+
+
+
+ }
+
+ ///
+ /// 打开监控列表
+ ///
+ public void ShowList()
+ {
+
+ }
+
+ ///
+ /// 开始
+ ///
+ public void Start()
+ {
+
+ }
+
+ ///
+ /// 根据Sku获取详情
+ ///
+ ///
+ ///
+ public dynamic GetItemDetail(string skuId)
+ {
+ try
+ {
+ HttpClient http = new HttpClient();
+ string html = http.GetStringAsync($"https://item.jd.com/{skuId}.html").Result;
+
+ int start = html.IndexOf("var pageConfig");
+ int end = html.IndexOf("};", start);
+
+ string json = html.Substring(start, end - start);
+
+ start = json.IndexOf("{");
+
+ json = json.Substring(start, json.Length - start);
+
+ json += "}";
+
+ var data = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
+
+ return data;
+ }
+ catch (Exception ex)
+ {
+ return null;
+ }
+ }
+
+ }
+
+
+}
diff --git a/JdShopListener/JdShopListener/Models/DateModel.cs b/JdShopListener/JdShopListener/Models/DateModel.cs
new file mode 100644
index 0000000..a216de4
--- /dev/null
+++ b/JdShopListener/JdShopListener/Models/DateModel.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace JdShopListener.Models
+{
+ public class DateModel
+ {
+ public string Name { get; set; }
+
+ public int Day { get; set; }
+ }
+}
diff --git a/JdShopListener/JdShopListener/Models/ItemChangeModel.cs b/JdShopListener/JdShopListener/Models/ItemChangeModel.cs
new file mode 100644
index 0000000..9634eb2
--- /dev/null
+++ b/JdShopListener/JdShopListener/Models/ItemChangeModel.cs
@@ -0,0 +1,133 @@
+using GalaSoft.MvvmLight;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Text;
+
+namespace JdShopListener.Models
+{
+ ///
+ /// 商品变化
+ ///
+ [Table("ItemChange")]
+ public class ItemChangeModel:ViewModelBase
+ {
+ public Guid Id { get; set; }
+
+ private string _SpuId;
+
+ ///
+ /// spu
+ ///
+ public string SpuId
+ {
+ get { return _SpuId; }
+ set { Set(ref _SpuId, value); }
+ }
+
+ private string _Desc;
+ ///
+ /// 备注
+ ///
+ public string Desc
+ {
+ get { return _Desc; }
+ set { Set(ref _Desc, value); }
+ }
+
+
+ private decimal _OldPrice;
+ ///
+ /// 原价格
+ ///
+ public decimal OldPrice
+ {
+ get { return _OldPrice; }
+ set { Set(ref _OldPrice, value); }
+ }
+
+
+ private decimal _NewPrice;
+ ///
+ /// 新价格
+ ///
+ public decimal NewPrice
+ {
+ get { return _NewPrice; }
+ set { Set(ref _NewPrice, value); }
+ }
+
+
+ private List _OldActive;
+ ///
+ /// 旧活动
+ ///
+ public List OldActive
+ {
+ get { return _OldActive; }
+ set { Set(ref _OldActive, value); }
+ }
+
+
+ private List _NewActive;
+ ///
+ /// 新活动
+ ///
+ public List NewActive
+ {
+ get { return _NewActive; }
+ set { Set(ref _NewActive, value); }
+ }
+
+ private List _OldPromotion;
+ ///
+ /// 旧促销
+ ///
+ public List OldPromotion
+ {
+ get { return _OldPromotion; }
+ set { Set(ref _OldPromotion, value); }
+ }
+
+ private List _NewPromotion;
+ ///
+ /// 新促销
+ ///
+ public List NewPromotion
+ {
+ get { return _NewPromotion; }
+ set { Set(ref _NewPromotion, value); }
+ }
+
+ private List _OldCoupons;
+ ///
+ /// 旧优惠券
+ ///
+ public List OldCoupons
+ {
+ get { return _OldCoupons; }
+ set { Set(ref _OldCoupons, value); }
+ }
+
+ private List _NewCoupons;
+ ///
+ /// 新优惠券
+ ///
+ public List NewCoupons
+ {
+ get { return _NewCoupons; }
+ set { Set(ref _NewCoupons, value); }
+ }
+
+ private DateTime _Date;
+ ///
+ /// 日期
+ ///
+ public DateTime Date
+ {
+ get { return _Date; }
+ set { Set(ref _Date, value); }
+ }
+
+ }
+}
diff --git a/JdShopListener/JdShopListener/Models/ItemData.cs b/JdShopListener/JdShopListener/Models/ItemData.cs
new file mode 100644
index 0000000..e4c7150
--- /dev/null
+++ b/JdShopListener/JdShopListener/Models/ItemData.cs
@@ -0,0 +1,95 @@
+using GalaSoft.MvvmLight;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace JdShopListener.Models
+{
+ public class ItemData : ViewModelBase
+ {
+ private List _OldProList;
+ ///
+ /// 旧的数据变化集合
+ ///
+ public List OldProList
+ {
+ get { return _OldProList; }
+ set { Set(ref _OldProList, value); }
+ }
+
+
+ private List _NewProList;
+ ///
+ /// 新的数据变化集合
+ ///
+ public List NewProList
+ {
+ get { return _NewProList; }
+ set { Set(ref _NewProList, value); }
+ }
+
+ private string _ImgUrl;
+ ///
+ /// 图片地址
+ ///
+ public string ImgUrl
+ {
+ get { return _ImgUrl; }
+ set { Set(ref _ImgUrl, value); }
+ }
+
+ private string _SkuId;
+ ///
+ /// Sku
+ ///
+ public string SkuId
+ {
+ get { return _SkuId; }
+ set { Set(ref _SkuId, value); }
+ }
+
+
+ private string _Desc;
+ ///
+ /// 备注
+ ///
+ public string Desc
+ {
+ get { return _Desc; }
+ set { Set(ref _Desc, value); }
+ }
+
+
+ private string _OldPro;
+ ///
+ /// 旧的字符串变化
+ ///
+ public string OldPro
+ {
+ get { return _OldPro; }
+ set { Set(ref _OldPro, value); }
+ }
+
+ private string _NewPro;
+ ///
+ /// 新的字符串变化
+ ///
+ public string NewPro
+ {
+ get { return _NewPro; }
+ set { Set(ref _NewPro, value); }
+ }
+
+ private DateTime _Date;
+ ///
+ /// 变化时间
+ ///
+ public DateTime Date
+ {
+ get { return _Date; }
+ set { Set(ref _Date, value); }
+ }
+
+
+ }
+}
diff --git a/JdShopListener/JdShopListener/Models/ProModel.cs b/JdShopListener/JdShopListener/Models/ProModel.cs
new file mode 100644
index 0000000..6258f7a
--- /dev/null
+++ b/JdShopListener/JdShopListener/Models/ProModel.cs
@@ -0,0 +1,48 @@
+using GalaSoft.MvvmLight;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace JdShopListener.Models
+{
+ ///
+ /// 属性
+ ///
+ public class ProModel:ViewModelBase
+ {
+ ///
+ /// 类型
+ ///
+ public ProType Type { get; set; }
+
+ ///
+ /// 名称
+ ///
+ public string Name { get; set; }
+
+
+ }
+
+ ///
+ /// 属性类型
+ ///
+ public enum ProType
+ {
+ ///
+ /// 价格
+ ///
+ Price=1,
+ ///
+ /// 活动
+ ///
+ Active=2,
+ ///
+ /// 促销
+ ///
+ Promotion=3,
+ ///
+ /// 优惠券
+ ///
+ Coupons=4
+ }
+}
diff --git a/JdShopListener/JdShopListener/Models/SkuModel.cs b/JdShopListener/JdShopListener/Models/SkuModel.cs
new file mode 100644
index 0000000..000b2d9
--- /dev/null
+++ b/JdShopListener/JdShopListener/Models/SkuModel.cs
@@ -0,0 +1,69 @@
+using GalaSoft.MvvmLight;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Text;
+
+namespace JdShopListener.Models
+{
+
+ [Table("SkuModel")]
+ public class SkuModel:ViewModelBase
+ {
+
+ public Guid Id { get; set; }
+
+ private string _SkuId;
+ ///
+ /// Sku
+ ///
+ public string SkuId
+ {
+ get { return _SkuId; }
+ set { Set(ref _SkuId, value); }
+ }
+
+ private string _ImgUrl;
+ ///
+ /// 商品主图
+ ///
+ public string ImgUrl
+ {
+ get { return _ImgUrl; }
+ set { Set(ref _ImgUrl, value); }
+ }
+
+ private string _SpuId;
+ ///
+ /// Spu
+ ///
+ public string SpuId
+ {
+ get { return _SpuId; }
+ set { Set(ref _SpuId, value); }
+ }
+
+
+ private string _Desc;
+
+ ///
+ /// 备注
+ ///
+ public string Desc
+ {
+ get { return _Desc; }
+ set { Set(ref _Desc, value); }
+ }
+
+ private string _Title;
+ ///
+ /// 标题
+ ///
+ public string Title
+ {
+ get { return _Title; }
+ set { Set(ref _Title, value); }
+ }
+
+ }
+}
diff --git a/JdShopListener/JdShopListener/SqlHelpers/SkuModelSql.cs b/JdShopListener/JdShopListener/SqlHelpers/SkuModelSql.cs
new file mode 100644
index 0000000..a1aed3d
--- /dev/null
+++ b/JdShopListener/JdShopListener/SqlHelpers/SkuModelSql.cs
@@ -0,0 +1,29 @@
+using JdShopListener.Models;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace JdShopListener.SqlHelpers
+{
+ public class SkuModelSql
+ {
+ ///
+ /// 添加sku监控
+ ///
+ ///
+ ///
+ public bool AddSkuModel(SkuModel model)
+ {
+ using (var db = new JdDBContext())
+ {
+ model.Id = Guid.NewGuid();
+ db.SkuItems.Add(model);
+ var count = db.SaveChanges();
+ return count > 0;
+ }
+ }
+
+
+
+ }
+}