From f70ec4155ee91282c9de3f42d0ba04ba0e77a664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Wed, 18 Mar 2026 23:15:54 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20[items]=20=ED=92=88=EB=AA=A9=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20API=EC=97=90=20=EA=B3=B5=EC=A0=95=20?= =?UTF-8?q?=EB=B0=B0=EC=A0=95=20=EC=A0=95=EB=B3=B4(assigned=5Fprocesses)?= =?UTF-8?q?=20=EC=9D=91=EB=8B=B5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - exclude_process_id 파라미터 시 품목 제외 대신 배정 공정 정보 포함하여 응답 - 프론트에서 다른 공정 배정 품목을 disabled 처리하도록 변경 Co-Authored-By: Claude Opus 4.6 (1M context) --- app/Services/ItemService.php | 39 ++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/app/Services/ItemService.php b/app/Services/ItemService.php index 28dfd1de..1784ce7b 100644 --- a/app/Services/ItemService.php +++ b/app/Services/ItemService.php @@ -436,20 +436,9 @@ public function index(array $params): LengthAwarePaginator } } - // 다른 공정에 배정된 품목 제외 (공정별 품목 선택 시 중복 방지) - // exclude_process_id가 주어지면: 해당 공정에 이미 있는 품목은 허용, 다른 공정 품목은 제외 - if ($excludeProcessId !== null && $excludeProcessId !== '') { - $excludeProcessId = (int) $excludeProcessId; - // 다른 공정에 배정된 품목 ID 목록 조회 - $assignedToOtherProcesses = ProcessItem::where('process_id', '!=', $excludeProcessId) - ->where('is_active', true) - ->pluck('item_id') - ->toArray(); - - if (! empty($assignedToOtherProcesses)) { - $query->whereNotIn('id', $assignedToOtherProcesses); - } - } + // 공정 배정 정보 조회용 플래그 + // exclude_process_id가 주어지면: 제외하지 않고, 각 품목의 공정 배정 정보를 응답에 포함 + $withProcessInfo = ($excludeProcessId !== null && $excludeProcessId !== ''); // common_codes에서 item_type 한글명 조회 (서브쿼리로 컬럼 충돌 방지) $tableName = $query->getModel()->getTable(); @@ -468,9 +457,24 @@ public function index(array $params): LengthAwarePaginator $itemIds = $paginator->pluck('id')->toArray(); $itemsWithInspection = $this->getItemsWithInspectionTemplate($itemIds); + // 공정 배정 정보 조회 (exclude_process_id 파라미터가 있을 때만) + $processAssignments = []; + if ($withProcessInfo && ! empty($itemIds)) { + $processAssignments = ProcessItem::whereIn('process_items.item_id', $itemIds) + ->where('process_items.is_active', true) + ->join('processes', 'process_items.process_id', '=', 'processes.id') + ->get(['process_items.item_id', 'processes.id as process_id', 'processes.process_name']) + ->groupBy('item_id') + ->map(fn ($items) => $items->map(fn ($pi) => [ + 'process_id' => $pi->process_id, + 'process_name' => $pi->process_name, + ])->values()->toArray()) + ->toArray(); + } + // 날짜 형식 변환, files 그룹화, options 펼침, code → item_code $paginator->setCollection( - $paginator->getCollection()->transform(function ($item) use ($itemsWithInspection) { + $paginator->getCollection()->transform(function ($item) use ($itemsWithInspection, $withProcessInfo, $processAssignments) { $arr = $item->toArray(); $arr['created_at'] = $item->created_at ? $item->created_at->format('Y-m-d') @@ -494,6 +498,11 @@ public function index(array $params): LengthAwarePaginator // has_inspection_template 필드 추가 (수입검사 양식 연결 여부) $arr['has_inspection_template'] = in_array($arr['id'], $itemsWithInspection); + // 공정 배정 정보 추가 + if ($withProcessInfo) { + $arr['assigned_processes'] = $processAssignments[$arr['id']] ?? []; + } + return $arr; }) );