diff --git a/pom.xml b/pom.xml index 18a6daee..ffa7faff 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,11 @@ mariadb-java-client runtime + + kr.dogfoot + hwplib + 1.1.1 + diff --git a/src/main/java/cokr/xit/fims/base/FileController.java b/src/main/java/cokr/xit/fims/base/FileController.java index 25220279..b305c9f1 100644 --- a/src/main/java/cokr/xit/fims/base/FileController.java +++ b/src/main/java/cokr/xit/fims/base/FileController.java @@ -6,6 +6,7 @@ import java.io.StringWriter; import java.net.URISyntaxException; import java.net.URLDecoder; +import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.parsers.DocumentBuilder; @@ -28,10 +29,17 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import cokr.xit.base.file.dao.FileMapper; import cokr.xit.base.file.service.FileQuery; +import cokr.xit.base.file.service.bean.FileBean; @Controller public class FileController extends cokr.xit.base.file.web.FileController { + @Resource(name = "fileMapper") + private FileMapper fileMapper; + + @Resource(name="fileBean") + private FileBean fileBean; @GetMapping(name = "SVG 이미지 파일 색상 변경", value = "/modifySvg/**") public void modifySvg(HttpServletRequest request, HttpServletResponse response) throws URISyntaxException, IOException, ParserConfigurationException, SAXException { @@ -140,4 +148,5 @@ public class FileController extends cokr.xit.base.file.web.FileController { "file" ); } + } \ No newline at end of file diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java new file mode 100644 index 00000000..b162d84c --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -0,0 +1,12 @@ +package cokr.xit.fims.cmmn; + +public class CmmnUtil { + public static String escapeHTMLEntity(String str) { + str = str.replaceAll("<", "<"); + str = str.replaceAll(">", ">"); + str = str.replaceAll("&", "&"); + str = str.replaceAll(""", "\\\""); + str = str.replaceAll("#39;", "'"); + return str; + } +} diff --git a/src/main/java/cokr/xit/fims/crdn/CrdnQuery.java b/src/main/java/cokr/xit/fims/crdn/CrdnQuery.java index 5b72a867..17f9b4f3 100644 --- a/src/main/java/cokr/xit/fims/crdn/CrdnQuery.java +++ b/src/main/java/cokr/xit/fims/crdn/CrdnQuery.java @@ -18,7 +18,7 @@ public class CrdnQuery extends QueryRequest { private String mainOption; private String subOption; - + private String view; private String grid; private String thisDay; private String currentUserId; @@ -70,6 +70,15 @@ public class CrdnQuery extends QueryRequest { return self(); } + public String getView() { + return ifEmpty(view, () -> null); + } + + public T setView(String view) { + this.view = view; + return self(); + } + public String getGrid() { return ifEmpty(grid, () -> null); } diff --git a/src/main/java/cokr/xit/fims/crdn/dao/Crdn01Mapper.java b/src/main/java/cokr/xit/fims/crdn/dao/Crdn01Mapper.java index 95698656..d45c48a5 100644 --- a/src/main/java/cokr/xit/fims/crdn/dao/Crdn01Mapper.java +++ b/src/main/java/cokr/xit/fims/crdn/dao/Crdn01Mapper.java @@ -51,4 +51,10 @@ public interface Crdn01Mapper extends AbstractMapper { */ DataObject selectCivilComplaintOriginalInfo(CrdnQuery req); + /** 민원 원본을 조회한다. + * @param req 민원원본 조회 조건 + * @return 민원원본 + */ + DataObject selectCivilComplaintOriginalInfoHwp(CrdnQuery req); + } diff --git a/src/main/java/cokr/xit/fims/crdn/service/bean/Crdn01Bean.java b/src/main/java/cokr/xit/fims/crdn/service/bean/Crdn01Bean.java index 6dc0561a..43b266dd 100644 --- a/src/main/java/cokr/xit/fims/crdn/service/bean/Crdn01Bean.java +++ b/src/main/java/cokr/xit/fims/crdn/service/bean/Crdn01Bean.java @@ -29,6 +29,9 @@ public class Crdn01Bean extends AbstractComponent { } public DataObject getCivilComplaintOriginalInfo(CrdnQuery req) { + if(ifEmpty(req.getView(), () -> "").equals("hwp")) { + return crdn01Mapper.selectCivilComplaintOriginalInfoHwp(req); + } return crdn01Mapper.selectCivilComplaintOriginalInfo(req); } diff --git a/src/main/java/cokr/xit/fims/crdn/service/bean/Crdn01ServiceBean.java b/src/main/java/cokr/xit/fims/crdn/service/bean/Crdn01ServiceBean.java index c5845d94..b80b3864 100644 --- a/src/main/java/cokr/xit/fims/crdn/service/bean/Crdn01ServiceBean.java +++ b/src/main/java/cokr/xit/fims/crdn/service/bean/Crdn01ServiceBean.java @@ -1,16 +1,27 @@ package cokr.xit.fims.crdn.service.bean; +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; +import org.springframework.web.servlet.ModelAndView; +import cokr.xit.base.file.FileInfo; +import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.crdn.CrdnQuery; import cokr.xit.fims.crdn.dao.Crdn01Mapper; import cokr.xit.fims.crdn.service.CrdnService; import cokr.xit.foundation.component.AbstractServiceBean; import cokr.xit.foundation.data.DataObject; +import kr.dogfoot.hwplib.object.HWPFile; +import kr.dogfoot.hwplib.reader.HWPReader; +import kr.dogfoot.hwplib.tool.objectfinder.FieldFinder; +import kr.dogfoot.hwplib.writer.HWPWriter; /**민원 관리 서비스 인터페이스의 구현체 * @author leebj @@ -47,5 +58,70 @@ public class Crdn01ServiceBean extends AbstractServiceBean implements CrdnServic return crdn01Bean.removeCivilComplaint(crdnIDs); } + public ModelAndView makeFileFromHwpFormat(CrdnQuery crdnQuery) { + crdnQuery.setView("hwp"); + DataObject dataObject = crdn01Bean.getCivilComplaintOriginalInfo(crdnQuery); + SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + SimpleDateFormat ymdFormat = new SimpleDateFormat("yyyyMMdd"); + SimpleDateFormat ymdHypenFormat = new SimpleDateFormat("yyyy-MM-dd"); + + String formatFilePath = "files" + File.separator + "format" + File.separator + "cvlcptOrgnl.hwp"; + + HWPFile hwpFile; + try { + hwpFile = HWPReader.fromFile(formatFilePath); + + ArrayList strings = new ArrayList(); + strings.add(dataObject.string("CVLCPT_APLCNT_NM")); + FieldFinder.setClickHereText(hwpFile, "신청자", strings); + + strings = new ArrayList(); + String cvlcptRcptYmd = dataObject.string("CVLCPT_RCPT_YMD"); + cvlcptRcptYmd = ymdHypenFormat.format(ymdFormat.parse(cvlcptRcptYmd)); + strings.add(cvlcptRcptYmd); + FieldFinder.setClickHereText(hwpFile, "접수일자", strings); + + strings = new ArrayList(); + String cvlcptRrcsPrnmntDt = dataObject.string("CVLCPT_PRCS_PRNMNT_DT"); + cvlcptRrcsPrnmntDt = ymdHypenFormat.format(ymdFormat.parse(cvlcptRrcsPrnmntDt)); + strings.add(cvlcptRrcsPrnmntDt); + FieldFinder.setClickHereText(hwpFile, "처리기한", strings); + + strings = new ArrayList(); + strings.add(dataObject.string("CVLCPT_RCPT_NO")); + FieldFinder.setClickHereText(hwpFile, "접수번호", strings); + + strings = new ArrayList(); + String cvlcptAplyCn = dataObject.string("CVLCPT_APLY_CN"); + cvlcptAplyCn = CmmnUtil.escapeHTMLEntity(cvlcptAplyCn); + strings.add(cvlcptAplyCn); + FieldFinder.setClickHereText(hwpFile, "민원내용", strings); + + //TODO : 사진삽입 + + String currentTime = ymdhmsFormat.format(new Date()); + String resultPath = "files" + File.separator + "result" + File.separator + currentTime + ".hwp"; + HWPWriter.toFile(hwpFile, resultPath); + + FileInfo fileInfo = new FileInfo(); + fileInfo.setPath(resultPath); + fileInfo.setName(currentTime+".hwp"); + fileInfo.setMimeType("application/vnd.hancom.hwpx"); + fileInfo.setExtension("hwp"); + fileInfo.setSize(new File(resultPath).length()); + + String downlaodFileName = "민원내역원본_" + currentTime + ".hwp"; + + ModelAndView mav = new ModelAndView("jsonView"); + mav.addObject("filePath", resultPath); + mav.addObject("fileName", downlaodFileName); + return mav; + } catch (Exception e) { + + return new ModelAndView("errorView"); + + } + } + } diff --git a/src/main/java/cokr/xit/fims/crdn/web/Crdn01Controller.java b/src/main/java/cokr/xit/fims/crdn/web/Crdn01Controller.java index b033ce97..877b1eb2 100644 --- a/src/main/java/cokr/xit/fims/crdn/web/Crdn01Controller.java +++ b/src/main/java/cokr/xit/fims/crdn/web/Crdn01Controller.java @@ -174,4 +174,12 @@ public class Crdn01Controller extends ApplicationController { return new ModelAndView("jsonView") .addObject("saved", saved); } + + /** 민원내역 원본을 한글 파일로 작성한다. + * @return hwp파일 + */ + @RequestMapping(name="민원내역 원본 한글 파일 생성", value="/050/makeFileFromHwpFormat.do") + public ModelAndView makeFileFromHwpFormat(CrdnQuery crdnQuery) { + return crdn01Service.makeFileFromHwpFormat(crdnQuery); + } } diff --git a/src/main/resources/sql/mapper/fims/crdn/crdn01-mapper.xml b/src/main/resources/sql/mapper/fims/crdn/crdn01-mapper.xml index 4497b7b4..44583d16 100644 --- a/src/main/resources/sql/mapper/fims/crdn/crdn01-mapper.xml +++ b/src/main/resources/sql/mapper/fims/crdn/crdn01-mapper.xml @@ -255,6 +255,7 @@ SELECT C.CRDN_ID + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn01050-info.jsp b/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn01050-info.jsp index 7dc755bc..716ac977 100644 --- a/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn01050-info.jsp +++ b/src/main/webapp/WEB-INF/jsp/fims/crdn/crdn01050-info.jsp @@ -36,6 +36,10 @@ +
+ +
+