Skip to content

Commit ab206d6

Browse files
authored
Merge pull request #30 from lisongkun/develop
release: v1.1.0
2 parents b43515e + d81bdce commit ab206d6

23 files changed

Lines changed: 370 additions & 774 deletions

App.xaml.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace hygge_imaotai
1919
/// </summary>
2020
public partial class App : Application
2121
{
22-
const string CacheDir = "cache";
22+
const string CacheDir = "cache";
2323
// 内部使用缓存文件
2424
private readonly string _productListFile = Path.Combine(CacheDir, "productList.json");
2525
private readonly string _sessionIdFile = Path.Combine(CacheDir, "mtSessionId.txt");
@@ -28,7 +28,7 @@ public partial class App : Application
2828
/// <summary>
2929
/// 订单数据库表名
3030
/// </summary>
31-
public const string OrderDatabasePath = "imaotai.db";
31+
public const string OrderDatabasePath = "cache/imaotai.db";
3232
/// <summary>
3333
/// 订单数据库连接字符串
3434
/// </summary>
@@ -43,9 +43,9 @@ public partial class App : Application
4343
protected override async void OnStartup(StartupEventArgs e)
4444
{
4545
base.OnStartup(e);
46-
46+
4747
// 判断cache文件夹是否存在
48-
if(!Directory.Exists(CacheDir))
48+
if (!Directory.Exists(CacheDir))
4949
Directory.CreateDirectory(CacheDir);
5050

5151
// 判断productListFile是否存在,存在则读入缓存
@@ -57,24 +57,30 @@ protected override async void OnStartup(StartupEventArgs e)
5757
// 开始初始化数据库
5858
CommonRepository.CreateDatabase();
5959
// 读取会话ID
60-
if(File.Exists(_sessionIdFile))
60+
if (File.Exists(_sessionIdFile))
6161
MtSessionId = File.ReadAllText(_sessionIdFile);
6262

6363
// 创建任务调度器
6464
var stdSchedulerFactory = new StdSchedulerFactory();
6565
var scheduler = await stdSchedulerFactory.GetScheduler();
6666
await scheduler.Start();
6767
Console.WriteLine("任务调度器已启动");
68+
69+
// 创建抢购预约的任务
6870
var jobDetail = JobBuilder.Create<ReservationJob>().Build();
6971
var trigger = TriggerBuilder.Create().WithCronSchedule("0 5 9 ? * * ").Build();
72+
// 创建刷新数据的任务
73+
var refreshJobDetail = JobBuilder.Create<RefreshJob>().Build();
74+
var refreshTrigger = TriggerBuilder.Create().WithCronSchedule("0 25,55 6,7,8 ? * * ").Build();
7075
// 添加调度
7176
await scheduler.ScheduleJob(jobDetail, trigger);
77+
await scheduler.ScheduleJob(refreshJobDetail, refreshTrigger);
7278
}
7379

74-
public static void WriteCache(string filename,string content)
80+
public static void WriteCache(string filename, string content)
7581
{
7682
var path = Path.Combine(CacheDir, filename);
77-
File.WriteAllText(path,content);
83+
File.WriteAllText(path, content);
7884
}
7985
}
8086
}

Domain/LogListViewModel.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using hygge_imaotai.Entity;
1+
using hygge_imaotai.Entity;
32
using System.Collections.ObjectModel;
43
using hygge_imaotai.Repository;
54
using System.Windows.Input;
@@ -19,10 +18,10 @@ public class LogListViewModel:ViewModelBase
1918

2019
private string _searchContent;
2120
// 分页数据
22-
private int _total = 0;
21+
private long _total = 0;
2322
private int _current = 1;
2423
private int _pageSize = 10;
25-
private int _pageCount = 0;
24+
private long _pageCount = 0;
2625

2726
#endregion
2827

@@ -46,7 +45,7 @@ public string SearchContent
4645
set => SetProperty(ref _searchContent, value);
4746
}
4847

49-
public int Total
48+
public long Total
5049
{
5150
get => _total;
5251
set => SetProperty(ref _total, value);
@@ -64,7 +63,7 @@ public int PageSize
6463
set => SetProperty(ref _pageSize, value);
6564
}
6665

