OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
63
app/Domain/Bom/Tools/DeleteMasterTool.php
Normal file
63
app/Domain/Bom/Tools/DeleteMasterTool.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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/工艺文件/工具清单)——高风险写操作。
|
||||
*
|
||||
* 会级联删除该主数据的全部明细行、动态列、Teable 数据源。
|
||||
* 调用方(AI)应先通过 getMasterDetail 列出将删除的内容并征得用户确认。
|
||||
*/
|
||||
class DeleteMasterTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Bom $bomService,
|
||||
) {}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'deleteMaster';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return '删除一个全局主数据(BOM/工艺文件/工具清单)。高风险操作:会级联删除其全部明细行、动态列、数据源,不可恢复。调用前必须先 getMasterDetail 列出内容并征得用户明确确认。';
|
||||
}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->integer('id')->description('要删除的主数据 ID。')->required()
|
||||
->boolean('confirmed')->description('用户是否已明确确认删除。必须为 true 才执行。')->required();
|
||||
}
|
||||
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$id = (int) ($arguments['id'] ?? 0);
|
||||
$confirmed = (bool) ($arguments['confirmed'] ?? false);
|
||||
|
||||
if (! $confirmed) {
|
||||
return ToolResult::error('未确认删除。请先 getMasterDetail 列出将删除的内容,征得用户确认后再传 confirmed=true。');
|
||||
}
|
||||
|
||||
$detail = $this->bomService->getBomDetail($id);
|
||||
if ($detail === false) {
|
||||
return ToolResult::error("主数据不存在或无权访问:{$id}");
|
||||
}
|
||||
|
||||
$bom = $detail['bom'] ?? [];
|
||||
$itemCount = count($detail['items'] ?? []);
|
||||
$label = trim((string) ($bom['bomNo'] ?? '').' '.(string) ($bom['productName'] ?? ''));
|
||||
|
||||
if ($this->bomService->deleteBom($id)) {
|
||||
return ToolResult::text("主数据已删除:{$label}(ID {$id}),连同 {$itemCount} 行明细一并删除。");
|
||||
}
|
||||
|
||||
return ToolResult::error('删除失败(可能无权限)。');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user