diff --git a/src/main/java/cokr/xit/base/file/etc/OutsourcingFileWriter.java b/src/main/java/cokr/xit/base/file/etc/OutsourcingFileWriter.java new file mode 100644 index 00000000..610f155e --- /dev/null +++ b/src/main/java/cokr/xit/base/file/etc/OutsourcingFileWriter.java @@ -0,0 +1,146 @@ +package cokr.xit.base.file.etc; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +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.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.egovframe.rte.fdl.string.EgovStringUtil; + +import cokr.xit.fims.cmmn.CmmnUtil; +import cokr.xit.fims.cmmn.Hangul; +import cokr.xit.fims.sprt.PrintOption; +import cokr.xit.foundation.data.DataObject; +import net.lingala.zip4j.ZipFile; + +public class OutsourcingFileWriter { + + + + public Map makeOutsourcingFile(String printKorName, PrintOption printOption, + List dataObjectList, List printStngItems) { + 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(); + } + + try { + + + String imagesFolderName = yyyymmdd + printKorName; + String metaFileName = yyyymmdd + printKorName + "(외주파일).txt"; + + String imagesFolderPath = outsourcingResultPath + File.separator + imagesFolderName; + String metaFilePath = outsourcingResultPath + File.separator + metaFileName; + + File imagesFolderPathFile = new File(imagesFolderPath); + if (!imagesFolderPathFile.exists()) { + imagesFolderPathFile.mkdirs(); + } + + for(int i=0; i < dataObjectList.size(); i++) { + DataObject dataObject = dataObjectList.get(i); + int crdnPhotoCnt = dataObject.number("CRDN_PHOTO_CNT").intValue(); + + for(int j=0; j < crdnPhotoCnt; j++){ + String orgnFilePath = dataObject.string("CRDN_PHOTO"+(j+1)); + String fileKey = dataObject.string("CRDN_PHOTO"+(j+1)+"KEY"); + + if(EgovStringUtil.null2void(orgnFilePath).equals("")) { + continue; + } + + if(!orgnFilePath.startsWith("files")) { + orgnFilePath = CmmnUtil.copyStaticResource(orgnFilePath, false); + } + + File orgnFile = new File(orgnFilePath); + if(!orgnFile.exists() || !orgnFile.canRead()) { + continue; + } + InputStream orgnFileInputStream = new FileInputStream(orgnFile); + + String modifiedFileName = "P"+fileKey+CmmnUtil.indexToAlphabet(j, true, true)+"."+"JPG"; + + String modifiedFilePath = imagesFolderPath + File.separator + modifiedFileName; + + File modifiedFile = new File(modifiedFilePath); + + if(dataObject.get("MOS"+fileKey) != null) { + CmmnUtil.createMaskedImage(orgnFileInputStream, modifiedFile, (List)dataObject.get("MOS"+fileKey)); + } else { + Files.copy(orgnFileInputStream, 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); + + + for(int i=0; i < dataObjectList.size(); i++) { + DataObject dataObject = dataObjectList.get(i); + + if(i != 0) { + writer.write("\n"); + } + String line = ""; + for(DataObject printStngItem : printStngItems){ + String colNm = printStngItem.string("COL_NM"); + int byteCnt = printStngItem.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("filename", zipFileName); + result.put("filePath", zipFilePath); + result.put("file", new File(zipFilePath)); + + } catch (IOException e) { + throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다."); + } + + return result; + } +} diff --git a/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java b/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java index 6dfae144..0e2dc017 100644 --- a/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java +++ b/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java @@ -12,6 +12,7 @@ import org.apache.poi.ss.usermodel.CellStyle; import org.springframework.web.servlet.ModelAndView; import cokr.xit.base.code.CommonCode; +import cokr.xit.base.file.etc.OutsourcingFileWriter; import cokr.xit.base.file.hwp.HWPWriter; import cokr.xit.base.file.pdf.PDFWriter; import cokr.xit.base.file.service.FileQuery; @@ -1760,8 +1761,43 @@ public class Sndb01Controller extends ApplicationController { for (int iLoop = 0; iLoop < list.size(); iLoop++) { crdnIds[iLoop] = list.get(iLoop).string("CRDN_ID"); } + SprtQuery sprtQuery = new SprtQuery(); + sprtQuery.setCrdnIds(crdnIds); + List dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery); + 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) { + int crdnPhotoCnt = fileInfoList.size(); + for(int j=0; j < fileInfoList.size(); j++) { + DataObject fileInfo = fileInfoList.get(j); + + dataObject.set("CRDN_PHOTO"+(j+1), fileInfo.string("FILE_PATH")); + dataObject.set("CRDN_PHOTO"+(j+1)+"KEY", fileInfo.string("FILE_ID")); + List mosSet = mediaBean.getMosaicList(fileInfo.string("FILE_ID")); + if(mosSet != null) { + for(int k=0; k < mosSet.size(); k++) { + dataObject.set("MOS"+fileInfo.string("FILE_ID"), mosSet); + } + } + } + dataObject.set("CRDN_PHOTO_CNT", crdnPhotoCnt); + } else { + dataObject.set("CRDN_PHOTO_CNT", 0); + } + + } + + List printStngItems = new ArrayList(); + + OutsourcingFileWriter osWriter = new OutsourcingFileWriter(); - Map result = integrationSearchService.makeOutsourcingFile("advntce", printOption, crdnIds); + Map result = osWriter.makeOutsourcingFile("사전통지", printOption, dataObjectList, printStngItems); mav.addAllObjects(result); diff --git a/src/main/java/cokr/xit/fims/sprt/service/IntegrationSearchService.java b/src/main/java/cokr/xit/fims/sprt/service/IntegrationSearchService.java index f58b1d01..2d14e0a8 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/IntegrationSearchService.java +++ b/src/main/java/cokr/xit/fims/sprt/service/IntegrationSearchService.java @@ -1,9 +1,7 @@ package cokr.xit.fims.sprt.service; import java.util.List; -import java.util.Map; -import cokr.xit.fims.sprt.PrintOption; import cokr.xit.fims.sprt.SprtQuery; import cokr.xit.foundation.data.DataObject; @@ -31,15 +29,4 @@ public interface IntegrationSearchService { */ String updateEtcCn(String etcCn, String... crdnIds); - - /** 외주요청 파일을 생성한다. - * @param formatName 서식명, printOption 출력옵션, crdnIds 출력대상 - * @return map 출력 요청 결과 - *
  • filename: 다운로드 파일명
  • - *
  • filePath: 결과 파일 경로
  • - *
  • file: 결과 파일
  • - *
- */ - Map makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds); - } diff --git a/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java b/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java index b5ee644a..3a9ed972 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java +++ b/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java @@ -1,40 +1,21 @@ package cokr.xit.fims.sprt.service.bean; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -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.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.annotation.Resource; 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.service.bean.StngBean; -import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.dao.CrdnListMapper; import cokr.xit.fims.mngt.service.bean.FactionBean; -import cokr.xit.fims.sprt.PrintOption; import cokr.xit.fims.sprt.SprtQuery; import cokr.xit.fims.sprt.dao.IntegrationSearchMapper; import cokr.xit.fims.sprt.dao.OtptStngMapper; import cokr.xit.fims.sprt.service.IntegrationSearchService; import cokr.xit.foundation.component.AbstractServiceBean; import cokr.xit.foundation.data.DataObject; -import net.lingala.zip4j.ZipFile; /**통합 조회 서비스 구현체. * @@ -91,136 +72,4 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements } - - - @Override - public Map makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds) { - 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; - - File imagesFolderPathFile = new File(imagesFolderPath); - if (!imagesFolderPathFile.exists()) { - imagesFolderPathFile.mkdirs(); - } - - 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 = mediaBean.getMosaicList(fileInfo.string("FILE_ID")); - String orgnFilePath = fileInfo.string("FILE_PATH"); - if(ifEmpty(orgnFilePath, ()->"").equals("")) { - continue; - } - - if(!orgnFilePath.startsWith("files")) { - orgnFilePath = CmmnUtil.copyStaticResource(orgnFilePath, false); - } - - File orgnFile = new File(orgnFilePath); - if(!orgnFile.exists() || !orgnFile.canRead()) { - continue; - } - InputStream orgnFileInputStream = new FileInputStream(orgnFile); - - String modifiedFileName = "P"+fileInfo.string("INF_KEY")+CmmnUtil.indexToAlphabet(j, true, true)+"."+"JPG"; - - String modifiedFilePath = imagesFolderPath + File.separator + modifiedFileName; - - File modifiedFile = new File(modifiedFilePath); - - if(mosaicInfos != null) { - CmmnUtil.createMaskedImage(orgnFileInputStream, modifiedFile, mosaicInfos); - } else { - Files.copy(orgnFileInputStream, 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("filename", zipFileName); - result.put("filePath", zipFilePath); - result.put("file", new File(zipFilePath)); - - } catch (IOException e) { - throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다."); - } - - return result; - } - } diff --git a/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java b/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java index 3a3e8340..b454daa6 100644 --- a/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java +++ b/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java @@ -18,6 +18,7 @@ import org.springframework.web.servlet.ModelAndView; import com.fasterxml.jackson.core.type.TypeReference; import cokr.xit.base.code.CommonCode; +import cokr.xit.base.file.etc.OutsourcingFileWriter; import cokr.xit.base.file.hwp.HWPWriter; import cokr.xit.base.file.pdf.PDFWriter; import cokr.xit.base.file.service.FileQuery; @@ -771,7 +772,43 @@ public class Sprt01Controller extends ApplicationController { public ModelAndView makeAdvntceOutsourcing(PrintOption printOption, String[] crdnIds) { ModelAndView mav = new ModelAndView("downloadView"); - Map result = integrationSearchService.makeOutsourcingFile("advntce", printOption, crdnIds); + SprtQuery sprtQuery = new SprtQuery(); + sprtQuery.setCrdnIds(crdnIds); + List dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery); + 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) { + int crdnPhotoCnt = fileInfoList.size(); + for(int j=0; j < fileInfoList.size(); j++) { + DataObject fileInfo = fileInfoList.get(j); + + dataObject.set("CRDN_PHOTO"+(j+1), fileInfo.string("FILE_PATH")); + dataObject.set("CRDN_PHOTO"+(j+1)+"KEY", fileInfo.string("FILE_ID")); + List mosSet = mediaBean.getMosaicList(fileInfo.string("FILE_ID")); + if(mosSet != null) { + for(int k=0; k < mosSet.size(); k++) { + dataObject.set("MOS"+fileInfo.string("FILE_ID"), mosSet); + } + } + } + dataObject.set("CRDN_PHOTO_CNT", crdnPhotoCnt); + } else { + dataObject.set("CRDN_PHOTO_CNT", 0); + } + + } + + List printStngItems = new ArrayList(); + + OutsourcingFileWriter osWriter = new OutsourcingFileWriter(); + + Map result = osWriter.makeOutsourcingFile("사전통지", printOption, dataObjectList, printStngItems); mav.addAllObjects(result); return mav; @@ -890,7 +927,43 @@ public class Sprt01Controller extends ApplicationController { public ModelAndView makeNhtOutsourcing(PrintOption printOption, String[] crdnIds) { ModelAndView mav = new ModelAndView("downloadView"); - Map result = integrationSearchService.makeOutsourcingFile("nht", printOption, crdnIds); + SprtQuery sprtQuery = new SprtQuery(); + sprtQuery.setCrdnIds(crdnIds); + List dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery); + 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) { + int crdnPhotoCnt = fileInfoList.size(); + for(int j=0; j < fileInfoList.size(); j++) { + DataObject fileInfo = fileInfoList.get(j); + + dataObject.set("CRDN_PHOTO"+(j+1), fileInfo.string("FILE_PATH")); + dataObject.set("CRDN_PHOTO"+(j+1)+"KEY", fileInfo.string("FILE_ID")); + List mosSet = mediaBean.getMosaicList(fileInfo.string("FILE_ID")); + if(mosSet != null) { + for(int k=0; k < mosSet.size(); k++) { + dataObject.set("MOS"+fileInfo.string("FILE_ID"), mosSet); + } + } + } + dataObject.set("CRDN_PHOTO_CNT", crdnPhotoCnt); + } else { + dataObject.set("CRDN_PHOTO_CNT", 0); + } + + } + + List printStngItems = new ArrayList(); + + OutsourcingFileWriter osWriter = new OutsourcingFileWriter(); + + Map result = osWriter.makeOutsourcingFile("고지서", printOption, dataObjectList, printStngItems); mav.addAllObjects(result); return mav;