feat: [items] 품목 목록 API에 공정 배정 정보(assigned_processes) 응답 추가
- exclude_process_id 파라미터 시 품목 제외 대신 배정 공정 정보 포함하여 응답 - 프론트에서 다른 공정 배정 품목을 disabled 처리하도록 변경 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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;
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user