diff --git a/src/main/java/cokr/xit/fims/cmmn/ExtrStngQuery.java b/src/main/java/cokr/xit/fims/cmmn/ExtrStngQuery.java new file mode 100644 index 00000000..8a993a77 --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/ExtrStngQuery.java @@ -0,0 +1,18 @@ +package cokr.xit.fims.cmmn; + +public class ExtrStngQuery extends CmmnQuery { + + private static final long serialVersionUID = 1L; + + private String templateId; + + public String getTemplateId() { + return ifEmpty(templateId, () -> null); + } + + public T setTemplateId(String templateId) { + this.templateId = templateId; + return self(); + } + +} diff --git a/src/main/java/cokr/xit/fims/cmmn/dao/ExtrStngMapper.java b/src/main/java/cokr/xit/fims/cmmn/dao/ExtrStngMapper.java new file mode 100644 index 00000000..ed28b233 --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/dao/ExtrStngMapper.java @@ -0,0 +1,18 @@ +package cokr.xit.fims.cmmn.dao; + +import java.util.List; + +import org.egovframe.rte.psl.dataaccess.mapper.Mapper; + +import cokr.xit.fims.cmmn.ExtrStngQuery; +import cokr.xit.foundation.component.AbstractMapper; +import cokr.xit.foundation.data.DataObject; + +@Mapper("extrStngMapper") +public interface ExtrStngMapper extends AbstractMapper { + + List selectExtrArtclStngList(ExtrStngQuery extrStngQuery); + + DataObject selectExtrBscStng(ExtrStngQuery extrStngQuery); + +} diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/extration/Extraction.java b/src/main/java/cokr/xit/fims/cmmn/pdf/extration/Extraction.java index 827cd147..0210002c 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/extration/Extraction.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/extration/Extraction.java @@ -1,6 +1,7 @@ package cokr.xit.fims.cmmn.pdf.extration; import java.util.List; +import java.util.Map; import lombok.Getter; import lombok.Setter; @@ -13,13 +14,16 @@ public class Extraction { * 페이지번호 */ int page; - /** - * 전자납부번호 - */ - String epayNo; + /** * 단속사진 base64 문자열 */ List base64List; + /** + * 텍스트 항목 + */ + Map textItem; + + } diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/extration/PDFExtractionUtil.java b/src/main/java/cokr/xit/fims/cmmn/pdf/extration/PDFExtractionUtil.java index 5b592029..88a6c854 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/extration/PDFExtractionUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/extration/PDFExtractionUtil.java @@ -3,15 +3,21 @@ package cokr.xit.fims.cmmn.pdf.extration; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.pdfbox.Loader; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageTree; +import cokr.xit.fims.cmmn.PrintUtil; +import cokr.xit.foundation.data.DataObject; + public class PDFExtractionUtil { - public static List extract(String pdfPath, String taskSeCd, String templateId) { + public static List extract(String pdfPath, List extractStngs) { + PrintUtil printUtil = new PrintUtil(); List extractList = new ArrayList(); @@ -38,13 +44,23 @@ public class PDFExtractionUtil { for(;pageIndex < pageCount; pageIndex++) { + Map textItem = new HashMap(); + extraction = new Extraction(); extraction.setPage(pageIndex+1); - //설정 = mapper.get설정(query.setSggCd().setTaskSeCd(taskSeCd).setTemplateId(templateId)); - String epayNo = ExtractText.getExtractByStng(pdDocument, pageIndex+1, 0, 0, 100, 100); + for(DataObject extractStng : extractStngs) { + + float x = printUtil.mmToPt(extractStng.number("LEFT_PSTN").floatValue()); + float y = printUtil.mmToPt(extractStng.number("TOP_PSTN").floatValue()); + float w = printUtil.mmToPt(extractStng.number("WIDTH_SZ").floatValue()); + float h = printUtil.mmToPt(extractStng.number("HEIGHT_SZ").floatValue()); + + String text0 = ExtractText.getExtractByStng(pdDocument, pageIndex+1, x, y, w, h); + textItem.put(extractStng.string("EXTR_ARTCL_NM"), text0); + } - extraction.setEpayNo(epayNo); + extraction.setTextItem(textItem); PDPage page = pages.get(pageIndex); diff --git a/src/main/java/cokr/xit/fims/cmmn/service/bean/LinkBean.java b/src/main/java/cokr/xit/fims/cmmn/service/bean/LinkBean.java index d4bcb68c..8cb5cf44 100644 --- a/src/main/java/cokr/xit/fims/cmmn/service/bean/LinkBean.java +++ b/src/main/java/cokr/xit/fims/cmmn/service/bean/LinkBean.java @@ -1,6 +1,8 @@ package cokr.xit.fims.cmmn.service.bean; +import java.util.Iterator; import java.util.List; +import java.util.Map; import javax.annotation.Resource; @@ -38,4 +40,36 @@ public class LinkBean extends AbstractComponent { return true; } + + public String makeJson(String jsonTemplate, Map extractedText, List crdnPhotoBase64) { + String result = jsonTemplate; + + Iterator it = extractedText.keySet().iterator(); + while(it.hasNext()) { + String key = it.next(); + String value = extractedText.get(key); + + result = result.replaceAll("^##"+key+"##$", value); + } + + + int i=0; + if(result.contains("##photo0##")) { + boolean flag = true; + while(flag) { + String value = ""; + if((i+1) <= crdnPhotoBase64.size()) { + value = crdnPhotoBase64.get(i); + } + result = result.replaceAll("^##photo"+i+"##$", value); + + i++; + if(!result.contains("##photo"+i+"##")) { + flag = false; + } + } + } + + return result; + } } diff --git a/src/main/java/cokr/xit/fims/cmmn/web/LinkController.java b/src/main/java/cokr/xit/fims/cmmn/web/LinkController.java index 29fd6a75..1f338358 100644 --- a/src/main/java/cokr/xit/fims/cmmn/web/LinkController.java +++ b/src/main/java/cokr/xit/fims/cmmn/web/LinkController.java @@ -1,6 +1,7 @@ package cokr.xit.fims.cmmn.web; import java.util.List; +import java.util.Map; import javax.annotation.Resource; @@ -8,6 +9,8 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; +import cokr.xit.fims.cmmn.ExtrStngQuery; +import cokr.xit.fims.cmmn.dao.ExtrStngMapper; import cokr.xit.fims.cmmn.pdf.extration.Extraction; import cokr.xit.fims.cmmn.pdf.extration.PDFExtractionUtil; import cokr.xit.fims.cmmn.service.bean.LinkBean; @@ -26,6 +29,9 @@ public class LinkController extends AbstractController { @Resource(name = "factionBean") private FactionBean factionBean; + @Resource(name = "extrStngMapper") + private ExtrStngMapper extrStngMapper; + @RequestMapping(name = "파일 처리", value = "/fileProcess.do") public ModelAndView fileProcess(String filePath, String job, String param) { ModelAndView mav = new ModelAndView("jsonView"); @@ -44,28 +50,52 @@ public class LinkController extends AbstractController { String tmplatId = dataObject.string("tmplatId"); String taskSeCd = dataObject.string("taskSeCd"); - List extractionInfos = PDFExtractionUtil.extract(filePath, taskSeCd, tmplatId); + ExtrStngQuery extrStngQuery = new ExtrStngQuery(); + extrStngQuery.setSggCd(sggCd).setTaskSeCd(taskSeCd); + extrStngQuery.setTemplateId(tmplatId); + List extractStngs = extrStngMapper.selectExtrArtclStngList(extrStngQuery); + + List extractionInfos = PDFExtractionUtil.extract(filePath, extractStngs); for(int i=0; i < extractionInfos.size(); i++) { + Map extractedText = extractionInfos.get(i).getTextItem(); + List crdnPhotoBase64 = extractionInfos.get(i).getBase64List(); + + //마스터 DataObject masterInfo = new DataObject(); masterInfo.set("signguCode", sggCd); masterInfo.set("ffnlgCode", taskSeCd); masterInfo.set("tmplatId", tmplatId); masterInfo.set("sndngCo", extractionInfos.size()); - //발송일시! - //마감일시! - + masterInfo.set("sndngDt", extractedText.get("sndngDt")); //발송일시 + masterInfo.set("closDt", extractedText.get("closDt")); //마감일시 + //디테일 DataObject detailInfo = new DataObject(); detailInfo.set("signguCode", sggCd); - masterInfo.set("ffnlgCode", taskSeCd); + detailInfo.set("ffnlgCode", taskSeCd); + detailInfo.set("vhcleNo", extractedText.get("vhcleNo")); + detailInfo.set("ihidnum", extractedText.get("ihidnum")); + detailInfo.set("moblphonNo", extractedText.get("moblphonNo")); + detailInfo.set("nm", extractedText.get("nm")); + detailInfo.set("adres", extractedText.get("adres")); + detailInfo.set("detailAdres", extractedText.get("detailAdres")); + detailInfo.set("zip", extractedText.get("zip")); + + //템플릿메시지데이터 + detailInfo.set("tmpltMsgData", ""); - //차량번호,주민등록번호,핸드폰번호,성명,주소,상세주소,우편번호 - //mmdd //모바일페이지 - //masterInfo.set("mainCode", ); //통합플랫폼 단속id? 전자납부번호? - //masterInfo.set("useInsttIdntfcId", ); //통합플랫폼 발송id? + String jsonTemplate = extrStngMapper.selectExtrBscStng(extrStngQuery).string("MOBILE_PAGE_TMPLT"); + String json = linkBean.makeJson(jsonTemplate, extractedText, crdnPhotoBase64); + detailInfo.set("mobilePageCn", json); + + // + detailInfo.set("mainCode", ""); + // + detailInfo.set("useInsttIdntfcId", ""); + //테이블 인서트 linkBean.insertElectronicNoticeSndng(masterInfo, List.of(detailInfo)); } diff --git a/src/main/resources/sql/mapper/fims/cmmn/extrStng-mapper.xml b/src/main/resources/sql/mapper/fims/cmmn/extrStng-mapper.xml new file mode 100644 index 00000000..bd7deb10 --- /dev/null +++ b/src/main/resources/sql/mapper/fims/cmmn/extrStng-mapper.xml @@ -0,0 +1,37 @@ + + + + + + + + + \ No newline at end of file