Очистка кеша после создания отчета
This commit is contained in:
@@ -15,6 +15,7 @@ use App\Models\UnwantedEvent;
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class ReportService
|
class ReportService
|
||||||
@@ -22,7 +23,8 @@ class ReportService
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
protected DateRangeService $dateRangeService,
|
protected DateRangeService $dateRangeService,
|
||||||
protected PatientService $patientQueryService,
|
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);
|
$this->snapshotService->createPatientSnapshots($report, $user, $data['dates'], $fillableAuto);
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
|
|
||||||
|
// ОЧИСТКА КЭША ПОСЛЕ УСПЕШНОГО СОЗДАНИЯ ОТЧЕТА
|
||||||
|
$this->clearCacheAfterReportCreation($user, $report);
|
||||||
|
|
||||||
return $report;
|
return $report;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
DB::rollBack();
|
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(
|
$outcomeCount = $this->patientQueryService->getOutcomePatients(
|
||||||
$branchId,
|
$branchId,
|
||||||
$dateRange,
|
$dateRange,
|
||||||
'all'
|
'without-transferred'
|
||||||
)->count();
|
)->count();
|
||||||
|
|
||||||
// Умершие за период
|
// Умершие за период
|
||||||
@@ -642,7 +684,7 @@ class ReportService
|
|||||||
'outcome' => $this->patientQueryService->getOutcomePatients(
|
'outcome' => $this->patientQueryService->getOutcomePatients(
|
||||||
$branchId,
|
$branchId,
|
||||||
$dateRange,
|
$dateRange,
|
||||||
'all'
|
'without-transferred'
|
||||||
)->count(),
|
)->count(),
|
||||||
'outcome-discharged' => $this->patientQueryService->getOutcomePatients(
|
'outcome-discharged' => $this->patientQueryService->getOutcomePatients(
|
||||||
$branchId,
|
$branchId,
|
||||||
|
|||||||
Reference in New Issue
Block a user