diff --git a/BBWY.Client/APIServices/StatisticsService.cs b/BBWY.Client/APIServices/StatisticsService.cs index df806421..22d7d3c7 100644 --- a/BBWY.Client/APIServices/StatisticsService.cs +++ b/BBWY.Client/APIServices/StatisticsService.cs @@ -1,6 +1,7 @@ using BBWY.Client.Models; using BBWY.Common.Http; using BBWY.Common.Models; +using System; using System.Net.Http; namespace BBWY.Client.APIServices @@ -16,11 +17,13 @@ namespace BBWY.Client.APIServices /// 今日业绩统计 /// /// - public ApiResponse GetTodayAchievementStatistics() + public ApiResponse GetTodayAchievementStatistics(DateTime startTime, DateTime endTime) { - return SendRequest(globalContext.BBYWApiHost, "Api/Statistics/GetTodayAchievementStatistics", new + return SendRequest(globalContext.BBYWApiHost, "Api/Statistics/GetOrderAchievementStatistics", new { - ShopId = globalContext.User.Shop.ShopId + globalContext.User.Shop.ShopId, + startTime, + endTime }, null, HttpMethod.Post); } diff --git a/BBWY.Client/App.xaml.cs b/BBWY.Client/App.xaml.cs index 80a08e61..0de8fb93 100644 --- a/BBWY.Client/App.xaml.cs +++ b/BBWY.Client/App.xaml.cs @@ -3,6 +3,7 @@ using BBWY.Client.ViewModels; using BBWY.Common.Extensions; using BBWY.Common.Http; using BBWY.Common.Models; +using BBWY.Common.Trigger; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; diff --git a/BBWY.Client/BBWY.Client.csproj b/BBWY.Client/BBWY.Client.csproj index da12e8d8..a225e56d 100644 --- a/BBWY.Client/BBWY.Client.csproj +++ b/BBWY.Client/BBWY.Client.csproj @@ -1,7 +1,7 @@  - WinExe + Exe netcoreapp3.1 true Resources\Images\bbwylogo.ico diff --git a/BBWY.Client/Models/Product/PurchaseSchemeProductSku.cs b/BBWY.Client/Models/Product/PurchaseSchemeProductSku.cs index 998d5079..20f5c206 100644 --- a/BBWY.Client/Models/Product/PurchaseSchemeProductSku.cs +++ b/BBWY.Client/Models/Product/PurchaseSchemeProductSku.cs @@ -1,4 +1,6 @@ -namespace BBWY.Client.Models +using System; + +namespace BBWY.Client.Models { /// /// 采购商品的Sku @@ -33,11 +35,23 @@ public long SkuPurchaseSchemeId { get; set; } public long UserId { get; set; } - public int ItemTotal { get => itemTotal; set { Set(ref itemTotal, value); } } + public int ItemTotal + { + get => itemTotal; set + { + if (Set(ref itemTotal, value)) + { + SkuAmount = value * Price; + OnItemTotalChanged?.Invoke(value); + } + } + } public decimal SkuAmount { get => skuAmount; set { Set(ref skuAmount, value); } } private int itemTotal; private decimal skuAmount; + + public Action OnItemTotalChanged { get; set; } } } diff --git a/BBWY.Client/ViewModels/Order/ChoosePurchaseSchemeViewModel.cs b/BBWY.Client/ViewModels/Order/ChoosePurchaseSchemeViewModel.cs index 3918c232..d38c7049 100644 --- a/BBWY.Client/ViewModels/Order/ChoosePurchaseSchemeViewModel.cs +++ b/BBWY.Client/ViewModels/Order/ChoosePurchaseSchemeViewModel.cs @@ -1,5 +1,6 @@ using BBWY.Client.APIServices; using BBWY.Client.Models; +using BBWY.Client.Views.Purchase; using BBWY.Common.Models; using GalaSoft.MvvmLight.Command; using System.Collections.Generic; @@ -46,6 +47,7 @@ namespace BBWY.Client.ViewModels protected override void Unload() { + this.ItemTotal = 0; this.OrderId = this.SkuId = this.SkuName = string.Empty; PurchaseSchemeList.Clear(); } @@ -100,7 +102,8 @@ namespace BBWY.Client.ViewModels public void PreviewPurchase(PurchaseScheme purchaseScheme) { - + var p = new _1688Purchase(this.OrderId, this.ItemTotal, purchaseScheme); + p.ShowDialog(); } } } diff --git a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs index d7afa335..2d73a25c 100644 --- a/BBWY.Client/ViewModels/Order/OrderListViewModel.cs +++ b/BBWY.Client/ViewModels/Order/OrderListViewModel.cs @@ -108,7 +108,7 @@ namespace BBWY.Client.ViewModels { PageIndex = 1; Task.Factory.StartNew(() => LoadOrder(1)); - Task.Factory.StartNew(LoadTodayAchievement); + Task.Factory.StartNew(() => LoadTodayAchievement(StartDate, EndDate)); }); CopyTextCommand = new RelayCommand(s => Clipboard.SetText(s)); CopyOrderWaybillCommand = new RelayCommand(o => Clipboard.SetText(o.WaybillNo)); @@ -118,12 +118,12 @@ namespace BBWY.Client.ViewModels StartDate = DateTime.Now.Date.AddDays(d * -1); PageIndex = 1; Task.Factory.StartNew(() => LoadOrder(1)); - Task.Factory.StartNew(LoadTodayAchievement); + Task.Factory.StartNew(() => LoadTodayAchievement(StartDate, EndDate)); }); OrderPageIndexChangedCommand = new RelayCommand(p => { Task.Factory.StartNew(() => LoadOrder(p.PageIndex)); - Task.Factory.StartNew(LoadTodayAchievement); + Task.Factory.StartNew(() => LoadTodayAchievement(StartDate, EndDate)); }); DecodeConsigneeCommand = new RelayCommand(DecodeConsignee); ChooseStorageTypeCommand = new RelayCommand(ChooseStorageType); @@ -187,9 +187,9 @@ namespace BBWY.Client.ViewModels IsLoading = false; } - private void LoadTodayAchievement() + private void LoadTodayAchievement(DateTime startTime, DateTime endTime) { - var response = statisticsService.GetTodayAchievementStatistics(); + var response = statisticsService.GetTodayAchievementStatistics(startTime, endTime); if (!response.Success) return; _ = response.Data.Map(ToDayOrderAchievement); diff --git a/BBWY.Client/ViewModels/Purchase/1688PreviewPurchaseViewModel.cs b/BBWY.Client/ViewModels/Purchase/1688PreviewPurchaseViewModel.cs index e25b1e6a..53cb9f55 100644 --- a/BBWY.Client/ViewModels/Purchase/1688PreviewPurchaseViewModel.cs +++ b/BBWY.Client/ViewModels/Purchase/1688PreviewPurchaseViewModel.cs @@ -1,5 +1,6 @@ using BBWY.Client.APIServices; using BBWY.Client.Models; +using BBWY.Common.Trigger; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; @@ -21,10 +22,13 @@ namespace BBWY.Client.ViewModels private int skuItemCount; private bool isLoading; private OneBoundAPIService oneBoundAPIService; + private DelayTrigger delayTrigger; public _1688PreviewPurchaseViewModel(OneBoundAPIService oneBoundAPIService) { this.oneBoundAPIService = oneBoundAPIService; + this.delayTrigger = new DelayTrigger(); + this.delayTrigger.OnExecute = OnDelayTriggerExecute; PurchaseSchemeProductSkuList = new ObservableCollection(); } @@ -74,6 +78,7 @@ namespace BBWY.Client.ViewModels { PurchaseSchemeProductSkuList.Add(purchaseSchemeProductSku); purchaseSchemeProductSku.ItemTotal = skuItemCount; + purchaseSchemeProductSku.OnItemTotalChanged = OnItemTotalChanged; } } }); @@ -139,5 +144,16 @@ namespace BBWY.Client.ViewModels } return "pack://application:,,,/Resources/Images/defaultItem.png"; } + + private void OnItemTotalChanged(int itemTotal) + { + Console.WriteLine($"OnItemTotalChanged {DateTime.Now} {itemTotal}"); + this.delayTrigger.SetKey(itemTotal.ToString()); + } + + private void OnDelayTriggerExecute(string key) + { + + } } } diff --git a/BBWY.Client/Views/Order/ChoosePurchaseScheme.xaml b/BBWY.Client/Views/Order/ChoosePurchaseScheme.xaml index 2cfb6a11..785a6a75 100644 --- a/BBWY.Client/Views/Order/ChoosePurchaseScheme.xaml +++ b/BBWY.Client/Views/Order/ChoosePurchaseScheme.xaml @@ -48,7 +48,9 @@ + Background="#1CC2A2" + Command="{Binding DataContext.PreviewPurchaseCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}}" + CommandParameter="{Binding }"/> - - + + diff --git a/BBWY.Client/Views/Purchase/1688Purchase.xaml b/BBWY.Client/Views/Purchase/1688Purchase.xaml index 3bc5f88d..3cac376f 100644 --- a/BBWY.Client/Views/Purchase/1688Purchase.xaml +++ b/BBWY.Client/Views/Purchase/1688Purchase.xaml @@ -5,12 +5,21 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:BBWY.Client.Views.Purchase" xmlns:c="clr-namespace:BBWY.Controls;assembly=BBWY.Controls" + xmlns:b="http://schemas.microsoft.com/xaml/behaviors" mc:Ignorable="d" Title="提交订单" Height="600" Width="800" Style="{StaticResource bwstyle}" MinButtonVisibility="Collapsed" MaxButtonVisibility="Collapsed" DataContext="{Binding _1688PreviewPurchase,Source={StaticResource Locator}}"> + + + + + + + + @@ -25,7 +34,8 @@ + ItemsSource="{Binding PurchaseSchemeProductSkuList}" + RowHeight="90"> @@ -40,21 +50,25 @@ - + - + - + + Binding="{Binding SkuAmount,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" + ElementStyle="{StaticResource middleTextBlock}"/> diff --git a/BBWY.Client/Views/Purchase/1688Purchase.xaml.cs b/BBWY.Client/Views/Purchase/1688Purchase.xaml.cs index 17d1e80f..ae6532ef 100644 --- a/BBWY.Client/Views/Purchase/1688Purchase.xaml.cs +++ b/BBWY.Client/Views/Purchase/1688Purchase.xaml.cs @@ -1,4 +1,6 @@ -using BBWY.Controls; +using BBWY.Client.Models; +using BBWY.Client.ViewModels; +using BBWY.Controls; namespace BBWY.Client.Views.Purchase { @@ -7,9 +9,10 @@ namespace BBWY.Client.Views.Purchase /// public partial class _1688Purchase : BWindow { - public _1688Purchase() + public _1688Purchase(string orderId, int skuItemCount, PurchaseScheme purchaseScheme) { InitializeComponent(); + (this.DataContext as _1688PreviewPurchaseViewModel).SetData(orderId, skuItemCount, purchaseScheme); } } } diff --git a/BBWY.Common/TaskSchedulers/DelayTrigger.cs b/BBWY.Common/TaskSchedulers/DelayTrigger.cs new file mode 100644 index 00000000..53e7f318 --- /dev/null +++ b/BBWY.Common/TaskSchedulers/DelayTrigger.cs @@ -0,0 +1,70 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace BBWY.Common.Trigger +{ + /// + /// 延迟触发组件 + /// + public class DelayTrigger + { + public DelayTrigger(int delayTime = 1000) + { + if (delayTime < 1000) + delayTime = 1000; + this.delayTime = delayTime; + } + /// + /// 延迟执行时间(ms) + /// + private int delayTime; + + /// + /// 关键字 + /// + private string currentKey; + + /// + /// 是否可以执行 + /// + private volatile bool canExecute; + + /// + /// 是否正在延迟响应中 + /// + private volatile bool isDelaying; + + + public Action OnExecute; + + + public void SetKey(string key) + { + currentKey = key; + if (isDelaying) + { + canExecute = false; + return; + } + Task.Factory.StartNew(delegate + { + isDelaying = true; + while (true) + { + canExecute = true; + Thread.Sleep(delayTime); + if (canExecute) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"DelayTrigger {currentKey} Execute at {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff")}"); + Console.ResetColor(); + OnExecute?.Invoke(currentKey); + isDelaying = false; + break; + } + } + }); + } + } +} diff --git a/BBWY.Server.API/Controllers/StatisticsController.cs b/BBWY.Server.API/Controllers/StatisticsController.cs index 77e453cd..9aebfb87 100644 --- a/BBWY.Server.API/Controllers/StatisticsController.cs +++ b/BBWY.Server.API/Controllers/StatisticsController.cs @@ -21,9 +21,9 @@ namespace BBWY.Server.API.Controllers /// /// [HttpPost] - public ToDayOrderAchievementResponse GetTodayAchievementStatistics(ToDayOrderAchievementRequest request) + public OrderAchievementResponse GetOrderAchievementStatistics([FromBody] OrderAchievementRequest request) { - return statisticsBusiness.GetTodayAchievementStatistics(request); + return statisticsBusiness.GetOrderAchievementStatistics(request); } } } diff --git a/BBWY.Server.Business/Statistics/StatisticsBusiness.cs b/BBWY.Server.Business/Statistics/StatisticsBusiness.cs index 6312178e..1e886422 100644 --- a/BBWY.Server.Business/Statistics/StatisticsBusiness.cs +++ b/BBWY.Server.Business/Statistics/StatisticsBusiness.cs @@ -17,15 +17,16 @@ namespace BBWY.Server.Business invalidOrderStateList = new List() { Enums.OrderState.待付款, Enums.OrderState.已取消 }; } - public ToDayOrderAchievementResponse GetTodayAchievementStatistics(ToDayOrderAchievementRequest request) + public OrderAchievementResponse GetOrderAchievementStatistics(OrderAchievementRequest request) { - var today = DateTime.Now.Date; + request.EndTime = request.EndTime.Date.AddDays(1); var response = fsql.Select().LeftJoin((o, oc) => o.Id == oc.OrderId) .Where((o, oc) => o.ShopId == request.ShopId && o.OrderState != null && !invalidOrderStateList.Contains(o.OrderState.Value) && - o.StartTime >= today) - .ToAggregate((o, oc) => new ToDayOrderAchievementResponse() + o.StartTime >= request.StartTime && + o.StartTime < request.EndTime) + .ToAggregate((o, oc) => new OrderAchievementResponse() { OrderCount = o.Count(), Profit = oc.Sum(oc.Key.Profit), diff --git a/BBWY.Server.Model/Dto/Request/Statistics/ToDayOrderAchievementRequest.cs b/BBWY.Server.Model/Dto/Request/Statistics/ToDayOrderAchievementRequest.cs index f73c1444..bbf9408e 100644 --- a/BBWY.Server.Model/Dto/Request/Statistics/ToDayOrderAchievementRequest.cs +++ b/BBWY.Server.Model/Dto/Request/Statistics/ToDayOrderAchievementRequest.cs @@ -1,7 +1,13 @@ -namespace BBWY.Server.Model.Dto +using System; + +namespace BBWY.Server.Model.Dto { - public class ToDayOrderAchievementRequest + public class OrderAchievementRequest { public long ShopId { get; set; } + + public DateTime StartTime { get; set; } + + public DateTime EndTime { get; set; } } } diff --git a/BBWY.Server.Model/Dto/Response/Statistics/ToDayOrderAchievementResponse.cs b/BBWY.Server.Model/Dto/Response/Statistics/OrderAchievementResponse.cs similarity index 96% rename from BBWY.Server.Model/Dto/Response/Statistics/ToDayOrderAchievementResponse.cs rename to BBWY.Server.Model/Dto/Response/Statistics/OrderAchievementResponse.cs index 4160fbd3..075f6a3b 100644 --- a/BBWY.Server.Model/Dto/Response/Statistics/ToDayOrderAchievementResponse.cs +++ b/BBWY.Server.Model/Dto/Response/Statistics/OrderAchievementResponse.cs @@ -2,7 +2,7 @@ namespace BBWY.Server.Model.Dto { - public class ToDayOrderAchievementResponse + public class OrderAchievementResponse { ///