Форматирование

This commit is contained in:
brusnitsyn
2026-04-24 16:46:10 +09:00
parent fd0e6ee817
commit 63daa62888
87 changed files with 1380 additions and 791 deletions

View File

@@ -33,6 +33,7 @@ class ClearStatisticsCache extends Command
// Очищаем весь кэш статистики
$this->clearAllStatisticsCache();
$this->info('✅ Весь кэш статистики очищен');
return 0;
}
@@ -40,6 +41,7 @@ class ClearStatisticsCache extends Command
// Очищаем кэш для конкретного отделения
$this->clearDepartmentCache($departmentId);
$this->info("✅ Кэш статистики для отдела {$departmentId} очищен");
return 0;
}
@@ -47,11 +49,13 @@ class ClearStatisticsCache extends Command
// Очищаем кэш за конкретную дату
$this->clearDateCache($date);
$this->info("✅ Кэш статистики за {$date} очищен");
return 0;
}
// Если опции не указаны, показываем помощь
$this->showHelp();
return 1;
}
@@ -69,7 +73,7 @@ class ClearStatisticsCache extends Command
$this->clearStatisticsKeys();
}
$this->info("Очищено: весь кэш статистики");
$this->info('Очищено: весь кэш статистики');
}
/**
@@ -78,14 +82,14 @@ class ClearStatisticsCache extends Command
private function clearDepartmentCache(int $departmentId): void
{
if (method_exists(Cache::store(), 'tags')) {
Cache::tags(['statistics', 'department_' . $departmentId])->flush();
Cache::tags(['statistics', 'department_'.$departmentId])->flush();
} else {
// Ищем и удаляем ключи для отдела
$keys = Cache::get('statistics_keys_' . $departmentId, []);
$keys = Cache::get('statistics_keys_'.$departmentId, []);
foreach ($keys as $key) {
Cache::forget($key);
}
Cache::forget('statistics_keys_' . $departmentId);
Cache::forget('statistics_keys_'.$departmentId);
}
$this->info("Очищено: кэш для отдела {$departmentId}");
@@ -97,7 +101,7 @@ class ClearStatisticsCache extends Command
private function clearDateCache(string $date): void
{
if (method_exists(Cache::store(), 'tags')) {
Cache::tags(['statistics', 'date_' . $date])->flush();
Cache::tags(['statistics', 'date_'.$date])->flush();
} else {
// Ищем ключи с этой датой
$prefix = config('cache.prefix', 'laravel');
@@ -119,9 +123,9 @@ class ClearStatisticsCache extends Command
$redis = $store->getRedis();
$keys = $redis->keys($pattern);
if (!empty($keys)) {
if (! empty($keys)) {
$redis->del($keys);
$this->info("Удалено ключей: " . count($keys));
$this->info('Удалено ключей: '.count($keys));
}
}
}
@@ -139,9 +143,9 @@ class ClearStatisticsCache extends Command
$redis = $store->getRedis();
$keys = $redis->keys("{$prefix}:statistics:*");
if (!empty($keys)) {
if (! empty($keys)) {
$redis->del($keys);
$this->info("Удалено ключей статистики: " . count($keys));
$this->info('Удалено ключей статистики: '.count($keys));
}
}
// Для файлового кэша
@@ -156,11 +160,11 @@ class ClearStatisticsCache extends Command
*/
private function clearFileCache(string $directory, string $pattern): void
{
if (!is_dir($directory)) {
if (! is_dir($directory)) {
return;
}
$files = glob($directory . '/*');
$files = glob($directory.'/*');
$deleted = 0;
foreach ($files as $file) {
@@ -173,7 +177,7 @@ class ClearStatisticsCache extends Command
}
}
$this->info("Удалено файлов кэша: " . $deleted);
$this->info('Удалено файлов кэша: '.$deleted);
}
/**

View File

@@ -1,4 +1,5 @@
<?php
// app/Console/Commands/FillAverageBedDaysMetric.php
namespace App\Console\Commands;
@@ -9,7 +10,6 @@ use App\Models\Report;
use App\Services\ReportService;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class FillAverageBedDaysMetric extends Command
{
@@ -71,19 +71,21 @@ class FillAverageBedDaysMetric extends Command
if ($totalReports === 0) {
$this->warn('No reports found matching criteria.');
return 0;
}
$this->info("Found {$totalReports} reports to process");
// Confirm if large number
if ($totalReports > 1000 && !$this->confirm("Processing {$totalReports} reports may take a while. Continue?")) {
if ($totalReports > 1000 && ! $this->confirm("Processing {$totalReports} reports may take a while. Continue?")) {
$this->info('Command cancelled.');
return 0;
}
$force = $this->option('force');
$chunkSize = (int)$this->option('chunk');
$chunkSize = (int) $this->option('chunk');
// Progress bar
$bar = $this->output->createProgressBar($totalReports);
@@ -110,7 +112,7 @@ class FillAverageBedDaysMetric extends Command
} catch (\Exception $e) {
$errors++;
$this->warn("\nError processing report {$report->report_id}: " . $e->getMessage());
$this->warn("\nError processing report {$report->report_id}: ".$e->getMessage());
}
$bar->advance();
@@ -139,7 +141,7 @@ class FillAverageBedDaysMetric extends Command
$this->info('Sample of updated reports:');
// Get a sample of recently updated reports
$sampleQuery = Report::whereHas('metrikaResults', function($q) {
$sampleQuery = Report::whereHas('metrikaResults', function ($q) {
$q->where('rf_metrika_item_id', 18);
})
->orderBy('report_id', 'desc')
@@ -156,10 +158,11 @@ class FillAverageBedDaysMetric extends Command
$sampleQuery->where('rf_department_id', $departmentId);
}
$sample = $sampleQuery->get()->map(function($report) {
$sample = $sampleQuery->get()->map(function ($report) {
$metric = $report->metrikaResults
->where('rf_metrika_item_id', 18)
->first();
return [
'report_id' => $report->report_id,
'department' => $report->rf_department_id,
@@ -189,7 +192,7 @@ class FillAverageBedDaysMetric extends Command
->where('rf_metrika_item_id', 18)
->first();
if ($existingMetric && !$force) {
if ($existingMetric && ! $force) {
return 'skipped';
}
@@ -207,6 +210,7 @@ class FillAverageBedDaysMetric extends Command
],
['value' => 0]
);
return 'no_snapshots';
}

View File

@@ -38,11 +38,13 @@ class FillReportsFromDate extends Command
$end = Carbon::createFromFormat('Y-m-d', $endDate, 'Asia/Yakutsk')->startOfDay();
} catch (\Throwable) {
$this->error('Неверный формат даты. Используйте YYYY-MM-DD.');
return 1;
}
if ($start->gt($end)) {
$this->error('Дата начала больше даты окончания.');
return 1;
}
@@ -55,6 +57,7 @@ class FillReportsFromDate extends Command
if ($departments->isEmpty()) {
$this->error('Отделения не найдены');
return 1;
}
@@ -66,8 +69,9 @@ class FillReportsFromDate extends Command
$user = $this->resolveResponsibleUser($department, $userId);
if (!$user) {
if (! $user) {
$this->warn("В отделении {$department->name_short} нет подходящего пользователя для автозаполнения");
continue;
}

View File

@@ -1,11 +1,12 @@
<?php
// app/Console/Commands/RecalculatePreoperativeMetric.php
namespace App\Console\Commands;
use App\Models\Report;
use App\Models\MedicalHistorySnapshot;
use App\Models\MetrikaResult;
use App\Models\Report;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
@@ -66,19 +67,21 @@ class RecalculatePreoperativeMetric extends Command
}
$force = $this->option('force');
$chunkSize = (int)$this->option('chunk');
$chunkSize = (int) $this->option('chunk');
$totalReports = $query->count();
if ($totalReports === 0) {
$this->warn('❌ Отчеты не найдены');
return 0;
}
$this->info("📊 Найдено отчетов: {$totalReports}");
if ($totalReports > 1000 && !$this->confirm("⚠️ Обработка {$totalReports} отчетов может занять время. Продолжить?")) {
if ($totalReports > 1000 && ! $this->confirm("⚠️ Обработка {$totalReports} отчетов может занять время. Продолжить?")) {
$this->info('❌ Операция отменена');
return 0;
}
@@ -104,7 +107,7 @@ class RecalculatePreoperativeMetric extends Command
} catch (\Exception $e) {
$errors++;
Log::error("Ошибка обработки отчета {$report->report_id}: " . $e->getMessage());
Log::error("Ошибка обработки отчета {$report->report_id}: ".$e->getMessage());
}
$bar->advance();
@@ -131,16 +134,17 @@ class RecalculatePreoperativeMetric extends Command
$this->newLine();
$this->info('📋 Примеры обновленных отчетов:');
$samples = Report::whereHas('metrikaResults', function($q) {
$samples = Report::whereHas('metrikaResults', function ($q) {
$q->where('rf_metrika_item_id', 21);
})
->orderBy('report_id', 'desc')
->limit(5)
->get()
->map(function($report) {
->map(function ($report) {
$metric = $report->metrikaResults
->where('rf_metrika_item_id', 21)
->first();
return [
'report_id' => $report->report_id,
'department' => $report->rf_department_id,
@@ -168,7 +172,7 @@ class RecalculatePreoperativeMetric extends Command
->where('rf_metrika_item_id', 21)
->first();
if ($existing && !$force) {
if ($existing && ! $force) {
return 'skipped';
}
@@ -186,6 +190,7 @@ class RecalculatePreoperativeMetric extends Command
],
['value' => 0]
);
return 'no_patients';
}
@@ -212,6 +217,7 @@ class RecalculatePreoperativeMetric extends Command
],
['value' => 0]
);
return 'no_patients';
}