65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
<?php
|
||
|
||
namespace Leantime\Domain\Bom\Tools;
|
||
|
||
use Laravel\Mcp\Server\Tool;
|
||
use Laravel\Mcp\Server\Tools\ToolInputSchema;
|
||
use Laravel\Mcp\Server\Tools\ToolResult;
|
||
use Leantime\Domain\Bom\Services\Bom;
|
||
|
||
/**
|
||
* 创建全局主数据(BOM/工艺文件/工具清单)。
|
||
*/
|
||
class CreateMasterTool extends Tool
|
||
{
|
||
public function __construct(
|
||
private Bom $bomService,
|
||
) {}
|
||
|
||
public function name(): string
|
||
{
|
||
return 'createMaster';
|
||
}
|
||
|
||
public function description(): string
|
||
{
|
||
return '创建一个全局主数据(BOM/工艺文件/工具清单)。主数据是跨项目共享的全局资源,创建后所有项目可见。';
|
||
}
|
||
|
||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||
{
|
||
return $schema
|
||
->string('type')->description('主数据类型:bom | process | tooling,默认 bom。')
|
||
->string('bomNo')->description('编号。')->required()
|
||
->string('productName')->description('名称/产品名。')->required()
|
||
->string('specification')->description('规格型号。')
|
||
->string('drawingNo')->description('图号。')
|
||
->string('version')->description('版本。')
|
||
->string('remark')->description('备注。');
|
||
}
|
||
|
||
public function handle(array $arguments): ToolResult
|
||
{
|
||
$type = (string) ($arguments['type'] ?? 'bom');
|
||
if (! in_array($type, ['bom', 'process', 'tooling'], true)) {
|
||
$type = 'bom';
|
||
}
|
||
|
||
$id = $this->bomService->createBom([
|
||
'type' => $type,
|
||
'bomNo' => (string) ($arguments['bomNo'] ?? ''),
|
||
'productName' => (string) ($arguments['productName'] ?? ''),
|
||
'specification' => (string) ($arguments['specification'] ?? ''),
|
||
'drawingNo' => (string) ($arguments['drawingNo'] ?? ''),
|
||
'version' => (string) ($arguments['version'] ?? ''),
|
||
'remark' => (string) ($arguments['remark'] ?? ''),
|
||
]);
|
||
|
||
if ($id > 0) {
|
||
return ToolResult::text("主数据创建成功,ID: {$id}(类型 {$type})。");
|
||
}
|
||
|
||
return ToolResult::error('主数据创建失败(可能无权限或参数不完整)。');
|
||
}
|
||
}
|