Merge remote-tracking branch 'origin/main' into V2025121808
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.pms.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -11,6 +12,7 @@ import javax.servlet.http.HttpSession;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@@ -2106,11 +2108,73 @@ public class PurchaseOrderController {
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* PDF 청크 업로드 (AJAX)
|
||||
* @param request
|
||||
* @param paramMap - sessionId, chunkIndex, totalChunks, chunk
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping(value="/purchaseOrder/uploadPdfChunk.do", method=RequestMethod.POST)
|
||||
public Map uploadPdfChunk(HttpServletRequest request, @RequestParam Map<String, Object> paramMap){
|
||||
Map resultMap = new HashMap();
|
||||
|
||||
try {
|
||||
String sessionId = CommonUtils.checkNull(paramMap.get("sessionId"));
|
||||
int chunkIndex = Integer.parseInt(CommonUtils.checkNull(paramMap.get("chunkIndex"), "0"));
|
||||
int totalChunks = Integer.parseInt(CommonUtils.checkNull(paramMap.get("totalChunks"), "1"));
|
||||
String chunk = CommonUtils.checkNull(paramMap.get("chunk"));
|
||||
|
||||
// 임시 디렉토리에 청크 저장
|
||||
String tempDir = System.getProperty("java.io.tmpdir");
|
||||
File chunkFile = new File(tempDir + File.separator + sessionId + "_chunk_" + chunkIndex);
|
||||
|
||||
// 청크 데이터 저장
|
||||
java.io.FileOutputStream fos = new java.io.FileOutputStream(chunkFile);
|
||||
fos.write(chunk.getBytes("UTF-8"));
|
||||
fos.close();
|
||||
|
||||
// 모든 청크가 업로드되면 합치기
|
||||
if(chunkIndex == totalChunks - 1) {
|
||||
StringBuilder fullBase64 = new StringBuilder();
|
||||
for(int i = 0; i < totalChunks; i++) {
|
||||
File cf = new File(tempDir + File.separator + sessionId + "_chunk_" + i);
|
||||
if(cf.exists()) {
|
||||
byte[] data = java.nio.file.Files.readAllBytes(cf.toPath());
|
||||
fullBase64.append(new String(data, "UTF-8"));
|
||||
cf.delete();
|
||||
}
|
||||
}
|
||||
|
||||
// Base64 디코딩하여 PDF 파일 생성 (Apache Commons Codec 사용 - Java 7 호환)
|
||||
byte[] pdfBytes = org.apache.commons.codec.binary.Base64.decodeBase64(fullBase64.toString());
|
||||
File pdfFile = new File(tempDir + File.separator + sessionId + ".pdf");
|
||||
java.io.FileOutputStream pdfFos = new java.io.FileOutputStream(pdfFile);
|
||||
pdfFos.write(pdfBytes);
|
||||
pdfFos.close();
|
||||
|
||||
pdfFile.deleteOnExit();
|
||||
|
||||
System.out.println("발주서 PDF 파일 생성 완료: " + pdfFile.getAbsolutePath() + " (" + pdfBytes.length + " bytes)");
|
||||
}
|
||||
|
||||
resultMap.put("result", "success");
|
||||
resultMap.put("chunkIndex", chunkIndex);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
resultMap.put("result", "error");
|
||||
resultMap.put("message", "청크 업로드 중 오류가 발생했습니다: " + e.getMessage());
|
||||
}
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 발주서 메일 발송 (AJAX)
|
||||
* @param session
|
||||
* @param request
|
||||
* @param paramMap - objId, toEmails, ccEmails, subject, contents
|
||||
* @param paramMap - objId, pdfSessionId, toEmails, ccEmails, subject, contents
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
|
||||
Reference in New Issue
Block a user