Skip to content

Commit

Permalink
Merge pull request #30 from lisongkun/develop
Browse files Browse the repository at this point in the history
release: v1.1.0
  • Loading branch information
lisongkun authored Aug 5, 2023
2 parents b43515e + d81bdce commit ab206d6
Show file tree
Hide file tree
Showing 23 changed files with 370 additions and 774 deletions.
20 changes: 13 additions & 7 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace hygge_imaotai
/// </summary>
public partial class App : Application
{
const string CacheDir = "cache";
const string CacheDir = "cache";
// 内部使用缓存文件
private readonly string _productListFile = Path.Combine(CacheDir, "productList.json");
private readonly string _sessionIdFile = Path.Combine(CacheDir, "mtSessionId.txt");
Expand All @@ -28,7 +28,7 @@ public partial class App : Application
/// <summary>
/// 订单数据库表名
/// </summary>
public const string OrderDatabasePath = "imaotai.db";
public const string OrderDatabasePath = "cache/imaotai.db";
/// <summary>
/// 订单数据库连接字符串
/// </summary>
Expand All @@ -43,9 +43,9 @@ public partial class App : Application
protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

// 判断cache文件夹是否存在
if(!Directory.Exists(CacheDir))
if (!Directory.Exists(CacheDir))
Directory.CreateDirectory(CacheDir);

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

// 创建任务调度器
var stdSchedulerFactory = new StdSchedulerFactory();
var scheduler = await stdSchedulerFactory.GetScheduler();
await scheduler.Start();
Console.WriteLine("任务调度器已启动");

// 创建抢购预约的任务
var jobDetail = JobBuilder.Create<ReservationJob>().Build();
var trigger = TriggerBuilder.Create().WithCronSchedule("0 5 9 ? * * ").Build();
// 创建刷新数据的任务
var refreshJobDetail = JobBuilder.Create<RefreshJob>().Build();
var refreshTrigger = TriggerBuilder.Create().WithCronSchedule("0 25,55 6,7,8 ? * * ").Build();
// 添加调度
await scheduler.ScheduleJob(jobDetail, trigger);
await scheduler.ScheduleJob(refreshJobDetail, refreshTrigger);
}

public static void WriteCache(string filename,string content)
public static void WriteCache(string filename, string content)
{
var path = Path.Combine(CacheDir, filename);
File.WriteAllText(path,content);
File.WriteAllText(path, content);
}
}
}
20 changes: 13 additions & 7 deletions Domain/LogListViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using hygge_imaotai.Entity;
using hygge_imaotai.Entity;
using System.Collections.ObjectModel;
using hygge_imaotai.Repository;
using System.Windows.Input;
Expand All @@ -19,10 +18,10 @@ public class LogListViewModel:ViewModelBase

private string _searchContent;
// 分页数据
private int _total = 0;
private long _total = 0;
private int _current = 1;
private int _pageSize = 10;
private int _pageCount = 0;
private long _pageCount = 0;

#endregion

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

public int Total
public long Total
{
get => _total;
set => SetProperty(ref _total, value);
Expand All @@ -64,7 +63,7 @@ public int PageSize
set => SetProperty(ref _pageSize, value);
}

