通过配置文件灵活管理 Roadway 到命令类型的映射关系,支持动态扩展,无需修改代码。
{应用程序根目录}/StackerCraneJob/stackercrane-command-config.json
{
"RoadwayCommandMapping": {
"HC": "Formation",
"GW": "Standard",
"CW": "Standard"
},
"DefaultCommandType": "Standard"
}
// 自动从配置文件加载
var job = new CommonStackerCraneJob(taskService, taskExecuteDetailService, taskRepository, routerService);
// 创建任务
var task = new Dt_Task
{
Roadway = "HC-01", // 包含 "HC" → 使用 Formation 命令
PalletCode = "P001",
TaskNum = 12345
};
// 转换为命令
var command = job.ConvertToStackerCraneTaskCommand(task);
public class CustomStackerCraneTaskCommand : DeviceCommand
{
public int TaskNum { get; set; }
public string Barcode { get; set; }
}
在 CommonStackerCraneJob 中添加:
private static CustomStackerCraneTaskCommand CreateCustomCommand(Dt_Task task)
{
return new CustomStackerCraneTaskCommand
{
Barcode = task.PalletCode,
TaskNum = task.TaskNum
};
}
在 switch 表达式中添加新分支:
return commandType switch
{
"Formation" => BuildCommand(task, CreateFormationCommand(task)),
"Custom" => BuildCommand(task, CreateCustomCommand(task)),
_ => BuildCommand(task, CreateStandardCommand(task))
};
{
"RoadwayCommandMapping": {
"HC": "Formation",
"GW": "Standard",
"XX": "Custom"
}
}