도면업로드기능 업데이트, 업로드한 파일을 순회해서 하이픈 앞이 5자리면 10자리, 7자리면 16자리를 품번으로 추출하고, 맨 마지막 확장자만 인식하여 매칭한다.)
This commit is contained in:
@@ -2284,25 +2284,23 @@ public class PartMngController {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 파일명에서 확장자 제거하여 품번 추출
|
||||
String fileNameWithoutExt = originalFileName;
|
||||
int lastDotIndex = originalFileName.lastIndexOf('.');
|
||||
if(lastDotIndex > 0) {
|
||||
fileNameWithoutExt = originalFileName.substring(0, lastDotIndex);
|
||||
}
|
||||
// 품번 추출 (맨 마지막 확장자만 제거 후 하이픈 기준 추출)
|
||||
String extractedPartNo = extractPartNoFromFileName(originalFileName);
|
||||
|
||||
// 품번과 정확히 일치하는 경우만 매칭
|
||||
String matchedPartNo = null;
|
||||
System.out.println("품번 매칭 시작 - 파일명(확장자 제외): " + fileNameWithoutExt);
|
||||
System.out.println("품번 매칭 시작 - 추출된 품번: " + extractedPartNo);
|
||||
|
||||
// 정확한 매칭 (품번과 파일명이 정확히 일치)
|
||||
if(partNoMap.containsKey(fileNameWithoutExt)) {
|
||||
matchedPartNo = fileNameWithoutExt;
|
||||
System.out.println(" ✓ 품번 정확 매칭 성공: " + matchedPartNo);
|
||||
if(extractedPartNo != null && !extractedPartNo.isEmpty()) {
|
||||
// 정확한 매칭 (추출된 품번과 DB 품번이 정확히 일치)
|
||||
if(partNoMap.containsKey(extractedPartNo)) {
|
||||
matchedPartNo = extractedPartNo;
|
||||
System.out.println(" ✓ 품번 정확 매칭 성공: " + matchedPartNo);
|
||||
}
|
||||
}
|
||||
|
||||
if(matchedPartNo == null) {
|
||||
System.out.println(" ✗ 품번 매칭 실패 - 파일명과 일치하는 품번이 없음");
|
||||
System.out.println(" ✗ 품번 매칭 실패 - 파일명: " + originalFileName + ", 추출된 품번: " + extractedPartNo);
|
||||
notFoundCount++;
|
||||
continue;
|
||||
}
|
||||
@@ -2488,25 +2486,23 @@ public class PartMngController {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 파일명에서 확장자 제거하여 품번 추출
|
||||
String fileNameWithoutExt = originalFileName;
|
||||
int lastDotIndex = originalFileName.lastIndexOf('.');
|
||||
if(lastDotIndex > 0) {
|
||||
fileNameWithoutExt = originalFileName.substring(0, lastDotIndex);
|
||||
}
|
||||
// 품번 추출 (맨 마지막 확장자만 제거 후 하이픈 기준 추출)
|
||||
String extractedPartNo = extractPartNoFromFileName(originalFileName);
|
||||
|
||||
// 품번과 정확히 일치하는 경우만 매칭
|
||||
String matchedPartNo = null;
|
||||
System.out.println("품번 매칭 시작 - 파일명(확장자 제외): " + fileNameWithoutExt);
|
||||
System.out.println("품번 매칭 시작 - 추출된 품번: " + extractedPartNo);
|
||||
|
||||
// 정확한 매칭 (품번과 파일명이 정확히 일치)
|
||||
if(partNoMap.containsKey(fileNameWithoutExt)) {
|
||||
matchedPartNo = fileNameWithoutExt;
|
||||
System.out.println(" ✓ 품번 정확 매칭 성공: " + matchedPartNo);
|
||||
if(extractedPartNo != null && !extractedPartNo.isEmpty()) {
|
||||
// 정확한 매칭 (추출된 품번과 DB 품번이 정확히 일치)
|
||||
if(partNoMap.containsKey(extractedPartNo)) {
|
||||
matchedPartNo = extractedPartNo;
|
||||
System.out.println(" ✓ 품번 정확 매칭 성공: " + matchedPartNo);
|
||||
}
|
||||
}
|
||||
|
||||
if(matchedPartNo == null) {
|
||||
System.out.println(" ✗ 품번 매칭 실패 - 파일명과 일치하는 품번이 없음");
|
||||
System.out.println(" ✗ 품번 매칭 실패 - 파일명: " + originalFileName + ", 추출된 품번: " + extractedPartNo);
|
||||
notFoundCount++;
|
||||
continue;
|
||||
}
|
||||
@@ -2556,4 +2552,116 @@ public class PartMngController {
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 파일명에서 품번을 추출하는 헬퍼 메서드
|
||||
*
|
||||
* 품번 추출 규칙:
|
||||
* 1. 모든 확장자 제거 (.idw.pdf → .idw도 제거)
|
||||
* 2. 확장자 제거 후 첫 번째 하이픈(-) 위치 찾기
|
||||
* 3. 하이픈 앞 자릿수에 따라 품번 길이 결정
|
||||
* - 5자리: 하이픈 포함 10자리 추출 (예: 20002-0043)
|
||||
* - 7자리: 하이픈 포함 16자리 추출 (예: 2000200-004300-01)
|
||||
*
|
||||
* @param fileName 원본 파일명 (예: "20002-0043.idw.pdf")
|
||||
* @return 추출된 품번 (예: "20002-0043") 또는 null
|
||||
*/
|
||||
private String extractPartNoFromFileName(String fileName) {
|
||||
if(fileName == null || fileName.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 1단계: 모든 확장자 제거 (이중/삼중 확장자 대응)
|
||||
// 알려진 CAD 확장자 목록
|
||||
String[] cadExtensions = {".idw", ".dwg", ".dxf", ".stp", ".step", ".pdf", ".chg"};
|
||||
|
||||
String fileNameWithoutExt = fileName;
|
||||
|
||||
// 반복적으로 확장자 제거 (예: file.idw.pdf → file.idw → file)
|
||||
boolean extensionRemoved = true;
|
||||
while(extensionRemoved) {
|
||||
extensionRemoved = false;
|
||||
|
||||
// 마지막 점 찾기
|
||||
int lastDotIndex = fileNameWithoutExt.lastIndexOf('.');
|
||||
if(lastDotIndex > 0) {
|
||||
String currentExt = fileNameWithoutExt.substring(lastDotIndex).toLowerCase();
|
||||
|
||||
// 알려진 CAD 확장자인 경우 제거
|
||||
for(String ext : cadExtensions) {
|
||||
if(currentExt.equals(ext)) {
|
||||
fileNameWithoutExt = fileNameWithoutExt.substring(0, lastDotIndex);
|
||||
extensionRemoved = true;
|
||||
System.out.println("[품번 추출] 확장자 제거: " + currentExt + " → " + fileNameWithoutExt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("[품번 추출] 1단계 완료 - 모든 확장자 제거: " + fileNameWithoutExt);
|
||||
|
||||
// 2단계: 첫 번째 하이픈 위치 찾기
|
||||
int firstHyphenIndex = fileNameWithoutExt.indexOf('-');
|
||||
if(firstHyphenIndex == -1) {
|
||||
System.out.println("[품번 추출] 하이픈이 없음 - 추출 실패");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3단계: 하이픈 앞 자릿수 확인
|
||||
String beforeHyphen = fileNameWithoutExt.substring(0, firstHyphenIndex);
|
||||
int beforeHyphenLength = beforeHyphen.length();
|
||||
|
||||
System.out.println("[품번 추출] 2단계 - 하이픈 앞 문자열: " + beforeHyphen + " (길이: " + beforeHyphenLength + ")");
|
||||
|
||||
// 4단계: 자릿수에 따라 품번 추출
|
||||
String extractedPartNo = null;
|
||||
|
||||
if(beforeHyphenLength == 5) {
|
||||
// 스핀들 설계팀: 5자리 -> 하이픈 1개 (5-4 = 10자리)
|
||||
// 예: 20002-0043
|
||||
int targetLength = 10;
|
||||
if(fileNameWithoutExt.length() >= targetLength) {
|
||||
extractedPartNo = fileNameWithoutExt.substring(0, targetLength);
|
||||
System.out.println("[품번 추출] 3단계 - 5자리 패턴 (10자리 추출): " + extractedPartNo);
|
||||
} else {
|
||||
System.out.println("[품번 추출] 5자리 패턴이지만 총 길이가 10자리 미만 - 추출 실패");
|
||||
}
|
||||
} else if(beforeHyphenLength == 7) {
|
||||
// 장비 개발팀: 7자리 -> 하이픈이 1개 또는 2개
|
||||
// 하이픈 1개: 7-9 = 17자리 (예: 2000200-004300-0)
|
||||
// 하이픈 2개: 7-6-2 = 18자리 (예: 2000200-004300-02)
|
||||
|
||||
// 두 번째 하이픈이 있는지 확인
|
||||
int secondHyphenIndex = fileNameWithoutExt.indexOf('-', firstHyphenIndex + 1);
|
||||
|
||||
if(secondHyphenIndex != -1) {
|
||||
// 하이픈이 2개인 경우: 7-6-2 패턴 = 18자리
|
||||
// 예: 2000200-004300-02
|
||||
extractedPartNo = fileNameWithoutExt;
|
||||
System.out.println("[품번 추출] 3단계 - 7자리 패턴 (하이픈 2개, 전체 품번): " + extractedPartNo);
|
||||
} else {
|
||||
// 하이픈이 1개인 경우: 7-9 패턴 = 17자리
|
||||
// 예: 2000200-004300-0 (16자리만 추출)
|
||||
int targetLength = 16;
|
||||
if(fileNameWithoutExt.length() >= targetLength) {
|
||||
extractedPartNo = fileNameWithoutExt.substring(0, targetLength);
|
||||
System.out.println("[품번 추출] 3단계 - 7자리 패턴 (하이픈 1개, 16자리 추출): " + extractedPartNo);
|
||||
} else {
|
||||
System.out.println("[품번 추출] 7자리 패턴이지만 총 길이가 16자리 미만 - 추출 실패");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.println("[품번 추출] 하이픈 앞이 5자리 또는 7자리가 아님 - 추출 실패");
|
||||
}
|
||||
|
||||
return extractedPartNo;
|
||||
|
||||
} catch(Exception e) {
|
||||
System.out.println("[품번 추출] 예외 발생: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user