Files
onboard/app/Infrastructure/Database/Repositories/ReportDutyRepository.php
2026-07-31 17:19:03 +09:00

77 lines
2.6 KiB
PHP

<?php
namespace App\Infrastructure\Database\Repositories;
use App\Domain\ReportDuty\Contracts\ReportDutyRepositoryInterface;
use App\Domain\ReportDuty\DTO\CreateReportDutyDto;
use Illuminate\Support\Carbon;
use App\Domain\ReportDuty\Models\ReportDuty;
class ReportDutyRepository implements ReportDutyRepositoryInterface
{
public function findOrCreate(CreateReportDutyDto $dto): ?ReportDuty
{
$attributes = [
'report_date' => $dto->reportDate,
'period_start' => $dto->periodStart,
'period_end' => $dto->periodEnd,
'rf_department_id' => $dto->rfDepartmentId,
];
$data = [
'report_date' => $dto->reportDate,
'sent_at' => Carbon::now()->format('Y-m-d H:i:s'),
'period_type' => $dto->periodType,
'period_start' => $dto->periodStart,
'period_end' => $dto->periodEnd,
'status_id' => $dto->statusId,
'rf_lpudoctor_id' => $dto->rfLpuDoctorId,
'rf_department_id' => $dto->rfDepartmentId,
'rf_user_id' => $dto->rfUserId,
];
// Проверяем существование
$exists = ReportDuty::where($attributes)->exists();
if ($exists) {
// Если существует, обновляем только некоторые поля
$updateData = array_diff_key($data, array_flip(['rf_lpudoctor_id', 'rf_user_id']));
$report = ReportDuty::updateOrCreate($attributes, $updateData);
} else {
$report = ReportDuty::create($data);
}
return $report;
}
public function save(\App\Domain\ReportDuty\Models\ReportDuty $reportDuty): ?\App\Domain\ReportDuty\Models\ReportDuty
{
// TODO: Implement save() method.
}
public function update(\App\Domain\ReportDuty\Models\ReportDuty $reportDuty): ?\App\Domain\ReportDuty\Models\ReportDuty
{
// TODO: Implement update() method.
}
public function findByPeriod(string $startAt, string $endAt): ?\App\Domain\ReportDuty\Models\ReportDuty
{
// TODO: Implement findByPeriod() method.
}
public function findByDepartment(int $departmentId): ?\App\Domain\ReportDuty\Models\ReportDuty
{
// TODO: Implement findByDepartment() method.
}
public function findByUser(int $userId): ?\App\Domain\ReportDuty\Models\ReportDuty
{
// TODO: Implement findByUser() method.
}
public function findById(int $id): ?\App\Domain\ReportDuty\Models\ReportDuty
{
// TODO: Implement findById() method.
}
}