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,113 @@
<?php
namespace Leantime\Domain\Projects\Controllers;
use Leantime\Core\Controller\Controller;
use Leantime\Domain\Auth\Models\Roles;
use Leantime\Domain\Auth\Services\Auth;
use Leantime\Domain\Bom\Services\Bom as BomService;
use Leantime\Domain\Bom\Services\MasterRef as MasterRefService;
use Leantime\Domain\Menu\Repositories\Menu as MenuRepository;
use Leantime\Domain\Projects\Services\Projects as ProjectService;
use Symfony\Component\HttpFoundation\Response;
class ShowAll extends Controller
{
private ProjectService $projectService;
private MenuRepository $menuRepo;
private BomService $bomService;
private MasterRefService $masterRefService;
/**
* Initializes dependencies.
*/
public function init(
ProjectService $projectService,
MenuRepository $menuRepo,
BomService $bomService,
MasterRefService $masterRefService
): void {
$this->projectService = $projectService;
$this->menuRepo = $menuRepo;
$this->bomService = $bomService;
$this->masterRefService = $masterRefService;
}
/**
* Displays the list of all projects.
*
* @param array $params Request parameters
*/
public function get(array $params): Response
{
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true);
if (! Auth::userIsAtLeast(Roles::$manager)) {
return $this->tpl->display('errors.error403', responseCode: 403);
}
if (! session()->exists('showClosedProjects')) {
session(['showClosedProjects' => false]);
}
$this->tpl->assign('role', session('userdata.role'));
if (Auth::userIsAtLeast(Roles::$admin)) {
$allProjects = $this->projectService->getAll(session('showClosedProjects'));
} else {
$allProjects = $this->projectService->getClientManagerProjects(session('userdata.id'), session('userdata.clientId'));
}
// 为每个项目附加其关联的全局主数据BOM/工艺文件/工具清单),供概览页展开显示
$typeNames = ['bom' => 'BOM', 'process' => '工艺文件', 'tooling' => '工具清单'];
foreach ($allProjects as &$project) {
$projectId = (int) $project['id'];
$linkedMasters = [];
foreach ($this->masterRefService->getRefs($projectId) as $ref) {
$master = $this->bomService->getBom((int) $ref['masterId']);
if ($master === false) {
continue;
}
$master['refId'] = (int) $ref['id'];
$master['typeName'] = $typeNames[$master['type'] ?? 'bom'] ?? 'BOM';
$linkedMasters[] = $master;
}
$project['linkedMasters'] = $linkedMasters;
}
unset($project);
$this->tpl->assign('allProjects', $allProjects);
// 项目概览甘特图数据frappe-gantt 兼容 tasks
$gantt = $this->projectService->getProjectGanttData($allProjects);
$this->tpl->assign('ganttTasks', $gantt['tasks'] ?? []);
$this->tpl->assign('menuTypes', $this->menuRepo->getMenuTypes());
$this->tpl->assign('showClosedProjects', session('showClosedProjects'));
return $this->tpl->display('projects.showAll');
}
/**
* Handles filter changes (show/hide closed projects).
*
* @param array $params Request parameters
*/
public function post(array $params): Response
{
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager], true);
if (isset($_POST['hideClosedProjects'])) {
session(['showClosedProjects' => false]);
}
if (isset($_POST['showClosedProjects'])) {
session(['showClosedProjects' => true]);
}
return $this->get($params);
}
}