diff options
Diffstat (limited to 'lib/swp/table/swp-upload-validation-dialog.tsx')
| -rw-r--r-- | lib/swp/table/swp-upload-validation-dialog.tsx | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/lib/swp/table/swp-upload-validation-dialog.tsx b/lib/swp/table/swp-upload-validation-dialog.tsx index ef48f0c6..a7cdb7c5 100644 --- a/lib/swp/table/swp-upload-validation-dialog.tsx +++ b/lib/swp/table/swp-upload-validation-dialog.tsx @@ -43,14 +43,14 @@ interface SwpUploadValidationDialogProps { * @param fileName 검증할 파일명 * @param availableDocNos 업로드 가능한 문서번호 목록 (선택) * @param isVendorMode 벤더 모드인지 여부 (true인 경우 문서번호 검증 필수) - * @param docNoToDocTypeMap 문서번호 → DOC_TYPE 매핑 (Stage 검증용) + * @param docNoToDocClsMap 문서번호 → DOC_CLS (Document Class) 매핑 (Stage 검증용) * @param documentClassStages Document Class → 허용 Stage 목록 매핑 */ export function validateFileName( fileName: string, availableDocNos?: string[], isVendorMode?: boolean, - docNoToDocTypeMap?: Record<string, string>, + docNoToDocClsMap?: Record<string, string>, documentClassStages?: Record<string, string[]> ): { valid: boolean; @@ -117,10 +117,12 @@ export function validateFileName( }; } + // trim된 값 미리 준비 (중복 제거) + const trimmedDocNo = ownDocNo.trim(); + const trimmedStage = stage.trim(); + // 문서번호 검증 (벤더 모드에서는 필수) if (isVendorMode) { - const trimmedDocNo = ownDocNo.trim(); - // 벤더 모드에서 문서 목록이 비어있으면 에러 if (!availableDocNos || availableDocNos.length === 0) { return { @@ -138,28 +140,49 @@ export function validateFileName( } } - // Stage 검증 (DOC_TYPE별 허용 Stage 확인) - const trimmedDocNo = ownDocNo.trim(); - const trimmedStage = stage.trim(); + // Stage 검증 (Document Class별 허용 Stage 확인) + // EVCP DB에서 vendorDocNumber로 Document Class를 조회하고, + // 해당 Document Class의 허용 Stage 목록과 비교 + + if (docNoToDocClsMap && documentClassStages) { + const docCls = docNoToDocClsMap[trimmedDocNo]; + console.log(`[validateFileName] 문서 '${trimmedDocNo}' → Document Class: '${docCls || "null"}'`); + + if (!docCls) { + // 문서가 EVCP DB에 등록되지 않음 + return { + valid: false, + error: `문서번호 '${trimmedDocNo}'는 문서 리스트에 등록되지 않았습니다. 먼저 문서 리스트를 제출해주세요.`, + }; + } - if (docNoToDocTypeMap && documentClassStages) { - const docType = docNoToDocTypeMap[trimmedDocNo]; + const allowedStages = documentClassStages[docCls]; + console.log(`[validateFileName] Document Class '${docCls}' → 허용 Stage:`, allowedStages); - if (docType) { - const allowedStages = documentClassStages[docType]; - - if (allowedStages && allowedStages.length > 0) { - // 허용된 Stage 목록이 있는 경우에만 검증 - if (!allowedStages.includes(trimmedStage)) { - return { - valid: false, - error: `문서 '${trimmedDocNo}'의 Document Class '${docType}'에서 Stage '${trimmedStage}'는 허용되지 않습니다. 허용된 Stage: ${allowedStages.join(", ")}`, - }; - } - } - // allowedStages가 비어있으면 Stage 검증을 스킵 (설정되지 않은 경우) + if (!allowedStages || allowedStages.length === 0) { + // Document Class에 Stage가 설정되지 않음 + return { + valid: false, + error: `문서 '${trimmedDocNo}'의 Document Class '${docCls}'에 Stage가 설정되지 않았습니다. 관리자에게 문의하세요.`, + }; + } + + console.log(`[validateFileName] Stage 검증: '${trimmedStage}' in [${allowedStages.join(", ")}]`); + if (!allowedStages.includes(trimmedStage)) { + return { + valid: false, + error: `문서 '${trimmedDocNo}'의 Document Class '${docCls}'에서 Stage '${trimmedStage}'는 허용되지 않습니다. 허용된 Stage: ${allowedStages.join(", ")}`, + }; } - // docType이 없으면 Stage 검증을 스킵 (문서 정보가 없는 경우) + + console.log(`[validateFileName] Stage 검증 통과: '${trimmedStage}'`); + } else { + // 검증 정보가 로드되지 않음 + console.log(`[validateFileName] 검증 정보가 없음 → 업로드 차단`); + return { + valid: false, + error: "문서 정보를 가져올 수 없습니다. 페이지를 새로고침하거나 프로젝트를 다시 선택해주세요.", + }; } return { |
