docs: items 테이블 통합 완료 내용 반영

- rules/item-policy.md: source_table 개념 제거, API 완료 상태 업데이트
- front/item-master-guide.md: source_table: 'items' 반영
- specs/database-schema.md: items 통합 테이블 구조 추가
This commit is contained in:
2025-12-16 10:01:30 +09:00
parent 3d6d7b67ea
commit e863d3762a
3 changed files with 108 additions and 71 deletions

View File

@@ -174,13 +174,15 @@ interface ItemPage {
group_id: number; group_id: number;
page_name: string; page_name: string;
item_type: 'FG' | 'PT' | 'SM' | 'RM' | 'CS'; item_type: 'FG' | 'PT' | 'SM' | 'RM' | 'CS';
source_table: 'products' | 'materials'; source_table: 'items'; // 통합됨 (2025-12-15)
absolute_path?: string; absolute_path?: string;
is_active: boolean; is_active: boolean;
sections: ItemSection[]; // init 응답에 포함 sections: ItemSection[]; // init 응답에 포함
} }
``` ```
> **통합 완료**: 기존 `products`/`materials` 분리 구조가 `items` 단일 테이블로 통합되었습니다.
### 3.2 ItemSection ### 3.2 ItemSection
```typescript ```typescript
@@ -333,6 +335,7 @@ init API 응답에 `is_locked` 필드가 포함됩니다.
| 날짜 | 변경 내용 | | 날짜 | 변경 내용 |
|------|----------| |------|----------|
| 2025-12-16 | items 테이블 통합 반영 (source_table: 'items') |
| 2025-12-09 | 시스템 기반 문서 전면 재작성 | | 2025-12-09 | 시스템 기반 문서 전면 재작성 |
| 2025-11-27 | 잠금(Lock) 기능 추가 | | 2025-11-27 | 잠금(Lock) 기능 추가 |
| 2025-11-26 | 독립 엔티티 아키텍처 적용 | | 2025-11-26 | 독립 엔티티 아키텍처 적용 |

View File

@@ -2,7 +2,7 @@
> 품목 관리 시스템의 핵심 비즈니스 규칙 정의 > 품목 관리 시스템의 핵심 비즈니스 규칙 정의
> >
> **최종 업데이트**: 2025-12-09 > **최종 업데이트**: 2025-12-16
--- ---
@@ -10,41 +10,50 @@
### 1.1 품목 유형 코드 정의 ### 1.1 품목 유형 코드 정의
| 코드 | 한글명 | 영문명 | source_table | 설명 | | 코드 | 한글명 | 영문명 | 설명 |
|------|--------|--------|--------------|------| |------|--------|--------|------|
| `FG` | 완제품 | Finished Goods | products | 판매 가능한 최종 제품 | | `FG` | 완제품 | Finished Goods | 판매 가능한 최종 제품 |
| `PT` | 부품 | Parts | products | 제품 구성에 사용되는 부품 | | `PT` | 부품 | Parts | 제품 구성에 사용되는 부품 |
| `SM` | 부자재 | Sub-Materials | materials | 생산에 사용되는 보조 자재 | | `SM` | 부자재 | Sub-Materials | 생산에 사용되는 보조 자재 |
| `RM` | 원자재 | Raw Materials | materials | 생산의 주요 원료 | | `RM` | 원자재 | Raw Materials | 생산의 주요 원료 |
| `CS` | 소모품 | Consumables | materials | 일회성 소모 자재 | | `CS` | 소모품 | Consumables | 일회성 소모 자재 |
> **통합 완료 (2025-12-15)**: 기존 products/materials 테이블이 **items 테이블로 통합**되었습니다.
### 1.2 저장 위치 ### 1.2 저장 위치
``` ```
common_codes 테이블 items 테이블 (통합)
├─ code_group = 'item_type' ├─ item_type = 'FG' | 'PT' | 'SM' | 'RM' | 'CS'
├─ code = 'FG' | 'PT' | 'SM' | 'RM' | 'CS' ├─ code, name, unit, category_id
attributes.source_table = 'products' | 'materials' bom (JSON)
└─ is_active
``` ```
### 1.3 source_table 매핑 규칙 ### 1.3 관련 테이블 구조
``` ```
item_type → source_table 자동 매핑: items (통합 테이블)
├─ id, tenant_id, item_type
├─ code, name, unit, category_id
├─ bom (JSON)
├─ is_active
└─ timestamps + soft deletes
FG (완제품) ─┐ item_details (확장 필드 - 1:1)
PT (부품) ─┴─→ products 테이블 ├─ is_sellable, is_purchasable, is_producible
├─ safety_stock, lead_time
└─ is_inspection 등
SM (부자재) ─┐ item_attributes (동적 속성 - 1:1)
RM (원자재) ─┼─→ materials 테이블 ├─ attributes (JSON)
CS (소모품) ─┘ └─ options (JSON)
``` ```
### 1.4 테넌트별 확장 ### 1.4 테넌트별 확장
- 품목 유형은 테넌트별로 커스터마이징 가능 - 품목 유형은 테넌트별로 커스터마이징 가능
- `common_codes.attributes` JSON 필드 활용 (스키마 변경 없음) - `common_codes.attributes` JSON 필드 활용 (스키마 변경 없음)
- 새 품목 유형 추가 시 source_table 매핑 필수
--- ---
@@ -55,54 +64,43 @@ CS (소모품) ─┘
| 용어 | 필드명 | 값 | 용도 | | 용어 | 필드명 | 값 | 용도 |
|------|--------|-----|------| |------|--------|-----|------|
| **품목 유형** | `item_type` | FG, PT, SM, RM, CS | API 파라미터, UI 필터링, 비즈니스 분류 | | **품목 유형** | `item_type` | FG, PT, SM, RM, CS | API 파라미터, UI 필터링, 비즈니스 분류 |
| **저장 테이블** | `source_table` | products, materials | 내부 DB 분기, 서비스 로직 |
| **참조 타입** | `ref_type` | PRODUCT, MATERIAL | 폴리모픽 관계 (BOM, Prices 등) | > ⚠️ **Deprecated**: `source_table`, `ref_type` 개념은 items 테이블 통합으로 더 이상 사용되지 않습니다.
### 2.2 사용 규칙 ### 2.2 사용 규칙
- **API 레벨**: `item_type` 파라미터 사용 - **API 레벨**: `item_type` 파라미터 사용
- **서비스 레벨**: `source_table`로 테이블 분기 - **서비스 레벨**: items 테이블 단일 조회 (item_type으로 필터링)
- **폴리모픽 관계**: `ref_type`으로 참조 (기존 호환성 유지)
### 2.3 API 흐름 예시 ### 2.3 API 흐름 예시
``` ```
1. 클라이언트 요청: GET /api/v1/items?item_type=FG 1. 클라이언트 요청: GET /api/v1/items?item_type=FG
2. 서버 처리: item_type='FG' → common_codes 조회 2. 서버 처리: items 테이블에서 item_type='FG' 조회
3. 테이블 분기: source_table='products' 확인 3. 응답 반환: item_type='FG' 포함하여 응답
4. 데이터 조회: products 테이블에서 조회
5. 응답 반환: item_type='FG' 포함하여 응답
``` ```
--- ---
## 3. 필드 키 예약어 정책 ## 3. 필드 키 예약어 정책
### 3.1 products 테이블 예약어 ### 3.1 items 테이블 예약어 (통합)
```php ```php
// 사용 불가 field_key 목록 // 사용 불가 field_key 목록
'code', 'name', 'unit', 'category_id', 'product_type', 'description', 'code', 'name', 'unit', 'category_id', 'item_type', 'bom', 'is_active',
'is_sellable', 'is_purchasable', 'is_producible', 'is_variable_size', 'is_active', 'attributes', 'options'
'safety_stock', 'lead_time', 'product_category', 'part_type',
'bending_diagram', 'bending_details',
'specification_file', 'specification_file_name',
'certification_file', 'certification_file_name',
'certification_number', 'certification_start_date', 'certification_end_date',
'attributes', 'attributes_archive'
``` ```
### 3.2 materials 테이블 예약어 ### 3.2 item_details 테이블 예약어
```php ```php
// 사용 불가 field_key 목록 // 사용 불가 field_key 목록 (확장 필드)
'name', 'item_name', 'specification', 'material_code', 'material_type', 'is_sellable', 'is_purchasable', 'is_producible', 'is_variable_size',
'unit', 'category_id', 'is_inspection', 'is_active', 'safety_stock', 'lead_time', 'product_category', 'part_type',
'search_tag', 'remarks', 'attributes', 'options' 'is_inspection'
``` ```
### 3.3 공통 시스템 컬럼 (모든 테이블) ### 3.3 공통 시스템 컬럼 (모든 테이블)
@@ -120,9 +118,7 @@ CS (소모품) ─┘
``` ```
field_key 입력 field_key 입력
source_table 확인 (products / materials) items 테이블 예약어 체크
해당 테이블 예약어 체크
기존 필드 중복 체크 기존 필드 중복 체크
@@ -270,19 +266,24 @@ CS (소모품) ─┘
### 8.1 완료 항목 ### 8.1 완료 항목
- ✅ item_type 코드 시딩 (ItemTypeSeeder) - ✅ item_type 코드 시딩 (ItemTypeSeeder)
- ✅ common_codes에 attributes.source_table 매핑
- ✅ field_key 예약어 검증 (SystemFields) - ✅ field_key 예약어 검증 (SystemFields)
- ✅ ItemMaster CRUD API (Pages, Sections, Fields) - ✅ ItemMaster CRUD API (Pages, Sections, Fields)
- ✅ 독립 엔티티 아키텍처 (entity_relationships) - ✅ 독립 엔티티 아키텍처 (entity_relationships)
- ✅ **items 테이블 통합** (2025-12-15)
- products/materials 테이블 삭제
- items + item_details + item_attributes 구조
- 전체 item_type (FG, PT, SM, RM, CS) 지원
### 8.2 개발 필요 항목 ### 8.2 API 현황 (통합 완료)
| API | Product | Material | 작업 내용 | | API | 상태 | 설명 |
|-----|:-------:|:--------:|----------| |-----|:----:|------|
| `PUT /items/{id}` | ✅ | ❌ | Material 수정 지원 추가 | | `GET /api/v1/items` | ✅ | 전체 품목 조회 (item_type 필터) |
| `DELETE /items/{id}` | ✅ | ❌ | Material 삭제 지원 추가 | | `POST /api/v1/items` | ✅ | 품목 생성 |
| `DELETE /items/batch` | ✅ | ❌ | Material 일괄삭제 지원 | | `GET /api/v1/items/{id}` | ✅ | 품목 상세 조회 |
| `GET /items/code/{code}` | ✅ | ❌ | Material 코드 조회 지원 | | `PUT /api/v1/items/{id}` | ✅ | 품목 수정 |
| `DELETE /api/v1/items/{id}` | ✅ | 품목 삭제 |
| `DELETE /api/v1/items/batch` | ✅ | 품목 일괄 삭제 |
--- ---
@@ -290,4 +291,5 @@ CS (소모품) ─┘
| 날짜 | 내용 | | 날짜 | 내용 |
|------|------| |------|------|
| 2025-12-16 | items 테이블 통합 완료 반영 (products/materials → items) |
| 2025-12-09 | 문서 생성 - 4개 문서 통합 (items-api-unified-plan, field-integration, field-key-validation, INDEX) | | 2025-12-09 | 문서 생성 - 4개 문서 통합 (items-api-unified-plan, field-integration, field-key-validation, INDEX) |

View File

@@ -1,6 +1,6 @@
# SAM 데이터베이스 스키마 # SAM 데이터베이스 스키마
**업데이트**: 2025-11-24 **업데이트**: 2025-12-16
**데이터베이스**: samdb (MySQL 8.0.43) **데이터베이스**: samdb (MySQL 8.0.43)
**전체 테이블**: 92개 **전체 테이블**: 92개
@@ -176,21 +176,23 @@
#### category_templates #### category_templates
- 버전 관리된 카테고리 필드 스냅샷 - 버전 관리된 카테고리 필드 스냅샷
#### products #### items (통합 - 2025-12-15)
- 제품 카탈로그 - **품목 통합 테이블** (기존 products/materials 통합)
- 타입 분류: `PRODUCT`, `PART`, `SUBASSEMBLY` - 타입 분류: `FG` (완제품), `PT` (부품), `SM` (부자재), `RM` (원자재), `CS` (소모품)
- 주요 컬럼: `item_type`, `code`, `name`, `unit`, `category_id`, `bom` (JSON)
- 1:1 확장 테이블: `item_details`, `item_attributes`
#### product_components #### item_details
- BOM 관계 - items 확장 필드 (1:1 관계)
- `MATERIAL` 또는 `PRODUCT` 참조 - `is_sellable`, `is_purchasable`, `is_producible`, `safety_stock`, `lead_time`
#### materials #### item_attributes
- 자재 마스터 - 동적 속성 저장 (1:1 관계)
- 동적 속성 지원 - `attributes` (JSON), `options` (JSON)
#### classifications #### classifications
- 그룹별 플랫 코드 테이블 - 그룹별 플랫 코드 테이블
- 예: `product_type`, `payment_method` - 예: `item_type`, `payment_method`
### 디자인 및 제조 ### 디자인 및 제조
@@ -317,9 +319,10 @@
``` ```
Tenant → Users (many-to-many via user_tenants) Tenant → Users (many-to-many via user_tenants)
Products ↔ Materials (via product_components with ref_type) Items → ItemDetails, ItemAttributes (1:1 확장)
Items.bom (JSON) → 자체 참조 BOM 구조
Models → Versions → BOM Templates (design workflow) Models → Versions → BOM Templates (design workflow)
Orders → Items → Components (order breakdown) Orders → OrderItems → Items (주문 구조)
Categories ↔ Fields ↔ Templates (dynamic forms with versioning) Categories ↔ Fields ↔ Templates (dynamic forms with versioning)
Audit Logs (polymorphic tracking across all major entities) Audit Logs (polymorphic tracking across all major entities)
``` ```
@@ -470,5 +473,34 @@ $role->syncPermissions(['users.view', 'users.create']);
--- ---
**최종 업데이트**: 2025-11-24 ## Items 테이블 통합 (2025-12-15)
**Phase 4**: 완료 (8개 테이블 상세화)
### 완료 항목
- ✅ products/materials 테이블 → items 테이블로 통합
- ✅ item_details (확장 필드), item_attributes (동적 속성) 분리
- ✅ BOM 구조 단순화 (child_item_id만 사용)
- ✅ 기존 Product, Material 모델/서비스 삭제
### 테이블 구조
```sql
items (
id, tenant_id, item_type, code, name, unit,
category_id, bom JSON, is_active,
created_by, updated_by, deleted_by, timestamps, soft_delete
)
item_details (
id, item_id, is_sellable, is_purchasable, is_producible,
safety_stock, lead_time, is_inspection, ...
)
item_attributes (
id, item_id, attributes JSON, options JSON
)
```
---
**최종 업데이트**: 2025-12-16
**Phase 4**: 완료 (8개 테이블 상세화)
**Items 통합**: 완료 (2025-12-15)