From 1d9fbb362e0c84ff5c15fa450d98c7bc43892fc4 Mon Sep 17 00:00:00 2001 From: Brusnitsyn Date: Mon, 6 Jul 2026 06:37:09 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=81=D1=82=D0=B8=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=201?= =?UTF-8?q?=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Web/DutyReportController.php | 2 +- app/Services/StatisticsService.php | 30 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Web/DutyReportController.php b/app/Http/Controllers/Web/DutyReportController.php index 8963268..6510383 100644 --- a/app/Http/Controllers/Web/DutyReportController.php +++ b/app/Http/Controllers/Web/DutyReportController.php @@ -376,7 +376,7 @@ class DutyReportController extends Controller $isRangeOneDay = $this->dateRangeService->isRangeOneDay($startDate, $endDate); $department = Department::find($queryDepartmentId); - $finalData = $this->statisticsService->getStatisticsData($user, $startDate, $endDate, $isRangeOneDay, $department->department_id); + $finalData = $this->statisticsService->getStatisticsDataForDepartment($department->department_id, $startDate, $endDate, $isRangeOneDay); return Excel::download(new DutyReportExport($finalData['data'], [$startDate, $endDate], $user, $department), 'statistics.xlsx'); } diff --git a/app/Services/StatisticsService.php b/app/Services/StatisticsService.php index 046cea9..1db71f6 100644 --- a/app/Services/StatisticsService.php +++ b/app/Services/StatisticsService.php @@ -50,10 +50,34 @@ class StatisticsService public function getStatisticsData(User $user, string $startDate, string $endDate, bool $isRangeOneDay): array { - $this->bedDayService->clearMemoryCache(); + return $this->buildStatisticsData($this->resolveUserDepartments($user), $startDate, $endDate, $isRangeOneDay); + } - // 1. Получаем отделения - $departments = $this->resolveUserDepartments($user); + /** + * Статистика по одному конкретному отделению (для отчёта дежурного). + * В отличие от getStatisticsData не привязана к списку отделений пользователя. + */ + public function getStatisticsDataForDepartment(int $departmentId, string $startDate, string $endDate, bool $isRangeOneDay): array + { + return $this->buildStatisticsData($this->resolveSingleDepartment($departmentId), $startDate, $endDate, $isRangeOneDay); + } + + /** + * Одно конкретное отделение в том же формате, что и resolveUserDepartments — + * сгруппировано по типу отделения. + */ + private function resolveSingleDepartment(int $departmentId) + { + return Department::select('department_id', 'name_short', 'rf_department_type') + ->with('departmentType') + ->where('department_id', $departmentId) + ->get() + ->groupBy('departmentType.name_full'); + } + + private function buildStatisticsData($departments, string $startDate, string $endDate, bool $isRangeOneDay): array + { + $this->bedDayService->clearMemoryCache(); if ($departments->isEmpty()) { return $this->emptyResponse();