From 82c072d72e3ab961347feb0d15f56b8510501c76 Mon Sep 17 00:00:00 2001 From: hskwon Date: Thu, 27 Nov 2025 09:09:05 +0900 Subject: [PATCH] =?UTF-8?q?fix(mng):=20=EC=95=84=EC=B9=B4=EC=9D=B4?= =?UTF-8?q?=EB=B8=8C=20=EB=A0=88=EC=BD=94=EB=93=9C=20batch=5Fid=20NULL=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존 데이터(batch_id NULL)는 legacy_ 접두사로 가상 batch_id 생성 - legacy 데이터 조회 시 id 기반으로 단일 레코드 조회 - batch_description NULL인 경우 레코드 타입과 원본 ID로 자동 생성 --- app/Services/ArchivedRecordService.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/Services/ArchivedRecordService.php b/app/Services/ArchivedRecordService.php index 79f115a0..6f3cb1a7 100644 --- a/app/Services/ArchivedRecordService.php +++ b/app/Services/ArchivedRecordService.php @@ -11,21 +11,23 @@ class ArchivedRecordService { /** * 아카이브 레코드 목록 조회 (batch_id로 그룹핑, 페이지네이션) + * batch_id가 NULL인 기존 데이터는 각각 개별 batch로 취급 */ public function getArchivedRecordsBatched(array $filters = [], int $perPage = 15): LengthAwarePaginator { // batch_id별로 그룹핑하여 첫 번째 레코드만 조회 + // batch_id가 NULL인 경우 id를 기반으로 가상 batch_id 생성 $query = ArchivedRecord::query() ->select([ - 'batch_id', - 'batch_description', + DB::raw("COALESCE(batch_id, CONCAT('legacy_', id)) as batch_id"), + DB::raw("COALESCE(batch_description, CONCAT(record_type, ' 삭제 (ID: ', original_id, ')')) as batch_description"), DB::raw('MIN(id) as id'), DB::raw('GROUP_CONCAT(DISTINCT record_type) as record_types'), DB::raw('COUNT(*) as record_count'), DB::raw('MIN(deleted_by) as deleted_by'), DB::raw('MIN(deleted_at) as deleted_at'), ]) - ->groupBy('batch_id', 'batch_description'); + ->groupBy(DB::raw("COALESCE(batch_id, CONCAT('legacy_', id))"), DB::raw("COALESCE(batch_description, CONCAT(record_type, ' 삭제 (ID: ', original_id, ')'))")); // 레코드 타입 필터 if (! empty($filters['record_type'])) { @@ -53,9 +55,19 @@ public function getArchivedRecordsBatched(array $filters = [], int $perPage = 15 /** * 특정 batch의 모든 레코드 조회 + * legacy_ 접두사가 붙은 경우 단일 레코드 ID로 조회 */ public function getRecordsByBatchId(string $batchId): Collection { + // legacy_ 접두사가 붙은 경우 (기존 데이터) + if (str_starts_with($batchId, 'legacy_')) { + $id = (int) str_replace('legacy_', '', $batchId); + + return ArchivedRecord::with(['deletedByUser', 'relations']) + ->where('id', $id) + ->get(); + } + return ArchivedRecord::with(['deletedByUser', 'relations']) ->where('batch_id', $batchId) ->orderBy('id')