public int PageCount
public long PageCount
{
get => _pageCount;
set => SetProperty(ref _pageCount, value);
Expand All @@ -88,7 +87,14 @@ public LogListViewModel()
private void UpdateData(object parameter)
{
LogList.Clear();
LogRepository.GetPageData((int)parameter, 10,this).ForEach(LogList.Add);
DB.Sqlite.Select<LogEntity>()
.WhereIf(!string.IsNullOrEmpty(this.Mobile),
i => i.MobilePhone.Contains(this.Mobile))
.WhereIf(!string.IsNullOrEmpty(this.SearchContent),
i => i.Content.Contains(this.SearchContent))
.WhereIf(!string.IsNullOrEmpty(this.Status),
i => i.Status.Contains(this.Status))
.Page((int)parameter, 10).ToList().ForEach(LogListViewModel.LogList.Add);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion Domain/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private static IEnumerable<DemoItem> GenerateDemoItems(ISnackbarMessageQueue sna

yield return new DemoItem(
"店铺管理",
typeof(StoreManageUserControl),
typeof(ShopManageUserControl),
selectedIcon: PackIconKind.Store,
unselectedIcon:PackIconKind.Store
);
Expand Down
32 changes: 20 additions & 12 deletions Domain/StoreListViewModel.cs → Domain/ShopListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
using System.Windows.Input;
using hygge_imaotai.Entity;
using hygge_imaotai.Repository;
using hygge_imaotai.UserInterface.UserControls;

namespace hygge_imaotai.Domain
{
/// <summary>
/// 门店列表Page的ViewModel
/// </summary>
public class StoreListViewModel:ViewModelBase
public class ShopListViewModel : ViewModelBase
{
#region Field
private string _shopId;
Expand All @@ -19,10 +18,10 @@ public class StoreListViewModel:ViewModelBase
private string _companyName;

// 分页数据
private int _total = 0;
private long _total = 0;
private int _current = 1;
private int _pageSize = 10;
private int _pageCount = 0;
private long _pageSize = 10;
private long _pageCount = 0;
#endregion

#region Properties
Expand Down Expand Up @@ -57,9 +56,9 @@ public string CompanyName
set => SetProperty(ref _companyName, value);
}

public static ObservableCollection<StoreEntity> StoreList { get; } = new ObservableCollection<StoreEntity>();
public static ObservableCollection<ShopEntity> StoreList { get; } = new ObservableCollection<ShopEntity>();

public int Total
public long Total
{
get => _total;
set => SetProperty(ref _total, value);
Expand All @@ -71,13 +70,13 @@ public int Current
set => SetProperty(ref _current, value);
}

public int PageSize
public long PageSize
{
get => _pageSize;
set => SetProperty(ref _pageSize, value);
}

public int PageCount
public long PageCount
{
get => _pageCount;
set => SetProperty(ref _pageCount, value);
Expand All @@ -87,18 +86,27 @@ public int PageCount

#region Constructor

public StoreListViewModel()
public ShopListViewModel()
{
CurrentPageChangeCommand = new AnotherCommandImplementation(UpdateData);
}
#endregion
#endregion

#region DelegateCommand
public ICommand CurrentPageChangeCommand { get; private set; }
private void UpdateData(object parameter)
{
StoreList.Clear();
ShopRepository.GetPageData((int)parameter, 10,this).ForEach(StoreList.Add);
DB.Sqlite.Select<ShopEntity>()
.WhereIf(!string.IsNullOrEmpty(this.ShopId),
i => i.ShopId.Contains(this.ShopId))
.WhereIf(!string.IsNullOrEmpty(this.Province),
i => i.Province.Contains(this.Province))
.WhereIf(!string.IsNullOrEmpty(this.City),
i => i.City.Contains(this.City))
.WhereIf(!string.IsNullOrEmpty(this.Area), i => i.Area.Contains(this.Area))
.WhereIf(!string.IsNullOrEmpty(this.CompanyName), i => i.CompanyName.Contains(this.CompanyName))
.Page((int)parameter, 10).ToList().ForEach(StoreList.Add);
}

#endregion
Expand Down
18 changes: 13 additions & 5 deletions Domain/UserManageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public class UserManageViewModel : ViewModelBase
private string? _city;

// 分页数据
private int _total = 0;
private long _total = 0;
private int _current = 1;
private int _pageSize = 10;
private int _pageCount = 0;
private long _pageCount = 0;

#endregion

Expand Down Expand Up @@ -76,7 +76,7 @@ public bool? IsAllItems1Selected
}
}

public int Total
public long Total
{
get => _total;
set => SetProperty(ref _total, value);
Expand All @@ -94,7 +94,7 @@ public int PageSize
set => SetProperty(ref _pageSize, value);
}

public int PageCount
public long PageCount
{
get => _pageCount;
set => SetProperty(ref _pageCount, value);
Expand Down Expand Up @@ -133,7 +133,15 @@ private static void SelectAll(bool select, IEnumerable<UserEntity> models)
private void UpdateData(object parameter)
{
UserList.Clear();
UserRepository.GetPageData((int)parameter, 10, this).ForEach(UserList.Add);
DB.Sqlite.Select<UserEntity>()
.WhereIf(!string.IsNullOrEmpty(this.Phone),
i => i.Mobile.Contains(this.Phone))
.WhereIf(!string.IsNullOrEmpty(this.UserId),
i => (i.UserId + "").Contains(this.UserId))
.WhereIf(!string.IsNullOrEmpty(this.Province),
i => i.ProvinceName.Contains(this.Province))
.WhereIf(!string.IsNullOrEmpty(this.City),i => i.CityName.Contains(this.City))
.Page((int)parameter, 10).ToList().ForEach(UserList.Add);
}

#endregion
Expand Down
4 changes: 3 additions & 1 deletion Entity/LogEntity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Security.Principal;
using FreeSql.DataAnnotations;
using hygge_imaotai.Domain;

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

#endregion
#region Properties

[Column(IsIdentity = true, IsPrimary = true)]
public int Id
{
get => _id;
Expand Down
4 changes: 0 additions & 4 deletions Entity/ProductEntity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using hygge_imaotai.Domain;

namespace hygge_imaotai.Entity
Expand Down
26 changes: 13 additions & 13 deletions Entity/StoreEntity.cs → Entity/ShopEntity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@


using System;
using System;
using FreeSql.DataAnnotations;
using hygge_imaotai.Domain;
using Newtonsoft.Json.Linq;

Expand All @@ -9,11 +8,11 @@ namespace hygge_imaotai.Entity
/// <summary>
/// 店铺的实体类
/// </summary>
public class StoreEntity:ViewModelBase
public class ShopEntity:ViewModelBase
{
#region Field

private string _productId;
private string _shopId;
private string _province;
private string _city;
private string _area;
Expand All @@ -29,14 +28,14 @@ public class StoreEntity:ViewModelBase

#region Construct

public StoreEntity()
public ShopEntity()
{
}


public StoreEntity(string shopId, JObject jObject)
public ShopEntity(string shopId, JObject jObject)
{
ProductId = shopId;
ShopId = shopId;
Province = jObject.GetValue("provinceName").Value<string>();
City = jObject.GetValue("cityName").Value<string>();
Area = jObject.GetValue("districtName").Value<string>();
Expand All @@ -48,9 +47,9 @@ public StoreEntity(string shopId, JObject jObject)
CreatedAt = DateTime.Now;
}

public StoreEntity(string productId, string province, string city, string area, string unbrokenAddress, string lat, string lng, string name, string companyName)
public ShopEntity(string shopId, string province, string city, string area, string unbrokenAddress, string lat, string lng, string name, string companyName)
{
_productId = productId;
_shopId = shopId;
_province = province;
_city = city;
_area = area;
Expand All @@ -66,10 +65,10 @@ public StoreEntity(string productId, string province, string city, string area,

#region Properties

public string ProductId
public string ShopId
{
get => _productId;
set => SetProperty(ref _productId, value);
get => _shopId;
set => SetProperty(ref _shopId, value);
}

public string Province
Expand Down Expand Up @@ -126,6 +125,7 @@ public DateTime CreatedAt
set => SetProperty(ref _createdAt, value);
}

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

#endregion
Expand Down
Loading

0 comments on commit ab206d6

Please sign in to comment.