Подготовка к переводу на MV

This commit is contained in:
brusnitsyn
2026-05-04 22:24:11 +09:00
parent 82673f385b
commit 51a4b5b9de
3 changed files with 44 additions and 0 deletions

View File

@@ -22,6 +22,11 @@ class MetrikaResult extends Model
return $this->belongsTo(Report::class, 'rf_report_id', 'report_id'); return $this->belongsTo(Report::class, 'rf_report_id', 'report_id');
} }
public function metrikaItem()
{
return $this->belongsTo(MetrikaItem::class, 'rf_metrika_item_id', 'metrika_item_id');
}
// public function group(): \Illuminate\Database\Eloquent\Relations\BelongsTo // public function group(): \Illuminate\Database\Eloquent\Relations\BelongsTo
// { // {
// return $this->belongsTo(MetrikaGroup::class, 'rf_metrika_group_id', 'metrika_group_id'); // return $this->belongsTo(MetrikaGroup::class, 'rf_metrika_group_id', 'metrika_group_id');

View File

@@ -2,6 +2,7 @@
namespace App\Services; namespace App\Services;
use App\Models\Report;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@@ -73,4 +74,21 @@ class MetrikaService
return array_fill_keys($departmentIds, 0); return array_fill_keys($departmentIds, 0);
} }
} }
public function getMetricsForReport(Report $report): array
{
$metrics = [];
foreach ($report->metrikaResults as $metrikaResult) {
$metrikaResult->load('metrikaItem');
$metrics[] = [
'metrika_id' => $metrikaResult->rf_metrika_item_id,
'value_id' => $metrikaResult->metrika_result_id,
'name' => $metrikaResult->metrikaItem->name,
'value' => $metrikaResult->value,
];
}
return $metrics;
}
} }

View File

@@ -36,6 +36,7 @@ class ReportService
?ReportMetadataReadService $reportMetadataReadService = null, ?ReportMetadataReadService $reportMetadataReadService = null,
?ReportSaveOrchestrator $reportSaveOrchestrator = null, ?ReportSaveOrchestrator $reportSaveOrchestrator = null,
?ReportRuntimeService $reportRuntimeService = null, ?ReportRuntimeService $reportRuntimeService = null,
protected MetrikaService $metrikaService
) { ) {
$this->autoFillReportPayloadBuilder = $autoFillReportPayloadBuilder ?? app(AutoFillReportPayloadBuilder::class); $this->autoFillReportPayloadBuilder = $autoFillReportPayloadBuilder ?? app(AutoFillReportPayloadBuilder::class);
$this->reportPatientsReadService = $reportPatientsReadService ?? app(ReportPatientsReadService::class); $this->reportPatientsReadService = $reportPatientsReadService ?? app(ReportPatientsReadService::class);
@@ -289,4 +290,24 @@ class ReportService
{ {
return $this->reportMetadataReadService->getRecipientPlanOfYear($department, $dateRange); return $this->reportMetadataReadService->getRecipientPlanOfYear($department, $dateRange);
} }
public function getReportInfo(User $user, Department $department, DateRange $dateRange)
{
$report = $this->resolveReport($department->department_id, $dateRange);
$metrics = $this->metrikaService->getMetricsForReport($report);
}
private function resolveReport(int $departmentId, DateRange $dateRange)
{
$query = Report::query()
->where('rf_department_id', $departmentId)
->exactPeriod($dateRange->startSql(), $dateRange->endSql())
->orderByDesc('report_id');
if ($dateRange->isOneDay) {
return $query->first();
}
return $query->onlySubmitted()->first();
}
} }