67-
public int PageCount
66+
public long PageCount
6867
{
6968
get => _pageCount;
7069
set => SetProperty(ref _pageCount, value);
@@ -88,7 +87,14 @@ public LogListViewModel()
8887
private void UpdateData(object parameter)
8988
{
9089
LogList.Clear();
91-
LogRepository.GetPageData((int)parameter, 10,this).ForEach(LogList.Add);
90+
DB.Sqlite.Select<LogEntity>()
91+
.WhereIf(!string.IsNullOrEmpty(this.Mobile),
92+
i => i.MobilePhone.Contains(this.Mobile))
93+
.WhereIf(!string.IsNullOrEmpty(this.SearchContent),
94+
i => i.Content.Contains(this.SearchContent))
95+
.WhereIf(!string.IsNullOrEmpty(this.Status),
96+
i => i.Status.Contains(this.Status))
97+
.Page((int)parameter, 10).ToList().ForEach(LogListViewModel.LogList.Add);
9298
}
9399

94100
#endregion

Domain/MainWindowViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private static IEnumerable<DemoItem> GenerateDemoItems(ISnackbarMessageQueue sna
127127

128128
yield return new DemoItem(
129129
"店铺管理",
130-
typeof(StoreManageUserControl),
130+
typeof(ShopManageUserControl),
131131
selectedIcon: PackIconKind.Store,
132132
unselectedIcon:PackIconKind.Store
133133
);
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
using System.Windows.Input;
33
using hygge_imaotai.Entity;
44
using hygge_imaotai.Repository;
5-
using hygge_imaotai.UserInterface.UserControls;
65

76
namespace hygge_imaotai.Domain
87
{
98
/// <summary>
109
/// 门店列表Page的ViewModel
1110
/// </summary>
12-
public class StoreListViewModel:ViewModelBase
11+
public class ShopListViewModel : ViewModelBase
1312
{
1413
#region Field
1514
private string _shopId;
@@ -19,10 +18,10 @@ public class StoreListViewModel:ViewModelBase
1918
private string _companyName;
2019

2120
// 分页数据
22-
private int _total = 0;
21+
private long _total = 0;
2322
private int _current = 1;
24-
private int _pageSize = 10;
25-
private int _pageCount = 0;
23+
private long _pageSize = 10;
24+
private long _pageCount = 0;
2625
#endregion
2726

2827
#region Properties
@@ -57,9 +56,9 @@ public string CompanyName
5756
set => SetProperty(ref _companyName, value);
5857
}
5958

60-
public static ObservableCollection<StoreEntity> StoreList { get; } = new ObservableCollection<StoreEntity>();
59+
public static ObservableCollection<ShopEntity> StoreList { get; } = new ObservableCollection<ShopEntity>();
6160

62-
public int Total
61+
public long Total
6362
{
6463
get => _total;
6564
set => SetProperty(ref _total, value);
@@ -71,13 +70,13 @@ public int Current
7170
set => SetProperty(ref _current, value);
7271
}
7372

74-
public int PageSize
73+
public long PageSize
7574
{
7675
get => _pageSize;
7776
set => SetProperty(ref _pageSize, value);
7877
}
7978

80-
public int PageCount
79+
public long PageCount
8180
{
8281
get => _pageCount;
8382
set => SetProperty(ref _pageCount, value);
@@ -87,18 +86,27 @@ public int PageCount
8786

8887
#region Constructor
8988

90-
public StoreListViewModel()
89+
public ShopListViewModel()
9190
{
9291
CurrentPageChangeCommand = new AnotherCommandImplementation(UpdateData);
9392
}
94-
#endregion
93+
#endregion
9594

9695
#region DelegateCommand
9796
public ICommand CurrentPageChangeCommand { get; private set; }
9897
private void UpdateData(object parameter)
9998
{
10099
StoreList.Clear();
101-
ShopRepository.GetPageData((int)parameter, 10,this).ForEach(StoreList.Add);
100+
DB.Sqlite.Select<ShopEntity>()
101+
.WhereIf(!string.IsNullOrEmpty(this.ShopId),
102+
i => i.ShopId.Contains(this.ShopId))
103+
.WhereIf(!string.IsNullOrEmpty(this.Province),
104+
i => i.Province.Contains(this.Province))
105+
.WhereIf(!string.IsNullOrEmpty(this.City),
106+
i => i.City.Contains(this.City))
107+
.WhereIf(!string.IsNullOrEmpty(this.Area), i => i.Area.Contains(this.Area))
108+
.WhereIf(!string.IsNullOrEmpty(this.CompanyName), i => i.CompanyName.Contains(this.CompanyName))
109+
.Page((int)parameter, 10).ToList().ForEach(StoreList.Add);
102110
}
103111

104112
#endregion

Domain/UserManageViewModel.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public class UserManageViewModel : ViewModelBase
2323
private string? _city;
2424

2525
// 分页数据
26-
private int _total = 0;
26+
private long _total = 0;
2727
private int _current = 1;
2828
private int _pageSize = 10;
29-
private int _pageCount = 0;
29+
private long _pageCount = 0;
3030

3131
#endregion
3232

@@ -76,7 +76,7 @@ public bool? IsAllItems1Selected
7676
}
7777
}
7878

79-
public int Total
79+
public long Total
8080
{
8181
get => _total;
8282
set => SetProperty(ref _total, value);
@@ -94,7 +94,7 @@ public int PageSize
9494
set => SetProperty(ref _pageSize, value);
9595
}
9696

97-
public int PageCount
97+
public long PageCount
9898
{
9999
get => _pageCount;
100100
set => SetProperty(ref _pageCount, value);
@@ -133,7 +133,15 @@ private static void SelectAll(bool select, IEnumerable<UserEntity> models)
133133
private void UpdateData(object parameter)
134134
{
135135
UserList.Clear();
136-
UserRepository.GetPageData((int)parameter, 10, this).ForEach(UserList.Add);
136+
DB.Sqlite.Select<UserEntity>()
137+
.WhereIf(!string.IsNullOrEmpty(this.Phone),
138+
i => i.Mobile.Contains(this.Phone))
139+
.WhereIf(!string.IsNullOrEmpty(this.UserId),
140+
i => (i.UserId + "").Contains(this.UserId))
141+
.WhereIf(!string.IsNullOrEmpty(this.Province),
142+
i => i.ProvinceName.Contains(this.Province))
143+
.WhereIf(!string.IsNullOrEmpty(this.City),i => i.CityName.Contains(this.City))
144+
.Page((int)parameter, 10).ToList().ForEach(UserList.Add);
137145
}
138146

139147
#endregion

Entity/LogEntity.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Security.Principal;
3+
using FreeSql.DataAnnotations;
24
using hygge_imaotai.Domain;
35

46
namespace hygge_imaotai.Entity
@@ -19,7 +21,7 @@ public class LogEntity : ViewModelBase
1921

2022
#endregion
2123
#region Properties
22-
24+
[Column(IsIdentity = true, IsPrimary = true)]
2325
public int Id
2426
{
2527
get => _id;

Entity/ProductEntity.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62
using hygge_imaotai.Domain;
73

84
namespace hygge_imaotai.Entity
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-

2-
3-
using System;
1+
using System;
2+
using FreeSql.DataAnnotations;
43
using hygge_imaotai.Domain;
54
using Newtonsoft.Json.Linq;
65

@@ -9,11 +8,11 @@ namespace hygge_imaotai.Entity
98
/// <summary>
109
/// 店铺的实体类
1110
/// </summary>
12-
public class StoreEntity:ViewModelBase
11+
public class ShopEntity:ViewModelBase
1312
{
1413
#region Field
1514

16-
private string _productId;
15+
private string _shopId;
1716
private string _province;
1817
private string _city;
1918
private string _area;
@@ -29,14 +28,14 @@ public class StoreEntity:ViewModelBase
2928

3029
#region Construct
3130

32-
public StoreEntity()
31+
public ShopEntity()
3332
{
3433
}
3534

3635

37-
public StoreEntity(string shopId, JObject jObject)
36+
public ShopEntity(string shopId, JObject jObject)
3837
{
39-
ProductId = shopId;
38+
ShopId = shopId;
4039
Province = jObject.GetValue("provinceName").Value<string>();
4140
City = jObject.GetValue("cityName").Value<string>();
4241
Area = jObject.GetValue("districtName").Value<string>();
@@ -48,9 +47,9 @@ public StoreEntity(string shopId, JObject jObject)
4847
CreatedAt = DateTime.Now;
4948
}
5049

51-
public StoreEntity(string productId, string province, string city, string area, string unbrokenAddress, string lat, string lng, string name, string companyName)
50+
public ShopEntity(string shopId, string province, string city, string area, string unbrokenAddress, string lat, string lng, string name, string companyName)
5251
{
53-
_productId = productId;
52+
_shopId = shopId;
5453
_province = province;
5554
_city = city;
5655
_area = area;
@@ -66,10 +65,10 @@ public StoreEntity(string productId, string province, string city, string area,
6665

6766
#region Properties
6867

69-
public string ProductId
68+
public string ShopId
7069
{
71-
get => _productId;
72-
set => SetProperty(ref _productId, value);
70+
get => _shopId;
71+
set => SetProperty(ref _shopId, value);
7372
}
7473

7574
public string Province
@@ -126,6 +125,7 @@ public DateTime CreatedAt
126125
set => SetProperty(ref _createdAt, value);
127126
}
128127

128+
[Column(IsIgnore = true)]
129129
public double Distance { get; set; }
130130

131131
#endregion

0 commit comments

Comments
 (0)