2025-11-26 22:23:37 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Services\ArchivedRecordService;
|
2025-12-01 00:43:58 +09:00
|
|
|
use App\Services\RestoreService;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
2025-11-26 22:23:37 +09:00
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
|
|
class ArchivedRecordController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
2025-12-01 00:43:58 +09:00
|
|
|
private readonly ArchivedRecordService $archivedRecordService,
|
|
|
|
|
private readonly RestoreService $restoreService
|
2025-11-26 22:23:37 +09:00
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 아카이브 레코드 목록 (Blade 화면만)
|
|
|
|
|
*/
|
|
|
|
|
public function index(): View
|
|
|
|
|
{
|
|
|
|
|
$deletedByUsers = $this->archivedRecordService->getDeletedByUsers();
|
|
|
|
|
|
|
|
|
|
return view('archived-records.index', compact('deletedByUsers'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-11-26 23:16:39 +09:00
|
|
|
* 아카이브 레코드 상세 보기 (batch 기준)
|
2025-11-26 22:23:37 +09:00
|
|
|
*/
|
2025-11-26 23:16:39 +09:00
|
|
|
public function show(string $batchId): View
|
2025-11-26 22:23:37 +09:00
|
|
|
{
|
2025-11-26 23:16:39 +09:00
|
|
|
$records = $this->archivedRecordService->getRecordsByBatchId($batchId);
|
2025-11-26 22:23:37 +09:00
|
|
|
|
2025-11-26 23:16:39 +09:00
|
|
|
if ($records->isEmpty()) {
|
2025-11-26 22:23:37 +09:00
|
|
|
abort(404, '아카이브 레코드를 찾을 수 없습니다.');
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-26 23:16:39 +09:00
|
|
|
// 첫 번째 레코드에서 batch 정보 추출
|
|
|
|
|
$batchInfo = [
|
|
|
|
|
'batch_id' => $batchId,
|
|
|
|
|
'batch_description' => $records->first()->batch_description,
|
|
|
|
|
'deleted_by' => $records->first()->deletedByUser?->name ?? '-',
|
|
|
|
|
'deleted_at' => $records->first()->deleted_at,
|
|
|
|
|
'record_count' => $records->count(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return view('archived-records.show', compact('records', 'batchInfo'));
|
2025-11-26 22:23:37 +09:00
|
|
|
}
|
2025-12-01 00:43:58 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 배치 복원 가능 여부 확인
|
|
|
|
|
*/
|
|
|
|
|
public function checkRestore(string $batchId): View
|
|
|
|
|
{
|
|
|
|
|
$records = $this->archivedRecordService->getRecordsByBatchId($batchId);
|
|
|
|
|
|
|
|
|
|
if ($records->isEmpty()) {
|
|
|
|
|
abort(404, '아카이브 레코드를 찾을 수 없습니다.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 복원 가능 여부 확인
|
|
|
|
|
$restoreCheck = $this->restoreService->canRestoreBatch($batchId);
|
|
|
|
|
|
|
|
|
|
// batch 정보 추출
|
|
|
|
|
$batchInfo = [
|
|
|
|
|
'batch_id' => $batchId,
|
|
|
|
|
'batch_description' => $records->first()->batch_description,
|
|
|
|
|
'deleted_by' => $records->first()->deletedByUser?->name ?? '-',
|
|
|
|
|
'deleted_at' => $records->first()->deleted_at,
|
|
|
|
|
'record_count' => $records->count(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return view('archived-records.restore-check', compact('records', 'batchInfo', 'restoreCheck'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 배치 복원 실행
|
|
|
|
|
*/
|
|
|
|
|
public function restore(string $batchId): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
// 슈퍼관리자 권한 확인
|
|
|
|
|
if (! auth()->user()?->is_super_admin) {
|
|
|
|
|
return redirect()
|
|
|
|
|
->route('archived-records.show', $batchId)
|
|
|
|
|
->with('error', '슈퍼관리자만 복원할 수 있습니다.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 복원 가능 여부 확인
|
|
|
|
|
$restoreCheck = $this->restoreService->canRestoreBatch($batchId);
|
|
|
|
|
|
|
|
|
|
if (! $restoreCheck['can_restore']) {
|
|
|
|
|
return redirect()
|
|
|
|
|
->route('archived-records.show', $batchId)
|
|
|
|
|
->with('error', '복원할 수 없습니다: '.implode(', ', $restoreCheck['issues']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$restoredModels = $this->restoreService->restoreBatch($batchId);
|
|
|
|
|
|
|
|
|
|
return redirect()
|
|
|
|
|
->route('archived-records.index')
|
|
|
|
|
->with('success', "복원 완료: {$restoredModels->count()}개 레코드가 복원되었습니다.");
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return redirect()
|
|
|
|
|
->route('archived-records.show', $batchId)
|
|
|
|
|
->with('error', '복원 중 오류 발생: '.$e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-26 22:23:37 +09:00
|
|
|
}
|