add - 手动创建任务功能,任务生成方式修改
parent
73e72df74d
commit
7da743e2bd
@ -0,0 +1,82 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,110 @@
|
|||||||
|
<UserControl x:CompileBindings="False" xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
x:Class="Sln.Wcs.UI.Views.Task.CreateTaskView">
|
||||||
|
<ScrollViewer Margin="20,14,20,14">
|
||||||
|
<StackPanel Spacing="14" MaxWidth="600">
|
||||||
|
|
||||||
|
<!-- 起点 -->
|
||||||
|
<Border CornerRadius="8" Padding="18" Background="{DynamicResource CardBgBrush}"
|
||||||
|
BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1">
|
||||||
|
<StackPanel Spacing="10">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||||
|
<Rectangle Width="3" Height="18" Fill="#4FC3F7" RadiusX="2" RadiusY="2" />
|
||||||
|
<TextBlock Text="起点" FontSize="14" FontWeight="SemiBold" Foreground="{DynamicResource PrimaryTextBrush}" />
|
||||||
|
</StackPanel>
|
||||||
|
<WrapPanel>
|
||||||
|
<StackPanel Spacing="4" Width="140" Margin="0,0,12,8">
|
||||||
|
<TextBlock Text="楼栋 (13/14/15)" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" />
|
||||||
|
<TextBox Text="{Binding StartBuilding}" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Spacing="4" Width="140" Margin="0,0,12,8">
|
||||||
|
<TextBlock Text="楼层 (1~5)" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" />
|
||||||
|
<TextBox Text="{Binding StartFloor}" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Spacing="4" Width="140" Margin="0,0,12,8">
|
||||||
|
<TextBlock Text="位置号" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" />
|
||||||
|
<TextBox Text="{Binding StartLocation}" Watermark="01" />
|
||||||
|
</StackPanel>
|
||||||
|
</WrapPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<!-- 终点 -->
|
||||||
|
<Border CornerRadius="8" Padding="18" Background="{DynamicResource CardBgBrush}"
|
||||||
|
BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1">
|
||||||
|
<StackPanel Spacing="10">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||||
|
<Rectangle Width="3" Height="18" Fill="#4FC3F7" RadiusX="2" RadiusY="2" />
|
||||||
|
<TextBlock Text="终点" FontSize="14" FontWeight="SemiBold" Foreground="{DynamicResource PrimaryTextBrush}" />
|
||||||
|
</StackPanel>
|
||||||
|
<WrapPanel>
|
||||||
|
<StackPanel Spacing="4" Width="140" Margin="0,0,12,8">
|
||||||
|
<TextBlock Text="楼栋 (13/14/15)" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" />
|
||||||
|
<TextBox Text="{Binding EndBuilding}" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Spacing="4" Width="140" Margin="0,0,12,8">
|
||||||
|
<TextBlock Text="楼层 (1~5)" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" />
|
||||||
|
<TextBox Text="{Binding EndFloor}" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Spacing="4" Width="140" Margin="0,0,12,8">
|
||||||
|
<TextBlock Text="位置号" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" />
|
||||||
|
<TextBox Text="{Binding EndLocation}" Watermark="01" />
|
||||||
|
</StackPanel>
|
||||||
|
</WrapPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<!-- 任务属性 -->
|
||||||
|
<Border CornerRadius="8" Padding="18" Background="{DynamicResource CardBgBrush}"
|
||||||
|
BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1">
|
||||||
|
<StackPanel Spacing="10">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||||
|
<Rectangle Width="3" Height="18" Fill="#4FC3F7" RadiusX="2" RadiusY="2" />
|
||||||
|
<TextBlock Text="任务属性" FontSize="14" FontWeight="SemiBold" Foreground="{DynamicResource PrimaryTextBrush}" />
|
||||||
|
</StackPanel>
|
||||||
|
<!-- 任务类型 / 任务类别 -->
|
||||||
|
<WrapPanel>
|
||||||
|
<StackPanel Spacing="4" Margin="0,0,20,8">
|
||||||
|
<TextBlock Text="任务类型" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" />
|
||||||
|
<TextBlock Text="1-入库 2-出库" FontSize="9" Foreground="{DynamicResource MutedTextBrush}" Margin="0,2,0,4" />
|
||||||
|
<TextBox Text="{Binding TaskType}" Width="200" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Spacing="4" Margin="0,0,20,8">
|
||||||
|
<TextBlock Text="任务类别" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" />
|
||||||
|
<TextBlock Text="1-包材 2-成品 3-托盘" FontSize="9" Foreground="{DynamicResource MutedTextBrush}" Margin="0,2,0,4" />
|
||||||
|
<TextBox Text="{Binding TaskCategory}" Width="200" />
|
||||||
|
</StackPanel>
|
||||||
|
</WrapPanel>
|
||||||
|
<!-- 托盘条码 / 物料编码 -->
|
||||||
|
<WrapPanel>
|
||||||
|
<StackPanel Spacing="4" Margin="0,0,20,8">
|
||||||
|
<TextBlock Text="托盘条码 (RFID)" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" />
|
||||||
|
<TextBox Text="{Binding PalletBarcode}" Watermark="PALLET001" Width="200" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Spacing="4" Margin="0,0,20,8">
|
||||||
|
<TextBlock Text="物料编码" FontSize="11" Foreground="{DynamicResource SecondaryTextBrush}" />
|
||||||
|
<TextBox Text="{Binding MaterialCode}" Watermark="M001" Width="200" />
|
||||||
|
</StackPanel>
|
||||||
|
</WrapPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
<!-- 操作 -->
|
||||||
|
<Border CornerRadius="8" Padding="18" Background="{DynamicResource CardBgBrush}"
|
||||||
|
BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1">
|
||||||
|
<StackPanel Spacing="10">
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="12">
|
||||||
|
<Button Content="创建任务" Command="{Binding CreateCommand}"
|
||||||
|
IsEnabled="{Binding !IsBusy}"
|
||||||
|
Background="{DynamicResource PrimaryBtnBrush}"
|
||||||
|
Foreground="White" FontSize="13" Padding="20,10" />
|
||||||
|
<TextBlock Text="{Binding StatusText}" FontSize="12"
|
||||||
|
Foreground="{DynamicResource AccentTextBrush}"
|
||||||
|
VerticalAlignment="Center" TextWrapping="Wrap" />
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
</ScrollViewer>
|
||||||
|
</UserControl>
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace Sln.Wcs.UI.Views.Task;
|
||||||
|
|
||||||
|
public partial class CreateTaskView : UserControl
|
||||||
|
{
|
||||||
|
public CreateTaskView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue