Files
sam-docs/changes/20260321_process_parent_id_tree.md

87 lines
3.7 KiB
Markdown
Raw Normal View History

# 공정관리 parent_id 트리 구조 도입
**날짜:** 2026-03-21
**작업자:** Claude Code (R&D실)
## 변경 개요
공정관리에 `parent_id` 기반 2depth 트리 구조를 도입했다. 기존 `options.process_group` 임시 방식을 제거하고, 부모-자식 관계로 공정을 계층 구조화했다.
## 배경
절곡 관련 공정이 5개(P-003~P-007)로 분리되면서 작업자 화면에 탭이 5개로 나뉘어 혼란이 발생했다. 공정관리 자체에서 그룹-하위 구조를 설계하는 것이 올바른 접근이다.
## 목표 구조
```
슬랫 (P-001) ← 단독 루트
스크린 (P-002) ← 단독 루트
절곡 (P-003) ← 부모 (자체 작업도 가능)
├── 재공품-가이드레일 (P-004) ← 자식
├── 재공품-케이스 (P-005)
├── 재공품-하단마감재 (P-006)
└── 재공품-기타 (P-007)
```
## 수정된 파일
### API
| 파일 | 변경 내용 |
|------|----------|
| `database/migrations/2026_03_21_152057_*.php` | `parent_id` 컬럼 + FK(onDelete: set null) + 인덱스 |
| `app/Models/Process.php` | `parent()`, `children()`, `scopeRoots()` 관계 추가 |
| `app/Services/ProcessService.php` | eager load에 parent/children 추가, store/update에 2depth 검증 |
| `app/Http/Requests/V1/Process/StoreProcessRequest.php` | `parent_id` 검증 규칙 |
| `app/Http/Requests/V1/Process/UpdateProcessRequest.php` | `parent_id` 검증 + 순환 참조 방지 |
### React
| 파일 | 변경 내용 |
|------|----------|
| `src/types/process.ts` | `parentId`, `children` 타입 추가, `processGroup` 제거 |
| `src/components/process-management/actions.ts` | API 변환에 parent_id/children 매핑, `getRootProcessOptions` 추가 |
| `src/components/process-management/ProcessListClient.tsx` | 트리 형태 목록 (접기/펼치기, 자식 들여쓰기, 자식 수 배지) |
| `src/components/process-management/ProcessForm.tsx` | "부모 공정" Select 필드 (루트 공정 드롭다운) |
| `src/components/process-management/ProcessDetail.tsx` | 부모 공정 링크 표시 + 하위 공정 섹션 |
| `src/components/production/WorkerScreen/index.tsx` | `groupedTabs`를 parent_id 기반으로 전환 |
### MNG
| 파일 | 변경 내용 |
|------|----------|
| `app/Models/Process.php` | `fillable``parent_id` 추가 |
## 작업지시 자식 공정 자동 연결
### 배경
재공품(WIP) 작업지시의 `process_id`가 부모 공정(P-003)을 참조하여 중간검사 시 자식 공정별 개별 양식이 아닌 절곡 전체 양식이 로드되는 문제가 있었다.
### 수정 내용
| 파일 | 변경 내용 |
|------|----------|
| `api/app/Services/WorkOrderService.php` | `store()`: 부모 공정 → 아이템 기반 자식 공정 자동 감지 |
| `api/app/Services/WorkOrderService.php` | `index()`: 부모 공정 필터 시 자식 공정 WO도 포함 |
### 동작 원리
1. 작업지시 생성 시 `process_id`가 자식이 있는 부모 공정이면
2. 아이템의 `item_id``process_items` 테이블과 대조
3. 가장 많이 매칭되는 자식 공정의 `process_id`로 자동 교체
4. 매칭 실패 시 원래 부모 `process_id` 유지 (하위 호환)
---
## 검증 규칙
- **2depth 제한**: 부모의 `parent_id`가 null인지 확인 (손자 공정 생성 불가)
- **순환 참조 방지**: 자기 자신 또는 자기 자식을 부모로 설정 불가
- **FK onDelete: set null**: 부모 삭제 시 자식이 루트로 승격 (작업지시 참조 보호)
## 관련 문서
- [bending/README.md](../features/bending/README.md) — 재공품 공정 구조
- [mng-document-template.md](../features/documents/mng-document-template.md) — 공정별 문서양식