fix: [items] 품목 규격 accessor + 감사로그 + bom_category 마이그레이션

- Item 모델에 specification accessor 추가 (attributes.spec 조회)
- ItemService.update()에 AuditLogger 감사 로그 추가
- items.options에 bom_category 추가 마이그레이션
This commit is contained in:
2026-03-17 13:55:44 +09:00
parent afc31be642
commit 0863afc8d0
4 changed files with 131 additions and 1 deletions

View File

@@ -0,0 +1,90 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
/**
* 품목 options JSON에 bom_category 필드 일괄 추가
*
* BOM 카테고리: material, motor, controller, steel, parts, inspection
* 매핑 규칙:
* - EST-RAW-* → material (주자재)
* - RM (원자재) → material
* - EST-MOTOR-* → motor (모터)
* - EST-CTRL-* → controller (제어기)
* - BD-* (BENDING) → steel (절곡품)
* - EST-INSPECTION → inspection (검사비)
* - CS (소모품) → inspection
* - 나머지 PT/SM → parts (부자재)
*/
return new class extends Migration
{
public function up(): void
{
// 1. material: EST-RAW-* 코드
DB::table('items')
->where('code', 'like', 'EST-RAW-%')
->update([
'options' => DB::raw("JSON_SET(COALESCE(options, '{}'), '$.bom_category', 'material')"),
]);
// 2. material: RM (원자재) 타입
DB::table('items')
->where('item_type', 'RM')
->update([
'options' => DB::raw("JSON_SET(COALESCE(options, '{}'), '$.bom_category', 'material')"),
]);
// 3. motor: EST-MOTOR-* 코드
DB::table('items')
->where('code', 'like', 'EST-MOTOR-%')
->update([
'options' => DB::raw("JSON_SET(COALESCE(options, '{}'), '$.bom_category', 'motor')"),
]);
// 4. controller: EST-CTRL-* 코드
DB::table('items')
->where('code', 'like', 'EST-CTRL-%')
->update([
'options' => DB::raw("JSON_SET(COALESCE(options, '{}'), '$.bom_category', 'controller')"),
]);
// 5. steel: item_category=BENDING (BD-* 코드)
DB::table('items')
->where('item_category', 'BENDING')
->update([
'options' => DB::raw("JSON_SET(COALESCE(options, '{}'), '$.bom_category', 'steel')"),
]);
// 6. inspection: EST-INSPECTION 코드
DB::table('items')
->where('code', 'EST-INSPECTION')
->update([
'options' => DB::raw("JSON_SET(COALESCE(options, '{}'), '$.bom_category', 'inspection')"),
]);
// 7. inspection: CS (소모품) 타입
DB::table('items')
->where('item_type', 'CS')
->update([
'options' => DB::raw("JSON_SET(COALESCE(options, '{}'), '$.bom_category', 'inspection')"),
]);
// 8. parts: 나머지 PT/SM (아직 bom_category가 없는 것)
DB::table('items')
->whereIn('item_type', ['PT', 'SM'])
->whereRaw("(options IS NULL OR JSON_EXTRACT(options, '$.bom_category') IS NULL)")
->update([
'options' => DB::raw("JSON_SET(COALESCE(options, '{}'), '$.bom_category', 'parts')"),
]);
}
public function down(): void
{
DB::table('items')
->whereRaw("JSON_EXTRACT(options, '$.bom_category') IS NOT NULL")
->update([
'options' => DB::raw("JSON_REMOVE(options, '$.bom_category')"),
]);
}
};