From ff4acb043cde2ca00ab75d45d252d743ae5b34a7 Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Tue, 6 Feb 2024 09:55:11 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A6=AC=EC=86=8C=EC=8A=A4=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EB=B3=B5=EC=82=AC=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cokr/xit/fims/cmmn/CmmnUtil.java | 34 ++++++++++ .../bean/IntegrationSearchServiceBean.java | 62 ++++++++----------- 2 files changed, 59 insertions(+), 37 deletions(-) diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java index c5ad4144..1820af65 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -8,6 +8,7 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.time.DayOfWeek; @@ -31,6 +32,7 @@ import org.apache.commons.io.FilenameUtils; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.HorizontalAlignment; +import org.springframework.core.io.ClassPathResource; import cokr.xit.base.file.xls.XLSWriter; import cokr.xit.base.file.xls.XLSWriter.CommentSupport; @@ -213,6 +215,38 @@ public class CmmnUtil { } + /** + * 리소스 파일을 파일 공통 저장 경로로 복사한다. + * @param staticResourcePath 리소스 파일 경로 + * @return + */ + public static String copyStaticResource(String staticResourcePath) { + try { + + String folderPath = FilenameUtils.getFullPathNoEndSeparator(staticResourcePath); + String storageRoot = "files"; + + File folder = new File(storageRoot + "/" + folderPath); + if(!folder.exists()) { + folder.mkdirs(); + } + + ClassPathResource cps = new ClassPathResource(staticResourcePath); + + String fileName = cps.getFilename(); + InputStream is = cps.getInputStream(); + + File newFile = new File(storageRoot + "/" + folderPath + "/" + fileName); + Files.copy(is, newFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + + return storageRoot + "/" + folderPath + "/" + fileName; + + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + /** * 현재 날짜와 지정한 날짜와의 차이(일)를 반환한다. diff --git a/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java b/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java index 1aae76c0..d958a6af 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java +++ b/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java @@ -472,14 +472,13 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements continue; } - InputStream is = null; - if(imagePath.startsWith("files")) { - File imageFile = new File(imagePath); - is = new FileInputStream(imageFile); - } else { - is = new ClassPathResource(imagePath).getInputStream(); + if(!imagePath.startsWith("files")) { + imagePath = CmmnUtil.copyStaticResource(imagePath); } + File imageFile = new File(imagePath); + InputStream is = new FileInputStream(imageFile); + String imageKey = ""; if(otptArtclNm.equals("rprsCrdnPhoto")) { imageKey = pdfFormat.getMappingValue(otptArtclNm+"Key",defaultValue,forPost,dataObject,printOption,pdfPrintUtil); @@ -488,13 +487,8 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements if(otptArtclNm.equals("rprsCrdnPhoto") && !imageKey.equals("")) { - InputStream is0 = null; - if(imagePath.startsWith("files")) { - File imageFile0 = new File(imagePath); - is0 = new FileInputStream(imageFile0); - } else { - is0 = new ClassPathResource(imagePath).getInputStream(); - } + File imageFile0 = new File(imagePath); + InputStream is0 = new FileInputStream(imageFile0); List transformedMosaicInfos = mediaBean.getTransformedMosaic( imageKey, is0, new PstnAndSize(pstn[0],pstn[1], size[0], size[1]) @@ -537,34 +531,30 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements for (int i=0; i< devideInfos.size(); i++){ PstnAndSize devideInfo = devideInfos.get(i); - String imagePath = imagePaths.get(i); - if(ifEmpty(imagePath, ()-> "").equals("")) { + if(ifEmpty(imagePaths.get(i), ()-> "").equals("")) { continue; } - InputStream is = null; - if(imagePaths.get(i).startsWith("files")) { - File imageFile = new File(imagePath); - is = new FileInputStream(imageFile); - } else { - is = new ClassPathResource(imagePath).getInputStream(); + if(!imagePaths.get(i).startsWith("files")) { + imagePaths.set(i, CmmnUtil.copyStaticResource(imagePaths.get(i))); } + String imagePath = imagePaths.get(i); + + File imageFile = new File(imagePath); + InputStream is = new FileInputStream(imageFile); + pdfPrintUtil.insertImage(doc, contentStream, is, devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float()); if(otptArtclNm.equals("crdnPhoto") && !imageKeys.isEmpty()) { - InputStream is0 = null; String imagePath0 = imagePaths.get(i); - if(imagePath0.startsWith("files")) { - File imageFile0 = new File(imagePath0); - is0 = new FileInputStream(imageFile0); - } else { - is0 = new ClassPathResource(imagePath0).getInputStream(); - } + + File imageFile0 = new File(imagePath0); + InputStream is0 = new FileInputStream(imageFile0); List transformedMosaicInfos = mediaBean.getTransformedMosaic( imageKeys.get(i), is0, devideInfo @@ -670,17 +660,15 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements continue; } - InputStream orgnFileInputStream = null; + if(!orgnFilePath.startsWith("files")) { + orgnFilePath = CmmnUtil.copyStaticResource(orgnFilePath);; + } - if(orgnFilePath.startsWith("files")) { - File orgnFile = new File(orgnFilePath); - if(!orgnFile.exists() || !orgnFile.canRead()) { - continue; - } - orgnFileInputStream = new FileInputStream(orgnFile); - } else { - orgnFileInputStream = new ClassPathResource(orgnFilePath).getInputStream(); + File orgnFile = new File(orgnFilePath); + if(!orgnFile.exists() || !orgnFile.canRead()) { + continue; } + InputStream orgnFileInputStream = new FileInputStream(orgnFile); String modifiedFileName = "P"+fileInfo.string("INF_KEY")+CmmnUtil.indexToAlphabet(j, true, true)+"."+"JPG";