feat: 环线批量操作、任务筛选与模拟下发搬运任务

为 LoopMission 增加一键上线/结束任务(含二次确认),DeliveryViewer 增加起点/终点/车辆/状态筛选并修复 CycleGUI 控件 id 碰撞,TransportMission 增加 Shelf 站点间随机模拟下发能力。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zhaowei.huang
2026-06-30 22:06:16 +08:00
co-authored by Cursor
parent 54cda958db
commit 1724ea57f6
4 changed files with 182 additions and 3 deletions
@@ -354,6 +354,89 @@ namespace StandardScene.Chained
}
}
#region /
/// <summary>模拟下发维持的在途任务数上限</summary>
private const int SimMaxTasks = 30;
/// <summary>模拟下发任务的 TaskId 前缀,用于识别与统计模拟任务</summary>
private const string SimTaskPrefix = "Sim-";
[JsonIgnore] private CancellationTokenSource _simCts;
[JsonIgnore] private Task _simTask;
[JsonIgnore] private volatile bool _simRunning;
[MethodMember(Name = "模拟下发搬运任务", Description = "随机在标记 Shelf 的站点间下发搬运任务,维持最多30个在途任务,完成后自动补发")]
public void StartSimulateTransport()
{
if (_simRunning)
{
CycleUiHelper.Alert("提示", "模拟下发搬运任务已在运行中。");
return;
}
_simRunning = true;
_simCts = new CancellationTokenSource();
_simTask = Task.Run(() => SimulateTransportLoop(_simCts.Token));
G.pushStatus($"已开始模拟下发搬运任务(目标在途 {SimMaxTasks} 个)");
}
[MethodMember(Name = "结束模拟下发搬运任务", Description = "停止模拟下发搬运任务")]
public void StopSimulateTransport()
{
_simRunning = false;
try { _simCts?.Cancel(); } catch { /* ignore */ }
G.pushStatus("已结束模拟下发搬运任务");
}
private async Task SimulateTransportLoop(CancellationToken token)
{
var rnd = new Random();
while (!token.IsCancellationRequested)
{
try
{
var shelfSiteIds = SimpleLib.GetAllSites()
.Where(s => s.fields.ContainsKey("shelf"))
.Select(s => s.id)
.ToList();
if (shelfSiteIds.Count < 2)
{
Diagnosis.Post("[TransportMission] 模拟下发:标记 Shelf 字段的站点不足 2 个,暂不下发", "SimTransport", true);
}
else
{
int activeSim = GetDeliveries()
.Count(d => !string.IsNullOrEmpty(d.TaskId) && d.TaskId.StartsWith(SimTaskPrefix));
for (int i = activeSim; i < SimMaxTasks && !token.IsCancellationRequested; i++)
{
int src = shelfSiteIds[rnd.Next(shelfSiteIds.Count)];
int dst;
do { dst = shelfSiteIds[rnd.Next(shelfSiteIds.Count)]; } while (dst == src);
Enqueue(new TransportDelivery
{
CarType = "Car",
Src = src,
Dst = dst,
TaskId = $"{SimTaskPrefix}{Guid.NewGuid():N}"
});
}
}
}
catch (Exception ex)
{
Diagnosis.Post($"[TransportMission] 模拟下发异常: {ExceptionFormatter.FormatEx(ex)}", "SimTransport", true);
}
try { await Task.Delay(1000, token); } catch { /* cancelled */ }
}
}
#endregion
/// <summary>
/// 查看任务列表界面
/// 打开任务查看器窗口,显示所有任务的状态