외주요청 파일 다운로드 수정

main
이범준 9 months ago
parent 5ccfbe310f
commit d05dd6ee89

@ -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<String, Object> makeOutsourcingFile(String printKorName, PrintOption printOption,
List<DataObject> dataObjectList, List<DataObject> printStngItems) {
Map<String, Object> 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>)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;
}
}

@ -12,6 +12,7 @@ import org.apache.poi.ss.usermodel.CellStyle;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import cokr.xit.base.code.CommonCode; 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.hwp.HWPWriter;
import cokr.xit.base.file.pdf.PDFWriter; import cokr.xit.base.file.pdf.PDFWriter;
import cokr.xit.base.file.service.FileQuery; import cokr.xit.base.file.service.FileQuery;
@ -1760,8 +1761,43 @@ public class Sndb01Controller extends ApplicationController {
for (int iLoop = 0; iLoop < list.size(); iLoop++) { for (int iLoop = 0; iLoop < list.size(); iLoop++) {
crdnIds[iLoop] = list.get(iLoop).string("CRDN_ID"); crdnIds[iLoop] = list.get(iLoop).string("CRDN_ID");
} }
SprtQuery sprtQuery = new SprtQuery();
sprtQuery.setCrdnIds(crdnIds);
List<DataObject> 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<DataObject> 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<DataObject> 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<DataObject> printStngItems = new ArrayList<DataObject>();
OutsourcingFileWriter osWriter = new OutsourcingFileWriter();
Map<String, Object> result = integrationSearchService.makeOutsourcingFile("advntce", printOption, crdnIds); Map<String, Object> result = osWriter.makeOutsourcingFile("사전통지", printOption, dataObjectList, printStngItems);
mav.addAllObjects(result); mav.addAllObjects(result);

@ -1,9 +1,7 @@
package cokr.xit.fims.sprt.service; package cokr.xit.fims.sprt.service;
import java.util.List; import java.util.List;
import java.util.Map;
import cokr.xit.fims.sprt.PrintOption;
import cokr.xit.fims.sprt.SprtQuery; import cokr.xit.fims.sprt.SprtQuery;
import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.DataObject;
@ -31,15 +29,4 @@ public interface IntegrationSearchService {
*/ */
String updateEtcCn(String etcCn, String... crdnIds); String updateEtcCn(String etcCn, String... crdnIds);
/** .
* @param formatName , printOption , crdnIds
* @return map
* <ul><li>filename: </li>
* <li>filePath: </li>
* <li>file: </li>
* </ul>
*/
Map<String, Object> makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds);
} }

@ -1,40 +1,21 @@
package cokr.xit.fims.sprt.service.bean; 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.List;
import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import cokr.xit.base.file.service.FileQuery;
import cokr.xit.base.file.service.bean.FileBean; 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.cmmn.service.bean.StngBean;
import cokr.xit.fims.crdn.Crdn;
import cokr.xit.fims.crdn.dao.CrdnListMapper; import cokr.xit.fims.crdn.dao.CrdnListMapper;
import cokr.xit.fims.mngt.service.bean.FactionBean; 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.SprtQuery;
import cokr.xit.fims.sprt.dao.IntegrationSearchMapper; import cokr.xit.fims.sprt.dao.IntegrationSearchMapper;
import cokr.xit.fims.sprt.dao.OtptStngMapper; import cokr.xit.fims.sprt.dao.OtptStngMapper;
import cokr.xit.fims.sprt.service.IntegrationSearchService; import cokr.xit.fims.sprt.service.IntegrationSearchService;
import cokr.xit.foundation.component.AbstractServiceBean; import cokr.xit.foundation.component.AbstractServiceBean;
import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.DataObject;
import net.lingala.zip4j.ZipFile;
/** . /** .
* *
@ -91,136 +72,4 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
} }
@Override
public Map<String, Object> makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds) {
Map<String, Object> 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<DataObject> 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<DataObject> fileInfoList = fileBean.getFileList(fileQuery);
if(fileInfoList == null) {
fileInfoList = new ArrayList<DataObject>();
}
for(int j=0; j < fileInfoList.size(); j++){
DataObject fileInfo = fileInfoList.get(j);
List<DataObject> 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<DataObject> printItems = new ArrayList<DataObject>();
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;
}
} }

@ -18,6 +18,7 @@ import org.springframework.web.servlet.ModelAndView;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import cokr.xit.base.code.CommonCode; 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.hwp.HWPWriter;
import cokr.xit.base.file.pdf.PDFWriter; import cokr.xit.base.file.pdf.PDFWriter;
import cokr.xit.base.file.service.FileQuery; import cokr.xit.base.file.service.FileQuery;
@ -771,7 +772,43 @@ public class Sprt01Controller extends ApplicationController {
public ModelAndView makeAdvntceOutsourcing(PrintOption printOption, String[] crdnIds) { public ModelAndView makeAdvntceOutsourcing(PrintOption printOption, String[] crdnIds) {
ModelAndView mav = new ModelAndView("downloadView"); ModelAndView mav = new ModelAndView("downloadView");
Map<String, Object> result = integrationSearchService.makeOutsourcingFile("advntce", printOption, crdnIds); SprtQuery sprtQuery = new SprtQuery();
sprtQuery.setCrdnIds(crdnIds);
List<DataObject> 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<DataObject> 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<DataObject> 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<DataObject> printStngItems = new ArrayList<DataObject>();
OutsourcingFileWriter osWriter = new OutsourcingFileWriter();
Map<String, Object> result = osWriter.makeOutsourcingFile("사전통지", printOption, dataObjectList, printStngItems);
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;
@ -890,7 +927,43 @@ public class Sprt01Controller extends ApplicationController {
public ModelAndView makeNhtOutsourcing(PrintOption printOption, String[] crdnIds) { public ModelAndView makeNhtOutsourcing(PrintOption printOption, String[] crdnIds) {
ModelAndView mav = new ModelAndView("downloadView"); ModelAndView mav = new ModelAndView("downloadView");
Map<String, Object> result = integrationSearchService.makeOutsourcingFile("nht", printOption, crdnIds); SprtQuery sprtQuery = new SprtQuery();
sprtQuery.setCrdnIds(crdnIds);
List<DataObject> 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<DataObject> 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<DataObject> 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<DataObject> printStngItems = new ArrayList<DataObject>();
OutsourcingFileWriter osWriter = new OutsourcingFileWriter();
Map<String, Object> result = osWriter.makeOutsourcingFile("고지서", printOption, dataObjectList, printStngItems);
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;

Loading…
Cancel
Save