From 94e374c32b7fb3c4b571b15bec2b8e6dbabb0da2 Mon Sep 17 00:00:00 2001 From: brusnitsyn Date: Tue, 10 Feb 2026 08:57:18 +0900 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=87=D0=B8=D1=81=D1=82=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=B5=D1=88=D0=B0=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/ReportService.php | 48 +++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/app/Services/ReportService.php b/app/Services/ReportService.php index 2a519ca..f4a1fd9 100644 --- a/app/Services/ReportService.php +++ b/app/Services/ReportService.php @@ -15,6 +15,7 @@ use App\Models\UnwantedEvent; use App\Models\User; use Carbon\Carbon; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; class ReportService @@ -22,7 +23,8 @@ class ReportService public function __construct( protected DateRangeService $dateRangeService, protected PatientService $patientQueryService, - protected SnapshotService $snapshotService + protected SnapshotService $snapshotService, + protected StatisticsService $statisticsService ) {} /** @@ -62,6 +64,10 @@ class ReportService $this->snapshotService->createPatientSnapshots($report, $user, $data['dates'], $fillableAuto); DB::commit(); + + // ОЧИСТКА КЭША ПОСЛЕ УСПЕШНОГО СОЗДАНИЯ ОТЧЕТА + $this->clearCacheAfterReportCreation($user, $report); + return $report; } catch (\Exception $e) { DB::rollBack(); @@ -69,6 +75,42 @@ class ReportService } } + /** + * Очистить кэш после создания отчета + */ + private function clearCacheAfterReportCreation(User $user, Report $report): void + { + // Очищаем кэш статистики для пользователя + $this->statisticsService->clearStatisticsCache($user); + + // Также можно очистить кэш для всех пользователей отдела + $this->statisticsService->clearDepartmentStatisticsCache($user->rf_department_id); + + // Очищаем кэш за сегодня и вчера (так как отчеты влияют на эти даты) + $this->clearDailyCache($user, $report->created_at); + } + + /** + * Очистить дневной кэш + */ + private function clearDailyCache(User $user, $reportDate): void + { + $datesToClear = [ + Carbon::parse($reportDate)->format('Y-m-d'), + Carbon::parse($reportDate)->subDay()->format('Y-m-d'), + ]; + + foreach ($datesToClear as $date) { + $cacheKey = $this->generateDailyCacheKey($user, $date); + Cache::forget($cacheKey); + } + } + + private function generateDailyCacheKey(User $user, string $date): string + { + return 'daily_stats:' . $user->rf_department_id . ':' . $date; + } + /** * Получить пациентов по статусу */ @@ -418,7 +460,7 @@ class ReportService $outcomeCount = $this->patientQueryService->getOutcomePatients( $branchId, $dateRange, - 'all' + 'without-transferred' )->count(); // Умершие за период @@ -642,7 +684,7 @@ class ReportService 'outcome' => $this->patientQueryService->getOutcomePatients( $branchId, $dateRange, - 'all' + 'without-transferred' )->count(), 'outcome-discharged' => $this->patientQueryService->getOutcomePatients( $branchId,