OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)

This commit is contained in:
wangruiguo
2026-09-03 18:49:20 +08:00
commit d647428529
3501 changed files with 1988906 additions and 0 deletions

View File

@@ -0,0 +1,172 @@
<?php
namespace Leantime\Domain\Bom\Repositories;
use Illuminate\Database\ConnectionInterface;
use Leantime\Core\Db\Db as DbCore;
class Bom
{
private ConnectionInterface $db;
public function __construct(DbCore $db)
{
$this->db = $db->getConnection();
}
// ---- BOM 头 ----
public function getBoms(int $projectId): array
{
$rows = $this->db->table('zp_bom')
->where('projectId', $projectId)
->orderByDesc('id')
->get();
return array_map(fn ($r) => (array) $r, $rows->all());
}
/**
* 按类型列出全局主数据bom/process/tooling
* 主数据是全局的:始终只返回 projectId=0 的全局主数据,跨项目完全一致。
*/
public function getMasters(string $type, int $projectId = 0): array
{
$q = $this->db->table('zp_bom')
->where('projectId', 0);
if ($type !== '') {
$q->where('type', $type);
}
$rows = $q->orderByDesc('id')->get();
return array_map(fn ($r) => (array) $r, $rows->all());
}
public function getBom(int $id): array|false
{
$r = $this->db->table('zp_bom')->where('id', $id)->first();
return $r ? (array) $r : false;
}
public function createBom(array $v): int
{
return (int) $this->db->table('zp_bom')->insertGetId($v);
}
public function updateBom(int $id, array $v): bool
{
return (bool) $this->db->table('zp_bom')->where('id', $id)->update($v);
}
public function updateHiddenColumns(int $bomId, string $json): bool
{
return (bool) $this->db->table('zp_bom')->where('id', $bomId)->update(['hiddenColumns' => $json]);
}
public function deleteBom(int $id): bool
{
return (bool) $this->db->table('zp_bom')->where('id', $id)->delete();
}
// ---- Teable 源 ----
public function getSources(int $bomId): array
{
$rows = $this->db->table('zp_bom_source')->where('bomId', $bomId)->orderBy('id')->get();
return array_map(fn ($r) => (array) $r, $rows->all());
}
public function getSource(int $id): array|false
{
$r = $this->db->table('zp_bom_source')->where('id', $id)->first();
return $r ? (array) $r : false;
}
public function addSource(array $v): int
{
return (int) $this->db->table('zp_bom_source')->insertGetId($v);
}
public function deleteSource(int $id): bool
{
return (bool) $this->db->table('zp_bom_source')->where('id', $id)->delete();
}
// ---- 动态列 ----
public function getColumns(int $bomId): array
{
$rows = $this->db->table('zp_bom_column')
->where('bomId', $bomId)
->orderBy('sortOrder')
->orderBy('id')
->get();
return array_map(fn ($r) => (array) $r, $rows->all());
}
public function getColumn(int $id): array|false
{
$r = $this->db->table('zp_bom_column')->where('id', $id)->first();
return $r ? (array) $r : false;
}
public function addColumn(array $v): int
{
return (int) $this->db->table('zp_bom_column')->insertGetId($v);
}
public function deleteColumn(int $id): bool
{
return (bool) $this->db->table('zp_bom_column')->where('id', $id)->delete();
}
public function deleteColumnsByBom(int $bomId): bool
{
return (bool) $this->db->table('zp_bom_column')->where('bomId', $bomId)->delete();
}
// ---- 明细 ----
public function getItems(int $bomId): array
{
$rows = $this->db->table('zp_bom_item')
->where('bomId', $bomId)
->orderBy('seq')
->orderBy('id')
->get();
return array_map(fn ($r) => (array) $r, $rows->all());
}
public function getItem(int $id): array|false
{
$r = $this->db->table('zp_bom_item')->where('id', $id)->first();
return $r ? (array) $r : false;
}
public function createItem(array $v): int
{
return (int) $this->db->table('zp_bom_item')->insertGetId($v);
}
public function updateItem(int $id, array $v): bool
{
return (bool) $this->db->table('zp_bom_item')->where('id', $id)->update($v);
}
public function deleteItem(int $id): bool
{
return (bool) $this->db->table('zp_bom_item')->where('id', $id)->delete();
}
public function deleteItemsByBom(int $bomId): bool
{
return (bool) $this->db->table('zp_bom_item')->where('bomId', $bomId)->delete();
}
}

