pdf정보추출, 전자고지발송정보 등록 수정

main
이범준 10 months ago
parent 19553ee51b
commit e6acf793c8

@ -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 extends ExtrStngQuery> T setTemplateId(String templateId) {
this.templateId = templateId;
return self();
}
}

@ -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<DataObject> selectExtrArtclStngList(ExtrStngQuery extrStngQuery);
DataObject selectExtrBscStng(ExtrStngQuery extrStngQuery);
}

@ -1,6 +1,7 @@
package cokr.xit.fims.cmmn.pdf.extration; package cokr.xit.fims.cmmn.pdf.extration;
import java.util.List; import java.util.List;
import java.util.Map;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -13,13 +14,16 @@ public class Extraction {
* *
*/ */
int page; int page;
/**
*
*/
String epayNo;
/** /**
* base64 * base64
*/ */
List<String> base64List; List<String> base64List;
/**
*
*/
Map<String, String> textItem;
} }

@ -3,15 +3,21 @@ package cokr.xit.fims.cmmn.pdf.extration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.pdfbox.Loader; import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageTree; import org.apache.pdfbox.pdmodel.PDPageTree;
import cokr.xit.fims.cmmn.PrintUtil;
import cokr.xit.foundation.data.DataObject;
public class PDFExtractionUtil { public class PDFExtractionUtil {
public static List<Extraction> extract(String pdfPath, String taskSeCd, String templateId) { public static List<Extraction> extract(String pdfPath, List<DataObject> extractStngs) {
PrintUtil printUtil = new PrintUtil();
List<Extraction> extractList = new ArrayList<Extraction>(); List<Extraction> extractList = new ArrayList<Extraction>();
@ -38,13 +44,23 @@ public class PDFExtractionUtil {
for(;pageIndex < pageCount; pageIndex++) { for(;pageIndex < pageCount; pageIndex++) {
Map<String,String> textItem = new HashMap<String,String>();
extraction = new Extraction(); extraction = new Extraction();
extraction.setPage(pageIndex+1); extraction.setPage(pageIndex+1);
//설정 = mapper.get설정(query.setSggCd().setTaskSeCd(taskSeCd).setTemplateId(templateId)); for(DataObject extractStng : extractStngs) {
String epayNo = ExtractText.getExtractByStng(pdDocument, pageIndex+1, 0, 0, 100, 100);
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); PDPage page = pages.get(pageIndex);

@ -1,6 +1,8 @@
package cokr.xit.fims.cmmn.service.bean; package cokr.xit.fims.cmmn.service.bean;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -38,4 +40,36 @@ public class LinkBean extends AbstractComponent {
return true; return true;
} }
public String makeJson(String jsonTemplate, Map<String, String> extractedText, List<String> crdnPhotoBase64) {
String result = jsonTemplate;
Iterator<String> 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;
}
} }

@ -1,6 +1,7 @@
package cokr.xit.fims.cmmn.web; package cokr.xit.fims.cmmn.web;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -8,6 +9,8 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; 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.Extraction;
import cokr.xit.fims.cmmn.pdf.extration.PDFExtractionUtil; import cokr.xit.fims.cmmn.pdf.extration.PDFExtractionUtil;
import cokr.xit.fims.cmmn.service.bean.LinkBean; import cokr.xit.fims.cmmn.service.bean.LinkBean;
@ -26,6 +29,9 @@ public class LinkController extends AbstractController {
@Resource(name = "factionBean") @Resource(name = "factionBean")
private FactionBean factionBean; private FactionBean factionBean;
@Resource(name = "extrStngMapper")
private ExtrStngMapper extrStngMapper;
@RequestMapping(name = "파일 처리", value = "/fileProcess.do") @RequestMapping(name = "파일 처리", value = "/fileProcess.do")
public ModelAndView fileProcess(String filePath, String job, String param) { public ModelAndView fileProcess(String filePath, String job, String param) {
ModelAndView mav = new ModelAndView("jsonView"); ModelAndView mav = new ModelAndView("jsonView");
@ -44,28 +50,52 @@ public class LinkController extends AbstractController {
String tmplatId = dataObject.string("tmplatId"); String tmplatId = dataObject.string("tmplatId");
String taskSeCd = dataObject.string("taskSeCd"); String taskSeCd = dataObject.string("taskSeCd");
List<Extraction> extractionInfos = PDFExtractionUtil.extract(filePath, taskSeCd, tmplatId); ExtrStngQuery extrStngQuery = new ExtrStngQuery();
extrStngQuery.setSggCd(sggCd).setTaskSeCd(taskSeCd);
extrStngQuery.setTemplateId(tmplatId);
List<DataObject> extractStngs = extrStngMapper.selectExtrArtclStngList(extrStngQuery);
List<Extraction> extractionInfos = PDFExtractionUtil.extract(filePath, extractStngs);
for(int i=0; i < extractionInfos.size(); i++) { for(int i=0; i < extractionInfos.size(); i++) {
Map<String, String> extractedText = extractionInfos.get(i).getTextItem();
List<String> crdnPhotoBase64 = extractionInfos.get(i).getBase64List();
//마스터
DataObject masterInfo = new DataObject(); DataObject masterInfo = new DataObject();
masterInfo.set("signguCode", sggCd); masterInfo.set("signguCode", sggCd);
masterInfo.set("ffnlgCode", taskSeCd); masterInfo.set("ffnlgCode", taskSeCd);
masterInfo.set("tmplatId", tmplatId); masterInfo.set("tmplatId", tmplatId);
masterInfo.set("sndngCo", extractionInfos.size()); masterInfo.set("sndngCo", extractionInfos.size());
//발송일시! masterInfo.set("sndngDt", extractedText.get("sndngDt")); //발송일시
//마감일시! masterInfo.set("closDt", extractedText.get("closDt")); //마감일시
//디테일
DataObject detailInfo = new DataObject(); DataObject detailInfo = new DataObject();
detailInfo.set("signguCode", sggCd); 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? 전자납부번호? String jsonTemplate = extrStngMapper.selectExtrBscStng(extrStngQuery).string("MOBILE_PAGE_TMPLT");
//masterInfo.set("useInsttIdntfcId", ); //통합플랫폼 발송id? String json = linkBean.makeJson(jsonTemplate, extractedText, crdnPhotoBase64);
detailInfo.set("mobilePageCn", json);
//
detailInfo.set("mainCode", "");
//
detailInfo.set("useInsttIdntfcId", "");
//테이블 인서트
linkBean.insertElectronicNoticeSndng(masterInfo, List.of(detailInfo)); linkBean.insertElectronicNoticeSndng(masterInfo, List.of(detailInfo));
} }

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cokr.xit.fims.cmmn.dao.ExtrStngMapper">
<select id="selectExtrArtclStngList" parameterType="cokr.xit.fims.cmmn.ExtrStngQuery" resultType="dataobject">
/* 추출 항목 설정 조회(otptStngMapper.selectExtrArtclStngList) */
SELECT EXTR_FORM_ID
, SGG_CD
, TASK_SE_CD
, TMPLAT_ID
, EXTR_ARTCL_NM
, EXTR_ARTCL_DSCRT
, LEFT_PSTN
, TOP_PSTN
, WIDTH_SZ
, HEIGHT_SZ
FROM TB_EXTR_FORM_STNG
WHERE USE_YN = 'Y'
AND SGG_CD = #{sggCd}
AND TASK_SE_CD = #{taskSeCd}
AND TMPLAT_ID = #{templateId}
</select>
<select id="selectExtrBscStng" parameterType="cokr.xit.fims.cmmn.ExtrStngQuery" resultType="dataobject">
/* 추출 기본 설정 조회(otptStngMapper.selectExtrBscStng) */
SELECT EXTR_BSC_ID
, SGG_CD
, TASK_SE_CD
, MOBILE_PAGE_TMPLT
FROM TB_EXTR_BSC_STNG
WHERE USE_YN = 'Y'
AND SGG_CD = #{sggCd}
AND TASK_SE_CD = #{taskSeCd}
AND TMPLAT_ID = #{templateId}
</select>
</mapper>
Loading…
Cancel
Save