E-BOM 확인/수정 파일업로드기능추가

This commit is contained in:
Johngreen
2025-10-27 21:03:21 +09:00
parent ff74ac99ca
commit 657a8d3234
7 changed files with 414 additions and 36 deletions

View File

@@ -21,6 +21,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.oreilly.servlet.MultipartRequest;
import com.pms.common.FileRenameClass;
import com.pms.common.JsonUtil;
import com.pms.common.SqlMapConfig;
import com.pms.common.bean.PersonBean;
@@ -2136,4 +2138,188 @@ public class PartMngController {
return "/ajax/ajaxResult";
}
/**
* 도면 파일 일괄 업로드
* 파일명에 품번이 포함된 경우 자동 매칭하여 업로드
* - stp 파일 -> 3D CAD 컬럼
* - dwg 파일 -> 2D Drawing CAD 컬럼
* - pdf 파일 -> 2D PDF CAD 컬럼
*
* @param request
* @param session
* @param bomObjId BOM OBJID
* @return
*/
@RequestMapping(value="/partMng/uploadDrawingFiles.do", method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> uploadDrawingFiles(
HttpServletRequest request,
HttpSession session) {
Map<String, Object> resultMap = new HashMap<>();
MultipartRequest multi = null;
FileRenameClass frc = null;
try {
PersonBean person = (PersonBean)session.getAttribute(Constants.PERSON_BEAN);
String userId = person != null ? person.getUserId() : "plmAdmin";
// MultipartRequest로 파일 업로드 처리
String storagePath = Constants.FILE_STORAGE;
int maxSize = 1024*1024*1024*9; // 9GB
File storage = new File(storagePath);
if(!storage.exists()) storage.mkdirs();
frc = new FileRenameClass();
multi = new MultipartRequest(request, storagePath, maxSize, "UTF-8", frc);
java.util.List fileList = frc.getFileList();
// MultipartRequest에서 bomObjId 파라미터 가져오기
String bomObjId = multi.getParameter("bomObjId");
if(bomObjId == null || bomObjId.isEmpty()) {
resultMap.put("result", "fail");
resultMap.put("message", "BOM ID가 전달되지 않았습니다.");
return resultMap;
}
// BOM 정보 조회
Map<String, Object> bomParam = new HashMap<>();
bomParam.put("objId", bomObjId);
Map bomInfo = partMngService.getBOMStructureStandardInfo(request, bomParam);
if(bomInfo == null) {
resultMap.put("result", "fail");
resultMap.put("message", "BOM 정보를 찾을 수 없습니다.");
return resultMap;
}
// 해당 BOM의 모든 파트 정보 조회
bomParam.put("SEARCH_BOM_OBJID", bomObjId);
ArrayList<Map> partList = commonService.selectList("partMng.partMngListByBom", request, bomParam);
if(partList == null || partList.isEmpty()) {
resultMap.put("result", "fail");
resultMap.put("message", "BOM에 등록된 파트가 없습니다.");
return resultMap;
}
// 품번 기준 파트 맵 생성
Map<String, Map> partNoMap = new HashMap<>();
for(Map part : partList) {
String partNo = CommonUtils.checkNull((String)part.get("PART_NO"));
if(!partNo.isEmpty()) {
partNoMap.put(partNo, part);
}
}
int successCount = 0;
int failCount = 0;
int notFoundCount = 0;
// 업로드된 파일 처리
if(fileList != null && !fileList.isEmpty()) {
for(Object fileObj : fileList) {
Map fileInfo = (Map)fileObj;
String originalFileName = CommonUtils.checkNull((String)fileInfo.get("realFileName"));
String savedFileName = CommonUtils.checkNull((String)fileInfo.get("savedFileName"));
String fileExt = CommonUtils.checkNull((String)fileInfo.get("fileExt"));
long fileSize = Long.parseLong(CommonUtils.checkNull(fileInfo.get("fileSize"), "0"));
// 확장자 대문자 변환 (이미 점 없이 저장됨)
fileExt = fileExt.toUpperCase();
System.out.println("========== 파일 업로드 처리 ==========");
System.out.println("원본 파일명: " + originalFileName);
System.out.println("저장 파일명: " + savedFileName);
System.out.println("확장자: " + fileExt);
System.out.println("===================================");
// 파일 확장자에 따른 문서 타입 결정
String docType = "";
String docTypeName = "";
if("STP".equals(fileExt) || "STEP".equals(fileExt)) {
docType = "3D_CAD";
docTypeName = "3D CAD 첨부파일";
} else if("DWG".equals(fileExt)) {
docType = "2D_DRAWING_CAD";
docTypeName = "2D(Drawing) CAD 첨부파일";
} else if("PDF".equals(fileExt)) {
docType = "2D_PDF_CAD";
docTypeName = "2D(PDF) CAD 첨부파일";
} else {
// 지원하지 않는 확장자는 스킵
System.out.println("지원하지 않는 확장자: " + fileExt + ", 파일명: " + originalFileName);
continue;
}
// 파일명에서 품번 찾기 (파일명에 품번이 포함되어 있는 경우)
String matchedPartNo = null;
System.out.println("품번 매칭 시작 - 파일명: " + originalFileName);
for(String partNo : partNoMap.keySet()) {
System.out.println(" 품번 확인: " + partNo + " -> " + (originalFileName.contains(partNo) ? "매칭!" : "미매칭"));
if(originalFileName.contains(partNo)) {
matchedPartNo = partNo;
System.out.println(" ✓ 품번 매칭 성공: " + partNo);
break;
}
}
if(matchedPartNo == null) {
System.out.println(" ✗ 품번 매칭 실패 - 파일명에서 품번을 찾을 수 없음");
}
if(matchedPartNo == null) {
notFoundCount++;
continue;
}
// 해당 파트에 파일 정보 저장
Map partInfo = partNoMap.get(matchedPartNo);
String partObjId = CommonUtils.checkNull((String)partInfo.get("OBJID"));
Map<String, Object> fileMap = new HashMap<>();
fileMap.put("OBJID", CommonUtils.createObjId());
fileMap.put("TARGET_OBJID", partObjId);
fileMap.put("SAVED_FILE_NAME", savedFileName);
fileMap.put("REAL_FILE_NAME", originalFileName);
fileMap.put("DOC_TYPE", docType);
fileMap.put("DOC_TYPE_NAME", docTypeName);
fileMap.put("FILE_SIZE", String.valueOf(fileSize));
fileMap.put("FILE_EXT", fileExt);
fileMap.put("FILE_PATH", storagePath);
fileMap.put("WRITER", userId);
try {
// 파일 정보 DB 저장
partMngService.insertDrawingFile(fileMap);
successCount++;
} catch(Exception e) {
e.printStackTrace();
failCount++;
}
}
}
resultMap.put("result", "success");
resultMap.put("successCount", successCount);
resultMap.put("failCount", failCount);
resultMap.put("notFoundCount", notFoundCount);
resultMap.put("message", "업로드가 완료되었습니다.");
} catch(Exception e) {
e.printStackTrace();
resultMap.put("result", "error");
resultMap.put("message", "업로드 중 오류가 발생했습니다: " + e.getMessage());
} finally {
if(frc != null) {
frc.clear();
}
}
return resultMap;
}
}