|
|
|
|
@ -11,21 +11,19 @@ import java.io.OutputStream;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
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.applib.Hangul;
|
|
|
|
|
import cokr.xit.base.file.ZIP;
|
|
|
|
|
import cokr.xit.foundation.Downloadable;
|
|
|
|
|
import cokr.xit.foundation.component.AbstractBean;
|
|
|
|
|
import cokr.xit.foundation.data.DataFormat;
|
|
|
|
|
import cokr.xit.foundation.data.DataObject;
|
|
|
|
|
|
|
|
|
|
public class OutsourcingFileMaker {
|
|
|
|
|
public class OutsourcingFileMaker extends AbstractBean {
|
|
|
|
|
protected String printKorName;
|
|
|
|
|
protected FimsPrintOption printOption;
|
|
|
|
|
protected List<DataObject> data;
|
|
|
|
|
@ -33,8 +31,7 @@ public class OutsourcingFileMaker {
|
|
|
|
|
|
|
|
|
|
protected String resultZipFilePath;
|
|
|
|
|
|
|
|
|
|
public OutsourcingFileMaker(String printKorName, FimsPrintOption printOption, List<DataObject> printStngItems,
|
|
|
|
|
List<DataObject> data){
|
|
|
|
|
public OutsourcingFileMaker(String printKorName, FimsPrintOption printOption, List<DataObject> printStngItems, List<DataObject> data){
|
|
|
|
|
this.printKorName = printKorName;
|
|
|
|
|
this.printOption = printOption;
|
|
|
|
|
this.data = data;
|
|
|
|
|
@ -45,36 +42,26 @@ public class OutsourcingFileMaker {
|
|
|
|
|
* 서식에서 사용하는 출력항목 중 사용하는 항목만 추출한다.
|
|
|
|
|
*/
|
|
|
|
|
public List<PredefinedSet> filterUsedArtcls() {
|
|
|
|
|
List<String> otptArtclNmList = this.printStngItems.stream().map((item) -> { return item.string("ARTCL_NM"); }).toList();
|
|
|
|
|
|
|
|
|
|
List<PredefinedSet> result = OutsourcingFileMaker.predifinedSetForOutsourcing().stream()
|
|
|
|
|
.filter((item) -> {
|
|
|
|
|
return otptArtclNmList.contains(item.getArtclNm());
|
|
|
|
|
}).toList();
|
|
|
|
|
List<String> otptArtclNmList = printStngItems.stream()
|
|
|
|
|
.map((item) -> item.string("ARTCL_NM"))
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
return OutsourcingFileMaker.predifinedSetForOutsourcing().stream()
|
|
|
|
|
.filter((item) -> otptArtclNmList.contains(item.getArtclNm()))
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 다운로드 이력에 남길 항목명을 추출한다.
|
|
|
|
|
*/
|
|
|
|
|
public List<String> filterDownloadDataNames() {
|
|
|
|
|
|
|
|
|
|
List<String> result = this.filterUsedArtcls().stream()
|
|
|
|
|
.filter((item) -> {
|
|
|
|
|
return item.isDownloadData();
|
|
|
|
|
})
|
|
|
|
|
.map(PredefinedSet::getArtclDscrp).toList();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
return filterUsedArtcls().stream()
|
|
|
|
|
.filter((item) -> item.isDownloadData())
|
|
|
|
|
.map(PredefinedSet::getArtclDscrp)
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> makeFile() {
|
|
|
|
|
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);
|
|
|
|
|
@ -85,57 +72,39 @@ public class OutsourcingFileMaker {
|
|
|
|
|
String outsourcingResultPath = "files"+File.separator+"temp"+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();
|
|
|
|
|
}
|
|
|
|
|
ensureDir(outsourcingResultPath);
|
|
|
|
|
|
|
|
|
|
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 < data.size(); i++) {
|
|
|
|
|
DataObject dataObject = data.get(i);
|
|
|
|
|
File imagesFolderPathFile = ensureDir(imagesFolderPath);
|
|
|
|
|
|
|
|
|
|
for(DataObject dataObject: data) {
|
|
|
|
|
CmmnUtil.setOcrInfo(dataObject);
|
|
|
|
|
CmmnUtil.setBarcode(dataObject);
|
|
|
|
|
String sndngDtlId = dataObject.string("SNDNG_DTL_ID");
|
|
|
|
|
|
|
|
|
|
int crdnPhotoCnt = dataObject.number("CRDN_PHOTO_CNT").intValue();
|
|
|
|
|
int crdnPhotoCnt = toInt(dataObject.get("CRDN_PHOTO_CNT"));
|
|
|
|
|
|
|
|
|
|
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(isEmpty(orgnFilePath)) continue;
|
|
|
|
|
|
|
|
|
|
if(!orgnFilePath.startsWith("files")) {
|
|
|
|
|
orgnFilePath = CmmnUtil.copyStaticResource(orgnFilePath, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File orgnFile = new File(orgnFilePath);
|
|
|
|
|
if(!orgnFile.exists() || !orgnFile.canRead()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(!orgnFile.exists() || !orgnFile.canRead()) continue;
|
|
|
|
|
|
|
|
|
|
InputStream orgnFileInputStream = new FileInputStream(orgnFile);
|
|
|
|
|
|
|
|
|
|
String modifiedFileName = "P"+sndngDtlId+CmmnUtil.indexToAlphabet(j, true, true)+"."+"JPG";
|
|
|
|
|
|
|
|
|
|
String modifiedFilePath = imagesFolderPath + File.separator + modifiedFileName;
|
|
|
|
|
|
|
|
|
|
File modifiedFile = new File(modifiedFilePath);
|
|
|
|
|
|
|
|
|
|
if(dataObject.get("MOS"+fileKey) != null) {
|
|
|
|
|
@ -150,48 +119,28 @@ public class OutsourcingFileMaker {
|
|
|
|
|
|
|
|
|
|
File metaFile = new File(metaFilePath);
|
|
|
|
|
if (!metaFile.exists()) {
|
|
|
|
|
if(!metaFile.createNewFile()) {
|
|
|
|
|
if(!metaFile.createNewFile())
|
|
|
|
|
throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다.");
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
FileWriter fw = new FileWriter(metaFile);
|
|
|
|
|
BufferedWriter writer = new BufferedWriter(fw);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Hangul hangul = new Hangul(2);
|
|
|
|
|
for(int i=0; i < data.size(); i++) {
|
|
|
|
|
DataObject dataObject = data.get(i);
|
|
|
|
|
|
|
|
|
|
if(i != 0) {
|
|
|
|
|
if(i != 0)
|
|
|
|
|
writer.write("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String line = "";
|
|
|
|
|
for(DataObject printStngItem : printStngItems){
|
|
|
|
|
String artclNm = printStngItem.string("ARTCL_NM");
|
|
|
|
|
int byteCnt = printStngItem.number("ARTCL_SZ").intValue();
|
|
|
|
|
String artclValue = "";
|
|
|
|
|
|
|
|
|
|
//조회한 데이터와 관련없는 항목(출력일시 등)
|
|
|
|
|
if(artclNm.equals("OTPT_YMD") || artclNm.equals("OTPT_YEAR")
|
|
|
|
|
|| artclNm.equals("OTPT_MONTH") || artclNm.equals("OTPT_DAY")) {
|
|
|
|
|
switch(artclNm) {
|
|
|
|
|
case "OTPT_YMD" :
|
|
|
|
|
artclValue = yyyymmdd;
|
|
|
|
|
break;
|
|
|
|
|
case "OTPT_YEAR" :
|
|
|
|
|
artclValue = year;
|
|
|
|
|
break;
|
|
|
|
|
case "OTPT_MONTH" :
|
|
|
|
|
artclValue = month;
|
|
|
|
|
break;
|
|
|
|
|
case "OTPT_DAY" :
|
|
|
|
|
artclValue = day;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
artclValue = dataObject.string(artclNm);
|
|
|
|
|
}
|
|
|
|
|
String artclValue = switch (artclNm) {
|
|
|
|
|
case "OTPT_YMD" -> yyyymmdd;
|
|
|
|
|
case "OTPT_YEAR" -> year;
|
|
|
|
|
case "OTPT_MONTH" -> month;
|
|
|
|
|
case "OTPT_DAY" -> day;
|
|
|
|
|
default -> dataObject.string(artclNm);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//포매팅
|
|
|
|
|
if(!printStngItem.string("FORMATTING").equals("")) {
|
|
|
|
|
@ -227,6 +176,7 @@ public class OutsourcingFileMaker {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//공백 패딩 방향
|
|
|
|
|
int byteCnt = toInt(printStngItem.get("ARTCL_SZ"));
|
|
|
|
|
if(printStngItem.string("PADDING_DIRECTION").equals("left")) {
|
|
|
|
|
line += hangul.lpadByte(artclValue, byteCnt, " ");
|
|
|
|
|
} else {
|
|
|
|
|
@ -242,8 +192,7 @@ public class OutsourcingFileMaker {
|
|
|
|
|
String zipFileName = yyyymmdd + printKorName + ".zip";
|
|
|
|
|
String zipFilePath = outsourcingResultPath + File.separator + zipFileName;
|
|
|
|
|
|
|
|
|
|
ZIP zip = new ZIP();
|
|
|
|
|
zip.compress(zipFilePath, metaFilePath, imagesFolderPath);
|
|
|
|
|
new ZIP().compress(zipFilePath, metaFilePath, imagesFolderPath);
|
|
|
|
|
|
|
|
|
|
metaFile.delete();
|
|
|
|
|
File[] images = imagesFolderPathFile.listFiles();
|
|
|
|
|
@ -253,27 +202,25 @@ public class OutsourcingFileMaker {
|
|
|
|
|
imagesFolderPathFile.delete();
|
|
|
|
|
|
|
|
|
|
resultZipFilePath = zipFilePath;
|
|
|
|
|
result.put("download", this.getDownloadable().setFilename(zipFileName));
|
|
|
|
|
result.put("downloadData", data);
|
|
|
|
|
result.put("dataNames", this.filterDownloadDataNames());
|
|
|
|
|
return Map.of(
|
|
|
|
|
"download", getDownloadable().setFilename(zipFileName),
|
|
|
|
|
"downloadData", data,
|
|
|
|
|
"dataNames", this.filterDownloadDataNames()
|
|
|
|
|
);
|
|
|
|
|
} catch(FileNotFoundException e) {
|
|
|
|
|
throw new RuntimeException("파일을 찾을 수 없습니다.");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void write(OutputStream out) {
|
|
|
|
|
try {
|
|
|
|
|
FileInputStream fis = new FileInputStream(resultZipFilePath);
|
|
|
|
|
try (FileInputStream fis = new FileInputStream(resultZipFilePath);) {
|
|
|
|
|
fis.transferTo(out);
|
|
|
|
|
fis.close();
|
|
|
|
|
new File(resultZipFilePath).delete();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -284,35 +231,35 @@ public class OutsourcingFileMaker {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<PredefinedSet> predifinedSetForOutsourcing() {
|
|
|
|
|
List<PredefinedSet> predefinedSetList = new ArrayList<>();
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("SNDNG_DTL_ID", "발송상세아이디").offLog());
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("VLTN_LAW_NM", "위반법명"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("BARCODE", "바코드").offLog());
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("CRDN_DT", "단속일시"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("DUDT_YMD", "납부기한"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("VHRNO", "차량번호"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("FFNLG_CARMDL_NM", "과태료차종명"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("VHCL_NM", "차량명"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("CRDN_PLC", "단속장소"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("RTPYR_ADDR", "납부자기본주소"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("RTPYR_DTL_ADDR", "납부자상세주소"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("RTPYR_ZIP", "납부자우편번호"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("RTPYR_NM", "납부자명"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("OPNN_RANGE", "의견진술기간"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("CRDN_SE_NM", "단속구분명"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("ATCH_FILE_CNT", "첨부파일갯수"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("FFNLG_CRDN_AMT", "과태료단속금액"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("LAST_AMT", "최종금액"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("RG_NO", "등기번호"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("OCR0", "OCR0").offLog());
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("OCR0_1", "OCR0_1").offLog());
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("OCR0_2", "OCR0_2").offLog());
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("OCR_BAND1", "OCR_BAND1").offLog());
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("OCR_BAND2", "OCR_BAND2").offLog());
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("BANK_NM", "가상계좌은행명"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("VR_ACTNO", "가상계좌"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("EPAYNO", "전자납부번호"));
|
|
|
|
|
predefinedSetList.add(new PredefinedSet("EMPTY", "공백").offLog());
|
|
|
|
|
return predefinedSetList;
|
|
|
|
|
return Arrays.asList(
|
|
|
|
|
new PredefinedSet("SNDNG_DTL_ID", "발송상세아이디").offLog(),
|
|
|
|
|
new PredefinedSet("VLTN_LAW_NM", "위반법명"),
|
|
|
|
|
new PredefinedSet("BARCODE", "바코드").offLog(),
|
|
|
|
|
new PredefinedSet("CRDN_DT", "단속일시"),
|
|
|
|
|
new PredefinedSet("DUDT_YMD", "납부기한"),
|
|
|
|
|
new PredefinedSet("VHRNO", "차량번호"),
|
|
|
|
|
new PredefinedSet("FFNLG_CARMDL_NM", "과태료차종명"),
|
|
|
|
|
new PredefinedSet("VHCL_NM", "차량명"),
|
|
|
|
|
new PredefinedSet("CRDN_PLC", "단속장소"),
|
|
|
|
|
new PredefinedSet("RTPYR_ADDR", "납부자기본주소"),
|
|
|
|
|
new PredefinedSet("RTPYR_DTL_ADDR", "납부자상세주소"),
|
|
|
|
|
new PredefinedSet("RTPYR_ZIP", "납부자우편번호"),
|
|
|
|
|
new PredefinedSet("RTPYR_NM", "납부자명"),
|
|
|
|
|
new PredefinedSet("OPNN_RANGE", "의견진술기간"),
|
|
|
|
|
new PredefinedSet("CRDN_SE_NM", "단속구분명"),
|
|
|
|
|
new PredefinedSet("ATCH_FILE_CNT", "첨부파일갯수"),
|
|
|
|
|
new PredefinedSet("FFNLG_CRDN_AMT", "과태료단속금액"),
|
|
|
|
|
new PredefinedSet("LAST_AMT", "최종금액"),
|
|
|
|
|
new PredefinedSet("RG_NO", "등기번호"),
|
|
|
|
|
new PredefinedSet("OCR0", "OCR0").offLog(),
|
|
|
|
|
new PredefinedSet("OCR0_1", "OCR0_1").offLog(),
|
|
|
|
|
new PredefinedSet("OCR0_2", "OCR0_2").offLog(),
|
|
|
|
|
new PredefinedSet("OCR_BAND1", "OCR_BAND1").offLog(),
|
|
|
|
|
new PredefinedSet("OCR_BAND2", "OCR_BAND2").offLog(),
|
|
|
|
|
new PredefinedSet("BANK_NM", "가상계좌은행명"),
|
|
|
|
|
new PredefinedSet("VR_ACTNO", "가상계좌"),
|
|
|
|
|
new PredefinedSet("EPAYNO", "전자납부번호"),
|
|
|
|
|
new PredefinedSet("EMPTY", "공백").offLog()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|