From 4ae3a2e6316802aae844cf25e2539b6cdc648f9a Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Mon, 8 Jan 2024 14:02:03 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B0=A8=EC=84=B8=EB=8C=80=EC=84=B8=EC=99=B8?= =?UTF-8?q?=EC=88=98=EC=9E=85=20=EA=B3=A0=EC=A7=80=EC=84=9C=20pdf=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EC=B6=9C=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20controller,=20html=20=EC=B6=94=EA=B0=80=201.=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EC=B2=98=EB=A6=AC=EC=9A=A9=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=B6=94=EA=B0=80=202.=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=EC=9A=A9=20html=ED=99=94=EB=A9=B4?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/fims/base/FileController.java | 36 +++ .../cokr/xit/fims/cmmn/pdf/ExtractText.java | 34 +++ .../java/cokr/xit/fims/cmmn/pdf/PDFUtil.java | 8 +- .../xit/fims/cmmn/web/LinkController.java | 34 +++ src/main/webapp/WEB-INF/jsp/include/top.jsp | 34 ++- .../webapp/resources/html/fileUpload.html | 266 ++++++++++++++++++ 6 files changed, 401 insertions(+), 11 deletions(-) create mode 100644 src/main/java/cokr/xit/fims/cmmn/web/LinkController.java create mode 100644 src/main/webapp/resources/html/fileUpload.html diff --git a/src/main/java/cokr/xit/fims/base/FileController.java b/src/main/java/cokr/xit/fims/base/FileController.java index ec0b4599..d567f974 100644 --- a/src/main/java/cokr/xit/fims/base/FileController.java +++ b/src/main/java/cokr/xit/fims/base/FileController.java @@ -7,6 +7,8 @@ import java.io.OutputStream; import java.io.StringWriter; import java.net.URISyntaxException; import java.net.URLDecoder; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import java.util.regex.Matcher; @@ -22,10 +24,13 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.commons.io.FilenameUtils; import org.springframework.core.io.ClassPathResource; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -194,5 +199,36 @@ public class FileController extends cokr.xit.base.file.web.FileController { } } + @PostMapping(name = "처리 전 파일업로드", value = "/uploadBeforeProcess.do") + public ModelAndView uploadBeforeProcess(MultipartFile[] uploadFiles) { + ModelAndView mav = new ModelAndView("jsonView"); + + boolean saved = false; + + MultipartFile uploadFile = uploadFiles[0]; + String orginalFileName = uploadFile.getOriginalFilename(); + String extension = FilenameUtils.getExtension(orginalFileName); + + SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String currentTime = ymdhmsFormat.format(new Date()); + + String folderPath = "files/tempForProcess"; + File folder = new File(folderPath); + folder.mkdirs(); + String filePath = folderPath + "/"+currentTime+"."+extension; + File file = new File(filePath); + + + try { + uploadFile.transferTo(file); + saved = true; + } catch (IOException e) { + e.printStackTrace(); + } + + mav.addObject("saved", saved); + mav.addObject("filePath", filePath); + return mav; + } } \ No newline at end of file diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/ExtractText.java b/src/main/java/cokr/xit/fims/cmmn/pdf/ExtractText.java index 0b4e3ba2..9ddb9e84 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/ExtractText.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/ExtractText.java @@ -1,15 +1,49 @@ package cokr.xit.fims.cmmn.pdf; +import java.awt.geom.Rectangle2D; import java.io.IOException; import java.util.regex.Pattern; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.text.PDFTextStripper; +import org.apache.pdfbox.text.PDFTextStripperByArea; public class ExtractText { public static final String REGEXP_PATTERN_NUMBER = "^[\\d]*$"; + public static String getExtractByStng(PDDocument document, int pageNum, + float x, float y, float w, float h) { + + try { + PDFTextStripperByArea textStripper = new PDFTextStripperByArea(); + + Rectangle2D rect = new java.awt.geom.Rectangle2D.Float(x, y, w, h); + textStripper.addRegion("region", rect); + + PDPage docPage = document.getPage(pageNum-1); + + textStripper.extractRegions(docPage); + + String textForRegion = textStripper.getTextForRegion("region"); + + System.out.println("영역지정으로 추출된 텍스트"); + System.out.println(textForRegion); + + return textForRegion; + + } catch (IOException e) { + + e.printStackTrace(); + } + + + + return ""; + } + + public static String getExtractEpayNo(PDDocument pdDocument, int pageNum) { String epayNo = ""; diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/PDFUtil.java b/src/main/java/cokr/xit/fims/cmmn/pdf/PDFUtil.java index 62b5ef16..d4fe7958 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/PDFUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/PDFUtil.java @@ -1,7 +1,6 @@ package cokr.xit.fims.cmmn.pdf; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -10,7 +9,6 @@ import org.apache.pdfbox.Loader; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageTree; -import org.springframework.util.ResourceUtils; public class PDFUtil { @@ -20,8 +18,8 @@ public class PDFUtil { File file = null; try { - file = ResourceUtils.getFile("classpath:sample/"+pdfName); - } catch (FileNotFoundException e2) { + file = new File(pdfName); + } catch (Exception e2) { e2.printStackTrace(); } PDDocument pdDocument = null; @@ -44,7 +42,7 @@ public class PDFUtil { extraction = new Extraction(); extraction.setPage(pageIndex+1); - String epayNo = ExtractText.getExtractEpayNo(pdDocument, pageIndex+1); + String epayNo = ExtractText.getExtractByStng(pdDocument, pageIndex+1, 0 , 0, 100, 100); extraction.setEpayNo(epayNo); diff --git a/src/main/java/cokr/xit/fims/cmmn/web/LinkController.java b/src/main/java/cokr/xit/fims/cmmn/web/LinkController.java new file mode 100644 index 00000000..96db43db --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/web/LinkController.java @@ -0,0 +1,34 @@ +package cokr.xit.fims.cmmn.web; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import cokr.xit.fims.cmmn.pdf.PDFUtil; +import cokr.xit.foundation.web.AbstractController; + +@Controller +@RequestMapping(name = "연계 처리", value = "/link") +public class LinkController extends AbstractController { + + @RequestMapping(name = "파일 처리", value = "/fileProcess.do") + public ModelAndView fileProcess(String filePath, String job, String param) { + ModelAndView mav = new ModelAndView("jsonView"); + + boolean saved = false; + + System.out.println("파일경로 : " +filePath); + System.out.println("업무 : " + job); + System.out.println("파라미터 : "+ param); + + //차세대 세외수입 pdf파일 정보 추출 + if(job.equals("01")) { + PDFUtil.extract(param); + } + + mav.addObject("saved", saved); + return mav; + } + +} + diff --git a/src/main/webapp/WEB-INF/jsp/include/top.jsp b/src/main/webapp/WEB-INF/jsp/include/top.jsp index 7655a5c8..33f481fc 100644 --- a/src/main/webapp/WEB-INF/jsp/include/top.jsp +++ b/src/main/webapp/WEB-INF/jsp/include/top.jsp @@ -34,17 +34,26 @@
-
-
+ @@ -154,6 +163,14 @@ +function fnOpenTempFileUploadWindow(){ + window.open( + wctx.url("/resources/html/fileUpload.html") + ,"fileUpload" + ,'top=10, left=10, width=1000, height=500' + ); +} + function fnOpenMyInfo(){ window.open( wctx.url("/user/openMyInfo.do") @@ -368,5 +385,10 @@ $("#photoMask--top").on( "click", function() { fn_photoMask(false); } }); + +/*--------------------- 외부자료 파일 처리 ---------------------*/ +$("#btnOpenTempFileUploadWindow").on( "click", function() { + fnOpenTempFileUploadWindow(); +}); diff --git a/src/main/webapp/resources/html/fileUpload.html b/src/main/webapp/resources/html/fileUpload.html new file mode 100644 index 00000000..07402e1f --- /dev/null +++ b/src/main/webapp/resources/html/fileUpload.html @@ -0,0 +1,266 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +파일업로드 + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+ + +
+ +
+ + + + + +
+ +
+ +
+ +
+
+ +
+ + +
+ +
+ + +
+ + +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +