docs: [receiving] 매핑 실행 스크립트 보강
- linked_item_ids + template_links + link_values 3곳 동시 설정 - MNG UI 파란 태그 표시를 위한 template_links 구조 반영 - 기존 old ID 삭제 → 신규 매핑 스크립트 완성
This commit is contained in:
@@ -162,37 +162,108 @@
|
||||
|
||||
## 4. 실행 방법
|
||||
|
||||
### 4.1 매핑표 확정 후 tinker 실행
|
||||
### 4.1 데이터 구조
|
||||
|
||||
R&D실 검토 후 확정된 매핑표를 기반으로 아래 형태로 실행:
|
||||
MNG UI "연결 설정"에 표시되려면 **3곳에 데이터를 넣어야** 한다:
|
||||
|
||||
```
|
||||
document_templates.linked_item_ids ← API 내부 매칭용 (JSON 배열)
|
||||
document_template_links ← MNG UI "연결 설정" 소스 테이블 정의
|
||||
document_template_link_values ← MNG UI 파란 태그 (개별 품목)
|
||||
```
|
||||
|
||||
> `linked_item_ids`만 설정하면 API 매칭은 되지만 MNG UI에 표시되지 않는다.
|
||||
> `template_links` + `link_values`도 함께 설정해야 MNG에서 파란 태그로 보이고 관리 가능.
|
||||
|
||||
### 4.2 매핑표 확정 후 tinker 실행
|
||||
|
||||
```bash
|
||||
docker exec sam-mng-1 php artisan tinker --execute="
|
||||
// 기존 무효 linked_item_ids 초기화 + 새 매핑 설정
|
||||
\$mapping = [
|
||||
19 => [14953,14954,14955,14956,14957,14958,14959,14960,14961,14962,14963,15226,14940], // SUS 절곡판
|
||||
18 => [14964,14965,14966,14967,14968,14969,15017,15018,15019,15020], // EGI
|
||||
20 => [15265,15266,15276,15277,15278,15279], // 앵글
|
||||
// ... 나머지 템플릿
|
||||
19 => [14953,14954,14955,14956,14957,14958,14959,14960,14961,14962,14963,15226,14940],
|
||||
18 => [14964,14965,14966,14967,14968,14969,15017,15018,15019,15020],
|
||||
20 => [15265,15266,15276,15277,15278,15279],
|
||||
26 => [15491,15493],
|
||||
25 => [15563],
|
||||
27 => [15564],
|
||||
30 => [15027],
|
||||
29 => [15548,15549,15550,15551,15552,15553,15554,15555,15556,15557,15558,15559,15560,15152,15153,15149,15174,15151,15145,15146,15172,15071],
|
||||
24 => [15098],
|
||||
23 => [15105],
|
||||
22 => [15072,15073,15080],
|
||||
];
|
||||
|
||||
foreach (\$mapping as \$templateId => \$itemIds) {
|
||||
// 1. linked_item_ids 업데이트
|
||||
DB::table('document_templates')
|
||||
->where('id', \$templateId)
|
||||
->update(['linked_item_ids' => json_encode(\$itemIds)]);
|
||||
print('템플릿 ' . \$templateId . ': ' . count(\$itemIds) . '개 품목 연결' . PHP_EOL);
|
||||
|
||||
// 2. 기존 template_links/link_values 삭제
|
||||
\$oldLinks = DB::table('document_template_links')
|
||||
->where('template_id', \$templateId)
|
||||
->pluck('id');
|
||||
if (\$oldLinks->isNotEmpty()) {
|
||||
DB::table('document_template_link_values')
|
||||
->whereIn('link_id', \$oldLinks)
|
||||
->delete();
|
||||
DB::table('document_template_links')
|
||||
->where('template_id', \$templateId)
|
||||
->delete();
|
||||
}
|
||||
|
||||
// 3. template_links 생성
|
||||
\$linkId = DB::table('document_template_links')->insertGetId([
|
||||
'template_id' => \$templateId,
|
||||
'link_key' => 'items',
|
||||
'label' => '연결 품목 (RM)',
|
||||
'link_type' => 'multiple',
|
||||
'source_table' => 'items',
|
||||
'search_params' => null,
|
||||
'display_fields' => null,
|
||||
'is_required' => false,
|
||||
'sort_order' => 0,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
// 4. link_values 생성
|
||||
foreach (\$itemIds as \$idx => \$itemId) {
|
||||
DB::table('document_template_link_values')->insert([
|
||||
'template_id' => \$templateId,
|
||||
'link_id' => \$linkId,
|
||||
'linkable_id' => \$itemId,
|
||||
'sort_order' => \$idx,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
print('템플릿 ' . \$templateId . ': ' . count(\$itemIds) . '개 품목 연결 완료' . PHP_EOL);
|
||||
}
|
||||
"
|
||||
```
|
||||
|
||||
### 4.2 검증
|
||||
### 4.3 검증
|
||||
|
||||
```bash
|
||||
# 매핑 확인
|
||||
# MNG에서 확인: 문서양식관리 → 각 수입검사 템플릿 편집 → "연결 설정"에 파란 태그 표시 확인
|
||||
# API에서 확인:
|
||||
docker exec sam-api-1 php artisan tinker --execute="
|
||||
\$items = DB::table('items')->where('tenant_id', 287)->whereIn('item_type', ['RM','SM'])->whereNull('deleted_at')->where('is_active', true)->pluck('id')->toArray();
|
||||
\$service = app(App\Services\ReceivingService::class);
|
||||
// ... has_inspection_template 확인
|
||||
\$templates = DB::table('document_templates')->where('tenant_id', 287)->where('category', '수입검사')->whereNotNull('linked_item_ids')->get(['id','name','linked_item_ids']);
|
||||
\$mapped = [];
|
||||
foreach (\$templates as \$t) {
|
||||
\$ids = json_decode(\$t->linked_item_ids, true) ?? [];
|
||||
foreach (\$ids as \$id) { \$mapped[] = (int)\$id; }
|
||||
}
|
||||
\$mapped = array_unique(\$mapped);
|
||||
\$unmapped = array_diff(\$items, \$mapped);
|
||||
print('매핑 완료: ' . count(\$mapped) . '개' . PHP_EOL);
|
||||
print('미매핑: ' . count(\$unmapped) . '개' . PHP_EOL);
|
||||
foreach (\$unmapped as \$id) {
|
||||
\$item = DB::table('items')->find(\$id, ['code','name']);
|
||||
print(' ❌ ' . \$id . ' | ' . \$item->code . ' | ' . \$item->name . PHP_EOL);
|
||||
}
|
||||
"
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user