feat: 배치(로트) 추적 — batch_id 컬럼 + 카드 진행률 표시

- work_order_process에 batch_id 컬럼 자동 추가 (ALTER TABLE IF NOT EXISTS)
- 접수 시 batch_id 자동 생성 (BATCH-timestamp-random)
- 다음 공정 접수 시 batch_id 전달 가능 (이어받기)
- 완료 카드: 같은 batch_id의 SPLIT 추적으로 정확한 진행률 표시
- 예: seq1만 완료 → ✓○○ (1/3), 전체 완료 → ✓✓✓ (전체 완료)
This commit is contained in:
SeongHyun Kim
2026-04-06 12:08:35 +09:00
parent 32a372a9b3
commit 32f99fba63
2 changed files with 46 additions and 10 deletions

View File

@@ -11,6 +11,17 @@ interface DefectDetailItem {
disposition: string;
}
// 자동 마이그레이션: batch_id 컬럼 추가 (배치/로트 추적용)
let _batchMigrationDone = false;
async function ensureBatchIdColumn() {
if (_batchMigrationDone) return;
try {
const pool = getPool();
await pool.query("ALTER TABLE work_order_process ADD COLUMN IF NOT EXISTS batch_id VARCHAR(100)");
_batchMigrationDone = true;
} catch { /* 이미 존재하거나 권한 문제 시 무시 */ }
}
/**
* inventory_stock UPSERT 공통 함수
* PC의 receivingController와 동일한 SELECT→INSERT/UPDATE 패턴 사용.
@@ -1746,25 +1757,30 @@ export const acceptProcess = async (req: AuthenticatedRequest, res: Response) =>
});
}
// 분할 행 INSERT (원본 행에서 공정 정보 복사)
// batch_id 생성 또는 전달받은 값 사용
// 프론트에서 batch_id를 전달하면 이어받고, 없으면 새로 생성
const batchId = req.body.batch_id || `BATCH-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
// 분할 행 INSERT (원본 행에서 공정 정보 복사 + batch_id)
await ensureBatchIdColumn();
const result = await client.query(
`INSERT INTO work_order_process (
id, wo_id, seq_no, process_code, process_name, is_required, is_fixed_order,
standard_time, equipment_code, routing_detail_id,
status, input_qty, good_qty, defect_qty, total_production_qty,
result_status, accepted_by, accepted_at, started_at,
parent_process_id, company_code, writer
parent_process_id, company_code, writer, batch_id
) VALUES (
gen_random_uuid()::text, $1, $2, $3, $4, $5, $6, $7, $8, $9,
'in_progress', $10, '0', '0', '0',
'draft', $11, NOW()::text, NOW()::text,
$12, $13, $11
) RETURNING id, input_qty, status, process_name, result_status, accepted_by`,
$12, $13, $11, $14
) RETURNING id, input_qty, status, process_name, result_status, accepted_by, batch_id`,
[
row.wo_id, row.seq_no, row.process_code, row.process_name,
row.is_required, row.is_fixed_order, row.standard_time,
row.equipment_code, row.routing_detail_id,
String(qty), userId, masterId, companyCode,
String(qty), userId, masterId, companyCode, batchId,
]
);