OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
83
app/Domain/Bom/Tools/AddMasterItemTool.php
Normal file
83
app/Domain/Bom/Tools/AddMasterItemTool.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?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 AddMasterItemTool extends Tool
|
||||
{
|
||||
public function __construct(
|
||||
private Bom $bomService,
|
||||
) {}
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'addMasterItem';
|
||||
}
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return '给主数据(BOM/工艺文件/工具清单)添加一条明细行。固定列:seq(序号)、partNo(零件编号)、partName(零件名称)、partDrawingNo(零件图号)、material(材质)、spec(零件规格)、qtyPerUnit(单件用量)、unit(单位)、process(工序)、remark(备注);动态列用 key 传值。';
|
||||
}
|
||||
|
||||
public function schema(ToolInputSchema $schema): ToolInputSchema
|
||||
{
|
||||
return $schema
|
||||
->integer('id')->description('主数据 ID。')->required()
|
||||
->integer('seq')->description('序号。')
|
||||
->string('partNo')->description('零件编号。')
|
||||
->string('partName')->description('零件名称。')
|
||||
->string('partDrawingNo')->description('零件图号。')
|
||||
->string('material')->description('材质。')
|
||||
->string('spec')->description('零件规格。')
|
||||
->string('qtyPerUnit')->description('单件用量。')
|
||||
->string('unit')->description('单位。')
|
||||
->string('process')->description('工序。')
|
||||
->string('remark')->description('备注。')
|
||||
->raw('dynamicColumns', [
|
||||
'type' => 'object',
|
||||
'description' => '动态列的值,键为列 key,值为字符串。',
|
||||
'additionalProperties' => ['type' => 'string'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function handle(array $arguments): ToolResult
|
||||
{
|
||||
$id = (int) ($arguments['id'] ?? 0);
|
||||
|
||||
$values = [
|
||||
'seq' => (int) ($arguments['seq'] ?? 0),
|
||||
'partNo' => (string) ($arguments['partNo'] ?? ''),
|
||||
'partName' => (string) ($arguments['partName'] ?? ''),
|
||||
'partDrawingNo' => (string) ($arguments['partDrawingNo'] ?? ''),
|
||||
'material' => (string) ($arguments['material'] ?? ''),
|
||||
'spec' => (string) ($arguments['spec'] ?? ''),
|
||||
'qtyPerUnit' => (string) ($arguments['qtyPerUnit'] ?? ''),
|
||||
'unit' => (string) ($arguments['unit'] ?? ''),
|
||||
'process' => (string) ($arguments['process'] ?? ''),
|
||||
'remark' => (string) ($arguments['remark'] ?? ''),
|
||||
];
|
||||
|
||||
// 动态列
|
||||
$dynamic = $arguments['dynamicColumns'] ?? [];
|
||||
if (is_array($dynamic)) {
|
||||
foreach ($dynamic as $k => $v) {
|
||||
$values[(string) $k] = (string) $v;
|
||||
}
|
||||
}
|
||||
|
||||
$itemId = $this->bomService->saveItem($id, $values);
|
||||
|
||||
if ($itemId > 0) {
|
||||
return ToolResult::text("明细行添加成功:itemId {$itemId}。");
|
||||
}
|
||||
|
||||
return ToolResult::error('添加明细行失败(可能无权限或主数据不存在)。');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user