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 @@