diff --git a/pom.xml b/pom.xml index d6a3dff9..aa5d2e86 100644 --- a/pom.xml +++ b/pom.xml @@ -89,6 +89,14 @@ 0.5 + + + + net.lingala.zip4j + zip4j + 2.11.5 + + diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java index 762e1c79..eb5f2c86 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -1,5 +1,7 @@ package cokr.xit.fims.cmmn; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -21,7 +23,12 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import javax.imageio.ImageIO; + +import org.apache.commons.io.FilenameUtils; + import cokr.xit.fims.sndb.service.bean.SndngBean; +import cokr.xit.foundation.data.DataObject; public class CmmnUtil { @@ -59,6 +66,63 @@ public class CmmnUtil { return Pattern.matches(REGEXP_PATTERN_KOR, str); } + /** + * 순서를 숫자에서 알파벳대문자로 변환한다. + * @param index 순서번호, startFromZero 0부터시작(또는 1부터 시작) + * @return 알파벳대문자(A~Z) + */ + public static String indexToAlphabet(int index, boolean startFromZero) { + int charCode = 64; + + charCode += index; + + if(startFromZero) { + charCode++; + } + + if(charCode < 65 || charCode > 90) { + return ""; + } + + return ""+(char)charCode; + } + + /** + * 확장자가 포함된 파일명에 추가 문자열을 더한 파일명을 반환한다. + * @param orgnFileName 원본파일명, append 추가 문자열 + * @return 변환된 파일명 + */ + public static String appendFileName(String orgnFileName, String append) { + return FilenameUtils.removeExtension(orgnFileName) + append + "." + FilenameUtils.getExtension(orgnFileName); + } + + /** + * 모자이크 처리된 이미지파일을 생성한다. + * @param source 원본파일, target 결과파일, mosaicInfos 모자이크 정보 + * @return + */ + public static void createMaskedImage(File source, File target, List mosaicInfos) { + + BufferedImage buffer_black_image = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR); + String extension = FilenameUtils.getExtension(target.getName()); + try { + + BufferedImage buffer_original_image = ImageIO.read(source); + Graphics2D graphic = buffer_original_image.createGraphics(); + for(DataObject mosaicInfo : mosaicInfos){ + int mosaicX = mosaicInfo.number("X_AXS").intValue(); + int mosaicY = mosaicInfo.number("Y_AXS").intValue(); + int mosaicWidth = mosaicInfo.number("MOSC_LT").intValue(); + int mosaicHeight = mosaicInfo.number("MOSC_HG").intValue(); + graphic.drawImage(buffer_black_image, mosaicX, mosaicY, mosaicWidth, mosaicHeight, null); + } + + ImageIO.write(buffer_original_image, extension, target); + } catch (IOException e) { + throw new RuntimeException("이미지 모자이크 처리 중 오류가 발생하였습니다."); + } + + } /** * 하위 폴더가 비워져 있으면 삭제한다. @@ -358,4 +422,5 @@ public class CmmnUtil { return band6; } + } diff --git a/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java b/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java index 15f174b9..c9137869 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java +++ b/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java @@ -1,8 +1,16 @@ package cokr.xit.fims.sprt.service.bean; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Comparator; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -22,6 +30,8 @@ import org.springframework.stereotype.Service; import cokr.xit.base.file.service.FileQuery; import cokr.xit.base.file.service.bean.FileBean; +import cokr.xit.fims.cmmn.CmmnUtil; +import cokr.xit.fims.cmmn.Hangul; import cokr.xit.fims.cmmn.hwp.AddUtil; import cokr.xit.fims.cmmn.hwp.HWPFormatWriter; import cokr.xit.fims.cmmn.hwp.HWPPrintUtil; @@ -37,6 +47,7 @@ import cokr.xit.fims.cmmn.pdf.PstnAndSize; import cokr.xit.fims.cmmn.pdf.format.Advntce; import cokr.xit.fims.cmmn.pdf.format.Nht; import cokr.xit.fims.cmmn.service.bean.FactionBean; +import cokr.xit.fims.cmmn.service.bean.MosaicBean; import cokr.xit.fims.cmmn.service.bean.StngBean; import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.CrdnQuery; @@ -53,6 +64,7 @@ import cokr.xit.foundation.data.DataObject; import kr.dogfoot.hwplib.object.HWPFile; import kr.dogfoot.hwplib.reader.HWPReader; import kr.dogfoot.hwplib.writer.HWPWriter; +import net.lingala.zip4j.ZipFile; /**통합 조회 서비스 구현체. * @@ -89,6 +101,9 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv @Resource(name = "otptStngMapper") protected OtptStngMapper otptStngMapper; + @Resource(name="mosaicBean") + private MosaicBean mosaicBean; + @Override public List getIntegrationDataList(SprtQuery query) { return sprt01Bean.getIntegrationDataList(query); @@ -511,9 +526,115 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv @Override public Map makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds) { - return null; - } + Map result = new HashMap<>(); + + Hangul hangul = new Hangul(2); + + SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String currentTime = ymdhmsFormat.format(new Date()); + String year = currentTime.substring(0, 4); + String month = currentTime.substring(4, 6); + String day = currentTime.substring(6, 8); + String yyyymmdd = year+month+day; + + String outsourcingResultPath = "files"+File.separator+"result"+File.separator+"outsourcing" + + File.separator + year + File.separator + month + File.separator + day + + File.separator + currentTime; + + File folder = new File(outsourcingResultPath); + if(!folder.exists()) { + folder.mkdirs(); + } + + String printKorName = "사전통지"; + + try { + SprtQuery sprtQuery = new SprtQuery(); + sprtQuery.setCrdnIDs(crdnIds); + List dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery); + + String imagesFolderName = yyyymmdd + printKorName; + String metaFileName = yyyymmdd + printKorName + "(외주파일).txt"; + + String imagesFolderPath = outsourcingResultPath + File.separator + imagesFolderName; + String metaFilePath = outsourcingResultPath + File.separator + metaFileName; + + + for(int i=0; i < dataObjectList.size(); i++) { + DataObject dataObject = dataObjectList.get(i); + + FileQuery fileQuery = new FileQuery(); + fileQuery.setInfoType(Crdn.INF_TYPE); + fileQuery.setInfoKeys(dataObject.string("CRDN_ID")); + List fileInfoList = fileBean.getFileList(fileQuery); + if(fileInfoList == null) { + fileInfoList = new ArrayList(); + } + for(int j=0; j < fileInfoList.size(); j++){ + DataObject fileInfo = fileInfoList.get(j); + List mosaicInfos = mosaicBean.getMosaicList(fileInfo.string("FILE_ID")); + + File orgnFile = new File(fileInfo.string("FILE_PATH")); + + String modifiedFileName = "P"+fileInfo.string("INF_KEY")+CmmnUtil.indexToAlphabet(j, true)+"."+"JPG"; + String modifiedFilePath = imagesFolderPath + File.separator + modifiedFileName; + File modifiedFile = new File(modifiedFilePath); + + if(mosaicInfos != null) { + CmmnUtil.createMaskedImage(orgnFile, modifiedFile, mosaicInfos); + } else { + Files.copy(orgnFile.toPath(), modifiedFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + dataObject.set("CRDN_PHOTO"+(j+1), modifiedFilePath); + } + + } + + File file = new File(metaFilePath); + if (!file.exists()) { + file.createNewFile(); + } + FileWriter fw = new FileWriter(file); + BufferedWriter writer = new BufferedWriter(fw); + + //외주파일 설정 + List printItems = new ArrayList(); + + for(int i=0; i < dataObjectList.size(); i++) { + DataObject dataObject = dataObjectList.get(i); + + if(i != 0) { + writer.write("\n"); + } + String line = ""; + for(DataObject printItem : printItems){ + String colNm = printItem.string("COL_NM"); + int byteCnt = printItem.number("BYTE_CNT").intValue(); + line += hangul.rpadByte(dataObject.string(colNm), byteCnt, " "); + } + writer.write(line); + } + + writer.close(); + + String zipFileName = yyyymmdd + printKorName + ".zip"; + String zipFilePath = outsourcingResultPath + File.separator + zipFileName; + + ZipFile zipFile = new ZipFile(zipFilePath); + zipFile.addFile(new File(metaFilePath)); + zipFile.addFolder(new File(imagesFolderPath)); + zipFile.close(); + + result.put("filePath", zipFilePath); + result.put("fileName", zipFileName); + + } catch (IOException e) { + throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다."); + } + + return result; + } }