View File

@@ -0,0 +1,135 @@
<?php
namespace Leantime\Domain\Bom\Repositories;
use Illuminate\Database\ConnectionInterface;
use Leantime\Core\Db\Db as DbCore;
/**
* 项目 ↔ 全局主数据BOM/工艺文件/工具清单)引用层。
*
* 单向引用:项目引用主数据后,可追加项目级列(日期/库存/采购数量等)与值,
* 全部写在本引用层绝不回写全局主数据zp_bom_item
*/
class MasterRef
{
private ConnectionInterface $db;
public function __construct(DbCore $db)
{
$this->db = $db->getConnection();
}
// ---- 引用 ----
public function getRefsByProject(int $projectId): array
{
$rows = $this->db->table('zp_master_ref')
->where('projectId', $projectId)
->orderBy('id')
->get();
return array_map(fn ($r) => (array) $r, $rows->all());
}
public function getRef(int $id): array|false
{
$r = $this->db->table('zp_master_ref')->where('id', $id)->first();
return $r ? (array) $r : false;
}
public function findRef(int $projectId, int $masterId): array|false
{
$r = $this->db->table('zp_master_ref')
->where('projectId', $projectId)
->where('masterId', $masterId)
->first();
return $r ? (array) $r : false;
}
public function createRef(array $v): int
{
return (int) $this->db->table('zp_master_ref')->insertGetId($v);
}
public function deleteRef(int $id): bool
{
$this->db->table('zp_master_ref_value')->where('refId', $id)->delete();
$this->db->table('zp_master_ref_column')->where('refId', $id)->delete();
return (bool) $this->db->table('zp_master_ref')->where('id', $id)->delete();
}
// ---- 项目级追加列 ----
public function getColumns(int $refId): array
{
$rows = $this->db->table('zp_master_ref_column')
->where('refId', $refId)
->orderBy('sortOrder')
->orderBy('id')
->get();
return array_map(fn ($r) => (array) $r, $rows->all());
}
/**
* 按追加列 id 反查引用(用于鉴权)。
*/
public function getRefByColumnId(int $columnId): array|false
{
$col = $this->db->table('zp_master_ref_column')->where('id', $columnId)->first();
if (! $col) {
return false;
}
return $this->getRef((int) $col->refId);
}
public function addColumn(array $v): int
{
return (int) $this->db->table('zp_master_ref_column')->insertGetId($v);
}
public function deleteColumn(int $id): bool
{
$this->db->table('zp_master_ref_value')->where('columnId', $id)->delete();
return (bool) $this->db->table('zp_master_ref_column')->where('id', $id)->delete();
}
// ---- 项目级追加值 ----
public function getValues(int $refId): array
{
$rows = $this->db->table('zp_master_ref_value')
->where('refId', $refId)
->get();
return array_map(fn ($r) => (array) $r, $rows->all());
}
public function setValue(int $refId, int $columnId, int $itemId, string $value): bool
{
$existing = $this->db->table('zp_master_ref_value')
->where('refId', $refId)
->where('columnId', $columnId)
->where('itemId', $itemId)
->first();
if ($existing) {
return (bool) $this->db->table('zp_master_ref_value')
->where('id', $existing->id)
->update(['value' => $value]);
}
return (bool) $this->db->table('zp_master_ref_value')->insert([
'refId' => $refId,
'columnId' => $columnId,
'itemId' => $itemId,
'value' => $value,
]);
}
}