diff --git a/src/components/production/WorkOrders/documents/InspectionReportModal.tsx b/src/components/production/WorkOrders/documents/InspectionReportModal.tsx index 7157921e..904c86c5 100644 --- a/src/components/production/WorkOrders/documents/InspectionReportModal.tsx +++ b/src/components/production/WorkOrders/documents/InspectionReportModal.tsx @@ -135,10 +135,17 @@ export function InspectionReportModal({ const [selfTemplateData, setSelfTemplateData] = useState(null); // props에서 목업 제외한 실제 개소만 사용 (WorkerScreen에서 apiItems + mockItems가 합쳐져 전달됨) - // props 데이터가 없거나 비어있으면 API 로딩 데이터를 fallback으로 사용 + // ★ 반드시 workItems와 inspectionDataMap을 같은 소스에서 가져와야 key 포맷이 일치함 + // props: key = "${orderId}-node-${nodeKey}" (예: "18-node-1층/FSS-01") + // API: key = "report-item-${itemId}" (예: "report-item-42") const propFiltered = propWorkItems?.filter(w => !w.id.startsWith('mock-')); - const effectiveWorkItems = (propFiltered && propFiltered.length > 0) ? propFiltered : apiWorkItems ?? undefined; - const effectiveInspectionDataMap = (propInspectionDataMap && propInspectionDataMap.size > 0) ? propInspectionDataMap : apiInspectionDataMap ?? undefined; + const propHasWorkItems = propFiltered && propFiltered.length > 0; + const propHasInspectionData = propInspectionDataMap && propInspectionDataMap.size > 0; + const usePropsSource = propHasWorkItems && propHasInspectionData; + const effectiveWorkItems = usePropsSource ? propFiltered : apiWorkItems ?? undefined; + const effectiveInspectionDataMap = usePropsSource ? propInspectionDataMap : apiInspectionDataMap ?? undefined; + + // 목업 WorkOrder 생성 const createMockOrder = (id: string, pType: ProcessType): WorkOrder => ({ diff --git a/src/components/production/WorkOrders/documents/TemplateInspectionContent.tsx b/src/components/production/WorkOrders/documents/TemplateInspectionContent.tsx index 6618b071..26135c70 100644 --- a/src/components/production/WorkOrders/documents/TemplateInspectionContent.tsx +++ b/src/components/production/WorkOrders/documents/TemplateInspectionContent.tsx @@ -253,6 +253,42 @@ export const TemplateInspectionContent = forwardRef inspectionDataMap.get(wi.id)); + if (hasAnyData) { + // 컬럼 라벨 → 레거시 필드 매핑 + const labelToLegacy: Record) => unknown> = { + '가공상태': (d) => d.processingStatus === 'good' ? 'ok' : d.processingStatus === 'bad' ? 'ng' : null, + '재봉상태': (d) => d.sewingStatus === 'good' ? 'ok' : d.sewingStatus === 'bad' ? 'ng' : null, + '조립상태': (d) => d.assemblyStatus === 'good' ? 'ok' : d.assemblyStatus === 'bad' ? 'ng' : null, + '절곡상태': (d) => d.bendingStatus === 'good' ? 'ok' : d.bendingStatus === 'bad' ? 'ng' : null, + '길이': (d) => d.length, + '높이': (d) => d.width, + '간격': (d) => d.gapStatus === 'ok' ? 'ok' : d.gapStatus === 'ng' ? 'ng' : null, + }; + + workItems.forEach((wi, rowIdx) => { + const itemData = inspectionDataMap.get(wi.id) as Record | undefined; + if (!itemData) return; + for (const col of template.columns) { + const cellKey = `${rowIdx}-${col.id}`; + // 컬럼 라벨에서 번호 접두사 제거 후 매칭 (예: "① 길이" → "길이") + const labelClean = col.label.replace(/[①②③④⑤⑥⑦⑧⑨⑩\s]/g, ''); + const matchEntry = Object.entries(labelToLegacy).find(([key]) => labelClean.includes(key)); + if (!matchEntry) continue; + const val = matchEntry[1](itemData); + if (val == null) continue; + if (val === 'ok') initial[cellKey] = { status: 'good' }; + else if (val === 'ng') initial[cellKey] = { status: 'bad' }; + else if (typeof val === 'number') initial[cellKey] = { value: String(val) }; + else if (typeof val === 'string') initial[cellKey] = { value: val }; + } + }); + } + } + if (Object.keys(initial).length > 0) setCellValues(initial); // 부적합 내용 복원: 각 개소의 nonConformingContent를 수집