订单任务,现已修改成全局任务列表 包括 订单任务和礼品单任务
订单列表动态展示礼品单状态
This commit is contained in:
1 parent
78dc8a5d03
commit
7998a753cc
20 files changed
+2820
-2627
No files matched your search
@@ -8,6 +8,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
@@ -44,7 +45,7 @@ public partial class OrderTaskDialogView : UserControl
|
||||
|
||||
private async void OrderTaskDialogView_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await _viewModel.LoadTasks();
|
||||
_viewModel.LoadTasks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,75 +55,103 @@ public partial class OrderTaskDialogView : UserControl
|
||||
public class OrderTaskDialogViewModel : BindableBaseEx, IDisposable
|
||||
{
|
||||
private DispatcherTimer _timer;
|
||||
private const int RefreshIntervals = 10;
|
||||
private int _timeCount = 0;
|
||||
private readonly PullWXOrderService _service;
|
||||
private readonly NotifyCollectionChangedEventHandler _collectionChangedHandler;
|
||||
|
||||
private readonly TaskService _taskService;
|
||||
|
||||
public OrderTaskDialogViewModel()
|
||||
: this(PullWXOrderService.Instance)
|
||||
: this(TaskService.Instance)
|
||||
{
|
||||
_timer = new DispatcherTimer();
|
||||
_timer.Interval = TimeSpan.FromSeconds(1);
|
||||
_timer.Tick += _timer_Tick;
|
||||
_timer.Start();
|
||||
}
|
||||
|
||||
private async void _timer_Tick(object sender, EventArgs e)
|
||||
public OrderTaskDialogViewModel(TaskService taskService)
|
||||
{
|
||||
_timeCount++;
|
||||
if (_timeCount % RefreshIntervals == 0)
|
||||
{
|
||||
await LoadTasks();
|
||||
_timeCount = 0;
|
||||
}
|
||||
RefreshTime = RefreshIntervals - _timeCount;
|
||||
}
|
||||
|
||||
public OrderTaskDialogViewModel(PullWXOrderService service)
|
||||
{
|
||||
_service = service ?? PullWXOrderService.Instance;
|
||||
Tasks = _service.Tasks;
|
||||
_collectionChangedHandler = OnTasksCollectionChanged;
|
||||
Tasks.CollectionChanged += _collectionChangedHandler;
|
||||
_taskService = taskService;
|
||||
|
||||
|
||||
ClearFinishedCommand = new DelegateCommand(ClearFinished);
|
||||
ClearAllCommand = new DelegateCommand(ClearAll);
|
||||
StartDate = _taskService.StartDate;
|
||||
EndDate = _taskService.EndDate;
|
||||
|
||||
UpdateSummary();
|
||||
|
||||
|
||||
Tasks = new ObservableCollection<TaskItem>();
|
||||
|
||||
TasksView = CollectionViewSource.GetDefaultView(Tasks);
|
||||
TasksView.Filter = FilterTaskStatus;
|
||||
|
||||
_taskService.TaskChanged += TaskChanged;
|
||||
}
|
||||
private async void _timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
RefreshTime = _taskService.ResetCountdown;
|
||||
}
|
||||
|
||||
public async Task LoadTasks()
|
||||
|
||||
public TaskType SelectedTaskType
|
||||
{
|
||||
await _service.GetTaskStatus();
|
||||
get => GetValue<TaskType>();
|
||||
set
|
||||
{
|
||||
SetValue(value);
|
||||
TasksView.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void TaskChanged(object sender, IEnumerable<TaskItem> data)
|
||||
{
|
||||
LoadTasks();
|
||||
}
|
||||
|
||||
public void LoadTasks()
|
||||
{
|
||||
System.Windows.Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
Tasks.Clear();
|
||||
foreach (var item in TaskService.Instance.Tasks)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item.TaskFailReason))
|
||||
{
|
||||
if (item.TaskFailReason.Contains("任务执行异常"))
|
||||
{
|
||||
item.Status = 4;
|
||||
}
|
||||
}
|
||||
Tasks.Add(item);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 过滤
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
private bool FilterTaskStatus(object obj)
|
||||
{
|
||||
if (obj is not OrderTask task)
|
||||
if (obj is not TaskItem task)
|
||||
return false;
|
||||
|
||||
if (IsShowAll == true)
|
||||
return true;
|
||||
// Status 维度筛选
|
||||
bool statusMatch = IsShowAll || task.Status != 2;
|
||||
// 如果 IsShowAll=true,表示显示所有状态;否则只显示特定状态
|
||||
|
||||
return task.Status !=2;
|
||||
// TaskType 维度筛选
|
||||
bool typeMatch = SelectedTaskType == TaskType.ALL ? true : SelectedTaskType == task.TaskType;
|
||||
bool timeMatch = StartDate <= task.CreateTime && task.CreateTime <= EndDate;
|
||||
|
||||
// 如果 SelectedTaskType==null,表示显示所有类型;否则只显示特定类型
|
||||
return statusMatch && typeMatch && timeMatch;
|
||||
}
|
||||
|
||||
/// <summary>任务列表</summary>
|
||||
public ObservableCollection<OrderTask> Tasks { get; }
|
||||
public ObservableCollection<TaskItem> Tasks { get; }
|
||||
|
||||
public ICollectionView TasksView { get; }
|
||||
|
||||
/// <summary>清空已完成/失败任务</summary>
|
||||
public ICommand ClearFinishedCommand { get; }
|
||||
|
||||
/// <summary>清空全部任务</summary>
|
||||
public ICommand ClearAllCommand { get; }
|
||||
|
||||
/// <summary>汇总文字(总数/执行中/成功/失败)</summary>
|
||||
public string SummaryText
|
||||
{
|
||||
@@ -134,6 +163,19 @@ public class OrderTaskDialogViewModel : BindableBaseEx, IDisposable
|
||||
get => GetValue<int>();
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
|
||||
public DateTime StartDate
|
||||
{
|
||||
get => GetValue<DateTime>();
|
||||
set => SetValue(value);
|
||||
}
|
||||
public DateTime EndDate
|
||||
{
|
||||
get => GetValue<DateTime>();
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
public bool IsShowAll
|
||||
{
|
||||
get => GetValue<bool>();
|
||||
@@ -144,38 +186,7 @@ public class OrderTaskDialogViewModel : BindableBaseEx, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearFinished()
|
||||
{
|
||||
_service.ClearFinished();
|
||||
}
|
||||
|
||||
private void ClearAll()
|
||||
{
|
||||
if (System.Windows.MessageBox.Show("确定清空全部任务吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK)
|
||||
return;
|
||||
_service.ClearAll();
|
||||
}
|
||||
|
||||
private void OnTasksCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
UpdateSummary();
|
||||
}
|
||||
|
||||
private void OnTaskPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(OrderTask.Status))
|
||||
UpdateSummary();
|
||||
}
|
||||
|
||||
private void UpdateSummary()
|
||||
{
|
||||
var items = Tasks;
|
||||
//int running = items.Count(t => t.Status == OrderTask.Running);
|
||||
//int success = items.Count(t => t.Status == OrderTask.Success);
|
||||
//int failed = items.Count(t => t.Status == OrderTask.Failed);
|
||||
//string.Format("任务总数:{0} 执行中:{1} 成功:{2} 失败:{3}",
|
||||
//items.Length, running, success, failed);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user