You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.8 KiB
C#
83 lines
2.8 KiB
C#
using Avalonia.Controls;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Sln.Wcs.Business;
|
|
using Sln.Wcs.Repository.service;
|
|
|
|
namespace Sln.Wcs.UI.ViewModels.Task;
|
|
|
|
public partial class CreateTaskViewModel : ObservableObject
|
|
{
|
|
private readonly TaskCreateService _taskCreateService;
|
|
private readonly ILiveTaskQueueService _taskQueueService;
|
|
|
|
public string PageTitle => "手动创建任务";
|
|
|
|
// ---- 起点 ----
|
|
[ObservableProperty] private int _startBuilding = 13;
|
|
[ObservableProperty] private int _startFloor = 1;
|
|
[ObservableProperty] private string _startLocation = "01";
|
|
|
|
// ---- 终点 ----
|
|
[ObservableProperty] private int _endBuilding = 15;
|
|
[ObservableProperty] private int _endFloor = 5;
|
|
[ObservableProperty] private string _endLocation = "01";
|
|
|
|
// ---- 任务属性 ----
|
|
[ObservableProperty] private int _taskType = 1; // 1-入库 2-出库
|
|
[ObservableProperty] private int _taskCategory = 1; // 1-包材 2-成品 3-托盘
|
|
[ObservableProperty] private string _palletBarcode = string.Empty;
|
|
[ObservableProperty] private string _materialCode = string.Empty;
|
|
|
|
// ---- 状态 ----
|
|
[ObservableProperty] private string _statusText = string.Empty;
|
|
[ObservableProperty] private bool _isBusy;
|
|
|
|
public CreateTaskViewModel(TaskCreateService taskCreateService, ILiveTaskQueueService taskQueueService)
|
|
{
|
|
_taskCreateService = taskCreateService;
|
|
_taskQueueService = taskQueueService;
|
|
}
|
|
|
|
public Avalonia.Controls.Control CreateView() => new Views.Task.CreateTaskView();
|
|
|
|
[RelayCommand]
|
|
private async System.Threading.Tasks.Task CreateAsync()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(PalletBarcode) || string.IsNullOrWhiteSpace(MaterialCode))
|
|
{
|
|
StatusText = "托盘条码和物料编码不能为空";
|
|
return;
|
|
}
|
|
|
|
IsBusy = true;
|
|
StatusText = "正在生成任务...";
|
|
|
|
try
|
|
{
|
|
var taskQueue = await System.Threading.Tasks.Task.Run(() =>
|
|
_taskCreateService.CreateTask(
|
|
StartBuilding, StartFloor, StartLocation,
|
|
EndBuilding, EndFloor, EndLocation,
|
|
TaskType, TaskCategory,
|
|
PalletBarcode, MaterialCode));
|
|
|
|
StatusText = $"路由生成完成,共 {taskQueue.taskSteps} 条明细,正在保存...";
|
|
|
|
var saved = await System.Threading.Tasks.Task.Run(() => _taskQueueService.InsertTaskQueue(taskQueue));
|
|
|
|
StatusText = saved
|
|
? $"✓ 任务创建成功: {taskQueue.taskCode},共 {taskQueue.taskSteps} 条明细"
|
|
: "✗ 保存失败";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
StatusText = $"✗ 创建失败: {ex.Message}";
|
|
}
|
|
finally
|
|
{
|
|
IsBusy = false;
|
|
}
|
|
}
|
|
}
|