feat(mng): 아카이브 레코드 batch 그룹핑 UI 구현

- ArchivedRecordService: batch_id 기준 그룹핑 쿼리 추가
- Controller: batchId 파라미터로 상세 조회 변경
- 목록: 작업 설명, 레코드 타입, 레코드 수 표시
- 상세: batch 내 모든 레코드를 카드 형태로 표시
- 한번의 삭제 작업이 하나의 행으로 표시됨
This commit is contained in:
2025-11-26 23:16:39 +09:00
parent d0b843057e
commit d45ccfb325
8 changed files with 192 additions and 146 deletions

View File

@@ -4,48 +4,43 @@
use App\Models\Archives\ArchivedRecord;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
class ArchivedRecordService
{
/**
* 아카이브 레코드 목록 조회 (페이지네이션)
* 아카이브 레코드 목록 조회 (batch_id로 그룹핑, 페이지네이션)
*/
public function getArchivedRecords(array $filters = [], int $perPage = 15): LengthAwarePaginator
public function getArchivedRecordsBatched(array $filters = [], int $perPage = 15): LengthAwarePaginator
{
// batch_id별로 그룹핑하여 첫 번째 레코드만 조회
$query = ArchivedRecord::query()
->with(['deletedByUser', 'relations'])
->withCount('relations');
->select([
'batch_id',
'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');
// 레코드 타입 필터
if (! empty($filters['record_type'])) {
$query->where('record_type', $filters['record_type']);
$query->having('record_types', 'like', "%{$filters['record_type']}%");
}
// 삭제자 필터
if (! empty($filters['deleted_by'])) {
$query->where('deleted_by', $filters['deleted_by']);
}
// 노트 유무 필터
if (isset($filters['has_notes'])) {
if ($filters['has_notes'] === 'yes' || $filters['has_notes'] === '1') {
$query->whereNotNull('notes')->where('notes', '!=', '');
} elseif ($filters['has_notes'] === 'no' || $filters['has_notes'] === '0') {
$query->where(function ($q) {
$q->whereNull('notes')->orWhere('notes', '');
});
}
$query->having('deleted_by', $filters['deleted_by']);
}
// 검색
if (! empty($filters['search'])) {
$search = $filters['search'];
$query->where(function ($q) use ($search) {
$q->where('record_type', 'like', "%{$search}%")
->orWhere('notes', 'like', "%{$search}%")
->orWhereRaw("JSON_EXTRACT(main_data, '$.name') LIKE ?", ["%{$search}%"])
->orWhereRaw("JSON_EXTRACT(main_data, '$.title') LIKE ?", ["%{$search}%"]);
});
$query->where('batch_description', 'like', "%{$search}%");
}
// 정렬 (기본: 삭제일시 내림차순)
@@ -56,6 +51,17 @@ public function getArchivedRecords(array $filters = [], int $perPage = 15): Leng
return $query->paginate($perPage);
}
/**
* 특정 batch의 모든 레코드 조회
*/
public function getRecordsByBatchId(string $batchId): Collection
{
return ArchivedRecord::with(['deletedByUser', 'relations'])
->where('batch_id', $batchId)
->orderBy('id')
->get();
}
/**
* 특정 아카이브 레코드 조회
*/
@@ -65,6 +71,17 @@ public function getArchivedRecordById(int $id): ?ArchivedRecord
->find($id);
}
/**
* batch_id로 첫 번째 레코드 조회 (상세 페이지 진입용)
*/
public function getFirstRecordByBatchId(string $batchId): ?ArchivedRecord
{
return ArchivedRecord::with(['deletedByUser', 'relations'])
->where('batch_id', $batchId)
->orderBy('id')
->first();
}
/**
* 삭제자 목록 조회 (필터용)
*/
@@ -87,12 +104,10 @@ public function getDeletedByUsers(): array
public function getStats(): array
{
return [
'total' => ArchivedRecord::count(),
'total_batches' => ArchivedRecord::distinct('batch_id')->count('batch_id'),
'total_records' => ArchivedRecord::count(),
'tenants' => ArchivedRecord::tenant()->count(),
'users' => ArchivedRecord::user()->count(),
'with_notes' => ArchivedRecord::whereNotNull('notes')
->where('notes', '!=', '')
->count(),
];
}
}