Перевод на доменную архитектуру

This commit is contained in:
brusnitsyn
2026-04-26 23:37:50 +09:00
parent 75ca01ffd8
commit f107ebd167
70 changed files with 4656 additions and 2070 deletions

View File

@@ -0,0 +1,117 @@
<?php
namespace App\Application\Reports\DTO;
use App\Domain\Reports\Models\ReportContext;
use App\Domain\Reports\Models\ReportSnapshot;
use DateTimeImmutable;
final readonly class GenerateReportInput
{
/**
* @param array<int|string, int|float|string|null> $metrics
* @param array<int, array<string, mixed>> $observationPatients
* @param array<int, array<string, mixed>> $unwantedEvents
* @param array<string, mixed>|null $rawPayload
*/
public function __construct(
public int $departmentId,
public int $userId,
public ?int $actorUserId,
public DateTimeImmutable $periodStart,
public DateTimeImmutable $periodEnd,
public array $metrics = [],
public array $observationPatients = [],
public array $unwantedEvents = [],
public ?int $reportId = null,
public string $status = 'draft',
public string $reportType = 'daily',
public bool $autoFill = false,
public ?array $rawPayload = null,
public ?int $persistedReportId = null,
public ?DateTimeImmutable $createdAt = null,
public ?DateTimeImmutable $sentAt = null,
) {}
public function toContext(): ReportContext
{
return new ReportContext(
departmentId: $this->departmentId,
userId: $this->userId,
actorUserId: $this->actorUserId,
periodStart: $this->periodStart,
periodEnd: $this->periodEnd,
reportType: $this->reportType,
metadata: [
'auto_fill' => $this->autoFill,
],
);
}
public function toSnapshot(): ReportSnapshot
{
return new ReportSnapshot(
departmentId: $this->departmentId,
userId: $this->userId,
actorUserId: $this->actorUserId,
periodStart: $this->periodStart,
periodEnd: $this->periodEnd,
status: $this->status,
autoFill: $this->autoFill,
metrics: $this->metrics,
observationPatients: $this->observationPatients,
unwantedEvents: $this->unwantedEvents,
reportId: $this->reportId,
createdAt: $this->createdAt,
sentAt: $this->sentAt,
reportType: $this->reportType,
);
}
/**
* @param array<string, mixed> $payload
*/
public function withRawPayload(array $payload): self
{
return new self(
departmentId: $this->departmentId,
userId: $this->userId,
actorUserId: $this->actorUserId,
periodStart: $this->periodStart,
periodEnd: $this->periodEnd,
metrics: $this->metrics,
observationPatients: $this->observationPatients,
unwantedEvents: $this->unwantedEvents,
reportId: $this->reportId,
status: $this->status,
reportType: $this->reportType,
autoFill: $this->autoFill,
rawPayload: $payload,
persistedReportId: $this->persistedReportId,
createdAt: $this->createdAt,
sentAt: $this->sentAt,
);
}
public function withPersistedReportId(int $reportId): self
{
return new self(
departmentId: $this->departmentId,
userId: $this->userId,
actorUserId: $this->actorUserId,
periodStart: $this->periodStart,
periodEnd: $this->periodEnd,
metrics: $this->metrics,
observationPatients: $this->observationPatients,
unwantedEvents: $this->unwantedEvents,
reportId: $this->reportId,
status: $this->status,
reportType: $this->reportType,
autoFill: $this->autoFill,
rawPayload: $this->rawPayload,
persistedReportId: $reportId,
createdAt: $this->createdAt,
sentAt: $this->sentAt,
);
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Application\Reports\DTO;
final readonly class GenerateReportResult
{
public function __construct(
public int $reportId,
public string $path,
public bool $usedNewArchitecture,
public ?ReportComparisonResult $comparison = null,
) {}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Application\Reports\DTO;
final readonly class ReportComparisonResult
{
/**
* @param array<string, mixed> $diff
*/
public function __construct(
public string $reportType,
public string $path,
public string $status,
public array $diff,
public int $departmentId,
public int $userId,
public string $periodStart,
public string $periodEnd,
public ?int $reportId,
public float $durationMs,
) {}
}