Files
Leantime/app/Domain/Bom/Tools/AddMasterColumnTool.php
wangruiguo d647428529
Some checks failed
Security Audit / Composer Security Audit (push) Has been cancelled
Security Audit / NPM Security Audit (push) Has been cancelled
Security Audit / CodeQL Analysis (push) Has been cancelled
OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
2026-09-03 18:49:20 +08:00

56 lines
1.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 AddMasterColumnTool extends Tool
{
public function __construct(
private Bom $bomService,
) {}
public function name(): string
{
return 'addMasterColumn';
}
public function description(): string
{
return '给主数据(BOM/工艺文件/工具清单)添加一个动态列(自定义字段)。key 为存储标识(英文或中文),label 为显示名。';
}
public function schema(ToolInputSchema $schema): ToolInputSchema
{
return $schema
->integer('id')->description('主数据 ID。')->required()
->string('key')->description('列标识(英文或中文,用于存储)。')->required()
->string('label')->description('列显示名,默认同 key。');
}
public function handle(array $arguments): ToolResult
{
$id = (int) ($arguments['id'] ?? 0);
$key = (string) ($arguments['key'] ?? '');
$label = (string) ($arguments['label'] ?? $key);
if ($key === '') {
return ToolResult::error('key 不能为空');
}
$columnId = $this->bomService->addColumn($id, $key, $label);
if ($columnId > 0) {
return ToolResult::text("动态列添加成功:{$key}(columnId {$columnId})。");
}
return ToolResult::error('添加列失败(可能无权限、key 冲突固定列、或主数据不存在)。');
}
}